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 <string> 19 20 #include <singleton.h> 21 22 #include "iwork_sched_service.h" 23 24 namespace OHOS { 25 namespace WorkScheduler { 26 class WorkSchedulerSrvClient final : public DelayedRefSingleton<WorkSchedulerSrvClient> { 27 DECLARE_DELAYED_REF_SINGLETON(WorkSchedulerSrvClient) 28 public: 29 DISALLOW_COPY_AND_MOVE(WorkSchedulerSrvClient); 30 31 bool StartWork(WorkInfo& workInfo); 32 bool StopWork(WorkInfo& workInfo); 33 bool StopAndCancelWork(WorkInfo& workInfo); 34 bool StopAndClearWorks(); 35 ErrCode IsLastWorkTimeout(int32_t workId, bool &result); 36 ErrCode GetWorkStatus(int32_t workId, std::shared_ptr<WorkInfo> &workInfo); 37 ErrCode ObtainAllWorks(std::list<std::shared_ptr<WorkInfo>> &workInfos); 38 bool ShellDump(const std::vector<std::string> &dumpOption, std::vector<std::string> &dumpInfo); 39 40 private: 41 class WorkSchedulerDeathRecipient : public IRemoteObject::DeathRecipient { 42 public: 43 WorkSchedulerDeathRecipient() = default; 44 ~WorkSchedulerDeathRecipient() = default; 45 void OnRemoteDied(const wptr<IRemoteObject>& remote); 46 private: 47 DISALLOW_COPY_AND_MOVE(WorkSchedulerDeathRecipient); 48 }; 49 50 ErrCode Connect(); 51 sptr<IWorkSchedService> iWorkSchedService_ {nullptr}; 52 sptr<IRemoteObject::DeathRecipient> deathRecipient_ {nullptr}; 53 void ResetProxy(const wptr<IRemoteObject>& remote); 54 std::mutex mutex_; 55 }; 56 } 57 } 58 #endif // FOUNDATION_RESOURCESCHEDULE_WORKSCHEDULER_WORKSCHEDDULER_SRV_CLIENT_H