Changeset 5921 for branches/newapi
- Timestamp:
- 12/03/07 00:37:29 (12 months ago)
- Location:
- branches/newapi/licq
- Files:
-
- 12 modified
-
licq/interface/plugin.h (modified) (2 diffs)
-
src/daemon.cpp (modified) (1 diff)
-
src/plugin/plugininstanceimpl.cpp (modified) (5 diffs)
-
src/plugin/plugininstanceimpl.h (modified) (3 diffs)
-
src/plugin/pluginlibrary.h (modified) (1 diff)
-
src/plugin/pluginlibraryimpl.cpp (modified) (1 diff)
-
src/plugin/pluginlibraryimpl.h (modified) (2 diffs)
-
src/plugin/pluginmanager.h (modified) (1 diff)
-
src/plugin/pluginmanagerimpl.cpp (modified) (1 diff)
-
src/plugin/pluginmanagerimpl.h (modified) (1 diff)
-
src/plugin/test/plugincachetest.cpp (modified) (1 diff)
-
src/plugin/test/pluginlibrarytest.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/newapi/licq/licq/interface/plugin.h
r5455 r5921 66 66 std::string filename; 67 67 }; 68 69 struct Setup 70 { 71 /// An unque id for the plugin instance. 72 Id id; 73 74 /// The log that the plugin should use when logging. 75 Log* log; 76 77 /// Number of arguments in argv. Always >= 1. 78 int argc; 79 80 /** 81 * Arguments passed to the plugin on e.g. the command line. Each 82 * plugin gets their own copy which contains "licq" in argv[0] and 83 * then all arguments passed to this plugin. Note that this is not 84 * the full list of arguments as entered by the user, only those 85 * that apply to this plugin. 86 */ 87 char** argv; 88 }; 68 89 }; 69 90 … … 88 109 * Creates the plugin. 89 110 * 90 * @param log The log that this plugin should use when logging. 91 * 92 * @param argc Number of arguments in @a argv. Always >= 1. 93 * 94 * @param argv Arguments passed to the plugin on e.g. the command 95 * line. Each plugin gets their own copy which contains "licq" in 96 * argv[0] and then all arguments passed to this plugin. Note that 97 * this is not the full list of arguments as entered by the user, 98 * only those that apply to this plugin. 111 * @param setup Setup data for the plugin. 99 112 * 100 113 * @return The created plugin instance; or, if the creation failed 101 114 * due to e.g. bad arguments, NULL. 102 115 */ 103 LICQ_EXPORT Licq::Plugin* licqCreatePlugin( Licq::Log& log, int argc, char** argv);116 LICQ_EXPORT Licq::Plugin* licqCreatePlugin(const Licq::Plugin::Setup& setup); 104 117 105 118 /** -
branches/newapi/licq/src/daemon.cpp
r5918 r5921 182 182 int LicqDaemon::Daemon::main() 183 183 { 184 PluginManager::getInstance()->unloadAll(); 184 185 return 1; 185 186 } -
branches/newapi/licq/src/plugin/plugininstanceimpl.cpp
r5796 r5921 29 29 #include <cstring> 30 30 31 static Licq::Plugin::Id globalPluginId = 0; 32 static Licq::Mutex globalPluginIdMutex("globalPluginId"); 31 static Licq::Plugin::Id getNextPluginId() 32 { 33 static Licq::Plugin::Id nextPluginId = 1; 34 static Licq::Mutex nextPluginIdMutex("nextPluginId"); 35 36 Licq::MutexLocker locker(&nextPluginIdMutex); 37 return nextPluginId++; 38 } 33 39 34 40 LicqDaemon::PluginInstanceImpl:: … … 38 44 : myInformation(info), 39 45 myLibrary(library), 40 myPluginId(0),41 46 myPlugin(NULL), 42 47 myThread(NULL), 43 myLogSink(sink), 44 myLog(NULL), 45 myArgc(0), 46 myArgv(NULL) 48 myLogSink(sink) 47 49 { 48 // Empty 50 mySetup.id = 0; 51 mySetup.log = NULL; 52 mySetup.argc = 0; 53 mySetup.argv = 0; 49 54 } 50 55 … … 53 58 delete myThread; 54 59 myLibrary->destroyPlugin(myPlugin); 55 delete myLog;56 60 57 for (int i = 0; i < myArgc; ++i)58 free(myArgv[i]);59 60 delete[] my Argv;61 delete static_cast<Log*>(mySetup.log); 62 for (int i = 0; i < mySetup.argc; ++i) 63 free(mySetup.argv[i]); 64 delete[] mySetup.argv; 61 65 } 62 66 … … 66 70 67 71 // Set up argc and argv for the plugin 68 my Argc = argc + 1;69 my Argv = new char*[myArgc];72 mySetup.argc = argc + 1; 73 mySetup.argv = new char*[mySetup.argc]; 70 74 71 my Argv[0] = ::strdup("licq");75 mySetup.argv[0] = ::strdup("licq"); 72 76 for (int i = 0; i < argc; ++i) 73 my Argv[i + 1] = ::strdup(argv[i]);77 mySetup.argv[i + 1] = ::strdup(argv[i]); 74 78 75 79 // Create the log 76 myLog = new Log(myInformation->name, &myLogSink); 80 mySetup.log = new Log(myInformation->name, &myLogSink); 81 82 // Get a plugin id 83 mySetup.id = getNextPluginId(); 77 84 78 85 // Create the plugin 79 myPlugin = myLibrary->createPlugin( *myLog, myArgc, myArgv);86 myPlugin = myLibrary->createPlugin(mySetup); 80 87 if (myPlugin == NULL) 81 88 { … … 87 94 myThread = new Licq::Thread(myPlugin); 88 95 89 Licq::MutexLocker locker(&globalPluginIdMutex); 90 myPluginId = ++globalPluginId; 91 return myPluginId; 96 return mySetup.id; 92 97 } -
branches/newapi/licq/src/plugin/plugininstanceimpl.h
r5362 r5921 21 21 #define LICQDAEMON_PLUGININSTANCEIMPL_H 22 22 23 #include "licq/thread/thread.h" 23 24 #include "plugin/plugininstance.h" 24 25 … … 72 73 boost::shared_ptr<PluginLibrary> myLibrary; 73 74 74 Licq::Plugin::Id myPluginId; 75 Licq::Plugin::Setup mySetup; 76 75 77 Licq::Plugin* myPlugin; 76 78 Licq::Thread* myThread; 77 79 78 80 Licq::LogSink& myLogSink; 79 LicqDaemon::Log* myLog;80 81 int myArgc;82 char** myArgv;83 81 }; 84 82 … … 87 85 inline Licq::Plugin::Id LicqDaemon::PluginInstanceImpl::getPluginId() const 88 86 { 89 return my PluginId;87 return mySetup.id; 90 88 } 91 89 -
branches/newapi/licq/src/plugin/pluginlibrary.h
r5362 r5921 37 37 virtual unsigned int getPluginAbiVersion() = 0; 38 38 virtual void getPluginInformation(Licq::Plugin::Information* info) = 0; 39 virtual Licq::Plugin* createPlugin( Licq::Log& log, int argc, char** argv) = 0;39 virtual Licq::Plugin* createPlugin(const Licq::Plugin::Setup& setup) = 0; 40 40 virtual void destroyPlugin(Licq::Plugin* plugin) = 0; 41 41 }; -
branches/newapi/licq/src/plugin/pluginlibraryimpl.cpp
r5339 r5921 41 41 42 42 Licq::Plugin* 43 LicqDaemon::PluginLibraryImpl::createPlugin( Licq::Log& log, int argc, char** argv)43 LicqDaemon::PluginLibraryImpl::createPlugin(const Licq::Plugin::Setup& setup) 44 44 { 45 return myCreate( log, argc, argv);45 return myCreate(setup); 46 46 } 47 47 -
branches/newapi/licq/src/plugin/pluginlibraryimpl.h
r5362 r5921 55 55 * Call the plugin's licqCreatePlugin() function. 56 56 */ 57 Licq::Plugin* createPlugin( Licq::Log& log, int argc, char** argv);57 Licq::Plugin* createPlugin(const Licq::Plugin::Setup& setup); 58 58 59 59 /** … … 67 67 unsigned int (*myGetVersion)(); 68 68 void (*myGetInformation)(Licq::Plugin::Information*); 69 Licq::Plugin* (*myCreate)( Licq::Log&, int, char**);69 Licq::Plugin* (*myCreate)(const Licq::Plugin::Setup& setup); 70 70 void (*myDestroy)(Licq::Plugin*); 71 71 }; -
branches/newapi/licq/src/plugin/pluginmanager.h
r5915 r5921 49 49 static PluginManager* getInstance(); 50 50 51 virtual void unloadAll() = 0; 52 51 53 virtual void setPluginLogSink(Licq::LogSink* sink) = 0; 52 54 -
branches/newapi/licq/src/plugin/pluginmanagerimpl.cpp
r5915 r5921 32 32 { 33 33 // Empty 34 } 35 36 void LicqDaemon::PluginManagerImpl::unloadAll() 37 { 38 myPlugins.clear(); 39 myCache.clear(); 40 myCache.unloadUnusedLibraries(); 34 41 } 35 42 -
branches/newapi/licq/src/plugin/pluginmanagerimpl.h
r5915 r5921 40 40 ~PluginManagerImpl(); 41 41 42 void unloadAll(); 43 42 44 /** 43 45 * Set the LogSink that plugins will log to. This must have been -
branches/newapi/licq/src/plugin/test/plugincachetest.cpp
r5909 r5921 79 79 } 80 80 81 Licq::Plugin* createPlugin( Licq::Log& /*log*/, int /*argc*/, char** /*argv*/)81 Licq::Plugin* createPlugin(const Licq::Plugin::Setup& /*setup*/) 82 82 { 83 83 return NULL; -
branches/newapi/licq/src/plugin/test/pluginlibrarytest.cpp
r5911 r5921 53 53 } 54 54 55 Licq::Plugin* licqCreatePlugin( Licq::Log&, int argc, char** argv)55 Licq::Plugin* licqCreatePlugin(const Licq::Plugin::Setup& setup) 56 56 { 57 BOOST_CHECK_EQUAL( argc, 1);58 BOOST_CHECK_EQUAL( argv[0], "licq");57 BOOST_CHECK_EQUAL(setup.argc, 1); 58 BOOST_CHECK_EQUAL(setup.argv[0], "licq"); 59 59 60 60 static FakePlugin plugin; 61 plugin.myArgc = argc;62 plugin.myArgv = argv;61 plugin.myArgc = setup.argc; 62 plugin.myArgv = setup.argv; 63 63 plugin.myDestroyed = false; 64 64 return (Licq::Plugin*)&plugin; … … 105 105 BOOST_AUTO_TEST_CASE(createDestroy) 106 106 { 107 Licq::Log* log = Licq::Log::getThreadLog();108 107 const char* argv[] = { "licq" }; 109 FakePlugin* plugin = (FakePlugin*)myLib.createPlugin(*log, 1, (char**)argv); 108 109 Licq::Plugin::Setup setup; 110 setup.log = Licq::Log::getThreadLog(); 111 setup.argc = 1; 112 setup.argv = (char**)argv; 113 114 FakePlugin* plugin = (FakePlugin*)myLib.createPlugin(setup); 110 115 BOOST_CHECK_EQUAL(plugin->myArgc, 1); 111 116 BOOST_CHECK_EQUAL(plugin->myArgv, (char**)argv);
