提交 9de05f1e 编写于 作者: L liubb_0516

modify coding style

Signed-off-by: Nliubb_0516 <liubeibei8@huawei.com>
上级 42e14e99
......@@ -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);
......
......@@ -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 <stdbool.h>
#include <stddef.h>
......@@ -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 */
......@@ -16,12 +16,12 @@
#include <unistd.h>
#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
......@@ -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
......@@ -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
}
......
......@@ -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);
......
......@@ -15,10 +15,12 @@
#ifndef _UAPI_LINUX_BINDER_H
#define _UAPI_LINUX_BINDER_H
#include <linux/types.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <linux/types.h>
#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
......@@ -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;
......
......@@ -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);
......
......@@ -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;
}
......
......@@ -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.");
......
......@@ -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);
......
......@@ -23,7 +23,7 @@ RemoteInvoker *InitRemoteInvoker(int32_t proto)
RemoteInvoker *remoteInvoker = NULL;
if (proto == IF_PROT_BINDER) {
remoteInvoker = GetIpcInvoker();
}
}
return remoteInvoker;
}
......
......@@ -17,7 +17,7 @@
#include "securec.h"
#include <stdlib.h>
#include <string.h>
#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;
}
......
# 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
# 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" ]
}
/*
* 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 <stdlib.h>
#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
# 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" ]
}
/*
* 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 <stdlib.h>
#include <string.h>
#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
# 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" ]
}
/*
* 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 <stdlib.h>
#include <pthread.h>
#include "rpc_log.h"
#include "rpc_errno.h"
#include "ipc_skeleton.h"
#include "serializer.h"
#include <unistd.h>
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
<?xml version="1.0" encoding="UTF-8"?>
<!-- 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.
-->
<configuration ver="2.0">
<target name="IPCNativeFrameworksTest">
<preparer>
<option name="push" value="communication/ipc/ipc_server_test -> /system/bin" src="out"/>
<option name="push" value="communication/ipc/libipc_test_helper.z.so -> /system/lib64" src="out"/>
<option name="push" value="communication/ipc/ipc_server_test_extra -> /system/bin" src="out"/>
<option name="push" value="communication/ipc/libipc_test_helper_extra.z.so -> /system/lib64" src="out"/>
<option name="push" value="communication/ipc/libipc_test_helper.z.so -> /system/lib" src="out"/>
<option name="push" value="communication/ipc/libipc_test_helper_extra.z.so -> /system/lib" src="out"/>
</preparer>
</target>
<target name="IPCNativeUnitTest">
<preparer>
<option name="push" value="communication/ipc/ipc_server_test -> /system/bin" src="out"/>
<option name="push" value="communication/ipc/ipc_client_test -> /system/bin" src="out"/>
<option name="push" value="communication/ipc/libipc_test_helper.z.so -> /system/lib64" src="out"/>
<option name="push" value="communication/ipc/libipc_test_helper.z.so -> /system/lib" src="out"/>
</preparer>
</target>
<target name="BinderTraceTest">
<preparer>
<option name="push" value="communication/ipc/ipc_server_test -> /system/bin" src="out"/>
<option name="push" value="communication/ipc/ipc_client_test -> /system/bin" src="out"/>
<option name="push" value="communication/ipc/libipc_test_helper.z.so -> /system/lib64" src="out"/>
<option name="push" value="communication/ipc/libipc_test_helper.z.so -> /system/lib" src="out"/>
</preparer>
</target>
<target name="IPCFileDescOpsTest">
<preparer>
<option name="push" value="communication/ipc/libipc_test_helper.z.so -> /system/lib64" src="out"/>
<option name="push" value="communication/ipc/libipc_test_helper.z.so -> /system/lib" src="out"/>
</preparer>
</target>
</configuration>
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<configuration ver="2.0">
<target name="DbinderTest">
<preparer>
<option name="push" value="communication/ipc/dbinder_test -> /data/test" src="out" />
<option name="push" value="communication/ipc/dbinder_send -> /data/test" src="out" />
</preparer>
</target>
<target name="DbinderTestAgent">
<preparer>
<option name="push" value="communication/ipc/dbinder_test -> /data/test" src="out" />
<option name="push" value="communication/ipc/dbinder_send -> /data/test" src="out" />
</preparer>
</target>
</configuration>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册