[kdbus] sync with kdbus (kdbus.h - commit: 5ae1ecac44cb)
[platform/upstream/glib.git] / gio / gnetworkmonitor.c
index 33e9704..79c7bd9 100644 (file)
@@ -13,9 +13,7 @@
  * 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.
+ * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
 #include "config.h"
 #include "ginitable.h"
 #include "gioenumtypes.h"
 #include "giomodule-priv.h"
-#include "gsimpleasyncresult.h"
+#include "gtask.h"
 
 /**
  * SECTION:gnetworkmonitor
  * @title: GNetworkMonitor
  * @short_description: Network status monitor
  * @include: gio/gio.h
+ *
+ * #GNetworkMonitor provides an easy-to-use cross-platform API
+ * for monitoring network connectivity. On Linux, the implementation
+ * is based on the kernel's netlink interface.
  */
 
 /**
@@ -47,7 +49,7 @@
  */
 
 G_DEFINE_INTERFACE_WITH_CODE (GNetworkMonitor, g_network_monitor, G_TYPE_OBJECT,
-                             g_type_interface_add_prerequisite (g_define_type_id, G_TYPE_INITABLE);)
+                              g_type_interface_add_prerequisite (g_define_type_id, G_TYPE_INITABLE);)
 
 
 enum {
@@ -70,8 +72,8 @@ GNetworkMonitor *
 g_network_monitor_get_default (void)
 {
   return _g_io_module_get_default (G_NETWORK_MONITOR_EXTENSION_POINT_NAME,
-                                  "GIO_USE_NETWORK_MONITOR",
-                                  NULL);
+                                   "GIO_USE_NETWORK_MONITOR",
+                                   NULL);
 }
 
 /**
@@ -83,7 +85,7 @@ g_network_monitor_get_default (void)
  * IPv6. It does not necessarily imply that the public Internet is
  * reachable. See #GNetworkMonitor:network-available for more details.
  *
- * Return value: whether the network is available
+ * Returns: whether the network is available
  *
  * Since: 2.32
  */
@@ -100,7 +102,7 @@ g_network_monitor_get_network_available (GNetworkMonitor *monitor)
  * g_network_monitor_can_reach:
  * @monitor: a #GNetworkMonitor
  * @connectable: a #GSocketConnectable
- * @cancellable: a #GCancellable, or %NULL
+ * @cancellable: (allow-none): a #GCancellable, or %NULL
  * @error: return location for a #GError, or %NULL
  *
  * Attempts to determine whether or not the host pointed to by
@@ -121,15 +123,15 @@ g_network_monitor_get_network_available (GNetworkMonitor *monitor)
  * trying to do multicast DNS on the local network), so if you do not
  * want to block, you should use g_network_monitor_can_reach_async().
  *
- * Return value: %TRUE if @connectable is reachable, %FALSE if not.
+ * Returns: %TRUE if @connectable is reachable, %FALSE if not.
  *
  * Since: 2.32
  */
 gboolean
 g_network_monitor_can_reach (GNetworkMonitor     *monitor,
-                            GSocketConnectable  *connectable,
-                            GCancellable        *cancellable,
-                            GError             **error)
+                             GSocketConnectable  *connectable,
+                             GCancellable        *cancellable,
+                             GError             **error)
 {
   GNetworkMonitorInterface *iface;
 
@@ -139,31 +141,47 @@ g_network_monitor_can_reach (GNetworkMonitor     *monitor,
 
 static void
 g_network_monitor_real_can_reach_async (GNetworkMonitor     *monitor,
-                                       GSocketConnectable  *connectable,
-                                       GCancellable        *cancellable,
-                                       GAsyncReadyCallback  callback,
-                                       gpointer             user_data)
+                                        GSocketConnectable  *connectable,
+                                        GCancellable        *cancellable,
+                                        GAsyncReadyCallback  callback,
+                                        gpointer             user_data)
 {
-  GSimpleAsyncResult *simple;
+  GTask *task;
   GError *error = NULL;
 
-  simple = g_simple_async_result_new (G_OBJECT (monitor),
-                                     callback, user_data,
-                                     g_network_monitor_real_can_reach_async);
+  task = g_task_new (monitor, cancellable, callback, user_data);
   if (g_network_monitor_can_reach (monitor, connectable, cancellable, &error))
-    g_simple_async_result_set_op_res_gboolean (simple, TRUE);
+    g_task_return_boolean (task, TRUE);
   else
-    g_simple_async_result_take_error (simple, error);
-  g_simple_async_result_complete_in_idle (simple);
-  g_object_unref (simple);
+    g_task_return_error (task, error);
+  g_object_unref (task);
 }
 
+/**
+ * g_network_monitor_can_reach_async:
+ * @monitor: a #GNetworkMonitor
+ * @connectable: a #GSocketConnectable
+ * @cancellable: (allow-none): a #GCancellable, or %NULL
+ * @callback: (scope async): a #GAsyncReadyCallback to call when the
+ *     request is satisfied
+ * @user_data: (closure): the data to pass to callback function
+ *
+ * Asynchronously attempts to determine whether or not the host
+ * pointed to by @connectable can be reached, without actually
+ * trying to connect to it.
+ *
+ * For more details, see g_network_monitor_can_reach().
+ *
+ * When the operation is finished, @callback will be called.
+ * You can then call g_network_monitor_can_reach_finish()
+ * to get the result of the operation.
+ */
 void
 g_network_monitor_can_reach_async (GNetworkMonitor     *monitor,
-                                  GSocketConnectable  *connectable,
-                                  GCancellable        *cancellable,
-                                  GAsyncReadyCallback  callback,
-                                  gpointer             user_data)
+                                   GSocketConnectable  *connectable,
+                                   GCancellable        *cancellable,
+                                   GAsyncReadyCallback  callback,
+                                   gpointer             user_data)
 {
   GNetworkMonitorInterface *iface;
 
@@ -173,24 +191,29 @@ g_network_monitor_can_reach_async (GNetworkMonitor     *monitor,
 
 static gboolean
 g_network_monitor_real_can_reach_finish (GNetworkMonitor  *monitor,
-                                        GAsyncResult     *result,
-                                        GError          **error)
+                                         GAsyncResult     *result,
+                                         GError          **error)
 {
-  GSimpleAsyncResult *simple;
+  g_return_val_if_fail (g_task_is_valid (result, monitor), FALSE);
 
-  g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (monitor), g_network_monitor_real_can_reach_async), FALSE);
-
-  simple = G_SIMPLE_ASYNC_RESULT (result);
-  if (g_simple_async_result_propagate_error (simple, error))
-    return FALSE;
-  else
-    return g_simple_async_result_get_op_res_gboolean (simple);
+  return g_task_propagate_boolean (G_TASK (result), error);
 }
 
