Changeset b3078b4 in nscp


Ignore:
Timestamp:
11/21/09 17:59:42 (4 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2
Children:
01a278b
Parents:
92c4b5b
Message:

added some build stuff

Files:
3 added
6 edited

Legend:

Unmodified
Added
Removed
  • service/NSCPlugin.cpp

    rd05c3f0 rb3078b4  
    4646  ,lastIsMsgPlugin_(false) 
    4747  ,broken_(false) 
     48  ,plugin_id_(0) 
    4849{ 
    49  
     50  plugin_id_ = ++last_plugin_id_; 
    5051} 
    5152/* 
  • service/NSCPlugin.h

    rd05c3f0 rb3078b4  
    108108  dll::dll module_; 
    109109  bool broken_; 
     110  static unsigned int last_plugin_id_; 
     111  unsigned int plugin_id_; 
    110112 
    111113  typedef int (*lpModuleHelperInit)(NSCModuleHelper::lpNSAPILoader f); 
     
    186188    return bLoaded_; 
    187189  } 
     190  unsigned int get_id() const { return plugin_id_; } 
    188191 
    189192private: 
     
    195198}; 
    196199 
    197  
     200unsigned int NSCPlugin::last_plugin_id_ = 0; 
     201 
     202 
     203 
  • service/NSClient++-2005.vcproj

    r818b54e rb3078b4  
    21392139      </File> 
    21402140      <File 
     2141        RelativePath=".\commands.hpp" 
     2142        > 
     2143      </File> 
     2144      <File 
    21412145        RelativePath=".\include\config.h" 
    21422146        > 
  • service/NSClient++.cpp

    rd05c3f0 rb3078b4  
    10601060    } 
    10611061    for (pluginList::size_type i=0;i<plugins_.size();++i) { 
    1062       NSCPlugin *p = plugins_[i]; 
     1062      plugin_type p = plugins_[i]; 
    10631063      if (!moduleList.empty()) 
    10641064        moduleList += _T(", "); 
    1065       moduleList += p->getModule(); 
    1066       if (p->getModule() == sModule) { 
    1067         LOG_DEBUG_STD(_T("Found module: ") + p->getName() + _T("...")); 
    1068         try { 
    1069           return p->commandLineExec(command, argLen, args); 
    1070         } catch (NSPluginException e) { 
    1071           LOG_ERROR_STD(_T("Could not execute command: ") + e.error_ + _T(" in ") + e.file_); 
    1072           return -1; 
     1065      if (p) { 
     1066        moduleList += p->getModule(); 
     1067        if (p->getModule() == sModule) { 
     1068          LOG_DEBUG_STD(_T("Found module: ") + p->getName() + _T("...")); 
     1069          try { 
     1070            return p->commandLineExec(command, argLen, args); 
     1071          } catch (NSPluginException e) { 
     1072            LOG_ERROR_STD(_T("Could not execute command: ") + e.error_ + _T(" in ") + e.file_); 
     1073            return -1; 
     1074          } 
    10731075        } 
    10741076      } 
     
    11231125    } 
    11241126    for (pluginList::reverse_iterator it = plugins_.rbegin(); it != plugins_.rend(); ++it) { 
    1125       NSCPlugin *p = *it; 
    1126       if (p == NULL) 
     1127      plugin_type p = *it; 
     1128      if (!p) 
    11271129        continue; 
    11281130      try { 
     
    11461148      return; 
    11471149    } 
     1150    commands_.remove_all(); 
    11481151    for (pluginList::iterator it = plugins_.begin(); it != plugins_.end();) { 
    1149       NSCPlugin *p = (*it); 
     1152      plugin_type p = (*it); 
    11501153      try { 
    1151         if (p != NULL && (unloadLoggers|| !p->isLoaded())) { 
     1154        if (!p && (unloadLoggers|| !p->isLoaded())) { 
    11521155          it = plugins_.erase(it); 
    1153           delete p; 
     1156          //delete p; 
    11541157          continue; 
    11551158        } 
     
    12091212 */ 
    12101213NSClientT::plugin_type NSClientT::loadPlugin(const boost::filesystem::wpath file) { 
    1211   return addPlugin(new NSCPlugin(file)); 
     1214  plugin_type plugin(new NSCPlugin(file)); 
     1215  return addPlugin(plugin); 
    12121216} 
    12131217/** 
     
    12351239 
    12361240std::wstring NSClientT::describeCommand(std::wstring command) { 
    1237   boost::shared_lock<boost::shared_mutex> readLock(m_mutexRWcmdDescriptions, boost::get_system_time() + boost::posix_time::seconds(5)); 
    1238   if (!readLock.owns_lock()) { 
    1239     LOG_ERROR(_T("FATAL ERROR: Could not get read-mutex when trying to get command list.")); 
    1240     return _T("Failed to get mutex when describing command: ") + command; 
    1241   } 
    1242   cmdMap::const_iterator cit = cmdDescriptions_.find(command); 
    1243   if (cit == cmdDescriptions_.end()) 
    1244     return _T("Command not found: ") + command + _T(", maybe it has not been register?"); 
    1245   return (*cit).second; 
     1241  return commands_.describe(command); 
    12461242} 
    12471243std::list<std::wstring> NSClientT::getAllCommandNames() { 
    1248   std::list<std::wstring> lst; 
    1249   boost::shared_lock<boost::shared_mutex> readLock(m_mutexRWcmdDescriptions, boost::get_system_time() + boost::posix_time::seconds(5)); 
    1250   if (!readLock.owns_lock()) { 
    1251     LOG_ERROR(_T("FATAL ERROR: Could not get read-mutex when trying to get command list.")); 
    1252     return lst; 
    1253   } 
    1254   for (cmdMap::const_iterator cit = cmdDescriptions_.begin(); cit != cmdDescriptions_.end(); ++cit) { 
    1255     lst.push_back((*cit).first); 
    1256   } 
    1257   return lst; 
    1258 } 
    1259 void NSClientT::registerCommand(std::wstring cmd, std::wstring desc) { 
    1260   boost::unique_lock<boost::shared_mutex> writeLock(m_mutexRWcmdDescriptions, boost::get_system_time() + boost::posix_time::seconds(10)); 
    1261   if (!writeLock.owns_lock()) { 
    1262     LOG_ERROR_STD(_T("FATAL ERROR: Failed to describe command:") + cmd); 
    1263     return; 
    1264   } 
    1265   cmdDescriptions_[cmd] = desc; 
     1244  return commands_.list(); 
     1245} 
     1246void NSClientT::registerCommand(unsigned int id, std::wstring cmd, std::wstring desc) { 
     1247  return commands_.register_command(id, cmd, desc); 
    12661248} 
    12671249 
     
    15781560  return _T(""); 
    15791561} 
     1562 
     1563void NSClientT::nsclient_log_error(std::wstring file, int line, std::wstring error) { 
     1564  NSAPIMessage(NSCAPI::error, file.c_str(), line, error); 
     1565} 
  • service/NSClient++.h

    rd05c3f0 rb3078b4  
    2727#include <config.h> 
    2828#include <service/system_service.hpp> 
     29 
    2930#include "NSCPlugin.h" 
     31#include "commands.hpp" 
     32#include "logger.hpp" 
     33 
    3034//#include <nsclient_session.hpp> 
    3135 
     
    5559 * 
    5660 */ 
    57 class NSClientT /*: public nsclient_session::session_handler_interface*/ { 
     61class NSClientT : public nsclient::logger /*: public nsclient_session::session_handler_interface*/ { 
    5862 
    5963public: 
     
    8892  }; 
    8993 
    90   typedef NSCPlugin* plugin_type; 
     94  typedef boost::shared_ptr<NSCPlugin> plugin_type; 
    9195  typedef std::vector<plugin_type> pluginList; 
    92   typedef std::map<std::wstring,std::wstring> cmdMap; 
     96  //typedef std::map<std::wstring,std::wstring> cmdMap; 
    9397  typedef std::list<cached_log_entry> log_cache_type; 
    9498  pluginList plugins_; 
     
    99103  boost::timed_mutex messageMutex; 
    100104  boost::shared_mutex m_mutexRW; 
    101   boost::shared_mutex m_mutexRWcmdDescriptions; 
    102   cmdMap cmdDescriptions_; 
     105  //boost::shared_mutex m_mutexRWcmdDescriptions; 
     106  //cmdMap cmdDescriptions_; 
    103107  typedef enum log_status {log_unknown, log_looking, log_debug, log_nodebug }; 
    104108  log_status debug_; 
     
    114118  bool enable_shared_session_; 
    115119 
     120  nsclient::commands commands_; 
     121 
    116122 
    117123public: 
    118124  // c-tor, d-tor 
    119   NSClientT(void) : debug_(log_unknown), plugins_loaded_(false), enable_shared_session_(false) {} 
     125  NSClientT(void) : debug_(log_unknown), plugins_loaded_(false), enable_shared_session_(false), commands_(this) {} 
    120126  virtual ~NSClientT(void) {} 
    121127  void enableDebug(bool debug = true) { 
     
    137143#endif 
    138144  void service_on_session_changed(DWORD dwSessionId, bool logon, DWORD dwEventType); 
     145 
     146 
     147  // Logger impl 
     148  void nsclient_log_error(std::wstring file, int line, std::wstring error); 
     149 
    139150 
    140151  // Member functions 
  • service/StdAfx.h

    rd05c3f0 rb3078b4  
    4747#include <NSCAPI.h> 
    4848 
     49#include <boost/shared_ptr.hpp> 
    4950#include <boost/thread/thread.hpp> 
    5051#include <boost/thread/locks.hpp> 
     
    5253#include <boost/algorithm/string.hpp> 
    5354#include <boost/filesystem.hpp> 
     55#include <boost/foreach.hpp> 
Note: See TracChangeset for help on using the changeset viewer.