From 5defc21e45808268507558008036bdf4faba8148 Mon Sep 17 00:00:00 2001 From: Sergey Zavyalov Date: Tue, 2 Sep 2025 11:13:34 +0300 Subject: [PATCH] Linux build support Signed-off-by: Sergey Zavyalov --- .../ipc_core/include/message_parcel.h | 1 + ipc/native/src/ani/rpc/BUILD.gn | 27 ++- .../src/ani/rpc/include/ani_util_class.h | 1 + .../src/ani/rpc/include/ani_util_native_ptr.h | 10 +- ipc/native/src/ani/rpc/mock/rpc_ani.cpp | 173 ++++++++++++++++++ 5 files changed, 201 insertions(+), 11 deletions(-) create mode 100644 ipc/native/src/ani/rpc/mock/rpc_ani.cpp diff --git a/interfaces/innerkits/ipc_core/include/message_parcel.h b/interfaces/innerkits/ipc_core/include/message_parcel.h index c3e86707..343a6e36 100644 --- a/interfaces/innerkits/ipc_core/include/message_parcel.h +++ b/interfaces/innerkits/ipc_core/include/message_parcel.h @@ -17,6 +17,7 @@ #define OHOS_IPC_MESSAGE_PARCEL_H #include +#include #include "parcel.h" #include "refbase.h" #include diff --git a/ipc/native/src/ani/rpc/BUILD.gn b/ipc/native/src/ani/rpc/BUILD.gn index 3a301b98..2afb1c40 100644 --- a/ipc/native/src/ani/rpc/BUILD.gn +++ b/ipc/native/src/ani/rpc/BUILD.gn @@ -26,23 +26,38 @@ config("ani_rpc_public_config") { } ohos_shared_library("rpc_ani") { - sources = [ - "src/rpc_ani.cpp", - "src/ani_rpc_error.cpp" - ] + if (is_linux) { + sources = [ + "mock/rpc_ani.cpp", + ] + } + else { + sources = [ + "src/rpc_ani.cpp", + "src/ani_rpc_error.cpp" + ] + } include_dirs = [ "include", "../../../../../utils/include", "../../../../../interfaces/innerkits/ipc_core/include", + "../../../../../ipc/native/src/core/framework/include", + "//commonlibrary/c_utils/base/include", ] public_configs = [ ":ani_rpc_public_config" ] - deps = [ "../../../../../interfaces/innerkits/ipc_core:ipc_core" ] external_deps = [ - "c_utils:utils", "hilog:libhilog", "runtime_core:ani", ] + + if (!is_linux) { + deps = [ "../../../../../interfaces/innerkits/ipc_core:ipc_core" ] + external_deps += [ + "c_utils:utils", + ] + } + subsystem_name = "communication" part_name = "ipc" output_extension = "so" diff --git a/ipc/native/src/ani/rpc/include/ani_util_class.h b/ipc/native/src/ani/rpc/include/ani_util_class.h index 14e4ac8b..4cec1f8b 100644 --- a/ipc/native/src/ani/rpc/include/ani_util_class.h +++ b/ipc/native/src/ani/rpc/include/ani_util_class.h @@ -18,6 +18,7 @@ #include #include +#include #include "ani_util_common.h" diff --git a/ipc/native/src/ani/rpc/include/ani_util_native_ptr.h b/ipc/native/src/ani/rpc/include/ani_util_native_ptr.h index 79594d4f..77983787 100644 --- a/ipc/native/src/ani/rpc/include/ani_util_native_ptr.h +++ b/ipc/native/src/ani/rpc/include/ani_util_native_ptr.h @@ -50,23 +50,23 @@ private: template class OhSharedPtrHolder : public NativeObject { public: - OhSharedPtrHolder(const OHOS::sptr &sptr) : sptr_(sptr) {} + OhSharedPtrHolder(const sptr &sptr) : sptr_(sptr) {} - OHOS::sptr Get() + sptr Get() { return sptr_; } - OHOS::sptr GetOrDefault() + sptr GetOrDefault() { if (!sptr_) { - sptr_ = OHOS::sptr::MakeSptr(); + sptr_ = sptr::MakeSptr(); } return sptr_; } private: - OHOS::sptr sptr_; + sptr sptr_; }; class AniObjectUtils { diff --git a/ipc/native/src/ani/rpc/mock/rpc_ani.cpp b/ipc/native/src/ani/rpc/mock/rpc_ani.cpp new file mode 100644 index 00000000..756a0d13 --- /dev/null +++ b/ipc/native/src/ani/rpc/mock/rpc_ani.cpp @@ -0,0 +1,173 @@ +/* + * 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. + */ + +#include "ipc_debug.h" +#include "iremote_object.h" +#include "log_tags.h" +#include "refbase.h" +#include +#include +#include +#include + +static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, OHOS::LOG_ID_IPC_NAPI, "NAPI_MessageSequenceWrite" }; + +using namespace OHOS; + +sptr AniGetNativeRemoteObject(ani_env *env, ani_object obj) +{ + ZLOGD(LOG_LABEL, "%{public}s NOT Implemented", __func__); + return 0; +} + +ani_object ANI_ohos_rpc_CreateJsRemoteObject(ani_env *env, sptr remoteObject) +{ + ZLOGD(LOG_LABEL, "%{public}s NOT Implemented", __func__); + return nullptr; +} + +static void InitMessageOption([[maybe_unused]] ani_env *env, + [[maybe_unused]] ani_object obj, + ani_double syncFlags, + ani_double waitTimeParam) +{ +} + +static ani_string MessageSequenceReadString([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object object) +{ + ZLOGD(LOG_LABEL, "%{public}s NOT Implemented", __func__); + return nullptr; +} + +static bool MessageSequenceWriteString([[maybe_unused]] ani_env *env, + [[maybe_unused]] ani_object object, + ani_string str) +{ + ZLOGD(LOG_LABEL, "%{public}s NOT Implemented", __func__); + return true; +} + +static ani_string GetRemoteObjectDescriptor([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object object) +{ + ZLOGD(LOG_LABEL, "%{public}s NOT Implemented", __func__); + return nullptr; +} + +static ani_string MessageSequencereadInterfaceToken([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object object) +{ + ZLOGD(LOG_LABEL, "%{public}s NOT Implemented", __func__); + return nullptr; +} + + +static ani_status BindMessageSequenceClassMethods(ani_env *env, const char *nsName) +{ + const std::string msgSeqClsName = std::string(nsName).append(".MessageSequence"); + ani_class msgSequenceClass; + if (ANI_OK != env->FindClass(msgSeqClsName.c_str(), &msgSequenceClass)) { + return ANI_NOT_FOUND; + } + + std::array methods = { + ani_native_function {"readString", nullptr, reinterpret_cast(MessageSequenceReadString)}, + ani_native_function {"writeString", nullptr, reinterpret_cast(MessageSequenceWriteString)}, + ani_native_function {"readInterfaceToken", nullptr, + reinterpret_cast(MessageSequencereadInterfaceToken)}, + }; + + if (ANI_OK != env->Class_BindNativeMethods(msgSequenceClass, methods.data(), methods.size())) { + return ANI_ERROR; + }; + + return ANI_OK; +} + + +static ani_status BindMessageOptionClassMethods(ani_env *env, const char *nsName) +{ + const std::string msgOptClsName = std::string(nsName).append(".MessageOption"); + ani_class msgOptionClass; + if (ANI_OK != env->FindClass(msgOptClsName.c_str(), &msgOptionClass)) { + return ANI_NOT_FOUND; + } + + std::array methods = { + ani_native_function {"init", nullptr, reinterpret_cast(InitMessageOption)}, + }; + + if (ANI_OK != env->Class_BindNativeMethods(msgOptionClass, methods.data(), methods.size())) { + return ANI_ERROR; + }; + + return ANI_OK; +} + +static void RemoteObjectInit([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object object, ani_string descriptor) +{ +} + +static ani_status BindRemoteObjectClassMethods(ani_env *env, const char *nsName) +{ + const std::string remoteObjClsName = std::string(nsName).append(".RemoteObject"); + ani_class remoteObjClass; + if (ANI_OK != env->FindClass(remoteObjClsName.c_str(), &remoteObjClass)) { + return ANI_NOT_FOUND; + } + + std::array methods = { + ani_native_function {"getDescriptor", nullptr, reinterpret_cast(GetRemoteObjectDescriptor)}, + ani_native_function {"init", "C{std.core.String}:", reinterpret_cast(RemoteObjectInit)}, + }; + + if (ANI_OK != env->Class_BindNativeMethods(remoteObjClass, methods.data(), methods.size())) { + return ANI_ERROR; + }; + + return ANI_OK; +} + +static ani_status BindCleanerclassMethods(ani_env *env, const char *nsName) +{ + return ANI_OK; +} + +ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) +{ + ani_env *env; + if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) { + return ANI_ERROR; + } + + static const char *nsName = "@ohos.rpc.rpc"; + + if (ANI_OK != BindMessageSequenceClassMethods(env, nsName)) { + return ANI_ERROR; + } + + if (ANI_OK != BindMessageOptionClassMethods(env, nsName)) { + return ANI_ERROR; + } + + if (ANI_OK != BindRemoteObjectClassMethods(env, nsName)) { + return ANI_ERROR; + } + + if (ANI_OK != BindCleanerclassMethods(env, nsName)) { + return ANI_ERROR; + } + + *result = ANI_VERSION_1; + return ANI_OK; +} -- Gitee