Function AddObjectToIndex() changed: now it add new element at the end and use qsort...
[public/netxms.git] / include / nms_util.h
CommitLineData
e9246d26 1/*
7ac71e60 2** NetXMS - Network Management System
e9246d26
VK
3** Copyright (C) 2003 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** $module: nms_util.h
20**
21**/
22
23#ifndef _nms_util_h_
24#define _nms_util_h_
25
26#include <nms_common.h>
27#include <nms_cscp.h>
5fad5c32 28#include <nms_threads.h>
e9246d26 29
f44f6a97
VK
30#define INVALID_INDEX 0xFFFFFFFF
31
e9246d26
VK
32
33//
34// Class for holding CSCP messages
35//
36
37class EXPORTABLE CSCPMessage
38{
39private:
40 WORD m_wCode;
41 DWORD m_dwId;
42 DWORD m_dwNumVar; // Number of variables
43 CSCP_DF **m_ppVarList; // List of variables
44
45 void Set(char *szName, BYTE bType, void *pValue);
46 void *Get(char *szName, BYTE bType);
47 DWORD FindVariable(char *szName);
48
49public:
50 CSCPMessage();
51 CSCPMessage(CSCP_MESSAGE *pMsg);
52 ~CSCPMessage();
53
54 CSCP_MESSAGE *CreateMessage(void);
55
56 WORD GetCode(void) { return m_wCode; }
57 void SetCode(WORD wCode) { m_wCode = wCode; }
58
59 DWORD GetId(void) { return m_dwId; }
60 void SetId(DWORD dwId) { m_dwId = dwId; }
61
f44f6a97
VK
62 BOOL IsVariableExist(char *szName) { return (FindVariable(szName) != INVALID_INDEX) ? TRUE : FALSE; }
63
5358362f 64 void SetVariable(char *szName, WORD wValue) { Set(szName, DT_INT16, &wValue); }
e9246d26
VK
65 void SetVariable(char *szName, DWORD dwValue) { Set(szName, DT_INTEGER, &dwValue); }
66 void SetVariable(char *szName, QWORD qwValue) { Set(szName, DT_INT64, &qwValue); }
67 void SetVariable(char *szName, char *szValue) { Set(szName, DT_STRING, szValue); }
68
69 DWORD GetVariableLong(char *szName);
70 QWORD GetVariableInt64(char *szName);
5358362f 71 WORD GetVariableShort(char *szName);
e9246d26 72 char *GetVariableStr(char *szName);
b5972f5d
VK
73
74 void DeleteAllVariables(void);
e9246d26
VK
75};
76
77
5fad5c32
VK
78//
79// Queue class
80//
81
82class EXPORTABLE Queue
83{
84private:
85 MUTEX m_hQueueAccess;
86 CONDITION m_hConditionNotEmpty;
87 void **m_pElements;
88 DWORD m_dwNumElements;
89 DWORD m_dwBufferSize;
90 DWORD m_dwFirst;
91 DWORD m_dwLast;
92 DWORD m_dwBufferIncrement;
93
94 void Lock(void) { MutexLock(m_hQueueAccess, INFINITE); }
95 void Unlock(void) { MutexUnlock(m_hQueueAccess); }
96
97public:
98 Queue(DWORD dwInitialSize = 256, DWORD dwBufferIncrement = 32);
99 ~Queue();
100
101 void Put(void *pObject);
102 void *Get(void);
103 void *GetOrBlock(void);
104 DWORD Size(void) { return m_dwNumElements; }
105};
106
107
e9246d26
VK
108//
109// Functions
110//
111
43d92b4c
VK
112
113#if __BYTE_ORDER == __LITTLE_ENDIAN
114#define htonq(x) __bswap_64(x)
115#define ntohq(x) __bswap_64(x)
116#else
117#define htonq(x) (x)
118#define ntohq(x) (x)
119#endif
15929b31 120
e9246d26
VK
121extern "C"
122{
123 void EXPORTABLE LibUtilDestroyObject(void *pObject);
43d92b4c 124 QWORD __bswap_64(QWORD qwVal);
e9246d26
VK
125}
126
127#endif /* _nms_util_h_ */