a02278be908b23fc71ee9264900813f31ca5452e
[public/netxms.git] / include / netxms_maps.h
1 /*
2 ** NetXMS - Network Management System
3 ** Copyright (C) 2003, 2004, 2005, 2006 Victor Kirhenshtein
4 **
5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation; either version 2 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 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: netxms_maps.h
20 **
21 **/
22
23 #ifndef _netxms_maps_h_
24 #define _netxms_maps_h_
25
26 #ifdef _WIN32
27 #ifdef LIBNXMAP_EXPORTS
28 #define LIBNXMAP_EXPORTABLE __declspec(dllexport)
29 #else
30 #define LIBNXMAP_EXPORTABLE __declspec(dllimport)
31 #endif
32 #else /* _WIN32 */
33 #define LIBNXMAP_EXPORTABLE
34 #endif
35
36
37 //
38 // Constants
39 //
40
41 #define MAP_OBJECT_SIZE_X 40
42 #define MAP_OBJECT_SIZE_Y 40
43 #define MAP_OBJECT_INTERVAL_X 50
44 #define MAP_OBJECT_INTERVAL_Y 50
45 #define MAP_TEXT_BOX_HEIGHT 24
46 #define MAP_TOP_MARGIN 10
47 #define MAP_LEFT_MARGIN 20
48 #define MAP_BOTTOM_MARGIN 10
49 #define MAP_RIGHT_MARGIN 20
50 #define MAX_CONNECTOR_NAME 64
51
52
53 //
54 // Submap attributes
55 //
56
57 #define SUBMAP_ATTR_AUTOMATIC_LAYOUT 0x00000001
58 #define SUBMAP_ATTR_HAS_BK_IMAGE 0x00000002
59 #define SUBMAP_ATTR_LAYOUT_COMPLETED 0x00010000
60
61
62 //
63 // Submap layout methods
64 //
65
66 #define SUBMAP_LAYOUT_DUMB 0
67 #define SUBMAP_LAYOUT_RADIAL 1
68 #define SUBMAP_LAYOUT_REINGOLD_TILFORD 2
69
70
71 //
72 // User access rights
73 //
74
75 #define MAP_ACCESS_READ 0x0001
76 #define MAP_ACCESS_WRITE 0x0002
77 #define MAP_ACCESS_ACL 0x0004
78 #define MAP_ACCESS_DELETE 0x0008
79
80
81 //
82 // Object link types
83 //
84
85 #define LINK_TYPE_NORMAL 0
86 #define LINK_TYPE_VPN 1
87
88
89 //
90 // Object-on-map structure
91 //
92
93 struct MAP_OBJECT
94 {
95 DWORD dwId;
96 LONG x;
97 LONG y;
98 DWORD dwState; // Runtime field, can be used freely by application
99 };
100
101
102 //
103 // Link between objects
104 //
105
106 struct OBJLINK
107 {
108 DWORD dwId1;
109 DWORD dwId2;
110 LONG nType;
111 TCHAR szPort1[MAX_CONNECTOR_NAME];
112 TCHAR szPort2[MAX_CONNECTOR_NAME];
113 };
114
115
116 //
117 // Access list entry
118 //
119
120 struct MAP_ACL_ENTRY
121 {
122 DWORD dwUserId;
123 DWORD dwAccess;
124 };
125
126
127 //
128 // Connected object list - used as source for nxSubmap::DoLayout
129 //
130
131 class LIBNXMAP_EXPORTABLE nxmap_ObjList
132 {
133 protected:
134 DWORD m_dwNumObjects;
135 DWORD *m_pdwObjectList;
136 DWORD m_dwNumLinks;
137 OBJLINK *m_pLinkList;
138
139 public:
140 nxmap_ObjList();
141 nxmap_ObjList(nxmap_ObjList *pSrc);
142 nxmap_ObjList(CSCPMessage *pMsg);
143 ~nxmap_ObjList();
144
145 void AddObject(DWORD dwId);
146 void LinkObjects(DWORD dwId1, DWORD dwId2);
147 void LinkObjectsEx(DWORD dwId1, DWORD dwId2, TCHAR *pszPort1, TCHAR *pszPort2);
148 void Clear(void);
149
150 DWORD GetNumObjects(void) { return m_dwNumObjects; }
151 DWORD *GetObjects(void) { return m_pdwObjectList; }
152 DWORD GetNumLinks(void) { return m_dwNumLinks; }
153 OBJLINK *GetLinks(void) { return m_pLinkList; }
154
155 void CreateMessage(CSCPMessage *pMsg);
156 };
157
158
159 //
160 // Graph's vertex
161 //
162
163 class LIBNXMAP_EXPORTABLE nxmap_Vertex
164 {
165 protected:
166 DWORD m_dwId;
167 DWORD m_dwNumChilds;
168 nxmap_Vertex **m_ppChildList;
169 DWORD m_dwNumParents;
170 nxmap_Vertex **m_ppParentList;
171 int m_posX;
172 int m_posY;
173 BOOL m_isProcessed; // Processed flag for various recursive operations
174
175 void LinkParent(nxmap_Vertex *pVtx);
176 void UnlinkParent(nxmap_Vertex *pVtx);
177
178 public:
179 nxmap_Vertex(DWORD dwId);
180 ~nxmap_Vertex();
181
182 DWORD GetId(void) { return m_dwId; }
183 int GetPosX(void) { return m_posX; }
184 int GetPosY(void) { return m_posY; }
185 DWORD GetNumChilds(void) { return m_dwNumChilds; }
186 nxmap_Vertex *GetChild(DWORD dwIndex) { return (dwIndex < m_dwNumChilds) ? m_ppChildList[dwIndex] : NULL; }
187 DWORD GetNumParents(void) { return m_dwNumParents; }
188 nxmap_Vertex *GetParent(DWORD dwIndex) { return (dwIndex < m_dwNumParents) ? m_ppParentList[dwIndex] : NULL; }
189 BOOL IsParentOf(nxmap_Vertex *pVertex);
190 BOOL IsProcessed(void) { return m_isProcessed; }
191
192 void LinkChild(nxmap_Vertex *pVtx);
193 void UnlinkChild(nxmap_Vertex *pVtx);
194 void SetPosition(int x, int y) { m_posX = x; m_posY = y; }
195 void SetAsProcessed(void) { m_isProcessed = TRUE; }
196 void SetAsUnprocessed(void) { m_isProcessed = FALSE; }
197 };
198
199
200 //
201 // Connected graph
202 //
203
204 class LIBNXMAP_EXPORTABLE nxmap_Graph
205 {
206 protected:
207 DWORD m_dwVertexCount;
208 nxmap_Vertex **m_ppVertexList;
209 nxmap_Vertex *m_pRoot;
210
211 void SetAsUnprocessed(void);
212 void NormalizeVertexLinks(nxmap_Vertex *pRoot);
213
214 public:
215 nxmap_Graph();
216 nxmap_Graph(DWORD dwNumObjects, DWORD *pdwObjectList, DWORD dwNumLinks, OBJLINK *pLinkList);
217 ~nxmap_Graph();
218
219 DWORD GetVertexCount(void) { return m_dwVertexCount; }
220 nxmap_Vertex *FindVertex(DWORD dwId);
221 DWORD GetVertexIndex(nxmap_Vertex *pVertex);
222 nxmap_Vertex *GetRootVertex(void) { return (m_pRoot != NULL) ? m_pRoot : (m_dwVertexCount > 0 ? m_ppVertexList[0] : NULL); }
223 nxmap_Vertex *GetVertexByIndex(DWORD dwIndex) { return dwIndex < m_dwVertexCount ? m_ppVertexList[dwIndex] : NULL; }
224
225 void SetRootVertex(DWORD dwId);
226 void NormalizeLinks(void);
227 void NormalizeVertexPositions(void);
228 };
229
230
231 //
232 // Submap class
233 //
234
235 class LIBNXMAP_EXPORTABLE nxSubmap
236 {
237 protected:
238 DWORD m_dwId;
239 DWORD m_dwAttr;
240 DWORD m_dwNumObjects;
241 MAP_OBJECT *m_pObjectList;
242 DWORD m_dwNumLinks;
243 OBJLINK *m_pLinkList;
244
245 void CommonInit(void);
246
247 public:
248 nxSubmap();
249 nxSubmap(DWORD dwObjectId);
250 nxSubmap(CSCPMessage *pMsg);
251 virtual ~nxSubmap();
252
253 DWORD Id(void) { return m_dwId; }
254
255 void CreateMessage(CSCPMessage *pMsg);
256 void ModifyFromMessage(CSCPMessage *pMsg);
257
258 POINT GetMinSize(void);
259
260 BOOL GetAutoLayoutFlag(void) { return (m_dwAttr & SUBMAP_ATTR_AUTOMATIC_LAYOUT) ? TRUE : FALSE; }
261 void SetAutoLayoutFlag(BOOL bFlag) { if (bFlag) m_dwAttr |= SUBMAP_ATTR_AUTOMATIC_LAYOUT; else m_dwAttr &= ~SUBMAP_ATTR_AUTOMATIC_LAYOUT; }
262
263 BOOL GetBkImageFlag(void) { return (m_dwAttr & SUBMAP_ATTR_HAS_BK_IMAGE) ? TRUE : FALSE; }
264 void SetBkImageFlag(BOOL bFlag) { if (bFlag) m_dwAttr |= SUBMAP_ATTR_HAS_BK_IMAGE; else m_dwAttr &= ~SUBMAP_ATTR_HAS_BK_IMAGE; }
265
266 BOOL IsLayoutCompleted(void) { return (m_dwAttr & SUBMAP_ATTR_LAYOUT_COMPLETED) ? TRUE : FALSE; }
267
268 void DoLayout(DWORD dwNumObjects, DWORD *pdwObjectList,
269 DWORD dwNumLinks, OBJLINK *pLinkList,
270 int nIdealX, int nIdealY, int nMethod,
271 BOOL bNormalize);
272 POINT GetObjectPosition(DWORD dwObjectId);
273 POINT GetObjectPositionByIndex(DWORD dwIndex);
274 void SetObjectPosition(DWORD dwObjectId, int x, int y);
275 void SetObjectPositionByIndex(DWORD dwIndex, int x, int y);
276
277 DWORD GetNumObjects(void) { return m_dwNumObjects; }
278 DWORD GetObjectIdFromIndex(DWORD dwIndex) { return m_pObjectList[dwIndex].dwId; }
279 DWORD GetObjectIndex(DWORD dwObjectId);
280
281 void SetObjectState(DWORD dwObjectId, DWORD dwState);
282 void SetObjectStateByIndex(DWORD dwIndex, DWORD dwState) { m_pObjectList[dwIndex].dwState = dwState; }
283 DWORD GetObjectState(DWORD dwObjectId);
284 DWORD GetObjectStateFromIndex(DWORD dwIndex) { return m_pObjectList[dwIndex].dwState; }
285
286 DWORD GetNumLinks(void) { return m_dwNumLinks; }
287 OBJLINK *GetLinkByIndex(DWORD dwIndex) { return &m_pLinkList[dwIndex]; }
288
289 void LinkObjects(DWORD dwObj1, const TCHAR *pszPort1, DWORD dwObj2, const TCHAR *pszPort2, int nType);
290 void UnlinkObjects(DWORD dwObj1, DWORD dwObj2);
291
292 void DeleteObject(DWORD dwObject);
293 };
294
295
296 //
297 // Callback type for submap creation
298 //
299
300 class nxMap;
301 typedef nxSubmap * (* SUBMAP_CREATION_CALLBACK)(DWORD, nxMap *);
302
303
304 //
305 // Map class
306 //
307
308 class LIBNXMAP_EXPORTABLE nxMap
309 {
310 protected:
311 DWORD m_dwMapId;
312 TCHAR *m_pszName;
313 TCHAR *m_pszDescription;
314 DWORD m_dwObjectId;
315 DWORD m_dwNumSubmaps;
316 nxSubmap **m_ppSubmaps;
317 DWORD m_dwACLSize;
318 MAP_ACL_ENTRY *m_pACL;
319 MUTEX m_mutex;
320 SUBMAP_CREATION_CALLBACK m_pfCreateSubmap;
321
322 void CommonInit(void);
323
324 public:
325 nxMap();
326 nxMap(DWORD dwMapId, DWORD dwObjectId, const TCHAR *pszName, const TCHAR *pszDescription);
327 nxMap(CSCPMessage *pMsg);
328 virtual ~nxMap();
329
330 void Lock(void) { MutexLock(m_mutex, INFINITE); }
331 void Unlock(void) { MutexUnlock(m_mutex); }
332
333 void SetName(const TCHAR *name) { safe_free(m_pszName); m_pszName = _tcsdup(name); }
334
335 DWORD MapId(void) { return m_dwMapId; }
336 DWORD ObjectId(void) { return m_dwObjectId; }
337 TCHAR *Name(void) { return CHECK_NULL(m_pszName); }
338
339 void AddSubmap(nxSubmap *pSubmap);
340 DWORD GetSubmapCount(void) { return m_dwNumSubmaps; }
341 nxSubmap *GetSubmap(DWORD dwObjectId);
342 nxSubmap *GetSubmapByIndex(DWORD dwIndex) { return dwIndex < m_dwNumSubmaps ? m_ppSubmaps[dwIndex] : NULL; }
343 BOOL IsSubmapExist(DWORD dwObjectId, BOOL bLock = TRUE);
344
345 void CreateMessage(CSCPMessage *pMsg);
346 void ModifyFromMessage(CSCPMessage *pMsg);
347 };
348
349 #endif