2006-08-31 Esteban Sanchez <estebans@artica.es>

* 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
This commit is contained in:
esanchezm 2006-09-18 11:26:39 +00:00
parent 37c50c6777
commit eaab351bbd
9 changed files with 82 additions and 51 deletions

View File

@ -1,3 +1,17 @@
2006-08-31 Esteban Sanchez <estebans@artica.es>
* 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 <estebans@artica.es>
* Initial import.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 960 B

After

Width:  |  Height:  |  Size: 957 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 968 B

After

Width:  |  Height:  |  Size: 964 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 964 B

After

Width:  |  Height:  |  Size: 954 B

View File

@ -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;

View File

@ -107,6 +107,7 @@ pandora_setup_dialog_init (PandoraSetupDialog *dialog)
str = g_strdup_printf ("<b>%s:</b>", _("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);

View File

@ -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

View File

@ -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);
}

View File

@ -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))