• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2024 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 OHOS_FILEMGMT_BACKUP_SCHED_SCHEDULER_H
17 #define OHOS_FILEMGMT_BACKUP_SCHED_SCHEDULER_H
18 
19 #include <cstdint>
20 #include <refbase.h>
21 #include <set>
22 #include <shared_mutex>
23 #include <string>
24 #include <vector>
25 
26 #include "b_resources/b_constants.h"
27 #include "iremote_broker.h"
28 #include "thread_pool.h"
29 #include "timer.h"
30 
31 namespace OHOS::FileManagement::Backup {
32 class Service;
33 class SvcSessionManager;
34 
35 class SchedScheduler final : public virtual RefBase {
36 public:
37     /**
38      * @brief 给threadPool下发任务
39      *
40      */
41     void Sched(std::string bundleName = "");
42 
43     /**
44      * @brief 执行队列任务
45      *
46      * @param bundleName
47      */
48     void ExecutingQueueTasks(const std::string &bundleName);
49 
50     /**
51      * @brief 移除定时器信息
52      *
53      * @param bundleName 应用名称
54      */
55     void RemoveExtConn(const std::string &bundleName);
56 
57     /**
58      * @brief try unload service timer
59      *
60      */
61     void TryUnloadServiceTimer(bool force = false);
62 
63     /**
64      * @brief clear scheduler data
65      *
66      */
67     void ClearSchedulerData();
68 
69     /**
70      * @brief unload service
71      *
72      */
73     void TryUnloadService();
74 
75     void StartTimer();
76 
77     void StartExecuteBundleTask(const std::string &bundleName, BConstants::ServiceSchedAction action);
78 
79 public:
SchedScheduler(wptr<Service> reversePtr,wptr<SvcSessionManager> sessionPtr)80     explicit SchedScheduler(wptr<Service> reversePtr, wptr<SvcSessionManager> sessionPtr)
81         : reversePtr_(reversePtr), sessionPtr_(sessionPtr)
82     {
83         threadPool_.Start(BConstants::SA_THREAD_POOL_COUNT);
84     }
85 
~SchedScheduler()86     ~SchedScheduler() override
87     {
88         extTime_.Shutdown();
89         bundleTimeVec_.clear();
90     }
91 
92 private:
93     mutable std::shared_mutex lock_;
94     OHOS::ThreadPool threadPool_;
95 
96     // 注册心跳信息
97     std::vector<std::tuple<std::string, uint32_t>> bundleTimeVec_;
98 
99     wptr<Service> reversePtr_;
100     wptr<SvcSessionManager> sessionPtr_;
101     Utils::Timer extTime_ {"backupSchedTimer"};
102 };
103 } // namespace OHOS::FileManagement::Backup
104 
105 #endif // OHOS_FILEMGMT_BACKUP_SCHED_SCHEDULER_H
106