Changeset cad08fb in nscp for service


Ignore:
Timestamp:
02/18/10 12:22:51 (3 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2
Children:
b0e7ecf
Parents:
60375ed
Message:

Major update with a new plugin glue that works better with *nix.
Everything should be the same but look tidier

Location:
service
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • service/CMakeLists.txt

    r40970de rcad08fb  
    1919  settings_manager_impl.cpp 
    2020 
    21   ${NSCP_DEF_PLUGIN_CPP} 
     21  ${NSCP_INCLUDE_PATH}/nscapi/nscapi_helper.cpp 
    2222 
    2323  ${NSCP_INCLUDE_PATH}/simpleini/ConvertUTF.c 
    2424  ${NSCP_INCLUDE_PATH}/b64/b64.c 
     25  ${NSCP_INCLUDE_PATH}/arrayBuffer.cpp 
    2526 
    2627) 
     
    6263    ${NSCP_INCLUDE_PATH}/service/system_service.hpp 
    6364    ${NSCP_INCLUDE_PATH}/service/win32_service.hpp 
    64  
    65     ${NSCP_DEF_PLUGIN_HPP} 
     65    ${NSCP_INCLUDE_PATH}/nscapi/nscapi_helper.hpp 
    6666 
    6767  ) 
  • service/NSCPlugin.cpp

    r60375ed rcad08fb  
    2323#include "core_api.h" 
    2424 
    25 unsigned int NSCPlugin::last_plugin_id_ = 0; 
    26  
    27  
    2825/** 
    2926 * Default c-tor 
     
    3330 * @param file The file (DLL) to load as a NSC plug in. 
    3431 */ 
    35 NSCPlugin::NSCPlugin(const boost::filesystem::wpath file) 
     32NSCPlugin::NSCPlugin(const unsigned int id, const boost::filesystem::wpath file) 
    3633  : module_(file.string()) 
    3734  ,fLoadModule(NULL) 
     
    4340  ,fDeleteBuffer(NULL) 
    4441  ,fGetDescription(NULL) 
    45   ,fGetConfigurationMeta(NULL) 
    4642  ,fGetVersion(NULL) 
    4743  ,fCommandLineExec(NULL) 
     
    5349  ,lastIsMsgPlugin_(false) 
    5450  ,broken_(false) 
    55   ,plugin_id_(0) 
     51  ,plugin_id_(id) 
    5652{ 
    57   plugin_id_ = ++last_plugin_id_; 
     53 
    5854} 
    5955/* 
     
    6763  ,fHandleMessage(NULL) 
    6864  ,fGetDescription(NULL) 
    69   ,fGetConfigurationMeta(NULL) 
    7065  ,fGetVersion(NULL) 
    7166  ,fCommandLineExec(NULL) 
     
    361356 
    362357  try { 
    363     fLoadModule = (lpLoadModule)module_.load_proc("NSLoadModule"); 
     358    fLoadModule = (nscapi::plugin_api::lpLoadModule)module_.load_proc("NSLoadModule"); 
    364359    if (!fLoadModule) 
    365360      throw NSPluginException(module_, _T("Could not load NSLoadModule")); 
    366361 
    367     fModuleHelperInit = (lpModuleHelperInit)module_.load_proc("NSModuleHelperInit"); 
     362    fModuleHelperInit = (nscapi::plugin_api::lpModuleHelperInit)module_.load_proc("NSModuleHelperInit"); 
    368363    if (!fModuleHelperInit) 
    369364      throw NSPluginException(module_, _T("Could not load NSModuleHelperInit")); 
     
    375370    } 
    376371 
    377     fGetName = (lpGetName)module_.load_proc("NSGetModuleName"); 
     372    fGetName = (nscapi::plugin_api::lpGetName)module_.load_proc("NSGetModuleName"); 
    378373    if (!fGetName) 
    379374      throw NSPluginException(module_, _T("Could not load NSGetModuleName")); 
    380375 
    381     fGetVersion = (lpGetVersion)module_.load_proc("NSGetModuleVersion"); 
     376    fGetVersion = (nscapi::plugin_api::lpGetVersion)module_.load_proc("NSGetModuleVersion"); 
    382377    if (!fGetVersion) 
    383378      throw NSPluginException(module_, _T("Could not load NSGetModuleVersion")); 
    384379 
    385     fGetDescription = (lpGetDescription)module_.load_proc("NSGetModuleDescription"); 
     380    fGetDescription = (nscapi::plugin_api::lpGetDescription)module_.load_proc("NSGetModuleDescription"); 
    386381    if (!fGetDescription) 
    387382      throw NSPluginException(module_, _T("Could not load NSGetModuleDescription")); 
    388383 
    389     fHasCommandHandler = (lpHasCommandHandler)module_.load_proc("NSHasCommandHandler"); 
     384    fHasCommandHandler = (nscapi::plugin_api::lpHasCommandHandler)module_.load_proc("NSHasCommandHandler"); 
    390385    if (!fHasCommandHandler) 
    391386      throw NSPluginException(module_, _T("Could not load NSHasCommandHandler")); 
    392387 
    393     fHasMessageHandler = (lpHasMessageHandler)module_.load_proc("NSHasMessageHandler"); 
     388    fHasMessageHandler = (nscapi::plugin_api::lpHasMessageHandler)module_.load_proc("NSHasMessageHandler"); 
    394389    if (!fHasMessageHandler) 
    395390      throw NSPluginException(module_, _T("Could not load NSHasMessageHandler")); 
    396391 
    397     fHandleCommand = (lpHandleCommand)module_.load_proc("NSHandleCommand"); 
     392    fHandleCommand = (nscapi::plugin_api::lpHandleCommand)module_.load_proc("NSHandleCommand"); 
    398393    //if (!fHandleCommand) 
    399394    //  throw NSPluginException(module_, _T("Could not load NSHandleCommand")); 
    400395 
    401     fDeleteBuffer = (lpDeleteBuffer)module_.load_proc("NSDeleteBuffer"); 
     396    fDeleteBuffer = (nscapi::plugin_api::lpDeleteBuffer)module_.load_proc("NSDeleteBuffer"); 
    402397    if (!fDeleteBuffer) 
    403398      throw NSPluginException(module_, _T("Could not load NSDeleteBuffer")); 
    404399 
    405     fHandleMessage = (lpHandleMessage)module_.load_proc("NSHandleMessage"); 
     400    fHandleMessage = (nscapi::plugin_api::lpHandleMessage)module_.load_proc("NSHandleMessage"); 
    406401    if (!fHandleMessage) 
    407402      throw NSPluginException(module_, _T("Could not load NSHandleMessage")); 
    408403 
    409     fUnLoadModule = (lpUnLoadModule)module_.load_proc("NSUnloadModule"); 
     404    fUnLoadModule = (nscapi::plugin_api::lpUnLoadModule)module_.load_proc("NSUnloadModule"); 
    410405    if (!fUnLoadModule) 
    411406      throw NSPluginException(module_, _T("Could not load NSUnloadModule")); 
    412407 
    413     fGetConfigurationMeta = (lpGetConfigurationMeta)module_.load_proc("NSGetConfigurationMeta"); 
    414     fCommandLineExec = (lpCommandLineExec)module_.load_proc("NSCommandLineExec"); 
    415     fHandleNotification = (lpHandleNotification)module_.load_proc("NSHandleNotification"); 
    416     fHasNotificationHandler = (lpHasNotificationHandler)module_.load_proc("NSHasNotificationHandler"); 
     408    fCommandLineExec = (nscapi::plugin_api::lpCommandLineExec)module_.load_proc("NSCommandLineExec"); 
     409    fHandleNotification = (nscapi::plugin_api::lpHandleNotification)module_.load_proc("NSHandleNotification"); 
     410    fHasNotificationHandler = (nscapi::plugin_api::lpHasNotificationHandler)module_.load_proc("NSHasNotificationHandler"); 
    417411     
    418     fShowTray = (lpShowTray)module_.load_proc("ShowIcon"); 
    419     fHideTray = (lpHideTray)module_.load_proc("HideIcon"); 
     412    fShowTray = (nscapi::plugin_api::lpShowTray)module_.load_proc("ShowIcon"); 
     413    fHideTray = (nscapi::plugin_api::lpHideTray)module_.load_proc("HideIcon"); 
    420414     
    421415  } catch (NSPluginException &e) { 
     
    430424 
    431425 
    432 std::wstring NSCPlugin::getCongifurationMeta()  
    433 { 
    434   wchar_t *buffer = new wchar_t[4097]; 
    435   if (!getConfigurationMeta_(buffer, 4096)) { 
    436     throw NSPluginException(module_, _T("Could not get metadata")); 
    437   } 
    438   std::wstring ret = buffer; 
    439   delete [] buffer; 
    440   return ret; 
    441 } 
    442 bool NSCPlugin::getConfigurationMeta_(wchar_t* buf, unsigned int buflen) { 
    443   if (fGetConfigurationMeta == NULL) 
    444     throw NSPluginException(module_, _T("Critical error (getCongifurationMeta)")); 
    445   try { 
    446     return fGetConfigurationMeta(buflen, buf)?true:false; 
    447   } catch (...) { 
    448     throw NSPluginException(module_, _T("Unhandled exception in getConfigurationMeta.")); 
    449   } 
    450 } 
    451  
    452426int NSCPlugin::commandLineExec(const unsigned int argLen, wchar_t **arguments) { 
    453427  if (fCommandLineExec== NULL) 
     
    459433  } 
    460434} 
     435 
  • service/NSCPlugin.h

    r40970de rcad08fb  
    2525#include <sstream> 
    2626#include <dll/dll.hpp> 
     27#include <boost/noncopyable.hpp> 
    2728 
    2829/** 
     
    103104 * 
    104105 */ 
    105 class NSCPlugin { 
     106class NSCPlugin : boost::noncopyable { 
    106107private: 
    107108  bool bLoaded_;      // Status of plug in 
    108109  dll::dll module_; 
    109110  bool broken_; 
    110   static unsigned int last_plugin_id_; 
    111111  unsigned int plugin_id_; 
    112112 
    113   typedef int (*lpModuleHelperInit)(unsigned int, NSCModuleHelper::lpNSAPILoader f); 
    114   typedef int (*lpLoadModule)(int); 
    115   typedef int (*lpGetName)(wchar_t*,unsigned int); 
    116   typedef int (*lpGetDescription)(wchar_t*,unsigned int); 
    117   typedef int (*lpGetVersion)(int*,int*,int*); 
    118   typedef int (*lpHasCommandHandler)(); 
    119   typedef int (*lpHasMessageHandler)(); 
    120   typedef NSCAPI::nagiosReturn (*lpHandleCommand)(const wchar_t*,const char*,const unsigned int,char**,unsigned int*); 
    121   typedef int (*lpDeleteBuffer)(char**); 
    122   typedef int (*lpCommandLineExec)(const unsigned int,wchar_t**); 
    123   typedef int (*lpHandleMessage)(int,const wchar_t*,const int,const wchar_t*); 
    124   typedef int (*lpUnLoadModule)(); 
    125   typedef int (*lpGetConfigurationMeta)(int, wchar_t*); 
    126   typedef void (*lpShowTray)(); 
    127   typedef void (*lpHideTray)(); 
    128   typedef int (*lpHasNotificationHandler)(); 
    129   typedef int (*lpHandleNotification)(const wchar_t *channel, const wchar_t* command, NSCAPI::nagiosReturn code, char* result, unsigned int result_len); 
    130  
    131  
    132   lpModuleHelperInit fModuleHelperInit; 
    133   lpLoadModule fLoadModule; 
    134   lpGetName fGetName; 
    135   lpGetVersion fGetVersion; 
    136   lpGetDescription fGetDescription; 
    137   lpHasCommandHandler fHasCommandHandler; 
    138   lpHasMessageHandler fHasMessageHandler; 
    139   lpHandleCommand fHandleCommand; 
    140   lpDeleteBuffer fDeleteBuffer; 
    141   lpHandleMessage fHandleMessage; 
    142   lpUnLoadModule fUnLoadModule; 
    143   lpGetConfigurationMeta fGetConfigurationMeta; 
    144   lpCommandLineExec fCommandLineExec; 
    145   lpShowTray fShowTray; 
    146   lpHideTray fHideTray; 
    147   lpHasNotificationHandler fHasNotificationHandler; 
    148   lpHandleNotification fHandleNotification; 
     113  nscapi::plugin_api::lpModuleHelperInit fModuleHelperInit; 
     114  nscapi::plugin_api::lpLoadModule fLoadModule; 
     115  nscapi::plugin_api::lpGetName fGetName; 
     116  nscapi::plugin_api::lpGetVersion fGetVersion; 
     117  nscapi::plugin_api::lpGetDescription fGetDescription; 
     118  nscapi::plugin_api::lpHasCommandHandler fHasCommandHandler; 
     119  nscapi::plugin_api::lpHasMessageHandler fHasMessageHandler; 
     120  nscapi::plugin_api::lpHandleCommand fHandleCommand; 
     121  nscapi::plugin_api::lpDeleteBuffer fDeleteBuffer; 
     122  nscapi::plugin_api::lpHandleMessage fHandleMessage; 
     123  nscapi::plugin_api::lpUnLoadModule fUnLoadModule; 
     124  nscapi::plugin_api::lpCommandLineExec fCommandLineExec; 
     125  nscapi::plugin_api::lpShowTray fShowTray; 
     126  nscapi::plugin_api::lpHideTray fHideTray; 
     127  nscapi::plugin_api::lpHasNotificationHandler fHasNotificationHandler; 
     128  nscapi::plugin_api::lpHandleNotification fHandleNotification; 
    149129 
    150130public: 
    151   NSCPlugin(const boost::filesystem::wpath file); 
    152   NSCPlugin(NSCPlugin &other); 
     131  NSCPlugin(const unsigned int id, const boost::filesystem::wpath file); 
     132  //NSCPlugin(NSCPlugin &other); 
    153133  virtual ~NSCPlugin(void); 
    154134 
     
    192172    return file; 
    193173  } 
     174  static std::wstring get_plugin_file(std::wstring key) { 
     175#ifdef WIN32 
     176    return key + _T(".dll"); 
     177#else 
     178    return _T("lib") + key + _T(".so"); 
     179#endif 
     180  } 
    194181  bool getLastIsMsgPlugin() { 
    195182    return lastIsMsgPlugin_; 
     
    205192  bool getDescription_(wchar_t* buf, unsigned int buflen); 
    206193  void loadRemoteProcs_(void); 
    207   bool getConfigurationMeta_(wchar_t* buf, unsigned int buflen); 
    208194}; 
    209195 
  • service/NSClient++.cpp

    r60375ed rcad08fb  
    3535#include "settings_manager_impl.h" 
    3636#include <settings/macros.h> 
    37 #include <NSCHelper.h> 
    3837#include "simple_client.hpp" 
    3938#include "settings_client.hpp" 
    4039#include "service_manager.hpp" 
     40#include <nscapi/nscapi_helper.hpp> 
    4141 
    4242#include "../libs/protobuf/plugin.proto.h" 
     
    304304    } else if ( wcscasecmp( _T("about"), argv[1]+1 ) == 0 ) { 
    305305      try { 
     306        unsigned int next_plugin_id = 0; 
    306307        g_bConsoleLog = true; 
    307308        LOG_MESSAGE(SZAPPNAME _T(" (C) Michael Medin - michael<at>medin<dot>name")); 
     
    318319            LOG_MESSAGE_STD(_T("Found: ") + file); 
    319320            if (is_module(pluginPath / file)) { 
    320               NSCPlugin *plugin = new NSCPlugin(pluginPath / file); 
     321              NSCPlugin *plugin = new NSCPlugin(next_plugin_id++, pluginPath / file); 
    321322              std::wstring name = _T("<unknown>"); 
    322323              std::wstring description = _T("<unknown>"); 
     
    459460        try { 
    460461          LOG_DEBUG_STD(_T("Attempting to fake load: ") + file.string()); 
    461           NSCPlugin plugin(pluginPath / file); 
     462          NSCPlugin plugin(next_plugin_id_++, pluginPath / file); 
    462463          plugin.load_dll(); 
    463464          plugin.load_plugin(NSCAPI::dontStart); 
     
    490491            try { 
    491492              LOG_DEBUG_STD(_T("Attempting to fake load: ") + file.string()); 
    492               NSCPlugin plugin(modPath / file); 
     493              NSCPlugin plugin(next_plugin_id_++, modPath / file); 
    493494              plugin.load_dll(); 
    494495              plugin.load_plugin(mode); 
     
    504505          std::wstring name = file.string(); 
    505506          try { 
    506             NSCPlugin plugin(modPath / file); 
     507            NSCPlugin plugin(next_plugin_id_++, modPath / file); 
    507508            name = plugin.getModule(); 
    508509            plugin.load_dll(); 
     
    626627      Settings::string_list list = settings_manager::get_settings()->get_keys(MAIN_MODULES_SECTION); 
    627628      for (Settings::string_list::const_iterator cit = list.begin(); cit != list.end(); ++cit) { 
    628         LOG_DEBUG_STD(_T("Processing plugin: " + *cit)); 
     629        std::wstring file = NSCPlugin::get_plugin_file(*cit); 
     630        LOG_DEBUG_STD(_T("Processing plugin: " + *cit) + _T(" in ") + file); 
    629631        try { 
    630632          if (settings_manager::get_settings()->get_string(MAIN_MODULES_SECTION, *cit) == _T("disabled")) { 
    631             LOG_DEBUG_STD(_T("Not booting: ") + *cit + _T(" since it is disabled.")); 
     633            LOG_DEBUG_STD(_T("Not booting: ") + file + _T(" since it is disabled.")); 
    632634            continue; 
    633635          } 
     
    636638        } 
    637639        try { 
    638           loadPlugin(getBasePath() / boost::filesystem::wpath(_T("modules")) / boost::filesystem::wpath(*cit)); 
     640          loadPlugin(getBasePath() / boost::filesystem::wpath(_T("modules")) / boost::filesystem::wpath(file)); 
    639641        } catch(const NSPluginException& e) { 
    640642          LOG_ERROR_CORE_STD(_T("Exception raised: '") + e.error_ + _T("' in module: ") + e.file_); 
    641643          //return false; 
    642644        } catch (std::exception e) { 
    643           LOG_ERROR_CORE_STD(_T("exception loading plugin: ") + (*cit) + strEx::string_to_wstring(e.what())); 
     645          LOG_ERROR_CORE_STD(_T("exception loading plugin: ") + file + strEx::string_to_wstring(e.what())); 
    644646          return false; 
    645647        } catch (...) { 
    646           LOG_ERROR_CORE_STD(_T("Unknown exception loading plugin: ") + (*cit)); 
     648          LOG_ERROR_CORE_STD(_T("Unknown exception loading plugin: ") + file); 
    647649          return false; 
    648650        } 
     
    971973 */ 
    972974NSClientT::plugin_type NSClientT::loadPlugin(const boost::filesystem::wpath file) { 
    973   plugin_type plugin(new NSCPlugin(file)); 
     975  plugin_type plugin(new NSCPlugin(next_plugin_id_++, file)); 
    974976  return addPlugin(plugin); 
    975977} 
     
    11221124      } 
    11231125      NSCAPI::nagiosReturn c = plugin->handleCommand(command, request, response); 
    1124       LOG_DEBUG_STD(_T("Result ") + std::wstring(command) + _T(": ") + NSCHelper::translateReturn(c) + _T(" {{{") + strEx::strip_hex(to_wstring(response)) + _T("}}}")); 
     1126      LOG_DEBUG_STD(_T("Result ") + std::wstring(command) + _T(": ") + nscapi::plugin_helper::translateReturn(c) + _T(" {{{") + strEx::strip_hex(to_wstring(response)) + _T("}}}")); 
    11251127      return c; 
    11261128    } catch (nsclient::commands::command_exception &e) { 
     
    12011203  OutputDebugString(msg.c_str()); 
    12021204#else 
    1203   std::wcout << _T("--BROKEN MESSAGE: ") << msg << _T("--") << std::endl; 
     1205//  std::wcout << _T("--BROKEN MESSAGE: ") << msg << _T("--") << std::endl; 
    12041206#endif 
    12051207} 
  • service/NSClient++.h

    r40970de rcad08fb  
    123123  nsclient::commands commands_; 
    124124  nsclient::channels channels_; 
     125  unsigned int next_plugin_id_; 
    125126 
    126127 
    127128public: 
    128129  // c-tor, d-tor 
    129   NSClientT(void) : debug_(log_unknown), plugins_loaded_(false), enable_shared_session_(false), commands_(this), channels_(this) {} 
     130  NSClientT(void) : debug_(log_unknown), plugins_loaded_(false), enable_shared_session_(false), commands_(this), channels_(this), next_plugin_id_(0) {} 
    130131  virtual ~NSClientT(void) {} 
    131132  void enableDebug(bool debug = true) { 
  • service/commands.hpp

    rc0d7e82 rcad08fb  
    55#include "NSCPlugin.h" 
    66#include "logger.hpp" 
     7#include <strEx.h> 
    78 
    89namespace nsclient { 
     
    4041 
    4142    void add_plugin(plugin_type plugin) { 
    42       if (!plugin || !plugin->hasCommandHandler()) 
     43      if (!plugin || !plugin->hasCommandHandler()) { 
    4344        return; 
     45      } 
    4446      plugins_[plugin->get_id()] = plugin; 
    4547       
     
    8890      std::wstring lc = make_key(cmd); 
    8991      if (!have_plugin(plugin_id)) 
    90         throw command_exception("Failed to find plugin: " + ::to_string(plugin_id)); 
     92        throw command_exception("Failed to find plugin: " + ::to_string(plugin_id) + ": " + unsafe_get_all_plugin_ids()); 
    9193      descriptions_[lc] = desc; 
    9294      commands_[lc] = plugins_[plugin_id]; 
    9395    } 
     96private: 
    9497 
     98    std::string unsafe_get_all_plugin_ids() { 
     99      std::string ret; 
     100      std::pair<unsigned long,plugin_type> cit; 
     101      BOOST_FOREACH(cit, plugins_) { 
     102        ret += ::to_string(cit.first) + ", "; 
     103        //lst.push_back(::to_wstring(cit.first) + _T("=") + cit.second->getName()); 
     104        //lst.push_back(::to_wstring(cit.first)); 
     105      } 
     106      return ret; 
     107    } 
     108 
     109 
     110public: 
    95111    std::wstring describe(std::wstring command) { 
    96112      boost::shared_lock<boost::shared_mutex> readLock(mutex_, boost::get_system_time() + boost::posix_time::seconds(5)); 
     
    120136    } 
    121137 
     138    std::list<std::wstring> list_plugins() { 
     139      std::list<std::wstring> lst; 
     140      boost::shared_lock<boost::shared_mutex> readLock(mutex_, boost::get_system_time() + boost::posix_time::seconds(5)); 
     141      if (!readLock.owns_lock()) { 
     142        log_error(__FILEW__, __LINE__, _T("Failed to get mutex")); 
     143        return lst; 
     144      } 
     145      std::pair<unsigned long,plugin_type> cit; 
     146      BOOST_FOREACH(cit, plugins_) { 
     147        //lst.push_back(::to_wstring(cit.first) + _T("=") + cit.second->getName()); 
     148        lst.push_back(::to_wstring(cit.first)); 
     149      } 
     150      return lst; 
     151    } 
     152 
    122153    plugin_type get(std::wstring command) { 
    123154      boost::shared_lock<boost::shared_mutex> readLock(mutex_, boost::get_system_time() + boost::posix_time::seconds(5)); 
     
    136167 
    137168    std::wstring to_wstring() { 
    138       std::wstring ret; 
     169      std::wstring ret = _T("commands {"); 
    139170      BOOST_FOREACH(std::wstring str, list()) { 
    140171        if (!ret.empty()) ret += _T(", "); 
    141172        ret += str; 
    142173      } 
     174      ret += _T("}, plugins {"); 
     175      BOOST_FOREACH(std::wstring str, list_plugins()) { 
     176        if (!ret.empty()) ret += _T(", "); 
     177        ret += str; 
     178      } 
     179      ret += _T("}"); 
    143180      return ret; 
    144181    } 
  • service/core_api.cpp

    r40970de rcad08fb  
    1919#include <config.h> 
    2020#include <msvc_wrappers.h> 
     21#include <arrayBuffer.h> 
    2122//#include <settings/settings_ini.hpp> 
    2223//#include <settings/settings_registry.hpp> 
     
    2829#include "settings_manager_impl.h" 
    2930#include <b64/b64.h> 
    30 #include <NSCHelper.h> 
     31#include <nscapi/nscapi_helper.hpp> 
    3132#ifdef _WIN32 
    3233#include <ServiceCmd.h> 
     
    3435 
    3536#define LOG_ERROR_STD(msg) LOG_ERROR(((std::wstring)msg).c_str()) 
    36 #define LOG_ERROR(msg) \ 
    37   NSAPIMessage(NSCAPI::error, __FILEW__, __LINE__, msg) 
    38  
     37#define LOG_ERROR(msg) LOG_ANY(msg, NSCAPI::error) 
    3938#define LOG_CRITICAL_STD(msg) LOG_CRITICAL(((std::wstring)msg).c_str()) 
    40 #define LOG_CRITICAL(msg) \ 
    41   NSAPIMessage(NSCAPI::critical, __FILEW__, __LINE__, msg) 
     39#define LOG_CRITICAL(msg) LOG_ANY(msg, NSCAPI::critical) 
    4240#define LOG_MESSAGE_STD(msg) LOG_MESSAGE(((std::wstring)msg).c_str()) 
    43 #define LOG_MESSAGE(msg) \ 
    44   NSAPIMessage(NSCAPI::log, __FILEW__, __LINE__, msg) 
    45  
     41#define LOG_MESSAGE(msg) LOG_ANY(msg, NSCAPI::log) 
    4642#define LOG_DEBUG_STD(msg) LOG_DEBUG(((std::wstring)msg).c_str()) 
    47 #define LOG_DEBUG(msg) \ 
    48   NSAPIMessage(NSCAPI::debug, __FILEW__, __LINE__, msg) 
    49  
     43#define LOG_DEBUG(msg) LOG_ANY(msg, NSCAPI::debug) 
     44 
     45#define LOG_ANY(msg, type) NSAPIMessage(type, __FILEW__, __LINE__, msg) 
    5046 
    5147NSCAPI::errorReturn NSAPIGetSettingsString(const wchar_t* section, const wchar_t* key, const wchar_t* defaultValue, wchar_t* buffer, unsigned int bufLen) { 
    5248  try { 
    53     return NSCHelper::wrapReturnString(buffer, bufLen, settings_manager::get_settings()->get_string(section, key, defaultValue), NSCAPI::isSuccess); 
     49    return nscapi::plugin_helper::wrapReturnString(buffer, bufLen, settings_manager::get_settings()->get_string(section, key, defaultValue), NSCAPI::isSuccess); 
    5450  } catch (...) { 
    5551    LOG_ERROR_STD(_T("Failed to getString: ") + key); 
     
    6662} 
    6763NSCAPI::errorReturn NSAPIGetBasePath(wchar_t*buffer, unsigned int bufLen) { 
    68   return NSCHelper::wrapReturnString(buffer, bufLen, mainClient.getBasePath().string(), NSCAPI::isSuccess); 
     64  return nscapi::plugin_helper::wrapReturnString(buffer, bufLen, mainClient.getBasePath().string(), NSCAPI::isSuccess); 
    6965} 
    7066NSCAPI::errorReturn NSAPIGetApplicationName(wchar_t*buffer, unsigned int bufLen) { 
    71   return NSCHelper::wrapReturnString(buffer, bufLen, SZAPPNAME, NSCAPI::isSuccess); 
     67  return nscapi::plugin_helper::wrapReturnString(buffer, bufLen, SZAPPNAME, NSCAPI::isSuccess); 
    7268} 
    7369NSCAPI::errorReturn NSAPIGetApplicationVersionStr(wchar_t*buffer, unsigned int bufLen) { 
    74   return NSCHelper::wrapReturnString(buffer, bufLen, SZVERSION, NSCAPI::isSuccess); 
     70  return nscapi::plugin_helper::wrapReturnString(buffer, bufLen, SZVERSION, NSCAPI::isSuccess); 
    7571} 
    7672void NSAPIMessage(int msgType, const wchar_t* file, const int line, const wchar_t* message) { 
     
    262258} 
    263259NSCAPI::errorReturn NSAPIDescribeCommand(const wchar_t* command, wchar_t* buffer, unsigned int bufLen) { 
    264   return NSCHelper::wrapReturnString(buffer, bufLen, mainClient.describeCommand(command), NSCAPI::isSuccess); 
     260  return nscapi::plugin_helper::wrapReturnString(buffer, bufLen, mainClient.describeCommand(command), NSCAPI::isSuccess); 
    265261} 
    266262NSCAPI::errorReturn NSAPIGetAllCommandNames(arrayBuffer::arrayBuffer* aBuffer, unsigned int *bufLen) { 
     
    369365 
    370366 
    371 LPVOID NSAPILoader(wchar_t*buffer) { 
     367LPVOID NSAPILoader(const wchar_t*buffer) { 
    372368  if (wcscasecmp(buffer, _T("NSAPIGetApplicationName")) == 0) 
    373369    return reinterpret_cast<LPVOID>(&NSAPIGetApplicationName); 
  • service/core_api.h

    r40970de rcad08fb  
    3030// 
    3131 
    32 LPVOID NSAPILoader(wchar_t*buffer); 
     32LPVOID NSAPILoader(const wchar_t*buffer); 
    3333NSCAPI::errorReturn NSAPIGetApplicationName(wchar_t*buffer, unsigned int bufLen); 
    3434NSCAPI::errorReturn NSAPIGetBasePath(wchar_t*buffer, unsigned int bufLen); 
  • service/simple_client.hpp

    rc0d7e82 rcad08fb  
    11#pragma once 
     2#include <nscapi/nscapi_helper.hpp> 
    23 
    34class NSClientT; 
     
    2526*/ 
    2627      std::wstring s = _T(""); 
    27       std::wstring buff = _T(""); 
     28 
    2829      while (true) { 
    29         std::wcin >> s; 
     30        std::wstring s; 
     31        std::getline(std::wcin, s); 
    3032        if (s == _T("exit")) { 
    3133          std::wcout << _T("Exiting...") << std::endl; 
     
    4042            std::wcout << *cit << _T(": ") << core_->describeCommand(*cit) << std::endl; 
    4143          std::wcout << _T("Listing commands...Done") << std::endl; 
    42         } else if (s == _T("off") && buff == _T("debug ")) { 
     44        } else if (s == _T("debug off")) { 
    4345          std::wcout << _T("Setting debug log off...") << std::endl; 
    4446          core_->enableDebug(false); 
    45         } else if (s == _T("on") && buff == _T("debug ")) { 
     47        } else if (s == _T("debug on")) { 
    4648          std::wcout << _T("Setting debug log on...") << std::endl; 
    4749          core_->enableDebug(true); 
     
    5153        } else if (s == _T("assert")) { 
    5254          throw "test"; 
    53         } else if (std::cin.peek() < 15) { 
    54           buff += s; 
    55           strEx::token t = strEx::getToken(buff, ' '); 
     55        } else { 
     56          strEx::token t = strEx::getToken(s, ' '); 
    5657          std::wstring msg, perf; 
    5758          NSCAPI::nagiosReturn ret = core_->inject(t.first, t.second, msg, perf); 
     
    5960            std::wcout << _T("No handler for command: ") << t.first << std::endl; 
    6061          } else { 
    61             std::wcout << NSCHelper::translateReturn(ret) << _T(":"); 
    62             std::cout << strEx::wstring_to_string(msg); 
     62            std::wcout << nscapi::plugin_helper::translateReturn(ret) << _T(":"); 
     63            std::wcout << msg; 
    6364            if (!perf.empty()) 
    6465              std::cout << "|" << strEx::wstring_to_string(perf); 
    6566            std::wcout << std::endl; 
    6667          } 
    67           buff = _T(""); 
    68         } else { 
    69           buff += s + _T(" "); 
    7068        } 
    7169      } 
Note: See TracChangeset for help on using the changeset viewer.