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 #ifndef FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_SERVICES_CORE_INCLUDE_ALLOW_RECORD_H
17 #define FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_SERVICES_CORE_INCLUDE_ALLOW_RECORD_H
18 
19 #include <list>
20 #include <string>
21 #include <cstdint>
22 #include "nlohmann/json.hpp"
23 
24 namespace OHOS {
25 namespace DevStandbyMgr {
26 struct AllowTime {
27     AllowTime() = default;
AllowTimeAllowTime28     AllowTime(uint32_t allowTypeIndex, int64_t endTime, const std::string& reason)
29         : allowTypeIndex_(allowTypeIndex), endTime_(endTime), reason_(reason) {}
30     uint32_t allowTypeIndex_;
31     int64_t endTime_ {0};
32     std::string reason_ {""};
33 };
34 
35 struct AllowRecord {
36     AllowRecord() = default;
AllowRecordAllowRecord37     AllowRecord(int32_t uid, int32_t pid, const std::string& name, uint32_t allowType)
38         : uid_(uid), pid_(pid), name_(name), allowType_(allowType) {}
39     nlohmann::json ParseToJson();
40     bool setAllowTime(const nlohmann::json& persistTime);
41     bool setAllowRecordField(const nlohmann::json& value);
42     bool ParseFromJson(const nlohmann::json& value);
43 
44     int32_t uid_ {-1};
45     int32_t pid_ {-1};
46     std::string name_ {""};
47     uint32_t allowType_ {0};
48     std::list<AllowTime> allowTimeList_ {};
49     uint32_t reasonCode_ {0};
50 };
51 }  // namespace DevStandbyMgr
52 }  // namespace OHOS
53 #endif  // FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_SERVICES_CORE_INCLUDE_ALLOW_RECORD_H