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 "media_user_setting_definition.h"
32 #include "mos_utilities.h"
33 
34 namespace MediaUserSetting {
35 
36 namespace Internal {
37 
38 typedef struct _ExtPathCFG
39 {
40     const char *subPath;
41     bool        bStated;
42 } ExtPathCFG;
43 
44 class Configure
45 {
46 public:
47     //!
48     //! \brief    Constructor
49     //!
50     Configure();
51 
52     //!
53     //! \brief    Constructor
54     //!
55     Configure(MOS_USER_FEATURE_KEY_PATH_INFO *keyPathInfo);
56 
57     //!
58     //! \brief    Destructor
59     //!
60     ~Configure();
61 
62     //!
63     //! \brief    Register user setting item
64     //! \param    [in] itemName
65     //!           Name of the item
66     //! \param    [in] group
67     //!           Group of the item
68     //! \param    [in] defaultValue
69     //!           The default value of the item
70     //! \param    [in] isReportKey
71     //!           Whether this item can be reported
72     //! \param    [in] debugOnly
73     //!           Whether this item is only for debug/release-internal
74     //! \param    [in] useCustomPath
75     //!           Specifiy a read path
76     //! \param    [in] customPath
77     //!           The specified read path
78     //! \return   MOS_STATUS
79     //!           MOS_STATUS_SUCCESS if no error, otherwise will return failed reason
80     //!
81     MOS_STATUS Register(
82         const std::string &itemName,
83         const Group &group,
84         const Value &defaultValue,
85         bool isReportKey,
86         bool debugOnly,
87         bool useCustomPath,
88         const std::string &customPath,
89         bool statePath);
90 
91     //!
92     //! \brief    Read value of specific item
93     //! \param    [out] value
94     //!           The return value of the item
95     //! \param    [in] itemName
96     //!           Name of the item
97     //! \param    [in] group
98     //!           Group of the item
99     //! \param    [in] mosContext
100     //!           The pointer of mos context
101     //! \param    [in] customValue
102     //!           The custom value when failed
103     //! \param    [in] useCustomValue
104     //!           Whether use costom value when failed
105     //! \return   MOS_STATUS
106     //!           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
107     //!
108     MOS_STATUS Read(Value &value,
109         const std::string &itemName,
110         const Group &group,
111         const Value &customValue,
112         bool useCustomValue = false,
113         uint32_t option = MEDIA_USER_SETTING_INTERNAL);
114 
115     //!
116     //! \brief    Write value to specific item
117     //! \param    [in] itemName
118     //!           Name of the item
119     //! \param    [in] value
120     //!           The value write to specific item
121     //! \param    [in] group
122     //!           Group of the item
123     //! \param    [in] mosContext
124     //!           The pointer of mos context
125     //! \param    [in] isForReport
126     //!           This call is for reporting a item value or modify the value of the item
127     //! \return   MOS_STATUS
128     //!           MOS_STATUS_SUCCESS if no error, otherwise will return failed reason
129     //!
130     MOS_STATUS Write(
131         const std::string &itemName,
132         const Value &value,
133         const Group &group,
134         bool isForReport,
135         uint32_t option = MEDIA_USER_SETTING_INTERNAL);
136 
137     //!
138     //! \brief    Get the report path of the key
139     //! \return   std::string
140     //!           the path
141     //!
142     std::string GetReportPath(
143         std::shared_ptr<Definition> def,
144         uint32_t option);
145 
146     //!
147     //! \brief    Get the read path of the key
148     //! \return   std::string
149     //!           the path
150     //!
151     std::string GetReadPath(
152         std::shared_ptr<Definition> def,
153         uint32_t option);
154 
155     //!
156     //! \brief    Get the path of the external key
157     //! \return   std::string
158     //!           the path
159     //!
160     std::string GetExternalPath(uint32_t option);
161 
162     //!
163     //! \brief    Check whether definition of specific item name exist in all groups
164     //! \param    [in] itemName
165     //!           Item name
166     //! \return   bool
167     //!           true if exist, otherwise false
168     //!
IsDefinitionExist(const std::string & itemName)169     inline bool IsDefinitionExist(const std::string &itemName)
170     {
171         bool ret = false;
172         for (auto &defs : m_definitions)
173         {
174             auto it = defs.find(MakeHash(itemName));
175             if (it != defs.end())
176             {
177                 ret = true;
178                 break;
179             }
180         }
181         return ret;
182     }
183 
184     //!
185     //! \brief    Get media user setting definitions of specific group
186     //! \param    [in] group
187     //!           Group of the item
188     //! \return   Media user setting definitions
189     //!           Definitions of specific group, return definitions of device group if failed
190     //!
GetDefinitions(const Group & group)191     inline Definitions &GetDefinitions(const Group &group)
192     {
193         if (group < Group::Device || group >= Group::MaxCount)
194         {
195             return m_definitions[Group::Device];
196         }
197 
198         return m_definitions[group];
199     }
200 protected:
201 
202     //!
203     //! \brief    Get hash value of specific string
204     //! \param    [in] str
205     //!           Input string
206     //! \return   size_t
207     //!           Hash value
208     //!
MakeHash(const std::string & str)209     size_t MakeHash(const std::string &str)
210     {
211         std::hash<std::string> HashFunc;
212         return HashFunc(str);
213     }
214 
215     const uint32_t GetRegAccessDataType(MOS_USER_FEATURE_VALUE_TYPE type);
216 
217 protected:
218     MosMutex m_mutexLock; //!< mutex for protecting definitions
219     Definitions m_definitions[Group::MaxCount]{}; //!< definitions of media user setting
220     bool m_isDebugMode = false; //!< whether in debug/release-internal mode
221     RegBufferMap m_regBufferMap{};
222     MOS_USER_FEATURE_KEY_PATH_INFO *m_keyPathInfo = nullptr;
223 
224     static const UFKEY_NEXT m_rootKey;
225     static const char *m_configPath;
226     static const char *m_reportPath;
227     static const std::map<uint32_t, ExtPathCFG> m_pathOption;
228     std::string                                 m_statedConfigPath = "";
229     std::string                                 m_statedReportPath = "";
230 };
231 }
232 }
233 #endif