Commit | Line | Data |
---|---|---|
4fe83ebd | 1 | /* |
605fc935 | 2 | ** NetXMS - Network Management System |
b0608204 | 3 | ** Copyright (C) 2003-2013 Victor Kirhenshtein |
605fc935 VK |
4 | ** |
5 | ** This program is free software; you can redistribute it and/or modify | |
6 | ** it under the terms of the GNU Lesser General Public License as published by | |
7 | ** the Free Software Foundation; either version 3 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 Lesser 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 | ** File: appagent.h | |
20 | ** | |
21 | **/ | |
22 | ||
23 | #ifndef _appagent_h_ | |
24 | #define _appagent_h_ | |
25 | ||
26 | #ifdef _WIN32 | |
27 | #ifdef APPAGENT_EXPORTS | |
28 | #define APPAGENT_EXPORTABLE __declspec(dllexport) | |
29 | #else | |
30 | #define APPAGENT_EXPORTABLE __declspec(dllimport) | |
31 | #endif | |
32 | #else /* _WIN32 */ | |
33 | #define APPAGENT_EXPORTABLE | |
34 | #endif | |
35 | ||
36 | #include <nms_common.h> | |
37 | #include <nms_util.h> | |
38 | ||
39 | #ifdef _WIN32 | |
40 | #include <aclapi.h> | |
41 | #else | |
42 | #include <sys/socket.h> | |
43 | #include <sys/un.h> | |
44 | #endif | |
45 | ||
46 | #ifndef SUN_LEN | |
47 | #define SUN_LEN(su) (sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path)) | |
48 | #endif | |
49 | ||
50 | #ifdef _WIN32 | |
51 | #define HPIPE HANDLE | |
52 | #define INVALID_PIPE_HANDLE INVALID_HANDLE_VALUE | |
53 | #else | |
54 | #define HPIPE int | |
55 | #define INVALID_PIPE_HANDLE (-1) | |
56 | #endif | |
57 | ||
58 | /** | |
59 | * Message constants | |
60 | */ | |
61 | #define APPAGENT_MSG_START_INDICATOR "APPAGENT" | |
62 | #define APPAGENT_MSG_START_INDICATOR_LEN 8 | |
63 | #define APPAGENT_MSG_SIZE_FIELD_LEN 2 | |
64 | #define APPAGENT_MSG_HEADER_LEN 16 | |
65 | ||
66 | /** | |
67 | * Command codes | |
68 | */ | |
69 | #define APPAGENT_CMD_GET_METRIC 0x0001 | |
70 | #define APPAGENT_CMD_LIST_METRICS 0x0002 | |
71 | #define APPAGENT_CMD_REQUEST_COMPLETED 0x0003 | |
72 | ||
73 | /** | |
74 | * Request completion codes | |
75 | */ | |
76 | #define APPAGENT_RCC_SUCCESS 0 | |
77 | #define APPAGENT_RCC_NO_SUCH_METRIC 1 | |
78 | #define APPAGENT_RCC_NO_SUCH_INSTANCE 2 | |
79 | #define APPAGENT_RCC_METRIC_READ_ERROR 3 | |
80 | #define APPAGENT_RCC_COMM_FAILURE 4 | |
81 | #define APPAGENT_RCC_BAD_REQUEST 5 | |
82 | ||
83 | /** | |
84 | * Communication message structure | |
85 | */ | |
86 | ||
87 | #ifdef __HP_aCC | |
88 | #pragma pack 1 | |
89 | #else | |
90 | #pragma pack(1) | |
91 | #endif | |
92 | ||
93 | typedef struct __apagent_msg | |
94 | { | |
95 | char prefix[APPAGENT_MSG_START_INDICATOR_LEN]; | |
96 | WORD length; // message length including prefix and length field | |
97 | WORD command; // command code | |
98 | WORD rcc; // request completion code | |
99 | BYTE padding[2]; | |
100 | BYTE payload[1]; // actual payload size determined by message length | |
101 | } APPAGENT_MSG; | |
102 | ||
103 | #ifdef __HP_aCC | |
104 | #pragma pack | |
105 | #else | |
106 | #pragma pack() | |
107 | #endif | |
108 | ||
b0608204 VK |
109 | #ifdef __cplusplus |
110 | extern "C" { | |
111 | #endif | |
112 | ||
605fc935 VK |
113 | /** |
114 | * Application agent metric definition | |
115 | */ | |
116 | typedef struct __appagent_metric | |
117 | { | |
118 | const TCHAR *name; | |
119 | const TCHAR *userArg; | |
120 | int (*handler)(const TCHAR *, const TCHAR *, TCHAR *); | |
121 | int type; | |
122 | const TCHAR *description; | |
123 | } APPAGENT_METRIC; | |
124 | ||
125 | /** | |
18c575eb VK |
126 | * Application agent list definition |
127 | */ | |
128 | typedef struct __appagent_list | |
129 | { | |
130 | const TCHAR *name; | |
131 | const TCHAR *userArg; | |
132 | int (*handler)(const TCHAR *, const TCHAR *, StringList *); | |
133 | const TCHAR *description; | |
134 | } APPAGENT_LIST; | |
135 | ||
136 | /** | |
137 | * Application agent table definition | |
138 | */ | |
139 | typedef struct __appagent_table | |
140 | { | |
141 | const TCHAR *name; | |
142 | const TCHAR *userArg; | |
143 | int (*handler)(const TCHAR *, const TCHAR *, Table *); | |
144 | const TCHAR *instanceColumns; | |
145 | const TCHAR *description; | |
146 | } APPAGENT_TABLE; | |
147 | ||
148 | /** | |
605fc935 VK |
149 | * Agent initialization structure |
150 | */ | |
151 | typedef struct __appagent_init | |
152 | { | |
153 | const TCHAR *name; | |
154 | const TCHAR *userId; | |
155 | void (*messageDispatcher)(APPAGENT_MSG *); | |
156 | void (*logger)(int, const TCHAR *, va_list); | |
157 | int numMetrics; | |
158 | APPAGENT_METRIC *metrics; | |
18c575eb VK |
159 | int numLists; |
160 | APPAGENT_LIST *lists; | |
161 | int numTables; | |
162 | APPAGENT_LIST *tables; | |
605fc935 VK |
163 | } APPAGENT_INIT; |
164 | ||
165 | /** | |
166 | * Application-side API | |
167 | */ | |
168 | bool APPAGENT_EXPORTABLE AppAgentInit(APPAGENT_INIT *initData); | |
169 | void APPAGENT_EXPORTABLE AppAgentStart(); | |
170 | void APPAGENT_EXPORTABLE AppAgentStop(); | |
18c575eb | 171 | void APPAGENT_EXPORTABLE AppAgentPostEvent(int code, const TCHAR *name, const char *format, ...); |
605fc935 | 172 | |
3460cec3 VK |
173 | bool APPAGENT_EXPORTABLE AppAgentGetParameterArgA(const TCHAR *param, int index, char *arg, int maxSize); |
174 | bool APPAGENT_EXPORTABLE AppAgentGetParameterArgW(const TCHAR *param, int index, WCHAR *arg, int maxSize); | |
175 | #ifdef UNICODE | |
176 | #define AppAgentGetParameterArg AppAgentGetParameterArgW | |
177 | #else | |
178 | #define AppAgentGetParameterArg AppAgentGetParameterArgA | |
179 | #endif | |
180 | ||
605fc935 VK |
181 | /** |
182 | * Client-side API | |
183 | */ | |
184 | bool APPAGENT_EXPORTABLE AppAgentConnect(const TCHAR *name, HPIPE *hPipe); | |
185 | void APPAGENT_EXPORTABLE AppAgentDisconnect(HPIPE hPipe); | |
186 | int APPAGENT_EXPORTABLE AppAgentGetMetric(HPIPE hPipe, const TCHAR *name, TCHAR *value, int bufferSize); | |
83b20bab | 187 | int APPAGENT_EXPORTABLE AppAgentListMetrics(HPIPE hPipe, APPAGENT_METRIC **metrics, UINT32 *size); |
605fc935 | 188 | |
b0608204 VK |
189 | #ifdef __cplusplus |
190 | } | |
191 | #endif | |
192 | ||
605fc935 | 193 | #endif |