diff options
-rw-r--r-- | .gitignore | 31 | ||||
-rw-r--r-- | docs/.gitignore | 1 | ||||
-rw-r--r-- | libohm/.gitignore | 9 | ||||
-rw-r--r-- | ohmd/.gitignore | 11 | ||||
-rw-r--r-- | ohmd/Makefile.am | 12 | ||||
-rw-r--r-- | ohmd/ohm-conf.c | 113 | ||||
-rw-r--r-- | ohmd/ohm-conf.h | 9 | ||||
-rw-r--r-- | ohmd/ohm-keystore.c | 4 | ||||
-rw-r--r-- | ohmd/ohm-marshal.list | 1 | ||||
-rw-r--r-- | ohmd/ohm-module.c | 107 | ||||
-rw-r--r-- | ohmd/ohm-module.h | 1 | ||||
-rw-r--r-- | ohmd/ohm-plugin.c | 267 | ||||
-rw-r--r-- | ohmd/ohm-plugin.h | 104 | ||||
-rw-r--r-- | plugins/.gitignore | 8 | ||||
-rw-r--r-- | plugins/ohm-plugin-battery.c | 48 | ||||
-rw-r--r-- | po/.gitignore | 9 |
16 files changed, 520 insertions, 215 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6b7a317 --- /dev/null +++ b/.gitignore @@ -0,0 +1,31 @@ +Makefile +Makefile.in +aclocal.m4 +autom4te.cache +ChangeLog +config.guess +config.h +config.h.in +config.log +config.status +config.sub +configure +ohm.conf +ohm.pc +libtool +ltmain.sh +stamp-h1 +intltool-extract +intltool-extract.in +intltool-merge +intltool-merge.in +intltool-update +intltool-update.in +mkinstalldirs +depcomp +install-sh +missing +INSTALL +*.o +*.tar.gz +*~ diff --git a/docs/.gitignore b/docs/.gitignore new file mode 100644 index 0000000..46aff8f --- /dev/null +++ b/docs/.gitignore @@ -0,0 +1 @@ +index.xml diff --git a/libohm/.gitignore b/libohm/.gitignore new file mode 100644 index 0000000..b5ad247 --- /dev/null +++ b/libohm/.gitignore @@ -0,0 +1,9 @@ +.deps +.libs +Makefile +Makefile.in +libohm-test +*.la +*.lo +*.o +*~ diff --git a/ohmd/.gitignore b/ohmd/.gitignore new file mode 100644 index 0000000..e2457eb --- /dev/null +++ b/ohmd/.gitignore @@ -0,0 +1,11 @@ +.deps +.libs +Makefile +Makefile.in +ohmd +ohm-marshal.c +ohm-marshal.h +ohm-dbus-*.h +*.o +*~ +massif.* diff --git a/ohmd/Makefile.am b/ohmd/Makefile.am index 4d603a3..8530801 100644 --- a/ohmd/Makefile.am +++ b/ohmd/Makefile.am @@ -20,15 +20,26 @@ ohmd_SOURCES = \ ohm-keystore.h \ ohm-conf.c \ ohm-conf.h \ + ohm-marshal.h \ + ohm-marshal.c \ ohm-manager.c \ ohm-manager.h \ ohm-main.c ohmd_LDADD = $(DBUS_LIBS) $(GTHREAD_LIBS) $(GMODULE_LIBS) BUILT_SOURCES = \ + ohm-marshal.c \ + ohm-marshal.h \ ohm-dbus-manager.h \ ohm-dbus-keystore.h +ohm-marshal.c: ohm-marshal.list + echo "#include \"ohm-marshal.h\"" > $@ && \ + @GLIB_GENMARSHAL@ $< --prefix=ohm_marshal --body >> $@ + +ohm-marshal.h: ohm-marshal.list + @GLIB_GENMARSHAL@ $< --prefix=ohm_marshal --header > $@ + ohm-dbus-manager.h: ohm-dbus-manager.xml libtool --mode=execute dbus-binding-tool --prefix=ohm_manager --mode=glib-server --output=ohm-dbus-manager.h $(srcdir)/ohm-dbus-manager.xml @@ -38,5 +49,6 @@ ohm-dbus-keystore.h: ohm-dbus-keystore.xml CLEANFILES = $(BUILT_SOURCES) EXTRA_DIST = \ + ohm-marshal.list \ ohm-dbus-manager.xml \ ohm-dbus-keystore.xml diff --git a/ohmd/ohm-conf.c b/ohmd/ohm-conf.c index c80206f..3a579ef 100644 --- a/ohmd/ohm-conf.c +++ b/ohmd/ohm-conf.c @@ -37,6 +37,7 @@ #include <glib/gi18n.h> #include "ohm-conf.h" +#include "ohm-marshal.h" #define OHM_CONF_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), OHM_TYPE_CONF, OhmConfPrivate)) @@ -48,12 +49,12 @@ struct OhmConfPrivate typedef struct { gchar *key; gboolean public; - gboolean notify; gint *current; gint value; // use hashtable/list for multiple values for each user? } OhmConfObjectMulti; enum { + KEY_ADDED, KEY_CHANGED, LAST_SIGNAL }; @@ -93,8 +94,8 @@ ohm_conf_compare_func (gconstpointer a, gconstpointer b) **/ static void ohm_conf_to_slist_iter (gpointer key, - OhmConfObjectMulti *entry, - gpointer *user_data) + OhmConfObjectMulti *entry, + gpointer *user_data) { GSList **list = (GSList **) user_data; *list = g_slist_insert_sorted (*list, (gpointer) entry, ohm_conf_compare_func); @@ -154,16 +155,15 @@ ohm_conf_print_all (OhmConf *conf) * ohm_conf_get_key: **/ gboolean -ohm_conf_get_key (OhmConf *conf, - const gchar *key, - gint *value, - GError **error) +ohm_conf_get_key (OhmConf *conf, + const gchar *key, + gint *value, + GError **error) { OhmConfObjectMulti *entry; g_return_val_if_fail (OHM_IS_CONF (conf), FALSE); g_return_val_if_fail (key != NULL, FALSE); g_return_val_if_fail (value != NULL, FALSE); - g_return_val_if_fail (error != NULL, FALSE); if (conf->priv->keys == NULL) { *error = g_error_new (ohm_conf_error_quark (), @@ -189,54 +189,18 @@ ohm_conf_get_key (OhmConf *conf, } /** - * ohm_conf_add_notify_key: - **/ -gboolean -ohm_conf_add_notify_key (OhmConf *conf, - const gchar *key, - GError **error) -{ - OhmConfObjectMulti *entry; - g_return_val_if_fail (OHM_IS_CONF (conf), FALSE); - g_return_val_if_fail (key != NULL, FALSE); - - if (conf->priv->keys == NULL) { - *error = g_error_new (ohm_conf_error_quark (), - OHM_CONF_ERROR_INVALID, - "Conf invalid"); - return FALSE; - } - - /* try to find the key in the global conf */ - entry = g_hash_table_lookup (conf->priv->keys, key); - if (entry == NULL) { - *error = g_error_new (ohm_conf_error_quark (), - OHM_CONF_ERROR_KEY_MISSING, - "Key missing"); - return FALSE; - } - - /* start notifying */ - g_debug ("notifying of change : %s", key); - entry->notify = TRUE; - return TRUE; -} - -/** * ohm_conf_set_key: * internal set true for plugin access and false for public dbus * **/ gboolean -ohm_conf_set_key_internal (OhmConf *conf, - const gchar *key, - gint value, - gboolean internal, - GError **error) +ohm_conf_set_key_internal (OhmConf *conf, + const gchar *key, + gint value, + gboolean internal, + GError **error) { OhmConfObjectMulti *entry; - gboolean force_signal; - gboolean value_changed; g_return_val_if_fail (OHM_IS_CONF (conf), FALSE); g_return_val_if_fail (key != NULL, FALSE); @@ -258,12 +222,11 @@ ohm_conf_set_key_internal (OhmConf *conf, /* maybe point to the key in the hashtable to save memory? */ entry->key = g_strdup (key); entry->public = FALSE; - entry->notify = FALSE; entry->value = value; - /* all new keys have to have a changed signal */ - force_signal = TRUE; - value_changed = FALSE; + /* all new keys have to have an added signal */ + g_debug ("emit key-added : %s", key); + g_signal_emit (conf, signals [KEY_ADDED], 0, key, value); /* assume the setting user is the current user */ entry->current = &(entry->value); @@ -283,20 +246,13 @@ ohm_conf_set_key_internal (OhmConf *conf, g_debug ("overwrite key '%s' : %i", key, value); /* Only force signal if different */ - force_signal = FALSE; - value_changed = FALSE; if (entry->value != value) { entry->value = value; - value_changed = TRUE; + g_debug ("emit key-changed : %s", key); + g_signal_emit (conf, signals [KEY_CHANGED], 0, key, value); } } - /* set the key value and emit signal only if new, or different and watched */ - if (force_signal == TRUE || (entry->notify && value_changed)) { - g_debug ("emit key-changed : %s", key); - g_signal_emit (conf, signals [KEY_CHANGED], 0, key); - } - return TRUE; } @@ -305,10 +261,10 @@ ohm_conf_set_key_internal (OhmConf *conf, * **/ static gboolean -ohm_conf_set_public (OhmConf *conf, - const gchar *key, - gboolean public, - GError **error) +ohm_conf_set_public (OhmConf *conf, + const gchar *key, + gboolean public, + GError **error) { OhmConfObjectMulti *entry; @@ -343,9 +299,9 @@ ohm_conf_set_public (OhmConf *conf, * ohm_conf_process_line: **/ static gboolean -ohm_conf_process_line (OhmConf *conf, - const gchar *line, - const gchar *plugin_name) +ohm_conf_process_line (OhmConf *conf, + const gchar *line, + const gchar *plugin_name) { gint len; len = strlen (line); @@ -431,9 +387,9 @@ ohm_conf_process_line (OhmConf *conf, * ohm_conf_load_defaults: **/ gboolean -ohm_conf_load_defaults (OhmConf *conf, - const gchar *plugin_name, - GError **error) +ohm_conf_load_defaults (OhmConf *conf, + const gchar *plugin_name, + GError **error) { gboolean ret; gchar *contents; @@ -470,6 +426,7 @@ ohm_conf_load_defaults (OhmConf *conf, g_free (contents); return TRUE; } + /** * ohm_hash_remove_return: * FIXME: there must be a better way to do this @@ -514,14 +471,22 @@ ohm_conf_class_init (OhmConfClass *klass) GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = ohm_conf_finalize; + signals [KEY_ADDED] = + g_signal_new ("key-added", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (OhmConfClass, key_added), + NULL, NULL, + ohm_marshal_VOID__STRING_INT, + G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_INT); signals [KEY_CHANGED] = g_signal_new ("key-changed", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (OhmConfClass, key_changed), NULL, NULL, - g_cclosure_marshal_VOID__STRING, - G_TYPE_NONE, 1, G_TYPE_STRING); + ohm_marshal_VOID__STRING_INT, + G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_INT); g_type_class_add_private (klass, sizeof (OhmConfPrivate)); } diff --git a/ohmd/ohm-conf.h b/ohmd/ohm-conf.h index 2c376bf..78e25d7 100644 --- a/ohmd/ohm-conf.h +++ b/ohmd/ohm-conf.h @@ -43,8 +43,12 @@ typedef struct typedef struct { GObjectClass parent_class; + void (* key_added) (OhmConf *conf, + const gchar *key, + gint value); void (* key_changed) (OhmConf *conf, - const gchar *key); + const gchar *key, + gint value); } OhmConfClass; typedef enum @@ -69,9 +73,6 @@ gboolean ohm_conf_set_key_internal (OhmConf *conf, gint value, gboolean internal, GError **error); -gboolean ohm_conf_add_notify_key (OhmConf *conf, - const gchar *key, - GError **error); gboolean ohm_conf_load_defaults (OhmConf *conf, const gchar *pluginname, GError **error); diff --git a/ohmd/ohm-keystore.c b/ohmd/ohm-keystore.c index 78b499b..b6340e8 100644 --- a/ohmd/ohm-keystore.c +++ b/ohmd/ohm-keystore.c @@ -76,7 +76,9 @@ ohm_keystore_add_notify_key (OhmKeystore *keystore, const gchar *key, GError **error) { - return ohm_conf_add_notify_key (keystore->priv->conf, key, error); + /* do this internally to this module with a hashtable! */ + //return ohm_conf_add_notify_key (keystore->priv->conf, key, error); + return FALSE; } /** diff --git a/ohmd/ohm-marshal.list b/ohmd/ohm-marshal.list new file mode 100644 index 0000000..6880221 --- /dev/null +++ b/ohmd/ohm-marshal.list @@ -0,0 +1 @@ +NONE:STRING,INT diff --git a/ohmd/ohm-module.c b/ohmd/ohm-module.c index cf8555f..3f0fbc8 100644 --- a/ohmd/ohm-module.c +++ b/ohmd/ohm-module.c @@ -39,6 +39,7 @@ #include "ohm-module.h" #include "ohm-plugin.h" +#include "ohm-conf.h" #define OHM_MODULE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), OHM_TYPE_MODULE, OhmModulePrivate)) @@ -48,44 +49,118 @@ struct OhmModulePrivate GSList *module_suggest; GSList *module_prevent; GSList *module_loaded; + GHashTable *interested; + OhmPlugin *plugin; /* needs to be a list */ + OhmConf *conf; }; +/* used as a hash entry type to provide int-passing services to the plugin */ +typedef struct { + OhmPlugin *plugin; + gint id; +} OhmModuleNofif; + G_DEFINE_TYPE (OhmModule, ohm_module, G_TYPE_OBJECT) /** - * ohm_module_get_key: + * ohm_module_require: **/ gboolean ohm_module_require (OhmModule *module, const gchar *name) { - g_debug ("require '%s'", name); + g_debug ("module:require '%s'", name); return TRUE; } /** - * ohm_module_add_notify_key: + * ohm_module_suggest: **/ gboolean ohm_module_suggest (OhmModule *module, const gchar *name) { - g_debug ("suggest '%s'", name); + g_debug ("module:suggest '%s'", name); return TRUE; } /** - * ohm_module_set_key: + * ohm_module_prevent: * **/ gboolean ohm_module_prevent (OhmModule *module, const gchar *name) { - g_debug ("prevent '%s'", name); + g_debug ("module:prevent '%s'", name); return TRUE; } +static void +key_changed_cb (OhmConf *conf, + const gchar *key, + gint value, + OhmModule *module) +{ + GSList **entry; + GSList *l; + OhmModuleNofif *notif; + const gchar *name; + + g_debug ("module:key changed! %s : %i", key, value); + + /* if present, add to SList, if not, add to hash as slist object */ + entry = g_hash_table_lookup (module->priv->interested, key); + + /* a key has changed that none of the plugins are watching */ + if (entry == NULL) { + return; + } + + g_debug ("module:found watched key %s", key); + /* go thru the SList and notify each plugin */ + for (l=*entry; l != NULL; l=l->next) { + notif = (OhmModuleNofif *) l->data; + name = ohm_plugin_get_name (notif->plugin); + g_debug ("module:notify %s with id:%i", name, notif->id); + ohm_plugin_conf_notify (notif->plugin, notif->id, value); + } +} + +static void +add_interested_cb (OhmPlugin *plugin, + const gchar *key, + gint id, + OhmModule *module) +{ + GSList **entry; + GSList **l; + OhmModuleNofif *notif; + g_debug ("module:add interested! %s : %i", key, id); + + /* if present, add to SList, if not, add to hash as slist object */ + entry = g_hash_table_lookup (module->priv->interested, key); + + /* create a new notifier, and copy over the data */ + notif = g_new0 (OhmModuleNofif, 1); /* TODO: use gslice */ + notif->plugin = plugin; + notif->id = id; + + if (entry != NULL) { + /* already present, just append to SList */ + g_debug ("module:key already watched by someting else"); + *entry = g_slist_prepend (*entry, (gpointer) notif); + } else { + g_debug ("module:key not already watched by someting else"); + /* create the new SList andd add the new notification to it */ + l = g_new0 (GSList *, 1); + *l = NULL; + *l = g_slist_prepend (*l, (gpointer) notif); + /* fixme we need to free this g_strdup at finalize and clear the list */ + g_hash_table_insert (module->priv->interested, (gpointer) g_strdup (key), l); + } +} + /** * ohm_module_finalize: **/ @@ -97,6 +172,10 @@ ohm_module_finalize (GObject *object) g_return_if_fail (OHM_IS_MODULE (object)); module = OHM_MODULE (object); + g_hash_table_destroy (module->priv->interested); + g_object_unref (module->priv->conf); + g_object_unref (module->priv->plugin); + g_return_if_fail (module->priv != NULL); G_OBJECT_CLASS (ohm_module_parent_class)->finalize (object); } @@ -126,10 +205,18 @@ ohm_module_init (OhmModule *module) module->priv->module_prevent = NULL; module->priv->module_loaded = NULL; - /* play for now */ - OhmPlugin *plugin; - plugin = ohm_plugin_load ("libpluginbattery.so"); - ohm_plugin_unload (plugin); + module->priv->interested = g_hash_table_new (g_str_hash, g_str_equal); + + module->priv->conf = ohm_conf_new (); + g_signal_connect (module->priv->conf, "key-changed", + G_CALLBACK (key_changed_cb), module); + + /* play for now, we really need to read in from disk a list of modules to load */ + module->priv->plugin = ohm_plugin_new (); + g_signal_connect (module->priv->plugin, "add-interested", + G_CALLBACK (add_interested_cb), module); + + ohm_plugin_load (module->priv->plugin, "libpluginbattery.so"); } /** diff --git a/ohmd/ohm-module.h b/ohmd/ohm-module.h index 60254ed..0c284ba 100644 --- a/ohmd/ohm-module.h +++ b/ohmd/ohm-module.h @@ -22,6 +22,7 @@ #define __OHM_MODULE_H #include <glib-object.h> +#include "ohm-plugin.h" G_BEGIN_DECLS diff --git a/ohmd/ohm-plugin.c b/ohmd/ohm-plugin.c index 4567ad3..1488855 100644 --- a/ohmd/ohm-plugin.c +++ b/ohmd/ohm-plugin.c @@ -18,43 +18,95 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +/* Provides the bridge between the .so plugin and intraprocess communication */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <stdlib.h> +#include <stdio.h> +#include <time.h> +#include <errno.h> + #include <string.h> +#include <sys/time.h> +#include <sys/types.h> +#ifdef HAVE_UNISTD_H #include <unistd.h> -#include <glib.h> -#include <glib-object.h> +#endif /* HAVE_UNISTD_H */ + +#include <glib/gi18n.h> #include <gmodule.h> #include "ohm-plugin.h" +#include "ohm-conf.h" +#include "ohm-marshal.h" + +#define OHM_PLUGIN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), OHM_TYPE_PLUGIN, OhmPluginPrivate)) + +struct OhmPluginPrivate +{ + OhmConf *conf; + OhmPluginInfo *info; + GModule *handle; + gchar *name; +}; + +enum { + ADD_INTERESTED, + LAST_SIGNAL +}; + +static guint signals [LAST_SIGNAL] = { 0, }; + +G_DEFINE_TYPE (OhmPlugin, ohm_plugin, G_TYPE_OBJECT) -static void ohm_plugin_destroy (OhmPlugin * plugin); -static OhmPlugin *ohm_plugins_find_with_name (const gchar * name); -static GList *plugins = NULL; - #define LIBDIR "../plugins/.libs" -G_MODULE_EXPORT void -ohm_plugin_get_key (int value) +/** + * ohm_plugin_get_key: + **/ +gboolean +ohm_plugin_require (OhmPlugin *plugin, + const gchar *name) { - /* do bar things */ - g_debug ("server! %i", value); + g_debug ("require '%s'", name); + return TRUE; } -OhmPlugin * -ohm_plugin_load (const gchar *name) +/** + * ohm_plugin_add_notify_key: + **/ +gboolean +ohm_plugin_suggest (OhmPlugin *plugin, + const gchar *name) +{ + g_debug ("suggest '%s'", name); + return TRUE; +} + +/** + * ohm_plugin_set_key: + * + **/ +gboolean +ohm_plugin_prevent (OhmPlugin *plugin, + const gchar *name) +{ + g_debug ("prevent '%s'", name); + return TRUE; +} + +gboolean +ohm_plugin_load (OhmPlugin *plugin, const gchar *name) { - OhmPlugin *plugin; gchar *path; GModule *handle; - gboolean (*ohm_init_plugin) (OhmPlugin *); - - g_return_val_if_fail (name != NULL, NULL); + OhmPluginInfo * (*ohm_init_plugin) (OhmPlugin *); - plugin = ohm_plugins_find_with_name (name); - if (plugin) { - ++plugin->ref_count; - return plugin; - } + g_return_val_if_fail (name != NULL, FALSE); path = g_build_filename (LIBDIR, name, NULL); handle = g_module_open (path, 0); @@ -63,98 +115,155 @@ ohm_plugin_load (const gchar *name) } g_free (path); - if (!g_module_symbol (handle, "ohm_init_plugin", (gpointer) & ohm_init_plugin)) { + if (!g_module_symbol (handle, "ohm_init_plugin", (gpointer) &ohm_init_plugin)) { g_module_close (handle); g_error ("could not find init function in plugin\n"); } - plugin = g_new0 (OhmPlugin, 1); - plugin->info = NULL; - plugin->handle = handle; - plugin->name = g_strdup (name); - plugin->ref_count = 1; - plugins = g_list_append (plugins, plugin); - - if (!ohm_init_plugin (plugin) || plugin->info == NULL) { - g_print ("init error or no info defined"); - ohm_plugin_destroy (plugin); - return NULL; - } + plugin->priv->handle = handle; + plugin->priv->name = g_strdup (name); + plugin->priv->info = ohm_init_plugin (plugin); - if (plugin->info->load != NULL) - plugin->info->load (plugin); + if (plugin->priv->info->load != NULL) { + plugin->priv->info->load (plugin); + } - return plugin; + return TRUE; } -gboolean -ohm_plugin_unload (OhmPlugin * plugin) +const gchar * +ohm_plugin_get_name (OhmPlugin * plugin) { - g_return_val_if_fail (plugin != NULL, FALSE); - g_return_val_if_fail (plugin->ref_count > 0, FALSE); + g_return_val_if_fail (plugin != NULL, NULL); + + return plugin->priv->name; +} - if (--plugin->ref_count > 0) - return TRUE; +const gchar * +ohm_plugin_get_version (OhmPlugin * plugin) +{ + g_return_val_if_fail (plugin != NULL, NULL); - if (plugin->info->unload != NULL) - plugin->info->unload (plugin); + return plugin->priv->info->version; +} - ohm_plugin_destroy (plugin); +const gchar * +ohm_plugin_get_author (OhmPlugin * plugin) +{ + g_return_val_if_fail (plugin != NULL, NULL); - return TRUE; + return plugin->priv->info->author; } -static void -ohm_plugin_destroy (OhmPlugin * plugin) +G_MODULE_EXPORT gboolean +ohm_plugin_conf_provide (OhmPlugin *plugin, + const gchar *name) { - g_return_if_fail (plugin != NULL); + g_debug ("%s provides %s", plugin->priv->name, name); + /* TODO; check that nothing else provides this key */ + return FALSE; +} - plugins = g_list_remove (plugins, plugin); +G_MODULE_EXPORT gboolean +ohm_plugin_conf_get_key (OhmPlugin *plugin, + const gchar *key, + int *value) +{ + return ohm_conf_get_key (plugin->priv->conf, key, value, NULL); +} - if (plugin->handle != NULL) - g_module_close (plugin->handle); +G_MODULE_EXPORT gboolean +ohm_plugin_conf_set_key (OhmPlugin *plugin, + const gchar *key, + int value) +{ + return ohm_conf_set_key_internal (plugin->priv->conf, key, value, TRUE, NULL); +} - if (plugin->name != NULL) - g_free (plugin->name); +G_MODULE_EXPORT gboolean +ohm_plugin_conf_notify (OhmPlugin *plugin, + int id, + int value) +{ + plugin->priv->info->conf_notify (plugin, id, value); + return TRUE; +} - g_free (plugin); +G_MODULE_EXPORT gboolean +ohm_plugin_conf_interested (OhmPlugin *plugin, + const gchar *key, + gint id) +{ + g_debug ("%s provides wants notification of %s on signal %i", plugin->priv->name, key, id); + g_signal_emit (plugin, signals [ADD_INTERESTED], 0, key, id); + return TRUE; } -static OhmPlugin * -ohm_plugins_find_with_name (const gchar * name) +/** + * ohm_plugin_finalize: + **/ +static void +ohm_plugin_finalize (GObject *object) { OhmPlugin *plugin; - GList *l; + g_return_if_fail (object != NULL); + g_return_if_fail (OHM_IS_PLUGIN (object)); + plugin = OHM_PLUGIN (object); - for (l = plugins; l != NULL; l = l->next) { - plugin = l->data; - if (plugin->name != NULL && !strcmp (plugin->name, name)) - return plugin; - } + g_object_unref (plugin->priv->conf); + + if (plugin->priv->info->unload != NULL) + plugin->priv->info->unload (plugin); + + if (plugin->priv->handle != NULL) + g_module_close (plugin->priv->handle); - return NULL; + if (plugin->priv->name != NULL) + g_free (plugin->priv->name); + + g_return_if_fail (plugin->priv != NULL); + G_OBJECT_CLASS (ohm_plugin_parent_class)->finalize (object); } -G_CONST_RETURN gchar * -ohm_plugin_get_name (OhmPlugin * plugin) +/** + * ohm_plugin_class_init: + **/ +static void +ohm_plugin_class_init (OhmPluginClass *klass) { - g_return_val_if_fail (plugin != NULL, NULL); - - return plugin->name; + GObjectClass *object_class = G_OBJECT_CLASS (klass); + object_class->finalize = ohm_plugin_finalize; + + signals [ADD_INTERESTED] = + g_signal_new ("add-interested", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (OhmPluginClass, add_interested), + NULL, NULL, + ohm_marshal_VOID__STRING_INT, + G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_INT); + + g_type_class_add_private (klass, sizeof (OhmPluginPrivate)); } -G_CONST_RETURN gchar * -ohm_plugin_get_version (OhmPlugin * plugin) +/** + * ohm_plugin_init: + **/ +static void +ohm_plugin_init (OhmPlugin *plugin) { - g_return_val_if_fail (plugin != NULL, NULL); + plugin->priv = OHM_PLUGIN_GET_PRIVATE (plugin); - return plugin->info->version; + plugin->priv->conf = ohm_conf_new (); } -G_CONST_RETURN gchar * -ohm_plugin_get_author (OhmPlugin * plugin) +/** + * ohm_plugin_new: + **/ +OhmPlugin * +ohm_plugin_new (void) { - g_return_val_if_fail (plugin != NULL, NULL); - - return plugin->info->author; + OhmPlugin *plugin; + plugin = g_object_new (OHM_TYPE_PLUGIN, NULL); + return OHM_PLUGIN (plugin); } diff --git a/ohmd/ohm-plugin.h b/ohmd/ohm-plugin.h index 38fa94e..8ed2f72 100644 --- a/ohmd/ohm-plugin.h +++ b/ohmd/ohm-plugin.h @@ -18,43 +18,83 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef SERVER_H -#define SERVER_H +#ifndef __OHM_PLUGIN_H +#define __OHM_PLUGIN_H #include <glib-object.h> +#include "ohm-plugin.h" -void ohm_plugin_get_key (int value); +G_BEGIN_DECLS -typedef struct _OhmPlugin OhmPlugin; -typedef struct _OhmPluginInfo OhmPluginInfo; +#define OHM_TYPE_PLUGIN (ohm_plugin_get_type ()) +#define OHM_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), OHM_TYPE_PLUGIN, OhmPlugin)) +#define OHM_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), OHM_TYPE_PLUGIN, OhmPluginClass)) +#define OHM_IS_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), OHM_TYPE_PLUGIN)) +#define OHM_IS_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), OHM_TYPE_PLUGIN)) +#define OHM_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), OHM_TYPE_PLUGIN, OhmPluginClass)) -struct _OhmPluginInfo { +typedef struct OhmPluginPrivate OhmPluginPrivate; + +typedef struct +{ + GObject parent; + OhmPluginPrivate *priv; +} OhmPlugin; + +typedef struct +{ + GObjectClass parent_class; + void (* add_interested) (OhmPlugin *plugin, + const gchar *key, + gint id); +} OhmPluginClass; + +typedef struct { gchar *description; gchar *version; gchar *author; - void (*load) (OhmPlugin * plugin); - void (*unload) (OhmPlugin * plugin); -}; - -struct _OhmPlugin { - OhmPluginInfo *info; - GType type; - GModule *handle; - gchar *name; - guint ref_count; -}; - -#define OHM_INIT_PLUGIN(initfunc, plugininfo) \ -G_MODULE_EXPORT gboolean ohm_init_plugin(OhmPlugin *plugin) { \ - plugin->info = &(plugininfo); \ - return initfunc((plugin)); \ -} - -OhmPlugin *ohm_plugin_load (const gchar * name); -gboolean ohm_plugin_unload (OhmPlugin * plugin); - -G_CONST_RETURN gchar *ohm_plugin_get_name (OhmPlugin * plugin); -G_CONST_RETURN gchar *ohm_plugin_get_version (OhmPlugin * plugin); -G_CONST_RETURN gchar *ohm_plugin_get_author (OhmPlugin * plugin); - -#endif /* SERVER_H */ + void (*load) (OhmPlugin *plugin); + void (*unload) (OhmPlugin *plugin); + void (*conf_notify) (OhmPlugin *plugin, gint id, gint value); +} OhmPluginInfo; + +#define OHM_INIT_PLUGIN(plugininfo) G_MODULE_EXPORT OhmPluginInfo *ohm_init_plugin (OhmPlugin *plugin) {return &(plugin_info);} + +GType ohm_plugin_get_type (void); +OhmPlugin *ohm_plugin_new (void); + +gboolean ohm_plugin_load (OhmPlugin *plugin, + const gchar *name); + +gboolean ohm_plugin_require (OhmPlugin *plugin, + const gchar *name); +gboolean ohm_plugin_suggest (OhmPlugin *plugin, + const gchar *name); +gboolean ohm_plugin_prevent (OhmPlugin *plugin, + const gchar *name); + +const gchar *ohm_plugin_get_name (OhmPlugin *plugin); +const gchar *ohm_plugin_get_version (OhmPlugin *plugin); +const gchar *ohm_plugin_get_author (OhmPlugin *plugin); + +/* used by plugin to manager */ +gboolean ohm_plugin_conf_provide (OhmPlugin *plugin, + const gchar *name); +gboolean ohm_plugin_conf_get_key (OhmPlugin *plugin, + const gchar *key, + gint *value); +gboolean ohm_plugin_conf_set_key (OhmPlugin *plugin, + const gchar *key, + gint value); +gboolean ohm_plugin_conf_interested (OhmPlugin *plugin, + const gchar *key, + gint id); + +/* used by manager to plugin */ +gboolean ohm_plugin_conf_notify (OhmPlugin *plugin, + gint id, + gint value); + +G_END_DECLS + +#endif /* __OHM_PLUGIN_H */ diff --git a/plugins/.gitignore b/plugins/.gitignore new file mode 100644 index 0000000..0ec65bf --- /dev/null +++ b/plugins/.gitignore @@ -0,0 +1,8 @@ +.deps +.libs +Makefile +Makefile.in +*.la +*.lo +*.o +*~ diff --git a/plugins/ohm-plugin-battery.c b/plugins/ohm-plugin-battery.c index 2f1e179..42e34b5 100644 --- a/plugins/ohm-plugin-battery.c +++ b/plugins/ohm-plugin-battery.c @@ -23,32 +23,50 @@ #include "../ohmd/ohm-plugin.h" -static gboolean -init_plugin (OhmPlugin *plugin) -{ - g_debug ("plugin init"); - return TRUE; -} +enum { + CONF_SOMETHINGBACKLIGHTCHANGED = 666, + CONF_LAST +}; static void load_plugin (OhmPlugin *plugin) { - g_debug ("load plugin"); - ohm_plugin_get_key (888); + g_debug ("plug:load plugin %p", plugin); + gint value; + ohm_plugin_conf_provide (plugin, "battery.percentage"); + ohm_plugin_conf_set_key (plugin, "battery.percentage", 99); + ohm_plugin_conf_get_key (plugin, "battery.percentage", &value); + + /* these don't have to be one enum per key, you can clump them as classes */ + ohm_plugin_conf_interested (plugin, "backlight.value_foo", CONF_SOMETHINGBACKLIGHTCHANGED); + ohm_plugin_conf_interested (plugin, "backlight.value_idle", CONF_SOMETHINGBACKLIGHTCHANGED); + + g_debug ("plug:got conf from plugin! %i", value); } static void unload_plugin (OhmPlugin *plugin) { - g_debug ("unload plugin"); + g_debug ("plug:unload plugin"); +} + +static void +conf_notify (OhmPlugin *plugin, gint id, gint value) +{ + g_debug ("plug:conf_notify %i: %i", id, value); + /* using an integer enumeration is much faster than a load of strcmp's */ + if (id == CONF_SOMETHINGBACKLIGHTCHANGED) { + g_error ("plug:backlight changed, so maybe we need to update something or re-evaluate policy"); + } } static OhmPluginInfo plugin_info = { - "Ohm RTP plugin", /* description */ - "0.1.0", /* version */ - "richard@hughsie.com", /* author */ - load_plugin, /* load */ - unload_plugin, /* unload */ + "OHM HAL Battery", /* description */ + "0.0.1", /* version */ + "richard@hughsie.com", /* author */ + load_plugin, /* load */ + unload_plugin, /* unload */ + conf_notify, /* conf_notify */ }; -OHM_INIT_PLUGIN (init_plugin, plugin_info); +OHM_INIT_PLUGIN (plugin_info); diff --git a/po/.gitignore b/po/.gitignore new file mode 100644 index 0000000..667920d --- /dev/null +++ b/po/.gitignore @@ -0,0 +1,9 @@ +*.gmo +*.mo +*.pot +Makefile +Makefile.in +POTFILES +*.o +stamp-it +*~ |