- Initial work on maps
[public/netxms.git] / src / libnxmap / map.cpp
1 /*
2 ** NetXMS - Network Management System
3 ** Network Maps 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: map.cpp
21 **
22 **/
23
24 #include "libnxmap.h"
25
26
27 //
28 // Default map object constructor
29 //
30
31 nxMap::nxMap()
32 {
33 CommonInit();
34 }
35
36
37 //
38 // Constructor for new map object
39 //
40
41 nxMap::nxMap(DWORD dwObjectId, TCHAR *pszName, TCHAR *pszDescription)
42 {
43 CommonInit();
44 m_dwObjectId = dwObjectId;
45 m_pszName = _tcsdup(pszName);
46 m_pszDescription = _tcsdup(pszDescription);
47 }
48
49
50 //
51 // Create map object from NXCP message
52 //
53
54 nxMap::nxMap(CSCPMessage *pMsg)
55 {
56 CommonInit();
57 ModifyFromMessage(pMsg);
58 }
59
60
61 //
62 // Common initialization code
63 //
64
65 void nxMap::CommonInit(void)
66 {
67 m_pszName = NULL;
68 m_pszDescription = NULL;
69 m_dwObjectId = 0;
70 m_dwNumSubmaps = 0;
71 m_ppSubmaps = NULL;
72 m_dwACLSize = 0;
73 m_pACL = NULL;
74 m_mutex = MutexCreate();
75 }
76
77
78 //
79 // Destructor
80 //
81
82 nxMap::~nxMap()
83 {
84 DWORD i;
85
86 safe_free(m_pszName);
87 safe_free(m_pszDescription);
88 for(i = 0; i < m_dwNumSubmaps; i++)
89 delete m_ppSubmaps[i];
90 safe_free(m_ppSubmaps);
91 safe_free(m_pACL);
92 MutexDestroy(m_mutex);
93 }
94
95
96 //
97 // Get submap by object ID or create if one doesn't exist
98 //
99
100 nxSubmap *nxMap::GetSubmap(DWORD dwObjectId)
101 {
102 DWORD i;
103 nxSubmap *pSubmap;
104
105 Lock();
106
107 for(i = 0; i < m_dwNumSubmaps; i++)
108 {
109 if (m_ppSubmaps[i]->Id() == dwObjectId)
110 {
111 pSubmap = m_ppSubmaps[i];
112 break;
113 }
114 }
115
116 if (i == m_dwNumSubmaps)
117 {
118 // Create new submap
119 pSubmap = new nxSubmap(dwObjectId);
120 m_dwNumSubmaps++;
121 m_ppSubmaps = (nxSubmap **)realloc(m_ppSubmaps, sizeof(nxSubmap *) * m_dwNumSubmaps);
122 m_ppSubmaps[i] = pSubmap;
123 }
124
125 Unlock();
126 return pSubmap;
127 }
128
129
130 //
131 // Fill NXCP message with map data
132 //
133
134 void nxMap::CreateMessage(CSCPMessage *pMsg)
135 {
136 }
137
138
139 //
140 // Modify map object from NXCP message
141 //
142
143 void nxMap::ModifyFromMessage(CSCPMessage *pMsg)
144 {
145 }