tools

various tools
git clone git://deadbeef.fr/tools.git
Log | Files | Refs | README | LICENSE

service_info.hpp (3301B)


      1 // Copyright (c) 2020 Morel BĂ©renger
      2 // 
      3 // This software is provided 'as-is', without any express or implied
      4 // warranty. In no event will the authors be held liable for any damages
      5 // arising from the use of this software.
      6 // 
      7 // Permission is granted to anyone to use this software for any purpose,
      8 // including commercial applications, and to alter it and redistribute it
      9 // freely, subject to the following restrictions:
     10 // 
     11 // 1. The origin of this software must not be misrepresented; you must not
     12 //    claim that you wrote the original software. If you use this software
     13 //    in a product, an acknowledgment in the product documentation would be
     14 //    appreciated but is not required.
     15 // 2. Altered source versions must be plainly marked as such, and must not be
     16 //    misrepresented as being the original software.
     17 // 3. This notice may not be removed or altered from any source distribution.
     18 
     19 #ifndef SERVICE_INFO_HPP
     20 #define SERVICE_INFO_HPP
     21 
     22 #include <regex.h>
     23 
     24 struct area_t
     25 {
     26 	uint16_t x, y;
     27 	uint16_t w, h;
     28 };
     29 
     30 enum status_t
     31 {
     32 	DOWN,
     33 	WAKING,
     34 	UP,
     35 };
     36 
     37 bool add_serv_info( void* var, char* arg );
     38 bool show_serv_info( void const* val, FILE* target );
     39 
     40 // registers info about a service:
     41 // * pointer to the filepath of logs to analyse
     42 // * directory inotify watcher
     43 // * file inotify watcher if the file exists
     44 // * open file descriptor if the file exists
     45 // * time since last "starting" regex was met, without "stoping" regex
     46 // * offset from filepath at which directory name ends
     47 struct service_info_t
     48 {
     49 	// passed argument is kept as is, and occurrences of ':' are
     50 	// used as end-of-string. The .*_sz vars are relative to
     51 	// previous index, 0 for filename_sz.
     52 	char *   path       = nullptr;   //path to watch with inotify
     53 	int      dir_wfd    = -1;        //inotify fd for parent dir
     54 	int      file_wfd   = -1;        //file to read data from
     55 	int      file_fd    = -1;        //file to read data from
     56 	uint16_t filename   = UINT16_MAX;//path offset, regex showing start of svc
     57 	uint16_t svstart    = UINT16_MAX;//path offset, regex showing start of svc
     58 	uint16_t svstop     = UINT16_MAX;//path offset, regex showind death of svc
     59 	//TODO: use for service identification
     60 	//uint16_t svcname    = UINT16_MAX;//path offset, regex showing start of svc
     61 	uint16_t live_delay = 0;         //seconds needed to be alive since birth
     62 	uint16_t birth_time = UINT16_MAX;//seconds since birth, MAX when not alive
     63 
     64 	area_t draw_area;
     65 };
     66 
     67 bool file_watch( service_info_t& svc, pollfd& pfd );
     68 
     69 size_t name_sz( service_info_t const& svc );
     70 char const* name( service_info_t const& svc );
     71 status_t status( service_info_t const& svc );
     72 
     73 bool print_status( service_info_t const& svc );
     74 bool refresh( service_info_t & svc, time_t time );
     75 bool update( service_info_t & svc );
     76 
     77 // stores the "master" inotify. Inotify is used to avoid
     78 // active probing files and still be able to handle log
     79 // rotations.
     80 extern int g_inotify_watch_fd;
     81 
     82 // stores the screen's dimensions, and the place in which
     83 // to start drawing (might be handy later).
     84 // Initialised at startup
     85 // TODO: keep it up to date with ioctl and SIGWINCH
     86 extern area_t g_screen_area;
     87 
     88 extern char const* g_color_down;
     89 extern char const* g_color_up;
     90 extern char const* g_color_wake;
     91 
     92 char const* move_to( service_info_t const& svc );
     93 
     94 #endif