From 8e649860d3f44ac182b63479323ee75744ce29c3 Mon Sep 17 00:00:00 2001 From: hanlin15 Date: Mon, 28 Jul 2025 16:23:00 +0800 Subject: [PATCH] fix:add some interface impl2 Signed-off-by: hanlin15 --- ipc/native/src/taihe/inc/rpc_taihe_error.h | 85 ++++++++++++ .../src/taihe/inc/taihe_ani_remote_object.h | 52 +++++++ ipc/native/src/taihe/inc/taihe_ashmem.h | 60 ++++++++ .../src/taihe/inc/taihe_deathrecipient.h | 49 +++++++ ipc/native/src/taihe/inc/taihe_ipc_skeleton.h | 45 ++++++ .../src/taihe/inc/taihe_iremote_broker.h | 39 ++++++ .../src/taihe/inc/taihe_message_option.h | 57 ++++++++ .../src/taihe/inc/taihe_message_sequence.h | 128 ++++++++++++++++++ ipc/native/src/taihe/inc/taihe_parcelable.h | 40 ++++++ .../src/taihe/inc/taihe_remote_object.h | 86 ++++++++++++ ipc/native/src/taihe/inc/taihe_remote_proxy.h | 65 +++++++++ 11 files changed, 706 insertions(+) create mode 100644 ipc/native/src/taihe/inc/rpc_taihe_error.h create mode 100644 ipc/native/src/taihe/inc/taihe_ani_remote_object.h create mode 100644 ipc/native/src/taihe/inc/taihe_ashmem.h create mode 100644 ipc/native/src/taihe/inc/taihe_deathrecipient.h create mode 100644 ipc/native/src/taihe/inc/taihe_ipc_skeleton.h create mode 100644 ipc/native/src/taihe/inc/taihe_iremote_broker.h create mode 100644 ipc/native/src/taihe/inc/taihe_message_option.h create mode 100644 ipc/native/src/taihe/inc/taihe_message_sequence.h create mode 100644 ipc/native/src/taihe/inc/taihe_parcelable.h create mode 100644 ipc/native/src/taihe/inc/taihe_remote_object.h create mode 100644 ipc/native/src/taihe/inc/taihe_remote_proxy.h diff --git a/ipc/native/src/taihe/inc/rpc_taihe_error.h b/ipc/native/src/taihe/inc/rpc_taihe_error.h new file mode 100644 index 00000000..f1f248d9 --- /dev/null +++ b/ipc/native/src/taihe/inc/rpc_taihe_error.h @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_TAIHE_ERROR_H +#define OHOS_TAIHE_ERROR_H + +#include +#include + +namespace OHOS { +enum RpcTaiheErrorCode { + CHECK_PARAM_ERROR, + OS_MMAP_ERROR, + OS_IOCTL_ERROR, + WRITE_TO_ASHMEM_ERROR, + READ_FROM_ASHMEM_ERROR, + ONLY_PROXY_OBJECT_PERMITTED_ERROR, + ONLY_REMOTE_OBJECT_PERMITTED_ERROR, + COMMUNICATION_ERROR, + PROXY_OR_REMOTE_OBJECT_INVALID_ERROR, + WRITE_DATA_TO_MESSAGE_SEQUENCE_ERROR, + READ_DATA_FROM_MESSAGE_SEQUENCE_ERROR, + PARCEL_MEMORY_ALLOC_ERROR, + CALL_JS_METHOD_ERROR, + OS_DUP_ERROR +}; + +struct RpcTaiheErrorInfo { + int errorCode; + std::string errorMsg; +}; + +#define RPC_TAIHE_ERROR(error_code) \ + do { \ + taihe::set_business_error( \ + OHOS::RpcTaiheError::Convert(error_code), \ + OHOS::RpcTaiheError::ToMessage(error_code)); \ + return; \ + } while (0) + +#define RPC_TAIHE_ERROR_WITH_RETVAL(error_code, retVal) \ + do { \ + taihe::set_business_error( \ + OHOS::RpcTaiheError::Convert(error_code), \ + OHOS::RpcTaiheError::ToMessage(error_code)); \ + return retVal; \ + } while (0) + +const std::map RPC_TAIHE_ERR_MAP { + { CHECK_PARAM_ERROR, { 401, "check param error" } }, + { OS_MMAP_ERROR, { 1900001, "os mmap function failed" } }, + { OS_IOCTL_ERROR, { 1900002, "os ioctl function failed" } }, + { WRITE_TO_ASHMEM_ERROR, { 1900003, "write to ashmem failed" } }, + { READ_FROM_ASHMEM_ERROR, { 1900004, "read from ashmem failed" } }, + { ONLY_PROXY_OBJECT_PERMITTED_ERROR, { 1900005, "only proxy object permitted" } }, + { ONLY_REMOTE_OBJECT_PERMITTED_ERROR, { 1900006, "only remote object permitted" } }, + { COMMUNICATION_ERROR, { 1900007, "communication failed" } }, + { PROXY_OR_REMOTE_OBJECT_INVALID_ERROR, { 1900008, "proxy or remote object is invalid" } }, + { WRITE_DATA_TO_MESSAGE_SEQUENCE_ERROR, { 1900009, "write data to message sequence failed" } }, + { READ_DATA_FROM_MESSAGE_SEQUENCE_ERROR, { 1900010, "read data from message sequence failed" } }, + { PARCEL_MEMORY_ALLOC_ERROR, { 1900011, "parcel memory alloc failed" } }, + { CALL_JS_METHOD_ERROR, { 1900012, "call js method failed" } }, + { OS_DUP_ERROR, { 1900013, "os dup function failed" } } +}; + +class RpcTaiheError { +public: + static int32_t Convert(const int errCode); + static std::string ToMessage(const int errCode); +}; +} + +#endif // OHOS_TAIHE_ERROR_H \ No newline at end of file diff --git a/ipc/native/src/taihe/inc/taihe_ani_remote_object.h b/ipc/native/src/taihe/inc/taihe_ani_remote_object.h new file mode 100644 index 00000000..011b2486 --- /dev/null +++ b/ipc/native/src/taihe/inc/taihe_ani_remote_object.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_IPC_TAIHE_ANI_REMOTE_OBJECT_H +#define OHOS_IPC_TAIHE_ANI_REMOTE_OBJECT_H + +#include "ohos.rpc.rpc.proj.hpp" +#include "ohos.rpc.rpc.impl.hpp" +#include "taihe/runtime.hpp" +#include "stdexcept" + +#include +#include +#include +#include +#include + +#include "message_parcel.h" +#include "ipc_object_stub.h" + +namespace OHOS { + +class ANIRemoteObject : public OHOS::IPCObjectStub { +public: + ANIRemoteObject(const std::u16string &descriptor, ::ohos::rpc::rpc::weak::RemoteObject jsObj); + ~ANIRemoteObject(); + + int OnRemoteRequest(uint32_t code, OHOS::MessageParcel &data, OHOS::MessageParcel &reply, + OHOS::MessageOption &option) override; + + int GetObjectType() const override; + + ::ohos::rpc::rpc::RemoteObject GetJsObject(); + +private: + std::optional<::ohos::rpc::rpc::RemoteObject> jsObjRef_; +}; +} // namespace + +#endif // OHOS_IPC_TAIHE_ANI_REMOTE_OBJECT_H \ No newline at end of file diff --git a/ipc/native/src/taihe/inc/taihe_ashmem.h b/ipc/native/src/taihe/inc/taihe_ashmem.h new file mode 100644 index 00000000..851f3645 --- /dev/null +++ b/ipc/native/src/taihe/inc/taihe_ashmem.h @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_IPC_TAIHE_ASHMEM_H +#define OHOS_IPC_TAIHE_ASHMEM_H + +#include "ohos.rpc.rpc.proj.hpp" +#include "ohos.rpc.rpc.impl.hpp" +#include "taihe/runtime.hpp" +#include "stdexcept" + +#include +#include +#include +#include +#include + +#include "ashmem.h" + +namespace OHOS { + +class AshmemImpl { +public: + // only be used for returning invalid Ashmem. + explicit AshmemImpl(); + + explicit AshmemImpl(const char *name, int32_t size); + + explicit AshmemImpl(OHOS::sptr ashmem); + + int64_t GetNativePtr(); + + void MapReadWriteAshmem(); + + int32_t GetAshmemSize(); + + OHOS::sptr GetAshmem(); + + static ::ohos::rpc::rpc::Ashmem CreateAshmem_WithTwoParam(::taihe::string_view name, int32_t size); + static ::ohos::rpc::rpc::Ashmem CreateAshmem_WithOneParam(::ohos::rpc::rpc::weak::Ashmem ashmem); + +private: + OHOS::sptr ashmem_ = nullptr; +}; + +} // namespace + +#endif // OHOS_IPC_TAIHE_ASHMEM_H \ No newline at end of file diff --git a/ipc/native/src/taihe/inc/taihe_deathrecipient.h b/ipc/native/src/taihe/inc/taihe_deathrecipient.h new file mode 100644 index 00000000..9ce31a55 --- /dev/null +++ b/ipc/native/src/taihe/inc/taihe_deathrecipient.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_IPC_TAIHE_DEATHRECIPIENT_H +#define OHOS_IPC_TAIHE_DEATHRECIPIENT_H + +#include "ohos.rpc.rpc.proj.hpp" +#include "ohos.rpc.rpc.impl.hpp" +#include "taihe/runtime.hpp" +#include "stdexcept" + +#include +#include +#include +#include +#include + +#include "iremote_object.h" + +namespace OHOS { +class DeathRecipientImpl : public OHOS::IRemoteObject::DeathRecipient { +public: + DeathRecipientImpl(::ohos::rpc::rpc::DeathRecipient jsObjRef); + + void OnRemoteDied(const OHOS::wptr &object) override; + + int64_t GetNativePtr(); + + void AddJsObjWeakRef(::ohos::rpc::rpc::weak::DeathRecipient obj); + + static ::ohos::rpc::rpc::DeathRecipient CreateDeathRecipient(); + + ::ohos::rpc::rpc::DeathRecipient jsObjRef_; +}; +} // namespace + +#endif // OHOS_IPC_TAIHE_DEATHRECIPIENT_H \ No newline at end of file diff --git a/ipc/native/src/taihe/inc/taihe_ipc_skeleton.h b/ipc/native/src/taihe/inc/taihe_ipc_skeleton.h new file mode 100644 index 00000000..3327368c --- /dev/null +++ b/ipc/native/src/taihe/inc/taihe_ipc_skeleton.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_IPC_TAIHE_IPC_SKELETON_H +#define OHOS_IPC_TAIHE_IPC_SKELETON_H + +#include "ohos.rpc.rpc.proj.hpp" +#include "ohos.rpc.rpc.impl.hpp" +#include "taihe/runtime.hpp" +#include "stdexcept" + +#include +#include +#include +#include +#include + +#include "ipc_skeleton.h" + +namespace OHOS { + +class IPCSkeletonImpl { +public: + static int32_t GetCallingPid(); + static int32_t GetCallingUid(); + static int64_t GetCallingTokenId(); + + static ::ohos::rpc::rpc::IRemoteObjectUnion GetContextObject(); +}; + +} // namespace + +#endif // OHOS_IPC_TAIHE_IPC_SKELETON_H \ No newline at end of file diff --git a/ipc/native/src/taihe/inc/taihe_iremote_broker.h b/ipc/native/src/taihe/inc/taihe_iremote_broker.h new file mode 100644 index 00000000..e2d1bb98 --- /dev/null +++ b/ipc/native/src/taihe/inc/taihe_iremote_broker.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_IPC_TAIHE_IREMOTE_BROKER_H +#define OHOS_IPC_TAIHE_IREMOTE_BROKER_H + +#include "ohos.rpc.rpc.proj.hpp" +#include "ohos.rpc.rpc.impl.hpp" +#include "taihe/runtime.hpp" +#include "stdexcept" + +#include +#include +#include +#include +#include + +namespace OHOS { + +class IRemoteBrokerImpl { +public: + ::ohos::rpc::rpc::IRemoteObjectUnion AsObject(); +}; + +} // namespace + +#endif // OHOS_IPC_TAIHE_IREMOTE_BROKER_H \ No newline at end of file diff --git a/ipc/native/src/taihe/inc/taihe_message_option.h b/ipc/native/src/taihe/inc/taihe_message_option.h new file mode 100644 index 00000000..0d204266 --- /dev/null +++ b/ipc/native/src/taihe/inc/taihe_message_option.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_IPC_TAIHE_MESSAGE_OPTION_H +#define OHOS_IPC_TAIHE_MESSAGE_OPTION_H + +#include "ohos.rpc.rpc.proj.hpp" +#include "ohos.rpc.rpc.impl.hpp" +#include "taihe/runtime.hpp" +#include "stdexcept" + +#include +#include +#include +#include +#include + +#include "message_option.h" + +namespace OHOS { + +class MessageOptionImpl { +public: + MessageOptionImpl(int32_t syncFlags, int32_t waitTime); + + bool IsAsync(); + + void SetAsync(bool isAsync); + + int64_t GetNativePtr(); + + void AddJsObjWeakRef(::ohos::rpc::rpc::weak::MessageOption obj); + + static ::ohos::rpc::rpc::MessageOption CreateMessageOption_WithTwoParam(int32_t syncFlags, int32_t waitTime); + static ::ohos::rpc::rpc::MessageOption CreateMessageOption_WithOneParam(bool isAsync); + static ::ohos::rpc::rpc::MessageOption CreateMessageOption(); + +private: + std::shared_ptr messageOption_ = nullptr; + std::optional<::ohos::rpc::rpc::weak::MessageOption> jsObjRef_; +}; + +} // namespace + +#endif // OHOS_IPC_TAIHE_MESSAGE_OPTION_H \ No newline at end of file diff --git a/ipc/native/src/taihe/inc/taihe_message_sequence.h b/ipc/native/src/taihe/inc/taihe_message_sequence.h new file mode 100644 index 00000000..5866e363 --- /dev/null +++ b/ipc/native/src/taihe/inc/taihe_message_sequence.h @@ -0,0 +1,128 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_IPC_TAIHE_MESSAGE_SEQUENCE_H +#define OHOS_IPC_TAIHE_MESSAGE_SEQUENCE_H + +#include "ohos.rpc.rpc.proj.hpp" +#include "ohos.rpc.rpc.impl.hpp" +#include "taihe/runtime.hpp" +#include "stdexcept" + +#include +#include +#include +#include +#include + +#include "ipc_skeleton.h" +#include "message_parcel.h" + +namespace OHOS { +class MessageSequenceImpl { +public: + MessageSequenceImpl(); + + MessageSequenceImpl(OHOS::MessageParcel* messageparcel); + + ~MessageSequenceImpl(); + + void Reclaim(); + + void WriteRemoteObject(::ohos::rpc::rpc::IRemoteObjectUnion const& object); + + ::ohos::rpc::rpc::IRemoteObjectUnion ReadRemoteObject(); + + void WriteInterfaceToken(::taihe::string_view token); + + ::taihe::string ReadInterfaceToken(); + + int32_t GetCapacity(); + + void SetCapacity(int32_t size); + + void WriteNoException(); + + void ReadException(); + + void WriteInt(int32_t val); + + void WriteLong(int64_t val); + + void WriteBoolean(bool val); + + void WriteString(::taihe::string_view val); + + void WriteParcelable(::ohos::rpc::rpc::weak::Parcelable val); + + void WriteByteArray(::taihe::array_view byteArray); + + void WriteIntArray(::taihe::array_view intArray); + + void WriteDoubleArray(::taihe::array_view doubleArray); + + void WriteBooleanArray(::taihe::array_view booleanArray); + + void WriteStringArray(::taihe::array_view<::taihe::string> stringArray); + + void WriteParcelableArray(::taihe::array_view<::ohos::rpc::rpc::Parcelable> parcelableArray); + + int32_t ReadInt(); + + int64_t ReadLong(); + + bool ReadBoolean(); + + ::taihe::string ReadString(); + + void ReadParcelable(::ohos::rpc::rpc::weak::Parcelable dataIn); + + ::taihe::array ReadIntArrayImpl(); + + ::taihe::array ReadDoubleArrayImpl(); + + ::taihe::array ReadBooleanArrayImpl(); + + ::taihe::array<::taihe::string> ReadStringArrayImpl(); + + void ReadParcelableArray(::taihe::array_view<::ohos::rpc::rpc::Parcelable> parcelableArray); + + void WriteFileDescriptor(int32_t fd); + + int32_t ReadFileDescriptor(); + + void WriteAshmem(::ohos::rpc::rpc::weak::Ashmem ashmem); + + ::ohos::rpc::rpc::Ashmem ReadAshmem(); + + void WriteRawDataBuffer(::taihe::array_view rawData, int32_t size); + + ::taihe::array ReadRawDataBuffer(int32_t size); + + int64_t GetNativePtr(); + + void AddJsObjWeakRef(::ohos::rpc::rpc::weak::MessageSequence obj); + + static ::ohos::rpc::rpc::MessageSequence CreateMessageSequence(); + static void CloseFileDescriptor(int32_t fd); + +private: + OHOS::MessageParcel* nativeParcel_ = nullptr; + std::optional<::ohos::rpc::rpc::weak::MessageSequence> jsObjRef_; + bool isOwner_ = false; +}; +} // namespace + +#endif // OHOS_IPC_TAIHE_MESSAGE_SEQUENCE_H \ No newline at end of file diff --git a/ipc/native/src/taihe/inc/taihe_parcelable.h b/ipc/native/src/taihe/inc/taihe_parcelable.h new file mode 100644 index 00000000..d2aeee6f --- /dev/null +++ b/ipc/native/src/taihe/inc/taihe_parcelable.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_IPC_TAIHE_PARCELABLE_H +#define OHOS_IPC_TAIHE_PARCELABLE_H + +#include "ohos.rpc.rpc.proj.hpp" +#include "ohos.rpc.rpc.impl.hpp" +#include "taihe/runtime.hpp" +#include "stdexcept" + +#include +#include +#include +#include +#include + +namespace OHOS { +class ParcelableImpl { +public: + bool Marshalling(::ohos::rpc::rpc::weak::MessageSequence dataOut); + + bool Unmarshalling(::ohos::rpc::rpc::weak::MessageSequence dataIn); +}; + +} // namespace + +#endif // OHOS_IPC_TAIHE_PARCELABLE_H \ No newline at end of file diff --git a/ipc/native/src/taihe/inc/taihe_remote_object.h b/ipc/native/src/taihe/inc/taihe_remote_object.h new file mode 100644 index 00000000..f3fbad6c --- /dev/null +++ b/ipc/native/src/taihe/inc/taihe_remote_object.h @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_IPC_TAIHE_REMOTEOBJECT_H +#define OHOS_IPC_TAIHE_REMOTEOBJECT_H + +#include "ohos.rpc.rpc.proj.hpp" +#include "ohos.rpc.rpc.impl.hpp" +#include "taihe/runtime.hpp" +#include "stdexcept" + +#include +#include +#include +#include +#include + +#include "ipc_object_stub.h" +#include "taihe_ani_remote_object.h" + +namespace OHOS { + +class RemoteObjectImpl { +public: + // ETS to ANI + explicit RemoteObjectImpl(::taihe::string_view descriptor); + + // ANI to ETS + explicit RemoteObjectImpl(uintptr_t nativePtr); + + int32_t GetCallingPid(); + + int32_t GetCallingUid(); + + void ModifyLocalInterface(::ohos::rpc::rpc::weak::IRemoteBroker localInterface, ::taihe::string_view descriptor); + + ::ohos::rpc::rpc::IRemoteBroker GetLocalInterface(::taihe::string_view descriptor); + + ::ohos::rpc::rpc::RequestResult SendMessageRequestSync(int32_t code, ::ohos::rpc::rpc::weak::MessageSequence data, + ::ohos::rpc::rpc::weak::MessageSequence reply, ::ohos::rpc::rpc::weak::MessageOption options); + + void RegisterDeathRecipient(::ohos::rpc::rpc::weak::DeathRecipient recipient, int32_t flags); + + void UnregisterDeathRecipient(::ohos::rpc::rpc::weak::DeathRecipient recipient, int32_t flags); + + ::taihe::string GetDescriptor(); + + bool IsObjectDead(); + + bool OnRemoteMessageRequest(int32_t code, ::ohos::rpc::rpc::weak::MessageSequence data, + ::ohos::rpc::rpc::weak::MessageSequence reply, ::ohos::rpc::rpc::weak::MessageOption options); + + OHOS::sptr GetNativeObject(); + + int64_t GetNativePtr(); + + void AddJsObjWeakRef(::ohos::rpc::rpc::weak::RemoteObject obj, bool isNative); + + static ::ohos::rpc::rpc::RemoteObject CreateRemoteObject(::ohos::rpc::rpc::weak::RemoteObject jsSelf, + ::taihe::string_view descriptor); + static ::ohos::rpc::rpc::RemoteObject CreateRemoteObjectFromNative(uintptr_t nativePtr); + +private: + std::mutex mutex_; + OHOS::wptr wptrCachedObject_; + OHOS::sptr sptrCachedObject_; + ::taihe::string desc_; + std::optional<::ohos::rpc::rpc::RemoteObject> jsObjRef_; + std::optional<::ohos::rpc::rpc::IRemoteBroker> jsLocalInterface_; +}; + +} // namespace + +#endif // OHOS_IPC_TAIHE_REMOTEOBJECT_H \ No newline at end of file diff --git a/ipc/native/src/taihe/inc/taihe_remote_proxy.h b/ipc/native/src/taihe/inc/taihe_remote_proxy.h new file mode 100644 index 00000000..9ec46e09 --- /dev/null +++ b/ipc/native/src/taihe/inc/taihe_remote_proxy.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_IPC_TAIHE_REMOTEPROXY_H +#define OHOS_IPC_TAIHE_REMOTEPROXY_H + +#include "ohos.rpc.rpc.proj.hpp" +#include "ohos.rpc.rpc.impl.hpp" +#include "taihe/runtime.hpp" +#include "stdexcept" + +#include +#include +#include +#include +#include + +#include "ipc_object_proxy.h" + +namespace OHOS { + +class RemoteProxyImpl { +public: + RemoteProxyImpl(uintptr_t nativePtr); + + ::ohos::rpc::rpc::IRemoteBroker GetLocalInterface(::taihe::string_view descriptor); + + ::ohos::rpc::rpc::RequestResult SendMessageRequestSync(int32_t code, ::ohos::rpc::rpc::weak::MessageSequence data, + ::ohos::rpc::rpc::weak::MessageSequence reply, ::ohos::rpc::rpc::weak::MessageOption options); + + void RegisterDeathRecipient(::ohos::rpc::rpc::DeathRecipient recipient, int32_t flags); + + void UnregisterDeathRecipient(::ohos::rpc::rpc::DeathRecipient recipient, int32_t flags); + + ::taihe::string GetDescriptor(); + + bool IsObjectDead(); + + int64_t GetNativePtr(); + + void AddJsObjWeakRef(::ohos::rpc::rpc::weak::RemoteProxy obj); + + static ::ohos::rpc::rpc::RemoteProxy CreateRemoteProxyFromNative(uintptr_t nativePtr); + +private: + OHOS::sptr cachedObject_; + std::optional<::ohos::rpc::rpc::RemoteProxy> jsObjRef_; + std::optional<::ohos::rpc::rpc::IRemoteBroker> jsLocalInterface_; + std::map<::ohos::rpc::rpc::DeathRecipient*, OHOS::sptr> deathRecipientMap_; +}; + +} // namespace +#endif // OHOS_IPC_TAIHE_REMOTEPROXY_H \ No newline at end of file -- Gitee