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