1 /* 2 * Copyright (c) 2023 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 #ifndef NAPI_IPC_OHOS_REMOTE_OBJECT_H 16 #define NAPI_IPC_OHOS_REMOTE_OBJECT_H 17 18 #include "iremote_object.h" 19 #include "napi/native_api.h" 20 #include "refbase.h" 21 22 namespace OHOS { 23 // Description of caller information parameters. 24 struct CallingInfo { 25 pid_t callingPid; 26 pid_t callingUid; 27 uint32_t callingTokenId; 28 std::string callingDeviceID; 29 std::string localDeviceID; 30 bool isLocalCalling; 31 int activeStatus; 32 }; 33 34 // NAPI caller information parameter description. 35 struct NAPI_CallingInfo { 36 napi_value callingPid; 37 napi_value callingUid; 38 napi_value callingTokenId; 39 napi_value callingDeviceID; 40 napi_value localDeviceID; 41 napi_value isLocalCalling; 42 napi_value activeStatus; 43 }; 44 45 EXTERN_C_START 46 47 /** 48 * @brief Export NAPIRemote object. 49 * @param env Indicates the environment in which NAPI is called. 50 * @param exports Indicates the NAPI exporter. 51 * @return Returns the exporter of NAPI. 52 * @since 9 53 */ 54 napi_value NAPIRemoteObjectExport(napi_env env, napi_value exports); 55 EXTERN_C_END 56 57 /** 58 * @brief Create a JavaScript proxy object. 59 * @param env Indicates the environment in which NAPI is called. 60 * @param target Indicates the IRemoteObject pointer object. 61 * @return Returns the created proxy object. 62 * @since 9 63 */ 64 napi_value NAPI_ohos_rpc_CreateJsRemoteObject(napi_env env, const sptr<IRemoteObject> target); 65 66 /** 67 * @brief Clear native proxy object that associated with js object. 68 * @param env Indicates the environment in which NAPI is called. 69 * @param jsRemoteProxy Indicates the js object(the associated native object will be cleared). 70 * @return Returns <b>true</b> if the operation succeeds; return <b>false</b> Otherwise. 71 * @since 12 72 */ 73 bool NAPI_ohos_rpc_ClearNativeRemoteProxy(napi_env env, napi_value jsRemoteProxy); 74 75 /** 76 * @brief Get a native remote object. 77 * @param env Indicates the environment in which NAPI is called. 78 * @param object Indicates the object obtained. 79 * @return Returns the IRemoteObject point object. 80 * @since 9 81 */ 82 sptr<IRemoteObject> NAPI_ohos_rpc_getNativeRemoteObject(napi_env env, napi_value object); 83 84 /** 85 * @brief Gets remote proxy object caller information. 86 * @param newCallingInfoParam Indicates the caller information. 87 * @return void 88 * @since 9 89 */ 90 void NAPI_RemoteObject_getCallingInfo(CallingInfo &newCallingInfoParam); 91 92 /** 93 * @brief Saves caller information for the old remote proxy object. 94 * @param env Indicates the environment in which NAPI is called. 95 * @param oldCallingInfo Indicates the old caller information. 96 * @return void 97 * @since 9 98 */ 99 void NAPI_RemoteObject_saveOldCallingInfo(napi_env env, NAPI_CallingInfo &oldCallingInfo); 100 101 /** 102 * @brief Sats caller information for the new remote proxy object. 103 * @param env Indicates the environment in which NAPI is called. 104 * @param newCallingInfoParam Indicates the new caller information. 105 * @return void 106 * @since 9 107 */ 108 void NAPI_RemoteObject_setNewCallingInfo(napi_env env, const CallingInfo &newCallingInfoParam); 109 110 /** 111 * @brief Resets caller information for the old remote proxy object. 112 * @param env Indicates the environment in which NAPI is called. 113 * @param oldCallingInfo Indicates the old caller information. 114 * @return void 115 * @since 9 116 */ 117 void NAPI_RemoteObject_resetOldCallingInfo(napi_env env, NAPI_CallingInfo &oldCallingInfo); 118 } 119 #endif