2006-12-12 Esteban Sanchez <estebans@artica.es>
* src/pandora_status.[ch]: pandora_status_set_* removed and replaced by an unique pandora_status_set_all function. Added a new signal throwed for each status property when it changes. Added a new signal throwed when there is an incidence (any of the values changed to bad or good. * src/pandora-status-checker.c: Error message when SQL connects failed rewritten. Fixed the return of a gboolean value on functions that returns PandoraState. Check code replaced with the new functions. * src/pandora-info-window.c: Listen to new signals of PandoraStatus object. Style correction. * src/pandora-applet.c: Listen to new "incidence" signal of PandoraStatus object. Callback rewritten. Removed unused function. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@316 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
53305575d5
commit
c9f271e74f
|
@ -1,3 +1,21 @@
|
|||
2006-12-12 Esteban Sanchez <estebans@artica.es>
|
||||
|
||||
* src/pandora_status.[ch]: pandora_status_set_* removed and replaced
|
||||
by an unique pandora_status_set_all function. Added a new signal
|
||||
throwed for each status property when it changes. Added a new signal
|
||||
throwed when there is an incidence (any of the values changed to bad
|
||||
or good.
|
||||
|
||||
* src/pandora-status-checker.c: Error message when SQL connects failed
|
||||
rewritten. Fixed the return of a gboolean value on functions that
|
||||
returns PandoraState. Check code replaced with the new functions.
|
||||
|
||||
* src/pandora-info-window.c: Listen to new signals of PandoraStatus
|
||||
object. Style correction.
|
||||
|
||||
* src/pandora-applet.c: Listen to new "incidence" signal of
|
||||
PandoraStatus object. Callback rewritten. Removed unused function.
|
||||
|
||||
2006-12-12 Esteban Sanchez <estebans@artica.es>
|
||||
|
||||
* src/pandora-status-checker.c: Wait one second before starting to
|
||||
|
|
|
@ -66,8 +66,9 @@ static void pandora_applet_set_image_from_stock (PandoraApplet *a
|
|||
static gboolean pandora_applet_toplevel_menu_button_press_cb (GtkWidget *widget,
|
||||
GdkEventButton *event,
|
||||
gpointer data);
|
||||
static void pandora_applet_changed_status_cb (GObject *object,
|
||||
gpointer *data);
|
||||
static void pandora_applet_incidence_cb (GObject *object,
|
||||
gint data,
|
||||
gpointer user_data);
|
||||
static GtkWidget *pandora_applet_context_menu_create (PandoraApplet *applet);
|
||||
|
||||
static GObject *pandora_applet_constructor (GType type, guint n_props,
|
||||
|
@ -133,8 +134,8 @@ pandora_applet_init (PandoraApplet *applet)
|
|||
|
||||
gtk_widget_show_all (GTK_WIDGET (applet));
|
||||
|
||||
g_signal_connect (G_OBJECT (applet->priv->status), "changed",
|
||||
G_CALLBACK (pandora_applet_changed_status_cb),
|
||||
g_signal_connect (G_OBJECT (applet->priv->status), "incidence",
|
||||
G_CALLBACK (pandora_applet_incidence_cb),
|
||||
(gpointer) applet);
|
||||
|
||||
pandora_status_checker_run (applet->priv->checker);
|
||||
|
@ -278,48 +279,25 @@ pandora_applet_show_setup_cb (GtkMenuItem *mi, PandoraApplet *applet)
|
|||
}
|
||||
|
||||
static void
|
||||
pandora_applet_changed_status_cb (GObject *object,
|
||||
gpointer *data)
|
||||
pandora_applet_incidence_cb (GObject *object,
|
||||
gint data,
|
||||
gpointer user_data)
|
||||
{
|
||||
PandoraApplet *applet = PANDORA_APPLET (data);
|
||||
PandoraState state = data;
|
||||
PandoraApplet *applet = PANDORA_APPLET (user_data);
|
||||
|
||||
switch (pandora_status_get_alerts (PANDORA_STATUS (object))) {
|
||||
switch (state) {
|
||||
case STATE_BAD:
|
||||
pandora_applet_set_image_from_pixbuf (applet, applet->priv->icon_bad);
|
||||
return;
|
||||
|
||||
break;
|
||||
case STATE_OK:
|
||||
pandora_applet_set_image_from_pixbuf (applet, applet->priv->icon_good);
|
||||
|
||||
break;
|
||||
default:
|
||||
pandora_applet_set_image_from_pixbuf (applet, applet->priv->icon_unknown);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (pandora_status_get_servers (PANDORA_STATUS (object))) {
|
||||
case STATE_BAD:
|
||||
pandora_applet_set_image_from_pixbuf (applet, applet->priv->icon_bad);
|
||||
return;
|
||||
break;
|
||||
case STATE_OK:
|
||||
break;
|
||||
default:
|
||||
pandora_applet_set_image_from_pixbuf (applet, applet->priv->icon_unknown);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (pandora_status_get_agents (PANDORA_STATUS (object))) {
|
||||
case STATE_BAD:
|
||||
pandora_applet_set_image_from_pixbuf (applet, applet->priv->icon_bad);
|
||||
return;
|
||||
break;
|
||||
case STATE_OK:
|
||||
break;
|
||||
default:
|
||||
pandora_applet_set_image_from_pixbuf (applet, applet->priv->icon_unknown);
|
||||
return;
|
||||
}
|
||||
|
||||
pandora_applet_set_image_from_pixbuf (applet, applet->priv->icon_good);
|
||||
}
|
||||
|
||||
static GtkWidget *
|
||||
|
@ -382,10 +360,10 @@ pandora_applet_menu_position_func (GtkMenu *menu G_GNUC_UNUSED,
|
|||
int *x, int *y, gboolean *push_in,
|
||||
gpointer user_data)
|
||||
{
|
||||
int screen_w, screen_h, button_x, button_y, panel_w, panel_h;
|
||||
gint screen_w, screen_h, button_x, button_y, panel_w, panel_h;
|
||||
GtkRequisition requisition;
|
||||
GdkScreen *screen;
|
||||
PandoraApplet *applet = (PandoraApplet *)user_data;
|
||||
GdkScreen *screen;
|
||||
PandoraApplet *applet = PANDORA_APPLET (user_data);
|
||||
|
||||
screen = gtk_widget_get_screen (applet->priv->event_box);
|
||||
screen_w = gdk_screen_get_width (screen);
|
||||
|
@ -412,7 +390,6 @@ pandora_applet_toplevel_menu_button_press_cb (GtkWidget *widget,
|
|||
GdkEventButton *event,
|
||||
gpointer data)
|
||||
{
|
||||
|
||||
PandoraApplet *applet;
|
||||
|
||||
applet = PANDORA_APPLET (data);
|
||||
|
@ -435,11 +412,6 @@ pandora_applet_toplevel_menu_button_press_cb (GtkWidget *widget,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
pandora_applet_setup_widgets (PandoraApplet *applet)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
pandora_applet_set_image_from_stock (PandoraApplet *applet,
|
||||
gchar *stock_id)
|
||||
|
|
|
@ -71,16 +71,25 @@ static gboolean pandora_info_window_delete_cb (GtkWidget *dialog,
|
|||
static gboolean pandora_info_window_close_cb (GtkWidget *widget,
|
||||
gpointer data);
|
||||
|
||||
static void pandora_info_window_status_changed_cb (GObject *object,
|
||||
gpointer data);
|
||||
static void pandora_info_window_alerts_changed_cb (GObject *object,
|
||||
gint data,
|
||||
gpointer user_data);
|
||||
|
||||
static void pandora_info_window_status_update (PandoraInfoWindow *window);
|
||||
static void pandora_info_window_agents_changed_cb (GObject *object,
|
||||
gint data,
|
||||
gpointer user_data);
|
||||
|
||||
static void pandora_info_window_status_update_alerts (PandoraInfoWindow *window,
|
||||
static void pandora_info_window_servers_changed_cb (GObject *object,
|
||||
gint data,
|
||||
gpointer user_data);
|
||||
|
||||
static void pandora_info_window_status_update_all (PandoraInfoWindow *window);
|
||||
|
||||
static void pandora_info_window_status_update_alerts (PandoraInfoWindow *window,
|
||||
PandoraState state);
|
||||
static void pandora_info_window_status_update_agents (PandoraInfoWindow *window,
|
||||
static void pandora_info_window_status_update_agents (PandoraInfoWindow *window,
|
||||
PandoraState state);
|
||||
static void pandora_info_window_status_update_servers (PandoraInfoWindow *window,
|
||||
static void pandora_info_window_status_update_servers (PandoraInfoWindow *window,
|
||||
PandoraState state);
|
||||
|
||||
GType
|
||||
|
@ -159,7 +168,7 @@ pandora_info_window_init (PandoraInfoWindow *window)
|
|||
gtk_table_attach (GTK_TABLE (table), window->priv->label_alerts,
|
||||
1, 2, 0, 1, GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
|
||||
|
||||
/* Third row */
|
||||
/* Second row */
|
||||
window->priv->label_agents = gtk_label_new (_("Agents status."));
|
||||
gtk_misc_set_alignment (GTK_MISC (window->priv->label_agents), 0, 0.5);
|
||||
|
||||
|
@ -171,7 +180,7 @@ pandora_info_window_init (PandoraInfoWindow *window)
|
|||
gtk_table_attach (GTK_TABLE (table), window->priv->label_agents,
|
||||
1, 2, 1, 2, GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
|
||||
|
||||
/* Second row */
|
||||
/* Third row */
|
||||
window->priv->label_servers = gtk_label_new (_("Servers status."));
|
||||
gtk_misc_set_alignment (GTK_MISC (window->priv->label_servers), 0, 0.5);
|
||||
|
||||
|
@ -262,7 +271,8 @@ pandora_info_window_new (void)
|
|||
}
|
||||
|
||||
static gboolean
|
||||
pandora_info_window_close_cb (GtkWidget *widget, gpointer data)
|
||||
pandora_info_window_close_cb (GtkWidget *widget,
|
||||
gpointer data)
|
||||
{
|
||||
GtkWidget *window;
|
||||
|
||||
|
@ -275,7 +285,9 @@ pandora_info_window_close_cb (GtkWidget *widget, gpointer data)
|
|||
}
|
||||
|
||||
static gboolean
|
||||
pandora_info_window_delete_cb (GtkWidget *widget, GdkEvent *event, gpointer data)
|
||||
pandora_info_window_delete_cb (GtkWidget *widget,
|
||||
GdkEvent *event,
|
||||
gpointer data)
|
||||
{
|
||||
gtk_widget_hide (widget);
|
||||
|
||||
|
@ -284,7 +296,7 @@ pandora_info_window_delete_cb (GtkWidget *widget, GdkEvent *event, gpointer data
|
|||
|
||||
void
|
||||
pandora_info_window_set_status (PandoraInfoWindow *window,
|
||||
PandoraStatus *status)
|
||||
PandoraStatus *status)
|
||||
{
|
||||
if (window->priv->status) {
|
||||
g_object_unref (window->priv->status);
|
||||
|
@ -292,16 +304,22 @@ pandora_info_window_set_status (PandoraInfoWindow *window,
|
|||
|
||||
window->priv->status = status;
|
||||
|
||||
g_signal_connect (status, "changed",
|
||||
G_CALLBACK (pandora_info_window_status_changed_cb),
|
||||
g_signal_connect (status, "changed_alerts",
|
||||
G_CALLBACK (pandora_info_window_alerts_changed_cb),
|
||||
(gpointer) window);
|
||||
g_signal_connect (status, "changed_agents",
|
||||
G_CALLBACK (pandora_info_window_agents_changed_cb),
|
||||
(gpointer) window);
|
||||
g_signal_connect (status, "changed_servers",
|
||||
G_CALLBACK (pandora_info_window_servers_changed_cb),
|
||||
(gpointer) window);
|
||||
|
||||
pandora_info_window_status_update (window);
|
||||
pandora_info_window_status_update_all (window);
|
||||
}
|
||||
|
||||
static void
|
||||
pandora_info_window_status_update_alerts (PandoraInfoWindow *window,
|
||||
PandoraState state)
|
||||
PandoraState state)
|
||||
{
|
||||
switch (state) {
|
||||
case STATE_BAD:
|
||||
|
@ -328,7 +346,7 @@ pandora_info_window_status_update_alerts (PandoraInfoWindow *window,
|
|||
|
||||
static void
|
||||
pandora_info_window_status_update_agents (PandoraInfoWindow *window,
|
||||
PandoraState state)
|
||||
PandoraState state)
|
||||
{
|
||||
switch (state) {
|
||||
case STATE_BAD:
|
||||
|
@ -355,7 +373,7 @@ pandora_info_window_status_update_agents (PandoraInfoWindow *window,
|
|||
|
||||
static void
|
||||
pandora_info_window_status_update_servers (PandoraInfoWindow *window,
|
||||
PandoraState state)
|
||||
PandoraState state)
|
||||
{
|
||||
switch (state) {
|
||||
case STATE_BAD:
|
||||
|
@ -381,34 +399,55 @@ pandora_info_window_status_update_servers (PandoraInfoWindow *window,
|
|||
}
|
||||
|
||||
static void
|
||||
pandora_info_window_status_update (PandoraInfoWindow *window)
|
||||
pandora_info_window_status_update_all (PandoraInfoWindow *window)
|
||||
{
|
||||
PandoraStatus *status;
|
||||
PandoraState state;
|
||||
PandoraState state;
|
||||
|
||||
status = window->priv->status;
|
||||
|
||||
if (status == NULL) {
|
||||
if (window->priv->status == NULL) {
|
||||
pandora_info_window_status_update_alerts (window, TRUE);
|
||||
pandora_info_window_status_update_agents (window, TRUE);
|
||||
pandora_info_window_status_update_servers (window, TRUE);
|
||||
} else {
|
||||
state = pandora_status_get_alerts (status);
|
||||
state = pandora_status_get_alerts (window->priv->status);
|
||||
pandora_info_window_status_update_alerts (window, state);
|
||||
|
||||
state = pandora_status_get_agents (status);
|
||||
state = pandora_status_get_agents (window->priv->status);
|
||||
pandora_info_window_status_update_agents (window, state);
|
||||
|
||||
state = pandora_status_get_servers (status);
|
||||
state = pandora_status_get_servers (window->priv->status);
|
||||
pandora_info_window_status_update_servers (window, state);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
pandora_info_window_status_changed_cb (GObject *object,
|
||||
gpointer data)
|
||||
pandora_info_window_alerts_changed_cb (GObject *object,
|
||||
gint data,
|
||||
gpointer user_data)
|
||||
{
|
||||
PandoraInfoWindow *window = PANDORA_INFO_WINDOW (data);
|
||||
PandoraState state = data;
|
||||
PandoraInfoWindow *window = PANDORA_INFO_WINDOW (user_data);
|
||||
|
||||
pandora_info_window_status_update (window);
|
||||
pandora_info_window_status_update_alerts (window, state);
|
||||
}
|
||||
|
||||
static void
|
||||
pandora_info_window_agents_changed_cb (GObject *object,
|
||||
gint data,
|
||||
gpointer user_data)
|
||||
{
|
||||
PandoraState state = data;
|
||||
PandoraInfoWindow *window = PANDORA_INFO_WINDOW (user_data);
|
||||
|
||||
pandora_info_window_status_update_agents (window, state);
|
||||
}
|
||||
|
||||
static void
|
||||
pandora_info_window_servers_changed_cb (GObject *object,
|
||||
gint data,
|
||||
gpointer user_data)
|
||||
{
|
||||
PandoraState state = data;
|
||||
PandoraInfoWindow *window = PANDORA_INFO_WINDOW (user_data);
|
||||
|
||||
pandora_info_window_status_update_servers (window, state);
|
||||
}
|
||||
|
|
|
@ -50,16 +50,16 @@ struct _PandoraStatusCheckerPrivate {
|
|||
(G_TYPE_INSTANCE_GET_PRIVATE ((object), PANDORA_STATUS_CHECKER_TYPE, \
|
||||
PandoraStatusCheckerPrivate))
|
||||
|
||||
static gboolean pandora_status_checker_connect (PandoraStatusChecker *checker);
|
||||
static gboolean pandora_status_checker_disconnect (PandoraStatusChecker *checker);
|
||||
static gboolean pandora_status_checker_connect (PandoraStatusChecker *checker);
|
||||
static gboolean pandora_status_checker_disconnect (PandoraStatusChecker *checker);
|
||||
|
||||
static PandoraState pandora_status_checker_check_alerts (PandoraStatusChecker *checker);
|
||||
static PandoraState pandora_status_checker_check_servers (PandoraStatusChecker *checker);
|
||||
static PandoraState pandora_status_checker_check_agents (PandoraStatusChecker *checker);
|
||||
|
||||
static void pandora_status_checker_init (PandoraStatusChecker *checker);
|
||||
static void pandora_status_checker_class_init (PandoraStatusCheckerClass *klass);
|
||||
static void pandora_status_checker_finalize (GObject *object);
|
||||
static void pandora_status_checker_init (PandoraStatusChecker *checker);
|
||||
static void pandora_status_checker_class_init (PandoraStatusCheckerClass *klass);
|
||||
static void pandora_status_checker_finalize (GObject *object);
|
||||
|
||||
static gpointer pandora_status_checker_run_thread (gpointer data);
|
||||
|
||||
|
@ -135,7 +135,6 @@ pandora_status_checker_finalize (GObject *object)
|
|||
checker->priv->status = NULL;
|
||||
}
|
||||
|
||||
|
||||
if (checker->priv->state_mutex) {
|
||||
g_mutex_free (checker->priv->state_mutex);
|
||||
checker->priv->state_mutex = NULL;
|
||||
|
@ -192,7 +191,7 @@ pandora_status_checker_connect (PandoraStatusChecker *checker)
|
|||
password, dbname, 3306, NULL, 0) == NULL)
|
||||
{
|
||||
|
||||
g_print ("mysql_real_connect() failed. %s\n",
|
||||
g_print ("SQL connection failed. %s\n",
|
||||
mysql_error (checker->priv->connection));
|
||||
mysql_close (checker->priv->connection);
|
||||
checker->priv->connection = NULL;
|
||||
|
@ -232,7 +231,7 @@ pandora_status_checker_check_agents (PandoraStatusChecker *checker)
|
|||
"WHERE estado != 100 and datos = 0.0";
|
||||
|
||||
if (checker->priv->connection == NULL) {
|
||||
return FALSE;
|
||||
return STATE_UNKNOWN;
|
||||
}
|
||||
|
||||
if (mysql_query (checker->priv->connection, query_time) != 0) {
|
||||
|
@ -272,7 +271,7 @@ pandora_status_checker_check_servers (PandoraStatusChecker *checker)
|
|||
"WHERE status = 0";
|
||||
|
||||
if (checker->priv->connection == NULL) {
|
||||
return FALSE;
|
||||
return STATE_UNKNOWN;
|
||||
}
|
||||
|
||||
if (mysql_query (checker->priv->connection, query) != 0) {
|
||||
|
@ -305,7 +304,7 @@ pandora_status_checker_check_alerts (PandoraStatusChecker *checker)
|
|||
gchar *query;
|
||||
|
||||
if (checker->priv->connection == NULL) {
|
||||
return FALSE;
|
||||
return STATE_UNKNOWN;
|
||||
}
|
||||
|
||||
if (mysql_query (checker->priv->connection, query_all_agents) != 0) {
|
||||
|
@ -377,17 +376,22 @@ pandora_status_checker_run_thread (gpointer data)
|
|||
while (checker->priv->state == CHECKER_STATE_RUNNING) {
|
||||
g_mutex_unlock (checker->priv->state_mutex);
|
||||
|
||||
pandora_status_checker_connect (checker);
|
||||
if (pandora_status_checker_connect (checker)) {
|
||||
|
||||
alerts = pandora_status_checker_check_alerts (checker);
|
||||
servers = pandora_status_checker_check_servers (checker);
|
||||
agents = pandora_status_checker_check_agents (checker);
|
||||
alerts = pandora_status_checker_check_alerts (checker);
|
||||
servers = pandora_status_checker_check_servers (checker);
|
||||
agents = pandora_status_checker_check_agents (checker);
|
||||
|
||||
pandora_status_set_alerts (checker->priv->status, alerts);
|
||||
pandora_status_set_servers (checker->priv->status, servers);
|
||||
pandora_status_set_agents (checker->priv->status, agents);
|
||||
pandora_status_set_all (checker->priv->status,
|
||||
alerts, agents, servers);
|
||||
|
||||
pandora_status_checker_disconnect (checker);
|
||||
pandora_status_checker_disconnect (checker);
|
||||
} else {
|
||||
pandora_status_set_all (checker->priv->status,
|
||||
STATE_UNKNOWN,
|
||||
STATE_UNKNOWN,
|
||||
STATE_UNKNOWN);
|
||||
}
|
||||
|
||||
g_usleep (G_USEC_PER_SEC * 10);
|
||||
|
||||
|
|
|
@ -27,7 +27,11 @@
|
|||
#include "pandora-status.h"
|
||||
|
||||
enum {
|
||||
CHANGED,
|
||||
NONE,
|
||||
INCIDENCE,
|
||||
CHANGED_ALERTS,
|
||||
CHANGED_AGENTS,
|
||||
CHANGED_SERVERS,
|
||||
N_SIGNALS
|
||||
};
|
||||
|
||||
|
@ -45,9 +49,9 @@ static guint pandora_status_signals[N_SIGNALS];
|
|||
(G_TYPE_INSTANCE_GET_PRIVATE ((object), PANDORA_STATUS_TYPE, \
|
||||
PandoraStatusPrivate))
|
||||
|
||||
static void pandora_status_init (PandoraStatus *status);
|
||||
static void pandora_status_class_init (PandoraStatusClass *klass);
|
||||
static void pandora_status_finalize (GObject *object);
|
||||
static void pandora_status_init (PandoraStatus *status);
|
||||
static void pandora_status_class_init (PandoraStatusClass *klass);
|
||||
static void pandora_status_finalize (GObject *object);
|
||||
|
||||
GType
|
||||
pandora_status_get_type (void)
|
||||
|
@ -85,7 +89,6 @@ pandora_status_init (PandoraStatus *status)
|
|||
status->priv->mutex = g_mutex_new ();
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
pandora_status_class_init (PandoraStatusClass *klass)
|
||||
{
|
||||
|
@ -96,14 +99,41 @@ pandora_status_class_init (PandoraStatusClass *klass)
|
|||
object_class = G_OBJECT_CLASS (klass);
|
||||
object_class->finalize = pandora_status_finalize;
|
||||
|
||||
pandora_status_signals[CHANGED] =
|
||||
g_signal_new ("changed",
|
||||
pandora_status_signals[INCIDENCE] =
|
||||
g_signal_new ("incidence",
|
||||
G_TYPE_FROM_CLASS (object_class),
|
||||
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
||||
G_STRUCT_OFFSET (PandoraStatusClass, changed),
|
||||
NULL, NULL,
|
||||
g_cclosure_marshal_VOID__VOID,
|
||||
G_TYPE_NONE, 0);
|
||||
g_cclosure_marshal_VOID__INT,
|
||||
G_TYPE_NONE, 1, G_TYPE_INT);
|
||||
|
||||
pandora_status_signals[CHANGED_ALERTS] =
|
||||
g_signal_new ("changed_alerts",
|
||||
G_TYPE_FROM_CLASS (object_class),
|
||||
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
||||
G_STRUCT_OFFSET (PandoraStatusClass, changed),
|
||||
NULL, NULL,
|
||||
g_cclosure_marshal_VOID__INT,
|
||||
G_TYPE_NONE, 1, G_TYPE_INT);
|
||||
|
||||
pandora_status_signals[CHANGED_AGENTS] =
|
||||
g_signal_new ("changed_agents",
|
||||
G_TYPE_FROM_CLASS (object_class),
|
||||
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
||||
G_STRUCT_OFFSET (PandoraStatusClass, changed),
|
||||
NULL, NULL,
|
||||
g_cclosure_marshal_VOID__INT,
|
||||
G_TYPE_NONE, 1, G_TYPE_INT);
|
||||
|
||||
pandora_status_signals[CHANGED_SERVERS] =
|
||||
g_signal_new ("changed_servers",
|
||||
G_TYPE_FROM_CLASS (object_class),
|
||||
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
||||
G_STRUCT_OFFSET (PandoraStatusClass, changed),
|
||||
NULL, NULL,
|
||||
g_cclosure_marshal_VOID__INT,
|
||||
G_TYPE_NONE, 1, G_TYPE_INT);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -131,54 +161,55 @@ pandora_status_new (void)
|
|||
}
|
||||
|
||||
void
|
||||
pandora_status_set_alerts (PandoraStatus *status, PandoraState value)
|
||||
pandora_status_set_all (PandoraStatus *status,
|
||||
PandoraState alerts,
|
||||
PandoraState agents,
|
||||
PandoraState servers)
|
||||
{
|
||||
PandoraState incidence = STATE_INVALID;
|
||||
|
||||
g_return_if_fail (PANDORA_IS_STATUS (status));
|
||||
|
||||
g_mutex_lock (status->priv->mutex);
|
||||
|
||||
if (status->priv->alerts != value) {
|
||||
status->priv->alerts = value;
|
||||
g_mutex_unlock (status->priv->mutex);
|
||||
if (status->priv->alerts != alerts) {
|
||||
status->priv->alerts = alerts;
|
||||
|
||||
g_signal_emit (status, pandora_status_signals[CHANGED], 0);
|
||||
} else {
|
||||
g_mutex_unlock (status->priv->mutex);
|
||||
g_signal_emit (status, pandora_status_signals[CHANGED_ALERTS],
|
||||
0, alerts);
|
||||
|
||||
incidence = alerts;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
pandora_status_set_agents (PandoraStatus *status, PandoraState value)
|
||||
{
|
||||
g_return_if_fail (PANDORA_IS_STATUS (status));
|
||||
if (status->priv->agents != agents) {
|
||||
status->priv->agents = agents;
|
||||
|
||||
g_mutex_lock (status->priv->mutex);
|
||||
g_signal_emit (status, pandora_status_signals[CHANGED_AGENTS],
|
||||
0, agents);
|
||||
|
||||
if (status->priv->agents != value) {
|
||||
status->priv->agents = value;
|
||||
g_mutex_unlock (status->priv->mutex);
|
||||
|
||||
g_signal_emit (status, pandora_status_signals[CHANGED], 0);
|
||||
} else {
|
||||
g_mutex_unlock (status->priv->mutex);
|
||||
/* Change value if it was invalid or OK, so
|
||||
* "incidence" signal will be emmited only if there
|
||||
* are any bad value or all are ok. */
|
||||
if (incidence == STATE_INVALID || incidence == STATE_OK)
|
||||
incidence = agents;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
pandora_status_set_servers (PandoraStatus *status, PandoraState value)
|
||||
{
|
||||
g_return_if_fail (PANDORA_IS_STATUS (status));
|
||||
if (status->priv->servers != servers) {
|
||||
status->priv->servers = servers;
|
||||
|
||||
g_mutex_lock (status->priv->mutex);
|
||||
g_signal_emit (status, pandora_status_signals[CHANGED_SERVERS],
|
||||
0, servers);
|
||||
|
||||
if (status->priv->servers != value) {
|
||||
status->priv->servers = value;
|
||||
g_mutex_unlock (status->priv->mutex);
|
||||
|
||||
g_signal_emit (status, pandora_status_signals[CHANGED], 0);
|
||||
} else {
|
||||
g_mutex_unlock (status->priv->mutex);
|
||||
if (incidence == STATE_INVALID || incidence == STATE_OK)
|
||||
incidence = agents;
|
||||
}
|
||||
|
||||
/* Emit incidence_any signal if necessary */
|
||||
if (incidence != STATE_INVALID)
|
||||
g_signal_emit (status, pandora_status_signals[INCIDENCE],
|
||||
0, incidence);
|
||||
|
||||
g_mutex_unlock (status->priv->mutex);
|
||||
}
|
||||
|
||||
PandoraState
|
||||
|
|
|
@ -27,10 +27,10 @@
|
|||
#include <glib-object.h>
|
||||
|
||||
typedef enum {
|
||||
STATE_INVALID,
|
||||
STATE_UNKNOWN,
|
||||
STATE_OK,
|
||||
STATE_BAD
|
||||
STATE_INVALID = 0,
|
||||
STATE_UNKNOWN = 1,
|
||||
STATE_OK = 2,
|
||||
STATE_BAD = 3
|
||||
} PandoraState;
|
||||
|
||||
#define PANDORA_STATUS_TYPE (pandora_status_get_type())
|
||||
|
@ -55,9 +55,10 @@ typedef struct {
|
|||
} PandoraStatusClass;
|
||||
|
||||
PandoraStatus *pandora_status_new (void);
|
||||
void pandora_status_set_alerts (PandoraStatus *status, PandoraState value);
|
||||
void pandora_status_set_agents (PandoraStatus *status, PandoraState value);
|
||||
void pandora_status_set_servers (PandoraStatus *status, PandoraState value);
|
||||
void pandora_status_set_all (PandoraStatus *status,
|
||||
PandoraState alerts,
|
||||
PandoraState agents,
|
||||
PandoraState servers);
|
||||
|
||||
PandoraState pandora_status_get_alerts (PandoraStatus *status);
|
||||
PandoraState pandora_status_get_agents (PandoraStatus *status);
|
||||
|
|
Loading…
Reference in New Issue