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 typedef struct { 28 int8_t valueType; 29 char *key; 30 void *value; 31 int64_t size; 32 } CParameters; 33 34 typedef struct { 35 CParameters *head; 36 int64_t size; 37 } CArrParameters; 38 39 struct RetWorkInfo { 40 int32_t workId; 41 char* bundleName; 42 char* abilityName; 43 int32_t netWorkType; 44 int32_t isCharging; 45 int32_t chargerType; 46 int32_t batteryLevel; 47 int32_t batteryStatus; 48 int32_t storageRequest; 49 int32_t isRepeat; 50 int32_t repeatCycleTime; 51 int32_t repeatCount; 52 bool isPersisted; 53 int32_t isDeepIdle; 54 int32_t idleWaitTime; 55 }; 56 57 struct RetWorkInfoV2 { 58 RetWorkInfo v1; 59 CArrParameters parameters; 60 }; 61 62 struct RetArrRetWorkInfo { 63 int32_t code; 64 int64_t size; 65 RetWorkInfo* data; 66 }; 67 68 struct RetArrRetWorkInfoV2 { 69 int32_t code; 70 int64_t size; 71 RetWorkInfoV2* data; 72 }; 73 74 const int32_t UNSET_INT_PARAM = -1; 75 76 FFI_EXPORT int32_t CJ_StartWork(RetWorkInfo work); 77 FFI_EXPORT int32_t CJ_StopWork(RetWorkInfo work, bool needCancel); 78 FFI_EXPORT int32_t CJ_GetWorkStatus(int32_t workId, RetWorkInfo& result); 79 FFI_EXPORT RetArrRetWorkInfo CJ_ObtainAllWorks(); 80 FFI_EXPORT int32_t CJ_IsLastWorkTimeOut(int32_t workId, bool& result); 81 FFI_EXPORT int32_t CJ_StopAndClearWorks(); 82 FFI_EXPORT int32_t CJ_StartWorkV2(RetWorkInfoV2 work); 83 FFI_EXPORT int32_t CJ_StopWorkV2(RetWorkInfoV2 work, bool needCancel); 84 FFI_EXPORT int32_t CJ_GetWorkStatusV2(int32_t workId, RetWorkInfoV2& result); 85 FFI_EXPORT RetArrRetWorkInfoV2 CJ_ObtainAllWorksV2(); 86 87 int32_t GetWorkInfo(RetWorkInfo cwork, OHOS::WorkScheduler::WorkInfo& workInfo); 88 int32_t GetNetWorkInfo(RetWorkInfo cwork, OHOS::WorkScheduler::WorkInfo& workInfo, bool& hasCondition); 89 int32_t GetChargeInfo(RetWorkInfo cwork, OHOS::WorkScheduler::WorkInfo& workInfo, bool& hasCondition); 90 int32_t GetBatteryInfo(RetWorkInfo cwork, OHOS::WorkScheduler::WorkInfo& workInfo, bool& hasCondition); 91 int32_t GetStorageInfo(RetWorkInfo cwork, OHOS::WorkScheduler::WorkInfo& workInfo, bool& hasCondition); 92 int32_t GetRepeatInfo(RetWorkInfo cwork, OHOS::WorkScheduler::WorkInfo& workInfo, bool& hasCondition); 93 int32_t GetExtrasInfo(RetWorkInfoV2 cwork, OHOS::WorkScheduler::WorkInfo& workInfo); 94 void ParseExtrasInfo(std::shared_ptr<OHOS::WorkScheduler::WorkInfo> workInfo, CArrParameters& arrParam); 95 void ParseWorkInfo(std::shared_ptr<OHOS::WorkScheduler::WorkInfo> workInfo, RetWorkInfo& cwork); 96 char* MallocCString(const std::string& origin); 97 } 98 99 #endif 100