Heraia  0.1.8
plugin.h
Go to the documentation of this file.
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /*
3  plugin.h
4  heraia - an hexadecimal file editor and analyser based on ghex
5 
6  (C) Copyright 2007 - 2011 Olivier Delhomme
7  e-mail : heraia@delhomme.org
8  URL : http://heraia.tuxfamily.org
9 
10  This program is free software; you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation; either version 2, or (at your option)
13  any later version.
14 
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with this program; if not, write to the Free Software
22  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 */
24 /**
25  * @file plugin.h
26  * Header file where plugin definitions are sat
27  */
28 #ifndef _HERAIA_PLUGIN_H_
29 #define _HERAIA_PLUGIN_H_
30 
31 /* Based on the gscore plugin interface */
32 
33 /**
34  * @def HERAIA_PLUGIN_API_VERSION
35  * API Version to use to verify within the plugin that the interface is what
36  * expected
37  */
38 #define HERAIA_PLUGIN_API_VERSION 1
39 
40 /**
41  * Plugin types.
42  */
43 typedef enum
44 {
45  HERAIA_PLUGIN_UNKNOWN = -1, /**< Unknown type */
46  HERAIA_PLUGIN_FILTER = 0, /**< Filter plugin */
47  HERAIA_PLUGIN_ACTION = 1, /**< Action plugin */
48 } PluginType;
49 
50 
51 /**
52  * May indicate the plugin state
53  */
54 typedef enum
55 {
62 } PluginState;
63 
64 
65 /* plugins functions */
66 typedef void (* InitProc) (heraia_struct_t *); /* Called once when the plugin is loaded */
67 typedef void (* QuitProc) (void); /* Called once when the plugin is unloaded */
68 typedef void (* RunProc) (GtkWidget *, gpointer); /* Called via the menu interface */
69 typedef void (* RefreshProc) (heraia_struct_t *, void *); /* Called every time that the cursor position changes */
70 /* this double structure is here to improve speed avoiding a list search */
71 
72 
73 /**
74  * Priorities ...
75  * @def HERAIA_PRIORITY_DEFAULT
76  * Default priority
77  *
78  * @def HERAIA_PRIORITY_HIGHEST
79  * highest priority
80  *
81  * @def HERAIA_PRIORITY_LOWEST
82  * lowest priority
83  *
84  * @note do we use this ?
85  */
86 typedef int PluginPriority;
87 #define HERAIA_PRIORITY_DEFAULT 0
88 #define HERAIA_PRIORITY_HIGHEST 9999
89 #define HERAIA_PRIORITY_LOWEST -9999
90 
91 
92 /**
93  * import / export and filters functions this may change quickly
94  */
95 /* returns false on error when loading */
96 typedef gboolean (* ImportFunction) (const gchar *filename, void *user_data);
97 
98 
99 /* returns false on error when saving */
100 typedef gboolean (* ExportFunction) (const gchar *filename, void *user_data);
101 
102 
103 /* this structure may change as the filters may not only be
104  * import / exports functions to load / save files but also
105  * filters (as in signal treatment) to do things on a file.
106  */
107 typedef struct
108 {
109  char *extensions;
110 
114 
115 
116 /**
117  * @struct plugin_info_t
118  * Detailed information about a plugin.
119  */
120 typedef struct
121 {
122  unsigned int api_version;
125  unsigned int id;
126 
127  char *name;
128  char *version;
129  char *summary;
130  char *description;
131  char *author;
132  char *homepage;
133 
134 } plugin_info_t;
135 
136 
137 /**
138  * @struct heraia_plugin_t
139  * Complete plugin structure.
140  */
141 typedef struct
142 {
143  PluginState state; /**< The state of the plugin */
144  GModule *handle; /**< The module handle */
145  char *path; /**< The path to the plugin */
146  char *filename; /**< Filename of the plugin */
147  plugin_info_t *info; /**< The plugin information */
148  plugin_filter_t *filter; /**< The plugin filter */
149  char *error; /**< last error message */
150  void *extra; /**< Plugin-specific data */
151 
152  InitProc init_proc; /**< Called when the application initialy starts up */
153  QuitProc quit_proc; /**< Called when the application exits */
154  RunProc run_proc; /**< Called to run an interface everytime the plugin is called */
155  RefreshProc refresh_proc; /**< Called when the cursor changes it's position */
156 
157  GtkCheckMenuItem *cmi_entry; /**< The CheckMenuItem that may be created in the heraia interface */
158  GtkBuilder *xml; /**< Eventually the plugin's GtkBuilder XML interface */
159  window_prop_t *win_prop; /**< Stores the window's properties */
161 
162 
163 /* Usefull plugins related functions provided */
164 /* to be used within the plugins themselves */
165 /* or the main program ! */
166 extern gboolean plugin_capable(void);
167 extern heraia_plugin_t *new_plugin(void);
168 extern void free_plugin(heraia_plugin_t *plugin);
169 extern void load_plugins(heraia_struct_t *main_struct);
170 extern void add_entry_to_plugins_menu(heraia_struct_t *main_struct, heraia_plugin_t *plugin);
171 extern heraia_plugin_t *find_plugin_by_name(GList *plugins_list, gchar *name);
172 extern gboolean load_plugin_xml(heraia_struct_t *main_struct, heraia_plugin_t *plugin);
173 extern void refresh_all_plugins(heraia_struct_t *main_struct);
174 
175 #endif /* _HERAIA_PLUGIN_H_ */
void(* QuitProc)(void)
Definition: plugin.h:67
gboolean(* ExportFunction)(const gchar *filename, void *user_data)
Definition: plugin.h:100
This is the main structure.
Definition: libheraia.h:332
Window properties.
Definition: libheraia.h:243
RefreshProc refresh_proc
Called when the cursor changes it's position.
Definition: plugin.h:155
heraia_plugin_t * find_plugin_by_name(GList *plugins_list, gchar *name)
Finds the desired plugin by its name and return the plugin structure or NULL.
Definition: plugin.c:323
Filter plugin.
Definition: plugin.h:46
gboolean plugin_capable(void)
Says whether the system can handle plugins (or not)
Definition: plugin.c:43
GtkBuilder * xml
Eventually the plugin's GtkBuilder XML interface.
Definition: plugin.h:158
void add_entry_to_plugins_menu(heraia_struct_t *main_struct, heraia_plugin_t *plugin)
adds a menu entry to the plugin menu adds a signal handler when the menu is toggled ...
Definition: plugin.c:296
InitProc init_proc
Called when the application initialy starts up.
Definition: plugin.h:152
PluginState
May indicate the plugin state.
Definition: plugin.h:54
gboolean(* ImportFunction)(const gchar *filename, void *user_data)
import / export and filters functions this may change quickly
Definition: plugin.h:96
plugin_info_t * info
The plugin information.
Definition: plugin.h:147
RunProc run_proc
Called to run an interface everytime the plugin is called.
Definition: plugin.h:154
PluginType
Plugin types.
Definition: plugin.h:43
Unknown type.
Definition: plugin.h:45
void(* RunProc)(GtkWidget *, gpointer)
Definition: plugin.h:68
window_prop_t * win_prop
Stores the window's properties.
Definition: plugin.h:159
char * version
Definition: plugin.h:128
PluginPriority priority
Definition: plugin.h:124
void load_plugins(heraia_struct_t *main_struct)
looks at the plugins dir(s) and loads the needed plugins (all ;-) (one at a time !!) ...
Definition: plugin.c:258
GModule * handle
The module handle.
Definition: plugin.h:144
char * description
Definition: plugin.h:130
void refresh_all_plugins(heraia_struct_t *main_struct)
To help the main program to send events to the plugins.
Definition: plugin.c:378
void * extra
Plugin-specific data.
Definition: plugin.h:150
char * extensions
Definition: plugin.h:109
char * summary
Definition: plugin.h:129
PluginType type
Definition: plugin.h:123
heraia_plugin_t * new_plugin(void)
Creates a new empty plugin it may be initialised by the plugin itself !
Definition: plugin.c:56
void(* InitProc)(heraia_struct_t *)
Definition: plugin.h:66
void free_plugin(heraia_plugin_t *plugin)
free an unused plugin use with caution
Definition: plugin.c:88
gboolean load_plugin_xml(heraia_struct_t *main_struct, heraia_plugin_t *plugin)
Loads the xml's definition file that describes the plugin (.gtkbuilder suffix) tries the paths found ...
Definition: plugin.c:356
int PluginPriority
Definition: plugin.h:86
char * name
Definition: plugin.h:127
ExportFunction export
Definition: plugin.h:112
PluginState state
The state of the plugin.
Definition: plugin.h:143
char * author
Definition: plugin.h:131
Complete plugin structure.
Definition: plugin.h:141
Detailed information about a plugin.
Definition: plugin.h:120
char * homepage
Definition: plugin.h:132
QuitProc quit_proc
Called when the application exits.
Definition: plugin.h:153
unsigned int id
Definition: plugin.h:125
void(* RefreshProc)(heraia_struct_t *, void *)
Definition: plugin.h:69
char * error
last error message
Definition: plugin.h:149
Action plugin.
Definition: plugin.h:47
plugin_filter_t * filter
The plugin filter.
Definition: plugin.h:148
char * filename
Filename of the plugin.
Definition: plugin.h:146
char * path
The path to the plugin.
Definition: plugin.h:145
GtkCheckMenuItem * cmi_entry
The CheckMenuItem that may be created in the heraia interface.
Definition: plugin.h:157
unsigned int api_version
Definition: plugin.h:122