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 "parameter.h"
17 #include <string>
18
SetParameterEx(const char * key,const char * val)19 extern "C" int SetParameterEx(const char *key, const char *val)
20 {
21 return SetParameter(key, val);
22 }
23
GetParameterEx(const char * key,const char * def,char * val,unsigned int len)24 extern "C" int GetParameterEx(const char *key, const char *def, char *val, unsigned int len)
25 {
26 return GetParameter(key, def, val, len);
27 }
28
WaitParameterEx(const char * key,const char * val,int timeout)29 extern "C" int WaitParameterEx(const char *key, const char *val, int timeout)
30 {
31 return WaitParameter(key, val, timeout);
32 }
33
34 namespace Hdc {
SetDevItem(const char * key,const char * value)35 bool SetDevItem(const char *key, const char *value)
36 {
37 return SetParameterEx(key, value) == 0;
38 }
39
GetDevItem(const char * key,std::string & out,const char * preDefine)40 bool GetDevItem(const char *key, std::string &out, const char *preDefine)
41 {
42 bool ret = true;
43 constexpr uint16_t paramLen = 512;
44 char tmpStringBuf[paramLen] = "";
45
46 auto res = GetParameter(key, preDefine, tmpStringBuf, paramLen);
47 if (res <= 0) {
48 return false;
49 }
50 out = tmpStringBuf;
51 return ret;
52 }
53 } // namespace Hdc