Changes in forced polling
authorVictor Kirhenshtein <victor@netxms.org>
Sun, 26 Sep 2004 14:32:09 +0000 (14:32 +0000)
committerVictor Kirhenshtein <victor@netxms.org>
Sun, 26 Sep 2004 14:32:09 +0000 (14:32 +0000)
15 files changed:
.gitattributes
src/console/win32/NodePoller.cpp [new file with mode: 0644]
src/console/win32/NodePoller.h [new file with mode: 0644]
src/console/win32/nxcon.clw
src/console/win32/nxcon.cpp
src/console/win32/nxcon.dsp
src/console/win32/nxcon.rc
src/console/win32/resource.h
src/server/core/interface.cpp
src/server/core/netobj.cpp
src/server/core/nms_core.h
src/server/core/nms_objects.h
src/server/core/node.cpp
src/server/core/session.cpp
src/server/core/status.cpp

index 6d82c94..eeb9e14 100644 (file)
@@ -166,6 +166,8 @@ src/console/win32/NewActionDlg.cpp -text
 src/console/win32/NewActionDlg.h -text
 src/console/win32/NewUserDlg.cpp -text
 src/console/win32/NewUserDlg.h -text
+src/console/win32/NodePoller.cpp -text
+src/console/win32/NodePoller.h -text
 src/console/win32/NodePropsGeneral.cpp -text
 src/console/win32/NodePropsGeneral.h -text
 src/console/win32/NodeSummary.cpp -text
