unfinished work on new network maps
authorVictor Kirhenshtein <victor@netxms.org>
Sun, 31 Oct 2010 18:30:37 +0000 (18:30 +0000)
committerVictor Kirhenshtein <victor@netxms.org>
Sun, 31 Oct 2010 18:30:37 +0000 (18:30 +0000)
16 files changed:
doc/internal/db_format_change.txt
include/netxms_maps.h
include/netxmsdb.h
include/nxclapi.h
sql/schema.in
src/libnxmap/element.cpp [new file with mode: 0644]
src/libnxmap/libnxmap.vcproj
src/libnxmap/libnxmapw.vcproj
src/server/core/netmap.cpp [new file with mode: 0644]
src/server/core/nxcore.vcproj
src/server/core/objects.cpp
src/server/core/rootobj.cpp
src/server/core/uniroot.cpp
src/server/include/nms_objects.h
src/server/libnxsrv/messages.mc
src/server/tools/nxdbmgr/upgrade.cpp

index 09a2fc8..8837018 100644 (file)
@@ -1,3 +1,28 @@
+***************
+* 214 ==> 215 *
+***************
+
+- New tables added:
+       CREATE TABLE network_maps
+       (
+               id integer not null,
+               map_type integer not null,
+               layout integer not null,
+               seed integer not null,
+               background integer not null,
+               PRIMARY KEY(id)
+       ) TABLE_TYPE;
+
+       CREATE TABLE network_map_elements
+       (
+               map_id integer not null,
+               element_id integer not null,
+               element_type integer not null,
+               element_data SQL_TEXT not null,
+               PRIMARY KEY(map_id,element_id)
+       ) TABLE_TYPE;
+
+
 ***************
 * 208 ==> 209 *
 ***************
index bb32648..a79b759 100644 (file)
@@ -33,6 +33,8 @@
 #define LIBNXMAP_EXPORTABLE
 #endif
 
+#include <nxconfig.h>
+
 
 //
 // Constants
@@ -346,4 +348,87 @@ public:
    void ModifyFromMessage(CSCPMessage *pMsg);
 };
 
+
+/********** 1.1.x Map API ********/
+
+
+//
+// Map element types
+//
+
+#define MAP_ELEMENT_GENERIC      0
+#define MAP_ELEMENT_OBJECT       1
+#define MAP_ELEMENT_DECORATION   2
+
+
+//
+// Generic map element
+//
+
+class LIBNXMAP_EXPORTABLE NetworkMapElement
+{
+protected:
+       LONG m_type;
+       LONG m_posX;
+       LONG m_posY;
+
+public:
+       NetworkMapElement();
+       NetworkMapElement(Config *config);
+       virtual ~NetworkMapElement();
+
+       virtual void updateConfig(Config *config);
+
+       LONG getType() { return m_type; }
+       LONG getPosX() { return m_posX; }
+       LONG getPosY() { return m_posY; }
+
+       void setPosition(LONG x, LONG y);
+};
+
+
+//
+// Object map element
+//
+
+class LIBNXMAP_EXPORTABLE NetworkMapObject : public NetworkMapElement
+{
+protected:
+       DWORD m_objectId;
+
+public:
+       NetworkMapObject(DWORD objectId);
+       NetworkMapObject(Config *config);
+       virtual ~NetworkMapObject();
+
+       virtual void updateConfig(Config *config);
+
+       DWORD getObjectId() { return m_objectId; }
+};
+
+
+//
+// Decoration map element
+//
+
+class LIBNXMAP_EXPORTABLE NetworkMapDecoration : public NetworkMapElement
+{
+protected:
+       LONG m_decorationType;
+       DWORD m_color;
+       TCHAR *m_title;
+
+public:
+       NetworkMapDecoration(LONG decorationType);
+       NetworkMapDecoration(Config *config);
+       virtual ~NetworkMapDecoration();
+
+       virtual void updateConfig(Config *config);
+
+       LONG getDecorationType() { return m_decorationType; }
+       DWORD getColor() { return m_color; }
+       const TCHAR *getTitle() { return CHECK_NULL_EX(m_title); }
+};
+
+
 #endif
index c66440f..7c9e2e2 100644 (file)
@@ -24,6 +24,6 @@
 #ifndef _netxmsdb_h
 #define _netxmsdb_h
 
-#define DB_FORMAT_VERSION   214
+#define DB_FORMAT_VERSION   215
 
 #endif
index 01076b7..be4584f 100644 (file)
@@ -151,6 +151,9 @@ typedef void * NXC_SESSION;
 #define OBJECT_POLICYROOT           16
 #define OBJECT_AGENTPOLICY          17
 #define OBJECT_AGENTPOLICY_CONFIG   18
