- Fixed compilation problem on RedHat 7.3
authorVictor Kirhenshtein <victor@netxms.org>
Thu, 26 Jul 2007 12:55:50 +0000 (12:55 +0000)
committerVictor Kirhenshtein <victor@netxms.org>
Thu, 26 Jul 2007 12:55:50 +0000 (12:55 +0000)
- Alarm viewer fully functional

configure.ac
src/client/console/include/nxmc_api.h
src/client/console/libnxmc/main.cpp
src/client/console/libnxmc/nxview.cpp
src/client/console/libnxmc/nxview.h
src/client/console/nxmc/nxmc.cpp
src/client/console/nxmc/nxmc.h
src/client/console/plugins/AlarmBrowser/alarm_browser.h
src/client/console/plugins/AlarmBrowser/view.cpp

index bdf4438..6927b9a 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: configure.ac,v 1.261 2007-07-23 15:58:19 victor Exp $
+# $Id: configure.ac,v 1.262 2007-07-26 12:55:49 victor Exp $
 #
 # NetXMS - Network Management System
 # Configure script
@@ -455,6 +455,9 @@ case "$PLATFORM" in
       LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
       export LD_LIBRARY_PATH
       ;;
+   Linux)
+      CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
+      ;;
    *)
       ;;
 esac
index 3fc4595..570ccb0 100644 (file)
@@ -203,6 +203,7 @@ typedef struct
 //
 
 BEGIN_DECLARE_EVENT_TYPES()
+    DECLARE_EXPORTED_EVENT_TYPE(LIBNXMC_EXPORTABLE, nxEVT_REQUEST_COMPLETED, 0)
     DECLARE_EXPORTED_EVENT_TYPE(LIBNXMC_EXPORTABLE, nxEVT_REFRESH_VIEW, 0)
     DECLARE_EXPORTED_EVENT_TYPE(LIBNXMC_EXPORTABLE, nxEVT_NXC_ALARM_CHANGE, 0)
     DECLARE_EXPORTED_EVENT_TYPE(LIBNXMC_EXPORTABLE, nxEVT_NXC_OBJECT_CHANGE, 0)
@@ -214,6 +215,7 @@ END_DECLARE_EVENT_TYPES()
                   (wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent(wxCommandEventFunction, &fn), \
         (wxObject *) NULL \
     ),
+#define EVT_NX_REQUEST_COMPLETED(fn)   EVT_LIBNXMC_EVENT(nxEVT_REQUEST_COMPLETED, fn)
 #define EVT_NX_REFRESH_VIEW(fn)                        EVT_LIBNXMC_EVENT(nxEVT_REFRESH_VIEW, fn)
 #define EVT_NXC_ALARM_CHANGE(fn)                       EVT_LIBNXMC_EVENT(nxEVT_NXC_ALARM_CHANGE, fn)
 #define EVT_NXC_OBJECT_CHANGE(fn)              EVT_LIBNXMC_EVENT(nxEVT_NXC_OBJECT_CHANGE, fn)
index c16302f..d06d071 100644 (file)
@@ -37,6 +37,7 @@ wxWindow *g_auiDefaultParent = NULL;
 // Custom events
 //
 
+DEFINE_EVENT_TYPE(nxEVT_REQUEST_COMPLETED)
 DEFINE_EVENT_TYPE(nxEVT_REFRESH_VIEW)
 DEFINE_EVENT_TYPE(nxEVT_NXC_ALARM_CHANGE)
 DEFINE_EVENT_TYPE(nxEVT_NXC_OBJECT_CHANGE)
index 75b7d4e..1b5672f 100644 (file)
@@ -37,6 +37,7 @@
 
 BEGIN_EVENT_TABLE(nxView, wxWindow)
        EVT_TIMER(RQ_TIMER_ID, nxView::OnTimer)
+       EVT_NX_REQUEST_COMPLETED(nxView::OnRequestCompleted)
 END_EVENT_TABLE()
 
 
@@ -49,6 +50,9 @@ nxView::nxView(wxWindow *parent)
 {
        m_icon = wxNullBitmap;
        m_timer = new wxTimer(this, RQ_TIMER_ID);
+       m_activeRequestCount = 0;
+       m_freeRqId = 0;
+       m_isBusy = false;
 }
 
 
