2 ** NetXMS - Network Management System
4 ** Copyright (C) 2006-2009 Victor Kirhenshtein
6 ** This program is free software; you can redistribute it and/or modify
7 ** it under the terms of the GNU General Public License as published by
8 ** the Free Software Foundation; either version 2 of the License, or
9 ** (at your option) any later version.
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.
16 ** You should have received a copy of the GNU 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.
25 #include <netxms_maps.h>
32 DWORD LIBNXCL_EXPORTABLE
NXCGetMapList(NXC_SESSION hSession
, DWORD
*pdwNumMaps
,
33 NXC_MAP_INFO
**ppMapList
)
35 CSCPMessage msg
, *pResponse
;
36 DWORD i
, dwRqId
, dwResult
, dwId
;
38 dwRqId
= ((NXCL_Session
*)hSession
)->CreateRqId();
40 msg
.SetCode(CMD_GET_MAP_LIST
);
42 ((NXCL_Session
*)hSession
)->SendMsg(&msg
);
44 pResponse
= ((NXCL_Session
*)hSession
)->WaitForMessage(CMD_REQUEST_COMPLETED
, dwRqId
);
45 if (pResponse
!= NULL
)
47 dwResult
= pResponse
->GetVariableLong(VID_RCC
);
48 if (dwResult
== RCC_SUCCESS
)
50 *pdwNumMaps
= pResponse
->GetVariableLong(VID_NUM_MAPS
);
51 *ppMapList
= (NXC_MAP_INFO
*)malloc(sizeof(NXC_MAP_INFO
) * (*pdwNumMaps
));
52 for(i
= 0, dwId
= VID_MAP_LIST_BASE
; i
< *pdwNumMaps
; i
++)
54 (*ppMapList
)[i
].dwMapId
= pResponse
->GetVariableLong(dwId
++);
55 (*ppMapList
)[i
].dwObjectId
= pResponse
->GetVariableLong(dwId
++);
56 (*ppMapList
)[i
].dwAccess
= pResponse
->GetVariableLong(dwId
++);
57 pResponse
->GetVariableStr(dwId
++, (*ppMapList
)[i
].szName
, MAX_DB_STRING
);
58 dwId
+= 6; // Reserved ids for future use
65 dwResult
= RCC_TIMEOUT
;
75 DWORD LIBNXCL_EXPORTABLE
NXCSaveMap(NXC_SESSION hSession
, void *pMap
)
79 DWORD i
, dwRqId
, dwResult
;
81 dwRqId
= ((NXCL_Session
*)hSession
)->CreateRqId();
82 ((nxMap
*)pMap
)->Lock();
84 msg
.SetCode(CMD_SAVE_MAP
);
86 ((nxMap
*)pMap
)->CreateMessage(&msg
);
87 ((NXCL_Session
*)hSession
)->SendMsg(&msg
);
89 // Wait for initial confirmation
90 dwResult
= ((NXCL_Session
*)hSession
)->WaitForRCC(dwRqId
);
92 // If OK, send all submaps to server
93 if (dwResult
== RCC_SUCCESS
)
95 msg
.SetCode(CMD_SUBMAP_DATA
);
96 for(i
= 0; i
< ((nxMap
*)pMap
)->GetSubmapCount(); i
++)
98 msg
.DeleteAllVariables();
99 pSubmap
= ((nxMap
*)pMap
)->GetSubmapByIndex(i
);
101 pSubmap
->CreateMessage(&msg
);
102 if (i
== ((nxMap
*)pMap
)->GetSubmapCount() - 1)
103 msg
.SetEndOfSequence();
104 ((NXCL_Session
*)hSession
)->SendMsg(&msg
);
107 // Wait for second confirmation
108 dwResult
= ((NXCL_Session
*)hSession
)->WaitForRCC(dwRqId
);
111 ((nxMap
*)pMap
)->Unlock();
120 DWORD LIBNXCL_EXPORTABLE
NXCLoadMap(NXC_SESSION hSession
, DWORD dwMapId
, void **ppMap
)
124 CSCPMessage msg
, *pResponse
;
125 DWORD dwRqId
, dwResult
, dwId
;
127 dwRqId
= ((NXCL_Session
*)hSession
)->CreateRqId();
129 msg
.SetCode(CMD_LOAD_MAP
);
131 msg
.SetVariable(VID_MAP_ID
, dwMapId
);
132 ((NXCL_Session
*)hSession
)->SendMsg(&msg
);
134 pResponse
= ((NXCL_Session
*)hSession
)->WaitForMessage(CMD_REQUEST_COMPLETED
, dwRqId
);
135 if (pResponse
!= NULL
)
137 dwResult
= pResponse
->GetVariableLong(VID_RCC
);
138 if (dwResult
== RCC_SUCCESS
)
140 pMap
= new nxMap(pResponse
);
141 if (pResponse
->GetVariableLong(VID_NUM_SUBMAPS
) > 0)
146 pResponse
= ((NXCL_Session
*)hSession
)->WaitForMessage(CMD_SUBMAP_DATA
, dwRqId
);
147 if (pResponse
!= NULL
)
149 dwResult
= pResponse
->GetVariableLong(VID_RCC
);
150 if (dwResult
== RCC_SUCCESS
)
152 dwId
= pResponse
->GetVariableLong(VID_OBJECT_ID
);
153 pSubmap
= pMap
->GetSubmap(dwId
);
154 pSubmap
->ModifyFromMessage(pResponse
);
159 dwResult
= RCC_TIMEOUT
;
162 } while((dwResult
== RCC_SUCCESS
) && (!pResponse
->IsEndOfSequence()));
163 if (dwResult
== RCC_SUCCESS
)
181 dwResult
= RCC_TIMEOUT
;
191 DWORD LIBNXCL_EXPORTABLE
NXCDeleteMap(NXC_SESSION hSession
, DWORD dwMapId
)
196 dwRqId
= ((NXCL_Session
*)hSession
)->CreateRqId();
198 msg
.SetCode(CMD_DELETE_MAP
);
200 msg
.SetVariable(VID_MAP_ID
, dwMapId
);
201 ((NXCL_Session
*)hSession
)->SendMsg(&msg
);
203 return ((NXCL_Session
*)hSession
)->WaitForRCC(dwRqId
);
211 DWORD LIBNXCL_EXPORTABLE
NXCRenameMap(NXC_SESSION hSession
, DWORD dwMapId
, const TCHAR
*pszName
)
216 dwRqId
= ((NXCL_Session
*)hSession
)->CreateRqId();
218 msg
.SetCode(CMD_RENAME_MAP
);
220 msg
.SetVariable(VID_MAP_ID
, dwMapId
);
221 msg
.SetVariable(VID_NAME
, pszName
);
222 ((NXCL_Session
*)hSession
)->SendMsg(&msg
);
224 return ((NXCL_Session
*)hSession
)->WaitForRCC(dwRqId
);
229 // Resolve map name to id
232 DWORD LIBNXCL_EXPORTABLE
NXCResolveMapName(NXC_SESSION hSession
, TCHAR
*pszMapName
,
235 CSCPMessage msg
, *pResponse
;
236 DWORD dwRqId
, dwResult
;
238 dwRqId
= ((NXCL_Session
*)hSession
)->CreateRqId();
240 msg
.SetCode(CMD_RESOLVE_MAP_NAME
);
242 msg
.SetVariable(VID_NAME
, pszMapName
);
243 ((NXCL_Session
*)hSession
)->SendMsg(&msg
);
245 pResponse
= ((NXCL_Session
*)hSession
)->WaitForMessage(CMD_REQUEST_COMPLETED
, dwRqId
);
246 if (pResponse
!= NULL
)
248 dwResult
= pResponse
->GetVariableLong(VID_RCC
);
249 if (dwResult
== RCC_SUCCESS
)
251 *pdwMapId
= pResponse
->GetVariableLong(VID_MAP_ID
);
257 dwResult
= RCC_TIMEOUT
;
264 // Upload background image to server
267 DWORD LIBNXCL_EXPORTABLE
NXCUploadSubmapBkImage(NXC_SESSION hSession
, DWORD dwMapId
,
268 DWORD dwSubmapId
, TCHAR
*pszFile
)
271 DWORD dwRqId
, dwResult
;
273 dwRqId
= ((NXCL_Session
*)hSession
)->CreateRqId();
275 msg
.SetCode(CMD_UPLOAD_SUBMAP_BK_IMAGE
);
277 msg
.SetVariable(VID_MAP_ID
, dwMapId
);
278 msg
.SetVariable(VID_OBJECT_ID
, dwSubmapId
);
279 ((NXCL_Session
*)hSession
)->SendMsg(&msg
);
281 dwResult
= ((NXCL_Session
*)hSession
)->WaitForRCC(dwRqId
);
282 if (dwResult
== RCC_SUCCESS
)
284 dwResult
= ((NXCL_Session
*)hSession
)->SendFile(dwRqId
, pszFile
);
285 if (dwResult
== RCC_SUCCESS
)
287 // Wait for final confirmation
288 dwResult
= ((NXCL_Session
*)hSession
)->WaitForRCC(dwRqId
);
296 // Retrieve background image from server
299 DWORD LIBNXCL_EXPORTABLE
NXCDownloadSubmapBkImage(NXC_SESSION hSession
, DWORD dwMapId
,
300 DWORD dwSubmapId
, TCHAR
*pszFile
)
303 DWORD dwRqId
, dwResult
;
305 dwRqId
= ((NXCL_Session
*)hSession
)->CreateRqId();
306 dwResult
= ((NXCL_Session
*)hSession
)->PrepareFileTransfer(pszFile
, dwRqId
);
307 if (dwResult
== RCC_SUCCESS
)
309 msg
.SetCode(CMD_GET_SUBMAP_BK_IMAGE
);
311 msg
.SetVariable(VID_MAP_ID
, dwMapId
);
312 msg
.SetVariable(VID_OBJECT_ID
, dwSubmapId
);
313 ((NXCL_Session
*)hSession
)->SendMsg(&msg
);
315 // Loading file may take time, so timeout is 300 sec. instead of default
316 dwResult
= ((NXCL_Session
*)hSession
)->WaitForFileTransfer(300000);
326 DWORD LIBNXCL_EXPORTABLE
NXCCreateMap(NXC_SESSION hSession
, DWORD dwRootObj
,
327 TCHAR
*pszName
, DWORD
*pdwMapId
)
329 CSCPMessage msg
, *pResponse
;
330 DWORD dwRqId
, dwResult
;
332 dwRqId
= ((NXCL_Session
*)hSession
)->CreateRqId();
334 msg
.SetCode(CMD_CREATE_MAP
);
336 msg
.SetVariable(VID_OBJECT_ID
, dwRootObj
);
337 msg
.SetVariable(VID_NAME
, pszName
);
338 ((NXCL_Session
*)hSession
)->SendMsg(&msg
);
340 pResponse
= ((NXCL_Session
*)hSession
)->WaitForMessage(CMD_REQUEST_COMPLETED
, dwRqId
);
341 if (pResponse
!= NULL
)
343 dwResult
= pResponse
->GetVariableLong(VID_RCC
);
344 if (dwResult
== RCC_SUCCESS
)
346 *pdwMapId
= pResponse
->GetVariableLong(VID_MAP_ID
);
352 dwResult
= RCC_TIMEOUT
;