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_WORKSCHEDDULER_SRV_CLIENT_H 16 #define FOUNDATION_RESOURCESCHEDULE_WORKSCHEDULER_WORKSCHEDDULER_SRV_CLIENT_H 17 18 #include <list> 19 #include <string> 20 21 #include <singleton.h> 22 23 #include "iwork_sched_service.h" 24 25 namespace OHOS { 26 namespace WorkScheduler { 27 class WorkSchedulerSrvClient final : public DelayedRefSingleton<WorkSchedulerSrvClient> { 28 DECLARE_DELAYED_REF_SINGLETON(WorkSchedulerSrvClient) 29 public: 30 DISALLOW_COPY_AND_MOVE(WorkSchedulerSrvClient); 31 32 /** 33 * @brief Start work. 34 * 35 * @param workInfo The info of work. 36 * @return ERR_OK on success, others on failure. 37 */ 38 ErrCode StartWork(WorkInfo& workInfo); 39 /** 40 * @brief Stop work. 41 * 42 * @param workInfo The info of work. 43 * @return ERR_OK on success, others on failure. 44 */ 45 ErrCode StopWork(WorkInfo& workInfo); 46 /** 47 * @brief Stop and cancel work. 48 * 49 * @param workInfo The info of work. 50 * @return ERR_OK on success, others on failure. 51 */ 52 ErrCode StopAndCancelWork(WorkInfo& workInfo); 53 /** 54 * @brief Stop and clear works. 55 * 56 * @return ERR_OK on success, others on failure. 57 */ 58 ErrCode StopAndClearWorks(); 59 /** 60 * @brief The last work time out. 61 * 62 * @param workId The id of work. 63 * @param result True if the work executed time out, else false. 64 * @return ERR_OK on success, others on failure. 65 */ 66 ErrCode IsLastWorkTimeout(int32_t workId, bool &result); 67 /** 68 * @brief Get the status of work. 69 * 70 * @param workId The id of work. 71 * @param workInfo The info of work. 72 * @return ERR_OK on success, others on failure. 73 */ 74 ErrCode GetWorkStatus(int32_t workId, std::shared_ptr<WorkInfo> &workInfo); 75 /** 76 * @brief Obtain all works. 77 * 78 * @param workInfos The infos of work. 79 * @return ERR_OK on success, others on failure. 80 */ 81 ErrCode ObtainAllWorks(std::list<std::shared_ptr<WorkInfo>> &workInfos); 82 83 private: 84 class WorkSchedulerDeathRecipient : public IRemoteObject::DeathRecipient { 85 public: 86 explicit WorkSchedulerDeathRecipient(WorkSchedulerSrvClient &workSchedulerSrvClient); 87 ~WorkSchedulerDeathRecipient() override = default; 88 void OnRemoteDied(const wptr<IRemoteObject>& remote) override; 89 private: 90 WorkSchedulerSrvClient &workSchedulerSrvClient_; 91 }; 92 93 ErrCode Connect(); 94 sptr<IWorkSchedService> iWorkSchedService_ {nullptr}; 95 sptr<IRemoteObject::DeathRecipient> deathRecipient_ {nullptr}; 96 void ResetProxy(); 97 std::mutex mutex_; 98 }; 99 } // namespace WorkScheduler 100 } // namespace OHOS 101 #endif // FOUNDATION_RESOURCESCHEDULE_WORKSCHEDULER_WORKSCHEDDULER_SRV_CLIENT_H