• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 SCHEDULER_MANAGER_H
17 #define SCHEDULER_MANAGER_H
18 
19 #include <memory>
20 
21 #include "db_delegate.h"
22 #include "executor_pool.h"
23 #include "subscriber_managers/rdb_subscriber_manager.h"
24 
25 namespace OHOS::DataShare {
26 class SchedulerManager {
27 public:
28     static SchedulerManager &GetInstance();
29     void Execute(const std::string &uri, const int32_t userId, const std::string &rdbDir, int version);
30     void Execute(const Key &key, const int32_t userId, const std::string &rdbDir, int version);
31     void ReExecuteAll();
32     void SetTimer(const std::string &dbPath, const int32_t userId, int version, const Key &key, int64_t reminderTime);
33     void RemoveTimer(const Key &key);
34     void ClearTimer();
35     void SetExecutorPool(std::shared_ptr<ExecutorPool> executor);
36 
37 private:
38     static constexpr const char *REMIND_TIMER_FUNC = "remindTimer(";
39     static constexpr int REMIND_TIMER_FUNC_LEN = 12;
40     SchedulerManager() = default;
41     ~SchedulerManager() = default;
42     static void GenRemindTimerFuncParams(const std::string &rdbDir, const int32_t userId, int version, const Key &key,
43         std::string &schedulerSQL);
44     void ExecuteSchedulerSQL(const std::string &rdbDir, const int32_t userId, int version, const Key &key,
45         std::shared_ptr<DBDelegate> delegate);
46 
47     std::mutex mutex_;
48     std::map<Key, Executor::TaskId> timerCache_;
49     std::shared_ptr<ExecutorPool> executor_ = nullptr;
50 };
51 } // namespace OHOS::DataShare
52 #endif // SCHEDULER_MANAGER_H
53