1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
|
#ifndef _E_PLUGIN_H
#define _E_PLUGIN_H
#include <glib.h>
#include <glib-object.h>
#include <libxml/tree.h>
/* ********************************************************************** */
typedef struct _EPlugin EPlugin;
typedef struct _EPluginClass EPluginClass;
#define E_PLUGIN_CLASSID "org.gnome.evolution.plugin"
/* Structure to define the author(s) names and addresses */
typedef struct _EPluginAuthor EPluginAuthor;
struct _EPluginAuthor {
char *name;
char *email;
};
/**
* struct _EPlugin - An EPlugin instance.
*
* @object: Superclass.
* @id: Unique identifier for plugin instance.
* @path: Filename where the xml definition resides.
* @hooks_pending: A list hooks which can't yet be loaded. This is
* the xmlNodePtr to the root node of the hook definition.
* @description: A description of the plugin's purpose.
* @name: The name of the plugin.
* @domain: The translation domain for this plugin.
* @hooks: A list of the EPluginHooks this plugin requires.
* @enabled: Whether the plugin is enabled or not. This is not fully
* implemented.
*
* The base EPlugin object is used to represent each plugin directly.
* All of the plugin's hooks are loaded and managed through this
* object.
**/
struct _EPlugin {
GObject object;
char *id;
char *path;
GSList *hooks_pending;
char *description;
char *name;
char *domain;
GSList *hooks;
GSList *authors; /* EPluginAuthor structures */
guint enabled:1;
};
/**
* struct _EPluginClass -
*
* @class: Superclass.
* @type: The plugin type. This is used by the plugin loader to
* determine which plugin object to instantiate to handle the plugin.
* This must be overriden by each subclass to provide a unique name.
* @construct: The construct virtual method scans the XML tree to
* initialise itself.
* @invoke: The invoke virtual method loads the plugin code, resolves
* the function name, and marshals a simple pointer to execute the
* plugin.
* @enable: Virtual method to enable/disable the plugin.
*
* The EPluginClass represents each plugin type. The type of each class is
* registered in a global table and is used to instantiate a
* container for each plugin.
*
* It provides two main functions, to load the plugin definition, and
* to invoke a function. Each plugin class is used to handle mappings
* to different languages.
**/
struct _EPluginClass {
GObjectClass class;
const char *type;
int (*construct)(EPlugin *, xmlNodePtr root);
void *(*invoke)(EPlugin *, const char *name, void *data);
void (*enable)(EPlugin *, int state);
};
GType e_plugin_get_type(void);
int e_plugin_construct(EPlugin *ep, xmlNodePtr root);
void e_plugin_add_load_path(const char *);
int e_plugin_load_plugins(void);
GSList * e_plugin_list_plugins(void);
void e_plugin_register_type(GType type);
void *e_plugin_invoke(EPlugin *ep, const char *name, void *data);
void e_plugin_enable(EPlugin *eph, int state);
/* static helpers */
/* maps prop or content to 'g memory' */
char *e_plugin_xml_prop(xmlNodePtr node, const char *id);
char *e_plugin_xml_prop_domain(xmlNodePtr node, const char *id, const char *domain);
int e_plugin_xml_int(xmlNodePtr node, const char *id, int def);
char *e_plugin_xml_content(xmlNodePtr node);
char *e_plugin_xml_content_domain(xmlNodePtr node, const char *domain);
/* ********************************************************************** */
#include <gmodule.h>
typedef struct _EPluginLib EPluginLib;
typedef struct _EPluginLibClass EPluginLibClass;
/* The callback signature used for epluginlib methods */
typedef void *(*EPluginLibFunc)(EPluginLib *ep, void *data);
/* The setup method, this will be called when the plugin is
* initialised. In the future it may also be called when the plugin
* is disabled. */
typedef int (*EPluginLibEnableFunc)(EPluginLib *ep, int enable);
/**
* struct _EPluginLib -
*
* @plugin: Superclass.
* @location: The filename of the shared object.
* @module: The GModule once it is loaded.
*
* This is a concrete EPlugin class. It loads and invokes dynamically
* loaded libraries using GModule. The shared object isn't loaded
* until the first callback is invoked.
*
* When the plugin is loaded, and if it exists, "e_plugin_lib_enable"
* will be invoked to initialise the
**/
struct _EPluginLib {
EPlugin plugin;
char *location;
GModule *module;
};
/**
* struct _EPluginLibClass -
*
* @plugin_class: Superclass.
*
* The plugin library needs no additional class data.
**/
struct _EPluginLibClass {
EPluginClass plugin_class;
};
GType e_plugin_lib_get_type(void);
/* ********************************************************************** */
typedef struct _EPluginHook EPluginHook;
typedef struct _EPluginHookClass EPluginHookClass;
/* utilities for subclasses to use */
typedef struct _EPluginHookTargetMap EPluginHookTargetMap;
typedef struct _EPluginHookTargetKey EPluginHookTargetKey;
/**
* struct _EPluginHookTargetKey -
*
* @key: Enumeration value as a string.
* @value: Enumeration value as an integer.
*
* A multi-purpose string to id mapping structure used with various
* helper functions to simplify plugin hook subclassing.
**/
struct _EPluginHookTargetKey {
const char *key;
guint32 value;
};
/**
* struct _EPluginHookTargetMap -
*
* @type: The string id of the target.
* @id: The integer id of the target. Maps directly to the type field
* of the various plugin type target id's.
* @mask_bits: A zero-fill terminated array of EPluginHookTargetKeys.
*
* Used by EPluginHook to define mappings of target type enumerations
* to and from strings. Also used to define the mask option names
* when reading the XML plugin hook definitions.
**/
struct _EPluginHookTargetMap {
const char *type;
int id;
const struct _EPluginHookTargetKey *mask_bits; /* null terminated array */
};
/**
* struct _EPluginHook - A plugin hook.
*
* @object: Superclass.
* @plugin: The parent object.
*
* An EPluginHook is used as a container for each hook a given plugin
* is listening to.
**/
struct _EPluginHook {
GObject object;
struct _EPlugin *plugin;
};
/**
* struct _EPluginHookClass -
*
* @class: Superclass.
* @id: The plugin hook type. This must be overriden by each subclass
* and is used as a key when loading hook definitions. This string
* should contain a globally unique name followed by a : and a version
* specification. This is to ensure plugins only hook into hooks with
* the right API.
* @construct: Virtual method used to initialise the object when
* loaded.
* @enable: Virtual method used to enable or disable the hook.
*
* The EPluginHookClass represents each hook type. The type of the
* class is registered in a global table and is used to instantiate a
* container for each hook.
**/
struct _EPluginHookClass {
GObjectClass class;
const char *id;
int (*construct)(EPluginHook *eph, EPlugin *ep, xmlNodePtr root);
void (*enable)(EPluginHook *eph, int state);
};
GType e_plugin_hook_get_type(void);
void e_plugin_hook_register_type(GType type);
EPluginHook * e_plugin_hook_new(EPlugin *ep, xmlNodePtr root);
void e_plugin_hook_enable(EPluginHook *eph, int state);
/* static methods */
guint32 e_plugin_hook_mask(xmlNodePtr root, const struct _EPluginHookTargetKey *map, const char *prop);
guint32 e_plugin_hook_id(xmlNodePtr root, const struct _EPluginHookTargetKey *map, const char *prop);
/* ********************************************************************** */
/* EPluginTypeHook lets a plugin register a new plugin type.
<hook class="org.gnome.evolution.plugin.type:1.0">
<plugin-type get-type="e_plugin_mono_get_type/>
</hook>
*/
typedef struct _EPluginTypeHook EPluginTypeHook;
typedef struct _EPluginTypeHookClass EPluginTypeHookClass;
struct _EPluginTypeHook {
EPluginHook hook;
char *get_type;
guint idle;
};
struct _EPluginTypeHookClass {
EPluginHookClass hook_class;
};
GType e_plugin_type_hook_get_type(void);
#endif /* ! _E_PLUGIN_H */
|