@@ -89,52 +93,54 @@ wxString nxView::GetLabel() const
 static THREAD_RESULT THREAD_CALL RequestThread(void *arg)
 {
    RqData *data = (RqData *)arg;
-   DWORD dwResult;
 
-       switch(data->dwNumParams)
+       switch(data->m_numArgs)
        {
                case 0:
-                       dwResult = data->func();
+                       data->m_rcc = data->m_func();
                        break;
                case 1:
-                       dwResult = data->func(data->arg1);
+                       data->m_rcc = data->m_func(data->m_arg[0]);
                        break;
                case 2:
-                       dwResult = data->func(data->arg1, data->arg2);
+                       data->m_rcc = data->m_func(data->m_arg[0], data->m_arg[1]);
                        break;
                case 3:
-                       dwResult = data->func(data->arg1, data->arg2, data->arg3);
+                       data->m_rcc = data->m_func(data->m_arg[0], data->m_arg[1], data->m_arg[2]);
                        break;
                case 4:
-                       dwResult = data->func(data->arg1, data->arg2, data->arg3, data->arg4);
+                       data->m_rcc = data->m_func(data->m_arg[0], data->m_arg[1], data->m_arg[2], data->m_arg[3]);
                        break;
                case 5:
-                       dwResult = data->func(data->arg1, data->arg2, data->arg3
-                                                                                       data->arg4, data->arg5);
+                       data->m_rcc = data->m_func(data->m_arg[0], data->m_arg[1], data->m_arg[2]
+                                                                                       data->m_arg[3], data->m_arg[4]);
                        break;
                case 6:
-                       dwResult = data->func(data->arg1, data->arg2, data->arg3
-                                                                                       data->arg4, data->arg5, data->arg6);
+                       data->m_rcc = data->m_func(data->m_arg[0], data->m_arg[1], data->m_arg[2]
+                                                                                       data->m_arg[3], data->m_arg[4], data->m_arg[5]);
                        break;
                case 7:
-                       dwResult = data->func(data->arg1, data->arg2, data->arg3, 
-                                                                                       data->arg4, data->arg5, data->arg6,
-                                                                                       data->arg7);
+                       data->m_rcc = data->m_func(data->m_arg[0], data->m_arg[1], data->m_arg[2], 
+                                                                                       data->m_arg[3], data->m_arg[4], data->m_arg[5],
+                                                                                       data->m_arg[6]);
+                       break;
                case 8:
-                       dwResult = data->func(data->arg1, data->arg2, data->arg3, 
-                                                                                       data->arg4, data->arg5, data->arg6,
-                                                                                       data->arg7, data->arg8);
+                       data->m_rcc = data->m_func(data->m_arg[0], data->m_arg[1], data->m_arg[2], 
+                                                                                       data->m_arg[3], data->m_arg[4], data->m_arg[5],
+                                                                                       data->m_arg[6], data->m_arg[7]);
+                       break;
                case 9:
-                       dwResult = data->func(data->arg1, data->arg2, data->arg3
-                                                                                       data->arg4, data->arg5, data->arg6,
-                                                                                       data->arg7, data->arg8, data->arg9);
+                       data->m_rcc = data->m_func(data->m_arg[0], data->m_arg[1], data->m_arg[2]
+                                                                                       data->m_arg[3], data->m_arg[4], data->m_arg[5],
+                                                                                       data->m_arg[6], data->m_arg[7], data->m_arg[8]);
                        break;
        }
-       if (data->hWnd != NULL)
-               PostMessage(data->hWnd, NXCM_REQUEST_COMPLETED, data->wParam, dwResult);
-       if (data->bDynamic)
-               free(data);
-   return dwResult;
+       
+       wxCommandEvent event(nxEVT_REQUEST_COMPLETED);
+       event.SetClientData(data);
+       wxPostEvent(data->m_owner, event);
+       
+   return THREAD_OK;
 }
 
 
@@ -142,22 +148,43 @@ static THREAD_RESULT THREAD_CALL RequestThread(void *arg)
 // Execute async request
 //
 
