Changeset a44cb15 in nscp


Ignore:
Timestamp:
09/02/11 07:38:44 (21 months ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2
Children:
a14aa07
Parents:
3b11e65
Message:
  • Implemented registration of channels (so no longer faked)
  • Added settings key to change the NSCAAgent channel name
  • Addded proper channel handling to PythonScript module
  • Improved error handling in channels API
  • Rewrote wrapper API to use templates and classes instead of macros (ish)
  • Improved the internal plugin wrapping API to support multiple plugin load
  • Fixed so PythonScript module supports multiple plugin load (with new argument for plugin_id)
  • Added API for registrying routers and handling routing (almost there now)
  • Fixed issue with messages due to new API
Files:
38 edited

Legend:

Unmodified
Added
Removed
  • changelog

    r81e420c ra44cb15  
    55 * Fixa dependonservice LanManWorkStation (old win) 
    66 * Fix RtlStringFromGUID problem on NT4 
     7 
     82011-09-01 MickeM 
     9 * Implemented registration of channels (so no longer faked) 
     10 * Added settings key to change the NSCAAgent channel name 
     11 * Addded proper channel handling to PythonScript module 
     12 * Improved error handling in channels API 
     13 * Rewrote wrapper API to use templates and classes instead of macros (ish) 
     14 * Improved the internal plugin wrapping API to support multiple plugin load 
     15 * Fixed so PythonScript module supports multiple plugin load (with new argument for plugin_id) 
     16 * Added API for registrying routers and handling routing (almost there now) 
     17 
     182011-09-01 MickeM 
     19 * Fixed issue with messages due to new API 
    720 
    8212011-08-31 MickeM 
  • include/NSCAPI.h

    r81e420c ra44cb15  
    152152    typedef void (*lpNSAPIDestroyBuffer)(char**); 
    153153 
    154     typedef NSCAPI::errorReturn (*lpNSAPINotify)(const wchar_t*, const wchar_t*, NSCAPI::nagiosReturn, const char*, unsigned int); 
     154    typedef NSCAPI::errorReturn (*lpNSAPINotify)(const wchar_t* channel, const wchar_t* command, const char* buffer, unsigned int buffer_len); 
    155155 
    156156    typedef NSCAPI::boolReturn (*lpNSAPICheckLogMessages)(int); 
     
    171171    typedef NSCAPI::errorReturn (*lpNSAPIReleasePluginList)(int len, NSCAPI::plugin_info *list[]); 
    172172    typedef NSCAPI::errorReturn (*lpNSAPISettingsSave)(void); 
     173    typedef NSCAPI::errorReturn (*lpNSAPIRegisterSubmissionListener)(unsigned int plugin_id, const wchar_t* channel); 
     174    typedef NSCAPI::errorReturn (*lpNSAPIRegisterRoutingListener)(unsigned int plugin_id, const wchar_t* channel); 
     175 
    173176  } 
    174177 
  • include/nscapi/functions.hpp

    r81e420c ra44cb15  
    174174    } 
    175175 
    176     static void parse_simple_query_response(std::string &response, std::wstring &msg, std::wstring &perf) { 
     176    static int parse_simple_query_response(std::string &response, std::wstring &msg, std::wstring &perf) { 
    177177      Plugin::QueryResponseMessage message; 
    178178      message.ParseFromString(response); 
     
    180180 
    181181      if (message.payload_size() == 0) { 
    182         return; 
     182        return NSCAPI::returnUNKNOWN; 
    183183      } else if (message.payload_size() > 1) { 
    184184        throw nscapi_exception(_T("Whoops, invalid payload size (for now)")); 
     
    188188      msg = utf8::cvt<std::wstring>(payload.message()); 
    189189      perf = utf8::cvt<std::wstring>(build_performance_data(payload)); 
     190      return gbp_to_nagios_status(payload.result()); 
    190191    } 
    191192 
  • include/nscapi/macros.hpp

    r3b11e65 ra44cb15  
    22#include <unicode_char.hpp> 
    33#include <boost/shared_ptr.hpp> 
    4 #include <map> 
     4#include <NSCAPI.h> 
    55 
    66////////////////////////////////////////////////////////////////////////// 
     
    2626#define NSC_WRAPPERS_CHANNELS() \ 
    2727  extern "C" int NSHasNotificationHandler(unsigned int plugin_id); \ 
    28   extern "C" int NSHandleNotification(unsigned int plugin_id, const wchar_t*, const wchar_t*, NSCAPI::nagiosReturn, const char*, unsigned int); 
     28  extern "C" int NSHandleNotification(unsigned int plugin_id, const wchar_t*, const wchar_t*, const char*, unsigned int); 
    2929 
    3030#define NSC_WRAPPERS_ROUTING() \ 
     
    7676#endif 
    7777 
    78 template<class impl_type> 
    79 struct plugin_instance_data { 
    80   typedef std::map<unsigned int, boost::shared_ptr<impl_type> > plugin_list_type; 
    81   plugin_list_type plugins; 
    82   boost::shared_ptr<impl_type> get(unsigned int id) { 
    83     typename plugin_list_type::iterator it = plugins.find(id); 
    84     if (it != plugins.end()) 
    85       return it->second; 
    86     boost::shared_ptr<impl_type> impl = boost::shared_ptr<impl_type>(new impl_type()); 
    87     plugins[id] = impl; 
    88     return impl;  
    89   } 
    90   void erase(unsigned int id) { 
    91     plugins.erase(id); 
    92   } 
    93 }; 
    94  
    9578 
    9679#define NSC_WRAPPERS_MAIN_DEF(impl_class) \ 
    97   static plugin_instance_data<impl_class> plugin_instance; \ 
    98   extern int NSModuleHelperInit(unsigned int id, nscapi::core_api::lpNSAPILoader f) { \ 
    99     try { \ 
    100       return GET_PLUGIN()->wrapModuleHelperInit(id, f); \ 
    101     } catch (...) { \ 
    102       NSC_LOG_CRITICAL(_T("Unknown exception in: wrapModuleHelperInit(...)")); \ 
    103       return NSCAPI::hasFailed; \ 
    104     } \ 
    105   } \ 
     80  typedef impl_class plugin_impl_class; \ 
     81  static nscapi::plugin_instance_data<plugin_impl_class> plugin_instance; \ 
     82  extern int NSModuleHelperInit(unsigned int id, nscapi::core_api::lpNSAPILoader f) { return nscapi::basic_wrapper_static<plugin_impl_class>::NSModuleHelperInit(f); } \ 
    10683  extern int NSLoadModuleEx(unsigned int id, wchar_t* alias, int mode) { \ 
    107   try { \ 
    108   return GET_PLUGIN()->wrapLoadModule(plugin_instance.get(id)->loadModuleEx(alias, mode)); \ 
    109     } catch (...) { \ 
    110     NSC_LOG_CRITICAL(_T("Unknown exception in: wrapLoadModule(...)")); \ 
    111     return NSCAPI::hasFailed; \ 
    112     } \ 
    113   } \ 
    114   extern int NSLoadModule() { \ 
    115     return NSCAPI::hasFailed; \ 
    116   } \ 
    117   extern int NSGetModuleName(wchar_t* buf, int buflen) { \ 
    118     try { \ 
    119       return GET_PLUGIN()->wrapGetModuleName(buf, buflen, impl_class::getModuleName()); \ 
    120     } catch (...) { \ 
    121       NSC_LOG_CRITICAL(_T("Unknown exception in: wrapGetModuleName(...)")); \ 
    122       return NSCAPI::hasFailed; \ 
    123     } \ 
    124   } \ 
    125   extern int NSGetModuleDescription(wchar_t* buf, int buflen) { \ 
    126     try { \ 
    127       return GET_PLUGIN()->wrapGetModuleName(buf, buflen, impl_class::getModuleDescription()); \ 
    128     } catch (...) { \ 
    129       NSC_LOG_CRITICAL(_T("Unknown exception in: wrapGetModuleName(...)")); \ 
    130       return NSCAPI::hasFailed; \ 
    131     } \ 
    132   } \ 
    133   extern int NSGetModuleVersion(int *major, int *minor, int *revision) { \ 
    134     try { \ 
    135       return GET_PLUGIN()->wrapGetModuleVersion(major, minor, revision, impl_class::getModuleVersion()); \ 
    136     } catch (...) { \ 
    137       NSC_LOG_CRITICAL(_T("Unknown exception in: wrapGetModuleVersion(...)")); \ 
    138       return NSCAPI::hasFailed; \ 
    139     } \ 
    140   } \ 
     84    nscapi::basic_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \ 
     85    return wrapper.NSLoadModuleEx(id, alias, mode); } \ 
     86  extern int NSLoadModule() { return nscapi::basic_wrapper_static<plugin_impl_class>::NSLoadModule(); } \ 
     87  extern int NSGetModuleName(wchar_t* buf, int buflen) { return nscapi::basic_wrapper_static<plugin_impl_class>::NSGetModuleName(buf, buflen); } \ 
     88  extern int NSGetModuleDescription(wchar_t* buf, int buflen) { return nscapi::basic_wrapper_static<plugin_impl_class>::NSGetModuleDescription(buf, buflen); } \ 
     89  extern int NSGetModuleVersion(int *major, int *minor, int *revision) { return nscapi::basic_wrapper_static<plugin_impl_class>::NSGetModuleVersion(major, minor, revision); } \ 
    14190  extern int NSUnloadModule(unsigned int id) { \ 
    142     try { \ 
    143       int ret = GET_PLUGIN()->wrapUnloadModule(plugin_instance.get(id)->unloadModule()); \ 
    144       plugin_instance.erase(id); \ 
    145       return ret; \ 
    146     } catch (...) { \ 
    147       NSC_LOG_CRITICAL(_T("Unknown exception in: wrapGetModuleVersion(...)")); \ 
    148       return NSCAPI::hasFailed; \ 
    149     } \ 
    150   } \ 
    151   extern void NSDeleteBuffer(char**buffer) { \ 
    152     try { \ 
    153       GET_PLUGIN()->wrapDeleteBuffer(buffer); \ 
    154     } catch (...) { \ 
    155       NSC_LOG_CRITICAL(_T("Unknown exception in: wrapModuleHelperInit(...)")); \ 
    156     } \ 
    157   } 
     91    nscapi::basic_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \ 
     92    return wrapper.NSUnloadModule(); } \ 
     93  extern void NSDeleteBuffer(char**buffer) { nscapi::basic_wrapper_static<plugin_impl_class>::NSDeleteBuffer(buffer); } 
     94 
    15895#define NSC_WRAPPERS_HANDLE_MSG_DEF(toObject) \ 
    15996  extern void NSHandleMessage(unsigned int id, const char* request_buffer, unsigned int request_buffer_len) { \ 
    160     try { \ 
    161       std::string request(request_buffer, request_buffer_len); \ 
    162       plugin_instance.get(id)->handleMessageRAW(request); \ 
    163     } catch (...) { \ 
    164       NSC_LOG_CRITICAL(_T("Unknown exception in: handleMessage(...)")); \ 
    165     } \ 
    166   } \ 
     97    nscapi::message_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \ 
     98    return wrapper.NSHandleMessage(request_buffer, request_buffer_len); } \ 
    16799  extern NSCAPI::boolReturn NSHasMessageHandler(unsigned int id) { \ 
    168     try { \ 
    169       return GET_PLUGIN()->wrapHasMessageHandler(plugin_instance.get(id)->hasMessageHandler()); \ 
    170     } catch (...) { \ 
    171       NSC_LOG_CRITICAL(_T("Unknown exception in: wrapHasMessageHandler(...)")); \ 
    172       return NSCAPI::isfalse; \ 
    173     } \ 
    174   } 
     100    nscapi::message_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \ 
     101    return wrapper.NSHasMessageHandler(); } 
     102 
     103#define NSC_WRAPPERS_HANDLE_CMD_DEF() \ 
     104  extern NSCAPI::nagiosReturn NSHandleCommand(unsigned int id, const wchar_t* command, const char* request_buffer, const unsigned int request_buffer_len, char** reply_buffer, unsigned int *reply_buffer_len) { \ 
     105    nscapi::command_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \ 
     106    return wrapper.NSHandleCommand(command, request_buffer, request_buffer_len, reply_buffer, reply_buffer_len); } \ 
     107  extern NSCAPI::boolReturn NSHasCommandHandler(unsigned int id) { \ 
     108    nscapi::command_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \ 
     109    return wrapper.NSHasCommandHandler(); } 
     110 
     111#define NSC_WRAPPERS_ROUTING_DEF() \ 
     112  extern NSCAPI::nagiosReturn NSRouteMessage(unsigned int id, const wchar_t* channel, const wchar_t* command, const char* request_buffer, const unsigned int request_buffer_len) { \ 
     113    nscapi::routing_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \ 
     114    return wrapper.NSRouteMessage(channel, command, request_buffer, request_buffer_len); } \ 
     115  extern NSCAPI::boolReturn NSHasRoutingHandler(unsigned int id) { \ 
     116    nscapi::routing_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \ 
     117    return wrapper.NSHasRoutingHandler(); } 
     118 
     119#define NSC_WRAPPERS_HANDLE_NOTIFICATION_DEF() \ 
     120  extern int NSHandleNotification(unsigned int id, const wchar_t* channel, const wchar_t* command, const char* result_buffer, unsigned int result_buffer_len) { \ 
     121    nscapi::submission_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \ 
     122    return wrapper.NSHandleNotification(channel, command, result_buffer, result_buffer_len); } \ 
     123  extern NSCAPI::boolReturn NSHasNotificationHandler(unsigned int id) { \ 
     124    nscapi::submission_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \ 
     125    return wrapper.NSHasNotificationHandler(); } 
     126 
     127#define NSC_WRAPPERS_CLI_DEF() \ 
     128  extern int NSCommandLineExec(unsigned int id, wchar_t *command, char *request_buffer, unsigned int request_len, char **response_buffer, unsigned int *response_len) { \ 
     129    nscapi::cliexec_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \ 
     130    return wrapper.NSCommandLineExec(command, request_buffer, request_len, response_buffer, response_len); } 
     131 
    175132#define NSC_WRAPPERS_IGNORE_MSG_DEF() \ 
    176133  extern void NSHandleMessage(unsigned int id, const char* data, unsigned int len) {} \ 
    177134  extern NSCAPI::boolReturn NSHasMessageHandler(unsigned int id) { return NSCAPI::isfalse; } 
    178 #define NSC_WRAPPERS_HANDLE_CMD_DEF() \ 
    179   extern NSCAPI::nagiosReturn NSHandleCommand(unsigned int id, const wchar_t* command, const char* request_buffer, const unsigned int request_buffer_len, char** reply_buffer, unsigned int *reply_buffer_len) \ 
    180   { \ 
    181   try { \ 
    182   std::string request(request_buffer, request_buffer_len), reply; \ 
    183   NSCAPI::nagiosReturn retCode = plugin_instance.get(id)->handleRAWCommand(command, request, reply); \ 
    184   return GET_PLUGIN()->wrapHandleCommand(retCode, reply, reply_buffer, reply_buffer_len); \ 
    185     } catch (...) { \ 
    186     NSC_LOG_CRITICAL(_T("Unknown exception in: wrapHandleCommand(...)")); \ 
    187     return NSCAPI::returnIgnored; \ 
    188     } \ 
    189   } \ 
    190   extern NSCAPI::boolReturn NSHasCommandHandler(unsigned int id) { \ 
    191   try { \ 
    192   return GET_PLUGIN()->wrapHasCommandHandler(plugin_instance.get(id)->hasCommandHandler()); \ 
    193     } catch (...) { \ 
    194     NSC_LOG_CRITICAL(_T("Unknown exception in: wrapHasCommandHandler(...)")); \ 
    195     return NSCAPI::isfalse; \ 
    196     } \ 
    197   } 
    198 #define NSC_WRAPPERS_ROUTING_DEF() \ 
    199   extern NSCAPI::nagiosReturn NSRouteMessage(unsigned int id, const wchar_t* channel, const wchar_t* command, const char* request_buffer, const unsigned int request_buffer_len) \ 
    200   { \ 
    201   try { \ 
    202   std::string request(request_buffer, request_buffer_len), reply; \ 
    203   return GET_PLUGIN()->wrapRouteMessage(plugin_instance.get(id)->RAWRouteMessage(channel, command, request)); \ 
    204     } catch (...) { \ 
    205     NSC_LOG_CRITICAL(_T("Unknown exception in: wrapHandleCommand(...)")); \ 
    206     return NSCAPI::returnIgnored; \ 
    207     } \ 
    208   } \ 
    209   extern NSCAPI::boolReturn NSHasRoutingHandler(unsigned int id) { \ 
    210   try { \ 
    211   return GET_PLUGIN()->wrapHasRoutingHandler(plugin_instance.get(id)->hasRoutingHandler()); \ 
    212     } catch (...) { \ 
    213     NSC_LOG_CRITICAL(_T("Unknown exception in: wrapHasCommandHandler(...)")); \ 
    214     return NSCAPI::isfalse; \ 
    215     } \ 
    216   } 
     135 
    217136#define NSC_WRAPPERS_IGNORE_CMD_DEF() \ 
    218   extern NSCAPI::nagiosReturn NSHandleCommand(unsigned int id, const wchar_t* IN_cmd, const unsigned int IN_argsLen, wchar_t **IN_args, \ 
    219   wchar_t *OUT_retBufMessage, unsigned int IN_retBufMessageLen, wchar_t *OUT_retBufPerf, unsigned int IN_retBufPerfLen) { \ 
    220   return NSCAPI::returnIgnored; \ 
    221   } \ 
     137  extern NSCAPI::nagiosReturn NSHandleCommand(unsigned int id, const wchar_t* IN_cmd, const unsigned int IN_argsLen, wchar_t **IN_args, wchar_t *OUT_retBufMessage, unsigned int IN_retBufMessageLen, wchar_t *OUT_retBufPerf, unsigned int IN_retBufPerfLen) {  return NSCAPI::returnIgnored; } \ 
    222138  extern NSCAPI::boolReturn NSHasCommandHandler(unsigned int id) { return NSCAPI::isfalse; } 
     139 
    223140#define NSC_WRAPPERS_IGNORE_NOTIFICATION_DEF() \ 
    224   extern void NSHandleNotification(const wchar_t*, const wchar_t*, NSCAPI::nagiosReturn, const char*, unsigned int) {} \ 
     141  extern int NSHandleNotification(unsigned int id, const wchar_t* channel, const wchar_t* command, const char* result_buffer, unsigned int result_buffer_len) {} \ 
    225142  extern NSCAPI::boolReturn NSHasNotificationHandler(unsigned int id) { return NSCAPI::isfalse; } 
    226 #define NSC_WRAPPERS_HANDLE_NOTIFICATION_DEF() \ 
    227   extern NSCAPI::nagiosReturn NSHandleNotification(unsigned int id, const wchar_t* channel, const wchar_t* command, NSCAPI::nagiosReturn code, const char* result_buffer, unsigned int result_buffer_len) \ 
    228   { \ 
    229     try { \ 
    230       std::string result(result_buffer, result_buffer_len); \ 
    231       return GET_PLUGIN()->wrapHandleNotification(plugin_instance.get(id)->handleRAWNotification(channel, command, code, result)); \ 
    232     } catch (...) { \ 
    233       NSC_LOG_CRITICAL(_T("Unknown exception in: wrapHasNotificationHandler(...)")); \ 
    234       return NSCAPI::returnIgnored; \ 
    235     } \ 
    236   } \ 
    237   extern NSCAPI::boolReturn NSHasNotificationHandler(unsigned int id) { \ 
    238     try { \ 
    239       return GET_PLUGIN()->wrapHasNotificationHandler(plugin_instance.get(id)->hasNotificationHandler()); \ 
    240     } catch (...) { \ 
    241       NSC_LOG_CRITICAL(_T("Unknown exception in: wrapHasNotificationHandler(...)")); \ 
    242       return NSCAPI::isfalse; \ 
    243     } \ 
    244   } 
    245  
    246  
    247 #define NSC_WRAPPERS_CLI_DEF() \ 
    248   extern int NSCommandLineExec(unsigned int id, wchar_t *command, char *request_buffer, unsigned int request_len, char **response_buffer, unsigned int *response_len) { \ 
    249     try { \ 
    250     std::string request = std::string(request_buffer, request_len); \ 
    251     std::string response; \ 
    252     NSCAPI::nagiosReturn retCode = plugin_instance.get(id)->commandRAWLineExec(command, request, response); \ 
    253     return GET_PLUGIN()->wrapCommandLineExec(retCode, response, response_buffer, response_len); \ 
    254     } catch (const std::exception &e) { \ 
    255     NSC_LOG_CRITICAL(_T("Exception in: commandLineExec(...)") + utf8::cvt<std::wstring>(e.what())); \ 
    256       std::wcerr << _T("Exception in: commandLineExec(...)") << utf8::cvt<std::wstring>(e.what()) << std::endl; \ 
    257       return NSCAPI::hasFailed; \ 
    258     } catch (...) { \ 
    259       NSC_LOG_CRITICAL(_T("Unknown exception in: commandLineExec(...)")); \ 
    260       std::wcerr << _T("Unknown exception in: commandLineExec(...)") << std::endl; \ 
    261       return NSCAPI::hasFailed; \ 
    262     } \ 
    263   } \ 
    264143 
    265144 
  • include/nscapi/nscapi_core_wrapper.cpp

    rd7e265d ra44cb15  
    129129  std::string request; 
    130130  nscapi::functions::create_simple_query_response(command, code, message, perf, request); 
    131   NSCAPI::nagiosReturn ret = NotifyChannel(channel, command, code, request); 
    132 } 
    133  
    134  
    135 NSCAPI::errorReturn nscapi::core_wrapper::NotifyChannel(std::wstring channel, std::wstring command, NSCAPI::nagiosReturn code, std::string result) { 
     131  NSCAPI::nagiosReturn ret = submit_message(channel, command, request); 
     132} 
     133 
     134NSCAPI::errorReturn nscapi::core_wrapper::submit_message(std::wstring channel, std::wstring command, std::string buffer) { 
    136135  if (!fNSAPINotify) 
    137136    throw nscapi::nscapi_exception(_T("NSCore has not been initiated...")); 
    138   return fNSAPINotify(channel.c_str(), command.c_str(), code, result.c_str(), result.size()); 
     137  return fNSAPINotify(channel.c_str(), command.c_str(), buffer.c_str(), buffer.size()); 
    139138} 
    140139 
     
    544543  return ret; 
    545544} 
    546 void nscapi::core_wrapper::registerCommand(std::wstring command, std::wstring description) { 
     545void nscapi::core_wrapper::registerCommand(unsigned int id, std::wstring command, std::wstring description) { 
    547546  if (!fNSAPIRegisterCommand) 
    548547    throw nscapi::nscapi_exception(_T("NSCore has not been initiated...")); 
    549   if (fNSAPIRegisterCommand(id_, command.c_str(), description.c_str()) != NSCAPI::isSuccess) { 
    550     CORE_LOG_ERROR_STD(_T("Failed to register command: ") + command + _T(" in plugin: ") + to_wstring(id_)); 
     548  if (fNSAPIRegisterCommand(id, command.c_str(), description.c_str()) != NSCAPI::isSuccess) { 
     549    CORE_LOG_ERROR_STD(_T("Failed to register command: ") + command + _T(" in plugin: ") + to_wstring(id)); 
     550  } 
     551} 
     552 
     553void nscapi::core_wrapper::registerSubmissionListener(unsigned int id, std::wstring channel) { 
     554  if (!fNSAPIRegisterSubmissionListener) 
     555    throw nscapi::nscapi_exception(_T("NSCore has not been initiated...")); 
     556  if (fNSAPIRegisterSubmissionListener(id, channel.c_str()) != NSCAPI::isSuccess) { 
     557    CORE_LOG_ERROR_STD(_T("Failed to register channel: ") + channel + _T(" in plugin: ") + to_wstring(id)); 
     558  } 
     559} 
     560void nscapi::core_wrapper::registerRoutingListener(unsigned int id, std::wstring channel) { 
     561  if (!fNSAPIRegisterRoutingListener) 
     562    throw nscapi::nscapi_exception(_T("NSCore has not been initiated...")); 
     563  if (fNSAPIRegisterRoutingListener(id, channel.c_str()) != NSCAPI::isSuccess) { 
     564    CORE_LOG_ERROR_STD(_T("Failed to register channel: ") + channel + _T(" in plugin: ") + to_wstring(id)); 
    551565  } 
    552566} 
     
    583597 * @return NSCAPI::success or NSCAPI::failure 
    584598 */ 
    585 bool nscapi::core_wrapper::load_endpoints(unsigned int id, nscapi::core_api::lpNSAPILoader f) { 
    586   id_ = id; 
     599bool nscapi::core_wrapper::load_endpoints(nscapi::core_api::lpNSAPILoader f) { 
    587600  fNSAPIGetApplicationName = (nscapi::core_api::lpNSAPIGetApplicationName)f(_T("NSAPIGetApplicationName")); 
    588601  fNSAPIGetApplicationVersionStr = (nscapi::core_api::lpNSAPIGetApplicationVersionStr)f(_T("NSAPIGetApplicationVersionStr")); 
     
    624637  fNSAPIExpandPath = (nscapi::core_api::lpNSAPIExpandPath)f(_T("NSAPIExpandPath")); 
    625638   
     639  fNSAPIRegisterSubmissionListener = (nscapi::core_api::lpNSAPIRegisterSubmissionListener)f(_T("NSAPIRegisterSubmissionListener")); 
     640  fNSAPIRegisterRoutingListener = (nscapi::core_api::lpNSAPIRegisterRoutingListener)f(_T("NSAPIRegisterRoutingListener")); 
     641 
    626642  return true; 
    627643} 
  • include/nscapi/nscapi_core_wrapper.hpp

    r2c95d22 ra44cb15  
    6969    nscapi::core_api::lpNSAPIReleasePluginList fNSAPIReleasePluginList; 
    7070    nscapi::core_api::lpNSAPISettingsSave fNSAPISettingsSave; 
    71  
    72     unsigned int buffer_length_; 
    73     unsigned int id_; 
     71    nscapi::core_api::lpNSAPIRegisterSubmissionListener fNSAPIRegisterSubmissionListener; 
     72    nscapi::core_api::lpNSAPIRegisterRoutingListener fNSAPIRegisterRoutingListener; 
    7473 
    7574  public: 
     
    116115      , fNSAPISettingsSave(NULL) 
    117116      , fNSAPIExpandPath(NULL) 
    118       , buffer_length_(-1) 
    119       , id_(-1) 
    120117    {} 
    121118 
     
    145142 
    146143    void submit_simple_message(std::wstring channel, std::wstring command, NSCAPI::nagiosReturn code, std::wstring & message, std::wstring & perf); 
    147     NSCAPI::errorReturn NotifyChannel(std::wstring channel, std::wstring command, NSCAPI::nagiosReturn code, std::string result); 
    148     //NSCAPI::nagiosReturn InjectCommand(const std::wstring command, const std::list<std::wstring> argument, std::string & result); 
    149     //NSCAPI::nagiosReturn InjectSplitAndCommand(const wchar_t* command, wchar_t* buffer, wchar_t splitChar, std::wstring & message, std::wstring & perf); 
    150     //NSCAPI::nagiosReturn InjectSplitAndCommand(const std::wstring command, const std::wstring buffer, wchar_t splitChar, std::wstring & message, std::wstring & perf, bool escape = false); 
     144    NSCAPI::errorReturn submit_message(std::wstring channel, std::wstring command, std::string buffer); 
     145 
    151146    void StopService(void); 
    152147    void Exit(void); 
     
    165160    std::list<std::wstring> getAllCommandNames(); 
    166161    std::wstring describeCommand(std::wstring command); 
    167     void registerCommand(std::wstring command, std::wstring description); 
     162    void registerCommand(unsigned int id, std::wstring command, std::wstring description); 
     163    void registerSubmissionListener(unsigned int id, std::wstring channel); 
     164    void registerRoutingListener(unsigned int id, std::wstring channel); 
     165 
    168166    unsigned int getBufferLength(); 
    169  
    170  
    171     bool load_endpoints(unsigned int id, nscapi::core_api::lpNSAPILoader f); 
     167    bool load_endpoints(nscapi::core_api::lpNSAPILoader f); 
    172168 
    173169  }; 
  • include/nscapi/nscapi_plugin_wrapper.cpp

    r81e420c ra44cb15  
    3838using namespace nscp::helpers; 
    3939 
    40 extern nscapi::helper_singleton* nscapi::plugin_singleton; 
     40//extern nscapi::helper_singleton* nscapi::plugin_singleton; 
    4141/** 
    4242* Wrap a return string. 
     
    8989 */ 
    9090int nscapi::plugin_wrapper::wrapModuleHelperInit(unsigned int id, nscapi::core_api::lpNSAPILoader f) { 
    91   return nscapi::plugin_singleton->get_core()->load_endpoints(id, f)?NSCAPI::isSuccess:NSCAPI::hasFailed; 
     91  return GET_CORE()->load_endpoints(f)?NSCAPI::isSuccess:NSCAPI::hasFailed; 
    9292} 
    9393/** 
     
    273273} 
    274274 
    275 NSCAPI::nagiosReturn nscapi::impl::SimpleNotificationHandler::handleRAWNotification(const wchar_t* channel, const wchar_t* command, NSCAPI::nagiosReturn code, std::string result) { 
     275NSCAPI::nagiosReturn nscapi::impl::SimpleNotificationHandler::handleRAWNotification(const wchar_t* channel, const wchar_t* command, std::string result) { 
    276276  try { 
    277277    std::wstring msg, perf; 
    278     nscapi::functions::parse_simple_query_response(result, msg, perf); 
     278    int code = nscapi::functions::parse_simple_query_response(result, msg, perf); 
    279279    return handleSimpleNotification(channel, command, code, msg, perf); 
    280280  } catch (std::exception &e) { 
  • include/nscapi/nscapi_plugin_wrapper.hpp

    r81e420c ra44cb15  
    2424#include <list> 
    2525#include <vector> 
     26#include <map> 
    2627 
    2728#include <boost/make_shared.hpp> 
     
    3031#include <NSCAPI.h> 
    3132#include <nscapi/settings_proxy.hpp> 
     33#include <nscapi/macros.hpp> 
     34#include <nscapi/nscapi_helper.hpp> 
    3235 
    3336 
     
    7780 
    7881  }; 
     82 
    7983  class core_wrapper; 
    8084  class helper_singleton { 
     
    96100 
    97101  namespace impl { 
    98  
    99     class simple_plugin { 
    100     public: 
     102    struct simple_plugin { 
     103      int id_; 
    101104      inline nscapi::core_wrapper* get_core() { 
    102         return nscapi::plugin_singleton->get_core(); 
     105        return plugin_singleton->get_core(); 
     106      } 
     107      inline unsigned int get_id() { 
     108        return id_; 
     109      } 
     110      inline void set_id(unsigned int id) { 
     111        id_ = id; 
    103112      } 
    104113      inline boost::shared_ptr<nscapi::settings_proxy> get_settings_proxy() { 
    105         return boost::shared_ptr<nscapi::settings_proxy>(new nscapi::settings_proxy(nscapi::plugin_singleton->get_core())); 
    106       } 
     114        return boost::shared_ptr<nscapi::settings_proxy>(new nscapi::settings_proxy(get_core())); 
     115      } 
     116      void register_command(std::wstring command, std::wstring description) { 
     117        get_core()->registerCommand(get_id(), _T("submit_nscp"), _T("Submit a query to a remote host via NSCP")); 
     118      } 
     119 
    107120    }; 
    108121 
    109122    class SimpleNotificationHandler { 
    110123    public: 
    111       NSCAPI::nagiosReturn handleRAWNotification(const wchar_t* channel, const wchar_t* command, NSCAPI::nagiosReturn code, std::string result); 
     124      NSCAPI::nagiosReturn handleRAWNotification(const wchar_t* channel, const wchar_t* command, std::string result); 
    112125      virtual NSCAPI::nagiosReturn handleSimpleNotification(const std::wstring channel, const std::wstring command, NSCAPI::nagiosReturn code, std::wstring msg, std::wstring perf) = 0; 
    113126 
     
    139152    }; 
    140153    */ 
    141   } 
     154  }; 
     155 
     156 
     157 
     158  template<class impl_type> 
     159  struct plugin_instance_data { 
     160    typedef std::map<unsigned int, boost::shared_ptr<impl_type> > plugin_list_type; 
     161    plugin_list_type plugins; 
     162    boost::shared_ptr<impl_type> get(unsigned int id) { 
     163      typename plugin_list_type::iterator it = plugins.find(id); 
     164      if (it != plugins.end()) 
     165        return it->second; 
     166      boost::shared_ptr<impl_type> impl = boost::shared_ptr<impl_type>(new impl_type()); 
     167      plugins[id] = impl; 
     168      return impl;  
     169    } 
     170    void erase(unsigned int id) { 
     171      plugins.erase(id); 
     172    } 
     173  }; 
     174 
     175  struct helpers { 
     176    static void wrap_string(std::string &string, char** buffer, unsigned int *buffer_len) { 
     177      // TODO: Make this global to allow remote deletion!!! 
     178      unsigned int buf_len = string.size(); 
     179      *buffer = new char[buf_len + 10]; 
     180      memcpy(*buffer, string.c_str(), buf_len+1); 
     181      (*buffer)[buf_len] = 0; 
     182      (*buffer)[buf_len+1] = 0; 
     183      *buffer_len = buf_len; 
     184    } 
     185    int static wrap_string(wchar_t *buffer, unsigned int bufLen, std::wstring str, int defaultReturnCode ) { 
     186      // @todo deprecate this 
     187      if (str.length() >= bufLen) { 
     188        std::wstring sstr = str.substr(0, bufLen-2); 
     189        NSC_DEBUG_MSG_STD(_T("String (") + strEx::itos(str.length()) + _T(") to long to fit inside buffer(") + strEx::itos(bufLen) + _T(") : ") + sstr); 
     190        return NSCAPI::isInvalidBufferLen; 
     191      } 
     192      wcsncpy(buffer, str.c_str(), bufLen); 
     193      return defaultReturnCode; 
     194    } 
     195 
     196  }; 
     197  template<class impl_class> 
     198  struct basic_wrapper_static { 
     199 
     200    static int NSModuleHelperInit(nscapi::core_api::lpNSAPILoader f) { 
     201      try {  
     202        return nscapi::plugin_singleton->get_core()->load_endpoints(f)?NSCAPI::isSuccess:NSCAPI::hasFailed; 
     203      } catch (...) {  
     204        NSC_LOG_CRITICAL(_T("Unknown exception in: wrapModuleHelperInit"));  
     205        return NSCAPI::hasFailed;  
     206      }  
     207    } 
     208    static int NSLoadModule() {  
     209      return NSCAPI::hasFailed;  
     210    }  
     211    static int NSGetModuleName(wchar_t* buf, int buflen) {  
     212      try { 
     213        return helpers::wrap_string(buf, buflen, impl_class::getModuleName(), NSCAPI::isSuccess); 
     214      } catch (...) {  
     215        NSC_LOG_CRITICAL(_T("Unknown exception in: NSGetModuleName"));  
     216      }  
     217      return NSCAPI::hasFailed;  
     218    }  
     219    static int NSGetModuleDescription(wchar_t* buf, int buflen) {  
     220      try {  
     221        return helpers::wrap_string(buf, buflen, impl_class::getModuleDescription(), NSCAPI::isSuccess); 
     222      } catch (...) {  
     223        NSC_LOG_CRITICAL(_T("Unknown exception in: NSGetModuleDescription"));  
     224      }  
     225      return NSCAPI::hasFailed;  
     226    }  
     227    static int NSGetModuleVersion(int *major, int *minor, int *revision) {  
     228      try {  
     229        nscapi::plugin_wrapper::module_version version = impl_class::getModuleVersion(); 
     230        *major = version.major; 
     231        *minor = version.minor; 
     232        *revision = version.revision; 
     233        return NSCAPI::isSuccess; 
     234      } catch (...) {  
     235        NSC_LOG_CRITICAL(_T("Unknown exception in: NSGetModuleVersion"));  
     236      }  
     237      return NSCAPI::hasFailed;  
     238    } 
     239    static void NSDeleteBuffer(char** buffer) {  
     240      try { 
     241        delete [] *buffer; 
     242      } catch (...) {  
     243        NSC_LOG_CRITICAL(_T("Unknown exception in: NSDeleteBuffer"));  
     244      }  
     245    } 
     246  }; 
     247 
     248  template<class impl_class> 
     249  struct basic_wrapper { 
     250    boost::shared_ptr<impl_class> instance; 
     251    basic_wrapper(boost::shared_ptr<impl_class> instance) : instance(instance) {} 
     252    int NSLoadModuleEx(unsigned int id, wchar_t* alias, int mode) {  
     253      try {  
     254        instance->set_id(id); 
     255        if (instance->loadModuleEx(alias, mode)) 
     256          return NSCAPI::isSuccess; 
     257      } catch (...) { 
     258        NSC_LOG_CRITICAL(_T("Unknown exception in: NSLoadModuleEx"));  
     259      }  
     260      return NSCAPI::hasFailed; 
     261    }  
     262    int NSUnloadModule() {  
     263      try {  
     264        if (instance->unloadModule()) 
     265          return NSCAPI::isSuccess; 
     266      } catch (...) {  
     267        NSC_LOG_CRITICAL(_T("Unknown exception in: NSUnloadModule"));  
     268      }  
     269      return NSCAPI::hasFailed; 
     270    } 
     271  }; 
     272  template<class impl_class> 
     273  struct message_wrapper { 
     274    boost::shared_ptr<impl_class> instance; 
     275    message_wrapper(boost::shared_ptr<impl_class> instance) : instance(instance) {} 
     276    void NSHandleMessage(const char* request_buffer, unsigned int request_buffer_len) {  
     277      try {  
     278        instance->handleMessageRAW(std::string(request_buffer, request_buffer_len)); 
     279      } catch (...) {  
     280        NSC_LOG_CRITICAL(_T("Unknown exception in: NSHandleMessage"));  
     281      }  
     282    }  
     283    NSCAPI::boolReturn NSHasMessageHandler() {  
     284      try { 
     285        if (instance->hasMessageHandler()) 
     286          return NSCAPI::istrue; 
     287      } catch (...) {  
     288        NSC_LOG_CRITICAL(_T("Unknown exception in: NSHasMessageHandler"));  
     289      }  
     290      return NSCAPI::isfalse;  
     291    } 
     292  }; 
     293  template<class impl_class> 
     294  struct command_wrapper { 
     295    boost::shared_ptr<impl_class> instance; 
     296    command_wrapper(boost::shared_ptr<impl_class> instance) : instance(instance) {} 
     297 
     298    NSCAPI::nagiosReturn NSHandleCommand(const wchar_t* command, const char* request_buffer, const unsigned int request_buffer_len, char** reply_buffer, unsigned int *reply_buffer_len) {  
     299      try {  
     300        std::string request(request_buffer, request_buffer_len), reply; 
     301        NSCAPI::nagiosReturn retCode = instance->handleRAWCommand(command, request, reply); 
     302        helpers::wrap_string(reply, reply_buffer, reply_buffer_len); 
     303        if (!nscapi::plugin_helper::isMyNagiosReturn(retCode)) { 
     304          NSC_LOG_ERROR(_T("A module returned an invalid return code")); 
     305        } 
     306        return retCode; 
     307      } catch (...) {  
     308        NSC_LOG_CRITICAL(_T("Unknown exception in: NSHandleCommand"));  
     309      }  
     310      return NSCAPI::returnIgnored;  
     311    }  
     312    NSCAPI::boolReturn NSHasCommandHandler() {  
     313      try {  
     314        if (instance->hasCommandHandler()) 
     315          return NSCAPI::istrue; 
     316      } catch (...) {  
     317        NSC_LOG_CRITICAL(_T("Unknown exception in: NSHasCommandHandler"));  
     318      }  
     319      return NSCAPI::isfalse;  
     320    } 
     321  }; 
     322 
     323  template<class impl_class> 
     324  struct routing_wrapper { 
     325    boost::shared_ptr<impl_class> instance; 
     326    routing_wrapper(boost::shared_ptr<impl_class> instance) : instance(instance) {} 
     327 
     328    NSCAPI::nagiosReturn NSRouteMessage(const wchar_t* channel, const wchar_t* command, const char* request_buffer, const unsigned int request_buffer_len, char** reply_buffer, unsigned int *reply_buffer_len) {  
     329      try {  
     330        std::string request(request_buffer, request_buffer_len), reply; 
     331        NSCAPI::nagiosReturn retCode = instance->RAWRouteMessage(channel, command, request, reply);  
     332        helpers::wrap_string(reply, reply_buffer, reply_buffer_len); 
     333        return retCode; 
     334      } catch (...) {  
     335        NSC_LOG_CRITICAL(_T("Unknown exception in: NSRouteMessage"));  
     336      }  
     337      return NSCAPI::returnIgnored;  
     338    }  
     339    NSCAPI::boolReturn NSHasRoutingHandler() {  
     340      try {  
     341        if (instance->hasRoutingHandler()) 
     342          return NSCAPI::istrue; 
     343      } catch (...) {  
     344        NSC_LOG_CRITICAL(_T("Unknown exception in: NSHasRoutingHandler"));  
     345      }  
     346      return NSCAPI::isfalse;  
     347    } 
     348  }; 
     349 
     350  template<class impl_class> 
     351  struct submission_wrapper { 
     352    boost::shared_ptr<impl_class> instance; 
     353    submission_wrapper(boost::shared_ptr<impl_class> instance) : instance(instance) {} 
     354 
     355    NSCAPI::nagiosReturn NSHandleNotification(const wchar_t* channel, const wchar_t* command, const char* result_buffer, unsigned int result_buffer_len) { 
     356      try {  
     357        std::string request(result_buffer, result_buffer_len); 
     358        NSCAPI::nagiosReturn retCode = instance->handleRAWNotification(channel, command, request);  
     359      } catch (...) {  
     360        NSC_LOG_CRITICAL(_T("Unknown exception in: NSHandleNotification"));  
     361      }  
     362      return NSCAPI::returnIgnored;  
     363    }  
     364    NSCAPI::boolReturn NSHasNotificationHandler() {  
     365      try {  
     366        if (instance->hasNotificationHandler()) 
     367          return NSCAPI::istrue; 
     368      } catch (...) {  
     369        NSC_LOG_CRITICAL(_T("Unknown exception in: NSHasNotificationHandler"));  
     370      }  
     371      return NSCAPI::isfalse;  
     372    } 
     373  }; 
     374 
     375  template<class impl_class> 
     376  struct cliexec_wrapper { 
     377    boost::shared_ptr<impl_class> instance; 
     378    cliexec_wrapper(boost::shared_ptr<impl_class> instance) : instance(instance) {} 
     379 
     380    int NSCommandLineExec(wchar_t *command, char *request_buffer, unsigned int request_buffer_len, char **response_buffer, unsigned int *response_buffer_len) { 
     381      try {  
     382        std::string request(request_buffer, request_buffer_len), reply; 
     383        NSCAPI::nagiosReturn retCode = instance->commandRAWLineExec(command, request, reply);  
     384        helpers::wrap_string(reply, response_buffer, response_buffer_len); 
     385        return retCode; 
     386      } catch (...) {  
     387        NSC_LOG_CRITICAL(_T("Unknown exception in: NSCommandLineExec"));  
     388      }  
     389      return NSCAPI::hasFailed;  
     390    }  
     391  }; 
    142392}; 
  • modules/CheckDisk/CheckDisk.cpp

    r81e420c ra44cb15  
    5454bool CheckDisk::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 
    5555  try { 
    56     get_core()->registerCommand(_T("CheckFileSize"), _T("Check or directory a file and verify its size.")); 
    57     get_core()->registerCommand(_T("CheckDriveSize"), _T("Check the size (free-space) of a drive or volume.")); 
    58     get_core()->registerCommand(_T("CheckFile2"), _T("(deprecated) Check various aspects of a file and/or folder.")); 
    59     get_core()->registerCommand(_T("CheckFiles"), _T("Check various aspects of a file and/or folder.")); 
     56    register_command(_T("CheckFileSize"), _T("Check or directory a file and verify its size.")); 
     57    register_command(_T("CheckDriveSize"), _T("Check the size (free-space) of a drive or volume.")); 
     58    register_command(_T("CheckFile2"), _T("(deprecated) Check various aspects of a file and/or folder.")); 
     59    register_command(_T("CheckFiles"), _T("Check various aspects of a file and/or folder.")); 
    6060 
    6161    sh::settings_registry settings(get_settings_proxy()); 
  • modules/CheckDisk/CheckDisk.h

    r81e420c ra44cb15  
    2525#include <checkHelpers.hpp> 
    2626 
    27 class CheckDisk : public nscapi::impl::simple_command, nscapi::impl::simple_plugin  { 
     27class CheckDisk : public nscapi::impl::simple_command, public nscapi::impl::simple_plugin  { 
    2828private: 
    2929  bool show_errors_; 
  • modules/CheckEventLog/CheckEventLog.cpp

    r81e420c ra44cb15  
    7070bool CheckEventLog::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 
    7171  try { 
    72     get_core()->registerCommand(_T("CheckEventLog"), _T("Check for errors in the event logger!")); 
     72    register_command(_T("CheckEventLog"), _T("Check for errors in the event logger!")); 
    7373 
    7474    sh::settings_registry settings(get_settings_proxy()); 
  • modules/CheckEventLog/CheckEventLog.h

    r81e420c ra44cb15  
    2727 
    2828 
    29 class CheckEventLog : public nscapi::impl::simple_command, nscapi::impl::simple_plugin { 
     29class CheckEventLog : public nscapi::impl::simple_command, public nscapi::impl::simple_plugin { 
    3030private: 
    3131  bool debug_; 
  • modules/CheckExternalScripts/CheckExternalScripts.h

    r81e420c ra44cb15  
    117117    command_data cd = command_data(tok.first, tok.second); 
    118118    commands[key.c_str()] = cd; 
    119     get_core()->registerCommand(key.c_str(), _T("Script: ") + cd.to_string()); 
     119    register_command(key.c_str(), _T("Script: ") + cd.to_string()); 
    120120  } 
    121121  void add_alias(std::wstring key, std::wstring command) { 
     
    124124    command_data cd = command_data(tok.first, tok.second); 
    125125    alias[key.c_str()] = cd; 
    126     get_core()->registerCommand(key.c_str(), _T("Alias for: ") + cd.to_string()); 
     126    register_command(key.c_str(), _T("Alias for: ") + cd.to_string()); 
    127127  } 
    128128  void add_wrapping(std::wstring key, std::wstring command) { 
  • modules/CheckHelpers/CheckHelpers.cpp

    r81e420c ra44cb15  
    4343bool CheckHelpers::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 
    4444  try { 
    45     get_core()->registerCommand(_T("CheckAlwaysOK"), _T("Run another check and regardless of its return code return OK.")); 
    46     get_core()->registerCommand(_T("CheckAlwaysCRITICAL"), _T("Run another check and regardless of its return code return CRIT.")); 
    47     get_core()->registerCommand(_T("CheckAlwaysWARNING"), _T("Run another check and regardless of its return code return WARN.")); 
    48     get_core()->registerCommand(_T("CheckMultiple"), _T("Run more then one check and return the worst state.")); 
    49     get_core()->registerCommand(_T("CheckOK"), _T("Just return OK (anything passed along will be used as a message).")); 
    50     get_core()->registerCommand(_T("check_ok"), _T("Just return OK (anything passed along will be used as a message).")); 
    51     get_core()->registerCommand(_T("CheckWARNING"), _T("Just return WARN (anything passed along will be used as a message).")); 
    52     get_core()->registerCommand(_T("CheckCRITICAL"), _T("Just return CRIT (anything passed along will be used as a message).")); 
    53     get_core()->registerCommand(_T("CheckVersion"), _T("Just return the nagios version (along with OK status).")); 
     45    register_command(_T("CheckAlwaysOK"), _T("Run another check and regardless of its return code return OK.")); 
     46    register_command(_T("CheckAlwaysCRITICAL"), _T("Run another check and regardless of its return code return CRIT.")); 
     47    register_command(_T("CheckAlwaysWARNING"), _T("Run another check and regardless of its return code return WARN.")); 
     48    register_command(_T("CheckMultiple"), _T("Run more then one check and return the worst state.")); 
     49    register_command(_T("CheckOK"), _T("Just return OK (anything passed along will be used as a message).")); 
     50    register_command(_T("check_ok"), _T("Just return OK (anything passed along will be used as a message).")); 
     51    register_command(_T("CheckWARNING"), _T("Just return WARN (anything passed along will be used as a message).")); 
     52    register_command(_T("CheckCRITICAL"), _T("Just return CRIT (anything passed along will be used as a message).")); 
     53    register_command(_T("CheckVersion"), _T("Just return the nagios version (along with OK status).")); 
    5454  } catch (nscapi::nscapi_exception &e) { 
    5555    NSC_LOG_ERROR_STD(_T("Failed to register command: ") + utf8::cvt<std::wstring>(e.what())); 
  • modules/CheckHelpers/CheckHelpers.h

    r81e420c ra44cb15  
    2323#include <strEx.h> 
    2424 
    25 class CheckHelpers : public nscapi::impl::simple_command, nscapi::impl::simple_plugin { 
     25class CheckHelpers : public nscapi::impl::simple_command, public nscapi::impl::simple_plugin { 
    2626private: 
    2727 
  • modules/CheckNSCP/CheckNSCP.cpp

    r81e420c ra44cb15  
    4848    settings.notify(); 
    4949 
    50     get_core()->registerCommand(_T("check_nscp"), _T("Check the internal healt of NSClient++.")); 
     50    register_command(_T("check_nscp"), _T("Check the internal healt of NSClient++.")); 
    5151  } catch (nscapi::nscapi_exception &e) { 
    5252    NSC_LOG_ERROR_STD(_T("Failed to register command: ") + utf8::cvt<std::wstring>(e.what())); 
  • modules/CheckSystem/CheckSystem.cpp

    r81e420c ra44cb15  
    136136    } 
    137137 
    138     get_core()->registerCommand(_T("checkCPU"), _T("Check the CPU load of the computer.")); 
    139     get_core()->registerCommand(_T("checkUpTime"), _T("Check the up-time of the computer.")); 
    140     get_core()->registerCommand(_T("checkServiceState"), _T("Check the state of one or more of the computer services.")); 
    141     get_core()->registerCommand(_T("checkProcState"), _T("Check the state of one or more of the processes running on the computer.")); 
    142     get_core()->registerCommand(_T("checkMem"), _T("Check free/used memory on the system.")); 
    143     get_core()->registerCommand(_T("checkCounter"), _T("Check a PDH counter.")); 
    144     get_core()->registerCommand(_T("listCounterInstances"), _T("List all instances for a counter.")); 
    145     get_core()->registerCommand(_T("checkSingleRegEntry"), _T("Check registry key")); 
     138    register_command(_T("checkCPU"), _T("Check the CPU load of the computer.")); 
     139    register_command(_T("checkUpTime"), _T("Check the up-time of the computer.")); 
     140    register_command(_T("checkServiceState"), _T("Check the state of one or more of the computer services.")); 
     141    register_command(_T("checkProcState"), _T("Check the state of one or more of the processes running on the computer.")); 
     142    register_command(_T("checkMem"), _T("Check free/used memory on the system.")); 
     143    register_command(_T("checkCounter"), _T("Check a PDH counter.")); 
     144    register_command(_T("listCounterInstances"), _T("List all instances for a counter.")); 
     145    register_command(_T("checkSingleRegEntry"), _T("Check registry key")); 
    146146  } catch (nscapi::nscapi_exception &e) { 
    147147    NSC_LOG_ERROR_STD(_T("Failed to register command: ") + utf8::cvt<std::wstring>(e.what())); 
  • modules/CheckTaskSched/CheckTaskSched.cpp

    r81e420c ra44cb15  
    4444bool CheckTaskSched::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 
    4545  try { 
    46     get_core()->registerCommand(_T("CheckTaskSchedValue"), _T("Run a WMI query and check the resulting value (the values of each row determin the state).")); 
    47     get_core()->registerCommand(_T("CheckTaskSched"), _T("Run a WMI query and check the resulting rows (the number of hits determine state).")); 
     46    register_command(_T("CheckTaskSchedValue"), _T("Run a WMI query and check the resulting value (the values of each row determin the state).")); 
     47    register_command(_T("CheckTaskSched"), _T("Run a WMI query and check the resulting rows (the number of hits determine state).")); 
    4848 
    4949    SETTINGS_REG_PATH(task_scheduler::SECTION); 
  • modules/CheckTaskSched2/CheckTaskSched2.cpp

    r81e420c ra44cb15  
    4343bool CheckTaskSched2::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 
    4444  try { 
    45     get_core()->registerCommand(_T("CheckTaskSchedValue"), _T("Run a WMI query and check the resulting value (the values of each row determin the state).")); 
    46     get_core()->registerCommand(_T("CheckTaskSched"), _T("Run a WMI query and check the resulting rows (the number of hits determine state).")); 
     45    register_command(_T("CheckTaskSchedValue"), _T("Run a WMI query and check the resulting value (the values of each row determin the state).")); 
     46    register_command(_T("CheckTaskSched"), _T("Run a WMI query and check the resulting rows (the number of hits determine state).")); 
    4747 
    4848    SETTINGS_REG_PATH(task_scheduler::SECTION); 
  • modules/CheckWMI/CheckWMI.cpp

    r81e420c ra44cb15  
    8989bool CheckWMI::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 
    9090  try { 
    91     get_core()->registerCommand(_T("CheckWMIValue"), _T("Run a WMI query and check the resulting value (the values of each row determin the state).")); 
    92     get_core()->registerCommand(_T("CheckWMI"), _T("Run a WMI query and check the resulting rows (the number of hits determine state).")); 
     91    register_command(_T("CheckWMIValue"), _T("Run a WMI query and check the resulting value (the values of each row determin the state).")); 
     92    register_command(_T("CheckWMI"), _T("Run a WMI query and check the resulting rows (the number of hits determine state).")); 
    9393 
    9494    sh::settings_registry settings(get_settings_proxy()); 
  • modules/NRPEClient/NRPEClient.cpp

    r81e420c ra44cb15  
    189189    commands[key.c_str()] = command_data; 
    190190 
    191     GET_CORE()->registerCommand(key.c_str(), command_data.toString()); 
     191    register_command(key.c_str(), command_data.toString()); 
    192192 
    193193  } catch (boost::program_options::validation_error &e) { 
  • modules/NRPEClient/NRPEClient.h

    r81e420c ra44cb15  
    2828 
    2929 
    30 class NRPEClient : public nscapi::impl::simple_command, nscapi::impl::simple_plugin, public nscapi::impl::simple_command_line_exec { 
     30class NRPEClient : public nscapi::impl::simple_command, public nscapi::impl::simple_plugin, public nscapi::impl::simple_command_line_exec { 
    3131private: 
    3232  typedef enum { 
  • modules/NSCAAgent/NSCAAgent.cpp

    r81e420c ra44cb15  
    7979      _T("PAYLOAD LENGTH"), _T("The password to use. Again has to be the same as the server or it wont work at all.")) 
    8080 
     81      (_T("channel"), sh::wstring_key(&channel_, _T("NSCA")), 
     82      _T("CHANNEL"), _T("The channel to listen to.")) 
     83 
    8184      ; 
    8285 
     
    104107    settings.register_all(); 
    105108    settings.notify(); 
     109 
     110    get_core()->registerSubmissionListener(get_id(), channel_); 
    106111 
    107112  } catch (nscapi::nscapi_exception &e) { 
  • modules/NSCAAgent/NSCAAgent.h

    r81e420c ra44cb15  
    3636  unsigned int timeout_; 
    3737  int time_delta_; 
     38  std::wstring channel_; 
    3839 
    3940public: 
  • modules/NSCPClient/NSCPClient.cpp

    r81e420c ra44cb15  
    5151  try { 
    5252 
    53     get_core()->registerCommand(_T("query_nscp"), _T("Submit a query to a remote host via NSCP")); 
    54     get_core()->registerCommand(_T("submit_nscp"), _T("Submit a query to a remote host via NSCP")); 
     53    register_command(_T("query_nscp"), _T("Submit a query to a remote host via NSCP")); 
     54    register_command(_T("submit_nscp"), _T("Submit a query to a remote host via NSCP")); 
    5555    //"/settings/NSCP/client/handlers" 
    5656    sh::settings_registry settings(get_settings_proxy()); 
     
    161161    commands[key.c_str()] = command_data; 
    162162 
    163     GET_CORE()->registerCommand(key.c_str(), command_data.toString()); 
     163    register_command(key.c_str(), command_data.toString()); 
    164164 
    165165  } catch (boost::program_options::validation_error &e) { 
  • modules/NSCPClient/NSCPClient.h

    r81e420c ra44cb15  
    2828 
    2929 
    30 class NSCPClient : public nscapi::impl::simple_command, nscapi::impl::simple_plugin, public nscapi::impl::simple_command_line_exec { 
     30class NSCPClient : public nscapi::impl::simple_command, public nscapi::impl::simple_plugin, public nscapi::impl::simple_command_line_exec { 
    3131private: 
    3232  struct nscp_connection_data { 
  • modules/PythonScript/PythonScript.cpp

    r81e420c ra44cb15  
    101101} 
    102102 
    103 python_script::python_script(const script_container& script) { 
     103python_script::python_script(unsigned int plugin_id, const std::string alias, const script_container& script) : alias(alias), plugin_id(plugin_id) { 
    104104  _exec(utf8::cvt<std::string>(script.script.string())); 
    105   callFunction("init", utf8::cvt<std::string>(script.alias)); 
     105  callFunction("init", plugin_id, alias, utf8::cvt<std::string>(script.alias)); 
    106106} 
    107107python_script::~python_script(){ 
     
    117117  } 
    118118} 
    119 void python_script::callFunction(const std::string& functionName, const std::string &str){ 
     119void python_script::callFunction(const std::string& functionName, unsigned int i1, const std::string &s1, const std::string &s2){ 
    120120  try { 
    121121    object scriptFunction = extract<object>(localDict[functionName]); 
    122122    if(scriptFunction) 
    123       scriptFunction(str); 
     123      scriptFunction(i1, s1, s2); 
    124124  } catch(error_already_set e) { 
    125125    script_wrapper::log_exception(); 
     
    131131    dict globalDict = extract<dict>(main_module.attr("__dict__")); 
    132132    localDict = globalDict.copy(); 
     133    //localDict.attr("plugin_id") = plugin_id; 
     134    //localDict.attr("plugin_alias") = alias; 
    133135 
    134136    PyRun_SimpleString("import cStringIO"); 
     
    175177 
    176178      BOOST_FOREACH(script_container &script, scripts_) { 
    177         instances_.push_back(boost::shared_ptr<python_script>(new python_script(script))); 
     179        instances_.push_back(boost::shared_ptr<python_script>(new python_script(get_id(), utf8::cvt<std::string>(alias), script))); 
    178180      } 
    179181 
     
    266268 
    267269NSCAPI::nagiosReturn PythonScript::commandRAWLineExec(const wchar_t* char_command, const std::string &request, std::string &response) { 
    268   boost::shared_ptr<script_wrapper::function_wrapper> inst = script_wrapper::function_wrapper::create(); 
     270  boost::shared_ptr<script_wrapper::function_wrapper> inst = script_wrapper::function_wrapper::create(get_id()); 
    269271  std::string cmd = utf8::cvt<std::string>(char_command); 
    270272  if (inst->has_cmdline(cmd)) { 
     
    283285 
    284286NSCAPI::nagiosReturn PythonScript::handleRAWCommand(const wchar_t* command, const std::string &request, std::string &response) { 
    285   boost::shared_ptr<script_wrapper::function_wrapper> inst = script_wrapper::function_wrapper::create(); 
     287  boost::shared_ptr<script_wrapper::function_wrapper> inst = script_wrapper::function_wrapper::create(get_id()); 
    286288  std::string cmd = utf8::cvt<std::string>(command); 
    287289  if (inst->has_function(cmd)) { 
     
    305307 
    306308 
    307 NSCAPI::nagiosReturn PythonScript::handleRAWNotification(const std::wstring &channel, const std::wstring &command, NSCAPI::nagiosReturn code, std::string &request) { 
    308   boost::shared_ptr<script_wrapper::function_wrapper> inst = script_wrapper::function_wrapper::create(); 
     309NSCAPI::nagiosReturn PythonScript::handleRAWNotification(const std::wstring &channel, const std::wstring &command, std::string &request) { 
     310  boost::shared_ptr<script_wrapper::function_wrapper> inst = script_wrapper::function_wrapper::create(get_id()); 
    309311  std::string cmd = utf8::cvt<std::string>(command); 
    310312  std::string chnl = utf8::cvt<std::string>(channel); 
     
    314316  if (inst->has_simple_message_handler(chnl)) { 
    315317    std::wstring msg, perf; 
    316     nscapi::functions::parse_simple_query_response(request, msg, perf); 
     318    int code = nscapi::functions::parse_simple_query_response(request, msg, perf); 
    317319    return inst->handle_simple_message(chnl, cmd, code, msg, perf); 
    318320  } 
  • modules/PythonScript/PythonScript.def

    r39c73cd ra44cb15  
    1515  NSCommandLineExec 
    1616  NSDeleteBuffer 
     17  NSHasNotificationHandler 
     18  NSHandleNotification 
  • modules/PythonScript/PythonScript.h

    r81e420c ra44cb15  
    3434 
    3535struct python_script : public boost::noncopyable { 
     36  unsigned int plugin_id; 
     37  std::string alias; 
    3638  boost::python::dict localDict; 
    37   python_script(const script_container& script); 
     39  python_script(unsigned int plugin_id, const std::string alias, const script_container& script); 
    3840  ~python_script(); 
    3941  void callFunction(const std::string& functionName); 
    40   void callFunction(const std::string& functionName, const std::string &str); 
     42  void callFunction(const std::string& functionName, unsigned int i1, const std::string &s1, const std::string &s2); 
    4143  void _exec(const std::string &scriptfile); 
    4244}; 
     
    8486  NSCAPI::nagiosReturn handleRAWCommand(const wchar_t* char_command, const std::string &request, std::string &response); 
    8587  NSCAPI::nagiosReturn commandRAWLineExec(const wchar_t* char_command, const std::string &request, std::string &response); 
    86   NSCAPI::nagiosReturn handleRAWNotification(const std::wstring &channel, const std::wstring &command, NSCAPI::nagiosReturn code, std::string &request); 
     88  NSCAPI::nagiosReturn handleRAWNotification(const std::wstring &channel, const std::wstring &command, std::string &request); 
    8789 
    8890  //NSCAPI::nagiosReturn RunLUA(const unsigned int argLen, wchar_t **char_args, std::wstring &message, std::wstring &perf); 
  • modules/PythonScript/script_wrapper.cpp

    r81e420c ra44cb15  
    3131 
    3232void script_wrapper::function_wrapper::subscribe_simple_function(std::string channel, PyObject* callable) { 
    33   functions::get()->simple_handler[channel] = callable; 
     33  try { 
     34    core->registerSubmissionListener(plugin_id, utf8::cvt<std::wstring>(channel)); 
     35    functions::get()->simple_handler[channel] = callable; 
     36  } catch (const std::exception &e) { 
     37    NSC_LOG_ERROR_STD(_T("Failed to subscribe to channel ") + utf8::cvt<std::wstring>(channel) + _T(": ") + utf8::cvt<std::wstring>(e.what())); 
     38  } catch (...) { 
     39    NSC_LOG_ERROR_STD(_T("Failed to subscribe to channel ") + utf8::cvt<std::wstring>(channel)); 
     40  } 
    3441} 
    3542void script_wrapper::function_wrapper::subscribe_function(std::string channel, PyObject* callable) { 
    36   functions::get()->normal_handler[channel] = callable; 
     43  try { 
     44    core->registerSubmissionListener(plugin_id, utf8::cvt<std::wstring>(channel)); 
     45    functions::get()->normal_handler[channel] = callable; 
     46  } catch (const std::exception &e) { 
     47    NSC_LOG_ERROR_STD(_T("Failed to subscribe to channel ") + utf8::cvt<std::wstring>(channel) + _T(": ") + utf8::cvt<std::wstring>(e.what())); 
     48  } catch (...) { 
     49    NSC_LOG_ERROR_STD(_T("Failed to subscribe to channel ") + utf8::cvt<std::wstring>(channel)); 
     50  } 
    3751} 
    3852 
     
    4054void script_wrapper::function_wrapper::register_simple_function(std::string name, PyObject* callable, std::string desc) { 
    4155  try { 
    42     core->registerCommand(utf8::cvt<std::wstring>(name), utf8::cvt<std::wstring>(desc)); 
     56    core->registerCommand(plugin_id, utf8::cvt<std::wstring>(name), utf8::cvt<std::wstring>(desc)); 
    4357    functions::get()->simple_functions[name] = callable; 
    4458  } catch (...) { 
     
    4862void script_wrapper::function_wrapper::register_function(std::string name, PyObject* callable, std::string desc) { 
    4963  try { 
    50   core->registerCommand(utf8::cvt<std::wstring>(name), utf8::cvt<std::wstring>(desc)); 
     64  core->registerCommand(plugin_id, utf8::cvt<std::wstring>(name), utf8::cvt<std::wstring>(desc)); 
    5165  functions::get()->normal_functions[name] = callable; 
    5266  } catch (...) { 
  • modules/PythonScript/script_wrapper.hpp

    r81e420c ra44cb15  
    4747  private: 
    4848    nscapi::core_wrapper* core; 
     49    unsigned int plugin_id; 
    4950    function_wrapper() {} 
    5051  public: 
     
    5455      return *this; 
    5556    } 
    56     function_wrapper(nscapi::core_wrapper* core) : core(core) {} 
     57    function_wrapper(nscapi::core_wrapper* core, unsigned int plugin_id) : core(core), plugin_id(plugin_id) {} 
    5758    typedef std::map<std::string,PyObject*> function_map_type; 
    5859    //typedef boost::python::tuple simple_return; 
    5960 
    6061 
    61     static boost::shared_ptr<function_wrapper> create() { 
    62       return boost::shared_ptr<function_wrapper>(new function_wrapper(nscapi::plugin_singleton->get_core())); 
     62    static boost::shared_ptr<function_wrapper> create(unsigned int plugin_id) { 
     63      return boost::shared_ptr<function_wrapper>(new function_wrapper(nscapi::plugin_singleton->get_core(), plugin_id)); 
    6364    } 
    6465 
  • modules/Scheduler/Scheduler.cpp

    r81e420c ra44cb15  
    159159    NSCAPI::nagiosReturn code = GET_CORE()->simple_query(item.command.c_str(), item.arguments, response); 
    160160    if (nscapi::report::matches(item.report, code)) { 
    161       GET_CORE()->NotifyChannel(item.channel, item.alias, code, response); 
     161      GET_CORE()->submit_message(item.channel, item.alias, response); 
    162162    } 
    163163  } catch (nscapi::nscapi_exception &e) { 
  • scripts/python/test.py

    r81e420c ra44cb15  
    1919 
    2020def test_channel(channel, command, code, message, perf): 
    21   log('inside test_channel: %s'%channel) 
     21  global prefix 
     22  log('inside test_channel: %s with prefix %s'%(channel, prefix)) 
    2223  log('Data: %d %s %s'%(code, message, perf)) 
    2324 
     
    8990   
    9091  response = plugin_pb2.QueryResponseMessage() 
    91   response.header.type = plugin_pb2.Common.Header.QUERY_RESPONSE 
    9292  response.header.version = plugin_pb2.Common.VERSION_1 
    9393 
     
    9999  return (status.OK, response.SerializeToString()) 
    100100 
    101 def init(alias): 
     101def init(plugin_id, plugin_alias, script_alias): 
    102102  global prefix 
    103   if alias: 
    104     prefix = '%s_'%alias 
     103  if script_alias: 
     104    prefix = '%s_'%script_alias 
    105105 
    106   log('Script: test.py with alias: %s'%alias) 
     106  log('Script: test.py with alias: %s (%s:%d)'%(script_alias, plugin_alias, plugin_id)) 
    107107 
    108108  conf = Settings.get() 
     
    112112   
    113113  log('Testing to register a function') 
    114   reg = Registry.get() 
     114  reg = Registry.get(plugin_id) 
    115115  reg.simple_function('%stest'%prefix, test, 'This is a sample command') 
    116116  reg.simple_function('%snormal'%prefix, normal, 'This is a sample command') 
  • service/NSClient++.cpp

    r81e420c ra44cb15  
    948948 
    949949    plugins_.insert(plugins_.end(), plugin); 
    950     commands_.add_plugin(plugin); 
    951     channels_.add_plugin(plugin); 
    952     if (plugin->hasNotificationHandler()) { 
    953       channels_.register_listener(plugin->get_id(), _T("NSCA")); 
    954     } 
     950    if (plugin->hasCommandHandler()) 
     951      commands_.add_plugin(plugin); 
     952    if (plugin->hasNotificationHandler()) 
     953      channels_.add_plugin(plugin); 
    955954    if (plugin->hasMessageHandler()) 
    956955      logger_master_.add_plugin(plugin); 
     
    12021201} 
    12031202 
     1203NSCAPI::errorReturn NSClientT::register_submission_listener(unsigned int plugin_id, const wchar_t* channel) { 
     1204  channels_.register_listener(plugin_id, channel); 
     1205  return NSCAPI::isSuccess; 
     1206} 
     1207NSCAPI::errorReturn NSClientT::register_routing_listener(unsigned int plugin_id, const wchar_t* channel) { 
     1208  routers_.register_listener(plugin_id, channel); 
     1209  return NSCAPI::isSuccess; 
     1210} 
     1211 
    12041212NSCAPI::errorReturn NSClientT::send_notification(const wchar_t* channel, const wchar_t* command, char* buffer, unsigned int buffer_len) { 
    12051213  boost::shared_lock<boost::shared_mutex> readLock(m_mutexRW, boost::get_system_time() + boost::posix_time::milliseconds(5000)); 
     
    12211229    } 
    12221230  } catch (nsclient::plugins_list_exception &e) { 
    1223     LOG_ERROR_CORE(_T("Erroro routing channel: ") + std::wstring(channel) + _T(": ") + to_wstring(e.what())); 
     1231    LOG_ERROR_CORE(_T("Error routing channel: ") + std::wstring(channel) + _T(": ") + to_wstring(e.what()) + _T("Current channels: ") + channels_.to_wstring()); 
    12241232    return NSCAPI::hasFailed; 
    12251233  } catch (...) { 
  • service/NSClient++.h

    r81e420c ra44cb15  
    172172  int simple_exec(std::wstring module, std::wstring command, std::vector<std::wstring> arguments, std::list<std::wstring> &resp); 
    173173  NSCAPI::nagiosReturn exec_command(const wchar_t* raw_command, std::string &request, std::string &response); 
     174  NSCAPI::errorReturn register_submission_listener(unsigned int plugin_id, const wchar_t* channel); 
     175  NSCAPI::errorReturn register_routing_listener(unsigned int plugin_id, const wchar_t* channel); 
    174176 
    175177  struct service_controller { 
  • service/core_api.cpp

    r81e420c ra44cb15  
    478478  if (wcscasecmp(buffer, _T("NSAPIExpandPath")) == 0) 
    479479    return reinterpret_cast<LPVOID>(&NSAPIExpandPath); 
     480  if (wcscasecmp(buffer, _T("NSAPIRegisterSubmissionListener")) == 0) 
     481    return reinterpret_cast<LPVOID>(&NSAPIRegisterSubmissionListener); 
     482  if (wcscasecmp(buffer, _T("NSAPIRegisterRoutingListener")) == 0) 
     483    return reinterpret_cast<LPVOID>(&NSAPIRegisterRoutingListener); 
    480484 
    481485  LOG_ERROR_STD(_T("Function not found: ") + buffer); 
     
    483487} 
    484488 
     489NSCAPI::errorReturn NSAPIRegisterSubmissionListener(unsigned int plugin_id, const wchar_t* channel) { 
     490  return mainClient.register_submission_listener(plugin_id, channel); 
     491} 
     492NSCAPI::errorReturn NSAPIRegisterRoutingListener(unsigned int plugin_id, const wchar_t* channel) { 
     493  return mainClient.register_routing_listener(plugin_id, channel); 
     494} 
     495 
     496//  channels_.register_listener(plugin->get_id(), _T("NSCA")); 
     497 
    485498NSCAPI::errorReturn NSAPINotify(const wchar_t* channel, const wchar_t* command, char* result, unsigned int result_len) { 
    486499  return mainClient.send_notification(channel, command, result, result_len); 
  • service/core_api.h

    r81e420c ra44cb15  
    6363void NSAPIDestroyBuffer(char**); 
    6464NSCAPI::errorReturn NSAPIExpandPath(const wchar_t*,wchar_t*,unsigned int); 
     65NSCAPI::errorReturn NSAPIRegisterSubmissionListener(unsigned int plugin_id, const wchar_t* channel); 
     66NSCAPI::errorReturn NSAPIRegisterRoutingListener(unsigned int plugin_id, const wchar_t* channel); 
  • service/plugin_list.hpp

    r81e420c ra44cb15  
    105105        ret += str; 
    106106      } 
    107       return ret; 
     107      return ret + parent::to_wstring(); 
     108    } 
     109    std::string to_string() { 
     110      std::string ret; 
     111      BOOST_FOREACH(std::wstring str, list()) { 
     112        if (!ret.empty()) ret += ", "; 
     113        ret += utf8::cvt<std::string>(str); 
     114      } 
     115      return ret + parent::to_string(); 
    108116    } 
    109117 
     
    149157      } 
    150158    } 
     159    std::wstring to_wstring() { 
     160      std::wstring ret; 
     161      BOOST_FOREACH(listener_list_type::value_type i, listeners_) { 
     162        ret += _T(", "); 
     163        ret += i.first; 
     164      } 
     165      return ret; 
     166    } 
     167    std::string to_string() { 
     168      std::string ret; 
     169      BOOST_FOREACH(listener_list_type::value_type i, listeners_) { 
     170        ret += ", "; 
     171        ret += utf8::cvt<std::string>(i.first); 
     172      } 
     173      return ret; 
     174    } 
     175 
    151176  }; 
    152177 
     
    163188      } 
    164189      std::wstring lc = make_key(channel); 
    165       if (!have_plugin(plugin_id)) 
    166         throw plugins_list_exception("Failed to find plugin: " + ::to_string(plugin_id)); 
     190      if (!have_plugin(plugin_id)) { 
     191        writeLock.release(); 
     192        throw plugins_list_exception("Failed to find plugin: " + ::to_string(plugin_id) + ", Plugins: " + to_string()); 
     193      } 
    167194      listeners_[lc].insert(plugin_id); 
    168195    } 
     
    174201      plugins_list_listeners_impl::listener_list_type::iterator cit = listeners_.find(lc); 
    175202      if (cit == listeners_.end()) { 
    176         throw plugins_list_exception("Channel not found: " + to_string(channel)); 
     203        return std::list<plugin_type>(); // throw plugins_list_exception("Channel not found: '" + ::to_string(channel) + "'" + to_string()); 
    177204      } 
    178205      std::list<plugin_type> ret; 
Note: See TracChangeset for help on using the changeset viewer.