- Finished migration to new client library model
authorVictor Kirhenshtein <victor@netxms.org>
Tue, 21 Dec 2004 16:48:56 +0000 (16:48 +0000)
committerVictor Kirhenshtein <victor@netxms.org>
Tue, 21 Dec 2004 16:48:56 +0000 (16:48 +0000)
- Fixed bug in NXC_EVENT structure transmission over network (incorrect UNICODE handling)
- Added function SwapWideString()

44 files changed:
include/netxms-version.h
include/nms_util.h
include/nxclapi.h
src/agent/subagents/skeleton/skeleton.cpp
src/console/win32/ActionEditor.cpp
src/console/win32/AlarmBrowser.cpp
src/console/win32/CreateObjectDlg.cpp
src/console/win32/DCIDataView.cpp
src/console/win32/DCIThresholdsPage.cpp
src/console/win32/DataCollectionEditor.cpp
src/console/win32/DataQueryDlg.cpp
src/console/win32/EventBrowser.cpp
src/console/win32/EventEditor.cpp
src/console/win32/EventPolicyEditor.cpp
src/console/win32/EventSelDlg.cpp
src/console/win32/GraphFrame.cpp
src/console/win32/GroupPropDlg.cpp
src/console/win32/MIBBrowserDlg.cpp
src/console/win32/MainFrm.cpp
src/console/win32/MapFrame.cpp
src/console/win32/NodeSummary.cpp
src/console/win32/ObjectBrowser.cpp
src/console/win32/ObjectPropSheet.cpp
src/console/win32/ObjectPropsSecurity.cpp
src/console/win32/ObjectSelDlg.cpp
src/console/win32/ThresholdDlg.cpp
src/console/win32/TrapEditDlg.cpp
src/console/win32/TrapEditor.cpp
src/console/win32/UserEditor.cpp
src/console/win32/UserSelectDlg.cpp
src/console/win32/comm.cpp
src/console/win32/globals.cpp
src/console/win32/globals.h
src/console/win32/nxcon.cpp
src/libnetxms/main.cpp
src/libnetxms/unicode.cpp
src/libnxcl/eventdb.cpp
src/libnxcl/events.cpp
src/libnxcl/libnxcl.dsp
src/libnxcl/libnxcl.h
src/libnxcl/session.cpp
src/nxevent/nxevent.cpp
src/server/core/events.cpp
src/server/core/session.cpp

index 564e4ff..2fc4769 100644 (file)
@@ -31,7 +31,7 @@
 #define NETXMS_VERSION_MAJOR      0
 #define NETXMS_VERSION_MINOR      1
 #define NETXMS_VERSION_BUILD      9
-#define NETXMS_VERSION_STRING     "0.1.9"
+#define NETXMS_VERSION_STRING     _T("0.1.9")
 
 
 #endif
index 5aad5c8..27272cc 100644 (file)
@@ -152,16 +152,18 @@ typedef struct _dir_struc
 //
 
 
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-#define htonq(x) __bswap_64(x)
-#define ntohq(x) __bswap_64(x)
-#define htond(x) __bswap_double(x)
-#define ntohd(x) __bswap_double(x)
-#else
+#if WORDS_BIGENDIAN
 #define htonq(x) (x)
 #define ntohq(x) (x)
 #define htond(x) (x)
 #define ntohd(x) (x)
+#define SwapWideString(x)
+#else
+#define htonq(x) __bswap_64(x)
+#define ntohq(x) __bswap_64(x)
+#define htond(x) __bswap_double(x)
+#define ntohd(x) __bswap_double(x)
+#define SwapWideString(x)  __bswap_wstr(x)
 #endif
 
 #ifdef __cplusplus
@@ -172,6 +174,7 @@ extern "C"
    QWORD LIBNETXMS_EXPORTABLE __bswap_64(QWORD qwVal);
 #endif
    double LIBNETXMS_EXPORTABLE __bswap_double(double dVal);
+   void LIBNETXMS_EXPORTABLE __bswap_wstr(WCHAR *pStr);
 
 #if !defined(_WIN32) && !defined(_NETWARE)
    void LIBNETXMS_EXPORTABLE strupr(TCHAR *in);
index a4f887a..6cf15f8 100644 (file)
@@ -443,7 +443,11 @@ typedef struct
    DWORD dwEventCode;
    DWORD dwSourceId;
    DWORD dwSeverity;
-   TCHAR  szMessage[MAX_EVENT_MSG_LENGTH];
+#ifdef UNICODE
+   WCHAR szMessage[MAX_EVENT_MSG_LENGTH];
+#else
+   char szMessage[MAX_EVENT_MSG_LENGTH * sizeof(WCHAR)];
+#endif
 } NXC_EVENT;
 
 