-DWORD nxView::DoRequest(RqData *data)
+int nxView::DoRequest(RqData *data)
 {
-       m_timer->Start(300, true);
+       if (m_activeRequestCount == 0)
+               m_timer->Start(300, true);
+       m_activeRequestCount++;
        ThreadCreate(RequestThread, 0, data);
+       return data->m_id;
+}
+
+int nxView::DoRequestArg1(void *func, wxUIntPtr arg1)
+{
+   RqData *data;
+
+       data = new RqData(m_freeRqId++, this, func, 1);
+   data->m_arg[0] = arg1;
+   return DoRequest(data);
+}
+
+int nxView::DoRequestArg2(void *func, wxUIntPtr arg1, wxUIntPtr arg2)
+{
+   RqData *data;
+
+       data = new RqData(m_freeRqId++, this, func, 2);
+   data->m_arg[0] = arg1;
+   data->m_arg[1] = arg2;
+   return DoRequest(data);
 }
 
-DWORD nxView::DoRequestArg1(void *func, void *arg1)
+int nxView::DoRequestArg3(void *func, wxUIntPtr arg1, wxUIntPtr arg2, wxUIntPtr arg3)
 {
-   RqData rqData;
-
-   rqData.hWnd = NULL;
-       rqData.isDynamic = false;
-   rqData.numParams = 1;
-   rqData.arg1 = arg1;
-   rqData.func = (DWORD (*)(...))func;
-   return ExecuteRequest(&rqData, pszInfoText);
+   RqData *data;
+
+       data = new RqData(m_freeRqId++, this, func, 3);
+   data->m_arg[0] = arg1;
+   data->m_arg[1] = arg2;
+   data->m_arg[2] = arg3;
+   return DoRequest(data);
 }
 
 
@@ -165,6 +192,43 @@ DWORD nxView::DoRequestArg1(void *func, void *arg1)
 // Timer event handler
 //
 
-void OnTimer(wxTimerEvent &event)
+void nxView::OnTimer(wxTimerEvent &event)
 {
+       if (m_activeRequestCount > 0)
+       {
+               // Set busy mode
+               SetCursor(*wxHOURGLASS_CURSOR);
+               m_isBusy = true;
+       }
 }
+
+
+//
+// Request completion event handler
+//
+
+void nxView::OnRequestCompleted(wxCommandEvent &event)
+{
+       RqData *data = (RqData *)event.GetClientData();
+       m_activeRequestCount--;
+       if (m_activeRequestCount == 0)
+       {
+               m_timer->Stop();
+
+               // Exit busy mode
+               SetCursor(wxNullCursor);
+               m_isBusy = false;
+       }
+       RequestCompletionHandler(data->m_id, data->m_rcc);
+       delete data;
+}
+
+
+//
+// Virtual request completion handler
+//
+
+void nxView::RequestCompletionHandler(int rqId, DWORD rcc)
+{
+}
+
index 0087d37..47f0c23 100644 (file)
 #ifndef _nxview_h_
 #define _nxview_h_
 
+
+//
+// Request data
+//
+
+class RqData
+{
+public:
+       RqData(int id, wxEvtHandler *owner, void *func, int numArgs)
+       { 
+               m_id = id;
+               m_owner = owner;
+               m_func = (DWORD (*)(...))func;
+               m_numArgs = numArgs;
+       }
+       
+       int m_id;
+       wxEvtHandler *m_owner;
+       DWORD (* m_func)(...);
+       int m_numArgs;
+       wxUIntPtr m_arg[9];
+       DWORD m_rcc;
+};
+
+
+//
+// Basic console view class
+//
+
 class LIBNXMC_EXPORTABLE nxView : public wxWindow
 {
 private:
        wxString m_label;
        wxBitmap m_icon;        // Icon associated with this view
        wxTimer *m_timer;
+       int m_activeRequestCount;
+       int m_freeRqId; // First free request id
+       bool m_isBusy;
+       
+       int DoRequest(RqData *data);
+       
+protected:
+       int DoRequestArg1(void *func, wxUIntPtr arg1);
+       int DoRequestArg2(void *func, wxUIntPtr arg1, wxUIntPtr arg2);
+       int DoRequestArg3(void *func, wxUIntPtr arg1, wxUIntPtr arg2, wxUIntPtr arg3);
+       
+       virtual void RequestCompletionHandler(int rqId, DWORD rcc);
 
 public:
        nxView(wxWindow *parent);
@@ -39,10 +80,13 @@ public:
        virtual wxString GetLabel() const;
 
        const wxBitmap& GetBitmap() { return m_icon; }
+       
+       bool IsBusy() { return m_isBusy; }
 
        // Event handlers
 protected:
        void OnTimer(wxTimerEvent &event);
+       void OnRequestCompleted(wxCommandEvent &event);
 
        DECLARE_EVENT_TABLE()
 };