+/**
+ * g_network_monitor_can_reach_finish:
+ * @monitor: a #GNetworkMonitor
+ * @result: a #GAsyncResult
+ * @error: return location for errors, or %NULL
+ *
+ * Finishes an async network connectivity test.
+ * See g_network_monitor_can_reach_async().
+ *
+ * Returns: %TRUE if network is reachable, %FALSE if not.
+ */
 gboolean
 g_network_monitor_can_reach_finish (GNetworkMonitor     *monitor,
-                                   GAsyncResult        *result,
-                                   GError             **error)
+                                    GAsyncResult        *result,
+                                    GError             **error)
 {
   GNetworkMonitorInterface *iface;
 
@@ -219,13 +242,13 @@ g_network_monitor_default_init (GNetworkMonitorInterface *iface)
    */
   signals[NETWORK_CHANGED] =
     g_signal_new (I_("network-changed"),
-                 G_TYPE_NETWORK_MONITOR,
-                 G_SIGNAL_RUN_LAST,
-                 G_STRUCT_OFFSET (GNetworkMonitorInterface, network_changed),
-                 NULL, NULL,
-                 g_cclosure_marshal_VOID__BOOLEAN,
-                 G_TYPE_NONE, 1,
-                 G_TYPE_BOOLEAN);
+                  G_TYPE_NETWORK_MONITOR,
+                  G_SIGNAL_RUN_LAST,
+                  G_STRUCT_OFFSET (GNetworkMonitorInterface, network_changed),
+                  NULL, NULL,
+                  g_cclosure_marshal_VOID__BOOLEAN,
+                  G_TYPE_NONE, 1,
+                  G_TYPE_BOOLEAN);
 
   /**
    * GNetworkMonitor:network-available:
@@ -239,10 +262,9 @@ g_network_monitor_default_init (GNetworkMonitorInterface *iface)
    * connected to a functioning router that has lost its own upstream
    * connectivity. Some hosts might only be accessible when a VPN is
    * active. Other hosts might only be accessible when the VPN is
-   * <emphasis>not</emphasis> active. Thus, it is best to use
-   * g_network_monitor_can_reach() or
-   * g_network_monitor_can_reach_async() to test for reachability on a
-   * host-by-host basis. (On the other hand, when the property is
+   * not active. Thus, it is best to use g_network_monitor_can_reach()
+   * or g_network_monitor_can_reach_async() to test for reachability
+   * on a host-by-host basis. (On the other hand, when the property is
    * %FALSE, the application can reasonably expect that no remote
    * hosts at all are reachable, and should indicate this to the user
    * in its UI.)
@@ -252,10 +274,10 @@ g_network_monitor_default_init (GNetworkMonitorInterface *iface)
    * Since: 2.32
    */
   g_object_interface_install_property (iface,
-                                      g_param_spec_boolean ("network-available",
-                                                            P_("Network available"),
-                                                            P_("Whether the network is available"),
-                                                            FALSE,
-                                                            G_PARAM_READABLE |
-                                                            G_PARAM_STATIC_STRINGS));
+                                       g_param_spec_boolean ("network-available",
+                                                             P_("Network available"),
+                                                             P_("Whether the network is available"),
+                                                             FALSE,
+                                                             G_PARAM_READABLE |
+                                                             G_PARAM_STATIC_STRINGS));
 }