• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #ifndef WORK_SCHED_SERVICES_WORK_STATUS_H
17 #define WORK_SCHED_SERVICES_WORK_STATUS_H
18 
19 #include <memory>
20 #include <string>
21 
22 #include "timer.h"
23 #include "work_info.h"
24 
25 namespace OHOS {
26 using namespace Utils;
27 namespace WorkScheduler {
28 class WorkStatus {
29 public:
30     enum Status {
31         WAIT_CONDITION = 0,
32         CONDITION_READY,
33         RUNNING,
34         REMOVED
35     };
36     const int32_t DEFAULT_PRIORITY = 100;
37     WorkStatus(WorkInfo &workInfo, int32_t uid);
38     ~WorkStatus();
39 
40     static std::string MakeWorkId(int32_t workId, int32_t uid);
41 
42     std::string workId_;
43     std::string bundleName_;
44     std::string abilityName_;
45     int32_t uid_;
46     int userId_;
47     bool persisted_;
48     int32_t priority_;
49     std::map<WorkCondition::Type, std::shared_ptr<Condition>> conditionMap_;
50     std::shared_ptr<WorkInfo> workInfo_;
51 
52     bool IsReady();
53     bool IsReadyStatus();
54     bool IsRunning();
55     bool IsRemoved();
56     bool IsRepeating();
57     bool IsLastWorkTimeout();
58     void OnConditionChanged(WorkCondition::Type &type, std::shared_ptr<Condition> value);
59     void MarkRound();
60     void MarkStatus(Status status);
61     Status GetStatus();
62     void Dump(std::string& result);
63     void UpdateTimerIfNeed();
64     bool NeedRemove();
65 
66     bool lastTimeout_ {false};
67 private:
68     Status currentStatus_;
69     time_t baseTime_;
70     void MarkTimeout();
71     bool IsSameUser();
72 };
73 } // namespace WorkScheduler
74 } // namespace OHOS
75 #endif // WORK_SCHED_SERVICES_WORK_STATUS_H