- Version number changed to 0.2.2-dev
[public/netxms.git] / include / nxcscpapi.h
CommitLineData
0d9c1b96
VK
1/*
2** NetXMS - Network Management System
3** CSCP API Library
4** Copyright (C) 2003, 2004 Victor Kirhenshtein
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 Free Software
18** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19**
20** $module: nxcscpapi.h
21**
22**/
23
24#ifndef _nxcscpapi_h_
25#define _nxcscpapi_h_
26
b50f1100
VK
27#include <nms_threads.h>
28
0d9c1b96
VK
29
30#ifdef _WIN32
31#ifdef LIBNXCSCP_EXPORTS
32#define LIBNXCSCP_EXPORTABLE __declspec(dllexport)
33#else
34#define LIBNXCSCP_EXPORTABLE __declspec(dllimport)
35#endif
36#else /* _WIN32 */
37#define LIBNXCSCP_EXPORTABLE
38#endif
39
40
41//
8c290af0
VK
42// Encryption methods
43//
44
45#define CSCP_ENCRYPTION_NONE 0
46#define CSCP_ENCRYPTION_BLOWFISH_SHA1 1
47
48
49//
0d9c1b96
VK
50// Temporary buffer structure for RecvCSCPMessage() function
51//
52
53typedef struct
54{
55 DWORD dwBufSize;
56 DWORD dwBufPos;
57 char szBuffer[CSCP_TEMP_BUF_SIZE];
58} CSCP_BUFFER;
59
60
61//
62// Class for holding CSCP messages
63//
64
65class LIBNXCSCP_EXPORTABLE CSCPMessage
66{
67private:
68 WORD m_wCode;
69 DWORD m_dwId;
70 DWORD m_dwNumVar; // Number of variables
71 CSCP_DF **m_ppVarList; // List of variables
72
a7d07192 73 void *Set(DWORD dwVarId, BYTE bType, void *pValue, DWORD dwSize = 0);
0d9c1b96
VK
74 void *Get(DWORD dwVarId, BYTE bType);
75 DWORD FindVariable(DWORD dwVarId);
76
77public:
78 CSCPMessage();
79 CSCPMessage(CSCP_MESSAGE *pMsg);
80 ~CSCPMessage();
81
82 CSCP_MESSAGE *CreateMessage(void);
83
84 WORD GetCode(void) { return m_wCode; }
85 void SetCode(WORD wCode) { m_wCode = wCode; }
86
87 DWORD GetId(void) { return m_dwId; }
88 void SetId(DWORD dwId) { m_dwId = dwId; }
89
90 BOOL IsVariableExist(DWORD dwVarId) { return (FindVariable(dwVarId) != INVALID_INDEX) ? TRUE : FALSE; }
91
42d7ed00
VK
92 void SetVariable(DWORD dwVarId, WORD wValue) { Set(dwVarId, CSCP_DT_INT16, &wValue); }
93 void SetVariable(DWORD dwVarId, DWORD dwValue) { Set(dwVarId, CSCP_DT_INTEGER, &dwValue); }
94 void SetVariable(DWORD dwVarId, QWORD qwValue) { Set(dwVarId, CSCP_DT_INT64, &qwValue); }
95 void SetVariable(DWORD dwVarId, double dValue) { Set(dwVarId, CSCP_DT_FLOAT, &dValue); }
4332e9d8 96 void SetVariable(DWORD dwVarId, TCHAR *szValue) { Set(dwVarId, CSCP_DT_STRING, szValue); }
42d7ed00 97 void SetVariable(DWORD dwVarId, BYTE *pValue, DWORD dwSize) { Set(dwVarId, CSCP_DT_BINARY, pValue, dwSize); }
a7d07192 98 void SetVariableToInt32Array(DWORD dwVarId, DWORD dwNumElements, DWORD *pdwData);
0d9c1b96
VK
99
100 DWORD GetVariableLong(DWORD dwVarId);
101 QWORD GetVariableInt64(DWORD dwVarId);
102 WORD GetVariableShort(DWORD dwVarId);
f86ffdd2 103 double GetVariableDouble(DWORD dwVarId);
4332e9d8 104 TCHAR *GetVariableStr(DWORD dwVarId, TCHAR *szBuffer = NULL, DWORD dwBufSize = 0);
0d9c1b96 105 DWORD GetVariableBinary(DWORD dwVarId, BYTE *pBuffer, DWORD dwBufSize);
a7d07192 106 DWORD GetVariableInt32Array(DWORD dwVarId, DWORD dwNumElements, DWORD *pdwBuffer);
0d9c1b96
VK
107
108 void DeleteAllVariables(void);
109};
110
111
112//
deaa4491
VK
113// Message waiting queue element structure
114//
115
116typedef struct
117{
118 WORD wCode; // Message code
119 WORD wIsBinary; // 1 for binary (raw) messages
120 DWORD dwId; // Message ID
121 DWORD dwTTL; // Message time-to-live in milliseconds
122 void *pMsg; // Pointer to message, either to CSCPMessage object or raw message
123} WAIT_QUEUE_ELEMENT;
124
125
126//
127// Message waiting queue class
128//
129
130class LIBNXCSCP_EXPORTABLE MsgWaitQueue
131{
deaa4491 132private:
cea97623 133 MUTEX m_hMutexDataAccess;
deaa4491
VK
134 CONDITION m_hStopCondition;
135 DWORD m_dwMsgHoldTime;
136 DWORD m_dwNumElements;
137 WAIT_QUEUE_ELEMENT *m_pElements;
cea97623 138 BOOL m_bIsRunning;
ccdbbb52 139 THREAD m_hHkThread;
deaa4491 140
cea97623
VK
141 void Lock(void) { MutexLock(m_hMutexDataAccess, INFINITE); }
142 void Unlock(void) { MutexUnlock(m_hMutexDataAccess); }
deaa4491
VK
143 void HousekeeperThread(void);
144 void *WaitForMessageInternal(WORD wIsBinary, WORD wCode, DWORD dwId, DWORD dwTimeOut);
1ba9a162 145
ccdbbb52 146 static THREAD_RESULT THREAD_CALL MWQThreadStarter(void *);
deaa4491
VK
147
148public:
149 MsgWaitQueue();
150 ~MsgWaitQueue();
151
152 void Put(CSCPMessage *pMsg);
153 void Put(CSCP_MESSAGE *pMsg);
154 CSCPMessage *WaitForMessage(WORD wCode, DWORD dwId, DWORD dwTimeOut)
155 {
156 return (CSCPMessage *)WaitForMessageInternal(0, wCode, dwId, dwTimeOut);
157 }
158 CSCP_MESSAGE *WaitForRawMessage(WORD wCode, DWORD dwId, DWORD dwTimeOut)
159 {
160 return (CSCP_MESSAGE *)WaitForMessageInternal(1, wCode, dwId, dwTimeOut);
161 }
162
163 void Clear(void);
164 void SetHoldTime(DWORD dwHoldTime) { m_dwMsgHoldTime = dwHoldTime; }
165};
166
167
168//
0d9c1b96
VK
169// Functions
170//
171
172#ifdef __cplusplus
173extern "C" {
174#endif
175
4c20673b
VK
176int LIBNXCSCP_EXPORTABLE RecvCSCPMessage(SOCKET hSocket, CSCP_MESSAGE *pMsg,
177 CSCP_BUFFER *pBuffer, DWORD dwMaxMsgSize);
b9b4ec17
VK
178CSCP_MESSAGE LIBNXCSCP_EXPORTABLE *CreateRawCSCPMessage(WORD wCode, DWORD dwId,
179 DWORD dwDataSize, void *pData,
0d9c1b96 180 CSCP_MESSAGE *pBuffer);
4332e9d8 181TCHAR LIBNXCSCP_EXPORTABLE *CSCPMessageCodeName(WORD wCode, TCHAR *pszBuffer);
d096bcdd 182BOOL LIBNXCSCP_EXPORTABLE SendFileOverCSCP(SOCKET hSocket, DWORD dwId, TCHAR *pszFile);
0d9c1b96 183
15cf5acc
VK
184BOOL LIBNXCSCP_EXPORTABLE InitCryptoLib(void);
185
0d9c1b96
VK
186#ifdef __cplusplus
187}
188#endif
189
190#endif /* _nxcscpapi_h_ */