libnetxms changed to unicode
[public/netxms.git] / include / nms_agent.h
1 /*
2 ** NetXMS - Network Management System
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_agent.h
20 **
21 **/
22
23 #ifndef _nms_agent_h_
24 #define _nms_agent_h_
25
26 #include <stdio.h>
27 #include <string.h>
28 #include <nms_common.h>
29 #include <nms_util.h>
30
31
32 //
33 // Some constants
34 //
35
36 #define AGENT_LISTEN_PORT 4700
37 #define AGENT_PROTOCOL_VERSION 2
38 #define MAX_PARAM_NAME 256
39 #define MAX_RESULT_LENGTH 256
40 #define MAX_CMD_LEN 256
41 #define COMMAND_TIMEOUT 60
42 #define MAX_SUBAGENT_NAME 64
43
44
45 //
46 // Error codes
47 //
48
49 #define ERR_SUCCESS ((DWORD)0)
50 #define ERR_UNKNOWN_COMMAND ((DWORD)400)
51 #define ERR_AUTH_REQUIRED ((DWORD)401)
52 #define ERR_UNKNOWN_PARAMETER ((DWORD)404)
53 #define ERR_REQUEST_TIMEOUT ((DWORD)408)
54 #define ERR_AUTH_FAILED ((DWORD)440)
55 #define ERR_ALREADY_AUTHENTICATED ((DWORD)441)
56 #define ERR_AUTH_NOT_REQUIRED ((DWORD)442)
57 #define ERR_INTERNAL_ERROR ((DWORD)500)
58 #define ERR_NOT_IMPLEMENTED ((DWORD)501)
59 #define ERR_OUT_OF_RESOURCES ((DWORD)503)
60 #define ERR_NOT_CONNECTED ((DWORD)900)
61 #define ERR_CONNECTION_BROKEN ((DWORD)901)
62 #define ERR_BAD_RESPONCE ((DWORD)902)
63
64
65 //
66 // Parameter handler return codes
67 //
68
69 #define SYSINFO_RC_SUCCESS 0
70 #define SYSINFO_RC_UNSUPPORTED 1
71 #define SYSINFO_RC_ERROR 2
72
73
74 //
75 // Connection handle
76 //
77
78 typedef void *HCONN;
79
80
81 //
82 // Structure for holding enumeration results
83 //
84
85 typedef struct
86 {
87 DWORD dwNumStrings;
88 TCHAR **ppStringList;
89 } NETXMS_VALUES_LIST;
90
91
92 //
93 // Subagent's parameter information
94 //
95
96 typedef struct
97 {
98 TCHAR szName[MAX_PARAM_NAME];
99 LONG (* fpHandler)(TCHAR *, TCHAR *, TCHAR *);
100 TCHAR *pArg;
101 } NETXMS_SUBAGENT_PARAM;
102
103
104 //
105 // Subagent's enum information
106 //
107
108 typedef struct
109 {
110 TCHAR szName[MAX_PARAM_NAME];
111 LONG (* fpHandler)(TCHAR *, TCHAR *, NETXMS_VALUES_LIST *);
112 TCHAR *pArg;
113 } NETXMS_SUBAGENT_ENUM;
114
115
116 //
117 // Subagent initialization structure
118 //
119
120 typedef struct
121 {
122 TCHAR szName[MAX_SUBAGENT_NAME];
123 DWORD dwVersion;
124 void (* pUnloadHandler)(void); // Called at subagent unload. Can be NULL.
125 DWORD dwNumParameters;
126 NETXMS_SUBAGENT_PARAM *pParamList;
127 DWORD dwNumEnums;
128 NETXMS_SUBAGENT_ENUM *pEnumList;
129 } NETXMS_SUBAGENT_INFO;
130
131
132 //
133 // Inline functions for returning parameters
134 //
135
136 #ifdef __cplusplus
137 #ifndef LIBNETXMS_INLINE
138
139 inline void ret_string(TCHAR *rbuf, TCHAR *value)
140 {
141 _tcsncpy(rbuf, value, MAX_RESULT_LENGTH);
142 }
143
144 inline void ret_int(TCHAR *rbuf, long value)
145 {
146 _stprintf(rbuf, _T("%ld"), value);
147 }
148
149 inline void ret_uint(TCHAR *rbuf, unsigned long value)
150 {
151 _stprintf(rbuf, _T("%lu"), value);
152 }
153
154 inline void ret_double(TCHAR *rbuf, double value)
155 {
156 _stprintf(rbuf, _T("%f"), value);
157 }
158
159 inline void ret_int64(TCHAR *rbuf, INT64 value)
160 {
161 #ifdef _WIN32
162 _stprintf(rbuf, _T("%I64d"), value);
163 #else /* _WIN32 */
164 _stprintf(rbuf, _T("%lld"), value);
165 #endif /* _WIN32 */
166 }
167
168 inline void ret_uint64(TCHAR *rbuf, QWORD value)
169 {
170 #ifdef _WIN32
171 _stprintf(rbuf, _T("%I64u"), value);
172 #else /* _WIN32 */
173 _stprintf(rbuf, _T("%llu"), value);
174 #endif /* _WIN32 */
175 }
176
177 #endif /* LIBNETXMS_INLINE */
178 #else /* __cplusplus */
179
180 void LIBNETXMS_EXPORTABLE ret_string(TCHAR *rbuf, TCHAR *value)
181 void LIBNETXMS_EXPORTABLE ret_int(TCHAR *rbuf, long value)
182 void LIBNETXMS_EXPORTABLE ret_uint(TCHAR *rbuf, unsigned long value)
183 void LIBNETXMS_EXPORTABLE ret_double(TCHAR *rbuf, double value)
184 void LIBNETXMS_EXPORTABLE ret_int64(TCHAR *rbuf, INT64 value)
185 void LIBNETXMS_EXPORTABLE ret_uint64(TCHAR *rbuf, QWORD value)
186
187 #endif /* __cplusplus */
188
189
190 //
191 // Functions from libnetxms
192 //
193
194 #ifdef __cplusplus
195 extern "C" {
196 #endif
197
198 BOOL LIBNETXMS_EXPORTABLE NxGetParameterArg(TCHAR *param, int index, TCHAR *arg, int maxSize);
199 void LIBNETXMS_EXPORTABLE NxAddResultString(NETXMS_VALUES_LIST *pList, TCHAR *pszString);
200
201 #ifdef __cplusplus
202 }
203 #endif
204
205 #endif /* _nms_agent_h_ */