giomodule test: force shared library build
[platform/upstream/glib.git] / gio / gpermission.c
index 97a4fd9..421d63a 100644 (file)
 #include "config.h"
 
 #include "gpermission.h"
+
+#include "gioerror.h"
+#include "gioenums.h"
+#include "gasyncresult.h"
+#include "gsimpleasyncresult.h"
 #include "glibintl.h"
 
 
 /**
  * SECTION:gpermission
  * @title: GPermission
- * @short_description: An object representing the permission to perform
- *                     a certain action
+ * @short_description: An object representing the permission
+ *     to perform a certain action
+ * @include: gio/gio.h
  *
  * A #GPermission represents the status of the caller's permission to
  * perform a certain action.
@@ -55,8 +61,6 @@
  * using the following functions.
  **/
 
-G_DEFINE_ABSTRACT_TYPE (GPermission, g_permission, G_TYPE_OBJECT)
-
 struct _GPermissionPrivate
 {
   gboolean allowed;
@@ -71,12 +75,13 @@ enum  {
   PROP_CAN_RELEASE
 };
 
+G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GPermission, g_permission, G_TYPE_OBJECT)
+
 /**
  * g_permission_acquire:
  * @permission: a #GPermission instance
- * @cancellable: a #GCancellable, or %NULL
+ * @cancellable: (allow-none): a #GCancellable, or %NULL
  * @error: a pointer to a %NULL #GError, or %NULL
- * @returns: %TRUE if the permission was successfully acquired
  *
  * Attempts to acquire the permission represented by @permission.
  *
@@ -94,6 +99,8 @@ enum  {
  * user interaction is required).  See g_permission_acquire_async() for
  * the non-blocking version.
  *
+ * Returns: %TRUE if the permission was successfully acquired
+ *
  * Since: 2.26
  */
 gboolean
