source: nscp/include/nscapi/macros.hpp

Last change on this file was f542694, checked in by Michael Medin <michael@…>, 3 days ago

Yet another massive update with mainly internal stuff
The most interesting thing is I guess the new documentation toolkit which is now "working" (not much content yet, but it will come)

  • Property mode set to 100644
File size: 9.8 KB
Line 
1#pragma once
2#include <unicode_char.hpp>
3#include <boost/shared_ptr.hpp>
4#include <NSCAPI.h>
5
6#pragma warning( disable : 4100 )
7
8//////////////////////////////////////////////////////////////////////////
9// Module wrappers (definitions)
10#define NSC_WRAPPERS_MAIN() \
11        extern "C" int NSModuleHelperInit(unsigned int id, nscapi::core_api::lpNSAPILoader f); \
12        extern "C" int NSLoadModule(); \
13        extern "C" int NSLoadModuleEx(unsigned int plugin_id, char* alias, int mode); \
14        extern "C" void NSDeleteBuffer(char**buffer); \
15        extern "C" int NSGetModuleName(char* buf, int buflen); \
16        extern "C" int NSGetModuleDescription(char* buf, int buflen); \
17        extern "C" int NSGetModuleVersion(int *major, int *minor, int *revision); \
18        extern "C" NSCAPI::boolReturn NSHasCommandHandler(unsigned int plugin_id); \
19        extern "C" NSCAPI::boolReturn NSHasMessageHandler(unsigned int plugin_id); \
20        extern "C" void NSHandleMessage(unsigned int plugin_id, const char* data, unsigned int len); \
21        extern "C" NSCAPI::nagiosReturn NSHandleCommand(unsigned int plugin_id, const char* request_buffer, const unsigned int request_buffer_len, char** reply_buffer, unsigned int *reply_buffer_len); \
22        extern "C" int NSUnloadModule(unsigned int plugin_id);
23
24
25#define NSC_WRAPPERS_CLI() \
26        extern "C" int NSCommandLineExec(unsigned int plugin_id, char *request_buffer, unsigned int request_len, char **response_buffer, unsigned int *response_len);
27
28#define NSC_WRAPPERS_CHANNELS() \
29        extern "C" int NSHasNotificationHandler(unsigned int plugin_id); \
30        extern "C" int NSHandleNotification(unsigned int plugin_id, const char* channel, const char* buffer, unsigned int buffer_len, char** response_buffer, unsigned int *response_buffer_len);
31
32#define NSC_WRAPPERS_ROUTING() \
33        extern "C" int NSHasRoutingHandler(unsigned int plugin_id); \
34        extern "C" int NSRouteMessage(unsigned int plugin_id, const char*, NSCAPI::nagiosReturn, const char*, unsigned int);
35
36//////////////////////////////////////////////////////////////////////////
37// Logging calls for the core wrapper
38
39#define NSC_LOG_ERROR_EXR(msg, ex) if (GET_CORE()->should_log(NSCAPI::log_level::error)) { NSC_ANY_MSG("Exception in " + std::string(msg) + ": " + utf8::utf8_from_native(ex.what()), NSCAPI::log_level::error); }
40#define NSC_LOG_ERROR_EX(msg) if (GET_CORE()->should_log(NSCAPI::log_level::error)) { NSC_ANY_MSG("Exception in " + std::string(msg), NSCAPI::log_level::error); }
41#define NSC_LOG_ERROR_STD(msg) if (GET_CORE()->should_log(NSCAPI::log_level::error)) { NSC_ANY_MSG((std::string)msg, NSCAPI::log_level::error); }
42#define NSC_LOG_ERROR(msg) if (GET_CORE()->should_log(NSCAPI::log_level::error)) { NSC_ANY_MSG(msg, NSCAPI::log_level::error); }
43#define NSC_LOG_ERROR_WA(msg, ws) if (GET_CORE()->should_log(NSCAPI::log_level::error)) { NSC_ANY_MSG((std::string)msg + utf8::cvt<std::string>(ws), NSCAPI::log_level::error); }
44#define NSC_LOG_ERROR_W(msg) if (GET_CORE()->should_log(NSCAPI::log_level::error)) { NSC_ANY_MSG(utf8::cvt<std::string>(msg), NSCAPI::log_level::error); }
45#define NSC_LOG_ERROR_LISTW(lst) if (GET_CORE()->should_log(NSCAPI::log_level::error)) { BOOST_FOREACH(const std::wstring &s, lst) { NSC_ANY_MSG(utf8::cvt<std::string>(s), NSCAPI::log_level::error); } }
46#define NSC_LOG_ERROR_LISTS(lst) if (GET_CORE()->should_log(NSCAPI::log_level::error)) { BOOST_FOREACH(const std::string &s, lst) { NSC_ANY_MSG(s, NSCAPI::log_level::error); } }
47
48#define NSC_LOG_CRITICAL_STD(msg) if (GET_CORE()->should_log(NSCAPI::log_level::critical)) { NSC_ANY_MSG((std::string)msg, NSCAPI::log_level::critical); }
49#define NSC_LOG_CRITICAL(msg) if (GET_CORE()->should_log(NSCAPI::log_level::critical)) { NSC_ANY_MSG(msg, NSCAPI::log_level::critical); }
50
51#define NSC_LOG_MESSAGE_STD(msg) if (GET_CORE()->should_log(NSCAPI::log_level::info)) { NSC_ANY_MSG((std::string)msg, NSCAPI::log_level::info); }
52#define NSC_LOG_MESSAGE(msg) if (GET_CORE()->should_log(NSCAPI::log_level::info)) { NSC_ANY_MSG(msg, NSCAPI::log_level::info); }
53
54#define NSC_DEBUG_MSG_STD(msg) if (GET_CORE()->should_log(NSCAPI::log_level::debug)) { NSC_ANY_MSG((std::string)msg, NSCAPI::log_level::debug); }
55#define NSC_DEBUG_MSG(msg) if (GET_CORE()->should_log(NSCAPI::log_level::debug)) { NSC_ANY_MSG(msg, NSCAPI::log_level::debug); }
56
57#define NSC_ANY_MSG(msg, type) GET_CORE()->log(type, __FILE__, __LINE__, msg)
58
59//////////////////////////////////////////////////////////////////////////
60// Message wrappers below this point
61
62#ifdef _WIN32
63#define NSC_WRAP_DLL() \
64        BOOL APIENTRY DllMain( HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved) { return TRUE; } \
65        nscapi::helper_singleton* nscapi::plugin_singleton = new nscapi::helper_singleton();
66#else
67#define NSC_WRAP_DLL() \
68        nscapi::helper_singleton* nscapi::plugin_singleton = new nscapi::helper_singleton();
69#endif
70
71
72#define NSC_WRAPPERS_MAIN_DEF(impl_class, def_alias) \
73        typedef impl_class plugin_impl_class; \
74        static nscapi::plugin_instance_data<plugin_impl_class> plugin_instance; \
75        extern int NSModuleHelperInit(unsigned int id, nscapi::core_api::lpNSAPILoader f) { return nscapi::basic_wrapper_static<plugin_impl_class>::NSModuleHelperInit(f); } \
76        extern int NSLoadModuleEx(unsigned int id, char* alias, int mode) { \
77                nscapi::basic_wrapper_static<plugin_impl_class>::set_alias(def_alias, alias); \
78                nscapi::basic_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \
79                return wrapper.NSLoadModuleEx(id, alias, mode); } \
80        extern int NSLoadModule() { return nscapi::basic_wrapper_static<plugin_impl_class>::NSLoadModule(); } \
81        extern int NSGetModuleName(char* buf, int buflen) { return nscapi::basic_wrapper_static<plugin_impl_class>::NSGetModuleName(buf, buflen); } \
82        extern int NSGetModuleDescription(char* buf, int buflen) { return nscapi::basic_wrapper_static<plugin_impl_class>::NSGetModuleDescription(buf, buflen); } \
83        extern int NSGetModuleVersion(int *major, int *minor, int *revision) { return nscapi::basic_wrapper_static<plugin_impl_class>::NSGetModuleVersion(major, minor, revision); } \
84        extern int NSUnloadModule(unsigned int id) { \
85                int ret; {nscapi::basic_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \
86                ret = wrapper.NSUnloadModule();} \
87                plugin_instance.erase(id); \
88                return ret; } \
89        extern void NSDeleteBuffer(char**buffer) { nscapi::basic_wrapper_static<plugin_impl_class>::NSDeleteBuffer(buffer); }
90
91#define NSC_WRAPPERS_HANDLE_MSG_DEF() \
92        extern void NSHandleMessage(unsigned int id, const char* request_buffer, unsigned int request_buffer_len) { \
93                nscapi::message_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \
94                return wrapper.NSHandleMessage(request_buffer, request_buffer_len); } \
95        extern NSCAPI::boolReturn NSHasMessageHandler(unsigned int id) { \
96                nscapi::message_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \
97                return wrapper.NSHasMessageHandler(); }
98
99#define NSC_WRAPPERS_HANDLE_CMD_DEF() \
100        extern NSCAPI::nagiosReturn NSHandleCommand(unsigned int id, const char* request_buffer, const unsigned int request_buffer_len, char** reply_buffer, unsigned int *reply_buffer_len) { \
101                nscapi::command_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \
102                return wrapper.NSHandleCommand(request_buffer, request_buffer_len, reply_buffer, reply_buffer_len); } \
103        extern NSCAPI::boolReturn NSHasCommandHandler(unsigned int id) { \
104                nscapi::command_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \
105                return wrapper.NSHasCommandHandler(); }
106
107#define NSC_WRAPPERS_ROUTING_DEF() \
108        extern NSCAPI::nagiosReturn NSRouteMessage(unsigned int id, const char* channel, const char* command, const char* request_buffer, const unsigned int request_buffer_len) { \
109                nscapi::routing_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \
110                return wrapper.NSRouteMessage(channel, command, request_buffer, request_buffer_len); } \
111        extern NSCAPI::boolReturn NSHasRoutingHandler(unsigned int id) { \
112                nscapi::routing_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \
113                return wrapper.NSHasRoutingHandler(); }
114
115#define NSC_WRAPPERS_HANDLE_NOTIFICATION_DEF() \
116        extern int NSHandleNotification(unsigned int id, const char* channel, const char* buffer, unsigned int buffer_len, char** response_buffer, unsigned int *response_buffer_len) { \
117                nscapi::submission_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \
118                return wrapper.NSHandleNotification(channel, buffer, buffer_len, response_buffer, response_buffer_len); } \
119        extern NSCAPI::boolReturn NSHasNotificationHandler(unsigned int id) { \
120                nscapi::submission_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \
121                return wrapper.NSHasNotificationHandler(); }
122
123#define NSC_WRAPPERS_CLI_DEF() \
124        extern int NSCommandLineExec(unsigned int id, char *request_buffer, unsigned int request_len, char **response_buffer, unsigned int *response_len) { \
125                nscapi::cliexec_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \
126                return wrapper.NSCommandLineExec(request_buffer, request_len, response_buffer, response_len); }
127
128#define NSC_WRAPPERS_IGNORE_MSG_DEF() \
129        extern void NSHandleMessage(unsigned int id, const char* data, unsigned int len) {} \
130        extern NSCAPI::boolReturn NSHasMessageHandler(unsigned int id) { return NSCAPI::isfalse; }
131
132#define NSC_WRAPPERS_IGNORE_CMD_DEF() \
133        extern NSCAPI::nagiosReturn NSHandleCommand(unsigned int id, const char* request_buffer, const unsigned int request_buffer_len, char** reply_buffer, unsigned int *reply_buffer_len) {  return NSCAPI::returnIgnored; } \
134        extern NSCAPI::boolReturn NSHasCommandHandler(unsigned int id) { return NSCAPI::isfalse; }
135
136#define NSC_WRAPPERS_IGNORE_NOTIFICATION_DEF() \
137        extern int NSHandleNotification(unsigned int id, const char* channel, const char* command, const char* result_buffer, unsigned int result_buffer_len) {} \
138        extern NSCAPI::boolReturn NSHasNotificationHandler(unsigned int id) { return NSCAPI::isfalse; }
139
140#define GET_CORE() nscapi::plugin_singleton->get_core()
Note: See TracBrowser for help on using the repository browser.