X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=gio%2Fgpermission.c;h=0fcd17ec74032b4627ffff9b77d4a103784aa56a;hb=634b69219979c084837c59874e5b2aec01a1d3e4;hp=cb1eec1c1d08d553709611c7fbe4f65e70f3a2e7;hpb=92fab483875c2d78ae2cb4749ae283cd26afa451;p=platform%2Fupstream%2Fglib.git
diff --git a/gio/gpermission.c b/gio/gpermission.c
index cb1eec1..0fcd17e 100644
--- a/gio/gpermission.c
+++ b/gio/gpermission.c
@@ -12,9 +12,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.
+ * License along with this library; if not, see .
*
* Author: Ryan Lortie
*/
@@ -22,15 +20,20 @@
#include "config.h"
#include "gpermission.h"
+
+#include "gioerror.h"
+#include "gioenums.h"
+#include "gasyncresult.h"
+#include "gsimpleasyncresult.h"
#include "glibintl.h"
-#include "gioalias.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.
@@ -56,8 +59,6 @@
* using the following functions.
**/
-G_DEFINE_ABSTRACT_TYPE (GPermission, g_permission, G_TYPE_OBJECT)
-
struct _GPermissionPrivate
{
gboolean allowed;
@@ -72,12 +73,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.
*
@@ -95,6 +97,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
@@ -102,6 +106,7 @@ g_permission_acquire (GPermission *permission,
GCancellable *cancellable,
GError **error)
{
+ g_return_val_if_fail (G_IS_PERMISSION (permission), FALSE);
return G_PERMISSION_GET_CLASS (permission)
->acquire (permission, cancellable, error);
}
@@ -109,7 +114,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
*
@@ -126,6 +131,7 @@ g_permission_acquire_async (GPermission *permission,
GAsyncReadyCallback callback,
gpointer user_data)
{
+ g_return_if_fail (G_IS_PERMISSION (permission));
G_PERMISSION_GET_CLASS (permission)
->acquire_async (permission, cancellable, callback, user_data);
}
@@ -135,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.
@@ -143,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
@@ -150,6 +157,7 @@ g_permission_acquire_finish (GPermission *permission,
GAsyncResult *result,
GError **error)
{
+ g_return_val_if_fail (G_IS_PERMISSION (permission), FALSE);
return G_PERMISSION_GET_CLASS (permission)
->acquire_finish (permission, result, error);
}
@@ -157,9 +165,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.
*
@@ -177,6 +184,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
@@ -184,6 +193,7 @@ g_permission_release (GPermission *permission,
GCancellable *cancellable,
GError **error)
{
+ g_return_val_if_fail (G_IS_PERMISSION (permission), FALSE);
return G_PERMISSION_GET_CLASS (permission)
->release (permission, cancellable, error);
}
@@ -191,7 +201,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
*
@@ -208,6 +218,7 @@ g_permission_release_async (GPermission *permission,
GAsyncReadyCallback callback,
gpointer user_data)
{
+ g_return_if_fail (G_IS_PERMISSION (permission));
G_PERMISSION_GET_CLASS (permission)
->release_async (permission, cancellable, callback, user_data);
}
@@ -217,7 +228,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.
@@ -225,6 +235,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
@@ -232,6 +244,7 @@ g_permission_release_finish (GPermission *permission,
GAsyncResult *result,
GError **error)
{
+ g_return_val_if_fail (G_IS_PERMISSION (permission), FALSE);
return G_PERMISSION_GET_CLASS (permission)
->release_finish (permission, result, error);
}
@@ -239,51 +252,57 @@ 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
g_permission_get_allowed (GPermission *permission)
{
+ g_return_val_if_fail (G_IS_PERMISSION (permission), FALSE);
return permission->priv->allowed;
}
/**
* 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
g_permission_get_can_acquire (GPermission *permission)
{
+ g_return_val_if_fail (G_IS_PERMISSION (permission), FALSE);
return permission->priv->can_acquire;
}
/**
* 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
g_permission_get_can_release (GPermission *permission)
{
+ g_return_val_if_fail (G_IS_PERMISSION (permission), FALSE);
return permission->priv->can_release;
}
@@ -308,25 +327,31 @@ g_permission_impl_update (GPermission *permission,
gboolean can_acquire,
gboolean can_release)
{
- GObject *object = G_OBJECT (permission);
+ GObject *object;
+
+ g_return_if_fail (G_IS_PERMISSION (permission));
+ object = G_OBJECT (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");
}
@@ -361,9 +386,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
@@ -373,6 +428,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:
*
@@ -381,7 +443,7 @@ g_permission_class_init (GPermissionClass *class)
*/
g_object_class_install_property (object_class, PROP_ALLOWED,
g_param_spec_boolean ("allowed",
- P(("Is allowed"),
+ P_("Is allowed"),
P_("If the caller is allowed to perform the action"),
FALSE,
G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
@@ -411,9 +473,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));
}
-
-#define __G_PERMISSION_C__
-#include "gioaliasdef.c"