• 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 #ifndef DEVICESTATUS_DATA_PARSE_H
17 #define DEVICESTATUS_DATA_PARSE_H
18 
19 #include <fcntl.h>
20 #include <poll.h>
21 #include <stdint.h>
22 #include <string>
23 #include <sys/socket.h>
24 #include <sys/stat.h>
25 #include <sys/un.h>
26 #include <unistd.h>
27 #include <vector>
28 
29 #include "cJSON.h"
30 
31 #include "devicestatus_data_define.h"
32 #include "devicestatus_data_utils.h"
33 #include "devicestatus_errors.h"
34 #include "devicestatus_hilog_wrapper.h"
35 
36 namespace OHOS {
37 namespace Msdp {
38 namespace DeviceStatus {
39 class DeviceStatusDataParse {
40 public:
41     DeviceStatusDataParse() = default;
42     ~DeviceStatusDataParse() = default;
43     bool ParseDeviceStatusData(DevicestatusDataUtils::DevicestatusData& data,
44         DevicestatusDataUtils::DevicestatusType& type);
45     bool DisableCount(const  DevicestatusDataUtils::DevicestatusType& type);
46     bool DataInit(const std::string& fileData, bool logStatus, DevicestatusDataUtils::DevicestatusType& type,
47         DevicestatusDataUtils::DevicestatusData& data);
48     int32_t CreateJsonFile();
49 
50 private:
51     bool JudgeTypeData(const int32_t valueInt);
52     int32_t GetFileSize(const std::string& filePath);
53     bool CheckFileDir(const std::string& filePath, const std::string& dir);
54     int32_t CheckFileSize(const std::string& filePath);
55     bool CheckFileExtendName(const std::string& filePath, const std::string& checkExtension);
56     bool IsFileExists(const std::string& fileName);
57     std::string ReadFile(const std::string &filePath);
58     std::string ReadJsonFile(const std::string &filePath);
59     static std::vector<int32_t> tempcount_;
60 };
61 } // namespace DeviceStatus
62 } // namespace Msdp
63 } // namespace OHOS
64 #endif // DEVICESTATUS_DATA_PARSE_H
65