+#define OBJECT_NETWORKMAPROOT       19
+#define OBJECT_NETWORKMAPGROUP      20
+#define OBJECT_NETWORKMAP           21
 
 
 //
@@ -695,6 +698,23 @@ enum
 #define ACTION_FORWARD_EVENT  4
 
 
+//
+// Network map types
+//
+
+#define NETMAP_USER_DEFINED   0
+#define NETMAP_IP_TOPOLOGY    1
+#define NETMAP_L2_TOPOLOGY    2
+
+
+//
+// Network map layouts
+//
+
+#define MAP_LAYOUT_MANUAL     0
+#define MAP_LAYOUT_RADIAL     1
+
+
 //
 // Deployment manager status codes
 //
index 20e17ee..3138406 100644 (file)
@@ -1217,11 +1217,9 @@ CREATE TABLE ap_config_files
        PRIMARY KEY(policy_id)
 ) TABLE_TYPE;
 
-
 /*
 ** Default SNMP v3 USM credentials
 */
-
 CREATE TABLE usm_credentials
 (
        id integer not null,
@@ -1232,3 +1230,29 @@ CREATE TABLE usm_credentials
        priv_password varchar(255),
        PRIMARY KEY(id)
 ) TABLE_TYPE;
+
+/*
+** Network maps
+*/
+CREATE TABLE network_maps
+(
+       id integer not null,
+       map_type integer not null,
+       layout integer not null,
+       seed integer not null,
+       background integer not null,
+       PRIMARY KEY(id)
+) TABLE_TYPE;
+
+/*
+** Elements of network maps
+*/
+
+CREATE TABLE network_map_elements
+(
+       map_id integer not null,
+       element_id integer not null,
+       element_type integer not null,
+       element_data SQL_TEXT not null,
+       PRIMARY KEY(map_id,element_id)
+) TABLE_TYPE;
diff --git a/src/libnxmap/element.cpp b/src/libnxmap/element.cpp
new file mode 100644 (file)
index 0000000..62b4c5b
--- /dev/null
@@ -0,0 +1,169 @@
+/* 
+** NetXMS - Network Management System
+** Network Maps Library
+** Copyright (C) 2003-2010 Victor Kirhenshtein
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU Lesser General Public License as published by
+** the Free Software Foundation; either version 3 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU Lesser General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** File: element.cpp
+**
+**/
+
+#include "libnxmap.h"
+
+
+//
+// Generic element default constructor
+//
+
+NetworkMapElement::NetworkMapElement()
+{
+       m_type = MAP_ELEMENT_GENERIC;
+       m_posX = 0;
+       m_posY = 0;
+}
+
+
+//
+// Generic element config constructor
+//
+
+NetworkMapElement::NetworkMapElement(Config *config)
+{
+       m_type = config->getValueInt(_T("/type"), MAP_ELEMENT_GENERIC);
+       m_posX = config->getValueInt(_T("/posX"), 0);
+       m_posY = config->getValueInt(_T("/posY"), 0);
+}
+
+
+//
+// Generic element destructor
+//
+
+NetworkMapElement::~NetworkMapElement()
+{
+}
+
+
+//
+// Update element's persistent configuration
+//
+
+void NetworkMapElement::updateConfig(Config *config)
+{
+       config->setValue(_T("/type"), m_type);
+       config->setValue(_T("/posX"), m_posX);
+       config->setValue(_T("/posY"), m_posY);
+}
+
+
+//
+// Set element's position
+//
+
+void NetworkMapElement::setPosition(LONG x, LONG y)
+{
+       m_posX = x;
+       m_posY = y;
+}
+
+
+//
+// Object element default constructor
+//
+
+NetworkMapObject::NetworkMapObject(DWORD objectId) : NetworkMapElement()
+{
+       m_type = MAP_ELEMENT_OBJECT;
+       m_objectId = objectId;
+}
+
+
+//
+// Object element config constructor
+//
+
+NetworkMapObject::NetworkMapObject(Config *config) : NetworkMapElement(config)
+{
+       m_objectId = config->getValueUInt(_T("/objectId"), 0);
+}
+
+
+//
+// Object element destructor
+//
+
+NetworkMapObject::~NetworkMapObject()
+{
+}
+
+
+//
+// Update element's persistent configuration
+//
+
+void NetworkMapObject::updateConfig(Config *config)
+{
+       NetworkMapElement::updateConfig(config);
+       config->setValue(_T("/objectId"), m_objectId);
+}
+
+
+//
+// Decoration element default constructor
+//
+
+NetworkMapDecoration::NetworkMapDecoration(LONG decorationType) : NetworkMapElement()
+{
+       m_type = MAP_ELEMENT_DECORATION;
+       m_decorationType = decorationType;
+       m_color = 0;
+       m_title = NULL;
+}
+
+
+//
+// Decoration element config constructor
+//
+
+NetworkMapDecoration::NetworkMapDecoration(Config *config) : NetworkMapElement(config)
+{
+       m_decorationType = config->getValueInt(_T("/decorationType"), 0);
+       m_color = config->getValueInt(_T("/color"), 0);
+       m_title = _tcsdup(config->getValue(_T("/title"), _T("")));
+}
+
+
+//
+// Decoration element destructor
+//
+
+NetworkMapDecoration::~NetworkMapDecoration()
+{
+       safe_free(m_title);
+}
+
+
+//
+// Update decoration element's persistent configuration
+//
+
+void NetworkMapDecoration::updateConfig(Config *config)
+{
+       NetworkMapElement::updateConfig(config);
+       config->setValue(_T("/decorationType"), m_decorationType);
+       config->setValue(_T("/color"), m_color);
+       config->setValue(_T("/title"), CHECK_NULL_EX(m_title));
+}
index 70dfad3..08168d4 100644 (file)
                        Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"\r
                        UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"\r
                        >\r
