18bf80f4bSopenharmony_ci/*
28bf80f4bSopenharmony_ci * Copyright (C) 2024 Huawei Device Co., Ltd.
38bf80f4bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
48bf80f4bSopenharmony_ci * you may not use this file except in compliance with the License.
58bf80f4bSopenharmony_ci * You may obtain a copy of the License at
68bf80f4bSopenharmony_ci *
78bf80f4bSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
88bf80f4bSopenharmony_ci *
98bf80f4bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
108bf80f4bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
118bf80f4bSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
128bf80f4bSopenharmony_ci * See the License for the specific language governing permissions and
138bf80f4bSopenharmony_ci * limitations under the License.
148bf80f4bSopenharmony_ci */
158bf80f4bSopenharmony_ci
168bf80f4bSopenharmony_ci#ifndef OHOS_RENDER_3D_PROPERTY_PROXY_H
178bf80f4bSopenharmony_ci#define OHOS_RENDER_3D_PROPERTY_PROXY_H
188bf80f4bSopenharmony_ci#include <meta/interface/intf_event.h>
198bf80f4bSopenharmony_ci#include <meta/interface/intf_task_queue.h>
208bf80f4bSopenharmony_ci#include <meta/interface/property/intf_property.h>
218bf80f4bSopenharmony_ci#include <meta/interface/property/property_events.h>
228bf80f4bSopenharmony_ci#include <napi_api.h>
238bf80f4bSopenharmony_ci
248bf80f4bSopenharmony_ci#include <base/containers/string.h>
258bf80f4bSopenharmony_ci#include <base/containers/string_view.h>
268bf80f4bSopenharmony_ci#include <base/containers/vector.h>
278bf80f4bSopenharmony_ci
288bf80f4bSopenharmony_ciclass PropertyProxy {
298bf80f4bSopenharmony_ci    BASE_NS::vector<class PropCtx*> accessors;
308bf80f4bSopenharmony_ci
318bf80f4bSopenharmony_ciprotected:
328bf80f4bSopenharmony_ci    CORE_NS::SpinLock duh;
338bf80f4bSopenharmony_ci    META_NS::IProperty::Ptr prop_;
348bf80f4bSopenharmony_ci    NapiApi::StrongRef obj;
358bf80f4bSopenharmony_ci    void Create(napi_env env, const BASE_NS::string jsName);
368bf80f4bSopenharmony_ci    void Hook(const BASE_NS::string member);
378bf80f4bSopenharmony_ci    META_NS::IOnChanged::InterfaceTypePtr changeHandler_;
388bf80f4bSopenharmony_ci    META_NS::IEvent::Token changeToken_;
398bf80f4bSopenharmony_ci    META_NS::ITaskQueueTask::Ptr updateTask_;
408bf80f4bSopenharmony_ci    META_NS::ITaskQueue::Token updateToken_ { nullptr };
418bf80f4bSopenharmony_ci    virtual void UpdateLocalValues() = 0;
428bf80f4bSopenharmony_ci    virtual void UpdateRemoteValues() = 0;
438bf80f4bSopenharmony_ci    void UpdateLocal();
448bf80f4bSopenharmony_ci    int32_t UpdateRemote();
458bf80f4bSopenharmony_ci    void ScheduleUpdate();
468bf80f4bSopenharmony_ci
478bf80f4bSopenharmony_ci    // synchronized get value.
488bf80f4bSopenharmony_ci    void SyncGet();
498bf80f4bSopenharmony_ci    BASE_NS::string name_;
508bf80f4bSopenharmony_cipublic:
518bf80f4bSopenharmony_ci    operator napi_value();
528bf80f4bSopenharmony_ci    explicit PropertyProxy(META_NS::IProperty::Ptr prop);
538bf80f4bSopenharmony_ci    virtual ~PropertyProxy();
548bf80f4bSopenharmony_ci
558bf80f4bSopenharmony_ci    // copy data from jsobject
568bf80f4bSopenharmony_ci    virtual bool SetValue(NapiApi::Object data) = 0;
578bf80f4bSopenharmony_ci    NapiApi::Value<NapiApi::Object> Value();
588bf80f4bSopenharmony_ci    virtual void SetValue(NapiApi::FunctionContext<>& info, BASE_NS::string_view memb) = 0;
598bf80f4bSopenharmony_ci    virtual napi_value GetValue(NapiApi::FunctionContext<>& info, BASE_NS::string_view memb) = 0;
608bf80f4bSopenharmony_ci    const META_NS::IProperty::Ptr& GetProperty() const;
618bf80f4bSopenharmony_ci};
628bf80f4bSopenharmony_ci#endif // OHOS_RENDER_3D_PROPERTY_PROXY_H
63