1 /* 2 * Copyright (c) 2022-2023 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 install success 59 * 60 * @param bundleName 61 * @param resultCode 62 */ 63 void InstallSuccess(const std::string &bundleName, const int32_t resultCode); 64 65 /** 66 * @brief try unload service timer 67 * 68 */ 69 void TryUnloadServiceTimer(bool force = false); 70 StartTimer()71 void StartTimer() 72 { 73 extTime_.Setup(); 74 TryUnloadServiceTimer(); 75 } 76 77 public: SchedScheduler(wptr<Service> reversePtr,wptr<SvcSessionManager> sessionPtr)78 explicit SchedScheduler(wptr<Service> reversePtr, wptr<SvcSessionManager> sessionPtr) 79 : reversePtr_(reversePtr), sessionPtr_(sessionPtr) 80 { 81 threadPool_.Start(BConstants::SA_THREAD_POOL_COUNT); 82 } 83 ~SchedScheduler()84 ~SchedScheduler() override 85 { 86 extTime_.Shutdown(); 87 reversePtr_ = nullptr; 88 sessionPtr_ = nullptr; 89 bundleTimeVec_.clear(); 90 } 91 92 private: 93 /** 94 * @brief install state 95 * 96 * @param bundleName 97 */ 98 void InstallingState(const std::string &bundleName); 99 100 private: 101 mutable std::shared_mutex lock_; 102 OHOS::ThreadPool threadPool_; 103 104 // 注册心跳信息 105 std::vector<std::tuple<std::string, uint32_t>> bundleTimeVec_; 106 107 wptr<Service> reversePtr_; 108 wptr<SvcSessionManager> sessionPtr_; 109 Utils::Timer extTime_ {"backupSchedTimer"}; 110 }; 111 } // namespace OHOS::FileManagement::Backup 112 113 #endif // OHOS_FILEMGMT_BACKUP_SCHED_SCHEDULER_H 114