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 
16 #ifndef OHOS_ABILITY_RUNTIME_JSUI_SERVICE_PROXY_H
17 #define OHOS_ABILITY_RUNTIME_JSUI_SERVICE_PROXY_H
18 
19 #include <memory>
20 
21 #include "ui_service_proxy.h"
22 #include "js_runtime_utils.h"
23 
24 namespace OHOS {
25 namespace AAFwk {
26 using namespace AbilityRuntime;
27 
28 class JsUIServiceProxy {
29 public:
30     static napi_value CreateJsUIServiceProxy(napi_env env, const sptr<IRemoteObject>& impl,
31         int64_t connectionId, const sptr<IRemoteObject>& hostProxy);
32     static void Finalizer(napi_env env, void* data, void* hint);
33 
34     JsUIServiceProxy(const sptr<IRemoteObject>& impl, const sptr<IRemoteObject>& hostProxy);
35     virtual ~JsUIServiceProxy();
36 
SetConnectionId(int64_t id)37     void SetConnectionId(int64_t id) { connectionId_ = id; }
GetConnectionId()38     int64_t GetConnectionId() { return connectionId_; }
39 private:
40     static napi_value SendData(napi_env env, napi_callback_info info);
41     napi_value OnSendData(napi_env env, NapiCallbackInfo& info);
42 
43 protected:
44     sptr<OHOS::AAFwk::IUIService> proxy_ = nullptr;
45     int64_t connectionId_ = 0;
46     sptr<IRemoteObject> hostProxy_ = nullptr;
47 };
48 
49 } // namespace AAFwk
50 } // namespace OHOS
51 #endif //OHOS_ABILITY_RUNTIME_JSUI_SERVICE_PROXY_H