Unbind working
authorVictor Kirhenshtein <victor@netxms.org>
Mon, 30 Jul 2007 16:54:00 +0000 (16:54 +0000)
committerVictor Kirhenshtein <victor@netxms.org>
Mon, 30 Jul 2007 16:54:00 +0000 (16:54 +0000)
src/client/console/include/nxmc_api.h
src/client/console/libnxmc/nxview.cpp
src/client/console/libnxmc/nxview.h
src/client/console/libnxmc/tools.cpp
src/client/console/plugins/AlarmBrowser/view.cpp
src/client/console/plugins/ObjectBrowser/browser.cpp
src/client/console/plugins/ObjectBrowser/object_browser.h

index b53ea01..39db381 100644 (file)
@@ -323,7 +323,7 @@ void LIBNXMC_EXPORTABLE NXMCInitializationComplete();
 
 nxmcArrayOfRegItems LIBNXMC_EXPORTABLE &NXMCGetRegistrations();
 
-void LIBNXMC_EXPORTABLE NXMCShowClientError(DWORD rcc, TCHAR *msgTemplate);
+void LIBNXMC_EXPORTABLE NXMCShowClientError(DWORD rcc, const TCHAR *msgTemplate);
 
 bool LIBNXMC_EXPORTABLE NXMCLoadResources(const TCHAR *name, NXMC_LIB_INSTANCE instance, TCHAR *resName);
 
index 1f94c5b..114ab5a 100644 (file)
@@ -148,7 +148,7 @@ static THREAD_RESULT THREAD_CALL RequestThread(void *arg)
 // Execute async request
 //
 
-int nxView::DoRequest(RqData *data, TCHAR *errMsg)
+int nxView::DoRequest(RqData *data)
 {
        if (m_activeRequestCount == 0)
                m_timer->Start(300, true);
@@ -157,30 +157,30 @@ int nxView::DoRequest(RqData *data, TCHAR *errMsg)
        return data->m_id;
 }
 
-int nxView::DoRequestArg1(void *func, wxUIntPtr arg1)
+int nxView::DoRequestArg1(void *func, wxUIntPtr arg1, const TCHAR *errMsg)
 {
    RqData *data;
 
-       data = new RqData(m_freeRqId++, this, func, 1);
+       data = new RqData(m_freeRqId++, this, func, 1, errMsg);
    data->m_arg[0] = arg1;
    return DoRequest(data);
 }
 
-int nxView::DoRequestArg2(void *func, wxUIntPtr arg1, wxUIntPtr arg2)
+int nxView::DoRequestArg2(void *func, wxUIntPtr arg1, wxUIntPtr arg2, const TCHAR *errMsg)
 {
    RqData *data;
 
-       data = new RqData(m_freeRqId++, this, func, 2);
+       data = new RqData(m_freeRqId++, this, func, 2, errMsg);
    data->m_arg[0] = arg1;
    data->m_arg[1] = arg2;
    return DoRequest(data);
 }
 
-int nxView::DoRequestArg3(void *func, wxUIntPtr arg1, wxUIntPtr arg2, wxUIntPtr arg3)
+int nxView::DoRequestArg3(void *func, wxUIntPtr arg1, wxUIntPtr arg2, wxUIntPtr arg3, const TCHAR *errMsg)
 {
    RqData *data;
 
-       data = new RqData(m_freeRqId++, this, func, 3);
+       data = new RqData(m_freeRqId++, this, func, 3, errMsg);
    data->m_arg[0] = arg1;
    data->m_arg[1] = arg2;
    data->m_arg[2] = arg3;
@@ -209,6 +209,8 @@ void nxView::OnTimer(wxTimerEvent &event)
 
 void nxView::OnRequestCompleted(wxCommandEvent &event)
 {
+       nxIntToStringHash::iterator it;
+       
        RqData *data = (RqData *)event.GetClientData();
        m_activeRequestCount--;
        if (m_activeRequestCount == 0)
@@ -219,7 +221,7 @@ void nxView::OnRequestCompleted(wxCommandEvent &event)
                SetCursor(wxNullCursor);
                m_isBusy = false;
        }
-       RequestCompletionHandler(data->m_id, data->m_rcc);
+       RequestCompletionHandler(data->m_id, data->m_rcc, data->m_errMsg);
        delete data;
 }
 
@@ -228,19 +230,11 @@ void nxView::OnRequestCompleted(wxCommandEvent &event)
 // Virtual request completion handler
 //
 