index 21d9f4c..9a65934 100644 (file)
@@ -25,7 +25,6 @@ SNMP_MIBObject *g_mibRoot = NULL;
 // Custom events
 //
 
-DEFINE_LOCAL_EVENT_TYPE(nxEVT_REQUEST_COMPLETED)
 DEFINE_LOCAL_EVENT_TYPE(nxEVT_SET_STATUS_TEXT)
 
 
index f535937..2046df7 100644 (file)
@@ -32,7 +32,6 @@ extern "C" WXDLLIMPEXP_BASE HINSTANCE wxGetInstance();
 //
 
 BEGIN_DECLARE_EVENT_TYPES()
-    DECLARE_LOCAL_EVENT_TYPE(nxEVT_REQUEST_COMPLETED, 0)
     DECLARE_LOCAL_EVENT_TYPE(nxEVT_SET_STATUS_TEXT, 0)
 END_DECLARE_EVENT_TYPES()
 
@@ -42,7 +41,6 @@ END_DECLARE_EVENT_TYPES()
                  (wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxCommandEventFunction, &fn ), \
         (wxObject *) NULL \
     ),
-#define EVT_NX_REQUEST_COMPLETED(fn)   EVT_NXMC_EVENT(nxEVT_REQUEST_COMPLETED, fn)
 #define EVT_NX_SET_STATUS_TEXT(fn)     EVT_NXMC_EVENT(nxEVT_SET_STATUS_TEXT, fn)
 
 
index 2a0082d..b8eab06 100644 (file)
@@ -34,7 +34,7 @@
 // Alarm view class
 //
 
-class nxAlarmView : public wxWindow
+class nxAlarmView : public nxView
 {
 private:
        wxListView *m_wndListCtrl;
@@ -59,6 +59,8 @@ protected:
        void OnListColumnClick(wxListEvent &event);
        void OnAlarmChange(wxCommandEvent &event);
        void OnAlarmAck(wxCommandEvent &event);
+       void OnAlarmTerminate(wxCommandEvent &event);
+       void OnAlarmDelete(wxCommandEvent &event);
 
        DECLARE_EVENT_TABLE()
 };
index 28741fb..014e658 100644 (file)
 // Event table
 //
 
-BEGIN_EVENT_TABLE(nxAlarmView, wxWindow)
+BEGIN_EVENT_TABLE(nxAlarmView, nxView)
        EVT_SIZE(nxAlarmView::OnSize)
        EVT_LIST_ITEM_RIGHT_CLICK(wxID_LIST_CTRL, nxAlarmView::OnListItemRightClick)
        EVT_LIST_COL_CLICK(wxID_LIST_CTRL, nxAlarmView::OnListColumnClick)
        EVT_MENU(XRCID("menuAlarmAck"), nxAlarmView::OnAlarmAck)
+       EVT_MENU(XRCID("menuAlarmTerminate"), nxAlarmView::OnAlarmTerminate)
+       EVT_MENU(XRCID("menuAlarmDelete"), nxAlarmView::OnAlarmDelete)
 END_EVENT_TABLE()
 
 
@@ -41,7 +43,7 @@ END_EVENT_TABLE()
 //
 
 nxAlarmView::nxAlarmView(wxWindow *parent, const TCHAR *context)
