1 /* gapcmon.h serial-0087-0 ************************************ 2 3 GKT+ GUI with Notification Area (System Tray) support. Program for 4 monitoring the apcctrl.sourceforge.net package. 5 Copyright (C) 2006 James Scott, Jr. <skoona@users.sourceforge.net> 6 7 This program is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation; either version 2 of the License, or 10 (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program; if not, write to the Free Software 19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 */ 21 22 23 24 25 #ifndef GAPC_H_ 26 #define GAPC_H_ 27 28 G_BEGIN_DECLS 29 30 #ifndef VERSION 31 #define GAPC_VERSION "0.8.7-0" 32 #else 33 #define GAPC_VERSION VERSION 34 #endif 35 36 #ifndef ICON_DIR 37 #define ICON_DIR "/usr/share" 38 #endif 39 40 #define GAPC_PROG_NAME "gapcmon" 41 #define GAPC_GROUP_TITLE "<i> Uninterruptible Power Supply Monitor...</i>\n for APCCTRL" 42 #define GAPC_WINDOW_TITLE "gapcmon: UPS Information Panels" 43 #define GAPC_CP_GROUP_KEY "/apps/gapcmon/controller" 44 #define GAPC_CP_SYSTRAY_KEY "/apps/gapcmon/controller/use_systray" 45 #define GAPC_CP_PAGERS_KEY "/apps/gapcmon/controller/skip_pagers" 46 47 #define GAPC_COLOR_LINEV_KEY "/apps/gapcmon/controller/color_linev" 48 #define GAPC_COLOR_LOADPCT_KEY "/apps/gapcmon/controller/color_loadpct" 49 #define GAPC_COLOR_TIMELEFT_KEY "/apps/gapcmon/controller/color_timeleft" 50 #define GAPC_COLOR_BCHARGE_KEY "/apps/gapcmon/controller/color_bcharge" 51 #define GAPC_COLOR_BATTV_KEY "/apps/gapcmon/controller/color_battv" 52 #define GAPC_COLOR_WINDOW_KEY "/apps/gapcmon/controller/color_window" 53 #define GAPC_COLOR_CHART_KEY "/apps/gapcmon/controller/color_chart" 54 #define GAPC_COLOR_TITLE_KEY "/apps/gapcmon/controller/color_title" 55 56 #define GAPC_MID_GROUP_KEY "/apps/gapcmon/monitor" 57 #define GAPC_ENABLE_KEY "/apps/gapcmon/monitor/%d/enabled" 58 #define GAPC_SYSTRAY_KEY "/apps/gapcmon/monitor/%d/use_systray" 59 #define GAPC_PAGER_KEY "/apps/gapcmon/monitor/%d/skip_pagers" /* not used */ 60 #define GAPC_PORT_KEY "/apps/gapcmon/monitor/%d/port_number" 61 #define GAPC_REFRESH_KEY "/apps/gapcmon/monitor/%d/network_interval" 62 #define GAPC_GRAPH_KEY "/apps/gapcmon/monitor/%d/graph_interval" 63 #define GAPC_HOST_KEY "/apps/gapcmon/monitor/%d/host_name" 64 #define GAPC_WATT_KEY "/apps/gapcmon/monitor/%d/ups_wattage" 65 #define GAPC_MAX_ARRAY 256 /* for arrays or lists */ 66 #define GAPC_MAX_TEXT 256 /* for strings */ 67 #define GAPC_ICON_SIZE 24 /* Ideal size of icons */ 68 #define GAPC_MAX_BUFFER 512 /* Size of a text buffer or local string */ 69 70 #define GAPC_REFRESH_FACTOR_1K 1000 /* micro.secs for visual refresh */ 71 #define GAPC_REFRESH_FACTOR_ONE_TIME 500 72 #define GAPC_HOST_DEFAULT "localhost" 73 #define GAPC_PORT_DEFAULT 3551 74 #define GAPC_WATT_DEFAULT 600 75 #define GAPC_REFRESH_DEFAULT 8.0 76 #define GAPC_REFRESH_MIN_INCREMENT 1.0 /* Minimum refresh cycle seconds */ 77 #define GAPC_LINEGRAPH_XMAX 40 78 #define GAPC_LINEGRAPH_YMAX 110 79 #define GAPC_LINEGRAPH_MAX_SERIES 5 80 #define GAPC_LINEGRAPH_REFRESH_FACTOR 30.0 /* Num refreshes per collection */ 81 82 #define SKNET_HUGE_ARRAY 4096 83 #define SKNET_REG_ARRAY 1024 84 #define SKNET_STR_ARRAY 256 85 86 typedef struct _SKNET_Control_Data { 87 gint cb_id; 88 GIOChannel *ioc; /* socket io channel */ 89 gint fd_server; /* our local server-socket */ 90 gint i_port; /* dest host port */ 91 gboolean b_network_control; /* TRUE signals resolve address needed */ 92 gchar ch_ip_string[SKNET_STR_ARRAY]; /* dest host ip addr or dns name */ 93 gchar ch_ip_client[SKNET_STR_ARRAY]; /* incoming host ip addr or dns name */ 94 gchar ch_ip_client_port[SKNET_STR_ARRAY]; /* incoming host ip port */ 95 gchar ch_session_message[SKNET_HUGE_ARRAY]; 96 gchar ch_error_msg[SKNET_REG_ARRAY]; 97 gpointer gip; /* struct sockaddr_in -- resolved tcp-ip address */ 98 gpointer gp_reserved; /* reserved private pointer for me */ 99 gpointer gp_user_data; /* private pointer for YOU or user */ 100 gint i_byte_counter; /* public byte counter */ 101 } SKNET_COMMS, *PSKCOMM; 102 103 typedef enum _Control_Block_id { 104 CB_SERIES_ID, 105 CB_RANGE_ID, 106 CB_GRAPH_ID, 107 CB_HISTORY_ID, 108 CB_MONITOR_ID, 109 CB_CONTROL_ID, 110 CB_COLUMN_ID, 111 CB_SUMM_ID, 112 CB_PSKCOMM_ID, 113 CB_N_ID 114 } GAPCDataID; 115 116 typedef enum _State_Icons_IDs { 117 GAPC_ICON_ONLINE, 118 GAPC_ICON_ONBATT, 119 GAPC_ICON_CHARGING, 120 GAPC_ICON_DEFAULT, 121 GAPC_ICON_UNPLUGGED, 122 GAPC_ICON_NETWORKERROR, 123 GAPC_N_ICONS 124 } GAPC_IconType; 125 126 typedef enum _Timer_IDs { 127 GAPC_TIMER_AUTO, 128 GAPC_TIMER_DEDICATED, 129 GAPC_TIMER_CONTROL, 130 GAPC_N_TIMERS 131 } GAPC_TimerType; 132 133 typedef enum _Prefs_Store_IDs { 134 GAPC_PREFS_MONITOR, 135 GAPC_PREFS_ENABLED, 136 GAPC_PREFS_SYSTRAY, 137 GAPC_PREFS_PORT, 138 GAPC_PREFS_REFRESH, 139 GAPC_PREFS_GRAPH, 140 GAPC_PREFS_HOST, 141 GAPC_PREFS_WATT, 142 GAPC_N_PREFS_COLUMNS 143 } GAPC_PrefsType; 144 145 typedef enum _Monitor_Store_IDs { 146 GAPC_MON_MONITOR, 147 GAPC_MON_ICON, 148 GAPC_MON_STATUS, 149 GAPC_MON_POINTER, 150 GAPC_MON_UPSSTATE, 151 GAPC_N_MON_COLUMNS 152 } GAPC_MonitorType; 153 154 typedef struct _Preferences_Key_Records { 155 gchar k_enabled[GAPC_MAX_TEXT]; 156 gchar k_use_systray[GAPC_MAX_TEXT]; 157 gchar k_port_number[GAPC_MAX_TEXT]; 158 gchar k_network_interval[GAPC_MAX_TEXT]; 159 gchar k_graph_interval[GAPC_MAX_TEXT]; 160 gchar k_host_name[GAPC_MAX_TEXT]; 161 gchar v_host_name[GAPC_MAX_TEXT]; 162 } GAPC_PKEYS, *PGAPC_PKEYS; 163 164 /* Control structure for TreeView columns and callbacks */ 165 typedef struct _Prefs_Column_Data { 166 GAPCDataID cb_id; /* This is REQUIRED TO BE 1ST in struct */ 167 guint cb_monitor_num; /* monitor number 1-based */ 168 guint i_col_num; 169 GConfClient *client; 170 GtkTreeModel *prefs_model; /* GtkListStore */ 171 172 } GAPC_PREFS_COLUMN, *PGAPC_PREFS_COLUMN; 173 174 typedef struct _Monitor_Column_Data { 175 GAPCDataID cb_id; /* This is REQUIRED TO BE 1ST in struct */ 176 guint cb_monitor_num; /* monitor number 1-based */ 177 guint i_col_num; 178 GConfClient *client; 179 GtkTreeModel *monitor_model; /* GtkListStore */ 180 181 } GAPC_MON_COLUMN, *PGAPC_MON_COLUMN; 182 183 typedef struct _GAPC_H_CHART { 184 GAPCDataID cb_id; 185 gdouble d_value; 186 gboolean b_center_text; 187 gchar c_text[GAPC_MAX_TEXT]; 188 GdkRectangle rect; 189 } GAPC_BAR_H, *PGAPC_BAR_H; 190 191 typedef struct _GAPC_SUM_SQUARES { 192 GAPCDataID cb_id; 193 gint point_count; 194 195 gdouble this_point; 196 gdouble this_answer; 197 198 gdouble last_point; 199 gdouble last_answer; 200 201 gdouble answer_summ; 202 gdouble point_min; 203 gdouble point_max; 204 205 GMutex *gm_graph; /* Control mutex for graphics filter */ 206 } GAPC_SUMS, *PGAPC_SUMS; 207 208 typedef struct _LGRAPH_SERIES { 209 GAPCDataID cb_id; 210 gint i_series_id; /* is this series number 1 2 or 3, ZERO based */ 211 gint i_point_count; /* 1 based */ 212 gint i_max_points; /* 1 based */ 213 gchar ch_legend_text[GAPC_MAX_TEXT]; 214 gchar ch_legend_color[GAPC_MAX_TEXT]; 215 GdkColor legend_color; 216 gdouble d_max_value; 217 gdouble d_min_value; 218 gdouble *lg_point_dvalue; /* array of doubles y values zero based, x = index */ 219 GdkPoint *point_pos; /* last gdk position each point - recalc on evey draw */ 220 } LG_SERIES, *PLG_SERIES; 221 222 typedef struct _LGRAPH_RANGES { 223 GAPCDataID cb_id; 224 gint i_inc_minor_scale_by; /* minor increments */ 225 gint i_inc_major_scale_by; /* major increments */ 226 gint i_min_scale; /* minimum scale value - ex: 0 */ 227 gint i_max_scale; /* maximum scale value - ex: 100 */ 228 gint i_num_minor; /* number of minor points */ 229 gint i_num_major; /* number of major points */ 230 gint i_minor_inc; /* pixels per minor increment */ 231 gint i_major_inc; /* pixels per major increment */ 232 } LG_RANGE , *PLG_RANGE; 233 234 typedef struct _LG_GRAPH { 235 GAPCDataID cb_id; 236 GtkWidget *drawing_area; 237 GdkPixmap *pixmap; /* --- Backing pixmap for drawing area --- */ 238 GdkGC *window_gc; 239 GdkGC *box_gc; 240 GdkGC *scale_gc; 241 GdkGC *title_gc; 242 GdkGC *series_gc; 243 /* data points and tooltip info */ 244 gint i_num_series; /* 1 based */ 245 GList *lg_series; /* double-linked list of data series PLG_SERIES */ 246 GList *lg_series_time; /* time_t of each sample */ 247 gint i_points_available; 248 gboolean b_tooltip_active; 249 /* actual size of graph area */ 250 gint width; 251 gint height; 252 /* buffer around all sides */ 253 gint x_border; 254 gint y_border; 255 /* current mouse position */ 256 gboolean b_mouse_onoff; 257 GdkPoint mouse_pos; 258 GdkModifierType mouse_state; 259 /* top/left or baseline of labels and titles */ 260 gchar ch_color_window_bg[GAPC_MAX_TEXT]; 261 gchar ch_color_chart_bg[GAPC_MAX_TEXT]; 262 gchar ch_color_title_fg[GAPC_MAX_BUFFER]; 263 GdkRectangle x_label; 264 GdkRectangle y_label; 265 GdkRectangle x_title; 266 GdkRectangle x_tooltip; 267 gchar ch_tooltip_text[GAPC_MAX_BUFFER]; 268 gchar *x_label_text; 269 gchar *y_label_text; 270 gchar *x_title_text; 271 /* position and area of main graph plot area */ 272 GdkRectangle plot_box; 273 gchar ch_color_scale_fg[GAPC_MAX_TEXT]; 274 LG_RANGE x_range; 275 LG_RANGE y_range; 276 } LGRAPH , *PLGRAPH; 277 278 /* * Control structure for GtkExtra Charts in Information Window */ 279 typedef struct _History_Page_Data { 280 GAPCDataID cb_id; /* This is REQUIRED TO BE 1ST in struct */ 281 guint cb_monitor_num; /* monitor number 1-based */ 282 gpointer *gp; /* ptr back to the monitor */ 283 LGRAPH *plg; /* Line Graph pointer */ 284 GAPC_SUMS sq[GAPC_LINEGRAPH_MAX_SERIES + 4]; /* data point collector */ 285 gdouble d_xinc; /* base refresh increment for graph */ 286 gboolean b_startup; 287 } GAPC_HISTORY, *PGAPC_HISTORY; 288 289 /* * Control structure per active monitor icon in panel */ 290 typedef struct _Monitor_Instance_Data { 291 GAPCDataID cb_id; /* This is REQUIRED TO BE 1ST in struct */ 292 293 guint cb_monitor_num; /* Begin Preference values 1-based */ 294 gboolean cb_enabled; 295 gboolean cb_use_systray; 296 gchar *pch_host; 297 gint i_port; 298 gint i_watt; /* rated wattage of UPS*/ 299 gfloat d_refresh; 300 gfloat d_graph; /* End Preference values */ 301 302 gchar ch_title_info[GAPC_MAX_TEXT]; 303 304 GtkWidget *window; /* information window */ 305 GtkWidget *menu; /* Popup Menu */ 306 GtkWidget *notebook; /* information Notebook */ 307 gboolean b_visible; /* is the info window visible */ 308 guint i_info_context; /* StatusBar message Context */ 309 310 gboolean b_run; /* controller for all monitor resources -- except thread */ 311 gboolean b_thread_stop; /* single flag to stop thread */ 312 GThread *tid_thread_qwork; /* Background Thread */ 313 GMutex *gm_update; /* Control mutex for hashtables and thread */ 314 GAsyncQueue *q_network; 315 guint i_netbusy_counter; 316 guint tid_automatic_refresh; /* monitor refresh timer id */ 317 guint tid_graph_refresh; 318 gboolean b_data_available; /* Flag from thread indicating data ready */ 319 gboolean b_network_control; /* TRUE signals resolve address needed */ 320 321 gboolean b_timer_control; /* TRUE signals change in refresh interval */ 322 gboolean b_graph_control; /* TRUE signals change in refresh interval */ 323 gboolean b_refresh_button; /* Flag to thread to immediately update */ 324 325 GHashTable *pht_Status; /* Private hashtable status key=values */ 326 GHashTable *pht_Widgets; /* Private hashtable holding widget ptrs */ 327 328 GtkTooltips *tooltips; 329 guint i_icon_index; 330 gint i_old_icon_index; 331 gint i_icon_size; 332 gint i_icon_height; 333 gint i_icon_width; 334 335 GdkPixbuf **my_icons; 336 337 EggTrayIcon *tray_icon; 338 GtkWidget *tray_image; 339 340 GList *data_status; /* Holds line of status text */ 341 GList *data_events; /* Holds line of event text */ 342 gchar *pach_status[GAPC_MAX_ARRAY]; /* Holds line of status text */ 343 gchar *pach_events[GAPC_MAX_ARRAY]; /* Holds line of event text */ 344 345 GConfClient *client; /* GCONF id */ 346 gpointer *gp; /* assumed to point to pcfg */ 347 GtkTreeModel *monitor_model; /* GtkListStore */ 348 GAPC_HISTORY phs; /* structure for history notebook page */ 349 PSKCOMM psk; /* communication structure */ 350 } GAPC_MONITOR, *PGAPC_MONITOR; 351 352 /* * Control structure for root panel object -- this is the anchor */ 353 typedef struct _System_Control_Data { 354 GAPCDataID cb_id; /* This is REQUIRED TO BE 1ST in struct */ 355 GList *cb_glist_monitors; /* assumed to point to PGAPC_MONITOR */ 356 guint cb_last_monitor; /* last selected from icon list - 1-based */ 357 gboolean b_use_systray; /* gconf parms */ 358 gboolean b_tooltips; 359 gboolean b_run; /* operational flag */ 360 gchar *pch_gkeys[GAPC_N_PREFS_COLUMNS]; 361 GConfClient *client; /* GCONF id */ 362 guint i_group_id; /* GCONF dir notify ids - controller */ 363 guint i_prefs_id; /* GCONF dir notify ids - prefs-view */ 364 365 GtkWidget *window; 366 GtkWidget *menu; /* Popup Menu */ 367 gboolean b_visible; /* is the info window visible */ 368 369 GtkTreeModel *prefs_model; /* GtkListStore */ 370 GtkTreeView *prefs_treeview; 371 GtkTreeSelection *prefs_select; 372 guint prefs_last_monitor; /* assigning monitor numbers */ 373 gint cb_last_monitor_deleted; /* overide gconf inconsistency on kde */ 374 375 GtkTreeModel *monitor_model; /* GtkListStore */ 376 GtkTreeView *monitor_treeview; 377 GtkTreeSelection *monitor_select; 378 379 GtkWidget *image; 380 GtkTooltips *tooltips; 381 382 EggTrayIcon *tray_icon; 383 GtkWidget *tray_image; 384 GtkTooltips *tray_tooltips; 385 gint i_icon_size; 386 gint i_icon_height; 387 gint i_icon_width; 388 389 GHashTable *pht_Widgets; /* hashtable holding widget ptrs */ 390 GHashTable *pht_Status; /* hashtable holding status text */ 391 guint i_info_context; /* StatusBar Context */ 392 GdkPixbuf *my_icons[GAPC_N_ICONS + 8]; 393 394 /* Global graph properties */ 395 GdkColor color_linev; 396 GdkColor color_loadpct; 397 GdkColor color_timeleft; 398 GdkColor color_bcharge; 399 GdkColor color_battv; 400 GdkColor color_window; 401 GdkColor color_chart; 402 GdkColor color_title; 403 404 } GAPC_CONFIG, *PGAPC_CONFIG; 405 406 /* ************************************************************************* */ 407 408 #define GAPC_GLOSSARY "<span size=\"xx-large\"><b>GAPCMON</b></span>\n \ 409 A monitor for UPS's under the management of APCCTRL.\n\n \ 410 When active, gapcmon provides three visual objects to interact with. \ 411 First is the main control.panel where monitors are defined, enabled, and listed when \ 412 active. Second are notification area icons that manage the visibility of each window or \ 413 panel. The third is an information window showing historical and current details of \ 414 a UPS being monitored. \n\ 415 \n\n\ 416 <big><b>CONTROL PANEL WINDOW PAGES</b></big>\n\ 417 <b>ACTIVE MONITORS PAGE</b>\n\ 418 \n\ 419 A short list of the monitors that are currently enabled. The list shows \ 420 each monitor's current icon, its status, and a brief summary of its key metrics. \ 421 Double-clicking a row causes the information window of that monitor to be presented.\n\ 422 \n\ 423 <b>PREFERENCES PAGE</b>\n\ 424 <i>-for the monitors\n</i>\ 425 \n\ 426 <b><i>Enable:</i></b>\nCauses the monitor to immediately run, create an info-window, \ 427 and add an entry in the icon list window.\n\ 428 \n\ 429 <b><i>Use Trayicon:</i></b>\nAdds a notification area icon which toggles \ 430 the visibility of the monitor info-window when clicked.\n\ 431 \n\ 432 <b><i>Network refresh:</i></b>\nThe number of seconds between collections of status and event \ 433 data from the network.\n\ 434 \n\ 435 <b><i>Graph refresh:</i></b>\nMultiplied by the network refresh value to determine \ 436 the total number of seconds between graph data collections.\n\ 437 \n\ 438 <b><i>Hostname or IP Address:</i></b>\nThe hostname or address where an apcctrl NIS interface \ 439 is running.\n\ 440 \n\ 441 <b><i>Port:</i></b>\nThe NIS access port on the APCCTRL host; defaults to 3551.\n\ 442 \n\ 443 <b><i>Add | Remove Buttons:</i></b>\nButtons to add or remove a monitor entry from the \ 444 list of monitors above. Add, adds with defaulted values at end of list. Remove, removes \ 445 the currently selected row.\n\ 446 \n\n\ 447 <i>-for the control.panel\n</i>\ 448 \n\ 449 <b><i>Use Trayicon:</i></b>\nAdds a notification area icon which toggles \ 450 the visibility of the control panel when clicked. <i><b>Note:</b> all tray icons \ 451 contain a popup menu with the choices of 'JumpTo' interactive window, and 'Quit' \ 452 which either hides the window or destroys it in the case of the control panel. \ 453 Additionally, when use_trayicon is selected, the title of the window is removed from \ 454 the desktop's windowlist or taskbar.</i>\n\ 455 \n\n\ 456 <b>GRAPH PROPERTIES PAGE</b>\n\ 457 \n\ 458 Allows you to specify the colors to be used for each of the five data series on the \ 459 Historical Summary graph page of each monitor. General window background colors can \ 460 also be specified.\n\ 461 \n\n\ 462 <b>GLOSSARY PAGE</b>\n\ 463 \n\ 464 This page of introductory text.\n\ 465 \n\ 466 <b>ABOUT PAGE</b>\n\ 467 More standard vanity, and my e-mail ID in case something breaks.\n\ 468 \n\n\ 469 <big><b>MONITOR INFORMATION WINDOW PAGES</b></big>\n\ 470 <b>HISTORICAL SUMMARY PAGE</b>\n\ 471 A graph showing the last 40 samples of five key data points, scaled to represent all \ 472 points as a percentage of that value's normal range. A data point's value can be \ 473 viewed by moving the mouse over any desired point, a tooltip will appear \ 474 showing the color and value of all points at that interval. Data points are collected \ 475 periodically, based on the product of graph_refresh times network_refresh in seconds. \ 476 These tooltips can be enabled or disabled by clicking anywhere on the graph once.\n\ 477 \n\ 478 <b>DETAILED INFORMATION PAGE</b>\n\ 479 A more in-depth view of the monitored UPS's environmental values. Software, product, \ 480 and operational values are available and updated every 'network_refresh' seconds.\n\ 481 \n\ 482 <b>POWER EVENTS PAGE</b>\n\ 483 A log of all power events recorded by APCCTRL on the server.\n\ 484 \n\ 485 <b>FULL UPS STATUS PAGE</b>\n\ 486 A listing of the output from apcaccess showing the actual state as reported \ 487 by the UPS.\n\ 488 \n\ 489 " 490 491 /* ************************************************************************* */ 492 493 G_END_DECLS 494 #endif /*GAPC_H_ */ 495