diff --git a/src/console/win32/NodePoller.cpp b/src/console/win32/NodePoller.cpp
new file mode 100644 (file)
index 0000000..33d339f
--- /dev/null
@@ -0,0 +1,160 @@
+// NodePoller.cpp : implementation file
+//
+
+#include "stdafx.h"
+#include "nxcon.h"
+#include "NodePoller.h"
+
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#undef THIS_FILE
+static char THIS_FILE[] = __FILE__;
+#endif
+
+/////////////////////////////////////////////////////////////////////////////
+// CNodePoller
+
+IMPLEMENT_DYNCREATE(CNodePoller, CMDIChildWnd)
+
+CNodePoller::CNodePoller()
+{
+   m_bPollingStopped = TRUE;
+}
+
+CNodePoller::~CNodePoller()
+{
+}
+
+
+BEGIN_MESSAGE_MAP(CNodePoller, CMDIChildWnd)
+       //{{AFX_MSG_MAP(CNodePoller)
+       ON_WM_CREATE()
+       ON_COMMAND(ID_POLL_RESTART, OnPollRestart)
+       ON_WM_SIZE()
+       ON_WM_SETFOCUS()
+       //}}AFX_MSG_MAP
+   ON_MESSAGE(WM_REQUEST_COMPLETED, OnRequestCompleted)
+   ON_MESSAGE(WM_POLLER_MESSAGE, OnPollerMessage)
+END_MESSAGE_MAP()
+
+/////////////////////////////////////////////////////////////////////////////
+// CNodePoller message handlers
+
+
+//
+// WM_CREATE message handler
+//
+
+int CNodePoller::OnCreate(LPCREATESTRUCT lpCreateStruct) 
+{
+   RECT rect;
+
+       if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1)
+               return -1;
+
+   // Create and setup message area
+   GetClientRect(&rect);
+   m_wndMsgArea.Create(WS_CHILD | WS_VISIBLE | ES_MULTILINE | ES_READONLY | 
+                       WS_VSCROLL | ES_AUTOVSCROLL | ES_AUTOHSCROLL, rect, this, -1);
+   m_font.CreateFont(-MulDiv(8, GetDeviceCaps(GetDC()->m_hDC, LOGPIXELSY), 72),
+                     0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
+                     OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY,
+                     FIXED_PITCH | FF_DONTCARE, "Courier");
+   m_wndMsgArea.SetFont(&m_font);
+
+   return 0;
+}
+
+
+//
+// (Re)start poll
+//
+
+void CNodePoller::OnPollRestart() 
+{
+   DWORD dwThreadId;
+
+   if (m_bPollingStopped)
+   {
+      m_wndMsgArea.SetWindowText(_T(""));
+      PrintMsg(_T("Sending poll request to server...\r\n"));
+      m_bPollingStopped = FALSE;
+      m_data.pArg1 = (void *)m_dwObjectId;
+      m_data.pArg2 = (void *)m_iPollType;
+      m_data.hWnd = m_hWnd;
+      m_hThread = CreateThread(NULL, 0, PollerThread, &m_data, 0, &dwThreadId);
+      CloseHandle(m_hThread);
+   }
+}
+
+
+//
+// WM_REQUEST_COMPLETED message handler
+//
+
+void CNodePoller::OnRequestCompleted(WPARAM wParam, LPARAM lParam)
+{
+   m_dwResult = lParam;
+   m_bPollingStopped = TRUE;
+   if (m_dwResult == RCC_SUCCESS)
+   {
+      PrintMsg(_T("Poll completed successfully\r\n"));
+   }
+   else
+   {
+      TCHAR szBuffer[1024];
+
+      _sntprintf(szBuffer, 1024, _T("Poll failed (%s)\r\n"), NXCGetErrorText(m_dwResult));
+      PrintMsg(szBuffer);
+   }
+}
+
+
+//
+// WM_POLLER_MESSAGE message handler
+//
+
+void CNodePoller::OnPollerMessage(WPARAM wParam, LPARAM lParam)
+{
+   if (lParam != 0)
+   {
+      PrintMsg((TCHAR *)lParam);
+      free((void *)lParam);
+   }
+}
+
+
+//
+// Print message in message area
+//
+
+void CNodePoller::PrintMsg(TCHAR *pszMsg)
+{
+   m_wndMsgArea.SetSel(0, -1);
+   m_wndMsgArea.SetSel(-1, -1);
+   m_wndMsgArea.ReplaceSel(pszMsg);
+}
+
+
+//
+// WM_SIZE message handler
+//
+
+void CNodePoller::OnSize(UINT nType, int cx, int cy) 
+{
+       CMDIChildWnd::OnSize(nType, cx, cy);
+
+   m_wndMsgArea.MoveWindow(0, 0, cx, cy);
+}
+
+
+//
+// WM_SETFOCUS message handler
+//
+
+void CNodePoller::OnSetFocus(CWnd* pOldWnd) 
+{
+       CMDIChildWnd::OnSetFocus(pOldWnd);
+
+   m_wndMsgArea.SetFocus();
+}
diff --git a/src/console/win32/NodePoller.h b/src/console/win32/NodePoller.h
new file mode 100644 (file)
index 0000000..5279a88
--- /dev/null
@@ -0,0 +1,62 @@
+#if !defined(AFX_NODEPOLLER_H__E530007B_DAA0_485D_A9B0_60B0284FFAF6__INCLUDED_)
+#define AFX_NODEPOLLER_H__E530007B_DAA0_485D_A9B0_60B0284FFAF6__INCLUDED_
+
+#include "globals.h"   // Added by ClassView
+#if _MSC_VER > 1000
+#pragma once
+#endif // _MSC_VER > 1000
+// NodePoller.h : header file
+//
+
+/////////////////////////////////////////////////////////////////////////////
+// CNodePoller frame
+
+class CNodePoller : public CMDIChildWnd
+{
+       DECLARE_DYNCREATE(CNodePoller)
+protected:
+       CNodePoller();           // protected constructor used by dynamic creation
+
+// Attributes
+       HANDLE m_hThread;
+
+public:
+
+// Operations
+public:
+       DWORD m_dwObjectId;
+       int m_iPollType;
+
+// Overrides
+       // ClassWizard generated virtual function overrides
+       //{{AFX_VIRTUAL(CNodePoller)
+       //}}AFX_VIRTUAL
+
+// Implementation
+protected:
+       RqData m_data;
+       void PrintMsg(TCHAR *pszMsg);
+       BOOL m_bPollingStopped;
+       CFont m_font;
+       CEdit m_wndMsgArea;
+       DWORD m_dwResult;
+       virtual ~CNodePoller();
+
+       // Generated message map functions
+       //{{AFX_MSG(CNodePoller)
+       afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
+       afx_msg void OnPollRestart();
+       afx_msg void OnSize(UINT nType, int cx, int cy);
+       afx_msg void OnSetFocus(CWnd* pOldWnd);
+       //}}AFX_MSG
+   afx_msg void OnRequestCompleted(WPARAM wParam, LPARAM lParam);
+   afx_msg void OnPollerMessage(WPARAM wParam, LPARAM lParam);
+       DECLARE_MESSAGE_MAP()
+};
+
+/////////////////////////////////////////////////////////////////////////////
+
+//{{AFX_INSERT_LOCATION}}
+// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
+
+#endif // !defined(AFX_NODEPOLLER_H__E530007B_DAA0_485D_A9B0_60B0284FFAF6__INCLUDED_)
index 28592da..0f55eb9 100644 (file)
@@ -17,20 +17,20 @@ Class9=CMapView
 
 ResourceCount=83
 Resource1=IDD_THRESHOLD (English (U.S.))
-Resource2=IDR_MAINFRAME
+Resource2=IDD_CREATE_CONTAINER
 Resource3=IDM_VIEW_SPECIFIC (English (U.S.))
