source: nscp/include/nscapi/macros.hpp @ 9fdde88

0.4.2
Last change on this file since 9fdde88 was 9fdde88, checked in by Michael Medin <michael@…>, 11 months ago
  • Added plugin_id to settings API to allow generating documentation based on module names.
  • Added option --filter <module name> to filter generation based on module name. You can now do this to generate documentation for a given module. nscp settings --settings dummy --generate trac --filter ExternalScripts? --load-all --add-defaults --log error
  • Property mode set to 100644
File size: 9.3 KB
Line 
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#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(s, NSCAPI::log_level::error); } }
40#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); } }
41
42#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); }
43#define NSC_LOG_CRITICAL(msg) if (GET_CORE()->should_log(NSCAPI::log_level::critical)) { NSC_ANY_MSG(msg, NSCAPI::log_level::critical); }
44
45#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); }
46#define NSC_LOG_MESSAGE(msg) if (GET_CORE()->should_log(NSCAPI::log_level::info)) { NSC_ANY_MSG(msg, NSCAPI::log_level::info); }
47
48#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); }
49#define NSC_DEBUG_MSG(msg) if (GET_CORE()->should_log(NSCAPI::log_level::debug)) { NSC_ANY_MSG(msg, NSCAPI::log_level::debug); }
50
51#define NSC_ANY_MSG(msg, type) GET_CORE()->log(type, __FILE__, __LINE__, msg)
52
53//////////////////////////////////////////////////////////////////////////
54// Message wrappers below this point
55
56#ifdef _WIN32
57#define NSC_WRAP_DLL() \
58        BOOL APIENTRY DllMain( HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved) { return TRUE; } \
59        nscapi::helper_singleton* nscapi::plugin_singleton = new nscapi::helper_singleton();
60#else
61#define NSC_WRAP_DLL() \
62        nscapi::helper_singleton* nscapi::plugin_singleton = new nscapi::helper_singleton();
63#endif
64
65
66#define NSC_WRAPPERS_MAIN_DEF(impl_class, def_alias) \
67        typedef impl_class plugin_impl_class; \
68        static nscapi::plugin_instance_data<plugin_impl_class> plugin_instance; \
69        extern int NSModuleHelperInit(unsigned int id, nscapi::core_api::lpNSAPILoader f) { return nscapi::basic_wrapper_static<plugin_impl_class>::NSModuleHelperInit(f); } \
70        extern int NSLoadModuleEx(unsigned int id, wchar_t* alias, int mode) { \
71                nscapi::basic_wrapper_static<plugin_impl_class>::set_alias(def_alias, alias); \
72                nscapi::basic_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \
73                return wrapper.NSLoadModuleEx(id, alias, mode); } \
74        extern int NSLoadModule() { return nscapi::basic_wrapper_static<plugin_impl_class>::NSLoadModule(); } \
75        extern int NSGetModuleName(wchar_t* buf, int buflen) { return nscapi::basic_wrapper_static<plugin_impl_class>::NSGetModuleName(buf, buflen); } \
76        extern int NSGetModuleDescription(wchar_t* buf, int buflen) { return nscapi::basic_wrapper_static<plugin_impl_class>::NSGetModuleDescription(buf, buflen); } \
77        extern int NSGetModuleVersion(int *major, int *minor, int *revision) { return nscapi::basic_wrapper_static<plugin_impl_class>::NSGetModuleVersion(major, minor, revision); } \
78        extern int NSUnloadModule(unsigned int id) { \
79                int ret; {nscapi::basic_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \
80                ret = wrapper.NSUnloadModule();} \
81                plugin_instance.erase(id); \
82                return ret; } \
83        extern void NSDeleteBuffer(char**buffer) { nscapi::basic_wrapper_static<plugin_impl_class>::NSDeleteBuffer(buffer); }
84
85#define NSC_WRAPPERS_HANDLE_MSG_DEF() \
86        extern void NSHandleMessage(unsigned int id, const char* request_buffer, unsigned int request_buffer_len) { \
87                nscapi::message_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \
88                return wrapper.NSHandleMessage(request_buffer, request_buffer_len); } \
89        extern NSCAPI::boolReturn NSHasMessageHandler(unsigned int id) { \
90                nscapi::message_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \
91                return wrapper.NSHasMessageHandler(); }
92
93#define NSC_WRAPPERS_HANDLE_CMD_DEF() \
94        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) { \
95                nscapi::command_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \
96                return wrapper.NSHandleCommand(command, request_buffer, request_buffer_len, reply_buffer, reply_buffer_len); } \
97        extern NSCAPI::boolReturn NSHasCommandHandler(unsigned int id) { \
98                nscapi::command_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \
99                return wrapper.NSHasCommandHandler(); }
100
101#define NSC_WRAPPERS_ROUTING_DEF() \
102        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) { \
103                nscapi::routing_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \
104                return wrapper.NSRouteMessage(channel, command, request_buffer, request_buffer_len); } \
105        extern NSCAPI::boolReturn NSHasRoutingHandler(unsigned int id) { \
106                nscapi::routing_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \
107                return wrapper.NSHasRoutingHandler(); }
108
109#define NSC_WRAPPERS_HANDLE_NOTIFICATION_DEF() \
110        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) { \
111                nscapi::submission_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \
112                return wrapper.NSHandleNotification(channel, buffer, buffer_len, response_buffer, response_buffer_len); } \
113        extern NSCAPI::boolReturn NSHasNotificationHandler(unsigned int id) { \
114                nscapi::submission_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \
115                return wrapper.NSHasNotificationHandler(); }
116
117#define NSC_WRAPPERS_CLI_DEF() \
118        extern int NSCommandLineExec(unsigned int id, wchar_t *command, char *request_buffer, unsigned int request_len, char **response_buffer, unsigned int *response_len) { \
119                nscapi::cliexec_wrapper<plugin_impl_class> wrapper(plugin_instance.get(id)); \
120                return wrapper.NSCommandLineExec(command, request_buffer, request_len, response_buffer, response_len); }
121
122#define NSC_WRAPPERS_IGNORE_MSG_DEF() \
123        extern void NSHandleMessage(unsigned int id, const char* data, unsigned int len) {} \
124        extern NSCAPI::boolReturn NSHasMessageHandler(unsigned int id) { return NSCAPI::isfalse; }
125
126#define NSC_WRAPPERS_IGNORE_CMD_DEF() \
127        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; } \
128        extern NSCAPI::boolReturn NSHasCommandHandler(unsigned int id) { return NSCAPI::isfalse; }
129
130#define NSC_WRAPPERS_IGNORE_NOTIFICATION_DEF() \
131        extern int NSHandleNotification(unsigned int id, const wchar_t* channel, const wchar_t* command, const char* result_buffer, unsigned int result_buffer_len) {} \
132        extern NSCAPI::boolReturn NSHasNotificationHandler(unsigned int id) { return NSCAPI::isfalse; }
133
134#define GET_CORE() nscapi::plugin_singleton->get_core()
Note: See TracBrowser for help on using the repository browser.