1 /* plugin.c -- generic plugin routines for vlock,
2 * the VT locking program for linux
4 * This program is copyright (C) 2007 Frank Benkstein, and is free
5 * software which is freely distributable under the terms of the
6 * GNU General Public License version 2, included as the file COPYING in this
7 * distribution. It is NOT public domain software, and any
8 * redistribution not permitted by the GNU General Public License is
9 * expressly forbidden without prior written permission from
23 GQuark
vlock_plugin_error_quark(void)
25 return g_quark_from_static_string("vlock-plugin-error-quark");
28 G_DEFINE_TYPE(VlockPlugin
, vlock_plugin
, G_TYPE_OBJECT
)
30 /* Initialize plugin to default values. */
31 static void vlock_plugin_init(VlockPlugin
*self
)
34 self
->save_disabled
= false;
35 for (size_t i
= 0; i
< nr_dependencies
; i
++)
36 self
->dependencies
[i
] = NULL
;
39 /* Create new plugin object. */
40 static GObject
*vlock_plugin_constructor(GType gtype
,
42 GObjectConstructParam
*properties
)
44 GObjectClass
*parent_class
= G_OBJECT_CLASS(vlock_plugin_parent_class
);
45 GObject
*object
= parent_class
->constructor(gtype
, n_properties
, properties
);
46 VlockPlugin
*self
= VLOCK_PLUGIN(object
);
48 g_return_val_if_fail(self
->name
!= NULL
, NULL
);
53 /* Destroy plugin object. */
54 static void vlock_plugin_finalize(GObject
*object
)
56 VlockPlugin
*self
= VLOCK_PLUGIN(object
);
61 /* Destroy dependency lists. */
62 for (size_t i
= 0; i
< nr_dependencies
; i
++) {
63 while (self
->dependencies
[i
] != NULL
) {
64 g_free(self
->dependencies
[i
]->data
);
65 self
->dependencies
[i
] = g_list_delete_link(self
->dependencies
[i
],
66 self
->dependencies
[i
]);
70 G_OBJECT_CLASS(vlock_plugin_parent_class
)->finalize(object
);
76 PROP_VLOCK_PLUGIN_NAME
79 static void vlock_plugin_set_name(VlockPlugin
*self
, const gchar
*name
)
81 /* For security plugin names must not contain a slash. */
82 char *last_slash
= strrchr(name
, '/');
84 if (last_slash
!= NULL
)
87 self
->name
= g_strdup(name
);
91 static void vlock_plugin_set_property(GObject
*object
,
96 VlockPlugin
*self
= VLOCK_PLUGIN(object
);
100 case PROP_VLOCK_PLUGIN_NAME
:
102 vlock_plugin_set_name(self
, g_value_get_string(value
));
105 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, property_id
, pspec
);
110 /* Get properties. */
111 static void vlock_plugin_get_property(GObject
*object
,
116 VlockPlugin
*self
= VLOCK_PLUGIN(object
);
120 case PROP_VLOCK_PLUGIN_NAME
:
121 g_value_set_string(value
, self
->name
);
124 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, property_id
, pspec
);
129 /* Initialize plugin class. */
130 static void vlock_plugin_class_init(VlockPluginClass
*klass
)
132 GObjectClass
*gobject_class
= G_OBJECT_CLASS(klass
);
133 GParamSpec
*vlock_plugin_param_spec
;
135 /* Virtual methods. */
137 klass
->call_hook
= NULL
;
139 /* Install overridden methods. */
140 gobject_class
->constructor
= vlock_plugin_constructor
;
141 gobject_class
->finalize
= vlock_plugin_finalize
;
142 gobject_class
->set_property
= vlock_plugin_set_property
;
143 gobject_class
->get_property
= vlock_plugin_get_property
;
145 /* Install properties. */
146 vlock_plugin_param_spec
= g_param_spec_string(
149 "Set the plugin's name",
151 G_PARAM_CONSTRUCT_ONLY
| G_PARAM_READWRITE
154 g_object_class_install_property(
156 PROP_VLOCK_PLUGIN_NAME
,
157 vlock_plugin_param_spec
161 bool vlock_plugin_open(VlockPlugin
*self
, GError
**error
)
163 VlockPluginClass
*klass
= VLOCK_PLUGIN_GET_CLASS(self
);
164 g_assert(klass
->open
!= NULL
);
165 return klass
->open(self
, error
);
168 bool vlock_plugin_call_hook(VlockPlugin
*self
, const gchar
*hook_name
)
170 VlockPluginClass
*klass
= VLOCK_PLUGIN_GET_CLASS(self
);
171 g_assert(klass
->call_hook
!= NULL
);
172 return klass
->call_hook(self
, hook_name
);