source: nscp/NSCPlugin.h @ 75d5e70

0.4.00.4.10.4.2stable
Last change on this file since 75d5e70 was e26cfe0, checked in by Michael Medin <michael@…>, 8 years ago

changes all over manily in the checking code

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