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
)
36 /* Create new plugin object. */
37 static GObject
*vlock_plugin_constructor(
40 GObjectConstructParam
*properties
)
42 GObjectClass
*parent_class
= G_OBJECT_CLASS(vlock_plugin_parent_class
);
43 GObject
*object
= parent_class
->constructor(gtype
, n_properties
, properties
);
44 VlockPlugin
*self
= VLOCK_PLUGIN(object
);
46 g_return_val_if_fail(self
->name
!= NULL
, NULL
);
51 /* Destroy plugin object. */
52 static void vlock_plugin_finalize(GObject
*object
)
54 VlockPlugin
*self
= VLOCK_PLUGIN(object
);
59 /* Destroy dependency lists. */
60 for (size_t i
= 0; i
< nr_dependencies
; i
++) {
61 while (self
->dependencies
[i
] != NULL
) {
62 g_free(self
->dependencies
[i
]->data
);
63 self
->dependencies
[i
] = g_list_delete_link(self
->dependencies
[i
], self
->dependencies
[i
]);
67 G_OBJECT_CLASS(vlock_plugin_parent_class
)->finalize(object
);
73 PROP_VLOCK_PLUGIN_NAME
76 static void vlock_plugin_set_name(VlockPlugin
*self
, const gchar
*name
)
78 /* For security plugin names must not contain a slash. */
79 char *last_slash
= strrchr(name
, '/');
81 if (last_slash
!= NULL
)
84 self
->name
= g_strdup(name
);
88 static void vlock_plugin_set_property(
94 VlockPlugin
*self
= VLOCK_PLUGIN(object
);
98 case PROP_VLOCK_PLUGIN_NAME
:
100 vlock_plugin_set_name(self
, g_value_get_string(value
));
103 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, property_id
, pspec
);
108 /* Get properties. */
109 static void vlock_plugin_get_property(
115 VlockPlugin
*self
= VLOCK_PLUGIN(object
);
119 case PROP_VLOCK_PLUGIN_NAME
:
120 g_value_set_string(value
, self
->name
);
123 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, property_id
, pspec
);
128 /* Initialize plugin class. */
129 static void vlock_plugin_class_init(VlockPluginClass
*klass
)
131 GObjectClass
*gobject_class
= G_OBJECT_CLASS(klass
);
132 GParamSpec
*vlock_plugin_param_spec
;
134 /* Virtual methods. */
136 klass
->call_hook
= NULL
;
138 /* Install overridden methods. */
139 gobject_class
->constructor
= vlock_plugin_constructor
;
140 gobject_class
->finalize
= vlock_plugin_finalize
;
141 gobject_class
->set_property
= vlock_plugin_set_property
;
142 gobject_class
->get_property
= vlock_plugin_get_property
;
144 /* Install properties. */
145 vlock_plugin_param_spec
= g_param_spec_string(
148 "Set the plugin's name",
150 G_PARAM_CONSTRUCT_ONLY
| G_PARAM_READWRITE
153 g_object_class_install_property(
155 PROP_VLOCK_PLUGIN_NAME
,
156 vlock_plugin_param_spec
160 bool vlock_plugin_open(VlockPlugin
*self
, GError
**error
)
162 VlockPluginClass
*klass
= VLOCK_PLUGIN_GET_CLASS(self
);
163 g_assert(klass
->open
!= NULL
);
164 return klass
->open(self
, error
);
167 bool vlock_plugin_call_hook(VlockPlugin
*self
, const gchar
*hook_name
)
169 VlockPluginClass
*klass
= VLOCK_PLUGIN_GET_CLASS(self
);
170 g_assert(klass
->call_hook
!= NULL
);
171 return klass
->call_hook(self
, hook_name
);