Plugin.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  * File:        ./Plugin.h
00003  * Author:      Ronni Grapenthin, NORVULK & HU-BERLIN
00004  * Created:     20.02.2007
00005  * Licence:     GPLv2
00006  *
00007  * #########################################################################
00008  *
00009  * CrusDe, simulation framework for crustal deformation studies
00010  * Copyright (C) 2007 Ronni Grapenthin
00011  *
00012  * This program is free software; you can redistribute it and/or
00013  * modify it under the terms of the GNU General Public License
00014  * as published by the Free Software Foundation; version 2
00015  * of the License.
00016  *
00017  * This program is distributed in the hope that it will be useful,
00018  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  * GNU General Public License for more details.
00021  *
00022  * You should have received a copy of the GNU General Public License
00023  * along with this program; if not, write to the Free Software
00024  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00025  *
00026  ****************************************************************************/
00027 
00028 #ifndef _plugin_h
00029 #define _plugin_h
00030 
00031 #include <string>
00032 #include <iostream>
00033 #include <cassert>
00034 #include <dlfcn.h>
00035 
00036 #include "crusde_api.h"
00037 #include "config.h"
00038 #include "exceptions.h"
00039 
00040 using namespace std;
00041 
00042 typedef void  (*void_t)();
00043 typedef char* (*char_t)();
00044 typedef PluginCategory (*category_t)();
00045 
00046 class Plugin
00047 {
00048         private:        
00049 
00050                 void_t func_void;       /*  Pointer to loaded routine   */
00051                 char_t func_get_string; /*  Pointer to loaded routine   */
00052                 
00053                 char_t func_get_name;
00054                 char_t func_get_version;
00055                 char_t func_get_authors;        
00056                 char_t func_get_description;    
00057                 
00058                 category_t func_get_category;
00059                 
00060                 void_t func_run;        
00061                 void_t func_register_parameter; 
00062                 void_t func_register_output_fields;
00063                 void_t func_request_plugins;    
00064                 void_t func_init;       
00065                 void_t func_release;
00066                                 
00067                 int rc;                         /*  return codes                */
00068 
00070                 Plugin(const Plugin& x); 
00071                 
00072                 void_t get_dl_voidFunc(string) throw (LibHandleError);
00073                 char_t get_dl_stringFunc(string) throw (LibHandleError);
00074                 category_t get_categoryFunc(string) throw (LibHandleError);
00075 
00076         protected:
00077                 void  *LibHandle;               /*  Handle to shared lib file   */
00078                 const string name;              /* identifier for plugin        */
00079                 string path;                    /* another id for plugin        */
00080                 string category;                /* category of plugin, determined by directory*/
00081                 bool is_released;               /* did we already release() the plugin? */
00082                 bool is_initialized;            /* did we already init() the plugin? */
00083                 bool is_registered;             /* did we already register_...() the plugin's parameter? */
00084                 bool is_loaded;                 /* were we able to load our library (default: false)? */
00085         
00086         public:
00087                 Plugin(const string name);      /* Constructor */
00088                 virtual ~Plugin();                      /* Destructor */
00089                 
00090                 /*plugin Interface*/
00091                 
00092                 virtual void load(const string) throw (FileNotFound, LibHandleError);
00093                 virtual void unload() throw (LibHandleError);
00094                 
00095                 virtual void run();
00096                 virtual void registerParameter();
00097                 virtual void registerOutputFields();
00098                 virtual void requestPlugins();
00099                 virtual void init();
00100                 virtual void release();
00101                 
00102                 virtual void selftest();
00103                 
00104                 /*plugin management interface */
00105                 
00106                 string  getName();              /*returns name of the plugin*/
00107                 string  getVersion();           /*returns version of the plugin*/
00108                 string  getAuthors();           /*returns authors of the plugin*/
00109                 string  getDescription();       /*returns description of the plugin*/
00110                 string  getCategory();          /*returns plugin type {green|kernel|out|load} */
00111                 PluginCategory getCategoryID();
00112 
00113                 bool isLoaded();                
00114                 void setCategory(string new_type);
00115                 
00116                 run_function getRunFunction();
00117 };
00118 
00119 #endif // _plugin_h

Generated on Sun Aug 31 13:19:00 2008 for CrusDe by  doxygen 1.5.0