-Resource4=IDD_SELECT_EVENT
-Resource5=IDD_DCI_THRESHOLDS
+Resource4=IDD_SELECT_OBJECT
+Resource5=IDD_SET_PASSWORD
 Class2=CChildView
 Class5=CAboutDlg
 Class6=CControlPanel
 Class8=CMapFrame
 Class10=CLoginDialog
-Resource6=IDD_SELECT_USER
+Resource6=IDD_OBJECT_GENERAL
 Class11=CProgressDialog
-Resource7=IDD_OBJECT_PRESENTATION
+Resource7=IDD_EDIT_RULE_COMMENT
 Class12=CObjectBrowser
-Resource8=IDD_DCI_COLLECTION
+Resource8=IDD_GROUP_PROPERTIES
 Class13=CObjectPropDlg
 Resource9=IDD_CP_GENERAL (English (U.S.))
 Resource10=IDA_OBJECT_BROWSER (English (U.S.))
@@ -46,7 +46,7 @@ Resource17=IDD_SET_PASSWORD (English (U.S.))
 Class16=CDebugFrame
 Resource18=IDD_OBJECT_SECURITY (English (U.S.))
 Resource19=IDD_OBJECT_PROPERTIES (English (U.S.))
-Resource20=IDD_ABOUTBOX
+Resource20=IDA_EPP
 Class17=CObjectPreview
 Resource21=IDD_DCI_TRANSFORM (English (U.S.))
 Class18=CToolBox
@@ -59,32 +59,32 @@ Class23=CNodePropsGeneral
 Resource23=IDD_LOGIN (English (U.S.))
 Class24=CObjectPropCaps
 Class25=CObjectPropSheet
-Resource24=IDA_EPP
+Resource24=IDA_MDI_DEFAULT
 Class26=CRequestProcessingDlg
 Resource25=IDD_EDIT_EVENT (English (U.S.))
 Resource26=IDD_PROGRESS (English (U.S.))
-Resource27=IDD_EDIT_RULE_ALARM
+Resource27=IDD_OBJECT_PRESENTATION
 Resource28=IDD_USER_PROPERTIES (English (U.S.))
 Class27=CObjectPropsGeneral
 Resource29=IDA_ALARM_BROWSER (English (U.S.))
 Class28=CObjectPropsSecurity
 Resource30=IDD_CREATE_NODE (English (U.S.))
-Resource31=IDD_GROUP_PROPERTIES
-Resource32=IDD_EDIT_RULE_SEVERITY
+Resource31=IDD_NEW_USER
+Resource32=IDD_SELECT_EVENT
 Class29=CUserSelectDlg
-Resource33=IDD_OBJECT_SECURITY
+Resource33=IDD_REQUEST_PROCESSING
 Class30=CUserEditor
 Resource34=IDD_DCI_PROPERTIES
 Class31=CNewUserDlg
-Resource35=IDD_OBJECT_GENERAL
-Resource36=IDA_ALARM_BROWSER
+Resource35=IDD_OBJECT_CAPS
+Resource36=IDA_OBJECT_BROWSER
 Class32=CUserPropDlg
 Resource37=IDM_CONTEXT (English (U.S.))
-Resource38=IDD_CP_GENERAL
+Resource38=IDD_EDIT_RULE_SEVERITY
 Class33=CGroupPropDlg
-Resource39=IDD_SELECT_OBJECT
-Resource40=IDA_MDI_DEFAULT
-Resource41=IDD_SELECT_ACTION
+Resource39=IDD_THRESHOLD
+Resource40=IDD_CREATE_NODE
+Resource41=IDD_NEW_ACTION
 Resource42=IDD_SELECT_OBJECT (English (U.S.))
 Class34=CPasswordChangeDlg
 Class35=CNodeSummary
@@ -100,10 +100,10 @@ Class41=CGraphFrame
 Class42=CDCIThresholdsPage
 Resource46=IDA_MDI_DEFAULT (English (U.S.))
 Resource47=IDD_OBJECT_CAPS (English (U.S.))
-Resource48=IDD_OBJECT_CAPS
+Resource48=IDD_EDIT_EVENT
 Class43=CThresholdDlg
 Resource49=IDD_SELECT_USER (English (U.S.))
-Resource50=IDD_NEW_USER
+Resource50=IDD_OBJECT_SECURITY
 Class44=CMIBBrowserDlg
 Class45=CEventPolicyEditor
 Class46=CRuleList
@@ -111,44 +111,44 @@ Class47=CRuleHeader
 Resource51=IDR_MAINFRAME (English (U.S.))
 Resource52=IDM_CONTEXT
 Class48=CObjectSelDlg
