• 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 NATIVE_RDB_DELAY_NOTIFY_H
17 #define NATIVE_RDB_DELAY_NOTIFY_H
18 #include <map>
19 #include <string>
20 #include <functional>
21 #include <memory>
22 #include "rdb_types.h"
23 #include "executor_pool.h"
24 namespace OHOS::NativeRdb {
25 class DelayNotify {
26 public:
27     using Task = std::function<int(const DistributedRdb::RdbChangedData &)>;
28     ~DelayNotify();
29     void SetExecutorPool(std::shared_ptr<ExecutorPool> pool);
30     void SetTask(Task task);
31     void UpdateNotify(const DistributedRdb::RdbChangedData &changedData);
32     void SetAutoSyncInterval(uint32_t autoSyncInterval);
33 private:
34     static constexpr uint32_t AUTO_SYNC_INTERVAL = 200;
35     ExecutorPool::TaskId delaySyncTaskId_ = ExecutorPool::INVALID_TASK_ID;
36     Task task_;
37     std::shared_ptr<ExecutorPool> pool_ = nullptr;
38     std::mutex mutex_;
39     DistributedRdb::RdbChangedData changedData_;
40 
41     void StartTimer();
42     void StopTimer();
43     void ExecuteTask();
44     void RestoreDefaultSyncInterval();
45     uint32_t autoSyncInterval_ = AUTO_SYNC_INTERVAL;
46 };
47 }
48 #endif // NATIVE_RDB_DELAY_NOTIFY_H