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 #ifndef FOUNDATION_RESOURCESCHEDULE_WORKSCHEDULER_WORK_SCHEDULER_SERVICE_STUB_H 16 #define FOUNDATION_RESOURCESCHEDULE_WORKSCHEDULER_WORK_SCHEDULER_SERVICE_STUB_H 17 18 #include <iremote_stub.h> 19 #include <nocopyable.h> 20 #include <list> 21 #include <memory> 22 23 #include "iwork_sched_service.h" 24 #include "iwork_sched_service_ipc_interface_code.h" 25 26 namespace OHOS { 27 namespace WorkScheduler { 28 class WorkSchedServiceStub : public IRemoteStub<IWorkSchedService> { 29 public: 30 WorkSchedServiceStub() = default; 31 virtual ~WorkSchedServiceStub() = default; 32 DISALLOW_COPY_AND_MOVE(WorkSchedServiceStub); 33 34 /** 35 * @brief The OnRemoteRequest callback. 36 * 37 * @param code The code. 38 * @param data The data. 39 * @param reply The reply. 40 * @param option The option. 41 * @return ERR_OK on success, others on failure. 42 */ 43 int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; 44 45 /** 46 * @brief Start work stub. 47 * 48 * @param data The data. 49 * @return error code, ERR_OK if success. 50 */ 51 int32_t StartWorkStub(MessageParcel& data); 52 /** 53 * @brief Stop work stub. 54 * 55 * @param data The data. 56 * @return error code, ERR_OK if success. 57 */ 58 int32_t StopWorkStub(MessageParcel& data); 59 /** 60 * @brief Stop and cancel work stub. 61 * 62 * @param data The data. 63 * @return error code, ERR_OK if success. 64 */ 65 int32_t StopAndCancelWorkStub(MessageParcel& data); 66 /** 67 * @brief Stop and clear works stub. 68 * 69 * @param data The data. 70 * @return error code, ERR_OK if success. 71 */ 72 int32_t StopAndClearWorksStub(MessageParcel& data); 73 /** 74 * @brief The last work time out stub. 75 * 76 * @param data The data. 77 * @param result True if the work executed time out, else false. 78 * @return error code, ERR_OK if success. 79 */ 80 int32_t IsLastWorkTimeoutStub(MessageParcel& data, bool &result); 81 /** 82 * @brief Obtain all works stub. 83 * 84 * @param data The data. 85 * @param workInfos The infos of work. 86 * @return error code, ERR_OK if success. 87 */ 88 int32_t ObtainAllWorksStub(MessageParcel& data, std::list<std::shared_ptr<WorkInfo>>& workInfos); 89 /** 90 * @brief Get work status stub. 91 * 92 * @param data The data. 93 * @param workInfo The info of work. 94 * @return error code, ERR_OK if success. 95 */ 96 int32_t GetWorkStatusStub(MessageParcel& data, std::shared_ptr<WorkInfo>& workInfo); 97 98 /** 99 * @brief Get the Running Work Scheduler Work object 100 * 101 * @param workInfos The infos of work. 102 * @return ErrCode ERR_OK on success, others on failure 103 */ 104 int32_t GetAllRunningWorksStub(std::list<std::shared_ptr<WorkInfo>>& workInfos); 105 106 /** 107 * @brief Pause Running Works. 108 * 109 * @param data The data. 110 * @param reply The reply. 111 * @return The errcode. ERR_OK on success, others on failure. 112 */ 113 int32_t PauseRunningWorksStub(MessageParcel &data, MessageParcel& reply); 114 115 /** 116 * @brief Resume Paused works. 117 * 118 * @param data The data. 119 * @param reply The reply. 120 * @return ErrCode ERR_OK on success, others on failure 121 */ 122 int32_t ResumePausedWorksStub(MessageParcel &data, MessageParcel& reply); 123 private: 124 int32_t HandleObtainAllWorksRequest(MessageParcel &data, MessageParcel &reply); 125 int32_t HandleGetWorkStatusRequest(MessageParcel &data, MessageParcel &reply); 126 int32_t HandleGetAllRunningWorksRequest(MessageParcel &reply); 127 int32_t HandleIsLastWorkTimeOutRequest(MessageParcel &data, MessageParcel &reply); 128 int32_t HandleRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); 129 int32_t HandleSetWorkSchedulerConfig(MessageParcel &data, MessageParcel &reply); 130 int32_t SetTimer(uint32_t code); 131 void CancelTimer(int32_t id); 132 private: 133 std::map<uint32_t, std::string> collieCodeStringMap_ = { 134 { uint32_t(IWorkSchedServiceInterfaceCode::START_WORK), "START_WORK" }, 135 }; 136 }; 137 } // namespace WorkScheduler 138 } // namespace OHOS 139 #endif // FOUNDATION_RESOURCESCHEDULE_WORKSCHEDULER_WORK_SCHEDULER_SERVICE_STUB_H