| 1 | #pragma once
|
|---|
| 2 | #include <unicode_char.hpp>
|
|---|
| 3 | #include <boost/shared_ptr.hpp>
|
|---|
| 4 | #include <NSCAPI.h>
|
|---|
| 5 |
|
|---|
| 6 | //////////////////////////////////////////////////////////////////////////
|
|---|
| 7 | // Module wrappers (definitions)
|
|---|
| 8 | #define NSC_WRAPPERS_MAIN() \
|
|---|
| 9 | extern "C" int NSModuleHelperInit(unsigned int id, nscapi::core_api::lpNSAPILoader f); \
|
|---|
| 10 | extern "C" int NSLoadModule(); \
|
|---|
| 11 | extern "C" int NSLoadModuleEx(unsigned int plugin_id, wchar_t* alias, int mode); \
|
|---|
| 12 | extern "C" void NSDeleteBuffer(char**buffer); \
|
|---|
| 13 | extern "C" int NSGetModuleName(wchar_t* buf, int buflen); \
|
|---|
| 14 | extern "C" int NSGetModuleDescription(wchar_t* buf, int buflen); \
|
|---|
| 15 | extern "C" int NSGetModuleVersion(int *major, int *minor, int *revision); \
|
|---|
| 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);
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 | #define NSC_WRAPPERS_CLI() \
|
|---|
| 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);
|
|---|
| 25 |
|
|---|
| 26 | #define NSC_WRAPPERS_CHANNELS() \
|
|---|
| 27 | extern "C" int NSHasNotificationHandler(unsigned int plugin_id); \
|
|---|
| 28 | extern "C" int NSHandleNotification(unsigned int plugin_id, const wchar_t* channel, const char* buffer, unsigned int buffer_len, char** response_buffer, unsigned int *response_buffer_len);
|
|---|
| 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*, NSCAPI::nagiosReturn, const char*, unsigned int);
|
|---|
| 33 |
|
|---|
| 34 | //////////////////////////////////////////////////////////////////////////
|
|---|
| 35 | // Logging calls for the core wrapper
|
|---|
| 36 |
|
|---|
| 37 | #define NSC_LOG_ERROR_STD(msg) if (GET_CORE()->should_log(NSCAPI::log_level::error)) { NSC_ANY_MSG((std::wstring)msg, NSCAPI::log_level::error); }
|
|---|
| 38 | #define NSC_LOG_ERROR(msg) if (GET_CORE()->should_log(NSCAPI::log_level::error)) { NSC_ANY_MSG(msg, NSCAPI::log_level::error); }
|
|---|
| 39 |
|
|---|
| 40 | #define NSC_LOG_CRITICAL_STD(msg) if (GET_CORE()->should_log(NSCAPI::log_level::critical)) { NSC_ANY_MSG((std::wstring)msg, NSCAPI::log_level::critical); }
|
|---|
| 41 | #define NSC_LOG_CRITICAL(msg) if (GET_CORE()->should_log(NSCAPI::log_level::critical)) { NSC_ANY_MSG(msg, NSCAPI::log_level::critical); }
|
|---|
| 42 |
|
|---|
| 43 | #define NSC_LOG_MESSAGE_STD(msg) if (GET_CORE()->should_log(NSCAPI::log_level::info)) { NSC_ANY_MSG((std::wstring)msg, NSCAPI::log_level::info); }
|
|---|
| 44 | #define NSC_LOG_MESSAGE(msg) if (GET_CORE()->should_log(NSCAPI::log_level::info)) { NSC_ANY_MSG(msg, NSCAPI::log_level::info); }
|
|---|
| 45 |
|
|---|
| 46 | #define NSC_DEBUG_MSG_STD(msg) if (GET_CORE()->should_log(NSCAPI::log_level::debug)) { NSC_ANY_MSG((std::wstring)msg, NSCAPI::log_level::debug); }
|
|---|
| 47 | #define NSC_DEBUG_MSG(msg) if (GET_CORE()->should_log(NSCAPI::log_level::debug)) { NSC_ANY_MSG(msg, NSCAPI::log_level::debug); }
|
|---|
| 48 |
|
|---|
| 49 | #define NSC_ANY_MSG(msg, type) GET_CORE()->log(type, __FILE__, __LINE__, msg)
|
|---|
| 50 |
|
|---|
| 51 | //////////////////////////////////////////////////////////////////////////
|
|---|
| 52 | // Message wrappers below this point
|
|---|
| 53 |
|
|---|
| 54 | #ifdef _WIN32
|
|---|
| 55 | #define NSC_WRAP_DLL() \
|
|---|
| 56 | BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { /*GET_PLUGIN()->wrapDllMain(hModule, ul_reason_for_call); */return TRUE; } \
|
|---|
| 57 | nscapi::helper_singleton* nscapi::plugin_singleton = new nscapi::helper_singleton();
|
|---|
| 58 | #else
|
|---|
| 59 | #define NSC_WRAP_DLL() \
|
|---|
| 60 | nscapi::helper_singleton* nscapi::plugin_singleton = new nscapi::helper_singleton();
|
|---|
| 61 | #endif
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 | #define NSC_WRAPPERS_MAIN_DEF(impl_class) \
|
|---|
| 65 | typedef impl_class plugin_impl_class; \
|
|---|
| 66 | static nscapi::plugin_instance_data<plugin_impl_class> plugin_instance; \
|
|---|
| 67 | extern int NSModuleHelperInit(unsigned int id, nscapi::core_api::lpNSAPILoader f) { return nscapi::basic_wrapper_static<plugin_impl_class>::NSModuleHelperInit(f); } \
|
|---|
| 68 | extern int NSLoadModuleEx(unsigned int id, wchar_t* alias, int mode) { \
|
|---|
| 69 | nscapi::basic_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \
|
|---|
| 70 | return wrapper.NSLoadModuleEx(id, alias, mode); } \
|
|---|
| 71 | extern int NSLoadModule() { return nscapi::basic_wrapper_static<plugin_impl_class>::NSLoadModule(); } \
|
|---|
| 72 | extern int NSGetModuleName(wchar_t* buf, int buflen) { return nscapi::basic_wrapper_static<plugin_impl_class>::NSGetModuleName(buf, buflen); } \
|
|---|
| 73 | extern int NSGetModuleDescription(wchar_t* buf, int buflen) { return nscapi::basic_wrapper_static<plugin_impl_class>::NSGetModuleDescription(buf, buflen); } \
|
|---|
| 74 | extern int NSGetModuleVersion(int *major, int *minor, int *revision) { return nscapi::basic_wrapper_static<plugin_impl_class>::NSGetModuleVersion(major, minor, revision); } \
|
|---|
| 75 | extern int NSUnloadModule(unsigned int id) { \
|
|---|
| 76 | int ret; {nscapi::basic_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \
|
|---|
| 77 | ret = wrapper.NSUnloadModule();} \
|
|---|
| 78 | plugin_instance.erase(id); \
|
|---|
| 79 | return ret; } \
|
|---|
| 80 | extern void NSDeleteBuffer(char**buffer) { nscapi::basic_wrapper_static<plugin_impl_class>::NSDeleteBuffer(buffer); }
|
|---|
| 81 |
|
|---|
| 82 | #define NSC_WRAPPERS_HANDLE_MSG_DEF() \
|
|---|
| 83 | extern void NSHandleMessage(unsigned int id, const char* request_buffer, unsigned int request_buffer_len) { \
|
|---|
| 84 | nscapi::message_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \
|
|---|
| 85 | return wrapper.NSHandleMessage(request_buffer, request_buffer_len); } \
|
|---|
| 86 | extern NSCAPI::boolReturn NSHasMessageHandler(unsigned int id) { \
|
|---|
| 87 | nscapi::message_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \
|
|---|
| 88 | return wrapper.NSHasMessageHandler(); }
|
|---|
| 89 |
|
|---|
| 90 | #define NSC_WRAPPERS_HANDLE_CMD_DEF() \
|
|---|
| 91 | 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) { \
|
|---|
| 92 | nscapi::command_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \
|
|---|
| 93 | return wrapper.NSHandleCommand(command, request_buffer, request_buffer_len, reply_buffer, reply_buffer_len); } \
|
|---|
| 94 | extern NSCAPI::boolReturn NSHasCommandHandler(unsigned int id) { \
|
|---|
| 95 | nscapi::command_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \
|
|---|
| 96 | return wrapper.NSHasCommandHandler(); }
|
|---|
| 97 |
|
|---|
| 98 | #define NSC_WRAPPERS_ROUTING_DEF() \
|
|---|
| 99 | 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) { \
|
|---|
| 100 | nscapi::routing_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \
|
|---|
| 101 | return wrapper.NSRouteMessage(channel, command, request_buffer, request_buffer_len); } \
|
|---|
| 102 | extern NSCAPI::boolReturn NSHasRoutingHandler(unsigned int id) { \
|
|---|
| 103 | nscapi::routing_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \
|
|---|
| 104 | return wrapper.NSHasRoutingHandler(); }
|
|---|
| 105 |
|
|---|
| 106 | #define NSC_WRAPPERS_HANDLE_NOTIFICATION_DEF() \
|
|---|
| 107 | extern int NSHandleNotification(unsigned int id, const wchar_t* channel, const char* buffer, unsigned int buffer_len, char** response_buffer, unsigned int *response_buffer_len) { \
|
|---|
| 108 | nscapi::submission_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \
|
|---|
| 109 | return wrapper.NSHandleNotification(channel, buffer, buffer_len, response_buffer, response_buffer_len); } \
|
|---|
| 110 | extern NSCAPI::boolReturn NSHasNotificationHandler(unsigned int id) { \
|
|---|
| 111 | nscapi::submission_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \
|
|---|
| 112 | return wrapper.NSHasNotificationHandler(); }
|
|---|
| 113 |
|
|---|
| 114 | #define NSC_WRAPPERS_CLI_DEF() \
|
|---|
| 115 | extern int NSCommandLineExec(unsigned int id, wchar_t *command, char *request_buffer, unsigned int request_len, char **response_buffer, unsigned int *response_len) { \
|
|---|
| 116 | nscapi::cliexec_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \
|
|---|
| 117 | return wrapper.NSCommandLineExec(command, request_buffer, request_len, response_buffer, response_len); }
|
|---|
| 118 |
|
|---|
| 119 | #define NSC_WRAPPERS_IGNORE_MSG_DEF() \
|
|---|
| 120 | extern void NSHandleMessage(unsigned int id, const char* data, unsigned int len) {} \
|
|---|
| 121 | extern NSCAPI::boolReturn NSHasMessageHandler(unsigned int id) { return NSCAPI::isfalse; }
|
|---|
| 122 |
|
|---|
| 123 | #define NSC_WRAPPERS_IGNORE_CMD_DEF() \
|
|---|
| 124 | 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; } \
|
|---|
| 125 | extern NSCAPI::boolReturn NSHasCommandHandler(unsigned int id) { return NSCAPI::isfalse; }
|
|---|
| 126 |
|
|---|
| 127 | #define NSC_WRAPPERS_IGNORE_NOTIFICATION_DEF() \
|
|---|
| 128 | extern int NSHandleNotification(unsigned int id, const wchar_t* channel, const wchar_t* command, const char* result_buffer, unsigned int result_buffer_len) {} \
|
|---|
| 129 | extern NSCAPI::boolReturn NSHasNotificationHandler(unsigned int id) { return NSCAPI::isfalse; }
|
|---|
| 130 |
|
|---|
| 131 |
|
|---|
| 132 | #define SETTINGS_MAKE_NAME(key) \
|
|---|
| 133 | std::wstring(setting_keys::key ## _PATH + _T(".") + setting_keys::key)
|
|---|
| 134 |
|
|---|
| 135 | #define SETTINGS_GET_STRING(key) \
|
|---|
| 136 | GET_CORE()->getSettingsString(setting_keys::key ## _PATH, setting_keys::key, setting_keys::key ## _DEFAULT)
|
|---|
| 137 | #define SETTINGS_GET_INT(key) \
|
|---|
| 138 | GET_CORE()->getSettingsInt(setting_keys::key ## _PATH, setting_keys::key, setting_keys::key ## _DEFAULT)
|
|---|
| 139 | #define SETTINGS_GET_BOOL(key) \
|
|---|
| 140 | GET_CORE()->getSettingsInt(setting_keys::key ## _PATH, setting_keys::key, setting_keys::key ## _DEFAULT)
|
|---|
| 141 |
|
|---|
| 142 | #define SETTINGS_GET_STRING_FALLBACK(key, fallback) \
|
|---|
| 143 | GET_CORE()->getSettingsString(setting_keys::key ## _PATH, setting_keys::key, GET_CORE()->getSettingsString(setting_keys::fallback ## _PATH, setting_keys::fallback, setting_keys::fallback ## _DEFAULT))
|
|---|
| 144 | #define SETTINGS_GET_INT_FALLBACK(key, fallback) \
|
|---|
| 145 | GET_CORE()->getSettingsInt(setting_keys::key ## _PATH, setting_keys::key, GET_CORE()->getSettingsInt(setting_keys::fallback ## _PATH, setting_keys::fallback, setting_keys::fallback ## _DEFAULT))
|
|---|
| 146 | #define SETTINGS_GET_BOOL_FALLBACK(key, fallback) \
|
|---|
| 147 | GET_CORE()->getSettingsInt(setting_keys::key ## _PATH, setting_keys::key, GET_CORE()->getSettingsInt(setting_keys::fallback ## _PATH, setting_keys::fallback, setting_keys::fallback ## _DEFAULT))
|
|---|
| 148 |
|
|---|
| 149 | #define SETTINGS_REG_KEY_S(key) \
|
|---|
| 150 | GET_CORE()->settings_register_key(setting_keys::key ## _PATH, setting_keys::key, NSCAPI::key_string, setting_keys::key ## _TITLE, setting_keys::key ## _DESC, setting_keys::key ## _DEFAULT, setting_keys::key ## _ADVANCED);
|
|---|
| 151 | #define SETTINGS_REG_KEY_I(key) \
|
|---|
| 152 | GET_CORE()->settings_register_key(setting_keys::key ## _PATH, setting_keys::key, NSCAPI::key_integer, setting_keys::key ## _TITLE, setting_keys::key ## _DESC, boost::lexical_cast<std::wstring>(setting_keys::key ## _DEFAULT), setting_keys::key ## _ADVANCED);
|
|---|
| 153 | #define SETTINGS_REG_KEY_B(key) \
|
|---|
| 154 | GET_CORE()->settings_register_key(setting_keys::key ## _PATH, setting_keys::key, NSCAPI::key_integer, setting_keys::key ## _TITLE, setting_keys::key ## _DESC, setting_keys::key ## _DEFAULT==1?_T("1"):_T("0"), setting_keys::key ## _ADVANCED);
|
|---|
| 155 | #define SETTINGS_REG_PATH(key) \
|
|---|
| 156 | GET_CORE()->settings_register_path(setting_keys::key ## _PATH, setting_keys::key ## _TITLE, setting_keys::key ## _DESC, setting_keys::key ## _ADVANCED);
|
|---|
| 157 |
|
|---|
| 158 | #define GET_CORE() nscapi::plugin_singleton->get_core()
|
|---|
| 159 | #define GET_PLUGIN() nscapi::plugin_singleton->get_plugin() |
|---|