1 /* 2 * Copyright (c) 2024 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 OHOS_DISTRIBUTED_DATA_GDB_JS_NAPI_GDB_STORE_H 16 #define OHOS_DISTRIBUTED_DATA_GDB_JS_NAPI_GDB_STORE_H 17 18 #include <functional> 19 #include <list> 20 #include <memory> 21 #include <mutex> 22 23 #include "gdb_store.h" 24 #include "js_proxy.h" 25 #include "js_uv_queue.h" 26 #include "napi/native_api.h" 27 #include "napi/native_common.h" 28 #include "napi/native_node_api.h" 29 30 namespace OHOS::GraphStoreJsKit { 31 using namespace DistributedDataAip; 32 #define ASSERT_CALL(env, theCall, object) \ 33 do { \ 34 if ((theCall) != napi_ok) { \ 35 delete (object); \ 36 GET_AND_THROW_LAST_ERROR((env)); \ 37 return nullptr; \ 38 } \ 39 } while (0) 40 41 using Descriptor = std::function<std::vector<napi_property_descriptor>(void)>; 42 class GdbStoreProxy : public GraphStoreJsKit::JSProxy<DBStore> { 43 public: 44 static void Init(napi_env env, napi_value exports); 45 static napi_value NewInstance(napi_env env, std::shared_ptr<DBStore> value, bool isSystemAppCalled); 46 GdbStoreProxy(); 47 ~GdbStoreProxy(); 48 GdbStoreProxy(std::shared_ptr<DBStore> gdbStore); 49 GdbStoreProxy &operator=(std::shared_ptr<DBStore> GdbStore); 50 bool IsSystemAppCalled(); 51 static constexpr int32_t MAX_GQL_LEN = 1024 * 1024; 52 53 private: 54 static napi_value Initialize(napi_env env, napi_callback_info info); 55 static napi_value Read(napi_env env, napi_callback_info info); 56 static napi_value Write(napi_env env, napi_callback_info info); 57 static napi_value CreateTransaction(napi_env env, napi_callback_info info); 58 static napi_value Close(napi_env env, napi_callback_info info); 59 60 static Descriptor GetDescriptors(); 61 62 static napi_value New(napi_env env, napi_callback_info info); 63 static void Destructor(napi_env env, void *nativeObject, void *finalize_hint); 64 65 bool isSystemAppCalled_ = false; 66 std::shared_ptr<AppDataMgrJsKit::UvQueue> queue_; 67 }; 68 } // namespace OHOS::GraphStoreJsKit 69 #endif