00001 //###################################################################### 00002 // 00003 // GraspIt! 00004 // Copyright (C) 2002-2009 Columbia University in the City of New York. 00005 // All rights reserved. 00006 // 00007 // GraspIt! is free software: you can redistribute it and/or modify 00008 // it under the terms of the GNU General Public License as published by 00009 // the Free Software Foundation, either version 3 of the License, or 00010 // (at your option) any later version. 00011 // 00012 // GraspIt! is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU General Public License 00018 // along with GraspIt!. If not, see <http://www.gnu.org/licenses/>. 00019 // 00020 // Author(s): Matei T. Ciocarlie 00021 // 00022 // $Id: application.h,v 1.1 2010/08/11 21:34:54 cmatei Exp $ 00023 // 00024 //###################################################################### 00025 00029 #ifndef __PLUGIN_H__ 00030 #include <string> 00031 00033 class Plugin 00034 { 00035 public: 00037 virtual ~Plugin(){} 00039 virtual int init(int argc, char **argv) = 0; 00041 virtual int mainLoop() = 0; 00042 }; 00043 00044 class PluginCreator 00045 { 00046 public: 00047 typedef Plugin* (*CreatePluginFctn)(); 00048 typedef std::string (*GetTypeFctn)(); 00049 private: 00050 void* mLibraryHandle; 00051 CreatePluginFctn mCreatePluginFctn; 00052 00053 bool mAutoStart; 00054 std::string mType; 00055 std::string mDefaultArgs; 00056 public: 00057 PluginCreator(void* libraryHandle, CreatePluginFctn createPluginFctn, 00058 bool autoStart, std::string type, std::string defaultArgs) : 00059 mLibraryHandle(libraryHandle), 00060 mCreatePluginFctn(createPluginFctn), 00061 mAutoStart(autoStart), 00062 mType(type), 00063 mDefaultArgs(defaultArgs) 00064 {} 00065 00066 ~PluginCreator(); 00067 00068 Plugin* createPlugin(std::string args); 00069 00070 bool autoStart() const {return mAutoStart;} 00071 std::string type() const {return mType;} 00072 std::string defaultArgs() const {return mDefaultArgs;} 00073 00074 static PluginCreator* loadFromLibrary(std::string libName); 00075 }; 00076 00077 00078 00079 00080 /*Under windows, DLL files only export symbols prefaced with this compiler macro. 00081 00082 00083 For both linux and windows, extern "C" are necessary. 00084 I.E. 00085 namespace fooplugin{ 00086 class fooPlugin: Plugin{ 00087 --stuff-- 00088 } 00089 PLUGIN_API extern "C" fooPlugin * createPlugin(){ return static_cast<fooPlugin*>(NULL);} 00090 PLUGIN_API extern "C" std::string createPlugin(){ return "foo";} 00091 00092 00093 Some compilers may complain about declaring a function using C++ strings using extern "C", 00094 but this does not appear to cause any problems. 00095 00096 00097 } 00098 00099 00100 Both the createPlugin and getType functions must be declared using these macros. 00101 */ 00102 #ifdef WIN32 00103 #define PLUGIN_API __declspec(dllexport) 00104 #else 00105 #define PLUGIN_API 00106 #endif 00107 00108 00109 #endif