-Resource53=IDD_CREATE_CONTAINER
-Resource54=IDD_NEW_ACTION
+Resource53=IDD_ACTION_PROPERTIES
+Resource54=IDD_EDIT_RULE_ALARM
 Class49=CRuleCommentDlg
-Resource55=IDD_REQUEST_PROCESSING
+Resource55=IDD_OBJECT_NODE_GENERAL
 Class50=CEventSelDlg
-Resource56=IDD_USER_PROPERTIES
+Resource56=IDD_SELECT_USER
 Resource57=IDD_REQUEST_PROCESSING (English (U.S.))
-Resource58=IDD_EDIT_RULE_COMMENT
+Resource58=IDD_MIB_BROWSER
 Resource59=IDD_ABOUTBOX (English (U.S.))
 Resource60=IDD_MIB_BROWSER (English (U.S.))
 Class51=CObjectPropsPresentation
 Resource61=IDD_OBJECT_PRESENTATION (English (U.S.))
-Resource62=IDD_OBJECT_NODE_GENERAL
+Resource62=IDD_LOGIN
 Class52=CRuleSeverityDlg
-Resource63=IDD_MIB_BROWSER
+Resource63=IDD_DCI_THRESHOLDS
 Class53=CRuleAlarmDlg
 Class54=CAlarmBrowser
 Resource64=IDD_SELECT_EVENT (English (U.S.))
-Resource65=IDD_CREATE_NODE
+Resource65=IDD_SELECT_ACTION
 Resource66=IDD_NEW_ACTION (English (U.S.))
 Resource67=IDD_DCI_COLLECTION (English (U.S.))
 Resource68=IDD_NEW_USER (English (U.S.))
 Class55=CConsolePropsGeneral
 Class56=CActionEditor
-Resource69=IDD_LOGIN
-Resource70=IDD_ACTION_PROPERTIES
+Resource69=IDA_ALARM_BROWSER
+Resource70=IDD_CP_GENERAL
 Class57=CNewActionDlg
-Resource71=IDD_THRESHOLD
+Resource71=IDD_DCI_COLLECTION
 Class58=CEditActionDlg
-Resource72=IDA_OBJECT_BROWSER
+Resource72=IDR_MAINFRAME
 Class59=CActionSelDlg
-Resource73=IDD_SET_PASSWORD
+Resource73=IDD_USER_PROPERTIES
 Resource74=IDD_EDIT_RULE_COMMENT (English (U.S.))
 Resource75=IDD_EDIT_RULE_ALARM (English (U.S.))
 Resource76=IDM_VIEW_SPECIFIC
 Class60=CCreateObjectDlg
 Class61=CCreateContainerDlg
-Resource77=IDD_EDIT_EVENT
+Resource77=IDD_ABOUTBOX
 Class62=CCreateNodeDlg
 Resource78=IDA_EPP (English (U.S.))
 Resource79=IDD_CREATE_CONTAINER (English (U.S.))
index d6ca6b7..7c1c003 100644 (file)
@@ -8,6 +8,7 @@
 #include "LoginDialog.h"
 #include "CreateContainerDlg.h"
 #include "CreateNodeDlg.h"
+#include "NodePoller.h"
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
@@ -1251,9 +1252,15 @@ void CConsoleApp::DeleteNetXMSObject(NXC_OBJECT *pObject)
 
 void CConsoleApp::PollNode(DWORD dwObjectId, int iPollType)
 {
-   DWORD dwResult;
+       CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
+   CNodePoller *pWnd;
 
-   dwResult = DoNodePoll(dwObjectId, iPollType);
-   if (dwResult != RCC_SUCCESS)
-      ErrorBox(dwResult, _T("Error polling node: %s"));
+       pWnd = (CNodePoller *)pFrame->CreateNewChild(
+               RUNTIME_CLASS(CNodePoller), IDR_NODE_POLLER, m_hMDIMenu, m_hMDIAccel);
+   if (pWnd != NULL)
+   {
+      pWnd->m_dwObjectId = dwObjectId;
+      pWnd->m_iPollType = iPollType;
+      pWnd->PostMessage(WM_COMMAND, ID_POLL_RESTART, 0);
+   }
 }
index f5679ee..26b0618 100644 (file)
@@ -241,6 +241,10 @@ SOURCE=.\NewUserDlg.cpp
 # End Source File
 # Begin Source File
 
+SOURCE=.\NodePoller.cpp
+# End Source File
+# Begin Source File
+
 SOURCE=.\NodePropsGeneral.cpp
 # End Source File
 # Begin Source File
@@ -301,10 +305,6 @@ SOURCE=.\PasswordChangeDlg.cpp
 # End Source File
 # Begin Source File
 
-SOURCE=.\PollNodeDlg.cpp
-# End Source File
-# Begin Source File
-
 SOURCE=.\RequestProcessingDlg.cpp
 # End Source File
 # Begin Source File
