source: nscp/trunk/NSCPlugin.h @ edbbfbb

Last change on this file since edbbfbb was 9bc31a8, checked in by Michael Medin <michael@…>, 7 years ago

Lots of update (I really should checkin more often :)

  • Property mode set to 100644
File size: 4.8 KB
Line 
1#pragma once
2
3#include <NSCAPI.h>
4#include <NSCHelper.h>
5#include <sstream>
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)
45         * @param sError An error message (human readable format)
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
91        typedef INT (*lpModuleHelperInit)(NSCModuleHelper::lpNSAPILoader f);
92        typedef INT (*lpLoadModule)();
93        typedef INT (*lpGetName)(char*,unsigned int);
94        typedef INT (*lpGetDescription)(char*,unsigned int);
95        typedef INT (*lpGetVersion)(int*,int*,int*);
96        typedef INT (*lpHasCommandHandler)();
97        typedef INT (*lpHasMessageHandler)();
98        typedef NSCAPI::nagiosReturn (*lpHandleCommand)(const char*,const unsigned int, char**,char*,unsigned int,char *,unsigned int);
99        typedef INT (*lpCommandLineExec)(const char*,const unsigned int,char**);
100        typedef INT (*lpHandleMessage)(int,const char*,const int,const char*);
101        typedef INT (*lpUnLoadModule)();
102        typedef INT (*lpGetConfigurationMeta)(int, char*);
103
104
105        lpModuleHelperInit fModuleHelperInit;
106        lpLoadModule fLoadModule;
107        lpGetName fGetName;
108        lpGetVersion fGetVersion;
109        lpGetDescription fGetDescription;
110        lpHasCommandHandler fHasCommandHandler;
111        lpHasMessageHandler fHasMessageHandler;
112        lpHandleCommand fHandleCommand;
113        lpHandleMessage fHandleMessage;
114        lpUnLoadModule fUnLoadModule;
115        lpGetConfigurationMeta fGetConfigurationMeta;
116        lpCommandLineExec fCommandLineExec;
117
118public:
119        NSCPlugin(const std::string file);
120        NSCPlugin(NSCPlugin &other);
121        virtual ~NSCPlugin(void);
122
123        std::string getName(void);
124        std::string getDescription();
125        void load_dll(void);
126        void load_plugin(void);
127        bool getVersion(int *major, int *minor, int *revision);
128        bool hasCommandHandler(void);
129        bool hasMessageHandler(void);
130        NSCAPI::nagiosReturn handleCommand(const char *command, const unsigned int argLen, char **arguments, char* returnMessageBuffer, unsigned int returnMessageBufferLen, char* returnPerfBuffer, unsigned int returnPerfBufferLen);
131        void handleMessage(int msgType, const char* file, const int line, const char *message);
132        void unload(void);
133        std::string getCongifurationMeta();
134        int commandLineExec(const char* command, const unsigned int argLen, char **arguments);
135
136private:
137        bool isLoaded() const {
138                return bLoaded_;
139        }
140        bool getName_(char* buf, unsigned int buflen);
141        bool getDescription_(char* buf, unsigned int buflen);
142        void loadRemoteProcs_(void);
143        bool getConfigurationMeta_(char* buf, unsigned int buflen);
144};
145
146
Note: See TracBrowser for help on using the repository browser.