• 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 #include "utils.h"
30 
31 namespace Hdc {
32 namespace SystemDepend {
SetDevItem(const char * key,const char * value)33     bool SetDevItem(const char *key, const char *value)
34     {
35         bool ret = true;
36         ret = SetParameter(key, value) == 0;
37         return ret;
38     }
39 
GetDevItem(const char * key,string & out,const char * preDefine)40     bool GetDevItem(const char *key, string &out, const char *preDefine)
41     {
42         char tmpStringBuf[BUF_SIZE_MEDIUM] = "";
43         auto res = GetParameter(key, preDefine, tmpStringBuf, BUF_SIZE_MEDIUM);
44         if (res <= 0) {
45             return false;
46         }
47         out = tmpStringBuf;
48         return true;
49     }
50 
RebootDevice(const string & cmd)51     bool RebootDevice(const string &cmd)
52     {
53         const string rebootProperty = "sys.powerctl";
54         string propertyVal;
55         string reason = cmd;
56         if (reason.size() == 0) {
57             propertyVal = "reboot";
58         } else {
59             propertyVal = Base::StringFormat("reboot,%s", reason.c_str());
60         }
61         return SetDevItem(rebootProperty.c_str(), propertyVal.c_str());
62     }
63 }
64 }  // namespace Hdc
65