+                       <File\r
+                               RelativePath=".\element.cpp"\r
+                               >\r
+                       </File>\r
                        <File\r
                                RelativePath=".\graph.cpp"\r
                                >\r
                                RelativePath="..\..\include\nms_util.h"\r
                                >\r
                        </File>\r
+                       <File\r
+                               RelativePath="..\..\include\nxconfig.h"\r
+                               >\r
+                       </File>\r
                        <File\r
                                RelativePath="..\..\include\unicode.h"\r
                                >\r
index be68ca4..682fc3d 100644 (file)
                        />\r
                </Configuration>\r
                <Configuration\r
-                       Name="Release|Win32"\r
-                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"\r
-                       IntermediateDirectory="$(ConfigurationName)_UNICODE"\r
+                       Name="Debug|x64"\r
+                       OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"\r
+                       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)_UNICODE"\r
                        ConfigurationType="2"\r
                        CharacterSet="1"\r
-                       WholeProgramOptimization="1"\r
                        >\r
                        <Tool\r
                                Name="VCPreBuildEventTool"\r
                        />\r
                        <Tool\r
                                Name="VCMIDLTool"\r
+                               TargetEnvironment="3"\r
                        />\r
                        <Tool\r
                                Name="VCCLCompilerTool"\r
+                               Optimization="0"\r
                                AdditionalIncludeDirectories="..\..\include"\r
-                               PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBNXMAP_EXPORTS"\r
-                               RuntimeLibrary="2"\r
+                               PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBNXMAP_EXPORTS"\r
+                               MinimalRebuild="true"\r
+                               BasicRuntimeChecks="3"\r
+                               RuntimeLibrary="3"\r
                                UsePrecompiledHeader="0"\r
                                WarningLevel="3"\r
-                               Detect64BitPortabilityProblems="false"\r
+                               Detect64BitPortabilityProblems="true"\r
                                DebugInformationFormat="3"\r
                        />\r
                        <Tool\r
                        />\r
                        <Tool\r
                                Name="VCLinkerTool"\r
-                               LinkIncremental="1"\r
+                               LinkIncremental="2"\r
                                GenerateDebugInformation="true"\r
                                SubSystem="2"\r
-                               OptimizeReferences="2"\r
-                               EnableCOMDATFolding="2"\r
-                               TargetMachine="1"\r
+                               TargetMachine="17"\r
                        />\r
                        <Tool\r
                                Name="VCALinkTool"\r
                        />\r
                </Configuration>\r
                <Configuration\r
-                       Name="Debug|x64"\r
-                       OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"\r
-                       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)_UNICODE"\r
+                       Name="Release|Win32"\r
+                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"\r
+                       IntermediateDirectory="$(ConfigurationName)_UNICODE"\r
                        ConfigurationType="2"\r
                        CharacterSet="1"\r
+                       WholeProgramOptimization="1"\r
                        >\r
                        <Tool\r
                                Name="VCPreBuildEventTool"\r
                        />\r
                        <Tool\r
                                Name="VCMIDLTool"\r
-                               TargetEnvironment="3"\r
                        />\r
                        <Tool\r
                                Name="VCCLCompilerTool"\r
-                               Optimization="0"\r
                                AdditionalIncludeDirectories="..\..\include"\r
-                               PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBNXMAP_EXPORTS"\r
-                               MinimalRebuild="true"\r
-                               BasicRuntimeChecks="3"\r
-                               RuntimeLibrary="3"\r
+                               PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBNXMAP_EXPORTS"\r
+                               RuntimeLibrary="2"\r
                                UsePrecompiledHeader="0"\r
                                WarningLevel="3"\r