-void nxView::RequestCompletionHandler(int rqId, DWORD rcc)
+void nxView::RequestCompletionHandler(int rqId, DWORD rcc, const TCHAR *errMsg)
 {
-       nxIntToStringHash::iterator it;
-
-       it = m_requestErrorMessages.find(rqId);
-       if (it != m_requestErrorMessages.end())
+       if ((rcc != RCC_SUCCESS) && (errMsg != NULL))
        {
-               if (rcc != RCC_SUCCESS)
-               {
-                       NXMCShowClientError(rcc, it->second);
-               }
-               free(it->second);
-               m_requestErrorMessages.erase(it);
+               NXMCShowClientError(rcc, errMsg);
        }
 }
 
index 73e5c01..d640f6e 100644 (file)
 class RqData
 {
 public:
-       RqData(int id, wxEvtHandler *owner, void *func, int numArgs)
+       RqData(int id, wxEvtHandler *owner, void *func, int numArgs, const TCHAR *errMsg)
        { 
                m_id = id;
                m_owner = owner;
                m_func = (DWORD (*)(...))func;
                m_numArgs = numArgs;
+               m_errMsg = (errMsg != NULL) ? _tcsdup(errMsg) : NULL;
+       }
+       ~RqData()
+       {
+               safe_free(m_errMsg);
        }
        
        int m_id;
@@ -46,6 +51,7 @@ public:
        int m_numArgs;
        wxUIntPtr m_arg[9];
        DWORD m_rcc;
+       TCHAR *m_errMsg;
 };
 
 
@@ -68,11 +74,11 @@ private:
        
 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);
+       int DoRequestArg1(void *func, wxUIntPtr arg1, const TCHAR *errMsg);
+       int DoRequestArg2(void *func, wxUIntPtr arg1, wxUIntPtr arg2, const TCHAR *errMsg);
+       int DoRequestArg3(void *func, wxUIntPtr arg1, wxUIntPtr arg2, wxUIntPtr arg3, const TCHAR *errMsg);
        
-       virtual void RequestCompletionHandler(int rqId, DWORD rcc);
+       virtual void RequestCompletionHandler(int rqId, DWORD rcc, const TCHAR *errMsg);
 
 public:
        nxView(wxWindow *parent);
index 02214bb..46d7596 100644 (file)
@@ -155,7 +155,7 @@ void LIBNXMC_EXPORTABLE NXMCLoadListCtrlColumns(wxConfigBase *cfg, wxListCtrl &w
 // Show client library error
 //
 
-void LIBNXMC_EXPORTABLE NXMCShowClientError(DWORD rcc, TCHAR *msgTemplate)
+void LIBNXMC_EXPORTABLE NXMCShowClientError(DWORD rcc, const TCHAR *msgTemplate)
 {
        TCHAR msg[4096];
 
index 7549a61..ebade24 100644 (file)
@@ -380,7 +380,7 @@ void nxAlarmView::OnAlarmAck(wxCommandEvent &event)
                        break;
                idList[i] = m_wndListCtrl->GetItemData(item);
        }
-       DoRequestArg2((void *)AckAlarms, count, CAST_FROM_POINTER(idList, wxUIntPtr));
+       DoRequestArg2((void *)AckAlarms, count, CAST_FROM_POINTER(idList, wxUIntPtr), _T("Cannot acknowledge alarm: %s"));
 }
 
 
@@ -417,7 +417,7 @@ void nxAlarmView::OnAlarmTerminate(wxCommandEvent &event)
                        break;
                idList[i] = m_wndListCtrl->GetItemData(item);
        }
-       DoRequestArg2((void *)TerminateAlarms, count, CAST_FROM_POINTER(idList, wxUIntPtr));
+       DoRequestArg2((void *)TerminateAlarms, count, CAST_FROM_POINTER(idList, wxUIntPtr), _T("Cannot terminate alarm: %s"));
 }
 
 
@@ -454,5 +454,5 @@ void nxAlarmView::OnAlarmDelete(wxCommandEvent &event)
                        break;
                idList[i] = m_wndListCtrl->GetItemData(item);
        }
-       DoRequestArg2((void *)DeleteAlarms, count, CAST_FROM_POINTER(idList, wxUIntPtr));
+       DoRequestArg2((void *)DeleteAlarms, count, CAST_FROM_POINTER(idList, wxUIntPtr), _T("Cannot delete alarm: %s"));
 }
