plugin.h

Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
00002 /*
00003   plugin.h
00004   heraia - an hexadecimal file editor and analyser based on ghex
00005  
00006   (C) Copyright 2007 Olivier Delhomme
00007   e-mail : heraia@delhomme.org
00008   URL    : http://heraia.tuxfamily.org
00009  
00010   This program is free software; you can redistribute it and/or modify
00011   it under the terms of the GNU General Public License as published by
00012   the Free Software Foundation; either version 2, or  (at your option) 
00013   any later version.
00014  
00015   This program is distributed in the hope that it will be useful,
00016   but WITHOUT ANY WARRANTY;  without even the implied warranty of
00017   MERCHANTABILITY  or  FITNESS FOR A PARTICULAR PURPOSE.  See the
00018   GNU General Public License for more details.
00019  
00020   You should have received a copy of the GNU General Public License
00021   along with this program; if not, write to the Free Software
00022   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00023 */
00024 /**
00025  * @file plugin.h
00026  *  Header file where plugin definitions are sat
00027  */
00028 #ifndef _HERAIA_PLUGIN_H_
00029 #define _HERAIA_PLUGIN_H_
00030 
00031 /* Based on the gscore plugin interface */
00032 
00033 /**
00034  * @def HERAIA_PLUGIN_API_VERSION
00035  * API Version to use to verify within the plugin that the interface is what
00036  * expected
00037  */
00038 #define HERAIA_PLUGIN_API_VERSION 1
00039 
00040 /**
00041  * Plugin types.
00042  */
00043 typedef enum
00044 {
00045         HERAIA_PLUGIN_UNKNOWN  = -1,  /**< Unknown type   */
00046         HERAIA_PLUGIN_FILTER = 0,     /**< Filter plugin  */
00047         HERAIA_PLUGIN_ACTION = 1,     /**< Action plugin  */
00048 } PluginType;
00049 
00050 /**
00051  *  May indicate the plugin state
00052  */
00053 typedef enum
00054 {
00055         PLUGIN_STATE_RUNNING,
00056         PLUGIN_STATE_INITIALIZING,
00057         PLUGIN_STATE_LOADED,
00058         PLUGIN_STATE_NEW,
00059         PLUGIN_STATE_EXITING,
00060         PLUGIN_STATE_NONE,
00061 } PluginState;
00062 
00063 /* plugins functions */
00064 typedef void (* InitProc)    (heraia_window_t *);         /* Called once when the plugin is loaded              */
00065 typedef void (* QuitProc)    (void);                      /* Called once when the plugin is unloaded            */
00066 typedef void (* RunProc)     (GtkWidget *, gpointer);     /* Called via the menu interface                      */
00067 typedef void (* RefreshProc) (heraia_window_t *, void *); /* Called every time that the cursor position changes */
00068 /* this double structure is here to improve speed avoiding a list search */
00069 
00070 
00071 /**
00072  *  Priorities ...
00073  * @def HERAIA_PRIORITY_DEFAULT
00074  *   Default priority
00075  *
00076  * @def HERAIA_PRIORITY_HIGHEST
00077  *   highest priority
00078  *
00079  * @def HERAIA_PRIORITY_LOWEST
00080  *   lowest priority
00081  *
00082  * @note do we use this ?
00083  */
00084 typedef int PluginPriority; 
00085 #define HERAIA_PRIORITY_DEFAULT     0
00086 #define HERAIA_PRIORITY_HIGHEST  9999
00087 #define HERAIA_PRIORITY_LOWEST  -9999
00088 
00089 
00090 /**
00091  *  import / export and filters functions this may change quickly
00092  */
00093 /* returns false on error when loading */
00094 typedef gboolean (* ImportFunction) (const gchar *filename, void *user_data);
00095 
00096 /* returns false on error when saving  */
00097 typedef gboolean (* ExportFunction) (const gchar *filename, void *user_data);
00098 
00099 
00100 /*  this structure may change as the filters may not only be
00101  *  import / exports functions to load / save files but also
00102  *  filters (as in signal treatment) to do things on a file.
00103  */
00104 typedef struct
00105 {
00106         char *extensions;
00107 
00108         ImportFunction import;
00109         ExportFunction export;
00110 } plugin_filter_t;
00111 
00112 
00113 /**
00114  * @struct plugin_info_t
00115  *  Detailed information about a plugin.
00116  */
00117 typedef struct
00118 {
00119         unsigned int api_version;
00120         PluginType type;
00121         PluginPriority priority;
00122         unsigned int id;
00123 
00124         char  *name;
00125         char  *version;
00126         char  *summary;
00127         char  *description;
00128         char  *author;
00129         char  *homepage;
00130 
00131 } plugin_info_t;
00132 
00133 /**
00134  * @struct heraia_plugin_t
00135  *  Complete plugin structure.
00136  */
00137 typedef struct 
00138 {
00139         PluginState state;         /**< The state of the plugin                  */
00140         GModule *handle;           /**< The module handle                        */
00141         char *path;                /**< The path to the plugin                   */
00142         char *filename;            /**< Filename of the plugin                   */
00143         plugin_info_t *info;       /**< The plugin information                   */
00144         plugin_filter_t *filter;   /**< The plugin filter                        */
00145         char *error;               /**< last error message                       */
00146         void *extra;               /**< Plugin-specific data                     */
00147         
00148         InitProc init_proc;       /**< Called when the application initialy starts up            */
00149         QuitProc quit_proc;       /**< Called when the application exits                         */
00150         RunProc  run_proc;        /**< Called to run an interface everytime the plugin is called */
00151         RefreshProc refresh_proc; /**< Called when the cursor changes it's position              */
00152 
00153         GtkCheckMenuItem *cmi_entry; /**< The CheckMenuItem that may be created in the heraia interface */
00154         GladeXML *xml;               /**< Eventually the plugin Glade XML interface                     */
00155         window_prop_t *win_prop;     /**< Stores the window's properties                                */
00156 } heraia_plugin_t;
00157 
00158 
00159 
00160 /* Usefull plugins related functions provided */
00161 /* to be used within the plugins themselves   */
00162 /* or the main program !                      */
00163 extern gboolean plugin_capable(void);
00164 extern heraia_plugin_t *new_plugin(void);
00165 extern void free_plugin(heraia_plugin_t *plugin);
00166 extern void load_plugins(heraia_window_t *main_window);
00167 extern void add_entry_to_plugins_menu(heraia_window_t *main_window, heraia_plugin_t *plugin);
00168 extern heraia_plugin_t *find_plugin_by_name(GList *plugins_list, gchar *name);
00169 extern gboolean load_plugin_glade_xml(heraia_window_t *main_window, heraia_plugin_t *plugin);
00170 extern void refresh_all_plugins(heraia_window_t *main_window);
00171 
00172 #endif /* _HERAIA_PLUGIN_H_ */

Generated on Tue Jun 30 23:18:17 2009 for Heraia by  doxygen 1.5.8