From 9de05f1e2700b05f678172dad05db2acae751dc8 Mon Sep 17 00:00:00 2001 From: liubb_0516 Date: Thu, 30 Dec 2021 09:42:35 +0800 Subject: [PATCH] modify coding style Signed-off-by: liubb_0516 --- .../innerkits/c/ipc/include/ipc_skeleton.h | 3 +- .../innerkits/c/ipc/include/serializer.h | 9 +- ipc/native/c/adapter/Linux/rpc_os_adapter.c | 4 +- .../c/adapter/Liteos_m/rpc_os_adapter.c | 4 +- ipc/native/c/adapter/include/rpc_os_adapter.h | 4 +- ipc/native/c/ipc/include/binder_invoker.h | 3 +- ipc/native/c/ipc/include/sys_binder.h | 22 +- ipc/native/c/ipc/src/binder_invoker.c | 4 +- .../c/manager/include/iremote_invoker.h | 2 - .../c/manager/src/ipc_process_skeleton.c | 11 +- ipc/native/c/manager/src/ipc_skeleton.c | 6 +- ipc/native/c/manager/src/ipc_thread_pool.c | 2 +- ipc/native/c/manager/src/iremote_invoker.c | 2 +- ipc/native/c/manager/src/serializer.c | 11 +- test/ipc/BUILD.gn | 22 -- test/ipc/client/BUILD.gn | 38 ---- test/ipc/client/client.c | 178 --------------- test/ipc/samgr/BUILD.gn | 41 ---- test/ipc/samgr/samgr.c | 123 ---------- test/ipc/server/BUILD.gn | 38 ---- test/ipc/server/server.c | 210 ------------------ test/resource/ipc/ohos_test.xml | 48 ---- test/resource/services/ohos_test.xml | 28 --- 23 files changed, 34 insertions(+), 779 deletions(-) delete mode 100644 test/ipc/BUILD.gn delete mode 100644 test/ipc/client/BUILD.gn delete mode 100644 test/ipc/client/client.c delete mode 100644 test/ipc/samgr/BUILD.gn delete mode 100644 test/ipc/samgr/samgr.c delete mode 100644 test/ipc/server/BUILD.gn delete mode 100644 test/ipc/server/server.c delete mode 100755 test/resource/ipc/ohos_test.xml delete mode 100755 test/resource/services/ohos_test.xml diff --git a/interfaces/innerkits/c/ipc/include/ipc_skeleton.h b/interfaces/innerkits/c/ipc/include/ipc_skeleton.h index b8f6368..b6c5a49 100644 --- a/interfaces/innerkits/c/ipc/include/ipc_skeleton.h +++ b/interfaces/innerkits/c/ipc/include/ipc_skeleton.h @@ -58,7 +58,8 @@ const SvcIdentity *GetContextObject(void); int32_t SetContextObject(SvcIdentity target); -int32_t SendRequest(SvcIdentity target, uint32_t code, IpcIo *data, IpcIo *reply, MessageOption option, uintptr_t *buffer); +int32_t SendRequest(SvcIdentity target, uint32_t code, IpcIo *data, IpcIo *reply, + MessageOption option, uintptr_t *buffer); int32_t FreeBuffer(void *ptr); diff --git a/interfaces/innerkits/c/ipc/include/serializer.h b/interfaces/innerkits/c/ipc/include/serializer.h index d6de816..1c86cea 100644 --- a/interfaces/innerkits/c/ipc/include/serializer.h +++ b/interfaces/innerkits/c/ipc/include/serializer.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef _LITEIPC_SERIALIZER_H_ -#define _LITEIPC_SERIALIZER_H_ +#ifndef OHOS_IPC_RPC_SERIALIZER_H +#define OHOS_IPC_RPC_SERIALIZER_H #include #include @@ -51,7 +51,6 @@ typedef struct { * offset entries to reserve from the buffer */ void IpcIoInit(IpcIo* io, void* data, size_t maxdata, size_t maxobjects); -bool IpcIoAvailable(IpcIo* io); /* Must ensure all the input is valid */ void IpcIoPushChar(IpcIo* io, char c); void IpcIoPushCharUnaligned(IpcIo* io, char c); @@ -103,12 +102,10 @@ void* IpcIoPopFlatObj(IpcIo* io, uint32_t* size); bool IpcIoPopSvc(IpcIo* io, SvcIdentity* svc); int32_t IpcIoPopFd(IpcIo* io); -struct flat_binder_object* IpcIoPopRef(IpcIo *io); - #ifdef __cplusplus #if __cplusplus } #endif /* __cplusplus */ #endif /* __cplusplus */ -#endif +#endif /* OHOS_IPC_RPC_SERIALIZER_H */ diff --git a/ipc/native/c/adapter/Linux/rpc_os_adapter.c b/ipc/native/c/adapter/Linux/rpc_os_adapter.c index d18d918..9214d26 100644 --- a/ipc/native/c/adapter/Linux/rpc_os_adapter.c +++ b/ipc/native/c/adapter/Linux/rpc_os_adapter.c @@ -16,12 +16,12 @@ #include #include "rpc_os_adapter.h" -int32_t RpcGetPid() +int32_t RpcGetPid(void) { return (int32_t)getpid(); } int32_t RpcGetUid() { - return (int32_t)getuid(); + return (int32_t)getuid(void); } \ No newline at end of file diff --git a/ipc/native/c/adapter/Liteos_m/rpc_os_adapter.c b/ipc/native/c/adapter/Liteos_m/rpc_os_adapter.c index 397a9b9..faeb00c 100644 --- a/ipc/native/c/adapter/Liteos_m/rpc_os_adapter.c +++ b/ipc/native/c/adapter/Liteos_m/rpc_os_adapter.c @@ -15,12 +15,12 @@ #include "rpc_os_adapter.h" -int32_t RpcGetPid() +int32_t RpcGetPid(void) { return 0; } -int32_t RpcGetUid() +int32_t RpcGetUid(void) { return 0; } \ No newline at end of file diff --git a/ipc/native/c/adapter/include/rpc_os_adapter.h b/ipc/native/c/adapter/include/rpc_os_adapter.h index 6669577..128af4f 100644 --- a/ipc/native/c/adapter/include/rpc_os_adapter.h +++ b/ipc/native/c/adapter/include/rpc_os_adapter.h @@ -24,9 +24,9 @@ extern "C" { #endif #endif /* __cplusplus */ -int32_t RpcGetPid(); +int32_t RpcGetPid(void); -int32_t RpcGetUid(); +int32_t RpcGetUid(void); #ifdef __cplusplus #if __cplusplus } diff --git a/ipc/native/c/ipc/include/binder_invoker.h b/ipc/native/c/ipc/include/binder_invoker.h index 44697f8..ed03350 100644 --- a/ipc/native/c/ipc/include/binder_invoker.h +++ b/ipc/native/c/ipc/include/binder_invoker.h @@ -27,7 +27,8 @@ extern "C" { RemoteInvoker *GetIpcInvoker(void); int32_t AcquireHandle(int32_t handle); int32_t ReleaseHandle(int32_t handle); -int32_t IpcSendRequest(SvcIdentity target, uint32_t code, IpcIo *data, IpcIo *reply, MessageOption option, uintptr_t *buffer); +int32_t IpcSendRequest(SvcIdentity target, uint32_t code, IpcIo *data, IpcIo *reply, + MessageOption option, uintptr_t *buffer); int32_t IpcFreeBuffer(void *ptr); int32_t IpcSetMaxWorkThread(int32_t maxThreadNum); void IpcJoinThread(bool initiative); diff --git a/ipc/native/c/ipc/include/sys_binder.h b/ipc/native/c/ipc/include/sys_binder.h index fc8d6a5..f1eba79 100644 --- a/ipc/native/c/ipc/include/sys_binder.h +++ b/ipc/native/c/ipc/include/sys_binder.h @@ -15,10 +15,12 @@ #ifndef _UAPI_LINUX_BINDER_H #define _UAPI_LINUX_BINDER_H -#include + #include #include #include +#include + #define B_PACK_CHARS(c1, c2, c3, c4) ((((c1) << 24)) | (((c2) << 16)) | (((c3) << 8)) | (c4)) #define B_TYPE_LARGE 0x85 @@ -31,8 +33,6 @@ enum { BINDER_TYPE_HANDLE = B_PACK_CHARS('s', 'h', '*', B_TYPE_LARGE), BINDER_TYPE_REMOTE_HANDLE = B_PACK_CHARS('r', 'h', '*', B_TYPE_LARGE), BINDER_TYPE_WEAK_HANDLE = B_PACK_CHARS('w', 'h', '*', B_TYPE_LARGE), - ZBINDER_TYPE_REMOTE_NODE = B_PACK_CHARS('r', 'n', '*', B_TYPE_LARGE), - ZBINDER_TYPE_NODE = B_PACK_CHARS('s', 'n', '*', B_TYPE_LARGE), BINDER_TYPE_FD = B_PACK_CHARS('f', 'd', '*', B_TYPE_LARGE), BINDER_TYPE_FDA = B_PACK_CHARS('f', 'd', 'a', B_TYPE_LARGE), BINDER_TYPE_PTR = B_PACK_CHARS('p', 't', '*', B_TYPE_LARGE), @@ -133,7 +133,6 @@ struct binder_ptr_count { #define BINDER_THREAD_EXIT _IOW('b', 8, __s32) #define BINDER_VERSION _IOWR('b', 9, struct binder_version) #define BINDER_GET_NODE_DEBUG_INFO _IOWR('b', 11, struct binder_node_debug_info) -#define BINDER_SET_DBINDER_MGR _IOW('b', 12, __s32) #define BINDER_GET_NODE_REFCOUNT _IOWR('b', 17, struct binder_ptr_count) enum transaction_flags { @@ -235,19 +234,4 @@ enum binder_driver_command_protocol { BC_RELEASE_NODE = _IOW('c', 19, binder_uintptr_t), }; -struct dbinder_transaction_data { - __u32 sizeOfSelf; - __u32 magic; - __u32 version; - int cmd; - __u32 code; - __u32 flags; - __u64 cookie; - __u64 seqNumber; - binder_size_t buffer_size; - binder_size_t offsets_size; - binder_uintptr_t offsets; - char *buffer; -}; - #endif diff --git a/ipc/native/c/ipc/src/binder_invoker.c b/ipc/native/c/ipc/src/binder_invoker.c index 0e7d77f..34636d6 100644 --- a/ipc/native/c/ipc/src/binder_invoker.c +++ b/ipc/native/c/ipc/src/binder_invoker.c @@ -136,7 +136,8 @@ int32_t ReleaseHandle(int32_t handle) return ret; } -static void ToTransData(uint32_t handle, uint32_t code, MessageOption option, const IpcIo *data, struct TransactData *buf) +static void ToTransData(uint32_t handle, uint32_t code, MessageOption option, + const IpcIo *data, struct TransactData *buf) { buf->btd.target.handle = handle; buf->btd.code = code; @@ -371,7 +372,6 @@ void IpcJoinThread(bool initiative) bwr.read_consumed = 0; bwr.read_buffer = (uintptr_t)readbuf; ret = ioctl(g_connector->fd, BINDER_WRITE_READ, &bwr); - if (ret < 0) { RPC_LOG_ERROR("ioctl failed errno = %d.", errno); break; diff --git a/ipc/native/c/manager/include/iremote_invoker.h b/ipc/native/c/manager/include/iremote_invoker.h index ebbe1d5..7e9c8e8 100644 --- a/ipc/native/c/manager/include/iremote_invoker.h +++ b/ipc/native/c/manager/include/iremote_invoker.h @@ -40,8 +40,6 @@ typedef struct { int32_t (*SetRegistryObject)(void); int32_t (*AddDeathRecipient)(int32_t handle, void *cookie); int32_t (*RemoveDeathRecipient)(int32_t handle, void *cookie); - // pid_t (*GetCallerPid)(); - // uid_t (*GetCallerUid)(); } RemoteInvoker; RemoteInvoker *InitRemoteInvoker(int32_t proto); diff --git a/ipc/native/c/manager/src/ipc_process_skeleton.c b/ipc/native/c/manager/src/ipc_process_skeleton.c index a59dc68..02dbd16 100644 --- a/ipc/native/c/manager/src/ipc_process_skeleton.c +++ b/ipc/native/c/manager/src/ipc_process_skeleton.c @@ -112,7 +112,7 @@ int32_t SetMaxWorkThread(int32_t maxThreadNum) return ERR_THREAD_INVOKER_NOT_INIT; } -void JoinMainWorkThread() +void JoinMainWorkThread(void) { RemoteInvoker *invoker = GetRemoteInvoker(IF_PROT_DEFAULT); if (invoker != NULL) { @@ -120,7 +120,7 @@ void JoinMainWorkThread() } } -pid_t ProcessGetCallingPid() +pid_t ProcessGetCallingPid(void) { ThreadContext *currentContext = GetCurrentThreadContext(); if (currentContext != NULL) { @@ -129,7 +129,7 @@ pid_t ProcessGetCallingPid() return RpcGetPid(); } -pid_t ProcessGetCallingUid() +pid_t ProcessGetCallingUid(void) { ThreadContext *currentContext = GetCurrentThreadContext(); if (currentContext != NULL) { @@ -184,7 +184,8 @@ static void DeleteDeadHandle(int32_t handle) } } -int32_t ProcessSendRequest(SvcIdentity target, uint32_t code, IpcIo *data, IpcIo *reply, MessageOption option, uintptr_t *buffer) +int32_t ProcessSendRequest(SvcIdentity target, uint32_t code, IpcIo *data, IpcIo *reply, + MessageOption option, uintptr_t *buffer) { int32_t ret = ERR_THREAD_INVOKER_NOT_INIT; RemoteInvoker *invoker = GetRemoteInvoker(IF_PROT_DEFAULT); @@ -269,7 +270,6 @@ int32_t ProcessAddDeathRecipient(int32_t handle, OnRemoteDead deathFunc, void *a return ERR_IPC_SKELETON_NOT_INIT; } if (deathFunc == NULL || cbId == NULL) { - RPC_LOG_ERROR("death func or callback id is NULL."); return ERR_INVALID_PARAM; } if (pthread_mutex_lock(&g_ipcSkeleton->lock) != 0) { @@ -288,7 +288,6 @@ int32_t ProcessAddDeathRecipient(int32_t handle, OnRemoteDead deathFunc, void *a return ERR_DEAD_OBJECT; } if (node->deathNum == MAX_DEATH_CALLBACK_NUM) { - RPC_LOG_ERROR("reached max death num on this service handle = %d.", handle); pthread_mutex_unlock(&g_ipcSkeleton->lock); return ERR_INVALID_PARAM; } diff --git a/ipc/native/c/manager/src/ipc_skeleton.c b/ipc/native/c/manager/src/ipc_skeleton.c index 7a68d82..c1848cd 100644 --- a/ipc/native/c/manager/src/ipc_skeleton.c +++ b/ipc/native/c/manager/src/ipc_skeleton.c @@ -37,7 +37,7 @@ int32_t SetMaxWorkThreadNum(int32_t maxThreadNum) } // join current thread into work loop. -void JoinWorkThread() +void JoinWorkThread(void) { if (GetCurrentSkeleton() == NULL) { RPC_LOG_ERROR("init ipc process skeleton failed."); @@ -46,7 +46,7 @@ void JoinWorkThread() return JoinMainWorkThread(); } -pid_t GetCallingPid() +pid_t GetCallingPid(void) { if (GetCurrentSkeleton() == NULL) { RPC_LOG_ERROR("init ipc process skeleton failed."); @@ -55,7 +55,7 @@ pid_t GetCallingPid() return ProcessGetCallingPid(); } -pid_t GetCallingUid() +pid_t GetCallingUid(void) { if (GetCurrentSkeleton() == NULL) { RPC_LOG_ERROR("init ipc process skeleton failed."); diff --git a/ipc/native/c/manager/src/ipc_thread_pool.c b/ipc/native/c/manager/src/ipc_thread_pool.c index c6d96d8..24b3c57 100644 --- a/ipc/native/c/manager/src/ipc_thread_pool.c +++ b/ipc/native/c/manager/src/ipc_thread_pool.c @@ -32,7 +32,7 @@ static RemoteInvoker *g_invoker[PROTO_NUM]; static void TlsDestructor(void *args) { - RPC_LOG_INFO( "thread exit, call tls destructor"); + RPC_LOG_INFO("thread exit, call tls destructor"); ThreadContext *threadContext = (ThreadContext *)args; RemoteInvoker *invoker = g_invoker[threadContext->proto]; free(threadContext); diff --git a/ipc/native/c/manager/src/iremote_invoker.c b/ipc/native/c/manager/src/iremote_invoker.c index 0fab2fc..7757a97 100644 --- a/ipc/native/c/manager/src/iremote_invoker.c +++ b/ipc/native/c/manager/src/iremote_invoker.c @@ -23,7 +23,7 @@ RemoteInvoker *InitRemoteInvoker(int32_t proto) RemoteInvoker *remoteInvoker = NULL; if (proto == IF_PROT_BINDER) { remoteInvoker = GetIpcInvoker(); - } + } return remoteInvoker; } diff --git a/ipc/native/c/manager/src/serializer.c b/ipc/native/c/manager/src/serializer.c index a5746dd..c19711b 100644 --- a/ipc/native/c/manager/src/serializer.c +++ b/ipc/native/c/manager/src/serializer.c @@ -17,7 +17,7 @@ #include "securec.h" #include #include -#ifndef __LITEOS_M__ +#ifdef __LINUX__ #include "sys_binder.h" #endif #include "rpc_log.h" @@ -45,7 +45,8 @@ static void* IoPop(IpcIo* io, size_t size); void IpcIoInit(IpcIo* io, void* buffer, size_t bufferSize, size_t maxobjects) { - if ((io == NULL) || (buffer == NULL) || (bufferSize == 0) || (bufferSize > MAX_IO_SIZE) || (maxobjects > MAX_OBJ_NUM)) { + if ((io == NULL) || (buffer == NULL) || (bufferSize == 0) || + (bufferSize > MAX_IO_SIZE) || (maxobjects > MAX_OBJ_NUM)) { return; } size_t objectsSize = maxobjects * sizeof(size_t); @@ -64,7 +65,7 @@ void IpcIoInit(IpcIo* io, void* buffer, size_t bufferSize, size_t maxobjects) io->flag = IPC_IO_INITIALIZED; } -bool IpcIoAvailable(IpcIo* io) +static bool IpcIoAvailable(IpcIo* io) { bool ret = false; if (io != NULL) { @@ -479,7 +480,7 @@ void IpcIoPushFlatObj(IpcIo* io, const void* obj, uint32_t size) } } -#ifndef __LITEOS_M__ +#ifdef __LINUX__ static struct flat_binder_object* IoPushBinderObj(IpcIo* io) { IPC_IO_RETURN_IF_FAIL(io != NULL); @@ -581,7 +582,7 @@ bool IpcIoPopSvc(IpcIo* io, SvcIdentity *svc) bool IpcIoPushFd(IpcIo* io, uint32_t fd) { - if (io == NULL) { + if (io == NULL) { RPC_LOG_ERROR("push fd io is NULL."); return false; } diff --git a/test/ipc/BUILD.gn b/test/ipc/BUILD.gn deleted file mode 100644 index 5768ac7..0000000 --- a/test/ipc/BUILD.gn +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright (c) 2021 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. - -import("//foundation/communication/dsoftbus/dsoftbus.gni") - -lite_component("ipc_test") { - features = [ - "client:ipc_client", - "server:ipc_server", - "samgr:samgr", - ] -} \ No newline at end of file diff --git a/test/ipc/client/BUILD.gn b/test/ipc/client/BUILD.gn deleted file mode 100644 index b4b893b..0000000 --- a/test/ipc/client/BUILD.gn +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright (c) 2020 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. - -import("//build/lite/config/component/lite_component.gni") - -SUBSYSTEM_DIR = "//foundation/communication/ipc/test" -IPC_CORE_ROOT = "//foundation/communication/ipc/ipc/native/c" - -executable("ipc_client") { - sources = [ - "$SUBSYSTEM_DIR/ipc/client/client.c", - ] - include_dirs = [ - "//third_party/bounds_checking_function/include", - "//utils/native/lite/include", - "$IPC_CORE_ROOT/manager/include", - "//base/hiviewdfx/hilog_lite/interfaces/native/innerkits", - ] - ldflags = [ - "-lstdc++", - "-lpthread", - ] - deps = [ - "//foundation/communication/ipc/interfaces/innerkits/c/ipc:ipc_single" - ] - - configs -= [ "//build/lite/config:clang_opt" ] -} diff --git a/test/ipc/client/client.c b/test/ipc/client/client.c deleted file mode 100644 index 33ff50d..0000000 --- a/test/ipc/client/client.c +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright (c) 2021 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 - -#include "rpc_log.h" -#include "rpc_errno.h" -#include "ipc_skeleton.h" -#include "serializer.h" - -static SvcIdentity *sid = NULL; -uint32_t cbId1 = -1; -uint32_t cbId2 = -1; -uint32_t cbId3 = -1; -uint32_t cbId4 = -1; -uint32_t cbId5 = -1; - -enum { - OP_ADD = 1, - OP_SUB = 2, - OP_PRINT = 3, -}; - -int32_t RemoteRequest(uint32_t code, IpcIo *data, IpcIo *reply, MessageOption option) -{ - int32_t result = ERR_NONE; - RPC_LOG_INFO("client OnRemoteRequest called...."); - switch (code) { - case OP_ADD: { - int32_t a = IpcIoPopInt32(data); - int32_t b = IpcIoPopInt32(data); - IpcIoPushInt32(reply, a + b); - break; - } - case OP_SUB: { - int32_t a = IpcIoPopInt32(data); - int32_t b = IpcIoPopInt32(data); - IpcIoPushInt32(reply, a - b); - break; - } - case OP_PRINT: { - size_t len; - char *str = (char *)IpcIoPopString(data, &len); - RPC_LOG_INFO("client pop string %{public}s....", str); - break; - } - default: - RPC_LOG_ERROR("unknown code %{public}d", code); - break; - } - return result; -} - -void ServerDead1() -{ - int ret = RemoveDeathRecipient(*sid, cbId1); - RPC_LOG_INFO("#### server dead callback11 called %{public}d ... ", ret); -} - -void ServerDead2() -{ - int ret = RemoveDeathRecipient(*sid, cbId2); - RPC_LOG_INFO("#### server dead callback22 called %{public}d ... ", ret); -} - -void ServerDead3() -{ - int ret = RemoveDeathRecipient(*sid, cbId3); - RPC_LOG_INFO("#### server dead callback33 called %{public}d ... ", ret); -} - -int main(int argc, char *argv[]) -{ - RPC_LOG_INFO("Enter System Ability Client .... "); - - IpcIo data1; - uint8_t tmpData1[64]; - IpcIoInit(&data1, tmpData1, 64, 0); - IpcIoPushInt32(&data1, 15); - - IpcIo reply1; - MessageOption option = TF_OP_SYNC; - - SvcIdentity target = { - .handle = 0 - }; - uintptr_t ptr = 0; - int ret = SendRequest(target, 1, &data1, &reply1, option, &ptr); - sid = (SvcIdentity *)malloc(sizeof(SvcIdentity)); - IpcIoPopSvc(&reply1, sid); - FreeBuffer((void *)ptr); - - IpcIo data2; - uint8_t tmpData2[64]; - IpcIoInit(&data2, tmpData2, 64, 0); - IpcIoPushInt32(&data2, 12); - IpcIoPushInt32(&data2, 17); - - IpcIo reply2; - uintptr_t ptr2 = 0; - ret = SendRequest(*sid, 1, &data2, &reply2, option, &ptr2); - RPC_LOG_INFO(" 12 + 17 = %{public}d", IpcIoPopInt32(&reply2)); - FreeBuffer((void *)ptr2); - - IpcObjectStub objectStub = { - .func = RemoteRequest, - .isRemote = false - }; - - SvcIdentity svc = { - .handle = -1, - .token = &objectStub, - .cookie = &objectStub - }; - - IpcIo anonymous; - uint8_t anonymousData[128]; - IpcIoInit(&anonymous, anonymousData, 128, 1); - IpcIoPushSvc(&anonymous, &svc); - - IpcIo anonymousreply; - uintptr_t anonymousptr = 0; - ret = SendRequest(*sid, 4, &anonymous, &anonymousreply, option, &anonymousptr); - RPC_LOG_INFO("add self to server = %{public}d", IpcIoPopInt32(&anonymousreply)); - FreeBuffer((void *)anonymousptr); - - RPC_LOG_INFO("============= test case for add death callback ============"); - ret = AddDeathRecipient(*sid, ServerDead1, NULL, &cbId1); - RPC_LOG_INFO("add death callback cbid1 = %{public}d", ret); - ret = AddDeathRecipient(*sid, ServerDead2, NULL, &cbId2); - RPC_LOG_INFO("add death callback cbid2 = %{public}d", ret); - ret = AddDeathRecipient(*sid, ServerDead3, NULL, &cbId3); - RPC_LOG_INFO("add death callback cbid3 = %{public}d", ret); - ret = AddDeathRecipient(*sid, ServerDead3, NULL, &cbId4); - RPC_LOG_INFO("add death callback cbid4 = %{public}d", ret); - ret = AddDeathRecipient(*sid, ServerDead3, NULL, &cbId5); // failed - RPC_LOG_INFO("add death callback cbid5 = %{public}d, ret = %{public}d", cbId5, ret); - - RPC_LOG_INFO("============= test case for remove death callback ============"); - ret = RemoveDeathRecipient(*sid, cbId2); - RPC_LOG_INFO("remove death callback2 ret = %{public}d", ret); - ret = RemoveDeathRecipient(*sid, cbId4); - RPC_LOG_INFO("remove death callback4 ret = %{public}d", ret); - ret = RemoveDeathRecipient(*sid, cbId1); - RPC_LOG_INFO("remove death callback1 ret = %{public}d", ret); - ret = RemoveDeathRecipient(*sid, cbId3); - RPC_LOG_INFO("remove death callback3 ret = %{public}d", ret); - - - int handleOld = sid->handle; - sid->handle = 17; - ret = AddDeathRecipient(*sid, ServerDead3, NULL, &cbId5); // failed - RPC_LOG_INFO("add invalid death callback cbid5 = %{public}d, ret = %{public}d", cbId5, ret); - - ret = RemoveDeathRecipient(*sid, cbId3); - RPC_LOG_INFO("remove invalid death callback ret = %{public}d", ret); - - sid->handle = handleOld; - - ret = AddDeathRecipient(*sid, ServerDead1, NULL, &cbId1); - RPC_LOG_INFO("add death callback cbid1 = %{public}d", ret); - ret = AddDeathRecipient(*sid, ServerDead2, NULL, &cbId2); - RPC_LOG_INFO("add death callback cbid2 = %{public}d", ret); - JoinWorkThread(); - return -1; -} \ No newline at end of file diff --git a/test/ipc/samgr/BUILD.gn b/test/ipc/samgr/BUILD.gn deleted file mode 100644 index c6b320d..0000000 --- a/test/ipc/samgr/BUILD.gn +++ /dev/null @@ -1,41 +0,0 @@ -# Copyright (c) 2020 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. - -import("//build/lite/config/component/lite_component.gni") - -SUBSYSTEM_DIR = "//foundation/communication/ipc/test" -IPC_CORE_ROOT = "//foundation/communication/ipc/ipc/native/c" - -executable("samgr") { - sources = [ - "$SUBSYSTEM_DIR/ipc/samgr/samgr.c", - ] - include_dirs = [ - "//third_party/bounds_checking_function/include", - "//utils/native/lite/include", - "$IPC_CORE_ROOT/manager/include", - "$IPC_CORE_ROOT/ipc/include", - "//foundation/communication/ipc/services/dbinder/c/include", - "//base/hiviewdfx/hilog_lite/interfaces/native/innerkits", - ] - ldflags = [ - "-lstdc++", - "-lpthread", - ] - deps = [ - "//foundation/communication/ipc/interfaces/innerkits/c/ipc:ipc_single", - # "//foundation/communication/ipc/interfaces/innerkits/c/dbinder:dbinder", - ] - - configs -= [ "//build/lite/config:clang_opt" ] -} diff --git a/test/ipc/samgr/samgr.c b/test/ipc/samgr/samgr.c deleted file mode 100644 index 272143e..0000000 --- a/test/ipc/samgr/samgr.c +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (c) 2021 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 -#include - -#include "rpc_log.h" -#include "rpc_errno.h" -#include "ipc_skeleton.h" -#include "serializer.h" -#include "utils_list.h" - -typedef struct { - UTILS_DL_LIST list; - int32_t saId; - SvcIdentity *sid; -} SvcInfo; - -static UTILS_DL_LIST *g_saList = NULL; - -enum { - GET_SYSTEM_ABILITY_TRANSACTION = 1, - ADD_SYSTEM_ABILITY_TRANSACTION = 2, - GET_REMOTE_SYSTEM_ABILITY_TRANSACTION = 3, - ADD_REMOTE_SYSTEM_ABILITY_TRANSACTION = 4, -}; - -int32_t AddSystemAbility(int32_t saId, SvcIdentity *sid) -{ - if (g_saList == NULL) { - return ERR_FAILED; - } - - SvcInfo* node = (SvcInfo *)calloc(1, sizeof(SvcInfo)); - node->saId = saId; - node->sid = sid; - UtilsListAdd(g_saList, &node->list); - return 23; -} - -int32_t GetSystemAbility(int32_t saId, const char* deviceId, SvcIdentity *sid) -{ - SvcInfo* node = NULL; - SvcInfo* next = NULL; - UTILS_DL_LIST_FOR_EACH_ENTRY_SAFE(node, next, g_saList, SvcInfo, list) - { - if (node->saId == saId) { - sid->handle = node->sid->handle; - sid->token = node->sid->token; - sid->cookie = node->sid->cookie; - return ERR_NONE; - } - } - return ERR_FAILED; -} - -int32_t RemoteRequest(uint32_t code, IpcIo *data, IpcIo *reply, MessageOption option) -{ - int32_t result = ERR_NONE; - RPC_LOG_INFO("OnRemoteRequest called.... code = %{public}d", code); - switch (code) { - case ADD_SYSTEM_ABILITY_TRANSACTION: { - int32_t saId = IpcIoPopInt32(data); - RPC_LOG_INFO("samgr pop said = %{public}d....", saId); - SvcIdentity *sid = (SvcIdentity *)malloc(sizeof(SvcIdentity)); - IpcIoPopSvc(data, sid); - result = AddSystemAbility(saId, sid); - break; - } - case GET_SYSTEM_ABILITY_TRANSACTION: { - int32_t saId = IpcIoPopInt32(data); - SvcIdentity sid; - result = GetSystemAbility(saId, "", &sid); - if (result != ERR_NONE) { - return result; - } - IpcIoPushSvc(reply, &sid); - break; - } - default: - RPC_LOG_ERROR("unknown code %{public}d", code); - break; - } - return result; -} - -int main(int argc, char *argv[]) -{ - RPC_LOG_INFO("Enter System Ability Manager .... "); - - g_saList = (UTILS_DL_LIST *)calloc(1, sizeof(UTILS_DL_LIST)); - UtilsListInit(g_saList); - - IpcObjectStub objectStub = { - .func = RemoteRequest, - .isRemote = false - }; - - SvcIdentity target = { - .handle = 0, - .cookie = &objectStub - }; - - if (SetContextObject(target) != ERR_NONE) { - RPC_LOG_ERROR("SAMGR register samgr failed"); - return -1; - } - - JoinWorkThread(); - return -1; -} \ No newline at end of file diff --git a/test/ipc/server/BUILD.gn b/test/ipc/server/BUILD.gn deleted file mode 100644 index 1a659f5..0000000 --- a/test/ipc/server/BUILD.gn +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright (c) 2020 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. - -import("//build/lite/config/component/lite_component.gni") - -SUBSYSTEM_DIR = "//foundation/communication/ipc/test" -IPC_CORE_ROOT = "//foundation/communication/ipc/ipc/native/c" - -executable("ipc_server") { - sources = [ - "$SUBSYSTEM_DIR/ipc/server/server.c", - ] - include_dirs = [ - "//third_party/bounds_checking_function/include", - "//utils/native/lite/include", - "$IPC_CORE_ROOT/manager/include", - "//base/hiviewdfx/hilog_lite/interfaces/native/innerkits", - ] - ldflags = [ - "-lstdc++", - "-lpthread", - ] - deps = [ - "//foundation/communication/ipc/interfaces/innerkits/c/ipc:ipc_single" - ] - - configs -= [ "//build/lite/config:clang_opt" ] -} diff --git a/test/ipc/server/server.c b/test/ipc/server/server.c deleted file mode 100644 index 5cfa2cd..0000000 --- a/test/ipc/server/server.c +++ /dev/null @@ -1,210 +0,0 @@ -/* - * Copyright (c) 2021 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 -#include -#include "rpc_log.h" -#include "rpc_errno.h" -#include "ipc_skeleton.h" -#include "serializer.h" -#include - -enum { - OP_ADD = 1, - OP_SUB = 2, - OP_MULTI = 3, - OP_ADD_SERVICE = 4, -}; - -static SvcIdentity *sid = NULL; - -static void CallAnonymosFunc(const char *str) -{ - if (sid == NULL) { - RPC_LOG_INFO("invalid anonymous client"); - return; - } - RPC_LOG_INFO("now server call client anonymous func"); - IpcIo data; - uint8_t tmpData1[128]; - IpcIoInit(&data, tmpData1, 128, 1); - IpcIoPushString(&data, str); - - IpcIo reply; - MessageOption option = TF_OP_ASYNC; - SendRequest(*sid, 3, &data, &reply, option, NULL); -} - -int32_t RemoteRequestOne(uint32_t code, IpcIo *data, IpcIo *reply, MessageOption option) -{ - int32_t result = ERR_NONE; - RPC_LOG_INFO("server OnRemoteRequestOne called...."); - switch (code) { - case OP_ADD: { - int32_t a = IpcIoPopInt32(data); - int32_t b = IpcIoPopInt32(data); - IpcIoPushInt32(reply, a + b); - break; - } - case OP_SUB: { - int32_t a = IpcIoPopInt32(data); - int32_t b = IpcIoPopInt32(data); - IpcIoPushInt32(reply, a - b); - break; - } - case OP_MULTI: { - int32_t a = IpcIoPopInt32(data); - int32_t b = IpcIoPopInt32(data); - IpcIoPushInt32(reply, a * b); - break; - } - case OP_ADD_SERVICE: { - sid = (SvcIdentity *)malloc(sizeof(SvcIdentity)); - IpcIoPopSvc(data, sid); - result = 77; - const char *str = "server call anonymos service one."; - CallAnonymosFunc(str); - break; - } - default: - RPC_LOG_ERROR("unknown code %{public}d", code); - break; - } - return result; -} - -int32_t RemoteRequestTwo(uint32_t code, IpcIo *data, IpcIo *reply, MessageOption option) -{ - int32_t result = ERR_NONE; - RPC_LOG_INFO("server OnRemoteRequestTwo called...."); - switch (code) { - case OP_ADD: { - int32_t a = IpcIoPopInt32(data); - int32_t b = IpcIoPopInt32(data); - IpcIoPushInt32(reply, a + b); - break; - } - case OP_SUB: { - int32_t a = IpcIoPopInt32(data); - int32_t b = IpcIoPopInt32(data); - IpcIoPushInt32(reply, a - b); - break; - } - case OP_MULTI: { - int32_t a = IpcIoPopInt32(data); - int32_t b = IpcIoPopInt32(data); - IpcIoPushInt32(reply, a * b); - break; - } - default: - RPC_LOG_ERROR("unknown code %{public}d", code); - break; - } - return result; -} - -static void *ThreadHandler() -{ - sleep(120); // sleep 2 min - const char *str = "server call anonymos service new thread."; - CallAnonymosFunc(str); - return NULL; -} - -int main(int argc, char *argv[]) -{ - RPC_LOG_INFO("Enter System Ability Server .... "); - - IpcObjectStub objectStubOne = { - .func = RemoteRequestOne, - .isRemote = false - }; - - IpcObjectStub objectStubTwo = { - .func = RemoteRequestTwo, - .isRemote = false - }; - - SvcIdentity svcOne = { - .handle = -1, - .token = &objectStubOne, - .cookie = &objectStubOne - }; - - SvcIdentity svcTwo = { - .handle = -1, - .token = &objectStubTwo, - .cookie = &objectStubTwo - }; - - IpcIo data; - uint8_t tmpData1[128]; - IpcIoInit(&data, tmpData1, 128, 1); - IpcIoPushInt32(&data, 15); - IpcIoPushSvc(&data, &svcOne); - - IpcIo dataTwo; - uint8_t tmpData2[128]; - IpcIoInit(&dataTwo, tmpData2, 128, 1); - IpcIoPushInt32(&dataTwo, 18); - IpcIoPushSvc(&dataTwo, &svcTwo); - - IpcIo reply; - MessageOption option = TF_OP_SYNC; - - SvcIdentity target = { - .handle = 0 - }; - - RPC_LOG_INFO("====== add ability one to samgr ======"); - uintptr_t ptr = 0; - int ret = SendRequest(target, 2, &data, &reply, option, &ptr); - FreeBuffer((void *)ptr); - - sleep(2); - RPC_LOG_INFO("====== add ability two to samgr ======"); - ret = SendRequest(target, 2, &dataTwo, &reply, option, &ptr); - RPC_LOG_INFO("send request two ret = %{public}d .... ", IpcIoPopInt32(&reply)); - FreeBuffer((void *)ptr); - - sleep(2); - RPC_LOG_INFO("====== get ability one from samgr ======"); - IpcIo data1; - uint8_t dataGet[64]; - IpcIoInit(&data1, dataGet, 64, 0); - IpcIoPushInt32(&data1, 15); - ret = SendRequest(target, 1, &data1, &reply, option, &ptr); - SvcIdentity sidOne; - IpcIoPopSvc(&reply, &sidOne); - FreeBuffer((void *)ptr); - - sleep(2); - RPC_LOG_INFO("====== call serverone OP_MULTI ======"); - IpcIo data2; - uint8_t dataMulti[128]; - IpcIoInit(&data2, dataMulti, 128, 0); - IpcIoPushInt32(&data2, 12); - IpcIoPushInt32(&data2, 17); - - ret = SendRequest(sidOne, OP_MULTI, &data2, &reply, option, &ptr); - RPC_LOG_INFO(" 12 * 17 = %{public}d", IpcIoPopInt32(&reply)); - FreeBuffer((void *)ptr); - - pthread_t pid; - ret = pthread_create(&pid, NULL, ThreadHandler, NULL); - pthread_detach(pid); - JoinWorkThread(); - return -1; -} \ No newline at end of file diff --git a/test/resource/ipc/ohos_test.xml b/test/resource/ipc/ohos_test.xml deleted file mode 100755 index b52fa50..0000000 --- a/test/resource/ipc/ohos_test.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/test/resource/services/ohos_test.xml b/test/resource/services/ohos_test.xml deleted file mode 100755 index 47806f0..0000000 --- a/test/resource/services/ohos_test.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - -- GitLab