[See comments to previous commits]
[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
1c0c8dde
VK
165 m_hDCEditorMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MAINFRAME));
166 InsertMenu(m_hDCEditorMenu, 3, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
167 InsertMenu(m_hDCEditorMenu, 3, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 4), "&Item");
168
8e748b3e
VK
169 m_hMDIAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_MDI_DEFAULT));
170 m_hEventBrowserAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_MDI_DEFAULT));
2060ba91 171 m_hObjectBrowserAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_OBJECT_BROWSER));
cad81e33 172 m_hUserEditorAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_MDI_DEFAULT));
1c0c8dde 173 m_hDCEditorAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_MDI_DEFAULT));
3bf7e95e
VK
174
175 // Load configuration from registry
176 dwBytes = sizeof(WINDOWPLACEMENT);
177 bSetWindowPos = GetProfileBinary(_T("General"), _T("WindowPlacement"),
178 &pData, (UINT *)&dwBytes);
179 strcpy(g_szServer, (LPCTSTR)GetProfileString(_T("Connection"), _T("Server"), _T("localhost")));
180 strcpy(g_szLogin, (LPCTSTR)GetProfileString(_T("Connection"), _T("Login"), NULL));
181
182 // The main window has been initialized, so show and update it.
183 if (bSetWindowPos)
184 {
185 pFrame->SetWindowPlacement((WINDOWPLACEMENT *)pData);
186 if (pFrame->IsIconic())
187 pFrame->ShowWindow(SW_RESTORE);
188 }
189 else
190 {
191 pFrame->ShowWindow(m_nCmdShow);
192 }
193 pFrame->UpdateWindow();
194 pFrame->PostMessage(WM_COMMAND, ID_CONNECT_TO_SERVER, 0);
195
196 return TRUE;
197}
198
199/////////////////////////////////////////////////////////////////////////////
200// CConsoleApp message handlers
201
202int CConsoleApp::ExitInstance()
203{
8e748b3e
VK
204 NXCSetDebugCallback(NULL);
205 NXCDisconnect();
206
3bf7e95e 207 // Free resources
8e748b3e
VK
208 SafeFreeResource(m_hMDIMenu);
209 SafeFreeResource(m_hMDIAccel);
210 SafeFreeResource(m_hEventBrowserMenu);
211 SafeFreeResource(m_hEventBrowserAccel);
1c0c8dde
VK
212 SafeFreeResource(m_hUserEditorMenu);
213 SafeFreeResource(m_hUserEditorAccel);
214 SafeFreeResource(m_hDCEditorMenu);
215 SafeFreeResource(m_hDCEditorAccel);
3bf7e95e
VK
216
217 return CWinApp::ExitInstance();
218}
219
220
221/////////////////////////////////////////////////////////////////////////////
222// CAboutDlg dialog used for App About
223
224class CAboutDlg : public CDialog
225{
226public:
227 CAboutDlg();
228
229// Dialog Data
230 //{{AFX_DATA(CAboutDlg)
231 enum { IDD = IDD_ABOUTBOX };
232 //}}AFX_DATA
233
234 // ClassWizard generated virtual function overrides
235 //{{AFX_VIRTUAL(CAboutDlg)
236 protected:
237 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
238 //}}AFX_VIRTUAL
239
240// Implementation
241protected:
242 //{{AFX_MSG(CAboutDlg)
243 // No message handlers
244 //}}AFX_MSG
245 DECLARE_MESSAGE_MAP()
246};
247
248CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
249{
250 //{{AFX_DATA_INIT(CAboutDlg)
251 //}}AFX_DATA_INIT
252}
253
254void CAboutDlg::DoDataExchange(CDataExchange* pDX)
255{
256 CDialog::DoDataExchange(pDX);
257 //{{AFX_DATA_MAP(CAboutDlg)
258 //}}AFX_DATA_MAP
259}
260
261BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
262 //{{AFX_MSG_MAP(CAboutDlg)
263 // No message handlers
264 //}}AFX_MSG_MAP
265END_MESSAGE_MAP()
266
267// App command to run the dialog
268void CConsoleApp::OnAppAbout()
269{
270 CAboutDlg aboutDlg;
271 aboutDlg.DoModal();
272}
273
274/////////////////////////////////////////////////////////////////////////////
275// CConsoleApp message handlers
276
277
278void CConsoleApp::OnViewControlpanel()
279{
280 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
281
282 // create a new MDI child window or open existing
283 if (m_bCtrlPanelActive)
284 m_pwndCtrlPanel->BringWindowToTop();
285 else
286 pFrame->CreateNewChild(
8e748b3e 287 RUNTIME_CLASS(CControlPanel), IDR_CTRLPANEL, m_hMDIMenu, m_hMDIAccel);
3bf7e95e
VK
288}
289
290
291//
292// This method called when new view is created
293//
294
f6915462 295void CConsoleApp::OnViewCreate(DWORD dwView, CWnd *pWnd, DWORD dwArg)
3bf7e95e 296{
f6915462
VK
297 DWORD i;
298
3bf7e95e
VK
299 switch(dwView)
300 {
301 case IDR_CTRLPANEL:
302 m_bCtrlPanelActive = TRUE;
303 m_pwndCtrlPanel = pWnd;
304 break;
305 case IDR_EVENTS:
306 m_bEventBrowserActive = TRUE;
307 m_pwndEventBrowser = (CEventBrowser *)pWnd;
308 break;
309 case IDR_OBJECTS:
310 m_bObjectBrowserActive = TRUE;
311 m_pwndObjectBrowser = pWnd;
312 break;
a5f8f9b0
VK
313 case IDR_EVENT_EDITOR:
314 m_bEventEditorActive = TRUE;
315 m_pwndEventEditor = (CEventEditor *)pWnd;
316 break;
417924d6
VK
317 case IDR_USER_EDITOR:
318 m_bUserEditorActive = TRUE;
319 m_pwndUserEditor = (CUserEditor *)pWnd;
320 break;
8e748b3e
VK
321 case IDR_DEBUG_WINDOW:
322 m_bDebugWindowActive = TRUE;
323 m_pwndDebugWindow = (CDebugFrame *)pWnd;
324 NXCSetDebugCallback(ClientDebugCallback);
325 break;
946d48b3
VK
326 case IDR_NETWORK_SUMMARY:
327 m_bNetSummaryActive = TRUE;
328 m_pwndNetSummary = (CNetSummaryFrame *)pWnd;
329 break;
f6915462
VK
330 case IDR_DC_EDITOR:
331 // Register new DC editor
332 for(i = 0; i < MAX_DC_EDITORS; i++)
333 if (m_openDCEditors[i].pWnd == NULL)
334 {
335 m_openDCEditors[i].pWnd = pWnd;
336 m_openDCEditors[i].dwNodeId = dwArg;
337 break;
338 }
339 break;
3bf7e95e
VK
340 default:
341 break;
342 }
343}
344
345
346//
347// This method called when view is destroyed
348//
349
f6915462 350void CConsoleApp::OnViewDestroy(DWORD dwView, CWnd *pWnd, DWORD dwArg)
3bf7e95e 351{
f6915462
VK
352 DWORD i;
353
3bf7e95e
VK
354 switch(dwView)
355 {
356 case IDR_CTRLPANEL:
357 m_bCtrlPanelActive = FALSE;
358 break;
359 case IDR_EVENTS:
360 m_bEventBrowserActive = FALSE;
361 break;
362 case IDR_OBJECTS:
363 m_bObjectBrowserActive = FALSE;
364 break;
a5f8f9b0
VK
365 case IDR_EVENT_EDITOR:
366 m_bEventEditorActive = FALSE;
367 break;
417924d6
VK
368 case IDR_USER_EDITOR:
369 m_bUserEditorActive = FALSE;
370 break;
8e748b3e
VK
371 case IDR_DEBUG_WINDOW:
372 m_bDebugWindowActive = FALSE;
373 NXCSetDebugCallback(NULL);
374 break;
946d48b3
VK
375 case IDR_NETWORK_SUMMARY:
376 m_bNetSummaryActive = FALSE;
377 break;
f6915462
VK
378 case IDR_DC_EDITOR:
379 // Unregister DC editor
380 for(i = 0; i < MAX_DC_EDITORS; i++)
381 if (m_openDCEditors[i].pWnd == pWnd)
382 {
383 m_openDCEditors[i].pWnd = NULL;
384 m_openDCEditors[i].dwNodeId = 0;
385 break;
386 }
387 break;
3bf7e95e
VK
388 default:
389 break;
390 }
391}
392
7ac0c0a8
VK
393
394//
395// WM_COMMAND::ID_VIEW_EVENTS message handler
396//
397
3bf7e95e
VK
398void CConsoleApp::OnViewEvents()
399{
400 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
401
402 // create a new MDI child window or open existing
403 if (m_bEventBrowserActive)
404 m_pwndEventBrowser->BringWindowToTop();
405 else
406 pFrame->CreateNewChild(
8e748b3e 407 RUNTIME_CLASS(CEventBrowser), IDR_EVENTS, m_hEventBrowserMenu, m_hEventBrowserAccel);
3bf7e95e
VK
408}
409
7ac0c0a8
VK
410
411//
412// WM_COMMAND::ID_VIEW_MAP message handler
413//
414
3bf7e95e
VK
415void CConsoleApp::OnViewMap()
416{
417 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
418
419 // create a new MDI child window
f7a7f8e4 420 pFrame->CreateNewChild(RUNTIME_CLASS(CMapFrame), IDR_MAPFRAME, m_hMDIMenu, m_hMDIAccel);
3bf7e95e
VK
421}
422
7ac0c0a8
VK
423
424//
425// WM_COMMAND::ID_CONNECT_TO_SERVER message handler
426//
427
3bf7e95e
VK
428void CConsoleApp::OnConnectToServer()
429{
430 CLoginDialog dlgLogin;
f7a7f8e4 431 DWORD dwResult;
3bf7e95e
VK
432
433 dlgLogin.m_szServer = g_szServer;
434 dlgLogin.m_szLogin = g_szLogin;
f7a7f8e4 435 do
3bf7e95e
VK
436 {
437 if (dlgLogin.DoModal() != IDOK)
438 {
439 PostQuitMessage(1);
440 break;
441 }
442 strcpy(g_szServer, (LPCTSTR)dlgLogin.m_szServer);
443 strcpy(g_szLogin, (LPCTSTR)dlgLogin.m_szLogin);
444 strcpy(g_szPassword, (LPCTSTR)dlgLogin.m_szPassword);
445
446 // Save last connection parameters
447 WriteProfileString(_T("Connection"), _T("Server"), g_szServer);
448 WriteProfileString(_T("Connection"), _T("Login"), g_szLogin);
449
450 // Initiate connection
f7a7f8e4
VK
451 dwResult = DoLogin();
452 if (dwResult != RCC_SUCCESS)
7ac0c0a8 453 ErrorBox(dwResult, "Unable to connect: %s", "Connection error");
3bf7e95e 454 }
f7a7f8e4 455 while(dwResult != RCC_SUCCESS);
3bf7e95e
VK
456}
457
7ac0c0a8
VK
458
459//
460// WM_COMMAND::ID_VIEW_OBJECTBROWSER message handler
461//
462
3bf7e95e
VK
463void CConsoleApp::OnViewObjectbrowser()
464{
465 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
466
467 // create a new MDI child window or open existing
468 if (m_bObjectBrowserActive)
469 m_pwndObjectBrowser->BringWindowToTop();
470 else
471 pFrame->CreateNewChild(
2060ba91 472 RUNTIME_CLASS(CObjectBrowser), IDR_OBJECTS, m_hObjectBrowserMenu, m_hObjectBrowserAccel);
3bf7e95e
VK
473}
474
475
476//
477// Event handler for client libray events
478//
479
480void CConsoleApp::EventHandler(DWORD dwEvent, DWORD dwCode, void *pArg)
481{
3bf7e95e
VK
482 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
483
484 switch(dwEvent)
485 {
486 case NXC_EVENT_STATE_CHANGED:
487 switch(dwCode)
488 {
489 case STATE_CONNECTING:
3bf7e95e
VK
490 break;
491 case STATE_IDLE:
3bf7e95e
VK
492 if ((m_bEventBrowserActive) && (m_dwClientState == STATE_SYNC_EVENTS))
493 m_pwndEventBrowser->EnableDisplay(TRUE);
494 break;
495 case STATE_DISCONNECTED:
3bf7e95e
VK
496 break;
497 case STATE_SYNC_EVENTS:
498 if (m_bEventBrowserActive)
499 m_pwndEventBrowser->EnableDisplay(FALSE);
500 break;
501 default:
502 break;
503 }
504 m_dwClientState = dwCode;
505 break;
3bf7e95e
VK
506 case NXC_EVENT_NEW_ELOG_RECORD:
507 if (m_bEventBrowserActive)
508 m_pwndEventBrowser->AddEvent((NXC_EVENT *)pArg);
509 MemFree(pArg);
3bf7e95e 510 break;
89d4d2a2
VK
511 case NXC_EVENT_OBJECT_CHANGED:
512 ((CMainFrame *)m_pMainWnd)->PostMessage(WM_OBJECT_CHANGE, dwCode, (LPARAM)pArg);
513 break;
fadbdf37
VK
514 case NXC_EVENT_USER_DB_CHANGED:
515 ((CMainFrame *)m_pMainWnd)->PostMessage(WM_USERDB_CHANGE, dwCode, (LPARAM)pArg);
516 break;
3bf7e95e
VK
517 default:
518 break;
519 }
520}
a5f8f9b0 521
999bd324
VK
522
523//
524// Handler for WM_COMMAND(ID_CONTROLPANEL_EVENTS) message
525//
526
a5f8f9b0
VK
527void CConsoleApp::OnControlpanelEvents()
528{
529 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
530
531 // create a new MDI child window or open existing
532 if (m_bEventEditorActive)
533 m_pwndEventEditor->BringWindowToTop();
534 else
417924d6
VK
535 {
536 DWORD dwResult;
537
f7a7f8e4 538 dwResult = DoRequest(NXCOpenEventDB, "Opening event configuration database...");
417924d6
VK
539 if (dwResult == RCC_SUCCESS)
540 {
541 pFrame->CreateNewChild(
542 RUNTIME_CLASS(CEventEditor), IDR_EVENT_EDITOR, m_hMDIMenu, m_hMDIAccel);
543 }
544 else
545 {
7ac0c0a8 546 ErrorBox(dwResult, "Unable to open event configuration database:\n%s");
417924d6
VK
547 }
548 }
549}
550
551
552//
7ac0c0a8 553// Handler for WM_COMMAND::ID_CONTROLPANEL_USERS message
417924d6
VK
554//
555
556void CConsoleApp::OnControlpanelUsers()
557{
558 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
559
560 // create a new MDI child window or open existing
561 if (m_bUserEditorActive)
562 m_pwndUserEditor->BringWindowToTop();
563 else
564 {
565 DWORD dwResult;
566
f7a7f8e4 567 dwResult = DoRequest(NXCLockUserDB, "Locking user database...");
417924d6
VK
568 if (dwResult == RCC_SUCCESS)
569 {
570 pFrame->CreateNewChild(
cad81e33 571 RUNTIME_CLASS(CUserEditor), IDR_USER_EDITOR, m_hUserEditorMenu, m_hUserEditorAccel);
417924d6
VK
572 }
573 else
574 {
7ac0c0a8 575 ErrorBox(dwResult, "Unable to lock user database:\n%s");
417924d6
VK
576 }
577 }
a5f8f9b0
VK
578}
579
580
8e748b3e
VK
581//
582// Handler for WM_COMMAND::ID_VIEW_DEBUG message
583//
584
585void CConsoleApp::OnViewDebug()
586{
587 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
588
589 // create a new MDI child window or open existing
590 if (m_bDebugWindowActive)
591 m_pwndDebugWindow->BringWindowToTop();
592 else
593 pFrame->CreateNewChild(
594 RUNTIME_CLASS(CDebugFrame), IDR_DEBUG_WINDOW, m_hMDIMenu, m_hMDIAccel);
595}
89d4d2a2
VK
596
597
598//
599// Print debug information
600//
601
602void CConsoleApp::DebugPrintf(char *szFormat, ...)
603{
604 if (m_bDebugWindowActive)
605 {
606 char szBuffer[1024];
607 va_list args;
608
609 va_start(args, szFormat);
610 vsprintf(szBuffer, szFormat, args);
611 va_end(args);
612
613 m_pwndDebugWindow->AddMessage(szBuffer);
614 }
615}
2057008d
VK
616
617
618//
619// Edit properties of specific object
620//
621
622void CConsoleApp::ObjectProperties(DWORD dwObjectId)
623{
624 CObjectPropSheet wndPropSheet("Object Properties", GetMainWnd(), 0);
625 CNodePropsGeneral wndNodeGeneral;
8e2809bb 626 CObjectPropsGeneral wndObjectGeneral;
2057008d 627 CObjectPropCaps wndObjectCaps;
8e2809bb 628 CObjectPropsSecurity wndObjectSecurity;
2057008d
VK
629 NXC_OBJECT *pObject;
630 char szBuffer[32];
631
632 pObject = NXCFindObjectById(dwObjectId);
633 if (pObject != NULL)
634 {
635 // Create "General" tab
8e2809bb 636 if (pObject->iClass == OBJECT_NODE)
2057008d 637 {
8e2809bb
VK
638 wndNodeGeneral.m_dwObjectId = dwObjectId;
639 wndNodeGeneral.m_strName = pObject->szName;
640 wndNodeGeneral.m_strOID = pObject->node.szObjectId;
641 wndNodeGeneral.m_strPrimaryIp = IpToStr(pObject->dwIpAddr, szBuffer);
642 wndNodeGeneral.m_iAgentPort = (int)pObject->node.wAgentPort;
643 wndNodeGeneral.m_strCommunity = pObject->node.szCommunityString;
644 wndNodeGeneral.m_iAuthType = pObject->node.wAuthMethod;
645 wndNodeGeneral.m_strSecret = pObject->node.szSharedSecret;
646 wndPropSheet.AddPage(&wndNodeGeneral);
647 }
648 else
649 {
650 wndObjectGeneral.m_dwObjectId = dwObjectId;
651 wndObjectGeneral.m_strClass = g_szObjectClass[pObject->iClass];
652 wndObjectGeneral.m_strName = pObject->szName;
653 wndPropSheet.AddPage(&wndObjectGeneral);
2057008d
VK
654 }
655
656 // Create tabs specific for node objects
657 if (pObject->iClass == OBJECT_NODE)
658 {
659 // Create "Capabilities" tab
660 wndObjectCaps.m_pObject = pObject;
661 wndPropSheet.AddPage(&wndObjectCaps);
662 }
663
f6d9527a 664 // Create "Security" tab
8e2809bb
VK
665 wndObjectSecurity.m_pObject = pObject;
666 wndObjectSecurity.m_bInheritRights = pObject->bInheritRights;
667 wndPropSheet.AddPage(&wndObjectSecurity);
f6d9527a
VK
668
669 wndPropSheet.SetObject(pObject);
670 if (wndPropSheet.DoModal() == IDOK)
671 wndPropSheet.SaveObjectChanges();
2057008d
VK
672 }
673}
790cd256
VK
674
675
676//
677// Get context menu
678//
679
680CMenu *CConsoleApp::GetContextMenu(int iIndex)
681{
682 return m_ctxMenu.GetSubMenu(iIndex);
683}
946d48b3
VK
684
685
686//
687// Start data collection editor for specific object
688//
689
690void CConsoleApp::StartObjectDCEditor(NXC_OBJECT *pObject)
691{
223ffcfa
VK
692 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
693 NXC_DCI_LIST *pItemList;
694 DWORD dwResult;
f6915462 695 CDataCollectionEditor *pWnd;
946d48b3 696
f6915462
VK
697 pWnd = (CDataCollectionEditor *)FindOpenDCEditor(pObject->dwId);
698 if (pWnd == NULL)
223ffcfa 699 {
f6915462
VK
700 dwResult = DoRequestArg2(NXCOpenNodeDCIList, (void *)pObject->dwId,
701 &pItemList, "Loading node's data collection information...");
702 if (dwResult == RCC_SUCCESS)
703 {
704 CCreateContext context;
705
706 pWnd = new CDataCollectionEditor(pItemList);
707
708 // load the frame
709 context.m_pCurrentFrame = pFrame;
710
711 if (pWnd->LoadFrame(IDR_DC_EDITOR, WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL, &context))
712 {
713 CString strFullString, strTitle;
714
715 if (strFullString.LoadString(IDR_DC_EDITOR))
716 AfxExtractSubString(strTitle, strFullString, CDocTemplate::docName);
717
718 // add node name to title
719 strTitle += " - [";
720 strTitle += pObject->szName;
721 strTitle += "]";
722
723 // set the handles and redraw the frame and parent
1c0c8dde 724 pWnd->SetHandles(m_hDCEditorMenu, m_hDCEditorAccel);
f6915462
VK
725 pWnd->SetTitle(strTitle);
726 pWnd->InitialUpdateFrame(NULL, TRUE);
727 }
728 else
729 {
730 delete pWnd;
731 }
732 }
733 else
734 {
7ac0c0a8 735 ErrorBox(dwResult, "Unable to load data collection information for node:\n%s");
f6915462 736 }
223ffcfa
VK
737 }
738 else
739 {
f6915462
VK
740 // Data collection editor already open, activate it
741 pWnd->BringWindowToTop();
223ffcfa 742 }
946d48b3
VK
743}
744
745
746//
747// Show network summary view
748//
749
750void CConsoleApp::OnViewNetworksummary()
751{
752 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
753
754 // create a new MDI child window or open existing
755 if (m_bNetSummaryActive)
756 m_pwndNetSummary->BringWindowToTop();
757 else
758 pFrame->CreateNewChild(
759 RUNTIME_CLASS(CNetSummaryFrame), IDR_NETWORK_SUMMARY, m_hMDIMenu, m_hMDIAccel);
760}
223ffcfa
VK
761
762
763//
764// Set object's management status
765//
766
767void CConsoleApp::SetObjectMgmtStatus(NXC_OBJECT *pObject, BOOL bIsManaged)
768{
769 DWORD dwResult;
770
771 dwResult = DoRequestArg2(NXCSetObjectMgmtStatus, (void *)pObject->dwId,
772 (void *)bIsManaged, "Changing object status...");
773 if (dwResult != RCC_SUCCESS)
774 {
775 char szBuffer[256];
776
777 sprintf(szBuffer, "Unable to change management status for object %s:\n%s",
778 pObject->szName, NXCGetErrorText(dwResult));
779 GetMainWnd()->MessageBox(szBuffer, "Error", MB_ICONSTOP);
780 }
781}
f6915462
VK
782
783
784//
785// Find open data collection editor for given node, if any
786//
787
788CWnd *CConsoleApp::FindOpenDCEditor(DWORD dwNodeId)
789{
790 DWORD i;
791
792 for(i = 0; i < MAX_DC_EDITORS; i++)
793 if (m_openDCEditors[i].dwNodeId == dwNodeId)
794 return m_openDCEditors[i].pWnd;
795 return NULL;
796}
7ac0c0a8
VK
797
798
799//
800// Display message box with error text from client library
801//
802
803void CConsoleApp::ErrorBox(DWORD dwError, char *pszMessage, char *pszTitle)
804{
805 char szBuffer[512];
806
807 sprintf(szBuffer, (pszMessage != NULL) ? pszMessage : "Error: %s",
808 NXCGetErrorText(dwError));
809 m_pMainWnd->MessageBox(szBuffer, (pszTitle != NULL) ? pszTitle : "Error", MB_ICONSTOP);
810}