• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 OHOS_DISTRIBUTED_DATA_RELATIONAL_STORE_FRAMEWORKS_NATIVE_RDB_SQL_LOG_H
17 #define OHOS_DISTRIBUTED_DATA_RELATIONAL_STORE_FRAMEWORKS_NATIVE_RDB_SQL_LOG_H
18 #include <set>
19 #include <string>
20 #include <shared_mutex>
21 #include <memory>
22 
23 #include "rdb_types.h"
24 #include "rdb_visibility.h"
25 
26 namespace OHOS {
27 template<typename _Key, typename _Tp>
28 class ConcurrentMap;
29 namespace NativeRdb {
30 using ExceptionMessage = DistributedRdb::SqlErrorObserver::ExceptionMessage;
31 using SqlErrorObserver = DistributedRdb::SqlErrorObserver;
32 class SqlLog {
33 public:
34     SqlLog();
35     ~SqlLog();
36     API_EXPORT static int Subscribe(const std::string storeId, std::shared_ptr<SqlErrorObserver> observer);
37     API_EXPORT static int Unsubscribe(const std::string storeId, std::shared_ptr<SqlErrorObserver> observer);
38     static void Notify(const std::string &storeId, const ExceptionMessage &exceptionMessage);
39     static void Pause();
40     static void Resume();
41 private:
42     static bool IsPause();
43     static ConcurrentMap<std::string, std::set<std::shared_ptr<SqlErrorObserver>>> observerSets_;
44     static std::atomic<bool> enabled_;
45     static std::shared_mutex mutex_;
46     static std::map<uint64_t, int32_t> suspenders_;
47 };
48 } // namespace NativeRdb
49 } // namespace OHOS
50 #endif // OHOS_DISTRIBUTED_DATA_RELATIONAL_STORE_FRAMEWORKS_NATIVE_RDB_SQL_LOG_H
51