• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 ############
17 This file is used to support compatibility between platforms, differences between old and new projects and
18 compilation platforms
19 
20 defined __MUSL__ Has migrated to the latest version of harmony project
21 
22 defined HARMONY_PROJECT
23 With openharmony toolchains suport. If not defined, it should be [device]buildroot or [PC]msys64(...)/ubuntu-apt(...)
24 envirments
25 ############
26 */
27 #include "system_depend.h"
28 #include "parameter.h"
29 
30 namespace Hdc {
31 namespace SystemDepend {
SetDevItem(const char * key,const char * value)32     bool SetDevItem(const char *key, const char *value)
33     {
34         bool ret = true;
35         ret = SetParameter(key, value) == 0;
36         return ret;
37     }
38 
GetDevItem(const char * key,string & out,const char * preDefine)39     bool GetDevItem(const char *key, string &out, const char *preDefine)
40     {
41         char tmpStringBuf[BUF_SIZE_MEDIUM] = "";
42         auto res = GetParameter(key, preDefine, tmpStringBuf, BUF_SIZE_MEDIUM);
43         if (res <= 0) {
44             return false;
45         }
46         out = tmpStringBuf;
47         return true;
48     }
49 
RebootDevice(const string & cmd)50     bool RebootDevice(const string &cmd)
51     {
52         const string rebootProperty = "sys.powerctl";
53         string propertyVal;
54         string reason = cmd;
55         if (reason.size() == 0) {
56             propertyVal = "reboot";
57         } else {
58             propertyVal = Base::StringFormat("reboot,%s", reason.c_str());
59         }
60         return SetDevItem(rebootProperty.c_str(), propertyVal.c_str());
61     }
62 }
63 }  // namespace Hdc
64