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_SCHED_SERVICE_PROXY_H
16 #define FOUNDATION_RESOURCESCHEDULE_WORKSCHEDULER_WORK_SCHED_SERVICE_PROXY_H
17 
18 #include <list>
19 #include <memory>
20 
21 #include <iremote_proxy.h>
22 #include <nocopyable.h>
23 #include "refbase.h"
24 
25 #include "iwork_sched_service.h"
26 
27 namespace OHOS {
28 namespace WorkScheduler {
29 class WorkSchedServiceProxy : public IRemoteProxy<IWorkSchedService> {
30 public:
WorkSchedServiceProxy(const sptr<IRemoteObject> & impl)31     explicit WorkSchedServiceProxy(const sptr<IRemoteObject>& impl) : IRemoteProxy<IWorkSchedService>(impl) {}
32     ~WorkSchedServiceProxy() = default;
33     DISALLOW_COPY_AND_MOVE(WorkSchedServiceProxy);
34 
35     /**
36      * @brief Start work.
37      *
38      * @param workInfo The info of work.
39      * @return error code, ERR_OK if success.
40      */
41     int32_t StartWork(WorkInfo& workInfo) override;
42     /**
43      * @brief Stop work.
44      *
45      * @param workInfo The info of work.
46      * @return error code, ERR_OK if success.
47      */
48     int32_t StopWork(WorkInfo& workInfo) override;
49     /**
50      * @brief Stop and cancel work.
51      *
52      * @param workInfo The info of work.
53      * @return error code, ERR_OK if success.
54      */
55     int32_t StopAndCancelWork(WorkInfo& workInfo) override;
56     /**
57      * @brief Stop and clear works.
58      *
59      * @return error code, ERR_OK if success.
60      */
61     int32_t StopAndClearWorks() override;
62     /**
63      * @brief The last work time out.
64      *
65      * @param workId The id of work.
66      * @param result True if the work executed time out, else false.
67      * @return error code, ERR_OK if success.
68      */
69     int32_t IsLastWorkTimeout(int32_t workId, bool &result) override;
70     /**
71      * @brief Obtain all works.
72      *
73      * @param workInfos The infos of work.
74      * @return error code, ERR_OK if success.
75      */
76     int32_t ObtainAllWorks(std::list<std::shared_ptr<WorkInfo>>& workInfos) override;
77     /**
78      * @brief Get the status of work.
79      *
80      * @param workId The id of work.
81      * @param workInfo The info of work.
82      * @return error code, ERR_OK if success.
83      */
84     int32_t GetWorkStatus(int32_t &workId, std::shared_ptr<WorkInfo>& workInfo) override;
85 
86     /**
87      * @brief Get the Running Work Scheduler Work object
88      *
89      * @param workInfos The infos of work.
90      * @return ErrCode ERR_OK on success, others on failure
91      */
92     int32_t GetAllRunningWorks(std::list<std::shared_ptr<WorkInfo>>& workInfos) override;
93 
94     /**
95      * @brief Pause Running Works.
96      *
97      * @param uid The uid.
98      * @return The errcode. ERR_OK on success, others on failure.
99      */
100     int32_t PauseRunningWorks(int32_t uid) override;
101 
102     /**
103      * @brief Resume Paused works.
104      *
105      * @param uid The uid.
106      * @return ErrCode ERR_OK on success, others on failure
107      */
108     int32_t ResumePausedWorks(int32_t uid) override;
109 
110     /**
111      * @brief Set work scheduler config.
112      *
113      * @param configData config param.
114      * @param sourceType data source.
115      * @return ErrCode ERR_OK on success, others on failure
116      */
117     int32_t SetWorkSchedulerConfig(const std::string &configData, int32_t sourceType) override;
118 private:
119     static inline BrokerDelegator<WorkSchedServiceProxy> delegator_;
120 };
121 } // namespace WorkScheduler
122 } // namespace OHOS
123 #endif // FOUNDATION_RESOURCESCHEDULE_WORKSCHEDULER_WORK_SCHED_SERVICE_PROXY_H