1 /*
2 * Copyright (c) 2025 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 DATASHARESERVICE_HIVIEW_BASE_ADAPTER_H
17 #define DATASHARESERVICE_HIVIEW_BASE_ADAPTER_H
18 
19 #include <cinttypes>
20 
21 #include "executor_pool.h"
22 #include "hisysevent_c.h"
23 
24 namespace OHOS {
25 namespace DataShare {
26 
27 class HiViewBaseAdapter {
28 public:
29     const int waitTime = 180 * 60;
30     std::shared_ptr<ExecutorPool> executors_ = nullptr;
31     std::atomic<bool> running_ = false;
32 
SetThreadPool(std::shared_ptr<ExecutorPool> executors)33     void SetThreadPool(std::shared_ptr<ExecutorPool> executors)
34     {
35         executors_ = executors;
36         StartTimerThread();
37     }
38 
StartTimerThread()39     void StartTimerThread()
40     {
41         if (executors_ == nullptr) {
42             return;
43         }
44         if (running_.exchange(true)) {
45             return;
46         }
47         auto interval = std::chrono::seconds(waitTime);
48         auto fun = [this]() { InvokeData(); };
49         executors_->Schedule(fun, interval);
50     }
51 
52     virtual void InvokeData() = 0;
53 };
54 }
55 }
56 #endif // DATASHARESERVICE_HIVIEW_ADAPTER_H