@@ -502,6 +502,10 @@ SOURCE=..\..\..\include\nms_util.h
 # End Source File
 # Begin Source File
 
+SOURCE=.\NodePoller.h
+# End Source File
+# Begin Source File
+
 SOURCE=.\NodePropsGeneral.h
 # End Source File
 # Begin Source File
@@ -562,10 +566,6 @@ SOURCE=.\PasswordChangeDlg.h
 # End Source File
 # Begin Source File
 
-SOURCE=.\PollNodeDlg.h
-# End Source File
-# Begin Source File
-
 SOURCE=.\RequestProcessingDlg.h
 # End Source File
 # Begin Source File
index 55720d5..a1a62db 100644 (file)
@@ -414,6 +414,10 @@ BEGIN
         MENUITEM SEPARATOR
         MENUITEM "&Properties...",              ID_ACTION_PROPERTIES
     END
+    POPUP "Poll"
+    BEGIN
+        MENUITEM "&Restart",                    ID_POLL_RESTART
+    END
 END
 
 
@@ -1109,21 +1113,6 @@ BEGIN
     PUSHBUTTON      "&Create...",IDC_BUTTON_CREATE,171,68,50,14
 END
 
-IDD_POLL_NODE DIALOGEX 0, 0, 297, 181
-STYLE DS_MODALFRAME | DS_3DLOOK | DS_CENTER | WS_POPUP | WS_CAPTION | 
-    WS_SYSMENU
-CAPTION "Poll Node"
-FONT 8, "MS Sans Serif"
-BEGIN
-    CONTROL         "Progress1",IDC_POLL_PROGRESS,"msctls_progress32",0x0,7,
-                    17,283,8,WS_EX_CLIENTEDGE
-    LTEXT           "Operation progress",IDC_STATIC,7,7,60,8
-    LTEXT           "Messages",IDC_STATIC,7,30,33,8
-    EDITTEXT        IDC_EDIT_MSG,7,42,283,111,ES_MULTILINE | ES_AUTOVSCROLL | 
-                    ES_AUTOHSCROLL | ES_READONLY | WS_VSCROLL
-    PUSHBUTTON      "Close",IDCANCEL,123,160,50,14
-END
-
 
 #ifndef _MAC
 /////////////////////////////////////////////////////////////////////////////
@@ -1415,14 +1404,6 @@ BEGIN
         TOPMARGIN, 7
         BOTTOMMARGIN, 128
     END
-
-    IDD_POLL_NODE, DIALOG
-    BEGIN
-        LEFTMARGIN, 7
-        RIGHTMARGIN, 290
-        TOPMARGIN, 7
-        BOTTOMMARGIN, 174
-    END
 END
 #endif    // APSTUDIO_INVOKED
 
@@ -1542,6 +1523,7 @@ BEGIN
     IDR_OBJECTS             "\nObject Browser\nObject Browser"
     IDR_DEBUG_WINDOW        "\nDebug Log\nDebug Log"
     IDR_ACTION_EDITOR       "\nAction Configuration\nAction Configuration"
+    IDR_NODE_POLLER         "\nPoll Node\nPoll Node"
 END
 
 STRINGTABLE DISCARDABLE 
index b0e1228..a80e1aa 100644 (file)
@@ -54,6 +54,7 @@
 #define IDA_MDI_DEFAULT                 153
 #define IDR_ACTION_EDITOR               153
 #define IDA_OBJECT_BROWSER              154
+#define IDR_NODE_POLLER                 154
 #define IDI_SORT_UP                     156
 #define IDI_SORT_DOWN                   157
 #define IDD_OBJECT_NODE_GENERAL         159
 #define ID_OBJECT_POLL_STATUS           32876
 #define ID_OBJECT_POLL_CONFIGURATION    32877
 #define ID_CONTROLPANEL_DCT             32880
+#define ID_POLL_RESTART                 32881
 #define IDS_GETFOLDERPATH_FAILED        61216
 #define IDS_WORKDIR_CREATION_FAILED     61217
 
 #ifndef APSTUDIO_READONLY_SYMBOLS
 #define _APS_3D_CONTROLS                     1
 #define _APS_NEXT_RESOURCE_VALUE        229
-#define _APS_NEXT_COMMAND_VALUE         32881
+#define _APS_NEXT_COMMAND_VALUE         32882
 #define _APS_NEXT_CONTROL_VALUE         1172
 #define _APS_NEXT_SYMED_VALUE           119
 #endif
index 9c983d4..0f0bbc0 100644 (file)
@@ -219,7 +219,7 @@ BOOL Interface::DeleteFromDB(void)
 // Perform status poll on interface
 //
 
