Changeset ac676a8 in nscp


Ignore:
Timestamp:
02/16/05 23:27:49 (8 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2, stable
Children:
8cf56a5
Parents:
167a5dd
Message:

Changed plugin load/unload

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • NSCPlugin.cpp

    ra0528c4 rac676a8  
    154154} 
    155155/** 
    156  * Helper function to create a plug in for a third party. 
    157  * <b>Notice</b> though the name might suggest it the plug in is <b>not</b> actually loaded. 
    158  * 
    159  * @deprecated 
    160  * @param file The file (DLL) of the plug in module 
    161  * @return A pointer to a new instance of the plug in wrapper class. 
    162  */ 
    163 NSCPlugin* NSCPlugin::loadPlugin(std::string file) { 
    164   return new NSCPlugin(file); 
    165 } 
    166 /** 
    167156 * Load all remote function pointers from the loaded module. 
    168157 * These pointers are cached for "speed" which might (?) be dangerous if something changes. 
  • NSCPlugin.h

    ra0528c4 rac676a8  
    119119  void unload(void); 
    120120 
    121   static NSCPlugin* loadPlugin(std::string file); 
    122  
    123121private: 
    124122  bool isLoaded() const { 
  • NSClient++.cpp

    ra0528c4 rac676a8  
    6565      LOG_MESSAGE("Enter command to inject or exit to terminate..."); 
    6666      std::string s = ""; 
     67      std::cin >> s; 
    6768      while (s != "exit") { 
     69        mainClient.inject(s); 
    6870        std::cin >> s; 
    69         mainClient.inject(s); 
    7071      } 
    7172      mainClient.TerminateService(); 
     73      LOG_MESSAGE("DONE!"); 
    7274      return 0; 
    7375    } else { 
     
    8890 */ 
    8991void NSClientT::InitiateService(void) { 
    90   char* buffer = new char[1024]; 
    91   GetModuleFileName(NULL, buffer, 1023); 
    92   std::string path = buffer; 
    93   std::string::size_type pos = path.rfind('\\'); 
    94   basePath = path.substr(0, pos) + "\\"; 
    95   LOG_DEBUG_STD("Base path is: " + basePath); 
    96   delete [] buffer; 
    97   Settings::getInstance()->setFile(basePath + "NSC.ini"); 
     92  Settings::getInstance()->setFile(getBasePath() + "NSC.ini"); 
    9893 
    9994  SettingsT::sectionList list = Settings::getInstance()->getSection("modules"); 
    10095  for (SettingsT::sectionList::iterator it = list.begin(); it != list.end(); it++) { 
    10196    try { 
    102       LOG_DEBUG_STD("Loading: " + basePath + "modules\\" + (*it)); 
    103       loadPlugin(basePath + "modules\\" + (*it)); 
     97      LOG_DEBUG_STD("Loading: " + getBasePath() + "modules\\" + (*it)); 
     98      loadPlugin(getBasePath() + "modules\\" + (*it)); 
    10499    } catch(const NSPluginException& e) { 
    105100      LOG_ERROR_STD("Exception raised: " + e.error_ + " in module: " + e.file_); 
     
    116111    LOG_ERROR("Could not exit socket listener thread"); 
    117112  try { 
     113    LOG_DEBUG("Socket closed, unloading plugins..."); 
    118114    mainClient.unloadPlugins(); 
     115    LOG_DEBUG("Plugins unloaded..."); 
    119116  } catch(NSPluginException *e) { 
    120117    LOG_ERROR_STD("Exception raised: " + e->error_ + " in module: " + e->file_); 
     
    157154 */ 
    158155void NSClientT::unloadPlugins() { 
     156  pluginList::reverse_iterator it; 
     157  for (it = plugins_.rbegin(); it != plugins_.rend(); ++it) { 
     158#ifdef _DEBUG 
     159    std::cout << "Unloading plugin: " << (*it)->getName() << "..."; 
     160#endif 
     161    (*it)->unload(); 
     162#ifdef _DEBUG 
     163    std::cout << "OK" << std::endl; 
     164#endif 
     165  } 
    159166  messageHandlers_.clear(); 
    160167  commandHandlers_.clear(); 
    161   pluginList::reverse_iterator it; 
    162168  for (it = plugins_.rbegin(); it != plugins_.rend(); ++it) { 
    163     LOG_DEBUG_STD("---\n\n\nUnloading: " + (*it)->getName()); 
    164     (*it)->unload(); 
    165169    delete (*it); 
    166170  } 
     
    172176 */ 
    173177void NSClientT::loadPlugin(std::string file) { 
    174   addPlugin(NSCPlugin::loadPlugin(file)); 
     178  addPlugin(new NSCPlugin(file)); 
    175179} 
    176180/** 
     
    178182 * @param *plugin The plug-ininstance to load. The pointer is managed by the  
    179183 */ 
    180 void NSClientT::addPlugin(NSCPlugin *plugin) { 
     184void NSClientT::addPlugin(plugin_type plugin) { 
    181185  plugin->load(); 
    182186  LOG_DEBUG_STD("Loading: " + plugin->getName()); 
     
    290294  } 
    291295} 
     296std::string NSClientT::getBasePath(void) { 
     297  if (!basePath.empty()) 
     298    return basePath; 
     299  char* buffer = new char[1024]; 
     300  GetModuleFileName(NULL, buffer, 1023); 
     301  std::string path = buffer; 
     302  std::string::size_type pos = path.rfind('\\'); 
     303  basePath = path.substr(0, pos) + "\\"; 
     304  delete [] buffer; 
     305  Settings::getInstance()->setFile(basePath + "NSC.ini"); 
     306  return basePath; 
     307} 
     308 
    292309 
    293310int NSAPIGetSettingsString(const char* section, const char* key, const char* defaultValue, char* buffer, unsigned int bufLen) { 
     
    298315} 
    299316 
     317 
     318int NSAPIGetBasePath(char*buffer, unsigned int bufLen) { 
     319  return NSCHelper::wrapReturnString(buffer, bufLen, mainClient.getBasePath()); 
     320} 
    300321int NSAPIGetApplicationName(char*buffer, unsigned int bufLen) { 
    301322  return NSCHelper::wrapReturnString(buffer, bufLen, SZAPPNAME); 
     
    329350  if (stricmp(buffer, "NSAPIInject") == 0) 
    330351    return &NSAPIInject; 
     352  if (stricmp(buffer, "NSAPIGetBasePath") == 0) 
     353    return &NSAPIGetBasePath; 
    331354  return NULL; 
    332355} 
  • NSClient++.h

    ra0528c4 rac676a8  
    3737class NSClientT { 
    3838private: 
    39   typedef std::list<NSCPlugin*> pluginList; 
     39  typedef NSCPlugin* plugin_type; 
     40  typedef std::list<plugin_type> pluginList; 
    4041  pluginList plugins_; 
    4142  pluginList commandHandlers_; 
     
    5859  // Member functions 
    5960  static std::string getPassword(void); 
     61  std::string getBasePath(void); 
    6062  std::string inject(std::string buffer); 
    6163  std::string execute(std::string password, std::string cmd, std::list<std::string> args); 
     
    6870 
    6971private: 
    70   void addPlugin(NSCPlugin *plugin); 
     72  void addPlugin(plugin_type plugin); 
    7173 
    7274}; 
     
    8284LPVOID NSAPILoader(char*buffer); 
    8385int NSAPIGetApplicationName(char*buffer, unsigned int bufLen); 
     86int NSAPIGetBasePath(char*buffer, unsigned int bufLen); 
    8487int NSAPIGetApplicationVersionStr(char*buffer, unsigned int bufLen); 
    8588int NSAPIGetSettingsString(const char* section, const char* key, const char* defaultValue, char* buffer, unsigned int bufLen); 
Note: See TracChangeset for help on using the changeset viewer.