unix signal watch: make API match other sources
authorRyan Lortie <desrt@desrt.ca>
Tue, 30 Aug 2011 13:45:52 +0000 (09:45 -0400)
committerRyan Lortie <desrt@desrt.ca>
Tue, 30 Aug 2011 23:22:54 +0000 (19:22 -0400)
Change the unix signal watch API to match other sources in both
available functions, names of those functions and order of the
parameters to the _full function.

https://bugzilla.gnome.org/show_bug.cgi?id=657705

docs/reference/glib/glib-sections.txt
glib/glib-unix.c
glib/glib-unix.h
glib/glib.symbols
glib/tests/unix.c

index 10f7ab9..e7036a6 100644 (file)
@@ -1958,8 +1958,9 @@ g_win32_ftruncate
 <FILE>gunix</FILE>
 G_UNIX_ERROR
 g_unix_open_pipe
 <FILE>gunix</FILE>
 G_UNIX_ERROR
 g_unix_open_pipe
+g_unix_signal_add
+g_unix_signal_add_full
 g_unix_signal_source_new
 g_unix_signal_source_new
-g_unix_signal_add_watch_full
 g_unix_set_fd_nonblocking
 
 <SUBSECTION Private>
 g_unix_set_fd_nonblocking
 
 <SUBSECTION Private>
index 77bcea1..6b5495b 100644 (file)
@@ -223,10 +223,10 @@ g_unix_signal_source_new (int signum)
 }
 
 /**
 }
 
 /**
- * g_unix_signal_add_watch_full:
- * @signum: Signal number
+ * g_unix_signal_add_full:
  * @priority: the priority of the signal source. Typically this will be in
  *            the range between #G_PRIORITY_DEFAULT and #G_PRIORITY_HIGH.
  * @priority: the priority of the signal source. Typically this will be in
  *            the range between #G_PRIORITY_DEFAULT and #G_PRIORITY_HIGH.
+ * @signum: Signal number
  * @handler: Callback
  * @user_data: Data for @handler
  * @notify: #GDestroyNotify for @handler
  * @handler: Callback
  * @user_data: Data for @handler
  * @notify: #GDestroyNotify for @handler
@@ -240,11 +240,11 @@ g_unix_signal_source_new (int signum)
  * Since: 2.30
  */
 guint
  * Since: 2.30
  */
 guint
-g_unix_signal_add_watch_full (int            signum,
-                              int            priority,
-                              GSourceFunc    handler,
-                              gpointer       user_data,
-                              GDestroyNotify notify)
+g_unix_signal_add_full (int            priority,
+                        int            signum,
+                        GSourceFunc    handler,
+                        gpointer       user_data,
+                        GDestroyNotify notify)
 {
   guint id;
   GSource *source;
 {
   guint id;
   GSource *source;
@@ -260,3 +260,25 @@ g_unix_signal_add_watch_full (int            signum,
 
   return id;
 }
 
   return id;
 }
+
+/**
+ * g_unix_signal_add_full:
+ * @signum: Signal number
+ * @handler: Callback
+ * @user_data: Data for @handler
+ *
+ * A convenience function for g_unix_signal_source_new(), which
+ * attaches to the default #GMainContext.  You can remove the watch
+ * using g_source_remove().
+ *
+ * Returns: An ID (greater than 0) for the event source
+ *
+ * Since: 2.30
+ */
+guint
+g_unix_signal_add (int         signum,
+                   GSourceFunc handler,
+                   gpointer    user_data)
+{
+  return g_unix_signal_add_full (G_PRIORITY_DEFAULT, signum, handler, user_data, NULL);
+}
index b136fe3..32c6c80 100644 (file)
@@ -65,12 +65,16 @@ gboolean g_unix_set_fd_nonblocking (gint       fd,
                                     gboolean   nonblock,
                                     GError   **error);
 
                                     gboolean   nonblock,
                                     GError   **error);
 
-GSource *g_unix_signal_source_new     (gint signum);
+GSource *g_unix_signal_source_new  (gint signum);
 
 
-guint    g_unix_signal_add_watch_full (gint           signum,
-                                       gint           priority,
-                                       GSourceFunc    handler,
-                                       gpointer       user_data,
-                                       GDestroyNotify notify);
+guint    g_unix_signal_add_full    (gint           priority,
+                                    gint           signum,
+                                    GSourceFunc    handler,
+                                    gpointer       user_data,
+                                    GDestroyNotify notify);
+
+guint    g_unix_signal_add         (gint        signum,
+                                    GSourceFunc handler,
+                                    gpointer    user_data);
 
 #endif
 
 #endif
index 3af1cfa..f611d91 100644 (file)
@@ -1576,8 +1576,9 @@ g_hostname_to_unicode
 g_unix_error_quark
 g_unix_open_pipe
 g_unix_set_fd_nonblocking
 g_unix_error_quark
 g_unix_open_pipe
 g_unix_set_fd_nonblocking
+g_unix_signal_add
+g_unix_signal_add_full
 g_unix_signal_source_new
 g_unix_signal_source_new
-g_unix_signal_add_watch_full
 #endif
 g_ascii_table
 g_utf8_skip
 #endif
 g_ascii_table
 g_utf8_skip
index 453ad64..061b5a6 100644 (file)
@@ -98,11 +98,7 @@ test_signal (int signum)
   mainloop = g_main_loop_new (NULL, FALSE);
 
   sig_received = FALSE;
   mainloop = g_main_loop_new (NULL, FALSE);
 
   sig_received = FALSE;
-  g_unix_signal_add_watch_full (signum,
-                               G_PRIORITY_DEFAULT,
-                               on_sig_received,
-                               mainloop,
-                               NULL);
+  g_unix_signal_add (signum, on_sig_received, mainloop);
   kill (getpid (), signum);
   g_assert (!sig_received);
   g_timeout_add (5000, sig_not_received, mainloop);
   kill (getpid (), signum);
   g_assert (!sig_received);
   g_timeout_add (5000, sig_not_received, mainloop);
@@ -138,11 +134,7 @@ test_sighup_add_remove (void)
   mainloop = g_main_loop_new (NULL, FALSE);
 
   sig_received = FALSE;
   mainloop = g_main_loop_new (NULL, FALSE);
 
   sig_received = FALSE;
-  id = g_unix_signal_add_watch_full (SIGHUP,
-                                    G_PRIORITY_DEFAULT,
-                                    on_sig_received,
-                                    mainloop,
-                                    NULL);
+  id = g_unix_signal_add (SIGHUP, on_sig_received, mainloop);
   g_source_remove (id);
   kill (getpid (), SIGHUP);
   g_assert (!sig_received);
   g_source_remove (id);
   kill (getpid (), SIGHUP);
   g_assert (!sig_received);