-void Interface::StatusPoll(ClientSession *pSession)
+void Interface::StatusPoll(ClientSession *pSession, DWORD dwRqId)
 {
    int iOldStatus = m_iStatus;
    DWORD dwPingStatus;
@@ -231,8 +231,8 @@ void Interface::StatusPoll(ClientSession *pSession)
       return;     // Interface has no IP address, we cannot check it
    }
 
-   SendPollerMsg("   Starting status poll on interface %s\r\n"
-                 "   Current interface status is %s\r\n",
+   SendPollerMsg(dwRqId, "   Starting status poll on interface %s\r\n"
+                         "   Current interface status is %s\r\n",
                  m_szName, g_pszStatusName[m_iStatus]);
    dwPingStatus = IcmpPing(m_dwIpAddr, 3, 1500, NULL);
    if (dwPingStatus == ICMP_RAW_SOCK_FAILED)
@@ -240,13 +240,13 @@ void Interface::StatusPoll(ClientSession *pSession)
    m_iStatus = (dwPingStatus == ICMP_SUCCESS) ? STATUS_NORMAL : STATUS_CRITICAL;
    if (m_iStatus != iOldStatus)
    {
-      SendPollerMsg("   Interface status changed to %s\r\n", g_pszStatusName[m_iStatus]);
+      SendPollerMsg(dwRqId, "   Interface status changed to %s\r\n", g_pszStatusName[m_iStatus]);
       PostEvent(m_iStatus == STATUS_NORMAL ? EVENT_INTERFACE_UP : EVENT_INTERFACE_DOWN,
                 GetParent()->Id(), "dsaad", m_dwId, m_szName, m_dwIpAddr, m_dwIpNetMask,
                 m_dwIfIndex);
       Modify();
    }
-   SendPollerMsg("   Finished status poll on interface %s\r\n", m_szName);
+   SendPollerMsg(dwRqId, "   Finished status poll on interface %s\r\n", m_szName);
 }
 
 
index eaa41f0..1b85166 100644 (file)
@@ -645,7 +645,7 @@ BOOL NetObj::IsChild(DWORD dwObjectId)
 // This method is used by Node and Interface class objects
 //
 
-void NetObj::SendPollerMsg(TCHAR *pszFormat, ...)
+void NetObj::SendPollerMsg(DWORD dwRqId, TCHAR *pszFormat, ...)
 {
    if (m_pPollRequestor != NULL)
    {
@@ -655,6 +655,6 @@ void NetObj::SendPollerMsg(TCHAR *pszFormat, ...)
       va_start(args, pszFormat);
       _vsntprintf(szBuffer, 1024, pszFormat, args);
       va_end(args);
-      m_pPollRequestor->SendPollerMsg(szBuffer);
+      m_pPollRequestor->SendPollerMsg(dwRqId, szBuffer);
    }
 }
index 34aadf2..626eb91 100644 (file)
@@ -232,6 +232,7 @@ private:
    MUTEX m_mutexSendObjects;
    MUTEX m_mutexSendAlarms;
    MUTEX m_mutexSendActions;
+   MUTEX m_mutexPollerInit;
    DWORD m_dwHostAddr;        // IP address of connected host (network byte order)
    char m_szUserName[256];    // String in form login_name@host
    DWORD m_dwOpenDCIListSize; // Number of open DCI lists
@@ -239,17 +240,18 @@ private:
    DWORD m_dwNumRecordsToUpload; // Number of records to be uploaded
    DWORD m_dwRecordsUploaded;
    EPRule **m_ppEPPRuleList;   // List of loaded EPP rules
-   DWORD m_dwPollRqId;        // Request ID for forced poll request
 
    static THREAD_RESULT THREAD_CALL ReadThreadStarter(void *);
    static THREAD_RESULT THREAD_CALL WriteThreadStarter(void *);
    static THREAD_RESULT THREAD_CALL ProcessingThreadStarter(void *);
    static THREAD_RESULT THREAD_CALL UpdateThreadStarter(void *);
+   static THREAD_RESULT THREAD_CALL PollerThreadStarter(void *);
 
    void ReadThread(void);
    void WriteThread(void);
    void ProcessingThread(void);
    void UpdateThread(void);
