all pollers converted to single thread pool
[public/netxms.git] / src / server / include / nxmodule.h
1 /*
2 ** NetXMS - Network Management System
3 ** Copyright (C) 2003-2013 Victor Kirhenshtein
4 **
5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation; either version 2 of the License, or
8 ** (at your option) any later version.
9 **
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ** GNU General Public License for more details.
14 **
15 ** You should have received a copy of the GNU General Public License
16 ** along with this program; if not, write to the Free Software
17 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 **
19 ** File: nxmodule.h
20 **
21 **/
22
23 #ifndef _nxmodule_h_
24 #define _nxmodule_h_
25
26 #include <nxdbapi.h>
27
28 /**
29 * Forward declaration of server classes
30 */
31 class ClientSession;
32 class MobileDeviceSession;
33 class Node;
34 class Event;
35 class NetObj;
36 class PollerInfo;
37 class NXSL_Environment;
38 struct NXCORE_LOG;
39
40 /**
41 * Command handler return codes
42 */
43 #define NXMOD_COMMAND_IGNORED -1
44 #define NXMOD_COMMAND_PROCESSED 0
45 #define NXMOD_COMMAND_ACCEPTED_ASYNC 1
46
47 /**
48 * Module-specific object data
49 */
50 class NXCORE_EXPORTABLE ModuleData
51 {
52 public:
53 ModuleData();
54 virtual ~ModuleData();
55
56 virtual void fillMessage(NXCPMessage *msg, UINT32 baseId);
57 virtual bool saveToDatabase(DB_HANDLE hdb, UINT32 objectId);
58 virtual bool deleteFromDatabase(DB_HANDLE hdb, UINT32 objectId);
59 };
60
61 /**
62 * Module registration structure
63 */
64 typedef struct
65 {
66 UINT32 dwSize; // Size of structure in bytes
67 TCHAR szName[MAX_OBJECT_NAME];
68 void (* pfServerStarted)();
69 void (* pfShutdown)();
70 void (* pfLoadObjects)();
71 void (* pfLinkObjects)();
72 int (* pfClientCommandHandler)(UINT32 dwCommand, NXCPMessage *pMsg, ClientSession *pSession);
73 int (* pfMobileDeviceCommandHandler)(UINT32 dwCommand, NXCPMessage *pMsg, MobileDeviceSession *pSession);
74 BOOL (* pfTrapHandler)(SNMP_PDU *pdu, Node *pNode);
75 BOOL (* pfEventHandler)(Event *event);
76 void (* pfAlarmChangeHook)(UINT32 changeCode, NXC_ALARM *alarm);
77 void (* pfStatusPollHook)(Node *node, ClientSession *session, UINT32 rqId, PollerInfo *poller);
78 bool (* pfConfPollHook)(Node *node, ClientSession *session, UINT32 rqId, PollerInfo *poller);
79 void (* pfTopologyPollHook)(Node *node, ClientSession *session, UINT32 rqId, PollerInfo *poller);
80 int (* pfCalculateObjectStatus)(NetObj *object);
81 BOOL (* pfNetObjInsert)(NetObj *object);
82 BOOL (* pfNetObjDelete)(NetObj *object);
83 void (* pfPostObjectCreate)(NetObj *object);
84 void (* pfPostObjectLoad)(NetObj *object);
85 void (* pfPreObjectDelete)(NetObj *object);
86 NetObj *(* pfCreateObject)(int objectClass, const TCHAR *name, NetObj *parent, NXCPMessage *msg);
87 BOOL (* pfIsValidParentClass)(int childClass, int parentClass);
88 BOOL (* pfAcceptNewNode)(const InetAddress& addr, UINT32 zoneId, BYTE *macAddr);
89 UINT32 (* pfValidateObjectCreation)(int objectClass, const TCHAR *name, const InetAddress& ipAddr, UINT32 zoneId, NXCPMessage *request);
90 UINT32 (* pfAdditionalLoginCheck)(UINT32 userId, NXCPMessage *request);
91 void (* pfClientSessionClose)(ClientSession *session);
92 void (* pfNXSLServerEnvConfig)(NXSL_Environment *env);
93 void (* pfOnConnectToAgent)(Node *node, AgentConnection *conn);
94 BOOL (* pfOnAgentMessage)(NXCPMessage *msg, UINT32 nodeId);
95 NXCORE_LOG *logs;
96 HMODULE hModule;
97 } NXMODULE;
98
99 /**
100 * Enumerate all modules where given entry point available
101 */
102 #define ENUMERATE_MODULES(e) if (!(g_flags & AF_SHUTDOWN)) \
103 for(UINT32 __i = 0; __i < g_dwNumModules; __i++) \
104 if (g_pModuleList[__i]. e != NULL)
105
106 /**
107 * Call module entry point for all loaded modules
108 */
109 #define CALL_ALL_MODULES(e, p) if (!(g_flags & AF_SHUTDOWN)) { \
110 for(UINT32 __i = 0; __i < g_dwNumModules; __i++) { \
111 if (g_pModuleList[__i]. e != NULL) { g_pModuleList[__i]. e p; } \
112 } \
113 }
114
115 /**
116 * Functions
117 */
118 bool LoadNetXMSModules();
119
120 /**
121 * Global variables
122 */
123 extern UINT32 g_dwNumModules;
124 extern NXMODULE *g_pModuleList;
125
126 #endif /* _nxmodule_h_ */