diff --git a/interfaces/innerkits/c/ipc/include/ipc_skeleton.h b/interfaces/innerkits/c/ipc/include/ipc_skeleton.h index b8f6368c0caf5d8b6fb1ef87f8fef7185914642f..b6c5a49f00f951392c3982628141a80834ce9181 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 d6de8161c7ea2e9ba15cc2c88829ac1843e8f681..1c86cea77717a6407a4715d98260fd194a0e6af0 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 d18d918600673242e31bff106db27b8d03e8e695..9214d260134e70aff5fe616ef265a18fe749fadf 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 397a9b919368271a6c943ae3c4617f0eafc5fc57..faeb00c79813daf01b14ec76df797a1223e63f79 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 6669577b390ff10e8e5603de8b88d9a99cb99e63..128af4f127e3bef936c39fad8f16e78e98778b70 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 44697f80108b2644a2861d141a4f6a4b41b7fd4d..ed033501b941b9c6de27b595fb1726f93d65cea6 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 fc8d6a509419622d775c93d3686c68d1583d2f61..f1eba799bf263b3ad815cc4eed1a87bab9548094 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 0e7d77f9c117bc7983fdd36c45c4dc38851d2258..34636d653120d40fca5fc20c29cfb0f38062dbc9 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 ebbe1d5f846ae0a955f38f17a9272014315e7fe5..7e9c8e81a27bc48df4b56325da3e55bed8c2a7a8 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 a59dc680e8ef7b41d8cfab564354bf7e8edf39fd..02dbd165315b65e76737f3ad838873814e22d93c 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 7a68d82e8ed6949d0f0ea029df7907ebd42a2087..c1848cd6d49251b546cedbcab2e29eaa97a79a1f 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 c6d96d8cca72e3d0638bb462bed353c0ac5e5edd..24b3c571de48dadcf2da27ccb2508b477f6ebda4 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 0fab2fc9ae57bddb94f593679e0d05e9c2ac67a9..7757a973a9bad5e3ecc1bc7f2617d771f90c68e7 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 a5746dd685f7c2e72bb112648048620f1ae3e145..c19711b941fd52862c26004ed015f63cfd383076 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 5768ac71a85efcd8c726dbe791c0a6d36dde194b..0000000000000000000000000000000000000000 --- 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 b4b893bfd28b1b9043087c03b8f35eef1f6a14ad..0000000000000000000000000000000000000000 --- 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 33ff50d724bf9db0703703abe50c1d8b42f71303..0000000000000000000000000000000000000000 --- 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 c6b320d50f4d245a3a81e7ebb9df36fb29327429..0000000000000000000000000000000000000000 --- 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 272143e2559915a1543b1ce3467e80bc4b1752b8..0000000000000000000000000000000000000000 --- 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 1a659f5a46f50805eed83c603f8f12a087ff5400..0000000000000000000000000000000000000000 --- 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 5cfa2cd81e1ad60ba1db6a8caf5f2159efb33543..0000000000000000000000000000000000000000 --- 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 b52fa50841efa21125fc8debf35f7509e24aa958..0000000000000000000000000000000000000000 --- 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 47806f0a191f137a67d6fd063d9655431b5c1960..0000000000000000000000000000000000000000 --- a/test/resource/services/ohos_test.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - -