- New fields added to NODES table
[public/netxms.git] / src / server / core / node.cpp
CommitLineData
eefe7d68
VK
1/*
2** Project X - Network Management System
3** Copyright (C) 2003 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** $module: node.cpp
20**
21**/
22
23#include "nms_core.h"
24
25
26//
27// Node class default constructor
28//
29
30Node::Node()
31 :NetObj()
32{
33 m_dwFlags = 0;
34 m_dwDiscoveryFlags = 0;
35}
36
37
38//
39// Constructor for new node object
40//
41
42Node::Node(DWORD dwAddr, DWORD dwFlags, DWORD dwDiscoveryFlags)
43 :NetObj()
44{
45 m_dwIpAddr = dwAddr;
46 m_dwFlags = dwFlags;
47 m_dwDiscoveryFlags = dwDiscoveryFlags;
48}
49
50
51//
52// Node destructor
53//
54
55Node::~Node()
56{
57}
58
59
60//
61// Save object to database
62//
63
64BOOL Node::SaveToDB(void)
65{
66 char szQuery[1024];
67 DB_RESULT hResult;
68 BOOL bNewObject = TRUE;
69
70 // Lock object's access
71 Lock();
72
73 // Check for object's existence in database
74 sprintf(szQuery, "SELECT id FROM nodes WHERE id=%ld", m_dwId);
75 hResult = DBSelect(g_hCoreDB, szQuery);
76 if (hResult != 0)
77 {
78 if (DBGetNumRows(hResult) > 0)
79 bNewObject = FALSE;
80 DBFreeResult(hResult);
81 }
82
83 // Form and execute INSERT or UPDATE query
84 if (bNewObject)
85 sprintf(szQuery, "INSERT INTO nodes (id,name,status,is_deleted,primary_ip,is_snmp,is_agent,is_bridge,is_router,snmp_version,discovery_flags)"
86 " VALUES (%d,'%s',%d,%d,%d,%d,%d,%d,%d,%d,%d)",
87 m_dwId, m_szName, m_iStatus, m_bIsDeleted, m_dwIpAddr,
88 m_dwFlags & NF_IS_SNMP ? 1 : 0,
89 m_dwFlags & NF_IS_NATIVE_AGENT ? 1 : 0,
90 m_dwFlags & NF_IS_BRIDGE ? 1 : 0,
91 m_dwFlags & NF_IS_ROUTER ? 1 : 0,
92 0, m_dwDiscoveryFlags);
93 else
94 sprintf(szQuery, "UPDATE nodes SET name='%s',status=%d,is_deleted=%d,primary_ip=%d,"
95 "is_snmp=%d,is_agent=%d,is_bridge=%d,is_router=%d,snmp_version=%d,"
96 "discovery_flags=%d WHERE id=%d",
97 m_szName, m_iStatus, m_bIsDeleted, m_dwIpAddr,
98 m_dwFlags & NF_IS_SNMP ? 1 : 0,
99 m_dwFlags & NF_IS_NATIVE_AGENT ? 1 : 0,
100 m_dwFlags & NF_IS_BRIDGE ? 1 : 0,
101 m_dwFlags & NF_IS_ROUTER ? 1 : 0,
102 0, m_dwDiscoveryFlags, m_dwId);
103 DBQuery(g_hCoreDB, szQuery);
104
105 // Clear modifications flag and unlock object
106 m_bIsModified = FALSE;
107 Unlock();
108
109 return TRUE;
110}
111
112
113//
114// Delete object from database
115//
116
117BOOL Node::DeleteFromDB(void)
118{
119 char szQuery[256];
120
121 sprintf(szQuery, "DELETE FROM nodes WHERE id=%ld", m_dwId);
122 DBQuery(g_hCoreDB, szQuery);
123 return TRUE;
124}