Changeset 81e420c in nscp for include/nscapi/macros.hpp
- Timestamp:
- 09/01/11 07:05:41 (21 months ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2
- Children:
- 3b11e65
- Parents:
- 1307e3f5
- File:
-
- 1 edited
-
include/nscapi/macros.hpp (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
include/nscapi/macros.hpp
r4b1e6fe r81e420c 1 1 #pragma once 2 2 #include <unicode_char.hpp> 3 #include <boost/shared_ptr.hpp> 4 #include <map> 3 5 4 6 ////////////////////////////////////////////////////////////////////////// … … 7 9 extern "C" int NSModuleHelperInit(unsigned int id, nscapi::core_api::lpNSAPILoader f); \ 8 10 extern "C" int NSLoadModule(); \ 9 extern "C" int NSLoadModuleEx( wchar_t* alias, int mode); \11 extern "C" int NSLoadModuleEx(unsigned int plugin_id, wchar_t* alias, int mode); \ 10 12 extern "C" void NSDeleteBuffer(char**buffer); \ 11 13 extern "C" int NSGetModuleName(wchar_t* buf, int buflen); \ 12 14 extern "C" int NSGetModuleDescription(wchar_t* buf, int buflen); \ 13 15 extern "C" int NSGetModuleVersion(int *major, int *minor, int *revision); \ 14 extern "C" NSCAPI::boolReturn NSHasCommandHandler( ); \15 extern "C" NSCAPI::boolReturn NSHasMessageHandler( ); \16 extern "C" void NSHandleMessage( const char* data); \17 extern "C" 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); \18 extern "C" int NSUnloadModule( );16 extern "C" NSCAPI::boolReturn NSHasCommandHandler(unsigned int plugin_id); \ 17 extern "C" NSCAPI::boolReturn NSHasMessageHandler(unsigned int plugin_id); \ 18 extern "C" void NSHandleMessage(unsigned int plugin_id, const char* data, unsigned int len); \ 19 extern "C" NSCAPI::nagiosReturn NSHandleCommand(unsigned int plugin_id, const wchar_t* command, const char* request_buffer, const unsigned int request_buffer_len, char** reply_buffer, unsigned int *reply_buffer_len); \ 20 extern "C" int NSUnloadModule(unsigned int plugin_id); 19 21 20 22 21 23 #define NSC_WRAPPERS_CLI() \ 22 extern "C" int NSCommandLineExec( wchar_t *command, char *request_buffer, unsigned int request_len, char **response_buffer, unsigned int *response_len);24 extern "C" int NSCommandLineExec(unsigned int plugin_id, wchar_t *command, char *request_buffer, unsigned int request_len, char **response_buffer, unsigned int *response_len); 23 25 24 26 #define NSC_WRAPPERS_CHANNELS() \ 25 extern "C" int NSHasNotificationHandler(); \ 26 extern "C" int NSHandleNotification(const wchar_t*, const wchar_t*, NSCAPI::nagiosReturn, const char*, unsigned int); 27 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); 29 30 #define NSC_WRAPPERS_ROUTING() \ 31 extern "C" int NSHasRoutingHandler(unsigned int plugin_id); \ 32 extern "C" int NSRouteMessage(unsigned int plugin_id, const wchar_t*, const wchar_t*, NSCAPI::nagiosReturn, const char*, unsigned int); 27 33 28 34 ////////////////////////////////////////////////////////////////////////// … … 70 76 #endif 71 77 72 #define NSC_WRAPPERS_MAIN_DEF(toObject) \ 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 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 95 96 #define NSC_WRAPPERS_MAIN_DEF(impl_class) \ 97 static plugin_instance_data<impl_class> plugin_instance; \ 73 98 extern int NSModuleHelperInit(unsigned int id, nscapi::core_api::lpNSAPILoader f) { \ 74 99 try { \ … … 79 104 } \ 80 105 } \ 81 extern int NSLoadModuleEx( wchar_t* alias, int mode) { \82 try { \ 83 return GET_PLUGIN()->wrapLoadModule( toObject.loadModuleEx(alias, mode)); \106 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)); \ 84 109 } catch (...) { \ 85 110 NSC_LOG_CRITICAL(_T("Unknown exception in: wrapLoadModule(...)")); \ … … 88 113 } \ 89 114 extern int NSLoadModule() { \ 90 try { \91 return GET_PLUGIN()->wrapLoadModule(toObject.loadModule()); \92 } catch (...) { \93 NSC_LOG_CRITICAL(_T("Unknown exception in: wrapLoadModule(...)")); \94 115 return NSCAPI::hasFailed; \ 95 } \96 116 } \ 97 117 extern int NSGetModuleName(wchar_t* buf, int buflen) { \ 98 118 try { \ 99 return GET_PLUGIN()->wrapGetModuleName(buf, buflen, toObject.getModuleName()); \119 return GET_PLUGIN()->wrapGetModuleName(buf, buflen, impl_class::getModuleName()); \ 100 120 } catch (...) { \ 101 121 NSC_LOG_CRITICAL(_T("Unknown exception in: wrapGetModuleName(...)")); \ … … 105 125 extern int NSGetModuleDescription(wchar_t* buf, int buflen) { \ 106 126 try { \ 107 return GET_PLUGIN()->wrapGetModuleName(buf, buflen, toObject.getModuleDescription()); \127 return GET_PLUGIN()->wrapGetModuleName(buf, buflen, impl_class::getModuleDescription()); \ 108 128 } catch (...) { \ 109 129 NSC_LOG_CRITICAL(_T("Unknown exception in: wrapGetModuleName(...)")); \ … … 113 133 extern int NSGetModuleVersion(int *major, int *minor, int *revision) { \ 114 134 try { \ 115 return GET_PLUGIN()->wrapGetModuleVersion(major, minor, revision, toObject.getModuleVersion()); \135 return GET_PLUGIN()->wrapGetModuleVersion(major, minor, revision, impl_class::getModuleVersion()); \ 116 136 } catch (...) { \ 117 137 NSC_LOG_CRITICAL(_T("Unknown exception in: wrapGetModuleVersion(...)")); \ … … 119 139 } \ 120 140 } \ 121 extern int NSUnloadModule() { \ 122 try { \ 123 return GET_PLUGIN()->wrapUnloadModule(toObject.unloadModule()); \ 141 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; \ 124 146 } catch (...) { \ 125 147 NSC_LOG_CRITICAL(_T("Unknown exception in: wrapGetModuleVersion(...)")); \ … … 135 157 } 136 158 #define NSC_WRAPPERS_HANDLE_MSG_DEF(toObject) \ 137 extern void NSHandleMessage(const char* data) { \ 138 try { \ 139 toObject.handleMessageRAW(data); \ 159 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); \ 140 163 } catch (...) { \ 141 164 NSC_LOG_CRITICAL(_T("Unknown exception in: handleMessage(...)")); \ 142 165 } \ 143 166 } \ 144 extern NSCAPI::boolReturn NSHasMessageHandler( ) { \145 try { \ 146 return GET_PLUGIN()->wrapHasMessageHandler( toObject.hasMessageHandler()); \167 extern NSCAPI::boolReturn NSHasMessageHandler(unsigned int id) { \ 168 try { \ 169 return GET_PLUGIN()->wrapHasMessageHandler(plugin_instance.get(id)->hasMessageHandler()); \ 147 170 } catch (...) { \ 148 171 NSC_LOG_CRITICAL(_T("Unknown exception in: wrapHasMessageHandler(...)")); \ … … 151 174 } 152 175 #define NSC_WRAPPERS_IGNORE_MSG_DEF() \ 153 extern void NSHandleMessage( const char* data) {} \154 extern NSCAPI::boolReturn NSHasMessageHandler( ) { return NSCAPI::isfalse; }155 #define NSC_WRAPPERS_HANDLE_CMD_DEF( toObject) \156 extern 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) \176 extern void NSHandleMessage(unsigned int id, const char* data, unsigned int len) {} \ 177 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) \ 157 180 { \ 158 181 try { \ 159 182 std::string request(request_buffer, request_buffer_len), reply; \ 160 NSCAPI::nagiosReturn retCode = (&toObject)->handleRAWCommand(command, request, reply); \183 NSCAPI::nagiosReturn retCode = plugin_instance.get(id)->handleRAWCommand(command, request, reply); \ 161 184 return GET_PLUGIN()->wrapHandleCommand(retCode, reply, reply_buffer, reply_buffer_len); \ 162 185 } catch (...) { \ … … 165 188 } \ 166 189 } \ 167 extern NSCAPI::boolReturn NSHasCommandHandler( ) { \168 try { \ 169 return GET_PLUGIN()->wrapHasCommandHandler( toObject.hasCommandHandler()); \190 extern NSCAPI::boolReturn NSHasCommandHandler(unsigned int id) { \ 191 try { \ 192 return GET_PLUGIN()->wrapHasCommandHandler(plugin_instance.get(id)->hasCommandHandler()); \ 170 193 } catch (...) { \ 171 194 NSC_LOG_CRITICAL(_T("Unknown exception in: wrapHasCommandHandler(...)")); \ … … 173 196 } \ 174 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 } 175 217 #define NSC_WRAPPERS_IGNORE_CMD_DEF() \ 176 extern NSCAPI::nagiosReturn NSHandleCommand( const wchar_t* IN_cmd, const unsigned int IN_argsLen, wchar_t **IN_args, \218 extern NSCAPI::nagiosReturn NSHandleCommand(unsigned int id, const wchar_t* IN_cmd, const unsigned int IN_argsLen, wchar_t **IN_args, \ 177 219 wchar_t *OUT_retBufMessage, unsigned int IN_retBufMessageLen, wchar_t *OUT_retBufPerf, unsigned int IN_retBufPerfLen) { \ 178 220 return NSCAPI::returnIgnored; \ 179 221 } \ 180 extern NSCAPI::boolReturn NSHasCommandHandler( ) { return NSCAPI::isfalse; }222 extern NSCAPI::boolReturn NSHasCommandHandler(unsigned int id) { return NSCAPI::isfalse; } 181 223 #define NSC_WRAPPERS_IGNORE_NOTIFICATION_DEF() \ 182 224 extern void NSHandleNotification(const wchar_t*, const wchar_t*, NSCAPI::nagiosReturn, const char*, unsigned int) {} \ 183 extern NSCAPI::boolReturn NSHasNotificationHandler( ) { return NSCAPI::isfalse; }184 #define NSC_WRAPPERS_HANDLE_NOTIFICATION_DEF( toObject) \185 extern NSCAPI::nagiosReturn NSHandleNotification( const wchar_t* channel, const wchar_t* command, NSCAPI::nagiosReturn code, const char* result_buffer, unsigned int result_buffer_len) \225 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) \ 186 228 { \ 187 229 try { \ 188 230 std::string result(result_buffer, result_buffer_len); \ 189 return GET_PLUGIN()->wrapHandleNotification( (&toObject)->handleRAWNotification(channel, command, code, result)); \231 return GET_PLUGIN()->wrapHandleNotification(plugin_instance.get(id)->handleRAWNotification(channel, command, code, result)); \ 190 232 } catch (...) { \ 191 233 NSC_LOG_CRITICAL(_T("Unknown exception in: wrapHasNotificationHandler(...)")); \ … … 193 235 } \ 194 236 } \ 195 extern NSCAPI::boolReturn NSHasNotificationHandler( ) { \196 try { \ 197 return GET_PLUGIN()->wrapHasNotificationHandler( toObject.hasNotificationHandler()); \237 extern NSCAPI::boolReturn NSHasNotificationHandler(unsigned int id) { \ 238 try { \ 239 return GET_PLUGIN()->wrapHasNotificationHandler(plugin_instance.get(id)->hasNotificationHandler()); \ 198 240 } catch (...) { \ 199 241 NSC_LOG_CRITICAL(_T("Unknown exception in: wrapHasNotificationHandler(...)")); \ … … 203 245 204 246 205 #define NSC_WRAPPERS_CLI_DEF( toObject) \206 extern int NSCommandLineExec( wchar_t *command, char *request_buffer, unsigned int request_len, char **response_buffer, unsigned int *response_len) { \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) { \ 207 249 try { \ 208 250 std::string request = std::string(request_buffer, request_len); \ 209 251 std::string response; \ 210 NSCAPI::nagiosReturn retCode = (&toObject)->commandRAWLineExec(command, request, response); \252 NSCAPI::nagiosReturn retCode = plugin_instance.get(id)->commandRAWLineExec(command, request, response); \ 211 253 return GET_PLUGIN()->wrapCommandLineExec(retCode, response, response_buffer, response_len); \ 212 254 } catch (const std::exception &e) { \ … … 220 262 } \ 221 263 } \ 222 223 264 224 265
Note: See TracChangeset
for help on using the changeset viewer.








