Minor changes
[public/netxms.git] / src / console / win32 / nxcon.cpp
CommitLineData
3bf7e95e
VK
1// nxcon.cpp : Defines the class behaviors for the application.
2//
3
4#include "stdafx.h"
5#include "nxcon.h"
6
7#include "MainFrm.h"
8#include "LoginDialog.h"
9
10#ifdef _DEBUG
11#define new DEBUG_NEW
12#undef THIS_FILE
13static char THIS_FILE[] = __FILE__;
14#endif
15
16
17//
18// Wrapper for client library event handler
19//
20
21static void ClientEventHandler(DWORD dwEvent, DWORD dwCode, void *pArg)
22{
23 theApp.EventHandler(dwEvent, dwCode, pArg);
24}
25
26
8e748b3e
VK
27//
28// Wrapper for client library debug callback
29//
30
31static void ClientDebugCallback(char *pszMsg)
32{
33 theApp.DebugCallback(pszMsg);
34}
35
36
3bf7e95e
VK
37//
38// CConsoleApp
39//
40
41BEGIN_MESSAGE_MAP(CConsoleApp, CWinApp)
42 //{{AFX_MSG_MAP(CConsoleApp)
43 ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
44 ON_COMMAND(ID_VIEW_CONTROLPANEL, OnViewControlpanel)
45 ON_COMMAND(ID_VIEW_EVENTS, OnViewEvents)
46 ON_COMMAND(ID_VIEW_MAP, OnViewMap)
47 ON_COMMAND(ID_CONNECT_TO_SERVER, OnConnectToServer)
48 ON_COMMAND(ID_VIEW_OBJECTBROWSER, OnViewObjectbrowser)
a5f8f9b0 49 ON_COMMAND(ID_CONTROLPANEL_EVENTS, OnControlpanelEvents)
8e748b3e 50 ON_COMMAND(ID_VIEW_DEBUG, OnViewDebug)
417924d6 51 ON_COMMAND(ID_CONTROLPANEL_USERS, OnControlpanelUsers)
946d48b3 52 ON_COMMAND(ID_VIEW_NETWORKSUMMARY, OnViewNetworksummary)
3bf7e95e
VK
53 //}}AFX_MSG_MAP
54END_MESSAGE_MAP()
55
56
57//
58// CConsoleApp construction
59//
60
61CConsoleApp::CConsoleApp()
62{
63 m_bCtrlPanelActive = FALSE;
64 m_bEventBrowserActive = FALSE;
a5f8f9b0 65 m_bEventEditorActive = FALSE;
417924d6 66 m_bUserEditorActive = FALSE;
3bf7e95e 67 m_bObjectBrowserActive = FALSE;
8e748b3e 68 m_bDebugWindowActive = FALSE;
946d48b3 69 m_bNetSummaryActive = FALSE;
3bf7e95e 70 m_dwClientState = STATE_DISCONNECTED;
f6915462 71 memset(m_openDCEditors, 0, sizeof(DC_EDITOR) * MAX_DC_EDITORS);
3bf7e95e
VK
72}
73
999bd324
VK
74
75//
76// CConsoleApp destruction
77//
78
79CConsoleApp::~CConsoleApp()
80{
999bd324
VK
81}
82
83
3bf7e95e
VK
84//
85// The one and only CConsoleApp object
86//
87
88CConsoleApp theApp;
89
90
91//
92// CConsoleApp initialization
93//
94
95BOOL CConsoleApp::InitInstance()
96{
97 BOOL bSetWindowPos;
98 DWORD dwBytes;
99 BYTE *pData;
8e748b3e 100 HMENU hMenu;
3bf7e95e
VK
101
102 if (!AfxSocketInit())
103 {
104 AfxMessageBox(IDP_SOCKETS_INIT_FAILED, MB_OK | MB_ICONSTOP);
105 return FALSE;
106 }
107
108 if (!NXCInitialize())
109 {
110 AfxMessageBox(IDS_NXC_INIT_FAILED, MB_OK | MB_ICONSTOP);
111 return FALSE;
112 }
113 NXCSetEventHandler(ClientEventHandler);
114
115 AfxEnableControlContainer();
116
117 // Standard initialization
118 // If you are not using these features and wish to reduce the size
119 // of your final executable, you should remove from the following
120 // the specific initialization routines you do not need.
121
122#ifdef _AFXDLL
123 Enable3dControls(); // Call this when using MFC in a shared DLL
124#else
125 Enable3dControlsStatic(); // Call this when linking to MFC statically
126#endif
127
128 // Change the registry key under which our settings are stored.
129 SetRegistryKey(_T("NetXMS"));
130
131 // To create the main window, this code creates a new frame window
132 // object and then sets it as the application's main window object.
133
134 CMDIFrameWnd* pFrame = new CMainFrame;
135 m_pMainWnd = pFrame;
136
137 // create main MDI frame window
138 if (!pFrame->LoadFrame(IDR_MAINFRAME))
139 return FALSE;
140
790cd256
VK
141 // Load context menus
142 if (!m_ctxMenu.LoadMenu(IDM_CONTEXT))
143 MessageBox(NULL, "FAILED", "", 0);
144
8e748b3e
VK
145 // Load shared MDI menus and accelerator table
146 HINSTANCE hInstance = AfxGetResourceHandle();
147
148 hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDM_VIEW_SPECIFIC));
149
150 m_hMDIMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MAINFRAME));
151 InsertMenu(m_hMDIMenu, 3, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
152
153 m_hEventBrowserMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MAINFRAME));
154 InsertMenu(m_hEventBrowserMenu, 3, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
155 InsertMenu(m_hEventBrowserMenu, 3, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 1), "&Event");
156
2060ba91
VK
157 m_hObjectBrowserMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MAINFRAME));
158 InsertMenu(m_hObjectBrowserMenu, 3, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
159 InsertMenu(m_hObjectBrowserMenu, 3, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 2), "&Object");
160
cad81e33
VK
161 m_hUserEditorMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MAINFRAME));
162 InsertMenu(m_hUserEditorMenu, 3, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
163 InsertMenu(m_hUserEditorMenu, 3, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 3), "&User");
164
8e748b3e
VK
165 m_hMDIAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_MDI_DEFAULT));
166 m_hEventBrowserAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_MDI_DEFAULT));
2060ba91 167 m_hObjectBrowserAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_OBJECT_BROWSER));
cad81e33 168 m_hUserEditorAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_MDI_DEFAULT));
3bf7e95e
VK
169
170 // Load configuration from registry
171 dwBytes = sizeof(WINDOWPLACEMENT);
172 bSetWindowPos = GetProfileBinary(_T("General"), _T("WindowPlacement"),
173 &pData, (UINT *)&dwBytes);
174 strcpy(g_szServer, (LPCTSTR)GetProfileString(_T("Connection"), _T("Server"), _T("localhost")));
175 strcpy(g_szLogin, (LPCTSTR)GetProfileString(_T("Connection"), _T("Login"), NULL));
176
177 // The main window has been initialized, so show and update it.
178 if (bSetWindowPos)
179 {
180 pFrame->SetWindowPlacement((WINDOWPLACEMENT *)pData);
181 if (pFrame->IsIconic())
182 pFrame->ShowWindow(SW_RESTORE);
183 }
184 else
185 {
186 pFrame->ShowWindow(m_nCmdShow);
187 }
188 pFrame->UpdateWindow();
189 pFrame->PostMessage(WM_COMMAND, ID_CONNECT_TO_SERVER, 0);
190
191 return TRUE;
192}
193
194/////////////////////////////////////////////////////////////////////////////
195// CConsoleApp message handlers
196
197int CConsoleApp::ExitInstance()
198{
8e748b3e
VK
199 NXCSetDebugCallback(NULL);
200 NXCDisconnect();
201
3bf7e95e 202 // Free resources
8e748b3e
VK
203 SafeFreeResource(m_hMDIMenu);
204 SafeFreeResource(m_hMDIAccel);
205 SafeFreeResource(m_hEventBrowserMenu);
206 SafeFreeResource(m_hEventBrowserAccel);
3bf7e95e
VK
207
208 return CWinApp::ExitInstance();
209}
210
211
212/////////////////////////////////////////////////////////////////////////////
213// CAboutDlg dialog used for App About
214
215class CAboutDlg : public CDialog
216{
217public:
218 CAboutDlg();
219
220// Dialog Data
221 //{{AFX_DATA(CAboutDlg)
222 enum { IDD = IDD_ABOUTBOX };
223 //}}AFX_DATA
224
225 // ClassWizard generated virtual function overrides
226 //{{AFX_VIRTUAL(CAboutDlg)
227 protected:
228 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
229 //}}AFX_VIRTUAL
230
231// Implementation
232protected:
233 //{{AFX_MSG(CAboutDlg)
234 // No message handlers
235 //}}AFX_MSG
236 DECLARE_MESSAGE_MAP()
237};
238
239CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
240{
241 //{{AFX_DATA_INIT(CAboutDlg)
242 //}}AFX_DATA_INIT
243}
244
245void CAboutDlg::DoDataExchange(CDataExchange* pDX)
246{
247 CDialog::DoDataExchange(pDX);
248 //{{AFX_DATA_MAP(CAboutDlg)
249 //}}AFX_DATA_MAP
250}
251
252BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
253 //{{AFX_MSG_MAP(CAboutDlg)
254 // No message handlers
255 //}}AFX_MSG_MAP
256END_MESSAGE_MAP()
257
258// App command to run the dialog
259void CConsoleApp::OnAppAbout()
260{
261 CAboutDlg aboutDlg;
262 aboutDlg.DoModal();
263}
264
265/////////////////////////////////////////////////////////////////////////////
266// CConsoleApp message handlers
267
268
269void CConsoleApp::OnViewControlpanel()
270{
271 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
272
273 // create a new MDI child window or open existing
274 if (m_bCtrlPanelActive)
275 m_pwndCtrlPanel->BringWindowToTop();
276 else
277 pFrame->CreateNewChild(
8e748b3e 278 RUNTIME_CLASS(CControlPanel), IDR_CTRLPANEL, m_hMDIMenu, m_hMDIAccel);
3bf7e95e
VK
279}
280
281
282//
283// This method called when new view is created
284//
285
f6915462 286void CConsoleApp::OnViewCreate(DWORD dwView, CWnd *pWnd, DWORD dwArg)
3bf7e95e 287{
f6915462
VK
288 DWORD i;
289
3bf7e95e
VK
290 switch(dwView)
291 {
292 case IDR_CTRLPANEL:
293 m_bCtrlPanelActive = TRUE;
294 m_pwndCtrlPanel = pWnd;
295 break;
296 case IDR_EVENTS:
297 m_bEventBrowserActive = TRUE;
298 m_pwndEventBrowser = (CEventBrowser *)pWnd;
299 break;
300 case IDR_OBJECTS:
301 m_bObjectBrowserActive = TRUE;
302 m_pwndObjectBrowser = pWnd;
303 break;
a5f8f9b0
VK
304 case IDR_EVENT_EDITOR:
305 m_bEventEditorActive = TRUE;
306 m_pwndEventEditor = (CEventEditor *)pWnd;
307 break;
417924d6
VK
308 case IDR_USER_EDITOR:
309 m_bUserEditorActive = TRUE;
310 m_pwndUserEditor = (CUserEditor *)pWnd;
311 break;
8e748b3e
VK
312 case IDR_DEBUG_WINDOW:
313 m_bDebugWindowActive = TRUE;
314 m_pwndDebugWindow = (CDebugFrame *)pWnd;
315 NXCSetDebugCallback(ClientDebugCallback);
316 break;
946d48b3
VK
317 case IDR_NETWORK_SUMMARY:
318 m_bNetSummaryActive = TRUE;
319 m_pwndNetSummary = (CNetSummaryFrame *)pWnd;
320 break;
f6915462
VK
321 case IDR_DC_EDITOR:
322 // Register new DC editor
323 for(i = 0; i < MAX_DC_EDITORS; i++)
324 if (m_openDCEditors[i].pWnd == NULL)
325 {
326 m_openDCEditors[i].pWnd = pWnd;
327 m_openDCEditors[i].dwNodeId = dwArg;
328 break;
329 }
330 break;
3bf7e95e
VK
331 default:
332 break;
333 }
334}
335
336
337//
338// This method called when view is destroyed
339//
340
f6915462 341void CConsoleApp::OnViewDestroy(DWORD dwView, CWnd *pWnd, DWORD dwArg)
3bf7e95e 342{
f6915462
VK
343 DWORD i;
344
3bf7e95e
VK
345 switch(dwView)
346 {
347 case IDR_CTRLPANEL:
348 m_bCtrlPanelActive = FALSE;
349 break;
350 case IDR_EVENTS:
351 m_bEventBrowserActive = FALSE;
352 break;
353 case IDR_OBJECTS:
354 m_bObjectBrowserActive = FALSE;
355 break;
a5f8f9b0
VK
356 case IDR_EVENT_EDITOR:
357 m_bEventEditorActive = FALSE;
358 break;
417924d6
VK
359 case IDR_USER_EDITOR:
360 m_bUserEditorActive = FALSE;
361 break;
8e748b3e
VK
362 case IDR_DEBUG_WINDOW:
363 m_bDebugWindowActive = FALSE;
364 NXCSetDebugCallback(NULL);
365 break;
946d48b3
VK
366 case IDR_NETWORK_SUMMARY:
367 m_bNetSummaryActive = FALSE;
368 break;
f6915462
VK
369 case IDR_DC_EDITOR:
370 // Unregister DC editor
371 for(i = 0; i < MAX_DC_EDITORS; i++)
372 if (m_openDCEditors[i].pWnd == pWnd)
373 {
374 m_openDCEditors[i].pWnd = NULL;
375 m_openDCEditors[i].dwNodeId = 0;
376 break;
377 }
378 break;
3bf7e95e
VK
379 default:
380 break;
381 }
382}
383
384void CConsoleApp::OnViewEvents()
385{
386 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
387
388 // create a new MDI child window or open existing
389 if (m_bEventBrowserActive)
390 m_pwndEventBrowser->BringWindowToTop();
391 else
392 pFrame->CreateNewChild(
8e748b3e 393 RUNTIME_CLASS(CEventBrowser), IDR_EVENTS, m_hEventBrowserMenu, m_hEventBrowserAccel);
3bf7e95e
VK
394}
395
396void CConsoleApp::OnViewMap()
397{
398 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
399
400 // create a new MDI child window
f7a7f8e4 401 pFrame->CreateNewChild(RUNTIME_CLASS(CMapFrame), IDR_MAPFRAME, m_hMDIMenu, m_hMDIAccel);
3bf7e95e
VK
402}
403
404void CConsoleApp::OnConnectToServer()
405{
406 CLoginDialog dlgLogin;
f7a7f8e4 407 DWORD dwResult;
3bf7e95e
VK
408
409 dlgLogin.m_szServer = g_szServer;
410 dlgLogin.m_szLogin = g_szLogin;
f7a7f8e4 411 do
3bf7e95e
VK
412 {
413 if (dlgLogin.DoModal() != IDOK)
414 {
415 PostQuitMessage(1);
416 break;
417 }
418 strcpy(g_szServer, (LPCTSTR)dlgLogin.m_szServer);
419 strcpy(g_szLogin, (LPCTSTR)dlgLogin.m_szLogin);
420 strcpy(g_szPassword, (LPCTSTR)dlgLogin.m_szPassword);
421
422 // Save last connection parameters
423 WriteProfileString(_T("Connection"), _T("Server"), g_szServer);
424 WriteProfileString(_T("Connection"), _T("Login"), g_szLogin);
425
426 // Initiate connection
f7a7f8e4
VK
427 dwResult = DoLogin();
428 if (dwResult != RCC_SUCCESS)
3bf7e95e 429 {
f7a7f8e4
VK
430 char szBuffer[256];
431
432 sprintf(szBuffer, "Unable to connect: %s", NXCGetErrorText(dwResult));
433 m_pMainWnd->MessageBox(szBuffer, "Connection error", MB_OK | MB_ICONSTOP);
3bf7e95e
VK
434 }
435 }
f7a7f8e4 436 while(dwResult != RCC_SUCCESS);
3bf7e95e
VK
437}
438
439void CConsoleApp::OnViewObjectbrowser()
440{
441 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
442
443 // create a new MDI child window or open existing
444 if (m_bObjectBrowserActive)
445 m_pwndObjectBrowser->BringWindowToTop();
446 else
447 pFrame->CreateNewChild(
2060ba91 448 RUNTIME_CLASS(CObjectBrowser), IDR_OBJECTS, m_hObjectBrowserMenu, m_hObjectBrowserAccel);
3bf7e95e
VK
449}
450
451
452//
453// Event handler for client libray events
454//
455
456void CConsoleApp::EventHandler(DWORD dwEvent, DWORD dwCode, void *pArg)
457{
3bf7e95e
VK
458 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
459
460 switch(dwEvent)
461 {
462 case NXC_EVENT_STATE_CHANGED:
463 switch(dwCode)
464 {
465 case STATE_CONNECTING:
3bf7e95e
VK
466 break;
467 case STATE_IDLE:
3bf7e95e
VK
468 if ((m_bEventBrowserActive) && (m_dwClientState == STATE_SYNC_EVENTS))
469 m_pwndEventBrowser->EnableDisplay(TRUE);
470 break;
471 case STATE_DISCONNECTED:
3bf7e95e
VK
472 break;
473 case STATE_SYNC_EVENTS:
474 if (m_bEventBrowserActive)
475 m_pwndEventBrowser->EnableDisplay(FALSE);
476 break;
477 default:
478 break;
479 }
480 m_dwClientState = dwCode;
481 break;
3bf7e95e
VK
482 case NXC_EVENT_NEW_ELOG_RECORD:
483 if (m_bEventBrowserActive)
484 m_pwndEventBrowser->AddEvent((NXC_EVENT *)pArg);
485 MemFree(pArg);
3bf7e95e 486 break;
89d4d2a2
VK
487 case NXC_EVENT_OBJECT_CHANGED:
488 ((CMainFrame *)m_pMainWnd)->PostMessage(WM_OBJECT_CHANGE, dwCode, (LPARAM)pArg);
489 break;
fadbdf37
VK
490 case NXC_EVENT_USER_DB_CHANGED:
491 ((CMainFrame *)m_pMainWnd)->PostMessage(WM_USERDB_CHANGE, dwCode, (LPARAM)pArg);
492 break;
3bf7e95e
VK
493 default:
494 break;
495 }
496}
a5f8f9b0 497
999bd324
VK
498
499//
500// Handler for WM_COMMAND(ID_CONTROLPANEL_EVENTS) message
501//
502
a5f8f9b0
VK
503void CConsoleApp::OnControlpanelEvents()
504{
505 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
506
507 // create a new MDI child window or open existing
508 if (m_bEventEditorActive)
509 m_pwndEventEditor->BringWindowToTop();
510 else
417924d6
VK
511 {
512 DWORD dwResult;
513
f7a7f8e4 514 dwResult = DoRequest(NXCOpenEventDB, "Opening event configuration database...");
417924d6
VK
515 if (dwResult == RCC_SUCCESS)
516 {
517 pFrame->CreateNewChild(
518 RUNTIME_CLASS(CEventEditor), IDR_EVENT_EDITOR, m_hMDIMenu, m_hMDIAccel);
519 }
520 else
521 {
522 char szBuffer[256];
523
524 sprintf(szBuffer, "Unable to open event configuration database:\n%s", NXCGetErrorText(dwResult));
525 GetMainWnd()->MessageBox(szBuffer, "Error", MB_ICONSTOP);
526 }
527 }
528}
529
530
531//
532// Handler for WM_COMMAND(ID_CONTROLPANEL_USERS) message
533//
534
535void CConsoleApp::OnControlpanelUsers()
536{
537 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
538
539 // create a new MDI child window or open existing
540 if (m_bUserEditorActive)
541 m_pwndUserEditor->BringWindowToTop();
542 else
543 {
544 DWORD dwResult;
545
f7a7f8e4 546 dwResult = DoRequest(NXCLockUserDB, "Locking user database...");
417924d6
VK
547 if (dwResult == RCC_SUCCESS)
548 {
549 pFrame->CreateNewChild(
cad81e33 550 RUNTIME_CLASS(CUserEditor), IDR_USER_EDITOR, m_hUserEditorMenu, m_hUserEditorAccel);
417924d6
VK
551 }
552 else
553 {
554 char szBuffer[256];
555
556 sprintf(szBuffer, "Unable to lock user database:\n%s", NXCGetErrorText(dwResult));
557 GetMainWnd()->MessageBox(szBuffer, "Error", MB_ICONSTOP);
558 }
559 }
a5f8f9b0
VK
560}
561
562
8e748b3e
VK
563//
564// Handler for WM_COMMAND::ID_VIEW_DEBUG message
565//
566
567void CConsoleApp::OnViewDebug()
568{
569 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
570
571 // create a new MDI child window or open existing
572 if (m_bDebugWindowActive)
573 m_pwndDebugWindow->BringWindowToTop();
574 else
575 pFrame->CreateNewChild(
576 RUNTIME_CLASS(CDebugFrame), IDR_DEBUG_WINDOW, m_hMDIMenu, m_hMDIAccel);
577}
89d4d2a2
VK
578
579
580//
581// Print debug information
582//
583
584void CConsoleApp::DebugPrintf(char *szFormat, ...)
585{
586 if (m_bDebugWindowActive)
587 {
588 char szBuffer[1024];
589 va_list args;
590
591 va_start(args, szFormat);
592 vsprintf(szBuffer, szFormat, args);
593 va_end(args);
594
595 m_pwndDebugWindow->AddMessage(szBuffer);
596 }
597}
2057008d
VK
598
599
600//
601// Edit properties of specific object
602//
603
604void CConsoleApp::ObjectProperties(DWORD dwObjectId)
605{
606 CObjectPropSheet wndPropSheet("Object Properties", GetMainWnd(), 0);
607 CNodePropsGeneral wndNodeGeneral;
8e2809bb 608 CObjectPropsGeneral wndObjectGeneral;
2057008d 609 CObjectPropCaps wndObjectCaps;
8e2809bb 610 CObjectPropsSecurity wndObjectSecurity;
2057008d
VK
611 NXC_OBJECT *pObject;
612 char szBuffer[32];
613
614 pObject = NXCFindObjectById(dwObjectId);
615 if (pObject != NULL)
616 {
617 // Create "General" tab
8e2809bb 618 if (pObject->iClass == OBJECT_NODE)
2057008d 619 {
8e2809bb
VK
620 wndNodeGeneral.m_dwObjectId = dwObjectId;
621 wndNodeGeneral.m_strName = pObject->szName;
622 wndNodeGeneral.m_strOID = pObject->node.szObjectId;
623 wndNodeGeneral.m_strPrimaryIp = IpToStr(pObject->dwIpAddr, szBuffer);
624 wndNodeGeneral.m_iAgentPort = (int)pObject->node.wAgentPort;
625 wndNodeGeneral.m_strCommunity = pObject->node.szCommunityString;
626 wndNodeGeneral.m_iAuthType = pObject->node.wAuthMethod;
627 wndNodeGeneral.m_strSecret = pObject->node.szSharedSecret;
628 wndPropSheet.AddPage(&wndNodeGeneral);
629 }
630 else
631 {
632 wndObjectGeneral.m_dwObjectId = dwObjectId;
633 wndObjectGeneral.m_strClass = g_szObjectClass[pObject->iClass];
634 wndObjectGeneral.m_strName = pObject->szName;
635 wndPropSheet.AddPage(&wndObjectGeneral);
2057008d
VK
636 }
637
638 // Create tabs specific for node objects
639 if (pObject->iClass == OBJECT_NODE)
640 {
641 // Create "Capabilities" tab
642 wndObjectCaps.m_pObject = pObject;
643 wndPropSheet.AddPage(&wndObjectCaps);
644 }
645
f6d9527a 646 // Create "Security" tab
8e2809bb
VK
647 wndObjectSecurity.m_pObject = pObject;
648 wndObjectSecurity.m_bInheritRights = pObject->bInheritRights;
649 wndPropSheet.AddPage(&wndObjectSecurity);
f6d9527a
VK
650
651 wndPropSheet.SetObject(pObject);
652 if (wndPropSheet.DoModal() == IDOK)
653 wndPropSheet.SaveObjectChanges();
2057008d
VK
654 }
655}
790cd256
VK
656
657
658//
659// Get context menu
660//
661
662CMenu *CConsoleApp::GetContextMenu(int iIndex)
663{
664 return m_ctxMenu.GetSubMenu(iIndex);
665}
946d48b3
VK
666
667
668//
669// Start data collection editor for specific object
670//
671
672void CConsoleApp::StartObjectDCEditor(NXC_OBJECT *pObject)
673{
223ffcfa
VK
674 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
675 NXC_DCI_LIST *pItemList;
676 DWORD dwResult;
f6915462 677 CDataCollectionEditor *pWnd;
946d48b3 678
f6915462
VK
679 pWnd = (CDataCollectionEditor *)FindOpenDCEditor(pObject->dwId);
680 if (pWnd == NULL)
223ffcfa 681 {
f6915462
VK
682 dwResult = DoRequestArg2(NXCOpenNodeDCIList, (void *)pObject->dwId,
683 &pItemList, "Loading node's data collection information...");
684 if (dwResult == RCC_SUCCESS)
685 {
686 CCreateContext context;
687
688 pWnd = new CDataCollectionEditor(pItemList);
689
690 // load the frame
691 context.m_pCurrentFrame = pFrame;
692
693 if (pWnd->LoadFrame(IDR_DC_EDITOR, WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL, &context))
694 {
695 CString strFullString, strTitle;
696
697 if (strFullString.LoadString(IDR_DC_EDITOR))
698 AfxExtractSubString(strTitle, strFullString, CDocTemplate::docName);
699
700 // add node name to title
701 strTitle += " - [";
702 strTitle += pObject->szName;
703 strTitle += "]";
704
705 // set the handles and redraw the frame and parent
706 pWnd->SetHandles(m_hMDIMenu, m_hMDIAccel);
707 pWnd->SetTitle(strTitle);
708 pWnd->InitialUpdateFrame(NULL, TRUE);
709 }
710 else
711 {
712 delete pWnd;
713 }
714 }
715 else
716 {
717 char szBuffer[256];
718
719 sprintf(szBuffer, "Unable to load data collection information for node:\n%s",
720 NXCGetErrorText(dwResult));
721 m_pMainWnd->MessageBox(szBuffer, "Error", MB_ICONSTOP);
722 }
223ffcfa
VK
723 }
724 else
725 {
f6915462
VK
726 // Data collection editor already open, activate it
727 pWnd->BringWindowToTop();
223ffcfa 728 }
946d48b3
VK
729}
730
731
732//
733// Show network summary view
734//
735
736void CConsoleApp::OnViewNetworksummary()
737{
738 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
739
740 // create a new MDI child window or open existing
741 if (m_bNetSummaryActive)
742 m_pwndNetSummary->BringWindowToTop();
743 else
744 pFrame->CreateNewChild(
745 RUNTIME_CLASS(CNetSummaryFrame), IDR_NETWORK_SUMMARY, m_hMDIMenu, m_hMDIAccel);
746}
223ffcfa
VK
747
748
749//
750// Set object's management status
751//
752
753void CConsoleApp::SetObjectMgmtStatus(NXC_OBJECT *pObject, BOOL bIsManaged)
754{
755 DWORD dwResult;
756
757 dwResult = DoRequestArg2(NXCSetObjectMgmtStatus, (void *)pObject->dwId,
758 (void *)bIsManaged, "Changing object status...");
759 if (dwResult != RCC_SUCCESS)
760 {
761 char szBuffer[256];
762
763 sprintf(szBuffer, "Unable to change management status for object %s:\n%s",
764 pObject->szName, NXCGetErrorText(dwResult));
765 GetMainWnd()->MessageBox(szBuffer, "Error", MB_ICONSTOP);
766 }
767}
f6915462
VK
768
769
770//
771// Find open data collection editor for given node, if any
772//
773
774CWnd *CConsoleApp::FindOpenDCEditor(DWORD dwNodeId)
775{
776 DWORD i;
777
778 for(i = 0; i < MAX_DC_EDITORS; i++)
779 if (m_openDCEditors[i].dwNodeId == dwNodeId)
780 return m_openDCEditors[i].pWnd;
781 return NULL;
782}