-                               Detect64BitPortabilityProblems="true"\r
+                               Detect64BitPortabilityProblems="false"\r
                                DebugInformationFormat="3"\r
                        />\r
                        <Tool\r
                        />\r
                        <Tool\r
                                Name="VCLinkerTool"\r
-                               LinkIncremental="2"\r
+                               LinkIncremental="1"\r
                                GenerateDebugInformation="true"\r
                                SubSystem="2"\r
-                               TargetMachine="17"\r
+                               OptimizeReferences="2"\r
+                               EnableCOMDATFolding="2"\r
+                               TargetMachine="1"\r
                        />\r
                        <Tool\r
                                Name="VCALinkTool"\r
                        Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"\r
                        UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"\r
                        >\r
+                       <File\r
+                               RelativePath=".\element.cpp"\r
+                               >\r
+                       </File>\r
                        <File\r
                                RelativePath=".\graph.cpp"\r
                                >\r
                                RelativePath="..\..\include\nms_util.h"\r
                                >\r
                        </File>\r
+                       <File\r
+                               RelativePath="..\..\include\nxconfig.h"\r
+                               >\r
+                       </File>\r
                        <File\r
                                RelativePath="..\..\include\unicode.h"\r
                                >\r
diff --git a/src/server/core/netmap.cpp b/src/server/core/netmap.cpp
new file mode 100644 (file)
index 0000000..c6c26f5
--- /dev/null
@@ -0,0 +1,221 @@
+/* 
+** NetXMS - Network Management System
+** Copyright (C) 2003-2010 Victor Kirhenshtein
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** File: netmap.cpp
+**
+**/
+
+#include "nxcore.h"
+
+
+//
+// Redefined status calculation for network maps group
+//
+
+void NetworkMapGroup::CalculateCompoundStatus(BOOL bForcedRecalc)
+{
+   m_iStatus = STATUS_NORMAL;
+}
+
+
+//
+// Network map object default constructor
+//
+
+NetworkMap::NetworkMap() : NetObj()
+{
+       m_mapType = NETMAP_USER_DEFINED;
+       m_seedObject = 0;
+       m_layout = MAP_LAYOUT_MANUAL;
+       m_background = 0;
+       m_numElements = 0;
+       m_elements = NULL;
+}
+
+
+//
+// Network map object destructor
+//
+
+NetworkMap::~NetworkMap()
+{
+       for(int i = 0; i < m_numElements; i++)
+               delete m_elements[i];
+       safe_free(m_elements);
+}
+
+
+//
+// Redefined status calculation for network maps
+//
+
+void NetworkMap::CalculateCompoundStatus(BOOL bForcedRecalc)
+{
+   m_iStatus = STATUS_NORMAL;
+}
+
+
+//
+// Save to database
+//
+
+BOOL NetworkMap::SaveToDB(DB_HANDLE hdb)
+{
+       TCHAR query[256];
+
+       if (!SaveCommonProperties(hdb))
+               return FALSE;
+
+       // Check for object's existence in database
+       bool isNewObject = true;
+   _sntprintf(query, 256, _T("SELECT id FROM network_maps WHERE id=%d"), m_dwId);
+   DB_RESULT hResult = DBSelect(hdb, query);
+   if (hResult != NULL)
+   {
+      if (DBGetNumRows(hResult) > 0)
+         isNewObject = false;
+      DBFreeResult(hResult);
+   }
+
+       if (isNewObject)
+      _sntprintf(query, 8192,
+                 _T("INSERT INTO network_maps (id,map_type,layout,seed,background) VALUES (%d,%d,%d,%d,%d)"),
+                 m_dwId, m_mapType, m_layout, m_seedObject, m_background);
+   else
+      _sntprintf(query, 8192,
+                 _T("UPDATE network_maps SET map_type=%d,layout=%d,seed=%d,background=%d WHERE id=%d"),
+                 m_mapType, m_layout, m_seedObject, m_background, m_dwId);
+   if (!DBQuery(hdb, query))
+               return FALSE;
+
+       if (!SaveACLToDB(hdb))
+               return FALSE;
+
+   // Save elements
+   _sntprintf(query, 256, _T("DELETE FROM network_map_elements WHERE map_id=%d"), m_dwId);
+   if (!DBQuery(hdb, query))
+               return FALSE;
+   for(int i = 0; i < m_numElements; i++)
+   {
+               Config *config = new Config();
+               config->setTopLevelTag(_T("element"));
+               m_elements[i]->updateConfig(config);
+               String data = EscapeStringForXML2(config->createXml());
+               delete config;
+               int len = data.getSize() + 256;
+               TCHAR *eq = (TCHAR *)malloc(len);
+      _sntprintf(eq, len, _T("INSERT INTO network_map_elements (map_id,element_id,element_type,element_data) VALUES (%d,%d,%d,%s)"),
+                          m_dwId, i, m_elements[i]->getType(), (const TCHAR *)data);
+      DBQuery(hdb, eq);
+               free(eq);
+   }
+
+       return TRUE;
+}
+
+
+//
+// Delete from database
+//
+
+BOOL NetworkMap::DeleteFromDB()
+{
+       TCHAR query[256];
+
+       _sntprintf(query, 256, _T("DELETE FROM network_maps WHERE id=%d"), m_dwId);
+       QueueSQLRequest(query);
+       _sntprintf(query, 256, _T("DELETE FROM network_map_elements WHERE map_id=%d"), m_dwId);
+       QueueSQLRequest(query);
+       return TRUE;
+}
+
+
+//
+// Load from database
+//
+
+BOOL NetworkMap::CreateFromDB(DWORD dwId)
+{
+       m_dwId = dwId;
+
+       if (!LoadCommonProperties())
+   {
+      DbgPrintf(2, "Cannot load common properties for network map object %d", dwId);
+      return FALSE;
+   }
+
+   if (!m_bIsDeleted)
+   {
+               TCHAR query[256];
+
+          LoadACLFromDB();
+
+               _sntprintf(query, 256, _T("SELECT map_type,layout,seed,background FROM network_maps WHERE id=%d"), dwId);
+               DB_RESULT hResult = DBSelect(g_hCoreDB, query);
+               if (hResult == NULL)
+                       return FALSE;
+
+               m_mapType = DBGetFieldLong(hResult, 0, 0);
+               m_layout = DBGetFieldLong(hResult, 0, 1);
+               m_seedObject = DBGetFieldULong(hResult, 0, 2);
+               m_background = DBGetFieldLong(hResult, 0, 3);
+               DBFreeResult(hResult);
+
+          // Load elements
+      _sntprintf(query, 256, _T("SELECT element_type,element_data FROM network_map_elements WHERE map_id=%d"), m_dwId);
+      hResult = DBSelect(g_hCoreDB, query);
+      if (hResult != NULL)
+      {
+         m_numElements = DBGetNumRows(hResult);
+                       if (m_numElements > 0)
+                       {
+                               m_elements = (NetworkMapElement **)malloc(sizeof(NetworkMapElement *) * m_numElements);
+                               for(int i = 0; i < m_numElements; i++)
+                               {
+                                       Config *config = new Config();
+                                       TCHAR *data = DBGetField(hResult, i, 1, NULL, 0);
+                                       if (data != NULL)
+                                       {
+                                               config->loadXmlConfigFromMemory(data, strlen(data), _T("<database>"), _T("element"));
+                                               free(data);
+                                               switch(DBGetFieldLong(hResult, i, 0))
+                                               {
+                                                       case MAP_ELEMENT_OBJECT:
+                                                               m_elements[i] = new NetworkMapObject(config);
+                                                               break;
+                                                       case MAP_ELEMENT_DECORATION:
+                                                               m_elements[i] = new NetworkMapDecoration(config);
+                                                               break;
+                                                       default:                // Unknown type, create generic element
+                                                               m_elements[i] = new NetworkMapElement(config);
+                                                               break;
+                                               }
+                                       }
+                                       else
+                                       {
+                                               m_elements[i] = new NetworkMapElement();
+                                       }
+                                       delete config;
+                               }
+                       }
+         DBFreeResult(hResult);
+      }
+       }
+
+       return TRUE;
+}
index 04dddd3..fd316a2 100644 (file)
                                RelativePath=".\netinfo.cpp"\r
                                >\r
                        </File>\r
