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