| 1 | #pragma once |
|---|
| 2 | |
|---|
| 3 | #include <string> |
|---|
| 4 | #include <list> |
|---|
| 5 | #include <NSCAPI.h> |
|---|
| 6 | |
|---|
| 7 | namespace NSCHelper |
|---|
| 8 | { |
|---|
| 9 | int wrapReturnString(char *buffer, unsigned int bufLen, std::string str, int defaultReturnCode = NSCAPI::success); |
|---|
| 10 | std::list<std::string> makelist(const unsigned int argLen, char **argument); |
|---|
| 11 | std::string translateMessageType(NSCAPI::messageTypes msgType); |
|---|
| 12 | }; |
|---|
| 13 | |
|---|
| 14 | namespace NSCModuleHelper |
|---|
| 15 | { |
|---|
| 16 | // Types for the Callbacks into the main program |
|---|
| 17 | typedef int (*lpNSAPIGetBasePath)(char*,unsigned int); |
|---|
| 18 | typedef int (*lpNSAPIGetApplicationName)(char*,unsigned int); |
|---|
| 19 | typedef int (*lpNSAPIGetApplicationVersionStr)(char*,unsigned int); |
|---|
| 20 | typedef int (*lpNSAPIGetSettingsString)(const char*,const char*,const char*,char*,unsigned int); |
|---|
| 21 | typedef int (*lpNSAPIGetSettingsInt)(const char*, const char*, int); |
|---|
| 22 | typedef void (*lpNSAPIMessage)(int, const char*, const int, const char*); |
|---|
| 23 | typedef int (*lpNSAPIStopServer)(void); |
|---|
| 24 | typedef int (*lpNSAPIInject)(const char*,char*,unsigned int); |
|---|
| 25 | typedef LPVOID (*lpNSAPILoader)(char*); |
|---|
| 26 | |
|---|
| 27 | // Helper functions for calling into the core |
|---|
| 28 | std::string getApplicationName(void); |
|---|
| 29 | std::string getApplicationVersionString(void); |
|---|
| 30 | std::string getSettingsString(std::string section, std::string key, std::string defaultValue); |
|---|
| 31 | int getSettingsInt(std::string section, std::string key, int defaultValue); |
|---|
| 32 | void Message(int msgType, std::string file, int line, std::string message); |
|---|
| 33 | std::string InjectCommand(std::string command); |
|---|
| 34 | void StopService(void); |
|---|
| 35 | std::string getBasePath(); |
|---|
| 36 | }; |
|---|
| 37 | |
|---|
| 38 | namespace NSCModuleWrapper { |
|---|
| 39 | struct module_version { |
|---|
| 40 | int major; |
|---|
| 41 | int minor; |
|---|
| 42 | int revision; |
|---|
| 43 | }; |
|---|
| 44 | |
|---|
| 45 | BOOL wrapDllMain(HANDLE hModule, DWORD ul_reason_for_call); |
|---|
| 46 | HINSTANCE getModule(); |
|---|
| 47 | |
|---|
| 48 | int wrapModuleHelperInit(NSCModuleHelper::lpNSAPILoader f);; |
|---|
| 49 | int wrapGetModuleName(char* buf, unsigned int buflen, std::string str); |
|---|
| 50 | int wrapLoadModule(bool success); |
|---|
| 51 | int wrapGetModuleVersion(int *major, int *minor, int *revision, module_version version); |
|---|
| 52 | int wrapHasCommandHandler(bool has); |
|---|
| 53 | int wrapHasMessageHandler(bool has); |
|---|
| 54 | int wrapUnloadModule(bool success); |
|---|
| 55 | int wrapHandleCommand(const std::string retStr, char *returnBuffer, unsigned int returnBufferLen); |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | ////////////////////////////////////////////////////////////////////////// |
|---|
| 59 | // Module wrappers (definitions) |
|---|
| 60 | #define NSC_WRAPPERS_MAIN() \ |
|---|
| 61 | extern "C" int NSModuleHelperInit(NSCModuleHelper::lpNSAPILoader f); \ |
|---|
| 62 | extern int NSLoadModule(); \ |
|---|
| 63 | extern int NSGetModuleName(char* buf, int buflen); \ |
|---|
| 64 | extern int NSGetModuleVersion(int *major, int *minor, int *revision); \ |
|---|
| 65 | extern int NSHasCommandHandler(); \ |
|---|
| 66 | extern int NSHasMessageHandler(); \ |
|---|
| 67 | extern void NSHandleMessage(int msgType, char* file, int line, char* message); \ |
|---|
| 68 | extern int NSHandleCommand(const char* command, const unsigned int argLen, char **argument, char *returnBuffer, unsigned int returnBufferLen); \ |
|---|
| 69 | extern int NSUnloadModule(); |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | #define NSC_LOG_ERROR_STD(msg) NSC_LOG_ERROR(((std::string)msg).c_str()) |
|---|
| 74 | #define NSC_LOG_ERROR(msg) \ |
|---|
| 75 | NSCModuleHelper::Message(NSCAPI::error, __FILE__, __LINE__, msg) |
|---|
| 76 | |
|---|
| 77 | #define NSC_LOG_CRITICAL_STD(msg) NSC_LOG_CRITICAL(((std::string)msg).c_str()) |
|---|
| 78 | #define NSC_LOG_CRITICAL(msg) \ |
|---|
| 79 | NSCModuleHelper::Message(NSCAPI::critical, __FILE__, __LINE__, msg) |
|---|
| 80 | |
|---|
| 81 | #define NSC_LOG_MESSAGE_STD(msg) NSC_LOG_MESSAGE(((std::string)msg).c_str()) |
|---|
| 82 | #define NSC_LOG_MESSAGE(msg) \ |
|---|
| 83 | NSCModuleHelper::Message(NSCAPI::log, __FILE__, __LINE__, msg) |
|---|
| 84 | |
|---|
| 85 | #ifdef _DEBUG |
|---|
| 86 | #define NSC_DEBUG_MSG_STD(msg) NSC_DEBUG_MSG(((std::string)msg).c_str()) |
|---|
| 87 | #define NSC_DEBUG_MSG(msg) \ |
|---|
| 88 | NSCModuleHelper::Message(NSCAPI::debug, __FILE__, __LINE__, msg) |
|---|
| 89 | #else |
|---|
| 90 | #define NSC_DEBUG_MSG_STD(msg) |
|---|
| 91 | #define NSC_DEBUG_MSG(msg) |
|---|
| 92 | #endif |
|---|
| 93 | |
|---|
| 94 | ////////////////////////////////////////////////////////////////////////// |
|---|
| 95 | // Message wrappers below this point |
|---|
| 96 | |
|---|
| 97 | #define NSC_WRAPPERS_MAIN_DEF(toObject) \ |
|---|
| 98 | extern int NSModuleHelperInit(NSCModuleHelper::lpNSAPILoader f) { \ |
|---|
| 99 | return NSCModuleWrapper::wrapModuleHelperInit(f); \ |
|---|
| 100 | } \ |
|---|
| 101 | extern int NSLoadModule() { \ |
|---|
| 102 | return NSCModuleWrapper::wrapLoadModule(toObject.loadModule()); \ |
|---|
| 103 | } \ |
|---|
| 104 | extern int NSGetModuleName(char* buf, int buflen) { \ |
|---|
| 105 | return NSCModuleWrapper::wrapGetModuleName(buf, buflen, toObject.getModuleName()); \ |
|---|
| 106 | } \ |
|---|
| 107 | extern int NSGetModuleVersion(int *major, int *minor, int *revision) { \ |
|---|
| 108 | return NSCModuleWrapper::wrapGetModuleVersion(major, minor, revision, toObject.getModuleVersion()); \ |
|---|
| 109 | } \ |
|---|
| 110 | extern int NSHasCommandHandler() { \ |
|---|
| 111 | return NSCModuleWrapper::wrapHasCommandHandler(toObject.hasCommandHandler()); \ |
|---|
| 112 | } \ |
|---|
| 113 | extern int NSHasMessageHandler() { \ |
|---|
| 114 | return NSCModuleWrapper::wrapHasMessageHandler(toObject.hasMessageHandler()); \ |
|---|
| 115 | } \ |
|---|
| 116 | extern int NSUnloadModule() { \ |
|---|
| 117 | return NSCModuleWrapper::wrapUnloadModule(toObject.unloadModule()); \ |
|---|
| 118 | } |
|---|
| 119 | #define NSC_WRAPPERS_HANDLE_MSG_DEF(toObject) \ |
|---|
| 120 | extern void NSHandleMessage(int msgType, char* file, int line, char* message) { \ |
|---|
| 121 | toObject.handleMessage(msgType, file, line, message); \ |
|---|
| 122 | } |
|---|
| 123 | #define NSC_WRAPPERS_IGNORE_MSG_DEF() \ |
|---|
| 124 | extern void NSHandleMessage(int msgType, char* file, int line, char* message) { \ |
|---|
| 125 | } |
|---|
| 126 | #define NSC_WRAPPERS_HANDLE_CMD_DEF(toObject) \ |
|---|
| 127 | extern int NSHandleCommand(const char* command, const unsigned int argLen, char **argument, char *returnBuffer, unsigned int returnBufferLen) { \ |
|---|
| 128 | return NSCModuleWrapper::wrapHandleCommand(toObject.handleCommand(command, argLen, argument), returnBuffer, returnBufferLen); \ |
|---|
| 129 | } |
|---|
| 130 | #define NSC_WRAPPERS_IGNORE_CMD_DEF() \ |
|---|
| 131 | extern int NSHandleCommand(const char* command, const unsigned int argLen, char **argument, char *returnBuffer, unsigned int returnBufferLen) { \ |
|---|
| 132 | return NSCAPI::failed; \ |
|---|
| 133 | } |
|---|
| 134 | #define NSC_LOG_DEBUG(str) \ |
|---|
| 135 | NSCHelper::DebugMessage(__FILE__, __LINE__, str); |
|---|