]> git.sur5r.net Git - bacula/bacula/commitdiff
- remove stl from vss (vector replaced by alist, wstring replaced by wchar)
authorThorsten Engel <thorsten.engel@matrix-computer.com>
Fri, 28 Apr 2006 09:58:03 +0000 (09:58 +0000)
committerThorsten Engel <thorsten.engel@matrix-computer.com>
Fri, 28 Apr 2006 09:58:03 +0000 (09:58 +0000)
- take christophers code for waitforasync

git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@2981 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/win32/compat/vss.cpp
bacula/src/win32/compat/vss.h

index fc7a4fa8f8e20efbb43e364248439c63d815eff0..ca5c716ef9c8834eb2a7d90bc250772454f8a6da 100644 (file)
 
 
 #ifdef WIN32_VSS
-#include <stdio.h>
-#include <basetsd.h>
-#include <stdarg.h>
-#include <sys/types.h>
-#include <process.h>
-#include <direct.h>
-#include <winsock2.h>
-#include <windows.h>
-#include <wincon.h>
-#include <winbase.h>
-#include <stdlib.h>
-#include <conio.h>
-#include <process.h>
-#include <errno.h>
-#include <string.h>
-#include <time.h>
-#include <signal.h>
-#include <malloc.h>
-#include <setjmp.h>
-#include <direct.h>
-#include <ctype.h>
-#include <fcntl.h>
-#include <io.h>
-
-
-// STL includes
-#include <vector>
-#include <algorithm>
-#include <string>
-#include <fstream>
-using namespace std;   
-
-#ifdef HAVE_MINGW
-   
-//#include <atlcomcli.h>
-#include "ms_atl.h"
-#include <objbase.h>
+#include "compat.h"
+#include "bacula.h"
 
-#else 
-
-#include <atlcomcli.h>
+#include "ms_atl.h"
 #include <objbase.h>
 
-// Used for safe string manipulation
-#include <strsafe.h>
-#endif
-
 #include "vss.h"
 
 
@@ -85,8 +44,8 @@ VSSClient::VSSClient()
     m_bDuringRestore = false;
     m_bBackupIsInitialized = false;
     m_pVssObject = NULL;
-    m_pVectorWriterStates = new vector<int>;
-    m_pVectorWriterInfo = new vector<string>;
+    m_pAlistWriterState = New (alist(10, not_owned_by_alist));
+    m_pAlistWriterInfoText = New (alist(10, owned_by_alist));
     m_uidCurrentSnapshotSet = GUID_NULL;
     memset(m_wszUniqueVolumeName, 0, sizeof(m_wszUniqueVolumeName));
     memset(m_szShadowCopyName, 0, sizeof(m_szShadowCopyName));
@@ -102,11 +61,9 @@ VSSClient::~VSSClient()
       m_pVssObject = NULL;
    }
 
-   if (m_pVectorWriterStates)
-      delete (m_pVectorWriterStates);
-
-   if (m_pVectorWriterInfo)
-      delete (m_pVectorWriterInfo);
+   DestroyWriterInfo();
+   delete (alist*) m_pAlistWriterState;
+   delete (alist*) m_pAlistWriterInfoText;
 
    // Call CoUninitialize if the CoInitialize was performed successfully
    if (m_bCoInitializeCalled)
