| 1 | #pragma once |
|---|
| 2 | |
|---|
| 3 | #include <NSCAPI.h> |
|---|
| 4 | #include <NSCHelper.h> |
|---|
| 5 | |
|---|
| 6 | /** |
|---|
| 7 | * @ingroup NSClient++ |
|---|
| 8 | * Exception class for the NSCPlugin class. |
|---|
| 9 | * When an unexpected error occurs in NSCPlugin this exception is thrown. |
|---|
| 10 | * |
|---|
| 11 | * @version 1.0 |
|---|
| 12 | * first version |
|---|
| 13 | * |
|---|
| 14 | * @date 02-12-2005 |
|---|
| 15 | * |
|---|
| 16 | * @author mickem |
|---|
| 17 | * |
|---|
| 18 | * @par license |
|---|
| 19 | * This code is absolutely free to use and modify. The code is provided "as is" with |
|---|
| 20 | * no expressed or implied warranty. The author accepts no liability if it causes |
|---|
| 21 | * any damage to your computer, causes your pet to fall ill, increases baldness |
|---|
| 22 | * or makes your car start emitting strange noises when you start it up. |
|---|
| 23 | * This code has no bugs, just undocumented features! |
|---|
| 24 | * |
|---|
| 25 | * @todo |
|---|
| 26 | * Add status codes to make error type simpler to parse out. |
|---|
| 27 | * |
|---|
| 28 | * @bug |
|---|
| 29 | * |
|---|
| 30 | */ |
|---|
| 31 | class NSPluginException { |
|---|
| 32 | public: |
|---|
| 33 | std::string file_; // DLL filename (for which the exception was thrown) |
|---|
| 34 | std::string error_; // An error message (human readable format) |
|---|
| 35 | /** |
|---|
| 36 | * @param file DLL filename (for which the exception is thrown) |
|---|
| 37 | * @param error An error message (human readable format) |
|---|
| 38 | */ |
|---|
| 39 | NSPluginException(std::string file, std::string error) : file_(file), error_(error) { |
|---|
| 40 | } |
|---|
| 41 | /** |
|---|
| 42 | * |
|---|
| 43 | * @param file DLL filename (for which the exception is thrown) |
|---|
| 44 | * @param error An error message (human readable format) |
|---|
| 45 | * @param nError Error code to be appended at the end of the string |
|---|
| 46 | * @todo Change this to be some form of standard error code and merge with above. |
|---|
| 47 | */ |
|---|
| 48 | NSPluginException(std::string file, std::string sError, int nError) : file_(file) { |
|---|
| 49 | std::stringstream s; |
|---|
| 50 | s << sError; |
|---|
| 51 | s << nError; |
|---|
| 52 | error_ = s.str(); |
|---|
| 53 | |
|---|
| 54 | } |
|---|
| 55 | }; |
|---|
| 56 | |
|---|
| 57 | /** |
|---|
| 58 | * @ingroup NSClient++ |
|---|
| 59 | * NSCPlugin is a wrapper class to wrap all DLL calls and make things simple and clean inside the actual application.<br> |
|---|
| 60 | * Things tend to be one-to-one by which I mean that a call to a function here should call the corresponding function in the plug in (if loaded). |
|---|
| 61 | * If things are "broken" NSPluginException is called to indicate this. Error states are returned for normal "conditions". |
|---|
| 62 | * |
|---|
| 63 | * |
|---|
| 64 | * @version 1.0 |
|---|
| 65 | * first version |
|---|
| 66 | * |
|---|
| 67 | * @date 02-12-2005 |
|---|
| 68 | * |
|---|
| 69 | * @author mickem |
|---|
| 70 | * |
|---|
| 71 | * @par license |
|---|
| 72 | * This code is absolutely free to use and modify. The code is provided "as is" with |
|---|
| 73 | * no expressed or implied warranty. The author accepts no liability if it causes |
|---|
| 74 | * any damage to your computer, causes your pet to fall ill, increases baldness |
|---|
| 75 | * or makes your car start emitting strange noises when you start it up. |
|---|
| 76 | * This code has no bugs, just undocumented features! |
|---|
| 77 | * |
|---|
| 78 | * @todo |
|---|
| 79 | * getVersion() is not implemented as of yet. |
|---|
| 80 | * |
|---|
| 81 | * @bug |
|---|
| 82 | * |
|---|
| 83 | */ |
|---|
| 84 | class NSCPlugin { |
|---|
| 85 | private: |
|---|
| 86 | bool bLoaded_; // Status of plug in |
|---|
| 87 | HMODULE hModule_; // module handle to the DLL (once it is loaded) |
|---|
| 88 | std::string file_; // Name of the DLL file |
|---|
| 89 | |
|---|
| 90 | typedef int (*lpModuleHelperInit)(NSCModuleHelper::lpNSAPILoader f); |
|---|
| 91 | typedef int (*lpLoadModule)(); |
|---|
| 92 | typedef INT (*lpGetName)(char*,unsigned int); |
|---|
| 93 | typedef INT (*lpHasCommandHandler)(); |
|---|
| 94 | typedef INT (*lpHasMessageHandler)(); |
|---|
| 95 | typedef NSCAPI::nagiosReturn (*lpHandleCommand)(const char*,const unsigned int, char**,char*,unsigned int,char *,unsigned int); |
|---|
| 96 | typedef INT (*lpHandleMessage)(int,const char*,const int,const char*); |
|---|
| 97 | typedef int (*lpUnLoadModule)(); |
|---|
| 98 | |
|---|
| 99 | lpModuleHelperInit fModuleHelperInit; |
|---|
| 100 | lpLoadModule fLoadModule; |
|---|
| 101 | lpGetName fGetName; |
|---|
| 102 | lpHasCommandHandler fHasCommandHandler; |
|---|
| 103 | lpHasMessageHandler fHasMessageHandler; |
|---|
| 104 | lpHandleCommand fHandleCommand; |
|---|
| 105 | lpHandleMessage fHandleMessage; |
|---|
| 106 | lpUnLoadModule fUnLoadModule; |
|---|
| 107 | |
|---|
| 108 | public: |
|---|
| 109 | NSCPlugin(const std::string file); |
|---|
| 110 | virtual ~NSCPlugin(void); |
|---|
| 111 | |
|---|
| 112 | std::string getName(void); |
|---|
| 113 | void load(void); |
|---|
| 114 | bool getVersion(int *major, int *minor, int *revision); |
|---|
| 115 | bool hasCommandHandler(void); |
|---|
| 116 | bool hasMessageHandler(void); |
|---|
| 117 | NSCAPI::nagiosReturn handleCommand(const char *command, const unsigned int argLen, char **arguments, char* returnMessageBuffer, unsigned int returnMessageBufferLen, char* returnPerfBuffer, unsigned int returnPerfBufferLen); |
|---|
| 118 | void handleMessage(int msgType, const char* file, const int line, const char *message); |
|---|
| 119 | void unload(void); |
|---|
| 120 | |
|---|
| 121 | private: |
|---|
| 122 | bool isLoaded() const { |
|---|
| 123 | return bLoaded_; |
|---|
| 124 | } |
|---|
| 125 | bool getName_(char* buf, unsigned int buflen); |
|---|
| 126 | void loadRemoteProcs_(void); |
|---|
| 127 | }; |
|---|
| 128 | |
|---|
| 129 | |
|---|