qsv: Update SDK version to v2022.2.4
[platform/upstream/gstreamer.git] / subprojects / gst-plugins-bad / sys / qsv / libmfx / dispatcher / windows / mfx_win_reg_key.h
1 /*############################################################################
2   # Copyright (C) Intel Corporation
3   #
4   # SPDX-License-Identifier: MIT
5   ############################################################################*/
6
7 #ifndef DISPATCHER_WINDOWS_MFX_WIN_REG_KEY_H_
8 #define DISPATCHER_WINDOWS_MFX_WIN_REG_KEY_H_
9
10 #include <windows.h>
11 #include "vpl/mfxcommon.h"
12 #include "windows/mfx_dispatcher_log.h"
13
14 #if !defined(MEDIASDK_UWP_DISPATCHER)
15 namespace MFX {
16
17 template <class T>
18 struct RegKey {};
19 template <>
20 struct RegKey<bool> {
21     enum { type = REG_DWORD };
22 };
23 template <>
24 struct RegKey<mfxU32> {
25     enum { type = REG_DWORD };
26 };
27 template <>
28 struct RegKey<mfxVersion> {
29     enum { type = REG_DWORD };
30 };
31 template <>
32 struct RegKey<char *> {
33     enum { type = REG_SZ };
34 };
35 template <>
36 struct RegKey<wchar_t *> {
37     enum { type = REG_SZ };
38 };
39
40 class WinRegKey {
41 public:
42     // Default constructor
43     WinRegKey(void);
44     // Destructor
45     ~WinRegKey(void);
46
47     // Open a registry key
48     bool Open(HKEY hRootKey, const wchar_t *pSubKey, REGSAM samDesired);
49     bool Open(WinRegKey &rootKey, const wchar_t *pSubKey, REGSAM samDesired);
50
51     // Query value
52     bool QueryInfo(LPDWORD lpcSubkeys);
53
54     bool QueryValueSize(const wchar_t *pValueName, DWORD type, LPDWORD pcbData);
55     bool Query(const wchar_t *pValueName, DWORD type, LPBYTE pData, LPDWORD pcbData);
56
57     bool Query(const wchar_t *pValueName, wchar_t *pData, mfxU32 &nData) {
58         DWORD dw = (DWORD)nData;
59         if (!Query(pValueName, RegKey<wchar_t *>::type, (LPBYTE)pData, &dw)) {
60             return false;
61         }
62         nData = dw;
63         return true;
64     }
65
66     // Enumerate value names
67     bool EnumValue(DWORD index, wchar_t *pValueName, LPDWORD pcchValueName, LPDWORD pType);
68     bool EnumKey(DWORD index, wchar_t *pValueName, LPDWORD pcchValueName);
69
70 protected:
71     // Release the object
72     void Release(void);
73
74     HKEY m_hKey; // (HKEY) handle to the opened key
75
76 private:
77     // unimplemented by intent to make this class non-copyable
78     WinRegKey(const WinRegKey &);
79     void operator=(const WinRegKey &);
80 };
81
82 template <class T>
83 inline bool QueryKey(WinRegKey &key, const wchar_t *pValueName, T &data) {
84     DWORD size = sizeof(data);
85     return key.Query(pValueName, RegKey<T>::type, (LPBYTE)&data, &size);
86 }
87
88 template <>
89 inline bool QueryKey<bool>(WinRegKey &key, const wchar_t *pValueName, bool &data) {
90     mfxU32 value = 0;
91     bool bRes    = QueryKey(key, pValueName, value);
92     data         = (1 == value);
93     return bRes;
94 }
95
96 } // namespace MFX
97 #endif // #if !defined(MEDIASDK_UWP_DISPATCHER)
98
99 #endif // DISPATCHER_WINDOWS_MFX_WIN_REG_KEY_H_