-            : wxWindow(parent, wxID_ANY)
+            : nxView(parent)
 {
        wxConfigBase *cfg = wxConfig::Get();
        wxString path = cfg->GetPath();
@@ -185,11 +187,14 @@ void nxAlarmView::OnListItemRightClick(wxListEvent &event)
 {
        wxMenu *menu;
 
-       menu = wxXmlResource::Get()->LoadMenu(_T("menuCtxAlarm"));
-       if (menu != NULL)
+       if (!IsBusy())
        {
-               PopupMenu(menu);
-               delete menu;
+               menu = wxXmlResource::Get()->LoadMenu(_T("menuCtxAlarm"));
+               if (menu != NULL)
+               {
+                       PopupMenu(menu);
+                       delete menu;
+               }
        }
 }
 
@@ -322,8 +327,109 @@ void nxAlarmView::OnAlarmChange(wxCommandEvent &event)
 // Handler for acknowledge alarm menu
 //
 
+static DWORD AckAlarms(int count, DWORD *list)
+{
+       int i;
+       DWORD rcc;
+       NXC_SESSION session = NXMCGetSession();
+       
+       for(i = 0; i < count; i++)
+       {
+               rcc = NXCAcknowledgeAlarm(session, list[i]);
+               if (rcc != RCC_SUCCESS)
+                       break;
+       }
+       delete list;
+       return rcc;
+}
+
 void nxAlarmView::OnAlarmAck(wxCommandEvent &event)
 {
-//     NXCAcknowledgeAlarm(NXMCGetSession(), m_wndListCtrl->GetItemData(m_wndListCtrl->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED)));
+       int i, count = m_wndListCtrl->GetSelectedItemCount();
+       DWORD *idList = new DWORD[count];
+       long item;
+
+       for(i = 0, item = -1; i < count; i++)
+       {
+               item = m_wndListCtrl->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
+               if (item == -1)
+                       break;
+               idList[i] = m_wndListCtrl->GetItemData(item);
+       }
+       DoRequestArg2((void *)AckAlarms, count, CAST_FROM_POINTER(idList, wxUIntPtr));
+}
+
+
+//
+// Handler for terminate alarm menu
+//
+
+static DWORD TerminateAlarms(int count, DWORD *list)
+{
+       int i;
+       DWORD rcc;
+       NXC_SESSION session = NXMCGetSession();
+       
+       for(i = 0; i < count; i++)
+       {
+               rcc = NXCTerminateAlarm(session, list[i]);
+               if (rcc != RCC_SUCCESS)
+                       break;
+       }
+       delete list;
+       return rcc;
+}
+
+void nxAlarmView::OnAlarmTerminate(wxCommandEvent &event)
+{
+       int i, count = m_wndListCtrl->GetSelectedItemCount();
+       DWORD *idList = new DWORD[count];
+       long item;
+
+       for(i = 0, item = -1; i < count; i++)
+       {
+               item = m_wndListCtrl->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
+               if (item == -1)
+                       break;
+               idList[i] = m_wndListCtrl->GetItemData(item);
+       }
+       DoRequestArg2((void *)TerminateAlarms, count, CAST_FROM_POINTER(idList, wxUIntPtr));
+}
+
+
+//
+// Handler for delete alarm menu
+//
+
+static DWORD DeleteAlarms(int count, DWORD *list)
+{
+       int i;
+       DWORD rcc;
+       NXC_SESSION session = NXMCGetSession();
+       
+       for(i = 0; i < count; i++)
+       {
+               rcc = NXCDeleteAlarm(session, list[i]);
+               if (rcc != RCC_SUCCESS)
+                       break;
+       }
+       delete list;
+       return rcc;
+}
+
+void nxAlarmView::OnAlarmDelete(wxCommandEvent &event)
+{
+       int i, count = m_wndListCtrl->GetSelectedItemCount();
+       DWORD *idList = new DWORD[count];
+       long item;
+
+       for(i = 0, item = -1; i < count; i++)
+       {
+               item = m_wndListCtrl->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
+               if (item == -1)
+                       break;
+               idList[i] = m_wndListCtrl->GetItemData(item);
+       }
+       DoRequestArg2((void *)DeleteAlarms, count, CAST_FROM_POINTER(idList, wxUIntPtr));
 }