From eaab351bbd451c0c69b02d465a574baa4dbcd33f Mon Sep 17 00:00:00 2001 From: esanchezm Date: Mon, 18 Sep 2006 11:26:39 +0000 Subject: [PATCH] 2006-08-31 Esteban Sanchez * data/pandora-applet-*.png: Updated and changed its colors. * src/pandora-applet.c: Restart the status checker when the settings are updated. * src/pandora-setup-dialog.c, src/pandora-setup.c: Memory leaks fixed. * src/pandora-status-checker.h: Enumerator moved to source file. * src/pandora-status-checker.c: The stop function now works. Memory leaks fixed. Code cleanup. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@174 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_applet/ChangeLog | 14 +++ pandora_applet/data/pandora-applet-bad.png | Bin 960 -> 957 bytes pandora_applet/data/pandora-applet-good.png | Bin 968 -> 964 bytes .../data/pandora-applet-unknown.png | Bin 964 -> 954 bytes pandora_applet/src/pandora-applet.c | 3 + pandora_applet/src/pandora-setup-dialog.c | 1 + pandora_applet/src/pandora-setup.c | 3 + pandora_applet/src/pandora-status-checker.c | 104 ++++++++++-------- pandora_applet/src/pandora-status-checker.h | 8 -- 9 files changed, 82 insertions(+), 51 deletions(-) diff --git a/pandora_applet/ChangeLog b/pandora_applet/ChangeLog index 54a57c7789..a32a59532d 100644 --- a/pandora_applet/ChangeLog +++ b/pandora_applet/ChangeLog @@ -1,3 +1,17 @@ +2006-08-31 Esteban Sanchez + + * data/pandora-applet-*.png: Updated and changed its colors. + + * src/pandora-applet.c: Restart the status checker when the settings + are updated. + + * src/pandora-setup-dialog.c, src/pandora-setup.c: Memory leaks fixed. + + * src/pandora-status-checker.h: Enumerator moved to source file. + + * src/pandora-status-checker.c: The stop function now works. Memory + leaks fixed. Code cleanup. + 2006-08-31 Esteban Sanchez * Initial import. diff --git a/pandora_applet/data/pandora-applet-bad.png b/pandora_applet/data/pandora-applet-bad.png index 2464dfc845678cc7047ab6cc9fb7508715226985..5028efdbd8628f473833df18ca220c723ec6b602 100644 GIT binary patch delta 83 zcmX@WzL$N13hT!JpAgrLIv<%>f(vddOjcyJQV`;1l==5ZOM-!c!PV2nF@)oKZr?>g n1_Ksn-ZbaOsS77pGaHI;~3dffKpAgso|I;>Veq>^q7wEZrvK+IO0xy@P!uc)7XE87^xO%!chHzZZ q?Yk(*V8G(6nHk2gC=EBn9_SOjJd&EcXH)pgz6000001bW%=J06^y0W&i*H0b)x>L;#2d z9Y~Wj10ZG+3O6WMmL=~1002fwL_t&t*KLl`5dbg*L+w9=t+It7s^L=Y^?k|1VMdUc z$l!?#(=f_y;1QSkit*EFb55d_>PJ!~g&Q07*qo IM6N<$f+IjZy#N3J delta 158 zcmV;P0Ac^c2gnDIBnbLYOjJex|NpTm_W}`a@@~R7pfZR0!8?&d~~hFbD-u|NjH;{R%@i2!b9mXUj$RNzW7~5`jl%ylLb< z1RLmdO=3=lgsE^yCmUZec&G#&}O00{P)F0;xy3IG5A M07*qoM6N<$g47{C`~Uy| diff --git a/pandora_applet/data/pandora-applet-unknown.png b/pandora_applet/data/pandora-applet-unknown.png index 50ce56618debb655091ebf05cbfebc88fb89b1a2..c130581ca1744018665c8324509b9cc5c9f15fe4 100644 GIT binary patch delta 91 zcmX@YzKeZ=3hTQ7pAgrLM(>zdEF6CbPgY^J(h%Zi61mOw@g)NTgR7^DV+hCf+`fx~ v3)u_^8X1fV{>xRV~5@ z07gkfK~xCWZH~bW03Zkh*?<@OPt|?ILMj^XMGpv*eFG^JUzIALBOE#V00000NkvXX Hu0mjfG2A6$ diff --git a/pandora_applet/src/pandora-applet.c b/pandora_applet/src/pandora-applet.c index 6c71bafe70..d4934ca3cb 100644 --- a/pandora_applet/src/pandora-applet.c +++ b/pandora_applet/src/pandora-applet.c @@ -261,6 +261,9 @@ pandora_applet_show_setup_cb (GtkMenuItem *mi, PandoraApplet *applet) case GTK_RESPONSE_ACCEPT: pandora_setup_dialog_apply_changes (applet->priv->setup_dialog); pandora_setup_save_to_disk (applet->priv->setup); + + pandora_status_checker_stop (applet->priv->checker); + pandora_status_checker_run (applet->priv->checker); break; default: break; diff --git a/pandora_applet/src/pandora-setup-dialog.c b/pandora_applet/src/pandora-setup-dialog.c index 3582b78cca..9617b05778 100644 --- a/pandora_applet/src/pandora-setup-dialog.c +++ b/pandora_applet/src/pandora-setup-dialog.c @@ -107,6 +107,7 @@ pandora_setup_dialog_init (PandoraSetupDialog *dialog) str = g_strdup_printf ("%s:", _("Database connection")); label_title = gtk_label_new (NULL); gtk_label_set_markup (GTK_LABEL (label_title), str); + g_free (str); gtk_misc_set_alignment (GTK_MISC (label_title), 0, 0.5); frame = gtk_frame_new (NULL); diff --git a/pandora_applet/src/pandora-setup.c b/pandora_applet/src/pandora-setup.c index f1509c2235..d005446ae7 100644 --- a/pandora_applet/src/pandora-setup.c +++ b/pandora_applet/src/pandora-setup.c @@ -349,6 +349,7 @@ pandora_setup_read_config_file (PandoraSetup *setup, gchar *file) root = xmlDocGetRootElement (doc); if (!root) { + xmlFreeDoc (doc); return; } @@ -370,6 +371,8 @@ pandora_setup_read_config_file (PandoraSetup *setup, gchar *file) g_free (password); g_free (dbname); } + + xmlFreeDoc (doc); } void diff --git a/pandora_applet/src/pandora-status-checker.c b/pandora_applet/src/pandora-status-checker.c index ebd610aa46..c121cd0f0b 100644 --- a/pandora_applet/src/pandora-status-checker.c +++ b/pandora_applet/src/pandora-status-checker.c @@ -26,6 +26,14 @@ #include "pandora-status-checker.h" +enum { + CHECKER_STATE_READY, + CHECKER_STATE_RUNNING, + CHECKER_STATE_FINISHED, + CHECKER_STATE_STOPPING, + CHECKER_STATE_FAILED +}; + struct _PandoraStatusCheckerPrivate { GThread *thread; GMutex *state_mutex; @@ -163,39 +171,40 @@ pandora_status_checker_new (PandoraSetup *setup, PandoraStatus *status) static gboolean pandora_status_checker_connect (PandoraStatusChecker *checker) { - MYSQL *connection; - PandoraSetup *setup; gchar *host, *username, *password, *dbname; gboolean retval = TRUE; - - connection = checker->priv->connection; - setup = checker->priv->setup; - if (connection) { - mysql_close (connection); + if (checker->priv->connection != NULL) { + mysql_close (checker->priv->connection); + checker->priv->connection = NULL; } - connection = mysql_init (NULL); + checker->priv->connection = mysql_init (NULL); - if (connection == NULL) { + if (checker->priv->connection == NULL) { return FALSE; } - g_object_get (G_OBJECT (setup), "host", &host, "username", &username, + g_object_get (G_OBJECT (checker->priv->setup), "host", &host, "username", &username, "password", &password, "dbname", &dbname, NULL); - if (mysql_real_connect (connection, host, username, + if (mysql_real_connect (checker->priv->connection, host, username, password, dbname, 3306, NULL, 0) == NULL) { g_print ("mysql_real_connect() failed. %s\n", - mysql_error (connection)); - mysql_close (connection); - + mysql_error (checker->priv->connection)); + mysql_close (checker->priv->connection); + checker->priv->connection = NULL; + retval = FALSE; } - checker->priv->connection = connection; + g_free (host); + g_free (username); + g_free (password); + g_free (dbname); + return retval; } @@ -212,7 +221,6 @@ pandora_status_checker_disconnect (PandoraStatusChecker *checker) static PandoraState pandora_status_checker_check_agents (PandoraStatusChecker *checker) { - MYSQL *connection = NULL; MYSQL_RES *result; MYSQL_ROW row; const gchar const *query_time = "SELECT * FROM tagente " @@ -222,28 +230,32 @@ pandora_status_checker_check_agents (PandoraStatusChecker *checker) "LEFT JOIN tagente " "ON tagente_estado.id_agente = tagente.id_agente " "WHERE estado != 100 and datos = 0.0"; - connection = checker->priv->connection; - g_return_val_if_fail (connection != NULL, FALSE); - if (mysql_query (connection, query_time) != 0) { + if (checker->priv->connection == NULL) { + return FALSE; + } + + if (mysql_query (checker->priv->connection, query_time) != 0) { return STATE_UNKNOWN; } - result = mysql_store_result (connection); + result = mysql_store_result (checker->priv->connection); if (mysql_num_rows (result) > 0) { + mysql_free_result (result); return STATE_BAD; } mysql_free_result (result); - if (mysql_query (connection, query_status) != 0) { + if (mysql_query (checker->priv->connection, query_status) != 0) { return STATE_UNKNOWN; } - result = mysql_store_result (connection); + result = mysql_store_result (checker->priv->connection); if (mysql_num_rows (result) > 0) { + mysql_free_result (result); return STATE_BAD; } @@ -254,23 +266,25 @@ pandora_status_checker_check_agents (PandoraStatusChecker *checker) static PandoraState pandora_status_checker_check_servers (PandoraStatusChecker *checker) { - MYSQL *connection = NULL; MYSQL_RES *result; MYSQL_ROW row; const gchar const *query = "SELECT * FROM tserver " "WHERE status = 0"; - connection = checker->priv->connection; - g_return_val_if_fail (connection != NULL, FALSE); - - if (mysql_query (connection, query) != 0) { + if (checker->priv->connection == NULL) { + return FALSE; + } + + if (mysql_query (checker->priv->connection, query) != 0) { return STATE_UNKNOWN; } - result = mysql_store_result (connection); + result = mysql_store_result (checker->priv->connection); - if (mysql_num_rows (result) > 0) + if (mysql_num_rows (result) > 0) { + mysql_free_result (result); return STATE_BAD; + } mysql_free_result (result); return STATE_OK; @@ -279,7 +293,6 @@ pandora_status_checker_check_servers (PandoraStatusChecker *checker) static PandoraState pandora_status_checker_check_alerts (PandoraStatusChecker *checker) { - MYSQL *connection = NULL; MYSQL_RES *result1 = NULL, *result2 = NULL, *result3 = NULL; MYSQL_ROW row; const gchar const *query_all_agents = "SELECT * FROM tagente " @@ -291,14 +304,15 @@ pandora_status_checker_check_alerts (PandoraStatusChecker *checker) "AND times_fired > 0"; gchar *query; - connection = checker->priv->connection; - g_return_val_if_fail (connection != NULL, FALSE); + if (checker->priv->connection == NULL) { + return FALSE; + } - if (mysql_query (connection, query_all_agents) != 0) { + if (mysql_query (checker->priv->connection, query_all_agents) != 0) { return STATE_UNKNOWN; } - result1 = mysql_store_result (connection); + result1 = mysql_store_result (checker->priv->connection); if (result1 == NULL) return STATE_UNKNOWN; @@ -308,8 +322,8 @@ pandora_status_checker_check_alerts (PandoraStatusChecker *checker) while (row = mysql_fetch_row (result1)) { query = g_strdup_printf (query_agent_state, row[0]); - if (mysql_query (connection, query) == 0) { - result2 = mysql_store_result (connection); + if (mysql_query (checker->priv->connection, query) == 0) { + result2 = mysql_store_result (checker->priv->connection); if (mysql_num_rows (result2) > 0) { @@ -319,8 +333,8 @@ pandora_status_checker_check_alerts (PandoraStatusChecker *checker) query = g_strdup_printf (query_agent_alert, row[1]); - if (mysql_query (connection, query) == 0) { - result3 = mysql_store_result (connection); + if (mysql_query (checker->priv->connection, query) == 0) { + result3 = mysql_store_result (checker->priv->connection); if (mysql_num_rows (result3) > 0) { mysql_free_result (result1); @@ -361,10 +375,7 @@ pandora_status_checker_run_thread (gpointer data) while (checker->priv->state == CHECKER_STATE_RUNNING) { g_mutex_unlock (checker->priv->state_mutex); - if (!pandora_status_checker_connect (checker)) { - pandora_status_checker_stop (checker); - return NULL; - } + pandora_status_checker_connect (checker); alerts = pandora_status_checker_check_alerts (checker); servers = pandora_status_checker_check_servers (checker); @@ -389,6 +400,13 @@ pandora_status_checker_run_thread (gpointer data) void pandora_status_checker_run (PandoraStatusChecker *checker) { + g_mutex_lock (checker->priv->state_mutex); + if (checker->priv->state == CHECKER_STATE_RUNNING) { + g_mutex_unlock (checker->priv->state_mutex); + return; + } + g_mutex_unlock (checker->priv->state_mutex); + checker->priv->thread = g_thread_create (pandora_status_checker_run_thread, (gpointer) checker, TRUE, NULL); } @@ -397,6 +415,6 @@ void pandora_status_checker_stop (PandoraStatusChecker *checker) { g_mutex_lock (checker->priv->state_mutex); - checker->priv->state = CHECKER_STATE_RUNNING; + checker->priv->state = CHECKER_STATE_STOPPING; g_mutex_unlock (checker->priv->state_mutex); } diff --git a/pandora_applet/src/pandora-status-checker.h b/pandora_applet/src/pandora-status-checker.h index d715524f74..1779bced81 100644 --- a/pandora_applet/src/pandora-status-checker.h +++ b/pandora_applet/src/pandora-status-checker.h @@ -29,14 +29,6 @@ #include "pandora-setup.h" #include "pandora-status.h" -enum { - CHECKER_STATE_READY, - CHECKER_STATE_RUNNING, - CHECKER_STATE_FINISHED, - CHECKER_STATE_STOPPING, - CHECKER_STATE_FAILED -}; - #define PANDORA_STATUS_CHECKER_TYPE (pandora_status_checker_get_type()) #define PANDORA_STATUS_CHECKER(object) (G_TYPE_CHECK_INSTANCE_CAST((object), PANDORA_STATUS_CHECKER_TYPE, PandoraStatusChecker)) #define PANDORA_STATUS_CHECKER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PANDORA_STATUS_CHECKER_TYPE, PandoraStatusCheckerClass))