source: nscp/NSClient++.h @ 36c340d

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

Multiple fixes in various places.

  • Added threadding blocks "core"
  • Added new Module (CheckDisk)
  • Added new option [log] / debug=1 to enable debug logs.
  • Added more error messages
  • other minor tweaks and fixes
  • Property mode set to 100644
File size: 3.9 KB
Line 
1#pragma once
2
3#include "resource.h"
4#include <ServiceCmd.h>
5#include <NTService.h>
6#include "NSCPlugin.h"
7#include "TCPSocketResponder.h"
8#include <Mutex.h>
9#include <NSCAPI.h>
10
11
12/**
13 * @ingroup NSClient++
14 * Main NSClient++ core class. This is the service core and as such is responsible for pretty much everything.
15 * It also acts as a broker for all plugins and other sub threads and such.
16 *
17 * @version 1.0
18 * first version
19 *
20 * @date 02-12-2005
21 *
22 * @author mickem
23 *
24 * @par license
25 * This code is absolutely free to use and modify. The code is provided "as is" with
26 * no expressed or implied warranty. The author accepts no liability if it causes
27 * any damage to your computer, causes your pet to fall ill, increases baldness
28 * or makes your car start emitting strange noises when you start it up.
29 * This code has no bugs, just undocumented features!
30 *
31 * @todo Plugininfy the socket somehow ?
32 * It is technically possible to make the socket a plug-in but would it be a good idea ?
33 *
34 * @bug
35 *
36 */
37class NSClientT {
38private:
39        typedef NSCPlugin* plugin_type;
40        typedef std::list<plugin_type> pluginList;
41        pluginList plugins_;
42        pluginList commandHandlers_;
43        pluginList messageHandlers_;
44        TCPSocketResponderThread socketThread;
45        std::string basePath;
46        MutexHandler pluginMutex;
47        MutexHandler messageMutex;
48
49public:
50        // c-tor, d-tor
51        NSClientT(void) {}
52        virtual ~NSClientT(void) {}
53
54        // Service helper functions
55        void InitiateService(void);
56        void TerminateService(void);
57        static void WINAPI service_main_dispatch(DWORD dwArgc, LPTSTR *lpszArgv);
58        static void WINAPI service_ctrl_dispatch(DWORD dwCtrlCode);
59
60        // Member functions
61        static std::string getPassword(void);
62        std::string getBasePath(void);
63        std::string inject(const std::string buffer);
64        std::string execute(std::string password, std::string cmd, std::list<std::string> args);
65        void reportMessage(int msgType, const char* file, const int line, std::string message);
66
67        void loadPlugins(const std::list<std::string> plugins);
68        void loadPlugin(const std::string plugin);
69        void loadPlugins(void);
70        void unloadPlugins(void);
71
72private:
73        void addPlugin(plugin_type plugin);
74
75};
76
77typedef NTService<NSClientT> NSClient;
78
79//////////////////////////////////////////////////////////////////////////
80// Various NSAPI callback functions (available for plug-ins to make calls back to the core.
81// <b>NOTICE</b> No threading is allowed so technically every thread is responsible for marshaling things back.
82// Though I think this is not the case at the moment.
83//
84
85LPVOID NSAPILoader(char*buffer);
86int NSAPIGetApplicationName(char*buffer, unsigned int bufLen);
87int NSAPIGetBasePath(char*buffer, unsigned int bufLen);
88int NSAPIGetApplicationVersionStr(char*buffer, unsigned int bufLen);
89int NSAPIGetSettingsString(const char* section, const char* key, const char* defaultValue, char* buffer, unsigned int bufLen);
90int NSAPIGetSettingsInt(const char* section, const char* key, int defaultValue);
91void NSAPIMessage(int msgType, const char* file, const int line, const char* message);
92void NSAPIStopServer(void);
93int NSAPIInject(const char* command, char* buffer, unsigned int bufLen);
94
95//////////////////////////////////////////////////////////////////////////
96// Log macros to simplify logging
97// Generally names are of the form LOG_<severity>[_STD]
98// Where _STD indicates that strings are force wrapped inside a std::string
99//
100#define LOG_ERROR_STD(msg) LOG_ERROR(((std::string)msg).c_str())
101#define LOG_ERROR(msg) \
102        NSAPIMessage(NSCAPI::error, __FILE__, __LINE__, msg)
103#define LOG_CRITICAL_STD(msg) LOG_CRITICAL(((std::string)msg).c_str())
104#define LOG_CRITICAL(msg) \
105        NSAPIMessage(NSCAPI::critical, __FILE__, __LINE__, msg)
106#define LOG_MESSAGE_STD(msg) LOG_MESSAGE(((std::string)msg).c_str())
107#define LOG_MESSAGE(msg) \
108        NSAPIMessage(NSCAPI::log, __FILE__, __LINE__, msg)
109#define LOG_DEBUG_STD(msg) LOG_DEBUG(((std::string)msg).c_str())
110#define LOG_DEBUG(msg) \
111        NSAPIMessage(NSCAPI::debug, __FILE__, __LINE__, msg)
Note: See TracBrowser for help on using the repository browser.