interreality.org [VOS]
[Home] [About]
[Screenshots]
[Download]
[News]
[Community]
[Documentation] [Manual]
[Bugs & Requests] [Wiki]

/home/tetron/hack/vos/libs/vos/vos/vosplugin.hh

Go to the documentation of this file.
00001 #ifndef _VOSPLUGIN_HH_
00002 #define _VOSPLUGIN_HH_
00003 
00004 #include <vos/vos/metaobject.hh>
00005 
00006 #if defined(WIN32)
00007 # define PLUGIN_API __declspec(dllexport)
00008 #else
00009 # ifdef HAVE_GCC_VISIBILITY
00010 #  define PLUGIN_API __attribute__ ((visibility("default")))
00011 # else
00012 #  define PLUGIN_API
00013 # endif
00014 #endif
00015 
00016 
00017 namespace VOS
00018 {
00019     class VOS_API VOSPlugin : public MetaObject
00020     {
00021     protected:
00022         VOSPlugin(VOS::VobjectBase* superobject);
00023         std::vector<std::string> searchPath;
00024 
00025     public:
00026         /** Get the name for this loadable plugin */
00027         virtual std::string getModuleName() = 0;
00028 
00029         /** Get the version of the plugin module */
00030         virtual void getModuleVersion(int& major, int& minor) = 0;
00031 
00032         struct HelpOption
00033         {
00034             HelpOption(const std::string& a, const std::string& b)
00035                 : option(a), description(b) { }
00036             std::string option;
00037             std::string description;
00038         };
00039 
00040         struct PluginHelp
00041         {
00042             std::string header;
00043             std::vector<HelpOption> options;
00044             std::string footer;
00045         };
00046 
00047         /** Fills in the supplied plugin help structure */
00048         virtual void getHelp(PluginHelp& ph) = 0;
00049 
00050         /** Trigger the actual loading, setup and execution of the module */
00051         virtual void initialize() = 0;
00052 
00053         virtual void setSearchPath(std::vector<std::string>& path);
00054         virtual std::vector<std::string> getSearchPath();
00055     };
00056 
00057     class VOS_API VOSPluginSharedObject : public virtual VOSPlugin
00058     {
00059     protected:
00060         VOSPluginSharedObject(VOS::VobjectBase* superobject);
00061 
00062         typedef void (*NameFunc)(std::string* name);
00063         typedef void (*VersionFunc)(int* major, int* minor);
00064         typedef void (*HelpFunc)(VOSPlugin::PluginHelp* help);
00065         typedef void (*InitFunc)(Vobject* parent);
00066 
00067         void* pluginModule;
00068         NameFunc nameFunc;
00069         VersionFunc versionFunc;
00070         HelpFunc helpFunc;
00071         InitFunc initFunc;
00072 
00073         virtual void checkLoadModule();
00074 
00075     public:
00076         static MetaObject* new_VOSPluginSharedObject(VOS::VobjectBase* superobject,
00077                                                      const std::string& type);
00078 
00079         virtual const std::string getVOSType();
00080 
00081         virtual std::string getModuleName();
00082         virtual void getModuleVersion(int& major, int& minor);
00083         virtual void getHelp(VOSPlugin::PluginHelp& ph);
00084         virtual void initialize();
00085     };
00086 
00087 #define DECLARE_VOS_PLUGIN(name, major, minor) \
00088   PLUGIN_API void vosplugin_name(std::string* n) { *n = (name); } \
00089   PLUGIN_API void vosplugin_version(int* maj, int* min) { *maj = (major); *min = (minor); }
00090 }
00091 
00092 #ifndef VOS_EXPORTS
00093 IMPORT_METAOBJECT_FACTORIES(VOSPluginSharedObject)
00094 #endif
00095 
00096 #endif