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:
parent
37c50c6777
commit
eaab351bbd
|
@ -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>
|
2006-08-31 Esteban Sanchez <estebans@artica.es>
|
||||||
|
|
||||||
* Initial import.
|
* 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 |
|
@ -261,6 +261,9 @@ pandora_applet_show_setup_cb (GtkMenuItem *mi, PandoraApplet *applet)
|
||||||
case GTK_RESPONSE_ACCEPT:
|
case GTK_RESPONSE_ACCEPT:
|
||||||
pandora_setup_dialog_apply_changes (applet->priv->setup_dialog);
|
pandora_setup_dialog_apply_changes (applet->priv->setup_dialog);
|
||||||
pandora_setup_save_to_disk (applet->priv->setup);
|
pandora_setup_save_to_disk (applet->priv->setup);
|
||||||
|
|
||||||
|
pandora_status_checker_stop (applet->priv->checker);
|
||||||
|
pandora_status_checker_run (applet->priv->checker);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -107,6 +107,7 @@ pandora_setup_dialog_init (PandoraSetupDialog *dialog)
|
||||||
str = g_strdup_printf ("<b>%s:</b>", _("Database connection"));
|
str = g_strdup_printf ("<b>%s:</b>", _("Database connection"));
|
||||||
label_title = gtk_label_new (NULL);
|
label_title = gtk_label_new (NULL);
|
||||||
gtk_label_set_markup (GTK_LABEL (label_title), str);
|
gtk_label_set_markup (GTK_LABEL (label_title), str);
|
||||||
|
g_free (str);
|
||||||
gtk_misc_set_alignment (GTK_MISC (label_title), 0, 0.5);
|
gtk_misc_set_alignment (GTK_MISC (label_title), 0, 0.5);
|
||||||
|
|
||||||
frame = gtk_frame_new (NULL);
|
frame = gtk_frame_new (NULL);
|
||||||
|
|
|
@ -349,6 +349,7 @@ pandora_setup_read_config_file (PandoraSetup *setup, gchar *file)
|
||||||
root = xmlDocGetRootElement (doc);
|
root = xmlDocGetRootElement (doc);
|
||||||
|
|
||||||
if (!root) {
|
if (!root) {
|
||||||
|
xmlFreeDoc (doc);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -370,6 +371,8 @@ pandora_setup_read_config_file (PandoraSetup *setup, gchar *file)
|
||||||
g_free (password);
|
g_free (password);
|
||||||
g_free (dbname);
|
g_free (dbname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xmlFreeDoc (doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -26,6 +26,14 @@
|
||||||
|
|
||||||
#include "pandora-status-checker.h"
|
#include "pandora-status-checker.h"
|
||||||
|
|
||||||
|
enum {
|
||||||
|
CHECKER_STATE_READY,
|
||||||
|
CHECKER_STATE_RUNNING,
|
||||||
|
CHECKER_STATE_FINISHED,
|
||||||
|
CHECKER_STATE_STOPPING,
|
||||||
|
CHECKER_STATE_FAILED
|
||||||
|
};
|
||||||
|
|
||||||
struct _PandoraStatusCheckerPrivate {
|
struct _PandoraStatusCheckerPrivate {
|
||||||
GThread *thread;
|
GThread *thread;
|
||||||
GMutex *state_mutex;
|
GMutex *state_mutex;
|
||||||
|
@ -163,39 +171,40 @@ pandora_status_checker_new (PandoraSetup *setup, PandoraStatus *status)
|
||||||
static gboolean
|
static gboolean
|
||||||
pandora_status_checker_connect (PandoraStatusChecker *checker)
|
pandora_status_checker_connect (PandoraStatusChecker *checker)
|
||||||
{
|
{
|
||||||
MYSQL *connection;
|
|
||||||
PandoraSetup *setup;
|
|
||||||
gchar *host, *username, *password, *dbname;
|
gchar *host, *username, *password, *dbname;
|
||||||
gboolean retval = TRUE;
|
gboolean retval = TRUE;
|
||||||
|
|
||||||
connection = checker->priv->connection;
|
if (checker->priv->connection != NULL) {
|
||||||
setup = checker->priv->setup;
|
mysql_close (checker->priv->connection);
|
||||||
|
checker->priv->connection = NULL;
|
||||||
if (connection) {
|
|
||||||
mysql_close (connection);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
connection = mysql_init (NULL);
|
checker->priv->connection = mysql_init (NULL);
|
||||||
|
|
||||||
if (connection == NULL) {
|
if (checker->priv->connection == NULL) {
|
||||||
return FALSE;
|
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);
|
"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)
|
password, dbname, 3306, NULL, 0) == NULL)
|
||||||
{
|
{
|
||||||
|
|
||||||
g_print ("mysql_real_connect() failed. %s\n",
|
g_print ("mysql_real_connect() failed. %s\n",
|
||||||
mysql_error (connection));
|
mysql_error (checker->priv->connection));
|
||||||
mysql_close (connection);
|
mysql_close (checker->priv->connection);
|
||||||
|
checker->priv->connection = NULL;
|
||||||
|
|
||||||
retval = FALSE;
|
retval = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
checker->priv->connection = connection;
|
g_free (host);
|
||||||
|
g_free (username);
|
||||||
|
g_free (password);
|
||||||
|
g_free (dbname);
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,7 +221,6 @@ pandora_status_checker_disconnect (PandoraStatusChecker *checker)
|
||||||
static PandoraState
|
static PandoraState
|
||||||
pandora_status_checker_check_agents (PandoraStatusChecker *checker)
|
pandora_status_checker_check_agents (PandoraStatusChecker *checker)
|
||||||
{
|
{
|
||||||
MYSQL *connection = NULL;
|
|
||||||
MYSQL_RES *result;
|
MYSQL_RES *result;
|
||||||
MYSQL_ROW row;
|
MYSQL_ROW row;
|
||||||
const gchar const *query_time = "SELECT * FROM tagente "
|
const gchar const *query_time = "SELECT * FROM tagente "
|
||||||
|
@ -222,28 +230,32 @@ pandora_status_checker_check_agents (PandoraStatusChecker *checker)
|
||||||
"LEFT JOIN tagente "
|
"LEFT JOIN tagente "
|
||||||
"ON tagente_estado.id_agente = tagente.id_agente "
|
"ON tagente_estado.id_agente = tagente.id_agente "
|
||||||
"WHERE estado != 100 and datos = 0.0";
|
"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;
|
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;
|
return STATE_BAD;
|
||||||
}
|
}
|
||||||
|
|
||||||
mysql_free_result (result);
|
mysql_free_result (result);
|
||||||
|
|
||||||
if (mysql_query (connection, query_status) != 0) {
|
if (mysql_query (checker->priv->connection, query_status) != 0) {
|
||||||
return STATE_UNKNOWN;
|
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;
|
return STATE_BAD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,23 +266,25 @@ pandora_status_checker_check_agents (PandoraStatusChecker *checker)
|
||||||
static PandoraState
|
static PandoraState
|
||||||
pandora_status_checker_check_servers (PandoraStatusChecker *checker)
|
pandora_status_checker_check_servers (PandoraStatusChecker *checker)
|
||||||
{
|
{
|
||||||
MYSQL *connection = NULL;
|
|
||||||
MYSQL_RES *result;
|
MYSQL_RES *result;
|
||||||
MYSQL_ROW row;
|
MYSQL_ROW row;
|
||||||
const gchar const *query = "SELECT * FROM tserver "
|
const gchar const *query = "SELECT * FROM tserver "
|
||||||
"WHERE status = 0";
|
"WHERE status = 0";
|
||||||
|
|
||||||
connection = checker->priv->connection;
|
if (checker->priv->connection == NULL) {
|
||||||
g_return_val_if_fail (connection != NULL, FALSE);
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (mysql_query (connection, query) != 0) {
|
if (mysql_query (checker->priv->connection, query) != 0) {
|
||||||
return STATE_UNKNOWN;
|
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;
|
return STATE_BAD;
|
||||||
|
}
|
||||||
|
|
||||||
mysql_free_result (result);
|
mysql_free_result (result);
|
||||||
return STATE_OK;
|
return STATE_OK;
|
||||||
|
@ -279,7 +293,6 @@ pandora_status_checker_check_servers (PandoraStatusChecker *checker)
|
||||||
static PandoraState
|
static PandoraState
|
||||||
pandora_status_checker_check_alerts (PandoraStatusChecker *checker)
|
pandora_status_checker_check_alerts (PandoraStatusChecker *checker)
|
||||||
{
|
{
|
||||||
MYSQL *connection = NULL;
|
|
||||||
MYSQL_RES *result1 = NULL, *result2 = NULL, *result3 = NULL;
|
MYSQL_RES *result1 = NULL, *result2 = NULL, *result3 = NULL;
|
||||||
MYSQL_ROW row;
|
MYSQL_ROW row;
|
||||||
const gchar const *query_all_agents = "SELECT * FROM tagente "
|
const gchar const *query_all_agents = "SELECT * FROM tagente "
|
||||||
|
@ -291,14 +304,15 @@ pandora_status_checker_check_alerts (PandoraStatusChecker *checker)
|
||||||
"AND times_fired > 0";
|
"AND times_fired > 0";
|
||||||
gchar *query;
|
gchar *query;
|
||||||
|
|
||||||
connection = checker->priv->connection;
|
if (checker->priv->connection == NULL) {
|
||||||
g_return_val_if_fail (connection != NULL, FALSE);
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (mysql_query (connection, query_all_agents) != 0) {
|
if (mysql_query (checker->priv->connection, query_all_agents) != 0) {
|
||||||
return STATE_UNKNOWN;
|
return STATE_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
result1 = mysql_store_result (connection);
|
result1 = mysql_store_result (checker->priv->connection);
|
||||||
if (result1 == NULL)
|
if (result1 == NULL)
|
||||||
return STATE_UNKNOWN;
|
return STATE_UNKNOWN;
|
||||||
|
|
||||||
|
@ -308,8 +322,8 @@ pandora_status_checker_check_alerts (PandoraStatusChecker *checker)
|
||||||
while (row = mysql_fetch_row (result1)) {
|
while (row = mysql_fetch_row (result1)) {
|
||||||
query = g_strdup_printf (query_agent_state, row[0]);
|
query = g_strdup_printf (query_agent_state, row[0]);
|
||||||
|
|
||||||
if (mysql_query (connection, query) == 0) {
|
if (mysql_query (checker->priv->connection, query) == 0) {
|
||||||
result2 = mysql_store_result (connection);
|
result2 = mysql_store_result (checker->priv->connection);
|
||||||
|
|
||||||
if (mysql_num_rows (result2) > 0) {
|
if (mysql_num_rows (result2) > 0) {
|
||||||
|
|
||||||
|
@ -319,8 +333,8 @@ pandora_status_checker_check_alerts (PandoraStatusChecker *checker)
|
||||||
query = g_strdup_printf (query_agent_alert,
|
query = g_strdup_printf (query_agent_alert,
|
||||||
row[1]);
|
row[1]);
|
||||||
|
|
||||||
if (mysql_query (connection, query) == 0) {
|
if (mysql_query (checker->priv->connection, query) == 0) {
|
||||||
result3 = mysql_store_result (connection);
|
result3 = mysql_store_result (checker->priv->connection);
|
||||||
|
|
||||||
if (mysql_num_rows (result3) > 0) {
|
if (mysql_num_rows (result3) > 0) {
|
||||||
mysql_free_result (result1);
|
mysql_free_result (result1);
|
||||||
|
@ -361,10 +375,7 @@ pandora_status_checker_run_thread (gpointer data)
|
||||||
while (checker->priv->state == CHECKER_STATE_RUNNING) {
|
while (checker->priv->state == CHECKER_STATE_RUNNING) {
|
||||||
g_mutex_unlock (checker->priv->state_mutex);
|
g_mutex_unlock (checker->priv->state_mutex);
|
||||||
|
|
||||||
if (!pandora_status_checker_connect (checker)) {
|
pandora_status_checker_connect (checker);
|
||||||
pandora_status_checker_stop (checker);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
alerts = pandora_status_checker_check_alerts (checker);
|
alerts = pandora_status_checker_check_alerts (checker);
|
||||||
servers = pandora_status_checker_check_servers (checker);
|
servers = pandora_status_checker_check_servers (checker);
|
||||||
|
@ -389,6 +400,13 @@ pandora_status_checker_run_thread (gpointer data)
|
||||||
void
|
void
|
||||||
pandora_status_checker_run (PandoraStatusChecker *checker)
|
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,
|
checker->priv->thread = g_thread_create (pandora_status_checker_run_thread,
|
||||||
(gpointer) checker, TRUE, NULL);
|
(gpointer) checker, TRUE, NULL);
|
||||||
}
|
}
|
||||||
|
@ -397,6 +415,6 @@ void
|
||||||
pandora_status_checker_stop (PandoraStatusChecker *checker)
|
pandora_status_checker_stop (PandoraStatusChecker *checker)
|
||||||
{
|
{
|
||||||
g_mutex_lock (checker->priv->state_mutex);
|
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);
|
g_mutex_unlock (checker->priv->state_mutex);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,14 +29,6 @@
|
||||||
#include "pandora-setup.h"
|
#include "pandora-setup.h"
|
||||||
#include "pandora-status.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_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(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))
|
#define PANDORA_STATUS_CHECKER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PANDORA_STATUS_CHECKER_TYPE, PandoraStatusCheckerClass))
|
||||||
|
|
Loading…
Reference in New Issue