1 /*
2  * Copyright (c) 2024 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 WORK_SCHEDULER_FFI_H
17 #define WORK_SCHEDULER_FFI_H
18 
19 #include "ffi_remote_data.h"
20 #include "cj_common_ffi.h"
21 #include "work_info.h"
22 #include <cstdint>
23 #include <memory>
24 #include <string>
25 
26 extern "C" {
27     struct RetWorkInfo {
28         int32_t workId;
29         char* bundleName;
30         char* abilityName;
31         int32_t netWorkType;
32         int32_t isCharging;
33         int32_t chargerType;
34         int32_t batteryLevel;
35         int32_t batteryStatus;
36         int32_t storageRequest;
37         int32_t isRepeat;
38         int32_t repeatCycleTime;
39         int32_t repeatCount;
40         bool isPersisted;
41         int32_t isDeepIdle;
42         int32_t idleWaitTime;
43     };
44 
45     struct RetArrRetWorkInfo {
46         int32_t code;
47         int64_t size;
48         RetWorkInfo* data;
49     };
50 
51     const int32_t UNSET_INT_PARAM = -1;
52 
53     FFI_EXPORT int32_t CJ_StartWork(RetWorkInfo work);
54     FFI_EXPORT int32_t CJ_StopWork(RetWorkInfo work, bool needCancel);
55     FFI_EXPORT int32_t CJ_GetWorkStatus(int32_t workId, RetWorkInfo& result);
56     FFI_EXPORT RetArrRetWorkInfo CJ_ObtainAllWorks();
57     FFI_EXPORT int32_t CJ_IsLastWorkTimeOut(int32_t workId, bool& result);
58 
59     int32_t GetWorkInfo(RetWorkInfo cwork, OHOS::WorkScheduler::WorkInfo& workInfo);
60     int32_t GetNetWorkInfo(RetWorkInfo cwork, OHOS::WorkScheduler::WorkInfo& workInfo, bool& hasCondition);
61     int32_t GetChargeInfo(RetWorkInfo cwork, OHOS::WorkScheduler::WorkInfo& workInfo, bool& hasCondition);
62     int32_t GetBatteryInfo(RetWorkInfo cwork, OHOS::WorkScheduler::WorkInfo& workInfo, bool& hasCondition);
63     int32_t GetStorageInfo(RetWorkInfo cwork, OHOS::WorkScheduler::WorkInfo& workInfo, bool& hasCondition);
64     int32_t GetRepeatInfo(RetWorkInfo cwork, OHOS::WorkScheduler::WorkInfo& workInfo, bool& hasCondition);
65     void ParseWorkInfo(std::shared_ptr<OHOS::WorkScheduler::WorkInfo> workInfo, RetWorkInfo& cwork);
66     char* MallocCString(const std::string& origin);
67 }
68 
69 #endif
70