+                       <File\r
+                               RelativePath=".\netmap.cpp"\r
+                               >\r
+                       </File>\r
                        <File\r
                                RelativePath=".\netobj.cpp"\r
                                >\r
index ab93232..71d4f3d 100644 (file)
@@ -1,6 +1,6 @@
 /* 
 ** NetXMS - Network Management System
-** Copyright (C) 2003, 2004, 2005, 2006, 2007 Victor Kirhenshtein
+** Copyright (C) 2003-2010 Victor Kirhenshtein
 **
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -33,6 +33,7 @@ Network NXCORE_EXPORTABLE *g_pEntireNet = NULL;
 ServiceRoot NXCORE_EXPORTABLE *g_pServiceRoot = NULL;
 TemplateRoot NXCORE_EXPORTABLE *g_pTemplateRoot = NULL;
 PolicyRoot NXCORE_EXPORTABLE *g_pPolicyRoot = NULL;
+NetworkMapRoot NXCORE_EXPORTABLE *g_pMapRoot = NULL;
 
 DWORD NXCORE_EXPORTABLE g_dwMgmtNode = 0;
 INDEX NXCORE_EXPORTABLE *g_pIndexById = NULL;
@@ -65,7 +66,8 @@ const char *g_szClassName[]={ "Generic", "Subnet", "Node", "Interface",
                               "Template", "TemplateGroup", "TemplateRoot",
                               "NetworkService", "VPNConnector", "Condition",
                               "Cluster", "PolicyGroup", "PolicyRoot",
-                              "AgentPolicy", "AgentPolicyConfig" };
+                              "AgentPolicy", "AgentPolicyConfig", "NetworkMapRoot",
+                              "NetworkMapGroup", "NetworkMap" };
 
 
 //
@@ -357,6 +359,9 @@ void NetObjInsert(NetObj *pObject, BOOL bNewObject)
                        case OBJECT_POLICYROOT:
                        case OBJECT_AGENTPOLICY:
                        case OBJECT_AGENTPOLICY_CONFIG:
+                       case OBJECT_NETWORKMAPROOT:
+                       case OBJECT_NETWORKMAPGROUP:
+                       case OBJECT_NETWORKMAP:
             break;
          case OBJECT_SUBNET:
             if (pObject->IpAddr() != 0)
@@ -427,6 +432,9 @@ void NetObjDeleteFromIndexes(NetObj *pObject)
                case OBJECT_POLICYROOT:
                case OBJECT_AGENTPOLICY:
                case OBJECT_AGENTPOLICY_CONFIG:
+               case OBJECT_NETWORKMAPROOT:
+               case OBJECT_NETWORKMAPGROUP:
+               case OBJECT_NETWORKMAP:
          break;
       case OBJECT_SUBNET:
          if (pObject->IpAddr() != 0)
@@ -1000,6 +1008,29 @@ BOOL LoadObjects()
       DBFreeResult(hResult);
    }
 
+   // Load agent policies
+   DbgPrintf(2, "Loading network maps...");
+   hResult = DBSelect(g_hCoreDB, "SELECT id FROM network_maps");
+   if (hResult != NULL)
+   {
+      dwNumRows = DBGetNumRows(hResult);
+      for(i = 0; i < dwNumRows; i++)
+      {
+         dwId = DBGetFieldULong(hResult, i, 0);
+         NetworkMap *map = new NetworkMap;
+         if (map->CreateFromDB(dwId))
+         {
+            NetObjInsert(map, FALSE);  // Insert into indexes
+         }
+         else     // Object load failed
+         {
+            delete map;
+            nxlog_write(MSG_NETMAP_LOAD_FAILED, EVENTLOG_ERROR_TYPE, "d", dwId);
+         }
+      }
+      DBFreeResult(hResult);
+   }
+
    // Load container objects
    DbgPrintf(2, "Loading containers...");
    sprintf(szQuery, "SELECT id FROM containers WHERE object_class=%d", OBJECT_CONTAINER);
@@ -1078,18 +1109,46 @@ BOOL LoadObjects()
       DBFreeResult(hResult);
    }
 
+   // Load map group objects
+   DbgPrintf(2, "Loading map groups...");
+   sprintf(szQuery, "SELECT id FROM containers WHERE object_class=%d", OBJECT_NETWORKMAPGROUP);
+   hResult = DBSelect(g_hCoreDB, szQuery);
+   if (hResult != 0)
+   {
+      NetworkMapGroup *pGroup;
+
+      dwNumRows = DBGetNumRows(hResult);
+      for(i = 0; i < dwNumRows; i++)
+      {
+         dwId = DBGetFieldULong(hResult, i, 0);
+         pGroup = new NetworkMapGroup;
+         if (pGroup->CreateFromDB(dwId))
+         {
+            NetObjInsert(pGroup, FALSE);  // Insert into indexes
+         }
+         else     // Object load failed
+         {
+            delete pGroup;
+            nxlog_write(MSG_MG_LOAD_FAILED, EVENTLOG_ERROR_TYPE, "d", dwId);
+         }
+      }
+      DBFreeResult(hResult);
+   }
+
    // Link childs to container and template group objects
    DbgPrintf(2, "Linking objects...");
    for(i = 0; i < g_dwIdIndexSize; i++)
       if ((((NetObj *)g_pIndexById[i].pObject)->Type() == OBJECT_CONTAINER) ||
           (((NetObj *)g_pIndexById[i].pObject)->Type() == OBJECT_TEMPLATEGROUP) ||
-          (((NetObj *)g_pIndexById[i].pObject)->Type() == OBJECT_POLICYGROUP))
+          (((NetObj *)g_pIndexById[i].pObject)->Type() == OBJECT_POLICYGROUP) ||
+          (((NetObj *)g_pIndexById[i].pObject)->Type() == OBJECT_NETWORKMAPGROUP))
          ((Container *)g_pIndexById[i].pObject)->LinkChildObjects();
 
    // Link childs to "Service Root" and "Template Root" objects
    g_pServiceRoot->LinkChildObjects();
    g_pTemplateRoot->LinkChildObjects();
    g_pPolicyRoot->LinkChildObjects();
+   g_pMapRoot->LinkChildObjects();
 
    // Allow objects to change it's modification flag
    g_bModificationsLocked = FALSE;
@@ -1098,6 +1157,8 @@ BOOL LoadObjects()
    g_pEntireNet->CalculateCompoundStatus();
    g_pServiceRoot->CalculateCompoundStatus();
    g_pTemplateRoot->CalculateCompoundStatus();
+   g_pPolicyRoot->CalculateCompoundStatus();
+   g_pMapRoot->CalculateCompoundStatus();
 
    // Recalculate status for zone objects
    if (g_dwFlags & AF_ENABLE_ZONING)
index 492a260..4b4e7c8 100644 (file)
@@ -104,3 +104,34 @@ void PolicyRoot::CalculateCompoundStatus(BOOL bForcedRecalc)
 {
    m_iStatus = STATUS_NORMAL;
 }
+
+
+//
+// Network maps root class default constructor
+//
+
+NetworkMapRoot::NetworkMapRoot()
+               :UniversalRoot()
+{
+   m_dwId = BUILTIN_OID_NETWORKMAPROOT;
+   strcpy(m_szName, "Network Maps");
+}
+
+
+//
+// Network maps root class destructor
+//
+
+NetworkMapRoot::~NetworkMapRoot()
+{
+}
+
+
+//
+// Redefined status calculation for network maps root
+//
+
+void NetworkMapRoot::CalculateCompoundStatus(BOOL bForcedRecalc)
+{
+   m_iStatus = STATUS_NORMAL;
+}
index a3ed1a5..c2cffc8 100644 (file)
@@ -1,6 +1,6 @@
 /* 
 ** NetXMS - Network Management System
-** Copyright (C) 2003, 2004 Victor Kirhenshtein
+** Copyright (C) 2003-2010 Victor Kirhenshtein
 **
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software
 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 **
-** $module: uniroot.cpp
+** File: uniroot.cpp
 **
 **/
 
