1 /* 2 * Copyright (c) 2021 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 NAPI_IPC_OHOS_REMOTE_OBJECT_H 17 #define NAPI_IPC_OHOS_REMOTE_OBJECT_H 18 19 #include "iremote_object.h" 20 #include "napi/native_api.h" 21 #include "napi/native_node_api.h" 22 #include "refbase.h" 23 24 constexpr size_t TRACESIZE = 64; 25 namespace OHOS { 26 EXTERN_C_START 27 napi_value NAPIIPCSkeletonExport(napi_env env, napi_value exports); 28 napi_value NAPIRemoteProxyExport(napi_env env, napi_value exports); 29 napi_value NAPIRemoteObjectExport(napi_env env, napi_value exports); 30 napi_value NAPIMessageOptionExport(napi_env env, napi_value exports); 31 EXTERN_C_END 32 33 // IPCSkeleton napi methods 34 napi_value NAPI_IPCSkeleton_getContextObject(napi_env env, napi_callback_info info); 35 36 napi_value NAPI_IPCSkeleton_getCallingPid(napi_env env, napi_callback_info info); 37 38 napi_value NAPI_IPCSkeleton_getCallingUid(napi_env env, napi_callback_info info); 39 40 napi_value NAPI_IPCSkeleton_getCallingDeviceID(napi_env env, napi_callback_info info); 41 42 napi_value NAPI_IPCSkeleton_getLocalDeviceID(napi_env env, napi_callback_info info); 43 44 napi_value NAPI_IPCSkeleton_isLocalCalling(napi_env env, napi_callback_info info); 45 46 napi_value NAPI_IPCSkeleton_flushCommands(napi_env env, napi_callback_info info); 47 48 napi_value NAPI_IPCSkeleton_resetCallingIdentity(napi_env env, napi_callback_info info); 49 50 napi_value NAPI_IPCSkeleton_setCallingIdentity(napi_env env, napi_callback_info info); 51 52 napi_value NAPI_IPCSkeleton_getCallingTokenId(napi_env env, napi_callback_info info); 53 54 // RemoteObject napi methods 55 napi_value NAPI_RemoteObject_sendRequest(napi_env env, napi_callback_info info); 56 57 napi_value NAPI_RemoteObject_getCallingPid(napi_env env, napi_callback_info info); 58 59 napi_value NAPI_RemoteObject_getCallingUid(napi_env env, napi_callback_info info); 60 61 napi_value NAPI_RemoteObject_getInterfaceDescriptor(napi_env env, napi_callback_info info); 62 63 napi_value NAPI_RemoteObject_attachLocalInterface(napi_env env, napi_callback_info info); 64 65 napi_value NAPI_RemoteObject_queryLocalInterface(napi_env env, napi_callback_info info); 66 67 napi_value NAPI_RemoteObject_addDeathRecipient(napi_env env, napi_callback_info info); 68 69 napi_value NAPI_RemoteObject_removeDeathRecipient(napi_env env, napi_callback_info info); 70 71 napi_value NAPI_RemoteObject_isObjectDead(napi_env env, napi_callback_info info); 72 73 // RemoteProxy napi methods 74 napi_value NAPI_RemoteProxy_sendRequest(napi_env env, napi_callback_info info); 75 76 napi_value NAPI_RemoteProxy_queryLocalInterface(napi_env env, napi_callback_info info); 77 78 napi_value NAPI_RemoteProxy_addDeathRecipient(napi_env env, napi_callback_info info); 79 80 napi_value NAPI_RemoteProxy_removeDeathRecipient(napi_env env, napi_callback_info info); 81 82 napi_value NAPI_RemoteProxy_getInterfaceDescriptor(napi_env env, napi_callback_info info); 83 84 napi_value NAPI_RemoteProxy_isObjectDead(napi_env env, napi_callback_info info); 85 86 sptr<IRemoteObject> NAPI_ohos_rpc_getNativeRemoteObject(napi_env env, napi_value object); 87 88 napi_value NAPI_ohos_rpc_CreateJsRemoteObject(napi_env env, const sptr<IRemoteObject> target); 89 90 struct SendRequestParam { 91 sptr<IRemoteObject> target; 92 uint32_t code; 93 std::shared_ptr<MessageParcel> data; 94 std::shared_ptr<MessageParcel> reply; 95 MessageOption &option; 96 napi_async_work asyncWork; 97 napi_deferred deferred; 98 int errCode; 99 napi_ref jsCodeRef; 100 napi_ref jsDataRef; 101 napi_ref jsReplyRef; 102 napi_ref callback; 103 napi_env env; 104 }; 105 } // namespace OHOS 106 #endif // NAPI_IPC_OHOS_REMOTE_OBJECT_H 107