+   void PollerThread(Node *pNode, int iPollType, DWORD dwRqId);
 
    BOOL CheckSysAccessRights(DWORD dwRequiredAccess) 
    { 
@@ -305,7 +307,7 @@ public:
    void Run(void);
 
    void SendMessage(CSCPMessage *pMsg) { m_pSendQueue->Put(pMsg->CreateMessage()); }
-   void SendPollerMsg(TCHAR *pszMsg);
+   void SendPollerMsg(DWORD dwRqId, TCHAR *pszMsg);
 
    DWORD GetIndex(void) { return m_dwIndex; }
    void SetIndex(DWORD dwIndex) { if (m_dwIndex == INVALID_INDEX) m_dwIndex = dwIndex; }
index 7067d41..251c0b3 100644 (file)
@@ -105,7 +105,7 @@ protected:
    BOOL LoadACLFromDB(void);
    BOOL SaveACLToDB(void);
 
-   void SendPollerMsg(TCHAR *pszFormat, ...);
+   void SendPollerMsg(DWORD dwRqId, TCHAR *pszFormat, ...);
 
 public:
    NetObj();
@@ -187,7 +187,7 @@ public:
    DWORD IpNetMask(void) { return m_dwIpNetMask; }
    DWORD IfIndex(void) { return m_dwIfIndex; }
 
-   void StatusPoll(ClientSession *pSession);
+   void StatusPoll(ClientSession *pSession, DWORD dwRqId);
    virtual void CreateMessage(CSCPMessage *pMsg);
 };
 
@@ -262,7 +262,7 @@ public:
    Interface *FindInterface(DWORD dwIndex, DWORD dwHostAddr);
 
    void SetDiscoveryPollTimeStamp(void) { m_tLastDiscoveryPoll = time(NULL); }
-   void StatusPoll(ClientSession *pSession);
+   void StatusPoll(ClientSession *pSession, DWORD dwRqId);
    void ConfigurationPoll(void);
    BOOL ReadyForStatusPoll(void);
    BOOL ReadyForConfigurationPoll(void);
index 5a23917..22af4bb 100644 (file)
@@ -602,21 +602,21 @@ void Node::CalculateCompoundStatus(void)
 // Perform status poll on node
 //
 
-void Node::StatusPoll(ClientSession *pSession)
+void Node::StatusPoll(ClientSession *pSession, DWORD dwRqId)
 {
    DWORD i;
 
    PollerLock();
    m_pPollRequestor = pSession;
-   SendPollerMsg("Starting status poll for node %s\r\n", m_szName);
+   SendPollerMsg(dwRqId, "Starting status poll for node %s\r\n", m_szName);
    for(i = 0; i < m_dwChildCount; i++)
       if ((m_pChildList[i]->Type() == OBJECT_INTERFACE) &&
           (m_pChildList[i]->Status() != STATUS_UNMANAGED))
-         ((Interface *)m_pChildList[i])->StatusPoll(pSession);
+         ((Interface *)m_pChildList[i])->StatusPoll(pSession, dwRqId);
    CalculateCompoundStatus();
    m_tLastStatusPoll = time(NULL);
-   SendPollerMsg("Finished status poll for node %s\r\n"
-                 "Node status after poll is %s\r\n", m_szName, g_pszStatusName[m_iStatus]);
+   SendPollerMsg(dwRqId, "Finished status poll for node %s\r\n"
+                         "Node status after poll is %s\r\n", m_szName, g_pszStatusName[m_iStatus]);
    m_pPollRequestor = NULL;
    PollerUnlock();
 }
index dd2ceb6..d4fc9ef 100644 (file)
 void UnregisterSession(DWORD dwIndex);
 
 
+//
+// Node poller start data
+//
+
+typedef struct
+{
+   ClientSession *pSession;
+   Node *pNode;
+   int iPollType;
+   DWORD dwRqId;
+} POLLER_START_DATA;
+
+
 //
 // Fill CSCP message with user data
 //
@@ -120,6 +133,21 @@ THREAD_RESULT THREAD_CALL ClientSession::UpdateThreadStarter(void *pArg)
 }
 
 
+//
+// Forced node poll thread starter
+//
+
+THREAD_RESULT THREAD_CALL ClientSession::PollerThreadStarter(void *pArg)
+{
+   ((POLLER_START_DATA *)pArg)->pSession->PollerThread(
+      ((POLLER_START_DATA *)pArg)->pNode,
+      ((POLLER_START_DATA *)pArg)->iPollType,
+      ((POLLER_START_DATA *)pArg)->dwRqId);
+   free(pArg);
+   return THREAD_OK;
+}
+
+
 //
 // Client session class constructor
 //
@@ -140,6 +168,7 @@ ClientSession::ClientSession(SOCKET hSocket, DWORD dwHostAddr)
    m_mutexSendObjects = MutexCreate();
    m_mutexSendAlarms = MutexCreate();
    m_mutexSendActions = MutexCreate();
+   m_mutexPollerInit = MutexCreate();
    m_dwFlags = 0;
    m_dwHostAddr = dwHostAddr;
    strcpy(m_szUserName, "<not logged in>");
