CSCP variable VID_LOGIN_RESULT removed
[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)
3bf7e95e
VK
52 //}}AFX_MSG_MAP
53END_MESSAGE_MAP()
54
55
56//
57// CConsoleApp construction
58//
59
60CConsoleApp::CConsoleApp()
61{
62 m_bCtrlPanelActive = FALSE;
63 m_bEventBrowserActive = FALSE;
a5f8f9b0 64 m_bEventEditorActive = FALSE;
417924d6 65 m_bUserEditorActive = FALSE;
3bf7e95e 66 m_bObjectBrowserActive = FALSE;
8e748b3e 67 m_bDebugWindowActive = FALSE;
3bf7e95e 68 m_dwClientState = STATE_DISCONNECTED;
a5f8f9b0 69 m_pRqWaitList = NULL;
999bd324
VK
70 m_dwRqWaitListSize = 0;
71 m_mutexRqWaitList = MutexCreate();
3bf7e95e
VK
72}
73
999bd324
VK
74
75//
76// CConsoleApp destruction
77//
78
79CConsoleApp::~CConsoleApp()
80{
81 if (m_pRqWaitList != NULL)
82 MemFree(m_pRqWaitList);
83 MutexDestroy(m_mutexRqWaitList);
84}
85
86
3bf7e95e
VK
87//
88// The one and only CConsoleApp object
89//
90
91CConsoleApp theApp;
92
93
94//
95// CConsoleApp initialization
96//
97
98BOOL CConsoleApp::InitInstance()
99{
100 BOOL bSetWindowPos;
101 DWORD dwBytes;
102 BYTE *pData;
8e748b3e 103 HMENU hMenu;
3bf7e95e
VK
104
105 if (!AfxSocketInit())
106 {
107 AfxMessageBox(IDP_SOCKETS_INIT_FAILED, MB_OK | MB_ICONSTOP);
108 return FALSE;
109 }
110
111 if (!NXCInitialize())
112 {
113 AfxMessageBox(IDS_NXC_INIT_FAILED, MB_OK | MB_ICONSTOP);
114 return FALSE;
115 }
116 NXCSetEventHandler(ClientEventHandler);
117
118 AfxEnableControlContainer();
119
120 // Standard initialization
121 // If you are not using these features and wish to reduce the size
122 // of your final executable, you should remove from the following
123 // the specific initialization routines you do not need.
124
125#ifdef _AFXDLL
126 Enable3dControls(); // Call this when using MFC in a shared DLL
127#else
128 Enable3dControlsStatic(); // Call this when linking to MFC statically
129#endif
130
131 // Change the registry key under which our settings are stored.
132 SetRegistryKey(_T("NetXMS"));
133
134 // To create the main window, this code creates a new frame window
135 // object and then sets it as the application's main window object.
136
137 CMDIFrameWnd* pFrame = new CMainFrame;
138 m_pMainWnd = pFrame;
139
140 // create main MDI frame window
141 if (!pFrame->LoadFrame(IDR_MAINFRAME))
142 return FALSE;
143
8e748b3e
VK
144 // Load shared MDI menus and accelerator table
145 HINSTANCE hInstance = AfxGetResourceHandle();
146
147 hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDM_VIEW_SPECIFIC));
148
149 m_hMDIMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MAINFRAME));
150 InsertMenu(m_hMDIMenu, 3, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
151
152 m_hEventBrowserMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MAINFRAME));
153 InsertMenu(m_hEventBrowserMenu, 3, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
154 InsertMenu(m_hEventBrowserMenu, 3, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 1), "&Event");
155
2060ba91
VK
156 m_hObjectBrowserMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MAINFRAME));
157 InsertMenu(m_hObjectBrowserMenu, 3, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
158 InsertMenu(m_hObjectBrowserMenu, 3, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 2), "&Object");
159
cad81e33
VK
160 m_hUserEditorMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MAINFRAME));
161 InsertMenu(m_hUserEditorMenu, 3, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
162 InsertMenu(m_hUserEditorMenu, 3, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 3), "&User");
163
8e748b3e
VK
164 m_hMDIAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_MDI_DEFAULT));
165 m_hEventBrowserAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_MDI_DEFAULT));
2060ba91 166 m_hObjectBrowserAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_OBJECT_BROWSER));
cad81e33 167 m_hUserEditorAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_MDI_DEFAULT));
3bf7e95e
VK
168
169 // Load configuration from registry
170 dwBytes = sizeof(WINDOWPLACEMENT);
171 bSetWindowPos = GetProfileBinary(_T("General"), _T("WindowPlacement"),
172 &pData, (UINT *)&dwBytes);
173 strcpy(g_szServer, (LPCTSTR)GetProfileString(_T("Connection"), _T("Server"), _T("localhost")));
174 strcpy(g_szLogin, (LPCTSTR)GetProfileString(_T("Connection"), _T("Login"), NULL));
175
176 // The main window has been initialized, so show and update it.
177 if (bSetWindowPos)
178 {
179 pFrame->SetWindowPlacement((WINDOWPLACEMENT *)pData);
180 if (pFrame->IsIconic())
181 pFrame->ShowWindow(SW_RESTORE);
182 }
183 else
184 {
185 pFrame->ShowWindow(m_nCmdShow);
186 }
187 pFrame->UpdateWindow();
188 pFrame->PostMessage(WM_COMMAND, ID_CONNECT_TO_SERVER, 0);
189
190 return TRUE;
191}
192
193/////////////////////////////////////////////////////////////////////////////
194// CConsoleApp message handlers
195
196int CConsoleApp::ExitInstance()
197{
8e748b3e
VK
198 NXCSetDebugCallback(NULL);
199 NXCDisconnect();
200
3bf7e95e 201 // Free resources
8e748b3e
VK
202 SafeFreeResource(m_hMDIMenu);
203 SafeFreeResource(m_hMDIAccel);
204 SafeFreeResource(m_hEventBrowserMenu);
205 SafeFreeResource(m_hEventBrowserAccel);
3bf7e95e
VK
206
207 return CWinApp::ExitInstance();
208}
209
210
211/////////////////////////////////////////////////////////////////////////////
212// CAboutDlg dialog used for App About
213
214class CAboutDlg : public CDialog
215{
216public:
217 CAboutDlg();
218
219// Dialog Data
220 //{{AFX_DATA(CAboutDlg)
221 enum { IDD = IDD_ABOUTBOX };
222 //}}AFX_DATA
223
224 // ClassWizard generated virtual function overrides
225 //{{AFX_VIRTUAL(CAboutDlg)
226 protected:
227 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
228 //}}AFX_VIRTUAL
229
230// Implementation
231protected:
232 //{{AFX_MSG(CAboutDlg)
233 // No message handlers
234 //}}AFX_MSG
235 DECLARE_MESSAGE_MAP()
236};
237
238CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
239{
240 //{{AFX_DATA_INIT(CAboutDlg)
241 //}}AFX_DATA_INIT
242}
243
244void CAboutDlg::DoDataExchange(CDataExchange* pDX)
245{
246 CDialog::DoDataExchange(pDX);
247 //{{AFX_DATA_MAP(CAboutDlg)
248 //}}AFX_DATA_MAP
249}
250
251BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
252 //{{AFX_MSG_MAP(CAboutDlg)
253 // No message handlers
254 //}}AFX_MSG_MAP
255END_MESSAGE_MAP()
256
257// App command to run the dialog
258void CConsoleApp::OnAppAbout()
259{
260 CAboutDlg aboutDlg;
261 aboutDlg.DoModal();
262}
263
264/////////////////////////////////////////////////////////////////////////////
265// CConsoleApp message handlers
266
267
268void CConsoleApp::OnViewControlpanel()
269{
270 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
271
272 // create a new MDI child window or open existing
273 if (m_bCtrlPanelActive)
274 m_pwndCtrlPanel->BringWindowToTop();
275 else
276 pFrame->CreateNewChild(
8e748b3e 277 RUNTIME_CLASS(CControlPanel), IDR_CTRLPANEL, m_hMDIMenu, m_hMDIAccel);
3bf7e95e
VK
278}
279
280
281//
282// This method called when new view is created
283//
284
285void CConsoleApp::OnViewCreate(DWORD dwView, CWnd *pWnd)
286{
287 switch(dwView)
288 {
289 case IDR_CTRLPANEL:
290 m_bCtrlPanelActive = TRUE;
291 m_pwndCtrlPanel = pWnd;
292 break;
293 case IDR_EVENTS:
294 m_bEventBrowserActive = TRUE;
295 m_pwndEventBrowser = (CEventBrowser *)pWnd;
296 break;
297 case IDR_OBJECTS:
298 m_bObjectBrowserActive = TRUE;
299 m_pwndObjectBrowser = pWnd;
300 break;
a5f8f9b0
VK
301 case IDR_EVENT_EDITOR:
302 m_bEventEditorActive = TRUE;
303 m_pwndEventEditor = (CEventEditor *)pWnd;
304 break;
417924d6
VK
305 case IDR_USER_EDITOR:
306 m_bUserEditorActive = TRUE;
307 m_pwndUserEditor = (CUserEditor *)pWnd;
308 break;
8e748b3e
VK
309 case IDR_DEBUG_WINDOW:
310 m_bDebugWindowActive = TRUE;
311 m_pwndDebugWindow = (CDebugFrame *)pWnd;
312 NXCSetDebugCallback(ClientDebugCallback);
313 break;
3bf7e95e
VK
314 default:
315 break;
316 }
317}
318
319
320//
321// This method called when view is destroyed
322//
323
324void CConsoleApp::OnViewDestroy(DWORD dwView, CWnd *pWnd)
325{
326 switch(dwView)
327 {
328 case IDR_CTRLPANEL:
329 m_bCtrlPanelActive = FALSE;
330 break;
331 case IDR_EVENTS:
332 m_bEventBrowserActive = FALSE;
333 break;
334 case IDR_OBJECTS:
335 m_bObjectBrowserActive = FALSE;
336 break;
a5f8f9b0
VK
337 case IDR_EVENT_EDITOR:
338 m_bEventEditorActive = FALSE;
339 break;
417924d6
VK
340 case IDR_USER_EDITOR:
341 m_bUserEditorActive = FALSE;
342 break;
8e748b3e
VK
343 case IDR_DEBUG_WINDOW:
344 m_bDebugWindowActive = FALSE;
345 NXCSetDebugCallback(NULL);
346 break;
3bf7e95e
VK
347 default:
348 break;
349 }
350}
351
352void CConsoleApp::OnViewEvents()
353{
354 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
355
356 // create a new MDI child window or open existing
357 if (m_bEventBrowserActive)
358 m_pwndEventBrowser->BringWindowToTop();
359 else
360 pFrame->CreateNewChild(
8e748b3e 361 RUNTIME_CLASS(CEventBrowser), IDR_EVENTS, m_hEventBrowserMenu, m_hEventBrowserAccel);
3bf7e95e
VK
362}
363
364void CConsoleApp::OnViewMap()
365{
366 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
367
368 // create a new MDI child window
89d4d2a2
VK
369// pFrame->CreateNewChild(RUNTIME_CLASS(CMapFrame), IDR_MAPFRAME, m_hMDIMenu, m_hMDIAccel);
370pFrame->BroadcastMessage(WM_OBJECT_CHANGE, 1, 0);
3bf7e95e
VK
371}
372
373void CConsoleApp::OnConnectToServer()
374{
375 CLoginDialog dlgLogin;
376
377 dlgLogin.m_szServer = g_szServer;
378 dlgLogin.m_szLogin = g_szLogin;
379 while(1)
380 {
381 if (dlgLogin.DoModal() != IDOK)
382 {
383 PostQuitMessage(1);
384 break;
385 }
386 strcpy(g_szServer, (LPCTSTR)dlgLogin.m_szServer);
387 strcpy(g_szLogin, (LPCTSTR)dlgLogin.m_szLogin);
388 strcpy(g_szPassword, (LPCTSTR)dlgLogin.m_szPassword);
389
390 // Save last connection parameters
391 WriteProfileString(_T("Connection"), _T("Server"), g_szServer);
392 WriteProfileString(_T("Connection"), _T("Login"), g_szLogin);
393
394 // Initiate connection
395 m_bAuthFailed = FALSE;
396 if (NXCConnect(g_szServer, g_szLogin, g_szPassword))
397 {
398 m_dlgProgress.m_szStatusText = "Connecting to server...";
399 if (m_dlgProgress.DoModal() == IDOK)
400 {
401 // Now we are connected, request data sync
402 NXCSyncObjects();
8e2809bb 403 NXCLoadUserDB();
3bf7e95e
VK
404 break;
405 }
406 else
407 m_pMainWnd->MessageBox(m_bAuthFailed ? "Client authentication failed (invalid login name or password)" :
408 "Unable to establish connection with the server",
409 "Connection error", MB_OK | MB_ICONSTOP);
410 }
411 else
412 {
413 m_pMainWnd->MessageBox("Unable to initiate connection to server",
414 "Connection error", MB_OK | MB_ICONSTOP);
415 }
416 }
417}
418
419void CConsoleApp::OnViewObjectbrowser()
420{
421 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
422
423 // create a new MDI child window or open existing
424 if (m_bObjectBrowserActive)
425 m_pwndObjectBrowser->BringWindowToTop();
426 else
427 pFrame->CreateNewChild(
2060ba91 428 RUNTIME_CLASS(CObjectBrowser), IDR_OBJECTS, m_hObjectBrowserMenu, m_hObjectBrowserAccel);
3bf7e95e
VK
429}
430
431
432//
433// Event handler for client libray events
434//
435
436void CConsoleApp::EventHandler(DWORD dwEvent, DWORD dwCode, void *pArg)
437{
438 static BOOL bNowConnecting = FALSE;
439 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
440
441 switch(dwEvent)
442 {
443 case NXC_EVENT_STATE_CHANGED:
444 switch(dwCode)
445 {
446 case STATE_CONNECTING:
447 bNowConnecting = TRUE;
448 break;
449 case STATE_IDLE:
450 if (bNowConnecting)
451 {
6aaf0c07 452 m_dlgProgress.Terminate(IDOK);
3bf7e95e
VK
453 bNowConnecting = FALSE;
454 }
455 if ((m_bEventBrowserActive) && (m_dwClientState == STATE_SYNC_EVENTS))
456 m_pwndEventBrowser->EnableDisplay(TRUE);
457 break;
458 case STATE_DISCONNECTED:
459 if (bNowConnecting)
460 {
6aaf0c07 461 m_dlgProgress.Terminate(IDCANCEL);
3bf7e95e
VK
462 bNowConnecting = FALSE;
463 }
464 break;
465 case STATE_SYNC_EVENTS:
466 if (m_bEventBrowserActive)
467 m_pwndEventBrowser->EnableDisplay(FALSE);
468 break;
469 default:
470 break;
471 }
472 m_dwClientState = dwCode;
473 break;
474 case NXC_EVENT_LOGIN_RESULT:
475 if (dwCode == 0)
476 m_bAuthFailed = TRUE;
477 break;
478 case NXC_EVENT_NEW_ELOG_RECORD:
479 if (m_bEventBrowserActive)
480 m_pwndEventBrowser->AddEvent((NXC_EVENT *)pArg);
481 MemFree(pArg);
3bf7e95e 482 break;
a5f8f9b0 483 case NXC_EVENT_REQUEST_COMPLETED:
999bd324 484 OnRequestComplete(dwCode, (DWORD)pArg);
a5f8f9b0 485 break;
89d4d2a2
VK
486 case NXC_EVENT_OBJECT_CHANGED:
487 ((CMainFrame *)m_pMainWnd)->PostMessage(WM_OBJECT_CHANGE, dwCode, (LPARAM)pArg);
488 break;
3bf7e95e
VK
489 default:
490 break;
491 }
492}
a5f8f9b0 493
999bd324
VK
494
495//
496// Handler for WM_COMMAND(ID_CONTROLPANEL_EVENTS) message
497//
498
a5f8f9b0
VK
499void CConsoleApp::OnControlpanelEvents()
500{
501 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
502
503 // create a new MDI child window or open existing
504 if (m_bEventEditorActive)
505 m_pwndEventEditor->BringWindowToTop();
506 else
417924d6
VK
507 {
508 DWORD dwResult;
509
510 dwResult = WaitForRequest(NXCOpenEventDB(), "Opening event configuration database...");
511 if (dwResult == RCC_SUCCESS)
512 {
513 pFrame->CreateNewChild(
514 RUNTIME_CLASS(CEventEditor), IDR_EVENT_EDITOR, m_hMDIMenu, m_hMDIAccel);
515 }
516 else
517 {
518 char szBuffer[256];
519
520 sprintf(szBuffer, "Unable to open event configuration database:\n%s", NXCGetErrorText(dwResult));
521 GetMainWnd()->MessageBox(szBuffer, "Error", MB_ICONSTOP);
522 }
523 }
524}
525
526
527//
528// Handler for WM_COMMAND(ID_CONTROLPANEL_USERS) message
529//
530
531void CConsoleApp::OnControlpanelUsers()
532{
533 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
534
535 // create a new MDI child window or open existing
536 if (m_bUserEditorActive)
537 m_pwndUserEditor->BringWindowToTop();
538 else
539 {
540 DWORD dwResult;
541
542 dwResult = WaitForRequest(NXCLockUserDB(), "Locking user database...");
543 if (dwResult == RCC_SUCCESS)
544 {
545 pFrame->CreateNewChild(
cad81e33 546 RUNTIME_CLASS(CUserEditor), IDR_USER_EDITOR, m_hUserEditorMenu, m_hUserEditorAccel);
417924d6
VK
547 }
548 else
549 {
550 char szBuffer[256];
551
552 sprintf(szBuffer, "Unable to lock user database:\n%s", NXCGetErrorText(dwResult));
553 GetMainWnd()->MessageBox(szBuffer, "Error", MB_ICONSTOP);
554 }
555 }
a5f8f9b0
VK
556}
557
558
559//
560// Register callback for request completion
561//
562
563void CConsoleApp::RegisterRequest(HREQUEST hRequest, CWnd *pWnd)
564{
f6d9527a 565 MutexLock(m_mutexRqWaitList, INFINITE);
999bd324
VK
566 m_pRqWaitList = (RQ_WAIT_INFO *)MemReAlloc(m_pRqWaitList, sizeof(RQ_WAIT_INFO) * (m_dwRqWaitListSize + 1));
567 m_pRqWaitList[m_dwRqWaitListSize].hRequest = hRequest;
568 m_pRqWaitList[m_dwRqWaitListSize].pWnd = pWnd;
569 m_dwRqWaitListSize++;
f6d9527a 570 MutexUnlock(m_mutexRqWaitList);
999bd324
VK
571}
572
573
574//
575// This method called by client library event handler on NXC_EVENT_REQUEST_COMPLETE
576//
577
578void CConsoleApp::OnRequestComplete(HREQUEST hRequest, DWORD dwRetCode)
579{
580 DWORD i;
a5f8f9b0 581
f6d9527a 582 MutexLock(m_mutexRqWaitList, INFINITE);
999bd324
VK
583 for(i = 0; i < m_dwRqWaitListSize; i++)
584 if (m_pRqWaitList[i].hRequest == hRequest)
585 {
586 m_pRqWaitList[i].pWnd->SendMessage(WM_REQUEST_COMPLETED, hRequest, dwRetCode);
587 m_dwRqWaitListSize--;
588 memmove(&m_pRqWaitList[i], &m_pRqWaitList[i + 1], sizeof(RQ_WAIT_INFO) * (m_dwRqWaitListSize - i));
589 i--;
590 }
f6d9527a 591 MutexUnlock(m_mutexRqWaitList);
a5f8f9b0 592}
8e748b3e
VK
593
594
595//
596// Handler for WM_COMMAND::ID_VIEW_DEBUG message
597//
598
599void CConsoleApp::OnViewDebug()
600{
601 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
602
603 // create a new MDI child window or open existing
604 if (m_bDebugWindowActive)
605 m_pwndDebugWindow->BringWindowToTop();
606 else
607 pFrame->CreateNewChild(
608 RUNTIME_CLASS(CDebugFrame), IDR_DEBUG_WINDOW, m_hMDIMenu, m_hMDIAccel);
609}
89d4d2a2
VK
610
611
612//
613// Print debug information
614//
615
616void CConsoleApp::DebugPrintf(char *szFormat, ...)
617{
618 if (m_bDebugWindowActive)
619 {
620 char szBuffer[1024];
621 va_list args;
622
623 va_start(args, szFormat);
624 vsprintf(szBuffer, szFormat, args);
625 va_end(args);
626
627 m_pwndDebugWindow->AddMessage(szBuffer);
628 }
629}
2057008d
VK
630
631
632//
633// Edit properties of specific object
634//
635
636void CConsoleApp::ObjectProperties(DWORD dwObjectId)
637{
638 CObjectPropSheet wndPropSheet("Object Properties", GetMainWnd(), 0);
639 CNodePropsGeneral wndNodeGeneral;
8e2809bb 640 CObjectPropsGeneral wndObjectGeneral;
2057008d 641 CObjectPropCaps wndObjectCaps;
8e2809bb 642 CObjectPropsSecurity wndObjectSecurity;
2057008d
VK
643 NXC_OBJECT *pObject;
644 char szBuffer[32];
645
646 pObject = NXCFindObjectById(dwObjectId);
647 if (pObject != NULL)
648 {
649 // Create "General" tab
8e2809bb 650 if (pObject->iClass == OBJECT_NODE)
2057008d 651 {
8e2809bb
VK
652 wndNodeGeneral.m_dwObjectId = dwObjectId;
653 wndNodeGeneral.m_strName = pObject->szName;
654 wndNodeGeneral.m_strOID = pObject->node.szObjectId;
655 wndNodeGeneral.m_strPrimaryIp = IpToStr(pObject->dwIpAddr, szBuffer);
656 wndNodeGeneral.m_iAgentPort = (int)pObject->node.wAgentPort;
657 wndNodeGeneral.m_strCommunity = pObject->node.szCommunityString;
658 wndNodeGeneral.m_iAuthType = pObject->node.wAuthMethod;
659 wndNodeGeneral.m_strSecret = pObject->node.szSharedSecret;
660 wndPropSheet.AddPage(&wndNodeGeneral);
661 }
662 else
663 {
664 wndObjectGeneral.m_dwObjectId = dwObjectId;
665 wndObjectGeneral.m_strClass = g_szObjectClass[pObject->iClass];
666 wndObjectGeneral.m_strName = pObject->szName;
667 wndPropSheet.AddPage(&wndObjectGeneral);
2057008d
VK
668 }
669
670 // Create tabs specific for node objects
671 if (pObject->iClass == OBJECT_NODE)
672 {
673 // Create "Capabilities" tab
674 wndObjectCaps.m_pObject = pObject;
675 wndPropSheet.AddPage(&wndObjectCaps);
676 }
677
f6d9527a 678 // Create "Security" tab
8e2809bb
VK
679 wndObjectSecurity.m_pObject = pObject;
680 wndObjectSecurity.m_bInheritRights = pObject->bInheritRights;
681 wndPropSheet.AddPage(&wndObjectSecurity);
f6d9527a
VK
682
683 wndPropSheet.SetObject(pObject);
684 if (wndPropSheet.DoModal() == IDOK)
685 wndPropSheet.SaveObjectChanges();
2057008d
VK
686 }
687}
f6d9527a
VK
688
689
690//
691// Wait for specific request
692//
693
694DWORD CConsoleApp::WaitForRequest(HREQUEST hRequest, char *pszMessage)
695{
696 CRequestProcessingDlg wndWaitDlg;
697
698 wndWaitDlg.m_hRequest = hRequest;
699 if (pszMessage != NULL)
700 wndWaitDlg.m_strInfoText = pszMessage;
701 else
702 wndWaitDlg.m_strInfoText = "Processing request...";
703 return (DWORD)wndWaitDlg.DoModal();
704}