source: nscp/NSCPlugin.h @ 30bfe74

0.4.00.4.10.4.2stable
Last change on this file since 30bfe74 was 30bfe74, checked in by Michael Medin <michael@…>, 6 years ago

2007-11-12 MickeM

+ Added option to configure socket_timeout (default is now 30 seconds) should (I hope) fix issue #85

2007-11-11 MickeM

+ Added option to configure the behavior of CheckService? CheckAll? (#64)

  • Property mode set to 100644
File size: 6.2 KB
Line 
1/**************************************************************************
2*   Copyright (C) 2004-2007 by Michael Medin <michael@medin.name>         *
3*                                                                         *
4*   This code is part of NSClient++ - http://trac.nakednuns.org/nscp      *
5*                                                                         *
6*   This program is free software; you can redistribute it and/or modify  *
7*   it under the terms of the GNU General Public License as published by  *
8*   the Free Software Foundation; either version 2 of the License, or     *
9*   (at your option) any later version.                                   *
10*                                                                         *
11*   This program is distributed in the hope that it will be useful,       *
12*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14*   GNU General Public License for more details.                          *
15*                                                                         *
16*   You should have received a copy of the GNU General Public License     *
17*   along with this program; if not, write to the                         *
18*   Free Software Foundation, Inc.,                                       *
19*   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
20***************************************************************************/
21#pragma once
22
23#include <NSCAPI.h>
24#include <NSCHelper.h>
25#include <sstream>
26
27/**
28 * @ingroup NSClient++
29 * Exception class for the NSCPlugin class.
30 * When an unexpected error occurs in NSCPlugin this exception is thrown.
31 *
32 * @version 1.0
33 * first version
34 *
35 * @date 02-12-2005
36 *
37 * @author mickem
38 *
39 * @par license
40 * This code is absolutely free to use and modify. The code is provided "as is" with
41 * no expressed or implied warranty. The author accepts no liability if it causes
42 * any damage to your computer, causes your pet to fall ill, increases baldness
43 * or makes your car start emitting strange noises when you start it up.
44 * This code has no bugs, just undocumented features!
45 *
46 * @todo
47 * Add status codes to make error type simpler to parse out.
48 *
49 * @bug
50 *
51 */
52class NSPluginException {
53public:
54        std::string file_;      // DLL filename (for which the exception was thrown)
55        std::string error_;     // An error message (human readable format)
56        /**
57         * @param file DLL filename (for which the exception is thrown)
58         * @param error An error message (human readable format)
59         */
60        NSPluginException(std::string file, std::string error) : file_(file), error_(error) {
61        }
62};
63
64/**
65 * @ingroup NSClient++
66 * NSCPlugin is a wrapper class to wrap all DLL calls and make things simple and clean inside the actual application.<br>
67 * 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).
68 * If things are "broken" NSPluginException is called to indicate this. Error states are returned for normal "conditions".
69 *
70 *
71 * @version 1.0
72 * first version
73 *
74 * @date 02-12-2005
75 *
76 * @author mickem
77 *
78 * @par license
79 * This code is absolutely free to use and modify. The code is provided "as is" with
80 * no expressed or implied warranty. The author accepts no liability if it causes
81 * any damage to your computer, causes your pet to fall ill, increases baldness
82 * or makes your car start emitting strange noises when you start it up.
83 * This code has no bugs, just undocumented features!
84 *
85 * @todo
86 * getVersion() is not implemented as of yet.
87 *
88 * @bug
89 *
90 */
91class NSCPlugin {
92private:
93        bool bLoaded_;                  // Status of plug in
94        HMODULE hModule_;               // module handle to the DLL (once it is loaded)
95        std::string file_;              // Name of the DLL file
96
97        typedef INT (*lpModuleHelperInit)(NSCModuleHelper::lpNSAPILoader f);
98        typedef INT (*lpLoadModule)();
99        typedef INT (*lpGetName)(char*,unsigned int);
100        typedef INT (*lpGetDescription)(char*,unsigned int);
101        typedef INT (*lpGetVersion)(int*,int*,int*);
102        typedef INT (*lpHasCommandHandler)();
103        typedef INT (*lpHasMessageHandler)();
104        typedef NSCAPI::nagiosReturn (*lpHandleCommand)(const char*,const unsigned int, char**,char*,unsigned int,char *,unsigned int);
105        typedef INT (*lpCommandLineExec)(const char*,const unsigned int,char**);
106        typedef INT (*lpHandleMessage)(int,const char*,const int,const char*);
107        typedef INT (*lpUnLoadModule)();
108        typedef INT (*lpGetConfigurationMeta)(int, char*);
109
110
111        lpModuleHelperInit fModuleHelperInit;
112        lpLoadModule fLoadModule;
113        lpGetName fGetName;
114        lpGetVersion fGetVersion;
115        lpGetDescription fGetDescription;
116        lpHasCommandHandler fHasCommandHandler;
117        lpHasMessageHandler fHasMessageHandler;
118        lpHandleCommand fHandleCommand;
119        lpHandleMessage fHandleMessage;
120        lpUnLoadModule fUnLoadModule;
121        lpGetConfigurationMeta fGetConfigurationMeta;
122        lpCommandLineExec fCommandLineExec;
123
124public:
125        NSCPlugin(const std::string file);
126        NSCPlugin(NSCPlugin &other);
127        virtual ~NSCPlugin(void);
128
129        std::string getName(void);
130        std::string getDescription();
131        void load_dll(void);
132        void load_plugin(void);
133        bool getVersion(int *major, int *minor, int *revision);
134        bool hasCommandHandler(void);
135        bool hasMessageHandler(void);
136        NSCAPI::nagiosReturn handleCommand(const char *command, const unsigned int argLen, char **arguments, char* returnMessageBuffer, unsigned int returnMessageBufferLen, char* returnPerfBuffer, unsigned int returnPerfBufferLen);
137        void handleMessage(int msgType, const char* file, const int line, const char *message);
138        void unload(void);
139        std::string getCongifurationMeta();
140        int commandLineExec(const char* command, const unsigned int argLen, char **arguments);
141        std::string getModule() {
142                if (file_.empty())
143                        return "";
144                std::string ret = file_;
145                std::string::size_type pos = ret.find_last_of("\\");
146                if (pos != std::string::npos && ++pos < ret.length()) {
147                        ret = ret.substr(pos);
148                }
149                pos = ret.find_last_of(".");
150                if (pos != std::string::npos) {
151                        ret = ret.substr(0, pos);
152                }
153                return ret;
154        }
155
156private:
157        bool isLoaded() const {
158                return bLoaded_;
159        }
160        bool getName_(char* buf, unsigned int buflen);
161        bool getDescription_(char* buf, unsigned int buflen);
162        void loadRemoteProcs_(void);
163        bool getConfigurationMeta_(char* buf, unsigned int buflen);
164};
165
166
Note: See TracBrowser for help on using the repository browser.