@@ -108,7 +115,7 @@ g_permission_acquire (GPermission   *permission,
 /**
  * g_permission_acquire_async:
  * @permission: a #GPermission instance
- * @cancellable: a #GCancellable, or %NULL
+ * @cancellable: (allow-none): a #GCancellable, or %NULL
  * @callback: the #GAsyncReadyCallback to call when done
  * @user_data: the user data to pass to @callback
  *
@@ -134,7 +141,6 @@ g_permission_acquire_async (GPermission         *permission,
  * @permission: a #GPermission instance
  * @result: the #GAsyncResult given to the #GAsyncReadyCallback
  * @error: a pointer to a %NULL #GError, or %NULL
- * @returns: %TRUE if the permission was successfully acquired
  *
  * Collects the result of attempting to acquire the permission
  * represented by @permission.
@@ -142,6 +148,8 @@ g_permission_acquire_async (GPermission         *permission,
  * This is the second half of the asynchronous version of
  * g_permission_acquire().
  *
+ * Returns: %TRUE if the permission was successfully acquired
+ *
  * Since: 2.26
  **/
 gboolean
@@ -156,9 +164,8 @@ g_permission_acquire_finish (GPermission   *permission,
 /**
  * g_permission_release:
  * @permission: a #GPermission instance
- * @cancellable: a #GCancellable, or %NULL
+ * @cancellable: (allow-none): a #GCancellable, or %NULL
  * @error: a pointer to a %NULL #GError, or %NULL
- * @returns: %TRUE if the permission was successfully released
  *
  * Attempts to release the permission represented by @permission.
  *
@@ -176,6 +183,8 @@ g_permission_acquire_finish (GPermission   *permission,
  * user interaction is required).  See g_permission_release_async() for
  * the non-blocking version.
  *
+ * Returns: %TRUE if the permission was successfully released
+ *
  * Since: 2.26
  **/
 gboolean
@@ -190,7 +199,7 @@ g_permission_release (GPermission   *permission,
 /**
  * g_permission_release_async:
  * @permission: a #GPermission instance
- * @cancellable: a #GCancellable, or %NULL
+ * @cancellable: (allow-none): a #GCancellable, or %NULL
  * @callback: the #GAsyncReadyCallback to call when done
  * @user_data: the user data to pass to @callback
  *
@@ -216,7 +225,6 @@ g_permission_release_async (GPermission         *permission,
  * @permission: a #GPermission instance
  * @result: the #GAsyncResult given to the #GAsyncReadyCallback
  * @error: a pointer to a %NULL #GError, or %NULL
- * @returns: %TRUE if the permission was successfully released
  *
  * Collects the result of attempting to release the permission
  * represented by @permission.
@@ -224,6 +232,8 @@ g_permission_release_async (GPermission         *permission,
  * This is the second half of the asynchronous version of
  * g_permission_release().
  *
+ * Returns: %TRUE if the permission was successfully released
+ *
  * Since: 2.26
  **/
 gboolean
@@ -238,12 +248,13 @@ g_permission_release_finish (GPermission   *permission,
 /**
  * g_permission_get_allowed:
  * @permission: a #GPermission instance
- * @returns: the value of the 'allowed' property
  *
  * Gets the value of the 'allowed' property.  This property is %TRUE if
  * the caller currently has permission to perform the action that
  * @permission represents the permission to perform.
  *
+ * Returns: the value of the 'allowed' property
+ *
  * Since: 2.26
  **/
 gboolean
@@ -255,12 +266,13 @@ g_permission_get_allowed (GPermission *permission)
 /**
  * g_permission_get_can_acquire:
  * @permission: a #GPermission instance
- * @returns: the value of the 'can-acquire' property
  *
  * Gets the value of the 'can-acquire' property.  This property is %TRUE
  * if it is generally possible to acquire the permission by calling
  * g_permission_acquire().
  *
+ * Returns: the value of the 'can-acquire' property
+ *
  * Since: 2.26
  **/
 gboolean
@@ -272,12 +284,13 @@ g_permission_get_can_acquire (GPermission *permission)
 /**
  * g_permission_get_can_release:
  * @permission: a #GPermission instance
- * @returns: the value of the 'can-release' property
  *
  * Gets the value of the 'can-release' property.  This property is %TRUE
  * if it is generally possible to release the permission by calling
  * g_permission_release().
  *
+ * Returns: the value of the 'can-release' property
+ *
  * Since: 2.26
  **/
 gboolean
@@ -311,21 +324,24 @@ g_permission_impl_update (GPermission *permission,
 
   g_object_freeze_notify (object);
 
+  allowed = allowed != FALSE;
   if (allowed != permission->priv->allowed)
     {
-      permission->priv->allowed = !!allowed;
+      permission->priv->allowed = allowed;
       g_object_notify (object, "allowed");
     }
 
+  can_acquire = can_acquire != FALSE;
   if (can_acquire != permission->priv->can_acquire)
     {
-      permission->priv->can_acquire = !!can_acquire;
+      permission->priv->can_acquire = can_acquire;
       g_object_notify (object, "can-acquire");
     }
 
+  can_release = can_release != FALSE;
   if (can_release != permission->priv->can_release)
     {
-      permission->priv->can_release = !!can_release;
+      permission->priv->can_release = can_release;
       g_object_notify (object, "can-release");
     }
 
@@ -360,9 +376,39 @@ g_permission_get_property (GObject *object, guint prop_id,
 static void
 g_permission_init (GPermission *permission)
 {
-  permission->priv = G_TYPE_INSTANCE_GET_PRIVATE (permission,
-                                                  G_TYPE_PERMISSION,
-                                                  GPermissionPrivate);
+  permission->priv = g_permission_get_instance_private (permission);
+}
+
+static gboolean
+acquire_or_release (GPermission   *permission,
+                    GCancellable  *cancellable,
+                    GError       **error)
+{
+  g_set_error_literal  (error,
+                        G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
+                        "Can't acquire or release permission");
+  return FALSE;
+}
+
+static void
+acquire_or_release_async (GPermission         *permission,
+                          GCancellable        *cancellable,
+                          GAsyncReadyCallback  callback,
+                          gpointer             user_data)
+{
+  g_simple_async_report_error_in_idle (G_OBJECT (permission),
+                                       callback, user_data,
+                                       G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
+                                       "Can't acquire or release permission");
+}
+
+static gboolean
+acquire_or_release_finish (GPermission   *permission,
+                           GAsyncResult  *result,
+                           GError       **error)
+{
+  g_async_result_legacy_propagate_error (result, error);
+  return FALSE;
 }
 
 static void
@@ -372,6 +418,13 @@ g_permission_class_init (GPermissionClass *class)
 
   object_class->get_property = g_permission_get_property;
 
+  class->acquire = acquire_or_release;
+  class->release = acquire_or_release;
+  class->acquire_async = acquire_or_release_async;
+  class->release_async = acquire_or_release_async;
+  class->acquire_finish = acquire_or_release_finish;
+  class->release_finish = acquire_or_release_finish;
+
   /**
    * GPermission:allowed:
    *
@@ -410,6 +463,4 @@ g_permission_class_init (GPermissionClass *class)
                            P_("If calling g_permission_release() makes sense"),
                            FALSE,
                            G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
-
-  g_type_class_add_private (class, sizeof (GPermissionPrivate));
 }