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 #ifndef RDB_JSKIT_NAPI_RDB_STATISTICS_OBSERVER_H 16 #define RDB_JSKIT_NAPI_RDB_STATISTICS_OBSERVER_H 17 #include <memory> 18 19 #include "js_uv_queue.h" 20 #include "napi/native_api.h" 21 #include "napi/native_common.h" 22 #include "napi/native_node_api.h" 23 #include "rdb_types.h" 24 25 namespace OHOS { 26 namespace RelationalStoreJsKit { 27 class NapiStatisticsObserver 28 : public DistributedRdb::SqlObserver, public std::enable_shared_from_this<NapiStatisticsObserver> { 29 public: 30 NapiStatisticsObserver(napi_env env, napi_value callback, std::shared_ptr<AppDataMgrJsKit::UvQueue> uvQueue); 31 virtual ~NapiStatisticsObserver(); 32 void Clear(); 33 bool operator==(napi_value value); 34 void OnStatistic(const SqlExecutionInfo &sqlExeInfo) override; 35 36 private: 37 napi_env env_ = nullptr; 38 napi_ref callback_ = nullptr; 39 std::shared_ptr<AppDataMgrJsKit::UvQueue> queue_ = nullptr; 40 }; 41 42 class NapiPerfStatObserver 43 : public DistributedRdb::SqlObserver, public std::enable_shared_from_this<NapiPerfStatObserver> { 44 public: 45 NapiPerfStatObserver(napi_env env, napi_value callback, std::shared_ptr<AppDataMgrJsKit::UvQueue> uvQueue); 46 virtual ~NapiPerfStatObserver(); 47 void Clear(); 48 bool operator==(napi_value value); 49 void OnStatistic(const SqlExecutionInfo &sqlExeInfo) override; 50 51 private: 52 napi_env env_ = nullptr; 53 napi_ref callback_ = nullptr; 54 std::shared_ptr<AppDataMgrJsKit::UvQueue> queue_ = nullptr; 55 }; 56 } // namespace RelationalStoreJsKit 57 } // namespace OHOS 58 #endif //RDB_JSKIT_NAPI_RDB_STATISTICS_OBSERVER_H 59