index 7f4fc9e..b7c516a 100644 (file)
@@ -45,6 +45,8 @@ BEGIN_EVENT_TABLE(nxObjectBrowser, nxView)
        EVT_TREE_ITEM_MENU(wxID_TREE_CTRL, nxObjectBrowser::OnTreeItemMenu)
        EVT_MENU(XRCID("menuObjectBind"), nxObjectBrowser::OnObjectBind)
        EVT_UPDATE_UI(XRCID("menuObjectBind"), nxObjectBrowser::OnUpdateUIObjectBind)
+       EVT_MENU(XRCID("menuObjectUnbind"), nxObjectBrowser::OnObjectUnbind)
+       EVT_UPDATE_UI(XRCID("menuObjectUnbind"), nxObjectBrowser::OnUpdateUIObjectUnbind)
 END_EVENT_TABLE()
 
 
@@ -453,7 +455,7 @@ void nxObjectBrowser::OnObjectBind(wxCommandEvent &event)
                dlg.m_allowedClasses = SCL_SUBNET | SCL_NODE | SCL_CONTAINER | SCL_CONDITION;
                if (dlg.ShowModal() == wxID_OK)
                {
-                       DoRequestArg2(BindObjects, m_currentObject->dwId, CAST_FROM_POINTER(new wxArrayLong(dlg.m_objectList), wxUIntPtr));
+                       DoRequestArg2((void *)BindObjects, m_currentObject->dwId, CAST_FROM_POINTER(new wxArrayLong(dlg.m_objectList), wxUIntPtr), _T("Error binding object: %s"));
                }
        }
 }
@@ -470,3 +472,59 @@ void nxObjectBrowser::OnUpdateUIObjectBind(wxUpdateUIEvent &event)
                             (m_currentObject->iClass == OBJECT_CONTAINER));
        }
 }
+
+
+//
+// Handlers for Object->Unbind menu
+//
+
+static DWORD UnbindObjects(DWORD parentId, wxArrayLong *childList)
+{
+       size_t i, count;
+       DWORD rcc;
+       NXC_SESSION session = NXMCGetSession();
+
+       count = childList->GetCount();
+       for(i = 0; i < count; i++)
+       {
+               rcc = NXCUnbindObject(session, parentId, childList->Item(i));
+               if (rcc != RCC_SUCCESS)
+                       break;
+       }
+       delete childList;
+       return rcc;
+}
+
+void nxObjectBrowser::OnObjectUnbind(wxCommandEvent &event)
+{
+       if ((m_currentObject != NULL) &&
+                ((m_currentObject->iClass == OBJECT_SERVICEROOT) ||
+                 (m_currentObject->iClass == OBJECT_CONTAINER) ||
+                 (m_currentObject->iClass == OBJECT_TEMPLATE)))
+       {
+               nxObjectSelDlg dlg(this);
+
+               dlg.m_isSingleSelection = false;
+               dlg.m_allowedClasses = SCL_SUBNET | SCL_NODE | SCL_CONTAINER | SCL_CONDITION;
+               dlg.m_parentObjectId = m_currentObject->dwId;
+               if (dlg.ShowModal() == wxID_OK)
+               {
+                       DoRequestArg2((void *)UnbindObjects, m_currentObject->dwId, CAST_FROM_POINTER(new wxArrayLong(dlg.m_objectList), wxUIntPtr), _T("Error unbinding object: %s"));
+               }
+       }
+}
+
+void nxObjectBrowser::OnUpdateUIObjectUnbind(wxUpdateUIEvent &event)
+{
+       if (m_currentObject == NULL)
+       {
+               event.Enable(false);
+       }
+       else
+       {
+               event.Enable((m_currentObject->iClass == OBJECT_SERVICEROOT) ||
+                            (m_currentObject->iClass == OBJECT_CONTAINER) ||
+                            (m_currentObject->iClass == OBJECT_TEMPLATE));
+       }
+}
+
index 6b10196..9868844 100644 (file)
@@ -162,6 +162,8 @@ protected:
        void OnObjectChange(wxCommandEvent &event);
        void OnObjectBind(wxCommandEvent &event);
        void OnUpdateUIObjectBind(wxUpdateUIEvent &event);
+       void OnObjectUnbind(wxCommandEvent &event);
+       void OnUpdateUIObjectUnbind(wxUpdateUIEvent &event);
 
        DECLARE_EVENT_TABLE()
 };