embeddable application agent - initial version
[public/netxms.git] / include / appagent.h
CommitLineData
605fc935
VK
1/*
2** NetXMS - Network Management System
3** Copyright (C) 2003-2012 Victor Kirhenshtein
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
93typedef 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
109/**
110 * Application agent metric definition
111 */
112typedef struct __appagent_metric
113{
114 const TCHAR *name;
115 const TCHAR *userArg;
116 int (*handler)(const TCHAR *, const TCHAR *, TCHAR *);
117 int type;
118 const TCHAR *description;
119} APPAGENT_METRIC;
120
121/**
122 * Agent initialization structure
123 */
124typedef struct __appagent_init
125{
126 const TCHAR *name;
127 const TCHAR *userId;
128 void (*messageDispatcher)(APPAGENT_MSG *);
129 void (*logger)(int, const TCHAR *, va_list);
130 int numMetrics;
131 APPAGENT_METRIC *metrics;
132} APPAGENT_INIT;
133
134/**
135 * Application-side API
136 */
137bool APPAGENT_EXPORTABLE AppAgentInit(APPAGENT_INIT *initData);
138void APPAGENT_EXPORTABLE AppAgentStart();
139void APPAGENT_EXPORTABLE AppAgentStop();
140
141/**
142 * Client-side API
143 */
144bool APPAGENT_EXPORTABLE AppAgentConnect(const TCHAR *name, HPIPE *hPipe);
145void APPAGENT_EXPORTABLE AppAgentDisconnect(HPIPE hPipe);
146int APPAGENT_EXPORTABLE AppAgentGetMetric(HPIPE hPipe, const TCHAR *name, TCHAR *value, int bufferSize);
147
148#endif