@@ -47,7 +47,7 @@ UniversalRoot::~UniversalRoot()
 // This method is expected to be called only at startup, so we don't lock
 //
 
-void UniversalRoot::LinkChildObjects(void)
+void UniversalRoot::LinkChildObjects()
 {
    DWORD i, dwNumChilds, dwObjectId;
    NetObj *pObject;
@@ -113,7 +113,7 @@ BOOL UniversalRoot::SaveToDB(DB_HANDLE hdb)
 // Load properties from database
 //
 
-void UniversalRoot::LoadFromDB(void)
+void UniversalRoot::LoadFromDB()
 {
    LoadCommonProperties();
    LoadACLFromDB();
index bbe9ca1..3d98d9f 100644 (file)
@@ -1156,10 +1156,10 @@ public:
    AgentPolicy(const TCHAR *name, int type);
    virtual ~AgentPolicy();
 
-   virtual int Type(void) { return OBJECT_AGENTPOLICY; }
+   virtual int Type() { return OBJECT_AGENTPOLICY; }
 
    virtual BOOL SaveToDB(DB_HANDLE hdb);
-   virtual BOOL DeleteFromDB(void);
+   virtual BOOL DeleteFromDB();
    virtual BOOL CreateFromDB(DWORD dwId);
 
    virtual void CreateMessage(CSCPMessage *pMsg);
@@ -1188,7 +1188,7 @@ public:
    AgentPolicyConfig(const TCHAR *name);
    virtual ~AgentPolicyConfig();
 
-   virtual int Type(void) { return OBJECT_AGENTPOLICY_CONFIG; }
+   virtual int Type() { return OBJECT_AGENTPOLICY_CONFIG; }
 
    virtual BOOL SaveToDB(DB_HANDLE hdb);
    virtual BOOL DeleteFromDB(void);
@@ -1234,6 +1234,68 @@ public:
 };
 
 
+//
+// Network map root
+//
+
+class NXCORE_EXPORTABLE NetworkMapRoot : public UniversalRoot
+{
+public:
+   NetworkMapRoot();
+   virtual ~NetworkMapRoot();
+
+   virtual int Type() { return OBJECT_NETWORKMAPROOT; }
+   virtual const char *DefaultName() { return "Network Maps"; }
+   virtual void CalculateCompoundStatus(BOOL bForcedRecalc = FALSE);
+};
+
+
+//
+// Network map group object
+//
+
+class NXCORE_EXPORTABLE NetworkMapGroup : public Container
+{
+public:
+   NetworkMapGroup() : Container() { }
+   NetworkMapGroup(TCHAR *pszName) : Container(pszName, 0) { }
+   virtual ~NetworkMapGroup() { }
+
+   virtual int Type() { return OBJECT_NETWORKMAPGROUP; }
+   virtual void CalculateCompoundStatus(BOOL bForcedRecalc = FALSE);
+};
+
+
+//
+// Network map object
+//
+
+class NXCORE_EXPORTABLE NetworkMap : public NetObj
+{
+protected:
+       int m_mapType;
+       DWORD m_seedObject;
+       int m_layout;
+       int m_background;
+       int m_numElements;
+       NetworkMapElement **m_elements;
+
+public:
+   NetworkMap();
+   virtual ~NetworkMap();
+
+   virtual int Type() { return OBJECT_NETWORKMAP; }
+   virtual void CalculateCompoundStatus(BOOL bForcedRecalc = FALSE);
+
+       virtual BOOL SaveToDB(DB_HANDLE hdb);
+   virtual BOOL DeleteFromDB();
+   virtual BOOL CreateFromDB(DWORD dwId);
+
+   virtual void CreateMessage(CSCPMessage *pMsg);
+   virtual DWORD ModifyFromMessage(CSCPMessage *pRequest, BOOL bAlreadyLocked = FALSE);
+};
+
+
 //
 // Object index structure
 //
@@ -1262,7 +1324,7 @@ struct CONTAINER_CATEGORY
 // Functions
 //
 
-void ObjectsInit(void);
+void ObjectsInit();
 
 void NXCORE_EXPORTABLE NetObjInsert(NetObj *pObject, BOOL bNewObject);
 void NetObjDeleteFromIndexes(NetObj *pObject);
@@ -1281,7 +1343,7 @@ DWORD NXCORE_EXPORTABLE FindLocalMgmtNode(void);
 CONTAINER_CATEGORY NXCORE_EXPORTABLE *FindContainerCategory(DWORD dwId);
 Zone NXCORE_EXPORTABLE *FindZoneByGUID(DWORD dwZoneGUID);
 
-BOOL LoadObjects(void);
+BOOL LoadObjects();
 void DumpObjects(CONSOLE_CTX pCtx);
 
 void DeleteUserFromAllObjects(DWORD dwUserId);
index eb200be..214e87a 100644 (file)
@@ -758,4 +758,16 @@ Language=English
 Inconsistent database: agent policy object %1 has reference to child object %2 which is not a node object
 .
 
+MessageId=
+SymbolicName=MSG_MG_LOAD_FAILED
+Language=English
+Failed to load network map group object with id %1 from database
+.
+
+MessageId=
+SymbolicName=MSG_NETMAP_LOAD_FAILED
+Language=English
+Failed to load network map object with id %1 from database
+.
+
 ;#endif
index 31c5038..2130677 100644 (file)
@@ -245,6 +245,32 @@ static BOOL SetColumnNullable(const TCHAR *table, const TCHAR *column, const TCH
 }
 
 
+//
+// Upgrade from V214 to V215
+//
+
+static BOOL H_UpgradeFromV214(int currVersion, int newVersion)
+{
+       CHK_EXEC(CreateTable(_T("CREATE TABLE network_maps (")
+                                 _T("id integer not null,")
+                                                     _T("map_type integer not null,")
+                                                     _T("layout integer not null,")
+                                                     _T("seed integer not null,")
+                                                     _T("background integer not null,")
+                            _T("PRIMARY KEY(id))")));
+
+       CHK_EXEC(CreateTable(_T("CREATE TABLE network_map_elements (")
+                                 _T("map_id integer not null,")
+                                 _T("element_id integer not null,")
+                                                     _T("element_type integer not null,")
+                                                               _T("element_data $SQL:TEXT not null,")
+                            _T("PRIMARY KEY(map_id,element_id))")));
+
+       CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='215' WHERE var_name='SchemaVersion'")));
+   return TRUE;
+}
+
+
 //
 // Upgrade from V213 to V214
 //
@@ -310,7 +336,6 @@ static BOOL H_UpgradeFromV213(int currVersion, int newVersion)
        }
 
        CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='214' WHERE var_name='SchemaVersion'")));
-
    return TRUE;
 }
 
@@ -4815,6 +4840,7 @@ static struct
        { 211, 212, H_UpgradeFromV211 },
        { 212, 213, H_UpgradeFromV212 },
        { 213, 214, H_UpgradeFromV213 },
+       { 214, 215, H_UpgradeFromV214 },
    { 0, NULL }
 };