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 - 2010 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 /**
00052  *  May indicate the plugin state
00053  */
00054 typedef enum
00055 {
00056     PLUGIN_STATE_RUNNING,
00057     PLUGIN_STATE_INITIALIZING,
00058     PLUGIN_STATE_LOADED,
00059     PLUGIN_STATE_NEW,
00060     PLUGIN_STATE_EXITING,
00061     PLUGIN_STATE_NONE,
00062 } PluginState;
00063 
00064 
00065 /* plugins functions */
00066 typedef void (* InitProc)    (heraia_struct_t *);         /* Called once when the plugin is loaded              */
00067 typedef void (* QuitProc)    (void);                      /* Called once when the plugin is unloaded            */
00068 typedef void (* RunProc)     (GtkWidget *, gpointer);     /* Called via the menu interface                      */
00069 typedef void (* RefreshProc) (heraia_struct_t *, void *); /* Called every time that the cursor position changes */
00070 /* this double structure is here to improve speed avoiding a list search */
00071 
00072 
00073 /**
00074  *  Priorities ...
00075  * @def HERAIA_PRIORITY_DEFAULT
00076  *   Default priority
00077  *
00078  * @def HERAIA_PRIORITY_HIGHEST
00079  *   highest priority
00080  *
00081  * @def HERAIA_PRIORITY_LOWEST
00082  *   lowest priority
00083  *
00084  * @note do we use this ?
00085  */
00086 typedef int PluginPriority;
00087 #define HERAIA_PRIORITY_DEFAULT     0
00088 #define HERAIA_PRIORITY_HIGHEST  9999
00089 #define HERAIA_PRIORITY_LOWEST  -9999
00090 
00091 
00092 /**
00093  *  import / export and filters functions this may change quickly
00094  */
00095 /* returns false on error when loading */
00096 typedef gboolean (* ImportFunction) (const gchar *filename, void *user_data);
00097 
00098 
00099 /* returns false on error when saving  */
00100 typedef gboolean (* ExportFunction) (const gchar *filename, void *user_data);
00101 
00102 
00103 /*  this structure may change as the filters may not only be
00104  *  import / exports functions to load / save files but also
00105  *  filters (as in signal treatment) to do things on a file.
00106  */
00107 typedef struct
00108 {
00109     char *extensions;
00110 
00111     ImportFunction import;
00112     ExportFunction export;
00113 } plugin_filter_t;
00114 
00115 
00116 /**
00117  * @struct plugin_info_t
00118  *  Detailed information about a plugin.
00119  */
00120 typedef struct
00121 {
00122     unsigned int api_version;
00123     PluginType type;
00124     PluginPriority priority;
00125     unsigned int id;
00126 
00127     char  *name;
00128     char  *version;
00129     char  *summary;
00130     char  *description;
00131     char  *author;
00132     char  *homepage;
00133 
00134 } plugin_info_t;
00135 
00136 
00137 /**
00138  * @struct heraia_plugin_t
00139  *  Complete plugin structure.
00140  */
00141 typedef struct
00142 {
00143     PluginState state;         /**< The state of the plugin                  */
00144     GModule *handle;           /**< The module handle                        */
00145     char *path;                /**< The path to the plugin                   */
00146     char *filename;            /**< Filename of the plugin                   */
00147     plugin_info_t *info;       /**< The plugin information                   */
00148     plugin_filter_t *filter;   /**< The plugin filter                        */
00149     char *error;               /**< last error message                       */
00150     void *extra;               /**< Plugin-specific data                     */
00151 
00152     InitProc init_proc;       /**< Called when the application initialy starts up            */
00153     QuitProc quit_proc;       /**< Called when the application exits                         */
00154     RunProc  run_proc;        /**< Called to run an interface everytime the plugin is called */
00155     RefreshProc refresh_proc; /**< Called when the cursor changes it's position              */
00156 
00157     GtkCheckMenuItem *cmi_entry; /**< The CheckMenuItem that may be created in the heraia interface */
00158     GtkBuilder *xml;             /**< Eventually the plugin's GtkBuilder XML interface                     */
00159     window_prop_t *win_prop;     /**< Stores the window's properties                                */
00160 } heraia_plugin_t;
00161 
00162 
00163 /* Usefull plugins related functions provided */
00164 /* to be used within the plugins themselves   */
00165 /* or the main program !                      */
00166 extern gboolean plugin_capable(void);
00167 extern heraia_plugin_t *new_plugin(void);
00168 extern void free_plugin(heraia_plugin_t *plugin);
00169 extern void load_plugins(heraia_struct_t *main_struct);
00170 extern void add_entry_to_plugins_menu(heraia_struct_t *main_struct, heraia_plugin_t *plugin);
00171 extern heraia_plugin_t *find_plugin_by_name(GList *plugins_list, gchar *name);
00172 extern gboolean load_plugin_xml(heraia_struct_t *main_struct, heraia_plugin_t *plugin);
00173 extern void refresh_all_plugins(heraia_struct_t *main_struct);
00174 
00175 #endif /* _HERAIA_PLUGIN_H_ */
Generated on Fri Aug 20 09:15:18 2010 for Heraia by  doxygen 1.6.3