Debian Codegraph @

media_common/agnostic/common/os/user_setting/media_user_setting_configure.h

raw
1 /*
2 * Copyright (c) 2021-2022, Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22 //!
23 //! \file media_user_setting_configure.h
24 //! \brief The interface of media user setting configure.
25 //!
26
27 #ifndef __MEDIA_USER_SETTING_CONFIGURE__H__
28 #define __MEDIA_USER_SETTING_CONFIGURE__H__
29
30 #include <string>
31 #include <set>
32 #include "media_user_setting_definition.h"
33 #include "mos_utilities.h"
34
35 namespace MediaUserSetting {
36
37 namespace Internal {
38
39 typedef struct _ExtPathCFG
40 {
41 const char *subPath;
42 bool bStated;
43 } ExtPathCFG;
44
45 class Configure
46 {
47 public:
48 //!
49 //! \brief Constructor
50 //!
51 Configure();
52
53 //!
54 //! \brief Constructor
55 //!
56 Configure(MOS_USER_FEATURE_KEY_PATH_INFO *keyPathInfo);
57
58 //!
59 //! \brief Destructor
60 //!
61 ~Configure();
62
63 //!
64 //! \brief Register user setting item
65 //! \param [in] itemName
66 //! Name of the item
67 //! \param [in] group
68 //! Group of the item
69 //! \param [in] defaultValue
70 //! The default value of the item
71 //! \param [in] isReportKey
72 //! Whether this item can be reported
73 //! \param [in] debugOnly
74 //! Whether this item is only for debug/release-internal
75 //! \param [in] useCustomPath
76 //! Specifiy a read path
77 //! \param [in] customPath
78 //! The specified read path
79 //! \return MOS_STATUS
80 //! MOS_STATUS_SUCCESS if no error, otherwise will return failed reason
81 //!
82 MOS_STATUS Register(
83 const std::string &itemName,
84 const Group &group,
85 const Value &defaultValue,
86 bool isReportKey,
87 bool debugOnly,
88 bool useCustomPath,
89 const std::string &customPath,
90 bool statePath);
91
92 //!
93 //! \brief Read value of specific item
94 //! \param [out] value
95 //! The return value of the item
96 //! \param [in] itemName
97 //! Name of the item
98 //! \param [in] group
99 //! Group of the item
100 //! \param [in] mosContext
101 //! The pointer of mos context
102 //! \param [in] customValue
103 //! The custom value when failed
104 //! \param [in] useCustomValue
105 //! Whether use costom value when failed
106 //! \return MOS_STATUS
107 //! MOS_STATUS_SUCCESS if no error,MOS_STATUS_USER_FEATURE_KEY_OPEN_FAILED if user setting is not set, otherwise will return specific failed reason
108 //!
109 MOS_STATUS Read(Value &value,
110 const std::string &itemName,
111 const Group &group,
112 const Value &customValue,
113 bool useCustomValue = false,
114 uint32_t option = MEDIA_USER_SETTING_INTERNAL);
115
116 //!
117 //! \brief Write value to specific item
118 //! \param [in] itemName
119 //! Name of the item
120 //! \param [in] value
121 //! The value write to specific item
122 //! \param [in] group
123 //! Group of the item
124 //! \param [in] mosContext
125 //! The pointer of mos context
126 //! \param [in] isForReport
127 //! This call is for reporting a item value or modify the value of the item
128 //! \return MOS_STATUS
129 //! MOS_STATUS_SUCCESS if no error, otherwise will return failed reason
130 //!
131 MOS_STATUS Write(
132 const std::string &itemName,
133 const Value &value,
134 const Group &group,
135 bool isForReport,
136 uint32_t option = MEDIA_USER_SETTING_INTERNAL);
137
138 //!
139 //! \brief Get the report path of the key
140 //! \return std::string
141 //! the path
142 //!
143 std::string GetReportPath(
144 std::shared_ptr<Definition> def,
145 uint32_t option);
146
147 //!
148 //! \brief Get the read path of the key
149 //! \return std::string
150 //! the path
151 //!
152 std::string GetReadPath(
153 std::shared_ptr<Definition> def,
154 uint32_t option);
155
156 //!
157 //! \brief Get the path of the external key
158 //! \return std::string
159 //! the path
160 //!
161 std::string GetExternalPath(uint32_t option);
162
163 //!
164 //! \brief Check whether definition of specific item name exist in all groups
165 //! \param [in] itemName
166 //! Item name
167 //! \return bool
168 //! true if exist, otherwise false
169 //!
170 inline bool IsDefinitionExist(const std::string &itemName)
171 {
172 bool ret = false;
173 for (auto &defs : m_definitions)
174 {
175 auto it = defs.find(MakeHash(itemName));
176 if (it != defs.end())
177 {
178 ret = true;
179 break;
180 }
181 }
182 return ret;
183 }
184
185 //!
186 //! \brief Get media user setting definitions of specific group
187 //! \param [in] group
188 //! Group of the item
189 //! \return Media user setting definitions
190 //! Definitions of specific group, return definitions of device group if failed
191 //!
192 inline Definitions &GetDefinitions(const Group &group)
193 {
194 if (group < Group::Device || group >= Group::MaxCount)
195 {
196 return m_definitions[Group::Device];
197 }
198
199 return m_definitions[group];
200 }
201 protected:
202
203 //!
204 //! \brief Get hash value of specific string
205 //! \param [in] str
206 //! Input string
207 //! \return size_t
208 //! Hash value
209 //!
210 size_t MakeHash(const std::string &str)
211 {
212 std::hash<std::string> HashFunc;
213 return HashFunc(str);
214 }
215
216 const uint32_t GetRegAccessDataType(MOS_USER_FEATURE_VALUE_TYPE type);
217
218 protected:
219 MosMutex m_mutexLock; //!< mutex for protecting definitions
220 Definitions m_definitions[Group::MaxCount]{}; //!< definitions of media user setting
221 bool m_isDebugMode = false; //!< whether in debug/release-internal mode
222 RegBufferMap m_regBufferMap{};
223 MOS_USER_FEATURE_KEY_PATH_INFO *m_keyPathInfo = nullptr;
224
225 static const UFKEY_NEXT m_rootKey;
226 static const char *m_configPath;
227 static const char *m_reportPath;
228 static const std::map<uint32_t, ExtPathCFG> m_pathOption;
229 std::string m_statedConfigPath = "";
230 std::string m_statedReportPath = "";
231 #if (_DEBUG || _RELEASE_INTERNAL)
232 std::string m_pidPath = "";
233 static std::set<std::string> m_nonPidRegPaths; // Record non-pid reg path which does not have inner pid path
234 #endif
235 };
236 }
237 }
238 #endif