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