@@ -871,7 +875,7 @@ DWORD LIBNXCL_EXPORTABLE NXCPollNode(NXC_SESSION hSession, DWORD dwObjectId, int
 DWORD LIBNXCL_EXPORTABLE NXCWakeUpNode(NXC_SESSION hSession, DWORD dwObjectId);
 
 DWORD LIBNXCL_EXPORTABLE NXCLoadCCList(NXC_SESSION hSession, NXC_CC_LIST **ppList);
-void LIBNXCL_EXPORTABLE NXCDestroyCCList(NXC_SESSION hSession, NXC_CC_LIST *pList);
+void LIBNXCL_EXPORTABLE NXCDestroyCCList(NXC_CC_LIST *pList);
 
 DWORD LIBNXCL_EXPORTABLE NXCSyncEvents(NXC_SESSION hSession);
 DWORD LIBNXCL_EXPORTABLE NXCLoadEventDB(NXC_SESSION hSession);
index 1f98950..b09a9ac 100644 (file)
@@ -91,7 +91,7 @@ static NETXMS_SUBAGENT_ENUM m_enums[] =
 static NETXMS_SUBAGENT_INFO m_info =
 {
    NETXMS_SUBAGENT_INFO_MAGIC,
-       _T("SKELETON"), _T("1.0"), UnloadHandler,
+       _T("SKELETON"), _T("1.0"), UnloadHandler, NULL,
        sizeof(m_parameters) / sizeof(NETXMS_SUBAGENT_PARAM),
        m_parameters,
        sizeof(m_enums) / sizeof(NETXMS_SUBAGENT_ENUM),
index 853747b..c7c2890 100644 (file)
@@ -140,7 +140,7 @@ void CActionEditor::OnSize(UINT nType, int cx, int cy)
 
 void CActionEditor::OnClose() 
 {
-   DoRequest(NXCUnlockActionDB, "Unlocking action configuration database...");
+   DoRequestArg1(NXCUnlockActionDB, g_hSession, "Unlocking action configuration database...");
        CMDIChildWnd::OnClose();
 }
 
@@ -254,7 +254,7 @@ void CActionEditor::OnActionNew()
 
    if (dlg.DoModal() == IDOK)
    {
-      dwResult = DoRequestArg2(NXCCreateAction, (void *)((LPCTSTR)dlg.m_strName), 
+      dwResult = DoRequestArg3(NXCCreateAction, g_hSession, (void *)((LPCTSTR)dlg.m_strName), 
                                &dwActionId, "Creating new action...");
       if (dwResult == RCC_SUCCESS)
       {
@@ -332,7 +332,7 @@ void CActionEditor::OnActionProperties()
                strncpy(action.szName, (LPCTSTR)dlg.m_strName, MAX_OBJECT_NAME);
                strncpy(action.szRcptAddr, (LPCTSTR)dlg.m_strRcpt, MAX_RCPT_ADDR_LEN);
 
-               dwResult = DoRequestArg1(NXCModifyAction, &action, "Updating action configuration...");
+               dwResult = DoRequestArg2(NXCModifyAction, g_hSession, &action, "Updating action configuration...");
                if (dwResult == RCC_SUCCESS)
                {
                   ReplaceItem(iItem, &action);
index 7affffd..6ab4d2b 100644 (file)
@@ -178,8 +178,8 @@ void CAlarmBrowser::OnViewRefresh()
    NXC_ALARM *pAlarmList;
 
    m_wndListCtrl.DeleteAllItems();
-   dwRetCode = DoRequestArg3(NXCLoadAllAlarms, (void *)m_bShowAllAlarms, &dwNumAlarms, 
-                             &pAlarmList, _T("Loading alarms..."));
+   dwRetCode = DoRequestArg4(NXCLoadAllAlarms, g_hSession, (void *)m_bShowAllAlarms, 
+                             &dwNumAlarms, &pAlarmList, _T("Loading alarms..."));
    if (dwRetCode == RCC_SUCCESS)
    {
       memset(m_iNumAlarms, 0, sizeof(int) * 5);
@@ -206,7 +206,7 @@ void CAlarmBrowser::AddAlarm(NXC_ALARM *pAlarm)
    TCHAR szBuffer[64];
    NXC_OBJECT *pObject;
 
-   pObject = NXCFindObjectById(pAlarm->dwSourceObject);
+   pObject = NXCFindObjectById(g_hSession, pAlarm->dwSourceObject);
    iIdx = m_wndListCtrl.InsertItem(0x7FFFFFFF, g_szStatusTextSmall[pAlarm->wSeverity],
                                    pAlarm->wSeverity);
    if (iIdx != -1)
@@ -311,7 +311,8 @@ void CAlarmBrowser::OnAlarmAcknowlege()
    iItem = m_wndListCtrl.GetNextItem(-1, LVNI_SELECTED);
    while(iItem != -1)
    {
-      DoRequestArg1(NXCAcknowlegeAlarm, (void *)m_wndListCtrl.GetItemData(iItem), "Acknowleging alarm...");
+      DoRequestArg2(NXCAcknowlegeAlarm, g_hSession, 
+                    (void *)m_wndListCtrl.GetItemData(iItem), _T("Acknowleging alarm..."));
       iItem = m_wndListCtrl.GetNextItem(iItem, LVNI_SELECTED);
    }
 }
index 1e7a71c..8feb247 100644 (file)
@@ -70,7 +70,7 @@ void CCreateObjectDlg::OnSelectParent()
    dlg.m_bSingleSelection = TRUE;
    if (dlg.DoModal() == IDOK)
    {
-      m_pParentObject = NXCFindObjectById(dlg.m_pdwObjectList[0]);
+      m_pParentObject = NXCFindObjectById(g_hSession, dlg.m_pdwObjectList[0]);
       UpdateParentInfo();
    }
 }
index 99a19e7..57bf901 100644 (file)
@@ -130,13 +130,13 @@ void CDCIDataView::OnViewRefresh()
    NXC_DCI_DATA *pData;
 
    m_wndListCtrl.DeleteAllItems();
-   dwResult = DoRequestArg6(NXCGetDCIData, (void *)m_dwNodeId, (void *)m_dwItemId,
-                            (void *)1000, 0, 0, &pData, "Loading item data...");
+   dwResult = DoRequestArg7(NXCGetDCIData, g_hSession, (void *)m_dwNodeId, (void *)m_dwItemId,
+                            (void *)1000, 0, 0, &pData, _T("Loading item data..."));
    if (dwResult == RCC_SUCCESS)
    {
       DWORD i;
       NXC_DCI_ROW *pRow;
-      char szBuffer[256];
+      TCHAR szBuffer[256];
 
       for(i = 0, pRow = pData->pRows; i < pData->dwNumRows; i++)
       {
@@ -182,10 +182,10 @@ void CDCIDataView::OnViewRefresh()
    }
    else
    {
-      theApp.ErrorBox(dwResult, "Unable to retrieve colected data: %s");
+      theApp.ErrorBox(dwResult, _T("Unable to retrieve colected data: %s"));
       iItem = m_wndListCtrl.InsertItem(0, "");
       if (iItem != -1)
-         m_wndListCtrl.SetItemText(iItem, 1, "ERROR LOADING DATA FROM SERVER");
+         m_wndListCtrl.SetItemText(iItem, 1, _T("ERROR LOADING DATA FROM SERVER"));
    }
 }
 
index c78250e..1034560 100644 (file)
@@ -156,7 +156,8 @@ void CDCIThresholdsPage::UpdateListEntry(int iItem, DWORD dwIndex)
    m_wndListCtrl.SetItemText(iItem, 0, szBuffer);
 
    // Event
-   m_wndListCtrl.SetItemText(iItem, 1, NXCGetEventName(m_pItem->pThresholdList[dwIndex].dwEvent));
+   m_wndListCtrl.SetItemText(iItem, 1, 
+      NXCGetEventName(g_hSession, m_pItem->pThresholdList[dwIndex].dwEvent));
 }
 
 
index 9b2c29d..f86f18f 100644 (file)
@@ -140,9 +140,10 @@ void CDataCollectionEditor::OnClose()
 {
    DWORD dwResult;
 
-   dwResult = DoRequestArg1(NXCCloseNodeDCIList, m_pItemList, "Unlocking node's data collection information...");
+   dwResult = DoRequestArg2(NXCCloseNodeDCIList, g_hSession, m_pItemList,
+                            _T("Unlocking node's data collection information..."));
    if (dwResult != RCC_SUCCESS)
-      theApp.ErrorBox(dwResult, "Unable to close data collection configuration:\n%s");
+      theApp.ErrorBox(dwResult, _T("Unable to close data collection configuration:\n%s"));
        
        CMDIChildWnd::OnClose();
 }
@@ -232,16 +233,16 @@ void CDataCollectionEditor::OnItemNew()
 
    if (EditItem(&item))
    {
-      dwResult = DoRequestArg2(NXCCreateNewDCI, m_pItemList, &dwItemId, 
-                               "Creating new data collection item...");
+      dwResult = DoRequestArg3(NXCCreateNewDCI, g_hSession, m_pItemList, &dwItemId, 
+                               _T("Creating new data collection item..."));
       if (dwResult == RCC_SUCCESS)
       {
          dwIndex = NXCItemIndex(m_pItemList, dwItemId);
          item.dwId = dwItemId;
          if (dwIndex != INVALID_INDEX)
          {
-            dwResult = DoRequestArg2(NXCUpdateDCI, (void *)m_pItemList->dwNodeId, &item,
-                                     "Updating data collection item...");
+            dwResult = DoRequestArg3(NXCUpdateDCI, g_hSession, (void *)m_pItemList->dwNodeId,
+                                     &item, _T("Updating data collection item..."));
             if (dwResult == RCC_SUCCESS)
             {
                memcpy(&m_pItemList->pItems[dwIndex], &item, sizeof(NXC_DCI));
@@ -250,13 +251,13 @@ void CDataCollectionEditor::OnItemNew()
             }
             else
             {
-               theApp.ErrorBox(dwResult, "Unable to update data collection item: %s");
+               theApp.ErrorBox(dwResult, _T("Unable to update data collection item: %s"));
             }
          }
       }
       else
       {
-         theApp.ErrorBox(dwResult, "Unable to create new data collection item: %s");
+         theApp.ErrorBox(dwResult, _T("Unable to create new data collection item: %s"));
       }
    }
 }
@@ -285,8 +286,8 @@ void CDataCollectionEditor::OnItemEdit()
                            sizeof(NXC_DCI_THRESHOLD) * item.dwNumThresholds);
          if (EditItem(&item))
          {
-            dwResult = DoRequestArg2(NXCUpdateDCI, (void *)m_pItemList->dwNodeId, &item,
-                                     "Updating data collection item...");
+            dwResult = DoRequestArg3(NXCUpdateDCI, g_hSession, (void *)m_pItemList->dwNodeId,
+                                     &item, _T("Updating data collection item..."));
             if (dwResult == RCC_SUCCESS)
             {
                free(m_pItemList->pItems[dwIndex].pThresholdList);
@@ -328,7 +329,7 @@ BOOL CDataCollectionEditor::EditItem(NXC_DCI *pItem)
    pgCollection.m_iStatus = pItem->iStatus;
    pgCollection.m_strName = pItem->szName;
    pgCollection.m_strDescription = pItem->szDescription;
-   pgCollection.m_pNode = NXCFindObjectById(m_pItemList->dwNodeId);
+   pgCollection.m_pNode = NXCFindObjectById(g_hSession, m_pItemList->dwNodeId);
 
    // Setup "Transformation" page
    pgTransform.m_iDeltaProc = pItem->iDeltaCalculation;
@@ -426,7 +427,7 @@ void CDataCollectionEditor::OnUpdateFileExport(CCmdUI* pCmdUI)
 {
    NXC_OBJECT *pObject;
 
-   pObject = NXCFindObjectById(m_pItemList->dwNodeId);
+   pObject = NXCFindObjectById(g_hSession, m_pItemList->dwNodeId);
    if (pObject != NULL)
       pCmdUI->Enable(pObject->iClass == OBJECT_TEMPLATE);
    else
@@ -476,11 +477,11 @@ void CDataCollectionEditor::OnItemDelete()
    while(iItem != -1)
    {
       dwItemId = m_wndListCtrl.GetItemData(iItem);
-      dwResult = DoRequestArg2(NXCDeleteDCI, m_pItemList, (void *)dwItemId,
-                               "Deleting data collection item...");
+      dwResult = DoRequestArg3(NXCDeleteDCI, g_hSession, m_pItemList, (void *)dwItemId,
+                               _T("Deleting data collection item..."));
       if (dwResult != RCC_SUCCESS)
       {
-         theApp.ErrorBox(dwResult, "Unable to delete data collection item: %s");
+         theApp.ErrorBox(dwResult, _T("Unable to delete data collection item: %s"));
          break;
       }
       m_wndListCtrl.DeleteItem(iItem);
@@ -515,7 +516,7 @@ void CDataCollectionEditor::OnItemShowdata()
    {
       dwItemId = m_wndListCtrl.GetItemData(iItem);
       dwIndex = NXCItemIndex(m_pItemList, dwItemId);
-      pObject = NXCFindObjectById(m_pItemList->dwNodeId);
+      pObject = NXCFindObjectById(g_hSession, m_pItemList->dwNodeId);
       sprintf(szBuffer, "%s - %s", pObject->szName, 
               m_pItemList->pItems[dwIndex].szDescription);
       theApp.ShowDCIData(m_pItemList->dwNodeId, dwItemId, szBuffer);
@@ -540,7 +541,7 @@ void CDataCollectionEditor::OnItemGraph()
    {
       dwItemId = m_wndListCtrl.GetItemData(iItem);
       dwIndex = NXCItemIndex(m_pItemList, dwItemId);
-      pObject = NXCFindObjectById(m_pItemList->dwNodeId);
+      pObject = NXCFindObjectById(g_hSession, m_pItemList->dwNodeId);
       sprintf(szBuffer, "%s - %s", pObject->szName, 
               m_pItemList->pItems[dwIndex].szDescription);
       theApp.ShowDCIGraph(m_pItemList->dwNodeId, dwItemId, szBuffer);
@@ -572,7 +573,7 @@ static DWORD __cdecl CopyItems(DWORD dwSourceNode, DWORD dwNumObjects, DWORD *pd
 
    for(i = 0; i < dwNumObjects; i++)
    {
-      dwResult = NXCCopyDCI(dwSourceNode, pdwObjectList[i], dwNumItems, pdwItemList);
+      dwResult = NXCCopyDCI(g_hSession, dwSourceNode, pdwObjectList[i], dwNumItems, pdwItemList);
       if (dwResult != RCC_SUCCESS)
          break;
    }
@@ -646,9 +647,9 @@ void CDataCollectionEditor::OnItemDuplicate()
       }
 
       // Perform request(s) to server
-      dwResult = DoRequestArg4(NXCCopyDCI, (void *)m_pItemList->dwNodeId, 
-               (void *)m_pItemList->dwNodeId, (void *)dwNumItems, 
-               pdwItemList, "Copying items...");
+      dwResult = DoRequestArg5(NXCCopyDCI, g_hSession, (void *)m_pItemList->dwNodeId, 
+                               (void *)m_pItemList->dwNodeId, (void *)dwNumItems, 
+                               pdwItemList, _T("Copying items..."));
       if (dwResult != RCC_SUCCESS)
          theApp.ErrorBox(dwResult, "Error copying items: %s");
       PostMessage(WM_COMMAND, ID_VIEW_REFRESH, 0);
@@ -688,11 +689,12 @@ void CDataCollectionEditor::OnViewRefresh()
    dwObjectId = m_pItemList->dwNodeId;
 
    // Re-open node's DCI list
-   dwResult = DoRequestArg1(NXCCloseNodeDCIList, m_pItemList, "Unlocking node's data collection information...");
+   dwResult = DoRequestArg2(NXCCloseNodeDCIList, g_hSession, m_pItemList,
+                            _T("Unlocking node's data collection information..."));
    if (dwResult != RCC_SUCCESS)
       theApp.ErrorBox(dwResult, "Unable to close data collection configuration:\n%s");
 
-   dwResult = DoRequestArg2(NXCOpenNodeDCIList, (void *)dwObjectId, 
+   dwResult = DoRequestArg3(NXCOpenNodeDCIList, g_hSession, (void *)dwObjectId, 
                             &m_pItemList, "Loading node's data collection information...");
    if (dwResult != RCC_SUCCESS)
       theApp.ErrorBox(dwResult, "Unable to load data collection information for node:\n%s");
@@ -748,7 +750,7 @@ void CDataCollectionEditor::ChangeItemsStatus(int iStatus)
       }
 
       // Send request to server
-      dwResult = DoRequestArg4(NXCSetDCIStatus, (void *)m_pItemList->dwNodeId,
+      dwResult = DoRequestArg5(NXCSetDCIStatus, g_hSession, (void *)m_pItemList->dwNodeId,
                                (void *)dwNumItems, pdwItemList, (void *)iStatus,
                                _T("Updating DCI status..."));
       if (dwResult == RCC_SUCCESS)
index cbaa1da..9aed463 100644 (file)
@@ -69,9 +69,9 @@ void CDataQueryDlg::OnButtonRestart()
    DWORD dwResult;
    TCHAR szBuffer[1024];
 
-   dwResult = DoRequestArg5(NXCQueryParameter, (void *)m_dwObjectId, (void *)m_iOrigin,
-                            (void *)((LPCTSTR)m_strParameter), szBuffer, 
-                            (void *)1024, _T("Querying agent..."));
+   dwResult = DoRequestArg6(NXCQueryParameter, g_hSession, (void *)m_dwObjectId,
+                            (void *)m_iOrigin, (void *)((LPCTSTR)m_strParameter),
+                            szBuffer, (void *)1024, _T("Querying agent..."));
    if (dwResult == RCC_SUCCESS)
    {
       m_wndEditValue.SetWindowText(szBuffer);
index e62bf57..5b93c21 100644 (file)
@@ -139,7 +139,7 @@ void CEventBrowser::AddEvent(NXC_EVENT *pEvent)
       NXC_OBJECT *pObject;
 
       m_wndListCtrl.SetItemText(iIdx, 1, g_szStatusTextSmall[pEvent->dwSeverity]);
-      pObject = NXCFindObjectById(pEvent->dwSourceId);
+      pObject = NXCFindObjectById(g_hSession, pEvent->dwSourceId);
       m_wndListCtrl.SetItemText(iIdx, 2, pObject ? pObject->szName : "<unknown>");
       m_wndListCtrl.SetItemText(iIdx, 3, pEvent->szMessage);
 
@@ -166,6 +166,6 @@ void CEventBrowser::EnableDisplay(BOOL bEnable)
 void CEventBrowser::OnViewRefresh() 
 {
    EnableDisplay(FALSE);
-   DoRequest(NXCSyncEvents, "Loading events...");
+   DoRequestArg1(NXCSyncEvents, g_hSession, "Loading events...");
    EnableDisplay(TRUE);
 }
index 56b6b8d..f58b073 100644 (file)
@@ -80,7 +80,7 @@ int CEventEditor::OnCreate(LPCREATESTRUCT lpCreateStruct)
    m_wndListCtrl.SetImageList(m_pImageList, LVSIL_SMALL);
 
    // Load event templates
-   NXCGetEventDB(&m_ppEventTemplates, &m_dwNumTemplates);
+   NXCGetEventDB(g_hSession, &m_ppEventTemplates, &m_dwNumTemplates);
    for(i = 0; i < m_dwNumTemplates; i++)
    {
       _stprintf(szBuffer, _T("%ld"), m_ppEventTemplates[i]->dwCode);
@@ -180,7 +180,8 @@ BOOL CEventEditor::EditEvent(int iItem)
          evt.pszMessage = _tcsdup((LPCTSTR)dlgEditEvent.m_strMessage);
          _tcsncpy(evt.szName, (LPCTSTR)dlgEditEvent.m_strName, MAX_EVENT_NAME);
 
-         dwResult = DoRequestArg1(NXCSetEventInfo, &evt, _T("Updating event configuration database..."));
+         dwResult = DoRequestArg2(NXCSetEventInfo, g_hSession, 
+                                  &evt, _T("Updating event configuration database..."));
          if (dwResult == RCC_SUCCESS)
          {
             // Record was successfully updated on server, update local copy
@@ -221,7 +222,7 @@ void CEventEditor::OnClose()
 {
    DWORD dwResult;
 
-   dwResult = DoRequest(NXCUnlockEventDB, _T("Unlocking event configuration database..."));
+   dwResult = DoRequestArg1(NXCUnlockEventDB, g_hSession, _T("Unlocking event configuration database..."));
    if (dwResult != RCC_SUCCESS)
       theApp.ErrorBox(dwResult, _T("Unable to unlock event configuration database: %s"));
        CMDIChildWnd::OnClose();
@@ -297,7 +298,8 @@ void CEventEditor::OnEventNew()
    TCHAR szBuffer[32];
    int iItem;
 
-   dwResult = DoRequestArg1(NXCGenerateEventCode, &dwNewCode, _T("Generating code for new event..."));
+   dwResult = DoRequestArg2(NXCGenerateEventCode, g_hSession, &dwNewCode,
+                            _T("Generating code for new event..."));
    if (dwResult == RCC_SUCCESS)
    {
       // Create new item in list view
@@ -309,17 +311,17 @@ void CEventEditor::OnEventNew()
       pData = (NXC_EVENT_TEMPLATE *)malloc(sizeof(NXC_EVENT_TEMPLATE));
       memset(pData, 0, sizeof(NXC_EVENT_TEMPLATE));
       pData->dwCode = dwNewCode;
-      NXCAddEventTemplate(pData);
+      NXCAddEventTemplate(g_hSession, pData);
 
       // Pointers inside client library can change after adding new template, so we reget it
-      NXCGetEventDB(&m_ppEventTemplates, &m_dwNumTemplates);
+      NXCGetEventDB(g_hSession, &m_ppEventTemplates, &m_dwNumTemplates);
 
       // Edit new event
       if (!EditEvent(iItem))
       {
          m_wndListCtrl.DeleteItem(iItem);
-         NXCDeleteEDBRecord(dwNewCode);
-         NXCGetEventDB(&m_ppEventTemplates, &m_dwNumTemplates);
+         NXCDeleteEDBRecord(g_hSession, dwNewCode);
+         NXCGetEventDB(g_hSession, &m_ppEventTemplates, &m_dwNumTemplates);
       }
    }
    else
index 4e05f97..7ecf839 100644 (file)
@@ -189,10 +189,11 @@ void CEventPolicyEditor::OnClose()
 
       if (iAnswer == IDYES)
       {
-         dwResult = DoRequestArg1(NXCSaveEventPolicy, m_pEventPolicy, "Saving event processing policy...");
+         dwResult = DoRequestArg2(NXCSaveEventPolicy, g_hSession, 
+                                  m_pEventPolicy, _T("Saving event processing policy..."));
          if (dwResult != RCC_SUCCESS)
          {
-            theApp.ErrorBox(dwResult, "Error saving event processing policy: %s");
+            theApp.ErrorBox(dwResult, _T("Error saving event processing policy: %s"));
             iAnswer = IDCANCEL;  // Will not close window if there are errors
          }
       }
@@ -200,7 +201,8 @@ void CEventPolicyEditor::OnClose()
 
    if (iAnswer != IDCANCEL)
    {
-          dwResult = DoRequest(NXCCloseEventPolicy, _T("Unlocking event processing policy..."));
+          dwResult = DoRequestArg1(NXCCloseEventPolicy, g_hSession, 
+                               _T("Unlocking event processing policy..."));
       if (dwResult != RCC_SUCCESS)
          theApp.ErrorBox(dwResult, _T("Error unlocking event processing policy: %s"));
           CMDIChildWnd::OnClose();
@@ -331,7 +333,7 @@ void CEventPolicyEditor::UpdateRow(int iRow)
 
       for(i = 0; i < m_pEventPolicy->pRuleList[iRow].dwNumSources; i++)
       {
-         pObject = NXCFindObjectById(m_pEventPolicy->pRuleList[iRow].pdwSourceList[i]);
+         pObject = NXCFindObjectById(g_hSession, m_pEventPolicy->pRuleList[iRow].pdwSourceList[i]);
          if (pObject != NULL)
             m_wndRuleList.AddItem(iRow, COL_SOURCE, pObject->szName, 
                                   GetObjectImageIndex(pObject));
@@ -348,8 +350,8 @@ void CEventPolicyEditor::UpdateRow(int iRow)
    {
       for(i = 0; i < m_pEventPolicy->pRuleList[iRow].dwNumEvents; i++)
          m_wndRuleList.AddItem(iRow, COL_EVENT, 
-                               (char *)NXCGetEventName(m_pEventPolicy->pRuleList[iRow].pdwEventList[i]),
-                               m_iImageSeverityBase + NXCGetEventSeverity(m_pEventPolicy->pRuleList[iRow].pdwEventList[i]));
+             (char *)NXCGetEventName(g_hSession, m_pEventPolicy->pRuleList[iRow].pdwEventList[i]),
+             m_iImageSeverityBase + NXCGetEventSeverity(g_hSession, m_pEventPolicy->pRuleList[iRow].pdwEventList[i]));
    }
 
    // Severity
@@ -942,7 +944,7 @@ void CEventPolicyEditor::OnPolicySave()
 {
    DWORD dwResult;
 
-   dwResult = DoRequestArg1(NXCSaveEventPolicy, m_pEventPolicy, "Saving event processing policy...");
+   dwResult = DoRequestArg2(NXCSaveEventPolicy, g_hSession, m_pEventPolicy, "Saving event processing policy...");
    if (dwResult != RCC_SUCCESS)
    {
       theApp.ErrorBox(dwResult, "Error saving event processing policy: %s");
index 639ab7c..83717ea 100644 (file)
@@ -90,7 +90,7 @@ BOOL CEventSelDlg::OnInitDialog()
    }
        
    // Fill in event list
-   NXCGetEventDB(&pList, &dwListSize);
+   NXCGetEventDB(g_hSession, &pList, &dwListSize);
    if (pList != NULL)
    {
       for(i = 0; i < dwListSize; i++)
@@ -158,7 +158,8 @@ static int CALLBACK CompareListItems(LPARAM lParam1, LPARAM lParam2, LPARAM lPar
 
    if ((lParamSort & 0xFFFF) == 0)
       return (lParam1 < lParam2) ? -iSortDir : ((lParam1 == lParam2) ? 0 : iSortDir);
-   return _tcsicmp(NXCGetEventName(lParam1), NXCGetEventName(lParam2)) * iSortDir;
+   return _tcsicmp(NXCGetEventName(g_hSession, lParam1), 
+                   NXCGetEventName(g_hSession, lParam2)) * iSortDir;
 }
 
 
index 5d20709..47220a0 100644 (file)
@@ -172,8 +172,9 @@ void CGraphFrame::OnViewRefresh()
 
    for(i = 0; i < m_dwNumItems; i++)
    {
-      dwResult = DoRequestArg6(NXCGetDCIData, (void *)m_pdwNodeId[i], (void *)m_pdwItemId[i],
-                               0, (void *)m_dwTimeFrom, (void *)m_dwTimeTo, &pData, "Loading item data...");
+      dwResult = DoRequestArg7(NXCGetDCIData, g_hSession, (void *)m_pdwNodeId[i], 
+                               (void *)m_pdwItemId[i], 0, (void *)m_dwTimeFrom,
+                               (void *)m_dwTimeTo, &pData, "Loading item data...");
       if (dwResult == RCC_SUCCESS)
       {
          m_wndGraph.SetData(i, pData);
index a8540c3..0b2f838 100644 (file)
@@ -119,7 +119,7 @@ BOOL CGroupPropDlg::OnInitDialog()
    // Fill in list control
    for(i = 0; i < m_dwNumMembers; i++)
    {
-      pUser = NXCFindUserById(m_pdwMembers[i]);
+      pUser = NXCFindUserById(g_hSession, m_pdwMembers[i]);
       if (pUser != NULL)
       {
          iItem = m_wndListCtrl.InsertItem(0x7FFFFFFF, pUser->szName,
@@ -171,7 +171,7 @@ void CGroupPropDlg::OnButtonAdd()
          m_pdwMembers[i] = wndSelectDlg.m_dwUserId;
 
          // Add new line to user list
-         pUser = NXCFindUserById(wndSelectDlg.m_dwUserId);
+         pUser = NXCFindUserById(g_hSession, wndSelectDlg.m_dwUserId);
          if (pUser != NULL)
          {
             iItem = m_wndListCtrl.InsertItem(0x7FFFFFFF, pUser->szName,
index d54b736..53f3ac6 100644 (file)
@@ -373,7 +373,7 @@ void CMIBBrowserDlg::OnButtonGet()
       dlg.m_dwAllowedClasses = SCL_NODE;
       if (dlg.DoModal() == IDOK)
       {
-         m_pNode = NXCFindObjectById(dlg.m_pdwObjectList[0]);
+         m_pNode = NXCFindObjectById(g_hSession, dlg.m_pdwObjectList[0]);
          if (m_pNode != NULL)
          {
             CString strTitle;
index 0c3e6bc..d6032ea 100644 (file)
@@ -182,7 +182,7 @@ void CMainFrame::OnUserDBChange(WPARAM wParam, LPARAM lParam)
 
 void CMainFrame::OnUpdateEventList(void) 
 {
-   DoRequest(NXCLoadEventDB, "Reloading event information...");
+   DoRequestArg1(NXCLoadEventDB, g_hSession, "Reloading event information...");
 }
 
 
index b6a9b12..c972cb3 100644 (file)
@@ -132,15 +132,15 @@ void CMapFrame::OnViewRefresh()
    m_wndMapView.DeleteAllItems();
    if (m_pRootObject == NULL)
    {
-      pObject = NXCGetTopologyRootObject();
+      pObject = NXCGetTopologyRootObject(g_hSession);
       if (pObject != NULL)
          AddObjectToView(pObject);
 
-      pObject = NXCGetServiceRootObject();
+      pObject = NXCGetServiceRootObject(g_hSession);
       if (pObject != NULL)
          AddObjectToView(pObject);
    
-      pObject = NXCGetTemplateRootObject();
+      pObject = NXCGetTemplateRootObject(g_hSession);
       if (pObject != NULL)
          AddObjectToView(pObject);
 
@@ -151,7 +151,7 @@ void CMapFrame::OnViewRefresh()
    {
       for(i = 0; i < m_pRootObject->dwNumChilds; i++)
       {
-         pObject = NXCFindObjectById(m_pRootObject->pdwChildList[i]);
+         pObject = NXCFindObjectById(g_hSession, m_pRootObject->pdwChildList[i]);
          if (pObject != NULL)
             if (!pObject->bIsDeleted)
                AddObjectToView(pObject);
@@ -232,7 +232,7 @@ void CMapFrame::OnObjectOpenparent()
       {
          if (m_pRootObject->dwNumParents > 0)
          {
-            m_pRootObject = NXCFindObjectById(m_pRootObject->pdwParentList[0]);
+            m_pRootObject = NXCFindObjectById(g_hSession, m_pRootObject->pdwParentList[0]);
          }
          else
          {
index d2bbc28..fe9b36c 100644 (file)
@@ -157,15 +157,15 @@ void CNodeSummary::UpdateStatus()
    
    memset(m_dwNodeStats, 0, sizeof(DWORD) * OBJECT_STATUS_COUNT);
    m_dwTotalNodes = 0;
-   NXCLockObjectIndex();
-   pIndex = (NXC_OBJECT_INDEX *)NXCGetObjectIndex(&dwNumObjects);
+   NXCLockObjectIndex(g_hSession);
+   pIndex = (NXC_OBJECT_INDEX *)NXCGetObjectIndex(g_hSession, &dwNumObjects);
    for(i = 0; i < dwNumObjects; i++)
       if (pIndex[i].pObject->iClass == OBJECT_NODE)
       {
          m_dwNodeStats[pIndex[i].pObject->iStatus]++;
          m_dwTotalNodes++;
       }
-   NXCUnlockObjectIndex();
+   NXCUnlockObjectIndex(g_hSession);
 }
 
 
index 1e838fe..b17d963 100644 (file)
@@ -354,15 +354,15 @@ void CObjectBrowser::OnViewRefresh()
    m_wndTreeCtrl.DeleteAllItems();
    m_dwTreeHashSize = 0;
 
-   pObject = NXCGetTopologyRootObject();
+   pObject = NXCGetTopologyRootObject(g_hSession);
    if (pObject != NULL)
       AddObjectToTree(pObject, TVI_ROOT);
 
-   pObject = NXCGetServiceRootObject();
+   pObject = NXCGetServiceRootObject(g_hSession);
    if (pObject != NULL)
       AddObjectToTree(pObject, TVI_ROOT);
    
-   pObject = NXCGetTemplateRootObject();
+   pObject = NXCGetTemplateRootObject(g_hSession);
    if (pObject != NULL)
       AddObjectToTree(pObject, TVI_ROOT);
    
@@ -370,12 +370,12 @@ void CObjectBrowser::OnViewRefresh()
 
    // Populate object's list
    m_wndListCtrl.DeleteAllItems();
-   NXCLockObjectIndex();
-   pIndex = (NXC_OBJECT_INDEX *)NXCGetObjectIndex(&dwNumObjects);
+   NXCLockObjectIndex(g_hSession);
+   pIndex = (NXC_OBJECT_INDEX *)NXCGetObjectIndex(g_hSession, &dwNumObjects);
    for(i = 0; i < dwNumObjects; i++)
       if (!pIndex[i].pObject->bIsDeleted)
          AddObjectToList(pIndex[i].pObject);
-   NXCUnlockObjectIndex();
+   NXCUnlockObjectIndex(g_hSession);
    m_wndListCtrl.SortItems(CompareListItems, m_dwSortMode);
 }
 
@@ -407,7 +407,7 @@ void CObjectBrowser::AddObjectToTree(NXC_OBJECT *pObject, HTREEITEM hParent)
    // Add object's childs
    for(i = 0; i < pObject->dwNumChilds; i++)
    {
-      NXC_OBJECT *pChildObject = NXCFindObjectById(pObject->pdwChildList[i]);
+      NXC_OBJECT *pChildObject = NXCFindObjectById(g_hSession, pObject->pdwChildList[i]);
       if (pChildObject != NULL)
          AddObjectToTree(pChildObject, hItem);
    }
@@ -480,7 +480,7 @@ void CObjectBrowser::OnTreeViewSelChange(LPNMTREEVIEW lpnmt, LRESULT *pResult)
 {
    if (m_dwFlags & VIEW_OBJECTS_AS_TREE)
    {
-      m_pCurrentObject = NXCFindObjectById(lpnmt->itemNew.lParam);
+      m_pCurrentObject = NXCFindObjectById(g_hSession, lpnmt->itemNew.lParam);
       m_wndPreviewPane.SetCurrentObject(m_pCurrentObject);
    }
    *pResult = 0;
@@ -799,7 +799,7 @@ void CObjectBrowser::OnObjectViewViewastree()
 
    // Display currenly selected item in preview pane
    hItem = m_wndTreeCtrl.GetSelectedItem();
-   m_pCurrentObject = (hItem == NULL) ? NULL : NXCFindObjectById(m_wndTreeCtrl.GetItemData(hItem));
+   m_pCurrentObject = (hItem == NULL) ? NULL : NXCFindObjectById(g_hSession, m_wndTreeCtrl.GetItemData(hItem));
    m_wndPreviewPane.SetCurrentObject(m_pCurrentObject);
 }
 
@@ -879,7 +879,7 @@ void CObjectBrowser::OnFindObject(WPARAM wParam, LPARAM lParam)
    {
       NXC_OBJECT *pObject;
 
-      pObject = NXCFindObjectByName((char *)lParam);
+      pObject = NXCFindObjectByName(g_hSession, (char *)lParam);
       if (pObject != NULL)
       {
          // Object found, select it in the current view
@@ -1340,7 +1340,7 @@ void CObjectBrowser::OnObjectBind()
    {
       for(i = 0; i < dlg.m_dwNumObjects; i++)
       {
-         dwResult = DoRequestArg2(NXCBindObject, (void *)m_pCurrentObject->dwId,
+         dwResult = DoRequestArg3(NXCBindObject, g_hSession, (void *)m_pCurrentObject->dwId,
                                   (void *)dlg.m_pdwObjectList[i], "Binding objects...");
          if (dwResult != RCC_SUCCESS)
          {
@@ -1603,7 +1603,7 @@ static void GetComparableObjectName(DWORD dwObjectId, TCHAR *pszName)
 {
    NXC_OBJECT *pObject;
 
-   pObject = NXCFindObjectById(dwObjectId);
+   pObject = NXCFindObjectById(g_hSession, dwObjectId);
    if (pObject != NULL)
    {
       // If object has an IP address as name, we sort as numbers
index 5e3e24e..4d4795d 100644 (file)
@@ -64,7 +64,7 @@ void CObjectPropSheet::SaveObjectChanges()
    {
       theApp.DebugPrintf("Saving changes for object %d (Flags: 0x%04X)", 
                          m_update.dwObjectId, m_update.dwFlags);
-      dwResult = DoRequestArg1(NXCModifyObject, &m_update, "Updating object...");
+      dwResult = DoRequestArg2(NXCModifyObject, g_hSession, &m_update, "Updating object...");
       if (dwResult != RCC_SUCCESS)
          theApp.ErrorBox(dwResult, "Error updating object: %s");
    }
index be5148f..a836755 100644 (file)
@@ -107,7 +107,7 @@ BOOL CObjectPropsSecurity::OnInitDialog()
    // Populate user list with current ACL data
    for(i = 0; i < m_dwAclSize; i++)
    {
-      pUser = NXCFindUserById(m_pAccessList[i].dwUserId);
+      pUser = NXCFindUserById(g_hSession, m_pAccessList[i].dwUserId);
       if (pUser != NULL)
       {
          iItem = m_wndUserList.InsertItem(0x7FFFFFFF, pUser->szName,
@@ -188,7 +188,7 @@ void CObjectPropsSecurity::OnAddUser()
          m_dwAclSize++;
 
          // Add new line to user list
-         pUser = NXCFindUserById(wndSelectDlg.m_dwUserId);
+         pUser = NXCFindUserById(g_hSession, wndSelectDlg.m_dwUserId);
          if (pUser != NULL)
          {
             iItem = m_wndUserList.InsertItem(0x7FFFFFFF, pUser->szName,
@@ -231,7 +231,7 @@ void CObjectPropsSecurity::OnItemchangedListUsers(NMHDR* pNMHDR, LRESULT* pResul
    if (pNMListView->iItem != -1)
       if ((pNMListView->uChanged & LVIF_STATE) && (pNMListView->uNewState & LVIS_FOCUSED))
       {
-         pUser = NXCFindUserById(m_wndUserList.GetItemData(pNMListView->iItem));
+         pUser = NXCFindUserById(g_hSession, m_wndUserList.GetItemData(pNMListView->iItem));
          if (pUser != NULL)   // It should't be NULL
          {
             // Find user in ACL
index 3207771..73ff9c0 100644 (file)
@@ -87,8 +87,8 @@ BOOL CObjectSelDlg::OnInitDialog()
    }
 
    // Fill in object list
-   NXCLockObjectIndex();
-   pIndex = (NXC_OBJECT_INDEX *)NXCGetObjectIndex(&dwNumObjects);
+   NXCLockObjectIndex(g_hSession);
+   pIndex = (NXC_OBJECT_INDEX *)NXCGetObjectIndex(g_hSession, &dwNumObjects);
    for(i = 0; i < dwNumObjects; i++)
       if (dwClassMask[pIndex[i].pObject->iClass] & m_dwAllowedClasses)
       {
@@ -97,7 +97,7 @@ BOOL CObjectSelDlg::OnInitDialog()
          m_wndListCtrl.SetItemText(iItem, 1, g_szObjectClass[pIndex[i].pObject->iClass]);
          m_wndListCtrl.SetItemData(iItem, pIndex[i].pObject->dwId);
       }
-   NXCUnlockObjectIndex();
+   NXCUnlockObjectIndex(g_hSession);
 
        return TRUE;
 }
index 659939b..b944cd8 100644 (file)
@@ -83,7 +83,7 @@ BOOL CThresholdDlg::OnInitDialog()
       m_wndEditArg1.EnableWindow(FALSE);
    }
 
-   m_wndEventName.SetWindowText(NXCGetEventName(m_dwEventId));
+   m_wndEventName.SetWindowText(NXCGetEventName(g_hSession, m_dwEventId));
        
        return TRUE;
 }
@@ -114,6 +114,6 @@ void CThresholdDlg::OnButtonSelect()
    if (dlg.DoModal() == IDOK)
    {
       m_dwEventId = dlg.m_pdwEventList[0];
-      m_wndEventName.SetWindowText(NXCGetEventName(m_dwEventId));
+      m_wndEventName.SetWindowText(NXCGetEventName(g_hSession, m_dwEventId));
    }
 }
index 376b4c3..36cbd06 100644 (file)
@@ -165,13 +165,13 @@ void CTrapEditDlg::UpdateEventInfo()
    static UINT nIconID[] = { IDI_SEVERITY_NORMAL, IDI_SEVERITY_WARNING, IDI_SEVERITY_MINOR,
                              IDI_SEVERITY_MAJOR, IDI_SEVERITY_CRITICAL };
 
-   NXCGetEventText(m_trap.dwEventCode, szBuffer, MAX_DB_STRING);
+   NXCGetEventText(g_hSession, m_trap.dwEventCode, szBuffer, MAX_DB_STRING);
    SetDlgItemText(IDC_EDIT_MESSAGE, szBuffer);
 
-   NXCGetEventNameEx(m_trap.dwEventCode, szBuffer, MAX_DB_STRING);
+   NXCGetEventNameEx(g_hSession, m_trap.dwEventCode, szBuffer, MAX_DB_STRING);
    SetDlgItemText(IDC_EDIT_EVENT, szBuffer);
 
-   iSeverity = NXCGetEventSeverity(m_trap.dwEventCode);
+   iSeverity = NXCGetEventSeverity(g_hSession, m_trap.dwEventCode);
    if (iSeverity != -1)
       m_wndEventIcon.SetIcon(theApp.LoadIcon(nIconID[iSeverity]));
    else
index cd63928..a53d1ee 100644 (file)
@@ -153,7 +153,7 @@ void CTrapEditor::OnSize(UINT nType, int cx, int cy)
 
 void CTrapEditor::OnClose() 
 {
-   DoRequest(NXCUnlockTrapCfg, "Unlocking SNMP trap configuration database...");
+   DoRequestArg1(NXCUnlockTrapCfg, g_hSession, "Unlocking SNMP trap configuration database...");
        CMDIChildWnd::OnClose();
 }
 
@@ -169,7 +169,8 @@ void CTrapEditor::OnViewRefresh()
    if (m_pTrapList != NULL)
       NXCDestroyTrapList(m_dwNumTraps, m_pTrapList);
    m_wndListCtrl.DeleteAllItems();
-   dwResult = DoRequestArg2(NXCLoadTrapCfg, &m_dwNumTraps, &m_pTrapList, _T("Loading SNMP trap configuration..."));
+   dwResult = DoRequestArg3(NXCLoadTrapCfg, g_hSession, &m_dwNumTraps, 
+                            &m_pTrapList, _T("Loading SNMP trap configuration..."));
    if (dwResult == RCC_SUCCESS)
    {
       for(i = 0; i < m_dwNumTraps; i++)
@@ -214,11 +215,11 @@ void CTrapEditor::UpdateItem(int iItem, DWORD dwIndex)
    SNMPConvertOIDToText(m_pTrapList[dwIndex].dwOidLen, m_pTrapList[dwIndex].pdwObjectId,
                         szBuffer, 1024);
    m_wndListCtrl.SetItemText(iItem, 1, szBuffer);
-   m_wndListCtrl.SetItemText(iItem, 2, NXCGetEventName(m_pTrapList[dwIndex].dwEventCode));
+   m_wndListCtrl.SetItemText(iItem, 2, NXCGetEventName(g_hSession, m_pTrapList[dwIndex].dwEventCode));
    m_wndListCtrl.SetItemText(iItem, 3, m_pTrapList[dwIndex].szDescription);
    
    m_wndListCtrl.SetItem(iItem, 0, LVIF_IMAGE, NULL, 
-                         NXCGetEventSeverity(m_pTrapList[dwIndex].dwEventCode),
+                         NXCGetEventSeverity(g_hSession, m_pTrapList[dwIndex].dwEventCode),
                          0, 0, 0);
 }
 
@@ -259,7 +260,7 @@ void CTrapEditor::OnTrapNew()
 {
    DWORD dwResult, dwTrapId;
 
-   dwResult = DoRequestArg1(NXCCreateTrap, &dwTrapId, _T("Creating trap configuration record..."));
+   dwResult = DoRequestArg2(NXCCreateTrap, g_hSession, &dwTrapId, _T("Creating trap configuration record..."));
    if (dwResult == RCC_SUCCESS)
    {
       m_pTrapList = (NXC_TRAP_CFG_ENTRY *)realloc(m_pTrapList, sizeof(NXC_TRAP_CFG_ENTRY) * (m_dwNumTraps + 1));
@@ -290,7 +291,7 @@ static DWORD DeleteTraps(DWORD dwNumTraps, DWORD *pdwDeleteList, CListCtrl *pLis
    lvfi.flags = LVFI_PARAM;
    for(i = 0; i < dwNumTraps; i++)
    {
-      dwResult = NXCDeleteTrap(pdwDeleteList[i]);
+      dwResult = NXCDeleteTrap(g_hSession, pdwDeleteList[i]);
       if (dwResult == RCC_SUCCESS)
       {
          lvfi.lParam = pdwDeleteList[i];
@@ -376,7 +377,8 @@ void CTrapEditor::OnTrapEdit()
             if (dlg.DoModal() == IDOK)
             {
                // Update record on server
-               dwResult = DoRequestArg1(NXCModifyTrap, &dlg.m_trap, _T("Updating trap configuration..."));
+               dwResult = DoRequestArg2(NXCModifyTrap, g_hSession,
+                                        &dlg.m_trap, _T("Updating trap configuration..."));
                if (dwResult == RCC_SUCCESS)
                {
                   // Clean existing configuration record
@@ -462,8 +464,8 @@ static int CALLBACK TrapCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lPara
             iResult = COMPARE_NUMBERS(pTrap1->dwOidLen, pTrap2->dwOidLen);
          break;
       case 2:     // Event
-         NXCGetEventNameEx(pTrap1->dwEventCode, szEvent1, MAX_EVENT_NAME);
-         NXCGetEventNameEx(pTrap2->dwEventCode, szEvent2, MAX_EVENT_NAME);
+         NXCGetEventNameEx(g_hSession, pTrap1->dwEventCode, szEvent1, MAX_EVENT_NAME);
+         NXCGetEventNameEx(g_hSession, pTrap2->dwEventCode, szEvent2, MAX_EVENT_NAME);
          iResult = _tcsicmp(szEvent1, szEvent2);
          break;
       case 3:     // Description
index ee5d296..d188e82 100644 (file)
@@ -69,7 +69,7 @@ BOOL CUserEditor::PreCreateWindow(CREATESTRUCT& cs)
 
 void CUserEditor::OnClose() 
 {
-   DoRequest(NXCUnlockUserDB, "Unlocking user database...");
+   DoRequestArg1(NXCUnlockUserDB, g_hSession, "Unlocking user database...");
        CMDIChildWnd::OnClose();
 }
 
@@ -178,7 +178,7 @@ void CUserEditor::OnViewRefresh()
    m_wndListCtrl.DeleteAllItems();
    
    // Fill in list view
-   if (NXCGetUserDB(&pUserList, &dwNumUsers))
+   if (NXCGetUserDB(g_hSession, &pUserList, &dwNumUsers))
    {
       for(i = 0; i < dwNumUsers; i++)
          if (!(pUserList[i].wFlags & UF_DELETED))
@@ -228,8 +228,8 @@ void CUserEditor::CreateUserObject(const char *pszName, BOOL bIsGroup, BOOL bSho
    DWORD dwResult, dwNewId;
 
    // Send request to server
-   dwResult = DoRequestArg3(NXCCreateUser, (void *)pszName, (void *)bIsGroup, &dwNewId,
-                            bIsGroup ? "Creating new group..." : "Creating new user...");
+   dwResult = DoRequestArg4(NXCCreateUser, g_hSession, (void *)pszName, (void *)bIsGroup, 
+                            &dwNewId, bIsGroup ? "Creating new group..." : "Creating new user...");
    if (dwResult == RCC_SUCCESS)
    {
       int iItem, iOldItem;
@@ -340,7 +340,7 @@ void CUserEditor::OnUserProperties()
       NXC_USER *pUser;
 
       dwId = m_wndListCtrl.GetItemData(iItem);
-      pUser = NXCFindUserById(dwId);
+      pUser = NXCFindUserById(g_hSession, dwId);
       if (pUser != NULL)
       {
          NXC_USER userInfo;
@@ -429,7 +429,7 @@ void CUserEditor::OnUserProperties()
          {
             DWORD dwResult;
 
-            dwResult = DoRequestArg1(NXCModifyUser, &userInfo, "Updating user database...");
+            dwResult = DoRequestArg2(NXCModifyUser, g_hSession, &userInfo, "Updating user database...");
             if (dwResult != RCC_SUCCESS)
                theApp.ErrorBox(dwResult, "Cannot modify user record: %s");
 
@@ -474,7 +474,7 @@ void CUserEditor::OnUserDelete()
       {
          NXC_USER *pUser;
 
-         pUser = NXCFindUserById(dwId);
+         pUser = NXCFindUserById(g_hSession, dwId);
          if (pUser != NULL)
          {
             char szBuffer[256];
@@ -485,7 +485,7 @@ void CUserEditor::OnUserDelete()
             {
                DWORD dwResult;
 
-               dwResult = DoRequestArg1(NXCDeleteUser, (void *)dwId, "Deleting user...");
+               dwResult = DoRequestArg2(NXCDeleteUser, g_hSession, (void *)dwId, "Deleting user...");
                if (dwResult != RCC_SUCCESS)
                   theApp.ErrorBox(dwResult, "Cannot delete user record: %s");
             }
@@ -550,7 +550,7 @@ void CUserEditor::OnUserSetpassword()
 
       dwId = m_wndListCtrl.GetItemData(iItem);
 
-      pUser = NXCFindUserById(dwId);
+      pUser = NXCFindUserById(g_hSession, dwId);
       if (pUser != NULL)
       {
          CPasswordChangeDlg dlg;
@@ -559,7 +559,7 @@ void CUserEditor::OnUserSetpassword()
          {
             DWORD dwResult;
 
-            dwResult = DoRequestArg2(NXCSetPassword, (void *)dwId, dlg.m_szPassword, "Changing password...");
+            dwResult = DoRequestArg3(NXCSetPassword, g_hSession, (void *)dwId, dlg.m_szPassword, "Changing password...");
             if (dwResult != RCC_SUCCESS)
                theApp.ErrorBox(dwResult, "Cannot change password: %s");
             else
index cf3eac2..da35226 100644 (file)
@@ -75,7 +75,7 @@ BOOL CUserSelectDlg::OnInitDialog()
    m_wndListCtrl.SetImageList(pImageList, LVSIL_SMALL);
 
    // Fill in list view
-   if (NXCGetUserDB(&pUserList, &dwNumUsers))
+   if (NXCGetUserDB(g_hSession, &pUserList, &dwNumUsers))
    {
       for(i = 0; i < dwNumUsers; i++)
          if (!(pUserList[i].wFlags & UF_DELETED))
index 2d8f50c..a986c92 100644 (file)
@@ -69,13 +69,23 @@ static DWORD CheckMIBFile(char *pszName, BYTE *pHash)
    {
       strcpy(szFileName, g_szWorkDir);
       strcat(szFileName, WORKDIR_MIBCACHE);
-      dwResult = NXCDownloadMIBFile(pszName, szFileName);
+      dwResult = NXCDownloadMIBFile(g_hSession, pszName, szFileName);
    }
    return dwResult;
 }
 
 
 //
+// Wrapper for client library event handler
+//
+
+static void ClientEventHandler(NXC_SESSION hSession, DWORD dwEvent, DWORD dwCode, void *pArg)
+{
+   theApp.EventHandler(dwEvent, dwCode, pArg);
+}
+
+
+//
 // Login thread
 //
 
@@ -84,32 +94,34 @@ static DWORD WINAPI LoginThread(void *pArg)
    HWND hWnd = *((HWND *)pArg);    // Handle to status window
    DWORD dwResult;
 
-   dwResult = NXCConnect(g_szServer, g_szLogin, g_szPassword);
+   dwResult = NXCConnect(g_szServer, g_szLogin, g_szPassword, &g_hSession);
 
    // If successful, load container objects' categories
    if (dwResult == RCC_SUCCESS)
    {
+      NXCSetEventHandler(g_hSession, ClientEventHandler);
+
       SetInfoText(hWnd, "Loading container categories...");
-      dwResult = NXCLoadCCList(&g_pCCList);
+      dwResult = NXCLoadCCList(g_hSession, &g_pCCList);
    }
 
    // Synchronize objects
    if (dwResult == RCC_SUCCESS)
    {
       SetInfoText(hWnd, "Synchronizing objects...");
-      dwResult = NXCSyncObjects();
+      dwResult = NXCSyncObjects(g_hSession);
    }
 
    if (dwResult == RCC_SUCCESS)
    {
       SetInfoText(hWnd, "Loading user database...");
-      dwResult = NXCLoadUserDB();
+      dwResult = NXCLoadUserDB(g_hSession);
    }
 
    if (dwResult == RCC_SUCCESS)
    {
       SetInfoText(hWnd, "Loading action configuration...");
-      dwResult = NXCLoadActions(&g_dwNumActions, &g_pActionList);
+      dwResult = NXCLoadActions(g_hSession, &g_dwNumActions, &g_pActionList);
       if (dwResult == RCC_ACCESS_DENIED)
          dwResult = RCC_SUCCESS;    // User may not have rights to see actions, it's ok here
    }
@@ -120,7 +132,7 @@ static DWORD WINAPI LoginThread(void *pArg)
       DWORD i;
 
       SetInfoText(hWnd, "Loading and initializing MIB files...");
-      dwResult = NXCGetMIBList(&pMibList);
+      dwResult = NXCGetMIBList(g_hSession, &pMibList);
       if (dwResult == RCC_SUCCESS)
       {
          for(i = 0; i < pMibList->dwNumFiles; i++)
@@ -135,7 +147,7 @@ static DWORD WINAPI LoginThread(void *pArg)
    if (dwResult == RCC_SUCCESS)
    {
       SetInfoText(hWnd, "Loading event information...");
-      dwResult = NXCLoadEventDB();
+      dwResult = NXCLoadEventDB(g_hSession);
    }
 
    // Synchronize images
@@ -146,7 +158,7 @@ static DWORD WINAPI LoginThread(void *pArg)
       SetInfoText(hWnd, "Synchronizing images...");
       strcpy(szCacheDir, g_szWorkDir);
       strcat(szCacheDir, WORKDIR_IMAGECACHE);
-      dwResult = NXCSyncImages(&g_pSrvImageList, szCacheDir, IMAGE_FORMAT_ICO);
+      dwResult = NXCSyncImages(g_hSession, &g_pSrvImageList, szCacheDir, IMAGE_FORMAT_ICO);
       if (dwResult == RCC_SUCCESS)
          CreateObjectImageList();
    }
@@ -157,7 +169,7 @@ static DWORD WINAPI LoginThread(void *pArg)
       DWORD i, *pdwClassId, *pdwImageId;
 
       SetInfoText(hWnd, "Loading default image list...");
-      dwResult = NXCLoadDefaultImageList(&g_dwDefImgListSize, &pdwClassId, &pdwImageId);
+      dwResult = NXCLoadDefaultImageList(g_hSession, &g_dwDefImgListSize, &pdwClassId, &pdwImageId);
       if (dwResult == RCC_SUCCESS)
       {
          g_pDefImgList = (DEF_IMG *)realloc(g_pDefImgList, sizeof(DEF_IMG) * g_dwDefImgListSize);
@@ -174,7 +186,7 @@ static DWORD WINAPI LoginThread(void *pArg)
 
    // Disconnect if some of post-login operations was failed
    if (dwResult != RCC_SUCCESS)
-      NXCDisconnect();
+      NXCDisconnect(g_hSession);
 
    PostMessage(hWnd, WM_REQUEST_COMPLETED, 0, dwResult);
    return dwResult;
@@ -245,6 +257,11 @@ static DWORD WINAPI RequestThread(void *pArg)
          dwResult = pData->pFunc(pData->pArg1, pData->pArg2, pData->pArg3, 
                                  pData->pArg4, pData->pArg5, pData->pArg6);
          break;
+      case 7:
+         dwResult = pData->pFunc(pData->pArg1, pData->pArg2, pData->pArg3, 
+                                 pData->pArg4, pData->pArg5, pData->pArg6,
+                                 pData->pArg7);
+         break;
    }
    if (pData->hWnd != NULL)
       PostMessage(pData->hWnd, WM_REQUEST_COMPLETED, 0, dwResult);
@@ -423,6 +440,29 @@ DWORD DoRequestArg6(void *pFunc, void *pArg1, void *pArg2, void *pArg3, void *pA
 
 
 //
+// Perform request with 7 parameter
+//
+
+DWORD DoRequestArg7(void *pFunc, void *pArg1, void *pArg2, void *pArg3, void *pArg4, 
+                    void *pArg5, void *pArg6, void *pArg7, char *pszInfoText)
+{
+   RqData rqData;
+
+   rqData.hWnd = NULL;
+   rqData.dwNumParams = 7;
+   rqData.pArg1 = pArg1;
+   rqData.pArg2 = pArg2;
+   rqData.pArg3 = pArg3;
+   rqData.pArg4 = pArg4;
+   rqData.pArg5 = pArg5;
+   rqData.pArg6 = pArg6;
+   rqData.pArg7 = pArg7;
+   rqData.pFunc = (DWORD (*)(...))pFunc;
+   return ExecuteRequest(&rqData, pszInfoText);
+}
+
+
+//
 // Callback function for node poller
 //
 
@@ -442,9 +482,8 @@ DWORD WINAPI PollerThread(void *pArg)
    RqData *pData = (RqData *)pArg;
    DWORD dwResult;
 
-theApp.DebugPrintf("Starting poll...");
-   dwResult = NXCPollNode((DWORD)pData->pArg1, (int)pData->pArg2, PollerCallback, pArg);
-theApp.DebugPrintf("poll complete: %d", dwResult);
+   dwResult = NXCPollNode(g_hSession, (DWORD)pData->pArg1, (int)pData->pArg2, 
+                          PollerCallback, pArg);
    if (pData->hWnd != NULL)
       PostMessage(pData->hWnd, WM_REQUEST_COMPLETED, 0, dwResult);
    return dwResult;
index 9b5d94b..259a676 100644 (file)
 
 
 //
+// Session handle
+//
+
+NXC_SESSION g_hSession = NULL;
+
+
+//
 // Connection parameters
 //
 
index df93e6d..c3fb8d3 100644 (file)
@@ -105,6 +105,7 @@ struct RqData
    void *pArg4;
    void *pArg5;
    void *pArg6;
+   void *pArg7;
 };
 
 
@@ -145,6 +146,8 @@ DWORD DoRequestArg5(void *pFunc, void *pArg1, void *pArg2, void *pArg3, void *pA
                     void *pArg5, char *pszInfoText);
 DWORD DoRequestArg6(void *pFunc, void *pArg1, void *pArg2, void *pArg3, void *pArg4, 
                     void *pArg5, void *pArg6, char *pszInfoText);
+DWORD DoRequestArg7(void *pFunc, void *pArg1, void *pArg2, void *pArg3, void *pArg4, 
+                    void *pArg5, void *pArg6, void *pArg7, char *pszInfoText);
 DWORD WINAPI PollerThread(void *pArg);
 
 
@@ -199,6 +202,7 @@ void UpdateActions(DWORD dwCode, NXC_ACTION *pAction);
 // Variables
 //
 
+extern NXC_SESSION g_hSession;
 extern DWORD g_dwOptions;
 extern char g_szServer[];
 extern char g_szLogin[];
index 28821e8..96d858c 100644 (file)
@@ -28,16 +28,6 @@ static char THIS_FILE[] = __FILE__;
 
 
 //
-// Wrapper for client library event handler
-//
-
-static void ClientEventHandler(DWORD dwEvent, DWORD dwCode, void *pArg)
-{
-   theApp.EventHandler(dwEvent, dwCode, pArg);
-}
-
-
-//
 // Wrapper for client library debug callback
 //
 
@@ -187,7 +177,6 @@ BOOL CConsoleApp::InitInstance()
                AfxMessageBox(IDS_NXC_INIT_FAILED, MB_OK | MB_ICONSTOP);
                return FALSE;
    }
-   NXCSetEventHandler(ClientEventHandler);
 
        AfxEnableControlContainer();
 
@@ -314,7 +303,7 @@ BOOL CConsoleApp::InitInstance()
           pFrame->ShowWindow(m_nCmdShow);
    }
        pFrame->UpdateWindow();
-   //pFrame->PostMessage(WM_COMMAND, ID_VIEW_DEBUG, 0);
+   pFrame->PostMessage(WM_COMMAND, ID_VIEW_DEBUG, 0);
    pFrame->PostMessage(WM_COMMAND, ID_CONNECT_TO_SERVER, 0);
 
        return TRUE;
@@ -326,7 +315,7 @@ BOOL CConsoleApp::InitInstance()
 int CConsoleApp::ExitInstance() 
 {
    NXCSetDebugCallback(NULL);
-   NXCDisconnect();
+   NXCDisconnect(g_hSession);
    NXCShutdown();
    NXCDestroyCCList(g_pCCList);
 
@@ -664,10 +653,6 @@ void CConsoleApp::EventHandler(DWORD dwEvent, DWORD dwCode, void *pArg)
 
    switch(dwEvent)
    {
-      case NXC_EVENT_STATE_CHANGED:
-         m_dwClientState = dwCode;
-         ((CMainFrame *)m_pMainWnd)->PostMessage(WM_STATE_CHANGE, dwCode, (LPARAM)pArg);
-         break;
       case NXC_EVENT_NEW_ELOG_RECORD:
          if (m_bEventBrowserActive)
             m_pwndEventBrowser->AddEvent((NXC_EVENT *)pArg);
@@ -725,7 +710,7 @@ void CConsoleApp::OnControlpanelEvents()
    {
       DWORD dwResult;
 
-      dwResult = DoRequest(NXCLockEventDB, "Locking event configuration database...");
+      dwResult = DoRequestArg1(NXCLockEventDB, g_hSession, "Locking event configuration database...");
       if (dwResult == RCC_SUCCESS)
       {
              pFrame->CreateNewChild(
@@ -754,7 +739,7 @@ void CConsoleApp::OnControlpanelUsers()
    {
       DWORD dwResult;
 
-      dwResult = DoRequest(NXCLockUserDB, "Locking user database...");
+      dwResult = DoRequestArg1(NXCLockUserDB, g_hSession, "Locking user database...");
       if (dwResult == RCC_SUCCESS)
       {
              pFrame->CreateNewChild(
@@ -820,7 +805,7 @@ void CConsoleApp::ObjectProperties(DWORD dwObjectId)
    NXC_OBJECT *pObject;
    char szBuffer[32];
 
-   pObject = NXCFindObjectById(dwObjectId);
+   pObject = NXCFindObjectById(g_hSession, dwObjectId);
    if (pObject != NULL)
    {
       // Create "General" tab
@@ -894,7 +879,7 @@ void CConsoleApp::StartObjectDCEditor(NXC_OBJECT *pObject)
    pWnd = (CDataCollectionEditor *)FindOpenDCEditor(pObject->dwId);
    if (pWnd == NULL)
    {
-      dwResult = DoRequestArg2(NXCOpenNodeDCIList, (void *)pObject->dwId, 
+      dwResult = DoRequestArg3(NXCOpenNodeDCIList, g_hSession, (void *)pObject->dwId, 
                                &pItemList, "Loading node's data collection information...");
       if (dwResult == RCC_SUCCESS)
       {
@@ -965,7 +950,7 @@ void CConsoleApp::SetObjectMgmtStatus(NXC_OBJECT *pObject, BOOL bIsManaged)
 {
    DWORD dwResult;
 
-   dwResult = DoRequestArg2(NXCSetObjectMgmtStatus, (void *)pObject->dwId, 
+   dwResult = DoRequestArg3(NXCSetObjectMgmtStatus, g_hSession, (void *)pObject->dwId, 
                             (void *)bIsManaged, "Changing object status...");
    if (dwResult != RCC_SUCCESS)
    {
@@ -1117,7 +1102,7 @@ void CConsoleApp::OnControlpanelEventpolicy()
    {
       DWORD dwResult;
 
-      dwResult = DoRequestArg1(NXCOpenEventPolicy, &m_pEventPolicy, "Loading event processing policy...");
+      dwResult = DoRequestArg2(NXCOpenEventPolicy, g_hSession, &m_pEventPolicy, "Loading event processing policy...");
       if (dwResult == RCC_SUCCESS)
       {
              pFrame->CreateNewChild(
@@ -1194,7 +1179,7 @@ void CConsoleApp::OnControlpanelActions()
    {
       DWORD dwResult;
 
-      dwResult = DoRequest(NXCLockActionDB, "Locking action configuration database...");
+      dwResult = DoRequestArg1(NXCLockActionDB, g_hSession, "Locking action configuration database...");
       if (dwResult == RCC_SUCCESS)
       {
              pFrame->CreateNewChild(
@@ -1225,7 +1210,7 @@ void CConsoleApp::OnControlpanelSnmptraps()
    {
       DWORD dwResult;
 
-      dwResult = DoRequest(NXCLockTrapCfg, "Locking SNMP trap configuration database...");
+      dwResult = DoRequestArg1(NXCLockTrapCfg, g_hSession, "Locking SNMP trap configuration database...");
       if (dwResult == RCC_SUCCESS)
       {
              pFrame->CreateNewChild(
@@ -1267,7 +1252,7 @@ void CConsoleApp::CreateObject(NXC_OBJECT_CREATE_INFO *pInfo)
 {
    DWORD dwResult, dwObjectId;
 
-   dwResult = DoRequestArg2(NXCCreateObject, pInfo, &dwObjectId, "Creating object...");
+   dwResult = DoRequestArg3(NXCCreateObject, g_hSession, pInfo, &dwObjectId, "Creating object...");
    if (dwResult != RCC_SUCCESS)
    {
       ErrorBox(dwResult, "Error creating object: %s");
@@ -1284,7 +1269,7 @@ void CConsoleApp::CreateContainer(DWORD dwParent)
    NXC_OBJECT_CREATE_INFO ci;
    CCreateContainerDlg dlg;
 
-   dlg.m_pParentObject = NXCFindObjectById(dwParent);
+   dlg.m_pParentObject = NXCFindObjectById(g_hSession, dwParent);
    if (dlg.m_pParentObject != NULL)
       if ((dlg.m_pParentObject->iClass != OBJECT_CONTAINER) &&
           (dlg.m_pParentObject->iClass != OBJECT_SERVICEROOT))
@@ -1310,7 +1295,7 @@ void CConsoleApp::CreateNode(DWORD dwParent)
    NXC_OBJECT_CREATE_INFO ci;
    CCreateNodeDlg dlg;
 
-   dlg.m_pParentObject = NXCFindObjectById(dwParent);
+   dlg.m_pParentObject = NXCFindObjectById(g_hSession, dwParent);
    if (dlg.m_pParentObject != NULL)
       if ((dlg.m_pParentObject->iClass != OBJECT_CONTAINER) &&
           (dlg.m_pParentObject->iClass != OBJECT_SERVICEROOT))
@@ -1336,7 +1321,7 @@ void CConsoleApp::CreateTemplate(DWORD dwParent)
    NXC_OBJECT_CREATE_INFO ci;
    CCreateTemplateDlg dlg;
 
-   dlg.m_pParentObject = NXCFindObjectById(dwParent);
+   dlg.m_pParentObject = NXCFindObjectById(g_hSession, dwParent);
    if (dlg.m_pParentObject != NULL)
       if ((dlg.m_pParentObject->iClass != OBJECT_TEMPLATEGROUP) &&
           (dlg.m_pParentObject->iClass != OBJECT_TEMPLATEROOT))
@@ -1360,7 +1345,7 @@ void CConsoleApp::CreateTemplateGroup(DWORD dwParent)
    NXC_OBJECT_CREATE_INFO ci;
    CCreateTGDlg dlg;
 
-   dlg.m_pParentObject = NXCFindObjectById(dwParent);
+   dlg.m_pParentObject = NXCFindObjectById(g_hSession, dwParent);
    if (dlg.m_pParentObject != NULL)
       if ((dlg.m_pParentObject->iClass != OBJECT_TEMPLATEGROUP) &&
           (dlg.m_pParentObject->iClass != OBJECT_TEMPLATEROOT))
@@ -1384,7 +1369,7 @@ void CConsoleApp::DeleteNetXMSObject(NXC_OBJECT *pObject)
 {
    DWORD dwResult;
 
-   dwResult = DoRequestArg1(NXCDeleteObject, (void *)pObject->dwId, "Deleting object...");
+   dwResult = DoRequestArg2(NXCDeleteObject, g_hSession, (void *)pObject->dwId, "Deleting object...");
    if (dwResult != RCC_SUCCESS)
       ErrorBox(dwResult, "Unable to delete object: %s");
 }
@@ -1428,7 +1413,7 @@ void CConsoleApp::WakeUpNode(DWORD dwObjectId)
 {
    DWORD dwResult;
 
-   dwResult = DoRequestArg1(NXCWakeUpNode, (void *)dwObjectId, _T("Sending Wake-On-LAN magic packet to node..."));
+   dwResult = DoRequestArg2(NXCWakeUpNode, g_hSession, (void *)dwObjectId, _T("Sending Wake-On-LAN magic packet to node..."));
    if (dwResult != RCC_SUCCESS)
       ErrorBox(dwResult, _T("Unable to send WOL magic packet: %s"));
    else
index 7d01ba6..3bc85d0 100644 (file)
@@ -65,6 +65,19 @@ double LIBNETXMS_EXPORTABLE __bswap_double(double dVal)
 
 
 //
+// Swap bytes in wide string
+//
+
+void LIBNETXMS_EXPORTABLE __bswap_wstr(WCHAR *pStr)
+{
+   WCHAR *pch;
+
+   for(pch = pStr; *pch != 0; pch++)
+      *pch = htons(*pch);
+}
+
+
+//
 // strupr() implementation for non-windows platforms
 //
 
index cc64a44..37911ba 100644 (file)
@@ -95,7 +95,7 @@ DWORD LIBNETXMS_EXPORTABLE inet_addr_w(WCHAR *pszAddr)
 {
    char szBuffer[256];
 
-   WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK | WC_DEFAULTCHAR, 
+   WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK | WC_DEFAULTCHAR,
                        pszAddr, -1, szBuffer, 256, NULL, NULL);
    return inet_addr(szBuffer);
 }
index a93fae4..5849912 100644 (file)
@@ -45,7 +45,7 @@ NXC_EVENT_TEMPLATE *DuplicateEventTemplate(NXC_EVENT_TEMPLATE *pSrc)
 
 void LIBNXCL_EXPORTABLE NXCAddEventTemplate(NXC_SESSION hSession, NXC_EVENT_TEMPLATE *pEventTemplate)
 {
-   ((NXCL_Session *)hSession)->AddEventTemplate(pEventTemplate);
+   ((NXCL_Session *)hSession)->AddEventTemplate(pEventTemplate, TRUE);
 }
 
 
@@ -81,7 +81,7 @@ void ProcessEventDBRecord(NXCL_Session *pSession, CSCPMessage *pMsg)
          pMsg->GetVariableStr(VID_NAME, pEventTemplate->szName, MAX_EVENT_NAME);
          pEventTemplate->pszMessage = pMsg->GetVariableStr(VID_MESSAGE, NULL, 0);
          pEventTemplate->pszDescription = pMsg->GetVariableStr(VID_DESCRIPTION, NULL, 0);
-         pSession->AddEventTemplate(pEventTemplate);
+         pSession->AddEventTemplate(pEventTemplate, FALSE);
       }
       else
       {
index dd44047..cd2d11e 100644 (file)
@@ -32,6 +32,9 @@ void ProcessEvent(NXCL_Session *pSession, CSCPMessage *pMsg, CSCP_MESSAGE *pRawM
 {
    NXC_EVENT *pEvent;
    WORD wCode;
+#ifdef UNICODE
+   WCHAR *pSrc, *pDst;
+#endif
 
    wCode = (pMsg != NULL) ? pMsg->GetCode() : pRawMsg->wCode;
 
@@ -45,12 +48,29 @@ void ProcessEvent(NXCL_Session *pSession, CSCPMessage *pMsg, CSCP_MESSAGE *pRawM
          {
             // Allocate new event structure and fill it with values from message
             pEvent = (NXC_EVENT *)malloc(sizeof(NXC_EVENT));
-            memcpy(pEvent, pRawMsg->df, sizeof(NXC_EVENT));
-            pEvent->dwEventCode = ntohl(pEvent->dwEventCode);
-            pEvent->qwEventId = ntohq(pEvent->qwEventId);
-            pEvent->dwSeverity = ntohl(pEvent->dwSeverity);
-            pEvent->dwSourceId = ntohl(pEvent->dwSourceId);
-            pEvent->dwTimeStamp = ntohl(pEvent->dwTimeStamp);
+            pEvent->dwEventCode = ntohl(((NXC_EVENT *)pRawMsg->df)->dwEventCode);
+            pEvent->qwEventId = ntohq(((NXC_EVENT *)pRawMsg->df)->qwEventId);
+            pEvent->dwSeverity = ntohl(((NXC_EVENT *)pRawMsg->df)->dwSeverity);
+            pEvent->dwSourceId = ntohl(((NXC_EVENT *)pRawMsg->df)->dwSourceId);
+            pEvent->dwTimeStamp = ntohl(((NXC_EVENT *)pRawMsg->df)->dwTimeStamp);
+
+            // Convert bytes in message characters to host byte order
+            // and than to single-byte if we building non-unicode library
+#ifdef UNICODE
+#if WORDS_BIGENDIAN
+            memcpy(pEvent->szMessage, ((NXC_EVENT *)pRawMsg->df)->szMessage,
+                   MAX_EVENT_MSG_LENGTH * sizeof(WCHAR));
+#else
+            for(pSrc = ((NXC_EVENT *)pRawMsg->df)->szMessage, 
+                pDst = pEvent->szMessage; *pSrc != 0; pSrc++, pDst++)
+               *pDst = ntohs(*pSrc);
+#endif
+#else
+            SwapWideString((WCHAR *)((NXC_EVENT *)pRawMsg->df)->szMessage);
+            WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK | WC_DEFAULTCHAR,
+                                (WCHAR *)((NXC_EVENT *)pRawMsg->df)->szMessage, -1,
+                                pEvent->szMessage, MAX_EVENT_MSG_LENGTH, NULL, NULL);
+#endif
 
             // Call client's callback to handle new record
             // It's up to client to destroy allocated event structure
index 3f3a2ef..3098afc 100644 (file)
@@ -199,6 +199,10 @@ SOURCE=..\..\include\nxcscpapi.h
 
 SOURCE=..\..\include\nxevent.h
 # End Source File
+# Begin Source File
+
+SOURCE=..\..\include\unicode.h
+# End Source File
 # End Group
 # Begin Group "Resource Files"
 
index 36daf93..20e6617 100644 (file)
@@ -139,7 +139,7 @@ public:
    DWORD OpenNodeDCIList(DWORD dwNodeId, NXC_DCI_LIST **ppItemList);
 
    DWORD LoadEventDB(void);
-   void AddEventTemplate(NXC_EVENT_TEMPLATE *pEventTemplate);
+   void AddEventTemplate(NXC_EVENT_TEMPLATE *pEventTemplate, BOOL bLock);
    void DeleteEDBRecord(DWORD dwEventCode);
    BOOL GetEventDB(NXC_EVENT_TEMPLATE ***pppTemplateList, DWORD *pdwNumRecords);
    const TCHAR *GetEventName(DWORD dwId);
index c586dfb..03c8f76 100644 (file)
@@ -31,6 +31,7 @@
 NXCL_Session::NXCL_Session()
 {
    m_dwFlags = 0;
+   m_dwMsgId = 0;
    m_pEventHandler = NULL;
    m_dwState = STATE_DISCONNECTED;
    m_dwCommandTimeout = 10000;    // Default timeout is 10 seconds
@@ -41,9 +42,9 @@ NXCL_Session::NXCL_Session()
    m_hSocket = -1;
    m_pItemList = NULL;
 
-   NXC_EVENT_TEMPLATE **m_ppEventTemplates = NULL;
-   DWORD m_dwNumTemplates = 0;
-   MUTEX m_mutexEventAccess = MutexCreate();
+   m_ppEventTemplates = NULL;
+   m_dwNumTemplates = 0;
+   m_mutexEventAccess = MutexCreate();
 
    m_dwNumUsers = 0;
    m_pUserList = NULL;
@@ -397,8 +398,7 @@ DWORD NXCL_Session::OpenNodeDCIList(DWORD dwNodeId, NXC_DCI_LIST **ppItemList)
 DWORD NXCL_Session::LoadEventDB(void)
 {
    CSCPMessage msg;
-   DWORD dwRetCode;
-   DWORD dwRqId;
+   DWORD dwRetCode, dwRqId;
 
    dwRqId = CreateRqId();
    PrepareForSync();
@@ -469,14 +469,16 @@ void NXCL_Session::DeleteEDBRecord(DWORD dwEventCode)
 // Add template to list
 //
 
-void NXCL_Session::AddEventTemplate(NXC_EVENT_TEMPLATE *pEventTemplate)
+void NXCL_Session::AddEventTemplate(NXC_EVENT_TEMPLATE *pEventTemplate, BOOL bLock)
 {
-   MutexLock(m_mutexEventAccess, INFINITE);
+   if (bLock)
+      MutexLock(m_mutexEventAccess, INFINITE);
    m_ppEventTemplates = (NXC_EVENT_TEMPLATE **)realloc(m_ppEventTemplates, 
       sizeof(NXC_EVENT_TEMPLATE *) * (m_dwNumTemplates + 1));
    m_ppEventTemplates[m_dwNumTemplates] = pEventTemplate;
    m_dwNumTemplates++;
-   MutexUnlock(m_mutexEventAccess);
+   if (bLock)
+      MutexUnlock(m_mutexEventAccess);
 }
 
 
index 70cf505..f5d1291 100644 (file)
@@ -55,6 +55,7 @@ static void DebugCallback(char *pMsg)
 static void SendEvent(int iNumArgs, TCHAR **pArgList)
 {
    DWORD dwResult;
+   NXC_SESSION hSession;
 
    if (!NXCInitialize())
    {
@@ -64,19 +65,19 @@ static void SendEvent(int iNumArgs, TCHAR **pArgList)
    {
       if (m_bDebug)
          NXCSetDebugCallback(DebugCallback);
-      NXCSetCommandTimeout(m_dwTimeOut * 1000);
 
-      dwResult = NXCConnect(m_szServer, m_szLogin, m_szPassword);
+      dwResult = NXCConnect(m_szServer, m_szLogin, m_szPassword, &hSession);
       if (dwResult != RCC_SUCCESS)
       {
          _tprintf(_T("Unable to connect to server: %s\n"), NXCGetErrorText(dwResult));
       }
       else
       {
-         dwResult = NXCSendEvent(m_dwEventCode, m_dwObjectId, iNumArgs, pArgList);
+         NXCSetCommandTimeout(hSession, m_dwTimeOut * 1000);
+         dwResult = NXCSendEvent(hSession, m_dwEventCode, m_dwObjectId, iNumArgs, pArgList);
          if (dwResult != RCC_SUCCESS)
             _tprintf(_T("Unable to send event: %s\n"), NXCGetErrorText(dwResult));
-         NXCDisconnect();
+         NXCDisconnect(hSession);
       }
    }
 }
index 4259d5d..2598417 100644 (file)
@@ -326,7 +326,14 @@ void Event::PrepareMessage(NXC_EVENT *pEventData)
    pEventData->dwEventCode = htonl(m_dwCode);
    pEventData->dwSeverity = htonl(m_dwSeverity);
    pEventData->dwSourceId = htonl(m_dwSource);
-   strcpy(pEventData->szMessage, CHECK_NULL(m_pszMessageText));
+
+#ifdef UNICODE
+   _tcsncpy(pEventData->szMessage, CHECK_NULL(m_pszMessageText), MAX_EVENT_MSG_LENGTH);
+#else
+   MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, CHECK_NULL(m_pszMessageText), -1, 
+                       (WCHAR *)pEventData->szMessage, MAX_EVENT_MSG_LENGTH);
+#endif
+   SwapWideString((WCHAR *)pEventData->szMessage);
 }
 
 
index 2bc93d7..677455c 100644 (file)
@@ -1063,6 +1063,9 @@ void ClientSession::SendAllEvents(DWORD dwRqId)
    CSCPMessage msg;
    DB_ASYNC_RESULT hResult;
    NXC_EVENT event;
+#ifndef UNICODE
+   char szBuffer[MAX_EVENT_MSG_LENGTH];
+#endif
 
    // Send confirmation message
    msg.SetCode(CMD_REQUEST_COMPLETED);
@@ -1087,8 +1090,16 @@ void ClientSession::SendAllEvents(DWORD dwRqId)
          event.dwTimeStamp = htonl(DBGetFieldAsyncULong(hResult, 2));
          event.dwSourceId = htonl(DBGetFieldAsyncULong(hResult, 3));
          event.dwSeverity = htonl(DBGetFieldAsyncULong(hResult, 4));
+#ifdef UNICODE
          DBGetFieldAsync(hResult, 5, event.szMessage, MAX_EVENT_MSG_LENGTH);
          DecodeSQLString(event.szMessage);
+#else
+         DBGetFieldAsync(hResult, 5, szBuffer, MAX_EVENT_MSG_LENGTH);
+         DecodeSQLString(szBuffer);
+         MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, szBuffer, -1, 
+                             (WCHAR *)event.szMessage, MAX_EVENT_MSG_LENGTH);
+#endif
+         SwapWideString((WCHAR *)event.szMessage);
          m_pSendQueue->Put(CreateRawCSCPMessage(CMD_EVENT, dwRqId, sizeof(NXC_EVENT), &event, NULL));
       }
       DBFreeAsyncResult(hResult);