f65b68be9b22962c8d307745d4625441e13dc17b
[public/netxms.git] / src / libnxcl / mp.cpp
1 /*
2 ** NetXMS - Network Management System
3 ** Client Library
4 ** Copyright (C) 2006 Victor Kirhenshtein
5 **
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.
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 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: mp.cpp
21 **
22 **/
23
24 #include "libnxcl.h"
25
26
27 //
28 // Create management pack file
29 //
30
31 DWORD LIBNXCL_EXPORTABLE NXCExportConfiguration(NXC_SESSION hSession, TCHAR *pszDescr,
32 DWORD dwNumEvents, DWORD *pdwEventList,
33 DWORD dwNumTemplates, DWORD *pdwTemplateList,
34 DWORD dwNumTraps, DWORD *pdwTrapList,
35 TCHAR **ppszContent)
36 {
37 CSCPMessage msg, *pResponse;
38 DWORD dwRqId, dwResult;
39
40 *ppszContent = NULL;
41
42 dwRqId = ((NXCL_Session *)hSession)->CreateRqId();
43
44 msg.SetCode(CMD_EXPORT_CONFIGURATION);
45 msg.SetId(dwRqId);
46 msg.SetVariable(VID_DESCRIPTION, pszDescr);
47 msg.SetVariable(VID_NUM_EVENTS, dwNumEvents);
48 msg.SetVariableToInt32Array(VID_EVENT_LIST, dwNumEvents, pdwEventList);
49 msg.SetVariable(VID_NUM_OBJECTS, dwNumTemplates);
50 msg.SetVariableToInt32Array(VID_OBJECT_LIST, dwNumTemplates, pdwTemplateList);
51 msg.SetVariable(VID_NUM_TRAPS, dwNumTraps);
52 msg.SetVariableToInt32Array(VID_TRAP_LIST, dwNumTraps, pdwTrapList);
53 ((NXCL_Session *)hSession)->SendMsg(&msg);
54
55 pResponse = ((NXCL_Session *)hSession)->WaitForMessage(CMD_REQUEST_COMPLETED, dwRqId);
56 if (pResponse != NULL)
57 {
58 dwResult = pResponse->GetVariableLong(VID_RCC);
59 if (dwResult == RCC_SUCCESS)
60 {
61 *ppszContent = pResponse->GetVariableStr(VID_NXMP_CONTENT);
62 }
63 delete pResponse;
64 }
65 else
66 {
67 dwResult = RCC_TIMEOUT;
68 }
69 return dwResult;
70 }
71
72
73 //
74 // Install management pack
75 //
76
77 DWORD LIBNXCL_EXPORTABLE NXCImportConfiguration(NXC_SESSION hSession, TCHAR *pszContent,
78 DWORD dwFlags, TCHAR *pszErrorText, int nErrorLen)
79 {
80 CSCPMessage msg, *pResponse;
81 DWORD dwRqId, dwResult;
82
83 dwRqId = ((NXCL_Session *)hSession)->CreateRqId();
84
85 msg.SetCode(CMD_IMPORT_CONFIGURATION);
86 msg.SetId(dwRqId);
87 msg.SetVariable(VID_NXMP_CONTENT, pszContent);
88 msg.SetVariable(VID_FLAGS, dwFlags);
89 ((NXCL_Session *)hSession)->SendMsg(&msg);
90
91 pResponse = ((NXCL_Session *)hSession)->WaitForMessage(CMD_REQUEST_COMPLETED, dwRqId);
92 if (pResponse != NULL)
93 {
94 dwResult = pResponse->GetVariableLong(VID_RCC);
95 if (dwResult == RCC_SUCCESS)
96 {
97 *pszErrorText = 0;
98 }
99 else
100 {
101 pResponse->GetVariableStr(VID_ERROR_TEXT, pszErrorText, nErrorLen);
102 }
103 delete pResponse;
104 }
105 else
106 {
107 dwResult = RCC_TIMEOUT;
108 }
109 return dwResult;
110 }