@@ -166,6 +195,7 @@ ClientSession::~ClientSession()
    MutexDestroy(m_mutexSendObjects);
    MutexDestroy(m_mutexSendAlarms);
    MutexDestroy(m_mutexSendActions);
+   MutexDestroy(m_mutexPollerInit);
    safe_free(m_pOpenDCIList);
    if (m_ppEPPRuleList != NULL)
    {
@@ -2599,16 +2629,19 @@ void ClientSession::SendContainerCategories(DWORD dwRqId)
 void ClientSession::ForcedNodePoll(CSCPMessage *pRequest)
 {
    CSCPMessage msg;
+   POLLER_START_DATA *pData;
    NetObj *pObject;
-   int iPollType;
+
+   pData = (POLLER_START_DATA *)malloc(sizeof(POLLER_START_DATA));
+   MutexLock(m_mutexPollerInit, INFINITE);
 
    // Prepare responce message
-   m_dwPollRqId = pRequest->GetId();
+   pData->dwRqId = pRequest->GetId();
    msg.SetCode(CMD_POLLING_INFO);
-   msg.SetId(m_dwPollRqId);
+   msg.SetId(pData->dwRqId);
 
    // Get polling type
-   iPollType = pRequest->GetVariableShort(VID_POLL_TYPE);
+   pData->iPollType = pRequest->GetVariableShort(VID_POLL_TYPE);
 
    // Find object to be deleted
    pObject = FindObjectById(pRequest->GetVariableLong(VID_OBJECT_ID));
@@ -2616,17 +2649,17 @@ void ClientSession::ForcedNodePoll(CSCPMessage *pRequest)
    {
       // We can do polls only for node objects
       if ((pObject->Type() == OBJECT_NODE) &&
-          ((iPollType == POLL_STATUS) || (iPollType == POLL_CONFIGURATION)))
+          ((pData->iPollType == POLL_STATUS) || (pData->iPollType == POLL_CONFIGURATION)))
       {
          // Check access rights
          if (pObject->CheckAccessRights(m_dwUserId, OBJECT_ACCESS_MODIFY))
          {
             ((Node *)pObject)->IncRefCount();
 
-            ((Node *)pObject)->StatusPoll(this);
-            
-            ((Node *)pObject)->DecRefCount();
-            msg.SetVariable(VID_RCC, RCC_SUCCESS);
+            pData->pNode = (Node *)pObject;
+            ThreadCreate(PollerThreadStarter, 0, pData);
+            msg.SetVariable(VID_RCC, RCC_OPERATION_IN_PROGRESS);
+            msg.SetVariable(VID_POLLER_MESSAGE, _T("Poll request accepted\r\n"));
          }
          else
          {
@@ -2645,6 +2678,7 @@ void ClientSession::ForcedNodePoll(CSCPMessage *pRequest)
 
    // Send responce
    SendMessage(&msg);
+   MutexUnlock(m_mutexPollerInit);
 }
 
 
@@ -2652,13 +2686,35 @@ void ClientSession::ForcedNodePoll(CSCPMessage *pRequest)
 // Send message fro poller to client
 //
 
-void ClientSession::SendPollerMsg(TCHAR *pszMsg)
+void ClientSession::SendPollerMsg(DWORD dwRqId, TCHAR *pszMsg)
 {
    CSCPMessage msg;
 
    msg.SetCode(CMD_POLLING_INFO);
-   msg.SetId(m_dwPollRqId);
+   msg.SetId(dwRqId);
    msg.SetVariable(VID_RCC, RCC_OPERATION_IN_PROGRESS);
    msg.SetVariable(VID_POLLER_MESSAGE, pszMsg);
    SendMessage(&msg);
 }
+
+
+//
+// Node poller thread
+//
+
+void ClientSession::PollerThread(Node *pNode, int iPollType, DWORD dwRqId)
+{
+   CSCPMessage msg;
+
+   // Wait while parent thread finishes initialization
+   MutexLock(m_mutexPollerInit, INFINITE);
+   MutexUnlock(m_mutexPollerInit);
+
+   pNode->StatusPoll(this, dwRqId);
+   pNode->DecRefCount();
+
+   msg.SetCode(CMD_POLLING_INFO);
+   msg.SetId(dwRqId);
+   msg.SetVariable(VID_RCC, RCC_SUCCESS);
+   SendMessage(&msg);
+}
index 0fc9675..03af4f1 100644 (file)
@@ -46,7 +46,7 @@ THREAD_RESULT THREAD_CALL StatusPoller(void *arg)
          pNode = (Node *)g_pNodeIndexByAddr[i].pObject;
          if (pNode->ReadyForStatusPoll())
          {
-            pNode->StatusPoll(NULL);
+            pNode->StatusPoll(NULL, 0);
             WatchdogNotify(dwWatchdogId);
          }
       }