1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "bms_param.h"
17 
18 #include "app_log_wrapper.h"
19 
20 namespace OHOS {
21 namespace AppExecFwk {
22 static std::map<std::string, std::string> BMS_PARAM;
23 
BmsParam()24 BmsParam::BmsParam()
25 {
26     APP_LOGD("BmsParam instance is created");
27 }
28 
~BmsParam()29 BmsParam::~BmsParam()
30 {
31     APP_LOGD("BmsParam instance is destroyed");
32 }
33 
GetBmsParam(const std::string & key,std::string & value)34 bool BmsParam::GetBmsParam(const std::string &key, std::string &value)
35 {
36     if (key.empty()) {
37         APP_LOGE("key is empty");
38         return false;
39     }
40 
41     auto iter = BMS_PARAM.find(key);
42     if (iter == BMS_PARAM.end()) {
43         return false;
44     }
45 
46     value = iter->second;
47     return true;
48 }
49 
SaveBmsParam(const std::string & paramKeyInfo,const std::string & paramValueInfo)50 bool BmsParam::SaveBmsParam(const std::string &paramKeyInfo, const std::string &paramValueInfo)
51 {
52     if (paramKeyInfo.empty()) {
53         APP_LOGE("key is empty");
54         return false;
55     }
56 
57     BMS_PARAM[paramKeyInfo] = paramValueInfo;
58     return true;
59 }
60 
DeleteBmsParam(const std::string & key)61 bool BmsParam::DeleteBmsParam(const std::string &key)
62 {
63     if (key.empty()) {
64         APP_LOGE("key is empty");
65         return false;
66     }
67 
68     BMS_PARAM.erase(key);
69     return true;
70 }
71 
72 }  // namespace AppExecFwk
73 }  // namespace OHOS