diff options
author | Charlie Brej <cbrej@cs.man.ac.uk> | 2010-08-07 15:38:22 +0100 |
---|---|---|
committer | Charlie Brej <cbrej@cs.man.ac.uk> | 2010-08-07 15:38:22 +0100 |
commit | 22202a2b372387c8b217f660488ab221f85ffdc8 (patch) | |
tree | c9f8be07db2d82ef152deeb9648743c72c1f9d07 | |
parent | 069d069e6dde75dc42da3245acae82baa181d9f0 (diff) |
Create a single main quit function
-rw-r--r-- | src/main.c | 13 | ||||
-rw-r--r-- | src/main.h | 27 | ||||
-rw-r--r-- | src/tidbit-dbus.c | 9 | ||||
-rw-r--r-- | src/tidbit-dbus.h | 2 |
4 files changed, 41 insertions, 10 deletions
@@ -29,6 +29,7 @@ #include "tidbit-dbus.h" #include "tidbit-http.h" +GMainLoop *main_loop; void print_guid (PtrTidbitGuid guid, gpointer database) { @@ -37,6 +38,10 @@ void print_guid (PtrTidbitGuid guid, gpointer database) tidbit_record_unref (record); } +void main_quit(void) +{ + g_main_loop_quit (main_loop); +} int main(int argc, char* argv[]) { @@ -66,7 +71,7 @@ int main(int argc, char* argv[]) if (!g_thread_supported ()) g_thread_init (NULL); - GMainLoop *loop = g_main_loop_new (NULL, TRUE); + main_loop = g_main_loop_new (NULL, TRUE); PtrTidbitDatabase database; @@ -78,7 +83,7 @@ int main(int argc, char* argv[]) if (enable_http) tidbit_http_setup (database); if (enable_dbus) - tidbit_dbus_setup (database, loop); + tidbit_dbus_setup (database); @@ -112,8 +117,8 @@ int main(int argc, char* argv[]) tidbit_query_unref (query); tidbit_guid_set_unref (guid_set); - g_main_loop_run (loop); - g_main_loop_unref (loop); + g_main_loop_run (main_loop); + g_main_loop_unref (main_loop); return 0; } diff --git a/src/main.h b/src/main.h new file mode 100644 index 0000000..6c4e130 --- /dev/null +++ b/src/main.h @@ -0,0 +1,27 @@ +/* Tidbit + * Copyright (C) 2010 Charlie Brej tidbit@brej.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3.0 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifndef _MAIN_H_ +#define _MAIN_H_ + +void main_quit(void); + +#endif + + diff --git a/src/tidbit-dbus.c b/src/tidbit-dbus.c index 51e74a8..7d354d4 100644 --- a/src/tidbit-dbus.c +++ b/src/tidbit-dbus.c @@ -49,12 +49,12 @@ tidbit_dbus_init (TidbitDbus *object) tidbit_dbus->database = NULL; } -static void on_disconnect_cb (DBusGProxy *proxy, GMainLoop *loop) +static void on_disconnect_cb (DBusGProxy *proxy) { - g_main_loop_quit (loop); + main_quit (); } -void tidbit_dbus_setup (PtrTidbitDatabase database, GMainLoop *loop) +void tidbit_dbus_setup (PtrTidbitDatabase database) { guint result; GError *error = NULL; @@ -67,7 +67,7 @@ void tidbit_dbus_setup (PtrTidbitDatabase database, GMainLoop *loop) proxy = dbus_g_proxy_new_for_name (connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); dbus_connection_set_exit_on_disconnect (dbus_g_connection_get_connection (connection), FALSE); org_freedesktop_DBus_request_name (proxy, DBUS_TIDBIT, DBUS_NAME_FLAG_DO_NOT_QUEUE, &result, &error); - g_signal_connect (G_OBJECT (proxy), "destroy", G_CALLBACK (on_disconnect_cb), loop); + g_signal_connect (G_OBJECT (proxy), "destroy", G_CALLBACK (on_disconnect_cb), NULL); object = g_object_new (TYPE_TIDBIT_DBUS, NULL); TidbitDbus *tidbit_dbus = TIDBIT_DBUS (object); @@ -98,7 +98,6 @@ gboolean tidbit_dbus_fetch (TidbitDbus *object, gchar *signature, gchar **reply_ *reply_record = g_strdup(record->raw); tidbit_record_unref (record); } - g_object_unref (tidbit_dbus->proxy); return TRUE; } diff --git a/src/tidbit-dbus.h b/src/tidbit-dbus.h index 1e9aec4..783539e 100644 --- a/src/tidbit-dbus.h +++ b/src/tidbit-dbus.h @@ -58,7 +58,7 @@ gboolean tidbit_dbus_query (TidbitDbus *object, gchar *table_name, GPtrArray *el TidbitDbus *tidbit_dbus_new (void); GType tidbit_dbus_get_type (void); -void tidbit_dbus_setup (PtrTidbitDatabase database, GMainLoop *loop); +void tidbit_dbus_setup (PtrTidbitDatabase database); G_END_DECLS |