| 1 | /* |
| 2 | * QEMU Guest Agent win32 VSS common declarations |
| 3 | * |
| 4 | * Copyright Hitachi Data Systems Corp. 2013 |
| 5 | * |
| 6 | * Authors: |
| 7 | * Tomoki Sekiyama <tomoki.sekiyama@hds.com> |
| 8 | * |
| 9 | * This work is licensed under the terms of the GNU GPL, version 2 or later. |
| 10 | * See the COPYING file in the top-level directory. |
| 11 | */ |
| 12 | |
| 13 | #ifndef VSS_COMMON_H |
| 14 | #define VSS_COMMON_H |
| 15 | |
| 16 | #define __MIDL_user_allocate_free_DEFINED__ |
| 17 | #include <windows.h> |
| 18 | #include <shlwapi.h> |
| 19 | |
| 20 | /* Reduce warnings to include vss.h */ |
| 21 | |
| 22 | /* Ignore annotations for MS IDE */ |
| 23 | #define __in IN |
| 24 | #define __out OUT |
| 25 | #define __RPC_unique_pointer |
| 26 | #define __RPC_string |
| 27 | #define __RPC__deref_inout_opt |
| 28 | #define __RPC__out |
| 29 | #ifndef __RPC__out_ecount_part |
| 30 | #define __RPC__out_ecount_part(x, y) |
| 31 | #endif |
| 32 | #define _declspec(x) |
| 33 | |
| 34 | #include <vss.h> |
| 35 | #include "vss-handles.h" |
| 36 | |
| 37 | /* Macros to convert char definitions to wchar */ |
| 38 | #define _L(a) L##a |
| 39 | #define L(a) _L(a) |
| 40 | |
| 41 | const GUID g_gProviderId = { 0x3629d4ed, 0xee09, 0x4e0e, |
| 42 | {0x9a, 0x5c, 0x6d, 0x8b, 0xa2, 0x87, 0x2a, 0xef} }; |
| 43 | const GUID g_gProviderVersion = { 0x11ef8b15, 0xcac6, 0x40d6, |
| 44 | {0x8d, 0x5c, 0x8f, 0xfc, 0x16, 0x3f, 0x24, 0xca} }; |
| 45 | |
| 46 | const CLSID CLSID_QGAVSSProvider = { 0x6e6a3492, 0x8d4d, 0x440c, |
| 47 | {0x96, 0x19, 0x5e, 0x5d, 0x0c, 0xc3, 0x1c, 0xa8} }; |
| 48 | |
| 49 | const TCHAR g_szClsid[] = TEXT("{6E6A3492-8D4D-440C-9619-5E5D0CC31CA8}"); |
| 50 | const TCHAR g_szProgid[] = TEXT("QGAVSSProvider"); |
| 51 | |
| 52 | #ifdef HAVE_VSS_SDK |
| 53 | /* Enums undefined in VSS SDK 7.2 but defined in newer Windows SDK */ |
| 54 | enum __VSS_VOLUME_SNAPSHOT_ATTRIBUTES { |
| 55 | VSS_VOLSNAP_ATTR_NO_AUTORECOVERY = 0x00000002, |
| 56 | VSS_VOLSNAP_ATTR_TXF_RECOVERY = 0x02000000 |
| 57 | }; |
| 58 | #endif |
| 59 | |
| 60 | /* COM pointer utility; call ->Release() when it goes out of scope */ |
| 61 | template <class T> |
| 62 | class COMPointer { |
| 63 | COMPointer(const COMPointer<T> &p) { } /* no copy */ |
| 64 | T *p; |
| 65 | public: |
| 66 | COMPointer &operator=(T *new_p) |
| 67 | { |
| 68 | /* Assignment of a new T* (or NULL) causes release of previous p */ |
| 69 | if (p && p != new_p) { |
| 70 | p->Release(); |
| 71 | } |
| 72 | p = new_p; |
| 73 | return *this; |
| 74 | } |
| 75 | /* Replace by assignment to the pointer of p */ |
| 76 | T **replace(void) |
| 77 | { |
| 78 | *this = NULL; |
| 79 | return &p; |
| 80 | } |
| 81 | /* Make COMPointer be used like T* */ |
| 82 | operator T*() { return p; } |
| 83 | T *operator->(void) { return p; } |
| 84 | T &operator*(void) { return *p; } |
| 85 | operator bool() { return !!p; } |
| 86 | |
| 87 | COMPointer(T *p = NULL) : p(p) { } |
| 88 | ~COMPointer() { *this = NULL; } /* Automatic release */ |
| 89 | }; |
| 90 | |
| 91 | /* |
| 92 | * COM initializer; this should declared before COMPointer to uninitialize COM |
| 93 | * after releasing COM objects. |
| 94 | */ |
| 95 | class COMInitializer { |
| 96 | public: |
| 97 | COMInitializer() { CoInitialize(NULL); } |
| 98 | ~COMInitializer() { CoUninitialize(); } |
| 99 | }; |
| 100 | |
| 101 | #endif |