looks like 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);
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
393void CConsoleApp::OnViewEvents()
394{
395 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
396
397 // create a new MDI child window or open existing
398 if (m_bEventBrowserActive)
399 m_pwndEventBrowser->BringWindowToTop();
400 else
401 pFrame->CreateNewChild(
8e748b3e 402 RUNTIME_CLASS(CEventBrowser), IDR_EVENTS, m_hEventBrowserMenu, m_hEventBrowserAccel);
3bf7e95e
VK
403}
404
405void CConsoleApp::OnViewMap()
406{
407 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
408
409 // create a new MDI child window
f7a7f8e4 410 pFrame->CreateNewChild(RUNTIME_CLASS(CMapFrame), IDR_MAPFRAME, m_hMDIMenu, m_hMDIAccel);
3bf7e95e
VK
411}
412
413void CConsoleApp::OnConnectToServer()
414{
415 CLoginDialog dlgLogin;
f7a7f8e4 416 DWORD dwResult;
3bf7e95e
VK
417
418 dlgLogin.m_szServer = g_szServer;
419 dlgLogin.m_szLogin = g_szLogin;
f7a7f8e4 420 do
3bf7e95e
VK
421 {
422 if (dlgLogin.DoModal() != IDOK)
423 {
424 PostQuitMessage(1);
425 break;
426 }
427 strcpy(g_szServer, (LPCTSTR)dlgLogin.m_szServer);
428 strcpy(g_szLogin, (LPCTSTR)dlgLogin.m_szLogin);
429 strcpy(g_szPassword, (LPCTSTR)dlgLogin.m_szPassword);
430
431 // Save last connection parameters
432 WriteProfileString(_T("Connection"), _T("Server"), g_szServer);
433 WriteProfileString(_T("Connection"), _T("Login"), g_szLogin);
434
435 // Initiate connection
f7a7f8e4
VK
436 dwResult = DoLogin();
437 if (dwResult != RCC_SUCCESS)
3bf7e95e 438 {
f7a7f8e4
VK
439 char szBuffer[256];
440
441 sprintf(szBuffer, "Unable to connect: %s", NXCGetErrorText(dwResult));
442 m_pMainWnd->MessageBox(szBuffer, "Connection error", MB_OK | MB_ICONSTOP);
3bf7e95e
VK
443 }
444 }
f7a7f8e4 445 while(dwResult != RCC_SUCCESS);
3bf7e95e
VK
446}
447
448void CConsoleApp::OnViewObjectbrowser()
449{
450 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
451
452 // create a new MDI child window or open existing
453 if (m_bObjectBrowserActive)
454 m_pwndObjectBrowser->BringWindowToTop();
455 else
456 pFrame->CreateNewChild(
2060ba91 457 RUNTIME_CLASS(CObjectBrowser), IDR_OBJECTS, m_hObjectBrowserMenu, m_hObjectBrowserAccel);
3bf7e95e
VK
458}
459
460
461//
462// Event handler for client libray events
463//
464
465void CConsoleApp::EventHandler(DWORD dwEvent, DWORD dwCode, void *pArg)
466{
3bf7e95e
VK
467 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
468
469 switch(dwEvent)
470 {
471 case NXC_EVENT_STATE_CHANGED:
472 switch(dwCode)
473 {
474 case STATE_CONNECTING:
3bf7e95e
VK
475 break;
476 case STATE_IDLE:
3bf7e95e
VK
477 if ((m_bEventBrowserActive) && (m_dwClientState == STATE_SYNC_EVENTS))
478 m_pwndEventBrowser->EnableDisplay(TRUE);
479 break;
480 case STATE_DISCONNECTED:
3bf7e95e
VK
481 break;
482 case STATE_SYNC_EVENTS:
483 if (m_bEventBrowserActive)
484 m_pwndEventBrowser->EnableDisplay(FALSE);
485 break;
486 default:
487 break;
488 }
489 m_dwClientState = dwCode;
490 break;
3bf7e95e
VK
491 case NXC_EVENT_NEW_ELOG_RECORD:
492 if (m_bEventBrowserActive)
493 m_pwndEventBrowser->AddEvent((NXC_EVENT *)pArg);
494 MemFree(pArg);
3bf7e95e 495 break;
89d4d2a2
VK
496 case NXC_EVENT_OBJECT_CHANGED:
497 ((CMainFrame *)m_pMainWnd)->PostMessage(WM_OBJECT_CHANGE, dwCode, (LPARAM)pArg);
498 break;
fadbdf37
VK
499 case NXC_EVENT_USER_DB_CHANGED:
500 ((CMainFrame *)m_pMainWnd)->PostMessage(WM_USERDB_CHANGE, dwCode, (LPARAM)pArg);
501 break;
3bf7e95e
VK
502 default:
503 break;
504 }
505}
a5f8f9b0 506
999bd324
VK
507
508//
509// Handler for WM_COMMAND(ID_CONTROLPANEL_EVENTS) message
510//
511
a5f8f9b0
VK
512void CConsoleApp::OnControlpanelEvents()
513{
514 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
515
516 // create a new MDI child window or open existing
517 if (m_bEventEditorActive)
518 m_pwndEventEditor->BringWindowToTop();
519 else
417924d6
VK
520 {
521 DWORD dwResult;
522
f7a7f8e4 523 dwResult = DoRequest(NXCOpenEventDB, "Opening event configuration database...");
417924d6
VK
524 if (dwResult == RCC_SUCCESS)
525 {
526 pFrame->CreateNewChild(
527 RUNTIME_CLASS(CEventEditor), IDR_EVENT_EDITOR, m_hMDIMenu, m_hMDIAccel);
528 }
529 else
530 {
531 char szBuffer[256];
532
533 sprintf(szBuffer, "Unable to open event configuration database:\n%s", NXCGetErrorText(dwResult));
534 GetMainWnd()->MessageBox(szBuffer, "Error", MB_ICONSTOP);
535 }
536 }
537}
538
539
540//
541// Handler for WM_COMMAND(ID_CONTROLPANEL_USERS) message
542//
543
544void CConsoleApp::OnControlpanelUsers()
545{
546 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
547
548 // create a new MDI child window or open existing
549 if (m_bUserEditorActive)
550 m_pwndUserEditor->BringWindowToTop();
551 else
552 {
553 DWORD dwResult;
554
f7a7f8e4 555 dwResult = DoRequest(NXCLockUserDB, "Locking user database...");
417924d6
VK
556 if (dwResult == RCC_SUCCESS)
557 {
558 pFrame->CreateNewChild(
cad81e33 559 RUNTIME_CLASS(CUserEditor), IDR_USER_EDITOR, m_hUserEditorMenu, m_hUserEditorAccel);
417924d6
VK
560 }
561 else
562 {
563 char szBuffer[256];
564
565 sprintf(szBuffer, "Unable to lock user database:\n%s", NXCGetErrorText(dwResult));
566 GetMainWnd()->MessageBox(szBuffer, "Error", MB_ICONSTOP);
567 }
568 }
a5f8f9b0
VK
569}
570
571
8e748b3e
VK
572//
573// Handler for WM_COMMAND::ID_VIEW_DEBUG message
574//
575
576void CConsoleApp::OnViewDebug()
577{
578 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
579
580 // create a new MDI child window or open existing
581 if (m_bDebugWindowActive)
582 m_pwndDebugWindow->BringWindowToTop();
583 else
584 pFrame->CreateNewChild(
585 RUNTIME_CLASS(CDebugFrame), IDR_DEBUG_WINDOW, m_hMDIMenu, m_hMDIAccel);
586}
89d4d2a2
VK
587
588
589//
590// Print debug information
591//
592
593void CConsoleApp::DebugPrintf(char *szFormat, ...)
594{
595 if (m_bDebugWindowActive)
596 {
597 char szBuffer[1024];
598 va_list args;
599
600 va_start(args, szFormat);
601 vsprintf(szBuffer, szFormat, args);
602 va_end(args);
603
604 m_pwndDebugWindow->AddMessage(szBuffer);
605 }
606}
2057008d
VK
607
608
609//
610// Edit properties of specific object
611//
612
613void CConsoleApp::ObjectProperties(DWORD dwObjectId)
614{
615 CObjectPropSheet wndPropSheet("Object Properties", GetMainWnd(), 0);
616 CNodePropsGeneral wndNodeGeneral;
8e2809bb 617 CObjectPropsGeneral wndObjectGeneral;
2057008d 618 CObjectPropCaps wndObjectCaps;
8e2809bb 619 CObjectPropsSecurity wndObjectSecurity;
2057008d
VK
620 NXC_OBJECT *pObject;
621 char szBuffer[32];
622
623 pObject = NXCFindObjectById(dwObjectId);
624 if (pObject != NULL)
625 {
626 // Create "General" tab
8e2809bb 627 if (pObject->iClass == OBJECT_NODE)
2057008d 628 {
8e2809bb
VK
629 wndNodeGeneral.m_dwObjectId = dwObjectId;
630 wndNodeGeneral.m_strName = pObject->szName;
631 wndNodeGeneral.m_strOID = pObject->node.szObjectId;
632 wndNodeGeneral.m_strPrimaryIp = IpToStr(pObject->dwIpAddr, szBuffer);
633 wndNodeGeneral.m_iAgentPort = (int)pObject->node.wAgentPort;
634 wndNodeGeneral.m_strCommunity = pObject->node.szCommunityString;
635 wndNodeGeneral.m_iAuthType = pObject->node.wAuthMethod;
636 wndNodeGeneral.m_strSecret = pObject->node.szSharedSecret;
637 wndPropSheet.AddPage(&wndNodeGeneral);
638 }
639 else
640 {
641 wndObjectGeneral.m_dwObjectId = dwObjectId;
642 wndObjectGeneral.m_strClass = g_szObjectClass[pObject->iClass];
643 wndObjectGeneral.m_strName = pObject->szName;
644 wndPropSheet.AddPage(&wndObjectGeneral);
2057008d
VK
645 }
646
647 // Create tabs specific for node objects
648 if (pObject->iClass == OBJECT_NODE)
649 {
650 // Create "Capabilities" tab
651 wndObjectCaps.m_pObject = pObject;
652 wndPropSheet.AddPage(&wndObjectCaps);
653 }
654
f6d9527a 655 // Create "Security" tab
8e2809bb
VK
656 wndObjectSecurity.m_pObject = pObject;
657 wndObjectSecurity.m_bInheritRights = pObject->bInheritRights;
658 wndPropSheet.AddPage(&wndObjectSecurity);
f6d9527a
VK
659
660 wndPropSheet.SetObject(pObject);
661 if (wndPropSheet.DoModal() == IDOK)
662 wndPropSheet.SaveObjectChanges();
2057008d
VK
663 }
664}
790cd256
VK
665
666
667//
668// Get context menu
669//
670
671CMenu *CConsoleApp::GetContextMenu(int iIndex)
672{
673 return m_ctxMenu.GetSubMenu(iIndex);
674}
946d48b3
VK
675
676
677//
678// Start data collection editor for specific object
679//
680
681void CConsoleApp::StartObjectDCEditor(NXC_OBJECT *pObject)
682{
223ffcfa
VK
683 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
684 NXC_DCI_LIST *pItemList;
685 DWORD dwResult;
f6915462 686 CDataCollectionEditor *pWnd;
946d48b3 687
f6915462
VK
688 pWnd = (CDataCollectionEditor *)FindOpenDCEditor(pObject->dwId);
689 if (pWnd == NULL)
223ffcfa 690 {
f6915462
VK
691 dwResult = DoRequestArg2(NXCOpenNodeDCIList, (void *)pObject->dwId,
692 &pItemList, "Loading node's data collection information...");
693 if (dwResult == RCC_SUCCESS)
694 {
695 CCreateContext context;
696
697 pWnd = new CDataCollectionEditor(pItemList);
698
699 // load the frame
700 context.m_pCurrentFrame = pFrame;
701
702 if (pWnd->LoadFrame(IDR_DC_EDITOR, WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL, &context))
703 {
704 CString strFullString, strTitle;
705
706 if (strFullString.LoadString(IDR_DC_EDITOR))
707 AfxExtractSubString(strTitle, strFullString, CDocTemplate::docName);
708
709 // add node name to title
710 strTitle += " - [";
711 strTitle += pObject->szName;
712 strTitle += "]";
713
714 // set the handles and redraw the frame and parent
1c0c8dde 715 pWnd->SetHandles(m_hDCEditorMenu, m_hDCEditorAccel);
f6915462
VK
716 pWnd->SetTitle(strTitle);
717 pWnd->InitialUpdateFrame(NULL, TRUE);
718 }
719 else
720 {
721 delete pWnd;
722 }
723 }
724 else
725 {
726 char szBuffer[256];
727
728 sprintf(szBuffer, "Unable to load data collection information for node:\n%s",
729 NXCGetErrorText(dwResult));
730 m_pMainWnd->MessageBox(szBuffer, "Error", MB_ICONSTOP);
731 }
223ffcfa
VK
732 }
733 else
734 {
f6915462
VK
735 // Data collection editor already open, activate it
736 pWnd->BringWindowToTop();
223ffcfa 737 }
946d48b3
VK
738}
739
740
741//
742// Show network summary view
743//
744
745void CConsoleApp::OnViewNetworksummary()
746{
747 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
748
749 // create a new MDI child window or open existing
750 if (m_bNetSummaryActive)
751 m_pwndNetSummary->BringWindowToTop();
752 else
753 pFrame->CreateNewChild(
754 RUNTIME_CLASS(CNetSummaryFrame), IDR_NETWORK_SUMMARY, m_hMDIMenu, m_hMDIAccel);
755}
223ffcfa
VK
756
757
758//
759// Set object's management status
760//
761
762void CConsoleApp::SetObjectMgmtStatus(NXC_OBJECT *pObject, BOOL bIsManaged)
763{
764 DWORD dwResult;
765
766 dwResult = DoRequestArg2(NXCSetObjectMgmtStatus, (void *)pObject->dwId,
767 (void *)bIsManaged, "Changing object status...");
768 if (dwResult != RCC_SUCCESS)
769 {
770 char szBuffer[256];
771
772 sprintf(szBuffer, "Unable to change management status for object %s:\n%s",
773 pObject->szName, NXCGetErrorText(dwResult));
774 GetMainWnd()->MessageBox(szBuffer, "Error", MB_ICONSTOP);
775 }
776}
f6915462
VK
777
778
779//
780// Find open data collection editor for given node, if any
781//
782
783CWnd *CConsoleApp::FindOpenDCEditor(DWORD dwNodeId)
784{
785 DWORD i;
786
787 for(i = 0; i < MAX_DC_EDITORS; i++)
788 if (m_openDCEditors[i].dwNodeId == dwNodeId)
789 return m_openDCEditors[i].pWnd;
790 return NULL;
791}