1 /* 2 * Copyright (c) 2022 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 JS_OBJECT_WRAPPER_H 17 #define JS_OBJECT_WRAPPER_H 18 19 #include "js_watcher.h" 20 21 namespace OHOS::ObjectStore { 22 class JSObjectWrapper { 23 public: 24 JSObjectWrapper(DistributedObjectStore *objectStore, DistributedObject *object); 25 virtual ~JSObjectWrapper(); 26 DistributedObject *GetObject(); 27 bool AddWatch(napi_env env, const char *type, napi_value handler); 28 void DeleteWatch(napi_env env, const char *type, napi_value handler = nullptr); 29 bool IsUndefined(const char *value); 30 void AddUndefined(const char *value); 31 void DeleteUndefined(const char *value); 32 void DestroyObject(); 33 void SetObjectId(const std::string &objectId); 34 std::string GetObjectId(); 35 36 private: 37 DistributedObjectStore *objectStore_ = nullptr; 38 DistributedObject *object_ = nullptr; 39 std::shared_ptr<JSWatcher> watcher_ = nullptr; 40 std::shared_mutex watchMutex_{}; 41 std::mutex mutex_; 42 std::vector<std::string> undefinedProperties_; 43 std::string objectId_; 44 }; 45 } // namespace OHOS::ObjectStore 46 47 #endif 48