Bug 620582 - a simple GPermission implementation
[platform/upstream/glib.git] / gio / gsimplepermission.c
1 /*
2  * Copyright © 2010 Codethink Limited
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the licence, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  *
19  * Author: Ryan Lortie <desrt@desrt.ca>
20  */
21
22 #include "gsimplepermission.h"
23 #include "gpermission.h"
24
25 #include "gioalias.h"
26
27 /**
28  * SECTION:gsimplepermission
29  * @title: GSimplePermission
30  * @short_description: a #GPermission that doesn't change value
31  *
32  * #GSimplePermission is a trivial implementation of #GPermission that
33  * represents a permission that is either always or never allowed.  The
34  * value is given at constuction and doesn't change.
35  *
36  * Calling request or release will result in errors.
37  **/
38
39 /**
40  * GSimplePermission:
41  *
42  * #GSimplePermission is an opaque data structure.  There are no methods
43  * except for those defined by #GPermission.
44  **/
45
46 typedef GPermissionClass GSimplePermissionClass;
47
48 struct _GSimplePermission
49 {
50   GPermission parent_instance;
51 };
52
53 G_DEFINE_TYPE (GSimplePermission, g_simple_permission, G_TYPE_PERMISSION)
54
55 static void
56 g_simple_permission_init (GSimplePermission *simple)
57 {
58 }
59
60 static void
61 g_simple_permission_class_init (GSimplePermissionClass *class)
62 {
63 }
64
65 /**
66  * g_simple_permission_new:
67  * @allowed: %TRUE if the action is allowed
68  * @returns: the #GSimplePermission, as a #GPermission
69  *
70  * Creates a new #GPermission instance that represents an action that is
71  * either always or never allowed.
72  **/
73 GPermission *
74 g_simple_permission_new (gboolean allowed)
75 {
76   GPermission *permission = g_object_new (G_TYPE_SIMPLE_PERMISSION, NULL);
77
78   g_permission_impl_update (permission, allowed, FALSE, FALSE);
79
80   return permission;
81 }
82
83 #define __G_SIMPLE_PERMISSION_C__
84 #include "gioaliasdef.c"