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