1 /*
2 * Copyright (c) 2017-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 mos_util_user_interface.cpp
24 //! \brief Common MOS util user feature key service across different platform
25 //!
26
27 #include "mos_util_user_interface.h"
28
29 std::map<uint32_t, PMOS_USER_FEATURE_VALUE> MosUtilUserInterface::m_userFeatureKeyMap;
30 MosMutex MosUtilUserInterface::m_mosMutex;
31
AddEntry(const uint32_t keyId,PMOS_USER_FEATURE_VALUE userFeatureKey)32 MOS_STATUS MosUtilUserInterface::AddEntry(const uint32_t keyId, PMOS_USER_FEATURE_VALUE userFeatureKey)
33 {
34 m_mosMutex.Lock();
35 auto result = m_userFeatureKeyMap.find(keyId);
36
37 if (result == m_userFeatureKeyMap.end())
38 {
39 m_userFeatureKeyMap.insert(std::make_pair(keyId, userFeatureKey));
40 }
41 else
42 {
43 MOS_OS_NORMALMESSAGE("User feature key already exist, replacing the old one.");
44 m_userFeatureKeyMap.erase(keyId);
45 m_userFeatureKeyMap.insert(std::make_pair(keyId, userFeatureKey));
46 m_mosMutex.Unlock();
47 return MOS_STATUS_SUCCESS;
48 }
49 m_mosMutex.Unlock();
50
51 return MOS_STATUS_SUCCESS;
52 }
53
DelEntry(const uint32_t keyId)54 MOS_STATUS MosUtilUserInterface::DelEntry(const uint32_t keyId)
55 {
56 m_mosMutex.Lock();
57
58 auto result = m_userFeatureKeyMap.find(keyId);
59
60 if (result != m_userFeatureKeyMap.end())
61 {
62 m_userFeatureKeyMap.erase(keyId);
63 }
64 else
65 {
66 m_mosMutex.Unlock();
67 return MOS_STATUS_SUCCESS;
68 }
69 m_mosMutex.Unlock();
70
71 return MOS_STATUS_SUCCESS;
72 }
73
GetValue(uint32_t keyId)74 PMOS_USER_FEATURE_VALUE MosUtilUserInterface::GetValue(uint32_t keyId)
75 {
76 m_mosMutex.Lock();
77
78 auto result = m_userFeatureKeyMap.find(keyId);
79
80 if (result != m_userFeatureKeyMap.end())
81 {
82 auto userFeatureValue = result->second;
83 m_mosMutex.Unlock();
84
85 return userFeatureValue;
86 }
87 else
88 {
89 m_mosMutex.Unlock();
90 return nullptr;
91 }
92 }
93