new C++ client library included in UNIX build
[public/netxms.git] / include / nxclient.h
CommitLineData
bf6fb6c3
VK
1/*
2** NetXMS - Network Management System
3** Client Library API
4** Copyright (C) 2003-2014 Victor Kirhenshtein
5**
6** This program is free software; you can redistribute it and/or modify
7** it under the terms of the GNU Lesser General Public License as published by
8** the Free Software Foundation; either version 3 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 Lesser General Public License
17** along with this program; if not, write to the Free Software
18** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19**
20** File: nxclient.h
21**
22**/
23
24#ifndef _nxclient_h_
25#define _nxclient_h_
26
27#include <nms_common.h>
28#include <nms_util.h>
29#include <nxevent.h>
30#include <nxcpapi.h>
31#include <nxtools.h>
32#include <nxlog.h>
33#include <uuid.h>
34#include <nxcldefs.h>
35
36#ifdef _WIN32
37#ifdef LIBNXCLIENT_EXPORTS
38#define LIBNXCLIENT_EXPORTABLE __declspec(dllexport)
39#else
40#define LIBNXCLIENT_EXPORTABLE __declspec(dllimport)
41#endif
42#else /* _WIN32 */
43#define LIBNXCLIENT_EXPORTABLE
44#endif
45
46#define MAX_TZ_LEN 32
47
48/**
49 * NXCSession::connect flags
50 */
51#define NXCF_DEFAULT 0
52#define NXCF_ENCRYPT 0x0001
53#define NXCF_EXACT_VERSION_MATCH 0x0002
54#define NXCF_USE_CERTIFICATE 0x0004
55#define NXCF_IGNORE_PROTOCOL_VERSION 0x0008
56
57/**
58 * Standard controller names
59 */
60#define CONTROLLER_ALARMS _T("ALARMS")
61#define CONTROLLER_DATA_COLLECTION _T("DATACOLL")
62#define CONTROLLER_EVENTS _T("EVENTS")
63#define CONTROLLER_OBJECTS _T("OBJECTS")
64
65/**
66 * DCI push data
67 */
68struct NXCPushData
69{
70 UINT32 dciId; // DCI ID or 0 if name is used
71 TCHAR *dciName;
72 UINT32 nodeId; // Node ID or 0 if name is used
73 TCHAR *nodeName;
74 TCHAR *value;
75};
76
77/**
78 * Debug callback
79 */
80typedef void (* NXC_DEBUG_CALLBACK)(const TCHAR *msg);
81
82class NXCSession;
83
84/**
85 * Abstract controller class
86 */
87class LIBNXCLIENT_EXPORTABLE Controller
88{
89protected:
90 NXCSession *m_session;
91
92public:
93 Controller(NXCSession *session) { m_session = session; }
94};
95
96/**
97 * Alarm controller
98 */
99class LIBNXCLIENT_EXPORTABLE AlarmController : public Controller
100{
101public:
102 AlarmController(NXCSession *session) : Controller(session) { }
103
104 UINT32 acknowledge(UINT32 alarmId, bool sticky = false);
105 UINT32 resolve(UINT32 alarmId);
106 UINT32 terminate(UINT32 alarmId);
107 ObjectArray<NXC_ALARM> *get();
108};
109
110/**
111 * Data collection controller
112 */
113class LIBNXCLIENT_EXPORTABLE DataCollectionController : public Controller
114{
115public:
116 DataCollectionController(NXCSession *session) : Controller(session) { }
117
118 UINT32 pushData(ObjectArray<NXCPushData> *data, UINT32 *failedIndex = NULL);
119};
120
121/**
122 * Event controller
123 */
124class LIBNXCLIENT_EXPORTABLE EventController : public Controller
125{
126public:
127 EventController(NXCSession *session) : Controller(session) { }
128};
129
130/**
131 * Object controller
132 */
133class LIBNXCLIENT_EXPORTABLE ObjectController : public Controller
134{
135public:
136 ObjectController(NXCSession *session) : Controller(session) { }
137
138 UINT32 manage(UINT32 objectId);
139 UINT32 unmanage(UINT32 objectId);
140};
141
142/**
143 * Session
144 */
145class LIBNXCLIENT_EXPORTABLE NXCSession
146{
147private:
148 THREAD m_receiverThread;
149
150 static THREAD_RESULT THREAD_CALL receiverThreadStarter(void *arg);
151 void receiverThread();
152
153protected:
154 // communications
155 bool m_connected;
156 bool m_disconnected;
157 VolatileCounter m_msgId;
158 SOCKET m_hSocket;
159 MsgWaitQueue *m_msgWaitQueue;
160 NXCPEncryptionContext *m_encryptionContext;
161 UINT32 m_commandTimeout;
162
163 // server information
164 BYTE m_serverId[8];
165 TCHAR m_serverVersion[64];
166 TCHAR m_serverTimeZone[MAX_TZ_LEN];
167 UINT32 m_userId;
168 UINT64 m_systemRights;
169 bool m_passwordChangeNeeded;
170
171 // data
172 MUTEX m_dataLock;
173 MUTEX m_msgSendLock;
174 StringObjectMap<Controller> *m_controllers;
175
176 void onNotify(NXCPMessage *msg);
177
178public:
179 NXCSession();
180 virtual ~NXCSession();
181
182 UINT32 connect(const TCHAR *host, const TCHAR *login, const TCHAR *password, UINT32 flags = NXCF_DEFAULT, const TCHAR *clientInfo = NULL);
183 void disconnect();
184
185 UINT32 createMessageId() { return InterlockedIncrement(&m_msgId); }
186 bool sendMessage(NXCPMessage *msg);
187 NXCPMessage *waitForMessage(UINT16 code, UINT32 id, UINT32 timeout = 0);
188 UINT32 waitForRCC(UINT32 id, UINT32 timeout = 0);
189
190 void setCommandTimeout(UINT32 timeout) { m_commandTimeout = timeout; }
191 UINT32 getCommandTimeout() { return m_commandTimeout; }
192
193 const TCHAR *getServerVersion() { return m_serverVersion; }
194 const TCHAR *getServerTimeZone() { return m_serverTimeZone; }
195 UINT32 getUserId() { return m_userId; }
196 UINT64 getSystemRights() { return m_systemRights; }
197 bool isPasswordChangeNeeded() { return m_passwordChangeNeeded; }
198
199 Controller *getController(const TCHAR *name);
200};
201
202/**
203 * Functions
204 */
205UINT32 LIBNXCLIENT_EXPORTABLE NXCGetVersion();
206const TCHAR LIBNXCLIENT_EXPORTABLE *NXCGetErrorText(UINT32 rcc);
207
208bool LIBNXCLIENT_EXPORTABLE NXCInitialize();
209void LIBNXCLIENT_EXPORTABLE NXCShutdown();
210void LIBNXCLIENT_EXPORTABLE NXCSetDebugCallback(NXC_DEBUG_CALLBACK cb);
211
212#endif /* _nxclient_h_ */