license changed to LGPL for libnxcl, libnxsnmp, libnxlp, libnxsl, and libnxmap
[public/netxms.git] / src / libnxcl / graph.cpp
1 /*
2 ** NetXMS - Network Management System
3 ** Client Library
4 ** Copyright (C) 2003-2010 Victor Kirhenshtein
5 **
6 ** This program is free software; you can redistribute it and/or modify
7 ** it under the terms of the GNU Lesser General Public License as published by
8 ** the Free Software Foundation; either version 3 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 Lesser 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 ** File: graph.cpp
21 **
22 **/
23
24 #include "libnxcl.h"
25
26
27 //
28 // Get list of configured graphs
29 //
30
31 DWORD LIBNXCL_EXPORTABLE NXCGetGraphList(NXC_SESSION hSession, DWORD *pdwNumGraphs, NXC_GRAPH **ppGraphList)
32 {
33 DWORD i, j, dwId, dwRqId, dwResult;
34 CSCPMessage msg, *pResponse;
35
36 dwRqId = ((NXCL_Session *)hSession)->CreateRqId();
37
38 msg.SetCode(CMD_GET_GRAPH_LIST);
39 msg.SetId(dwRqId);
40 ((NXCL_Session *)hSession)->SendMsg(&msg);
41
42 *pdwNumGraphs = 0;
43 *ppGraphList = NULL;
44
45 pResponse = ((NXCL_Session *)hSession)->WaitForMessage(CMD_REQUEST_COMPLETED, dwRqId);
46 if (pResponse != NULL)
47 {
48 dwResult = pResponse->GetVariableLong(VID_RCC);
49 if (dwResult == RCC_SUCCESS)
50 {
51 *pdwNumGraphs = pResponse->GetVariableLong(VID_NUM_GRAPHS);
52 if (*pdwNumGraphs > 0)
53 {
54 *ppGraphList = (NXC_GRAPH *)malloc(sizeof(NXC_GRAPH) * (*pdwNumGraphs));
55 memset(*ppGraphList, 0, sizeof(NXC_GRAPH) * (*pdwNumGraphs));
56 for(i = 0, dwId = VID_GRAPH_LIST_BASE; i < *pdwNumGraphs; i++)
57 {
58 (*ppGraphList)[i].dwId = pResponse->GetVariableLong(dwId++);
59 (*ppGraphList)[i].dwOwner = pResponse->GetVariableLong(dwId++);
60 (*ppGraphList)[i].pszName = pResponse->GetVariableStr(dwId++);
61 (*ppGraphList)[i].pszConfig = pResponse->GetVariableStr(dwId++);
62 (*ppGraphList)[i].dwAclSize = pResponse->GetVariableLong(dwId++);
63 if ((*ppGraphList)[i].dwAclSize > 0)
64 {
65 DWORD *pdwData;
66
67 (*ppGraphList)[i].pACL = (NXC_GRAPH_ACL_ENTRY *)malloc(sizeof(NXC_GRAPH_ACL_ENTRY) * (*ppGraphList)[i].dwAclSize);
68 pdwData = (DWORD *)malloc(sizeof(DWORD) * (*ppGraphList)[i].dwAclSize * 2);
69 pResponse->GetVariableInt32Array(dwId++, (*ppGraphList)[i].dwAclSize, pdwData);
70 pResponse->GetVariableInt32Array(dwId++, (*ppGraphList)[i].dwAclSize, pdwData + (*ppGraphList)[i].dwAclSize);
71 for(j = 0; j < (*ppGraphList)[i].dwAclSize; j++)
72 {
73 (*ppGraphList)[i].pACL[j].dwUserId = pdwData[j];
74 (*ppGraphList)[i].pACL[j].dwAccess = pdwData[j + (*ppGraphList)[i].dwAclSize];
75 }
76 free(pdwData);
77 }
78 else
79 {
80 dwId += 2;
81 }
82 dwId += 3;
83 }
84 }
85 }
86 delete pResponse;
87 }
88 else
89 {
90 dwResult = RCC_TIMEOUT;
91 }
92 return dwResult;
93 }
94
95
96 //
97 // Destroy graph list
98 //
99
100 void LIBNXCL_EXPORTABLE NXCDestroyGraphList(DWORD dwNumGraphs, NXC_GRAPH *pList)
101 {
102 DWORD i;
103
104 for(i = 0; i < dwNumGraphs; i++)
105 {
106 safe_free(pList[i].pACL);
107 safe_free(pList[i].pszConfig);
108 safe_free(pList[i].pszName);
109 }
110 safe_free(pList);
111 }
112
113
114 //
115 // Delete graph
116 //
117
118 DWORD LIBNXCL_EXPORTABLE NXCDeleteGraph(NXC_SESSION hSession, DWORD dwGraphId)
119 {
120 DWORD dwRqId;
121 CSCPMessage msg;
122
123 dwRqId = ((NXCL_Session *)hSession)->CreateRqId();
124
125 msg.SetCode(CMD_DELETE_GRAPH);
126 msg.SetId(dwRqId);
127 msg.SetVariable(VID_GRAPH_ID, dwGraphId);
128 ((NXCL_Session *)hSession)->SendMsg(&msg);
129
130 return ((NXCL_Session *)hSession)->WaitForRCC(dwRqId);
131 }
132
133
134 //
135 // Define graph
136 //
137
138 DWORD LIBNXCL_EXPORTABLE NXCDefineGraph(NXC_SESSION hSession, NXC_GRAPH *pGraph)
139 {
140 DWORD i, dwId, dwRqId;
141 CSCPMessage msg;
142
143 dwRqId = ((NXCL_Session *)hSession)->CreateRqId();
144
145 msg.SetCode(CMD_DEFINE_GRAPH);
146 msg.SetId(dwRqId);
147 msg.SetVariable(VID_GRAPH_ID, pGraph->dwId);
148 msg.SetVariable(VID_NAME, pGraph->pszName);
149 msg.SetVariable(VID_GRAPH_CONFIG, pGraph->pszConfig);
150 msg.SetVariable(VID_ACL_SIZE, pGraph->dwAclSize);
151 for(i = 0, dwId = VID_GRAPH_ACL_BASE; i < pGraph->dwAclSize; i++)
152 {
153 msg.SetVariable(dwId++, pGraph->pACL[i].dwUserId);
154 msg.SetVariable(dwId++, pGraph->pACL[i].dwAccess);
155 }
156 ((NXCL_Session *)hSession)->SendMsg(&msg);
157
158 return ((NXCL_Session *)hSession)->WaitForRCC(dwRqId);
159 }