Changeset 5921 for branches/newapi

Show
Ignore:
Timestamp:
12/03/07 00:37:29 (12 months ago)
Author:
erijo
Message:

Move arguments passed to licqCreatePlugin to the struct Licq::Plugin::Setup.

Location:
branches/newapi/licq
Files:
12 modified

Legend:

Unmodified
Added
Removed
  • branches/newapi/licq/licq/interface/plugin.h

    r5455 r5921  
    6666    std::string filename; 
    6767  }; 
     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  }; 
    6889}; 
    6990 
     
    88109   * Creates the plugin. 
    89110   * 
    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. 
    99112   * 
    100113   * @return The created plugin instance; or, if the creation failed 
    101114   * due to e.g. bad arguments, NULL. 
    102115   */ 
    103   LICQ_EXPORT Licq::Plugin* licqCreatePlugin(Licq::Log& log, int argc, char** argv); 
     116  LICQ_EXPORT Licq::Plugin* licqCreatePlugin(const Licq::Plugin::Setup& setup); 
    104117 
    105118  /** 
  • branches/newapi/licq/src/daemon.cpp

    r5918 r5921  
    182182int LicqDaemon::Daemon::main() 
    183183{ 
     184  PluginManager::getInstance()->unloadAll(); 
    184185  return 1; 
    185186} 
  • branches/newapi/licq/src/plugin/plugininstanceimpl.cpp

    r5796 r5921  
    2929#include <cstring> 
    3030 
    31 static Licq::Plugin::Id globalPluginId = 0; 
    32 static Licq::Mutex globalPluginIdMutex("globalPluginId"); 
     31static 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} 
    3339 
    3440LicqDaemon::PluginInstanceImpl:: 
     
    3844  : myInformation(info), 
    3945    myLibrary(library), 
    40     myPluginId(0), 
    4146    myPlugin(NULL), 
    4247    myThread(NULL), 
    43     myLogSink(sink), 
    44     myLog(NULL), 
    45     myArgc(0), 
    46     myArgv(NULL) 
     48    myLogSink(sink) 
    4749{ 
    48   // Empty 
     50  mySetup.id = 0; 
     51  mySetup.log = NULL; 
     52  mySetup.argc = 0; 
     53  mySetup.argv = 0; 
    4954} 
    5055 
     
    5358  delete myThread; 
    5459  myLibrary->destroyPlugin(myPlugin); 
    55   delete myLog; 
    5660 
    57   for (int i = 0; i < myArgc; ++i) 
    58     free(myArgv[i]); 
    59  
    60   delete[] myArgv; 
     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; 
    6165} 
    6266 
     
    6670 
    6771  // Set up argc and argv for the plugin 
    68   myArgc = argc + 1; 
    69   myArgv = new char*[myArgc]; 
     72  mySetup.argc = argc + 1; 
     73  mySetup.argv = new char*[mySetup.argc]; 
    7074 
    71   myArgv[0] = ::strdup("licq"); 
     75  mySetup.argv[0] = ::strdup("licq"); 
    7276  for (int i = 0; i < argc; ++i) 
    73     myArgv[i + 1] = ::strdup(argv[i]); 
     77    mySetup.argv[i + 1] = ::strdup(argv[i]); 
    7478 
    7579  // 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(); 
    7784 
    7885  // Create the plugin 
    79   myPlugin = myLibrary->createPlugin(*myLog, myArgc, myArgv); 
     86  myPlugin = myLibrary->createPlugin(mySetup); 
    8087  if (myPlugin == NULL) 
    8188  { 
     
    8794  myThread = new Licq::Thread(myPlugin); 
    8895 
    89   Licq::MutexLocker locker(&globalPluginIdMutex); 
    90   myPluginId = ++globalPluginId; 
    91   return myPluginId; 
     96  return mySetup.id; 
    9297} 
  • branches/newapi/licq/src/plugin/plugininstanceimpl.h

    r5362 r5921  
    2121#define LICQDAEMON_PLUGININSTANCEIMPL_H 
    2222 
     23#include "licq/thread/thread.h" 
    2324#include "plugin/plugininstance.h" 
    2425 
     
    7273  boost::shared_ptr<PluginLibrary> myLibrary; 
    7374 
    74   Licq::Plugin::Id myPluginId; 
     75  Licq::Plugin::Setup mySetup; 
     76 
    7577  Licq::Plugin* myPlugin; 
    7678  Licq::Thread* myThread; 
    7779 
    7880  Licq::LogSink& myLogSink; 
    79   LicqDaemon::Log* myLog; 
    80  
    81   int myArgc; 
    82   char** myArgv; 
    8381}; 
    8482 
     
    8785inline Licq::Plugin::Id LicqDaemon::PluginInstanceImpl::getPluginId() const 
    8886{ 
    89   return myPluginId; 
     87  return mySetup.id; 
    9088} 
    9189 
  • branches/newapi/licq/src/plugin/pluginlibrary.h

    r5362 r5921  
    3737  virtual unsigned int getPluginAbiVersion() = 0; 
    3838  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; 
    4040  virtual void destroyPlugin(Licq::Plugin* plugin) = 0; 
    4141}; 
  • branches/newapi/licq/src/plugin/pluginlibraryimpl.cpp

    r5339 r5921  
    4141 
    4242Licq::Plugin* 
    43 LicqDaemon::PluginLibraryImpl::createPlugin(Licq::Log& log, int argc, char** argv) 
     43LicqDaemon::PluginLibraryImpl::createPlugin(const Licq::Plugin::Setup& setup) 
    4444{ 
    45   return myCreate(log, argc, argv); 
     45  return myCreate(setup); 
    4646} 
    4747 
  • branches/newapi/licq/src/plugin/pluginlibraryimpl.h

    r5362 r5921  
    5555   * Call the plugin's licqCreatePlugin() function. 
    5656   */ 
    57   Licq::Plugin* createPlugin(Licq::Log& log, int argc, char** argv); 
     57  Licq::Plugin* createPlugin(const Licq::Plugin::Setup& setup); 
    5858 
    5959  /** 
     
    6767  unsigned int (*myGetVersion)(); 
    6868  void (*myGetInformation)(Licq::Plugin::Information*); 
    69   Licq::Plugin* (*myCreate)(Licq::Log&, int, char**); 
     69  Licq::Plugin* (*myCreate)(const Licq::Plugin::Setup& setup); 
    7070  void (*myDestroy)(Licq::Plugin*); 
    7171}; 
  • branches/newapi/licq/src/plugin/pluginmanager.h

    r5915 r5921  
    4949  static PluginManager* getInstance(); 
    5050 
     51  virtual void unloadAll() = 0; 
     52 
    5153  virtual void setPluginLogSink(Licq::LogSink* sink) = 0; 
    5254 
  • branches/newapi/licq/src/plugin/pluginmanagerimpl.cpp

    r5915 r5921  
    3232{ 
    3333  // Empty 
     34} 
     35 
     36void LicqDaemon::PluginManagerImpl::unloadAll() 
     37{ 
     38  myPlugins.clear(); 
     39  myCache.clear(); 
     40  myCache.unloadUnusedLibraries(); 
    3441} 
    3542 
  • branches/newapi/licq/src/plugin/pluginmanagerimpl.h

    r5915 r5921  
    4040  ~PluginManagerImpl(); 
    4141 
     42  void unloadAll(); 
     43 
    4244  /** 
    4345   * Set the LogSink that plugins will log to. This must have been 
  • branches/newapi/licq/src/plugin/test/plugincachetest.cpp

    r5909 r5921  
    7979  } 
    8080 
    81   Licq::Plugin* createPlugin(Licq::Log& /*log*/, int /*argc*/, char** /*argv*/) 
     81  Licq::Plugin* createPlugin(const Licq::Plugin::Setup& /*setup*/) 
    8282  { 
    8383    return NULL; 
  • branches/newapi/licq/src/plugin/test/pluginlibrarytest.cpp

    r5911 r5921  
    5353} 
    5454 
    55 Licq::Plugin* licqCreatePlugin(Licq::Log&, int argc, char** argv) 
     55Licq::Plugin* licqCreatePlugin(const Licq::Plugin::Setup& setup) 
    5656{ 
    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"); 
    5959 
    6060  static FakePlugin plugin; 
    61   plugin.myArgc = argc; 
    62   plugin.myArgv = argv; 
     61  plugin.myArgc = setup.argc; 
     62  plugin.myArgv = setup.argv; 
    6363  plugin.myDestroyed = false; 
    6464  return (Licq::Plugin*)&plugin; 
     
    105105BOOST_AUTO_TEST_CASE(createDestroy) 
    106106{ 
    107   Licq::Log* log = Licq::Log::getThreadLog(); 
    108107  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); 
    110115  BOOST_CHECK_EQUAL(plugin->myArgc, 1); 
    111116  BOOST_CHECK_EQUAL(plugin->myArgv, (char**)argv);