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