@@ -139,10 +96,12 @@ BOOL VSSClient::GetShadowPath(const char *szFilePath, char *szShadowPath, int nB
    if (bIsValidName) {
       int nDriveIndex = toupper(szFilePath[0])-'A';
       if (m_szShadowCopyName[nDriveIndex][0] != 0) {
-         strncpy(szShadowPath, m_szShadowCopyName[nDriveIndex], nBuflen);
-         nBuflen -= (int)strlen(m_szShadowCopyName[nDriveIndex]);
-         strncat(szShadowPath, szFilePath+2, nBuflen);
-         return TRUE;
+
+         if (WideCharToMultiByte(CP_UTF8,0,m_szShadowCopyName[nDriveIndex],-1,szShadowPath,nBuflen-1,NULL,NULL)) {
+            nBuflen -= (int)strlen(szShadowPath);
+            strncat(szShadowPath, szFilePath+2, nBuflen);
+            return TRUE;
+         }
       }
    }
    
@@ -168,8 +127,8 @@ BOOL VSSClient::GetShadowPathW(const WCHAR *szFilePath, WCHAR *szShadowPath, int
    if (bIsValidName) {
       int nDriveIndex = towupper(szFilePath[0])-'A';
       if (m_szShadowCopyName[nDriveIndex][0] != 0) {
-//       wcsncpy(szShadowPath, CA2W(m_szShadowCopyName[nDriveIndex]), nBuflen);
-         nBuflen -= (int)strlen(m_szShadowCopyName[nDriveIndex]);
+         wcsncpy(szShadowPath, m_szShadowCopyName[nDriveIndex], nBuflen);
+         nBuflen -= (int)wcslen(m_szShadowCopyName[nDriveIndex]);
          wcsncat(szShadowPath, szFilePath+2, nBuflen);
          return TRUE;
       }
@@ -183,20 +142,41 @@ BOOL VSSClient::GetShadowPathW(const WCHAR *szFilePath, WCHAR *szShadowPath, int
 
 const size_t VSSClient::GetWriterCount()
 {
-   vector<int>* pV = (vector<int>*) m_pVectorWriterStates;
+   alist* pV = (alist*) m_pAlistWriterInfoText;
    return pV->size();
 }
 
-const char* VSSClient::GetWriterInfo(size_t nIndex)
+const char* VSSClient::GetWriterInfo(int nIndex)
 {
-   vector<string>* pV = (vector<string>*) m_pVectorWriterInfo;   
-   return pV->at(nIndex).c_str();
+   alist* pV = (alist*) m_pAlistWriterInfoText;
+   return (char*) pV->get(nIndex);
 }
 
 
-const int VSSClient::GetWriterState(size_t nIndex)
+const int VSSClient::GetWriterState(int nIndex)
 {
-   vector<int>* pV = (vector<int>*) m_pVectorWriterStates;   
-   return pV->at(nIndex);
+   alist* pV = (alist*) m_pAlistWriterState;   
+   return (int) pV->get(nIndex);
+}
+
+void VSSClient::AppendWriterInfo(int nState, const char* pszInfo)
+{
+   alist* pT = (alist*) m_pAlistWriterInfoText;
+   alist* pS = (alist*) m_pAlistWriterState;
+
+   pT->push (bstrdup(pszInfo));
+   pS->push ((void*) nState);   
+}
+
+void VSSClient::DestroyWriterInfo()
+{
+   alist* pT = (alist*) m_pAlistWriterInfoText;
+   alist* pS = (alist*) m_pAlistWriterState;
+
+   while (!pT->empty())
+      free (pT->pop());
+
+   while (!pS->empty())
+      pS->pop();      
 }
 #endif
index ec10bfd3e75d05890a2a0ea00b8b20e665d77b5f..6eab807ebba0fac866879f32663be28d8aaa2e17 100644 (file)
@@ -51,13 +51,15 @@ public:
     BOOL GetShadowPathW (const WCHAR* szFilePath, WCHAR* szShadowPath, int nBuflen); /* nBuflen in characters */
 
     const size_t GetWriterCount();
-    const char* GetWriterInfo(size_t nIndex);
-    const int   GetWriterState(size_t nIndex);
+    const char* GetWriterInfo(int nIndex);
+    const int   GetWriterState(int nIndex);
+    void DestroyWriterInfo();
+    void AppendWriterInfo(int nState, const char* pszInfo);
     const BOOL  IsInitialized() { return m_bBackupIsInitialized; };
          
 private:
     virtual BOOL Initialize(DWORD dwContext, BOOL bDuringRestore = FALSE) = 0;
-    virtual void WaitAndCheckForAsyncOperation(IVssAsync*  pAsync) = 0;
+    virtual BOOL WaitAndCheckForAsyncOperation(IVssAsync*  pAsync) = 0;
     virtual void QuerySnapshotSet(GUID snapshotSetID) = 0;
 
 protected:
@@ -75,10 +77,10 @@ protected:
 
     // drive A will be stored on position 0,Z on pos. 25
     WCHAR                           m_wszUniqueVolumeName[26][MAX_PATH]; // approx. 7 KB
-    char /* in utf-8 */             m_szShadowCopyName[26][MAX_PATH*2]; // approx. 7 KB
-
-    void*                           m_pVectorWriterStates;
-    void*                           m_pVectorWriterInfo;
+    WCHAR                           m_szShadowCopyName[26][MAX_PATH]; // approx. 7 KB
+    
+    void*                           m_pAlistWriterState;
+    void*                           m_pAlistWriterInfoText;
 };
 
 class VSSClientXP:public VSSClient
@@ -91,7 +93,7 @@ public:
    virtual const char* GetDriverName() { return "VSS WinXP"; };
 private:
    virtual BOOL Initialize(DWORD dwContext, BOOL bDuringRestore);
-   virtual void WaitAndCheckForAsyncOperation(IVssAsync* pAsync);
+   virtual BOOL WaitAndCheckForAsyncOperation(IVssAsync* pAsync);
    virtual void QuerySnapshotSet(GUID snapshotSetID);
    BOOL CheckWriterStatus();   
 };
@@ -106,7 +108,7 @@ public:
    virtual const char* GetDriverName() { return "VSS Win 2003"; };
 private:
    virtual BOOL Initialize(DWORD dwContext, BOOL bDuringRestore);
-   virtual void WaitAndCheckForAsyncOperation(IVssAsync*  pAsync);
+   virtual BOOL WaitAndCheckForAsyncOperation(IVssAsync*  pAsync);
    virtual void QuerySnapshotSet(GUID snapshotSetID);
    BOOL CheckWriterStatus();
 };