mirror of
https://gitee.com/openharmony/communication_ipc
synced 2024-11-26 17:41:17 +00:00
doc to unix
Sig:SIG_ApplicationFramework Feature or Bugfix:Bugfix Binary Source:No Signed-off-by: @ma-gentang <magentang3@huawei.com> Signed-off-by: 18392170496 <magentang3@huawei.com>
This commit is contained in:
parent
0eece5fa53
commit
7cb1570c6f
218
bundle.json
218
bundle.json
@ -1,109 +1,109 @@
|
||||
{
|
||||
"name": "@openharmony/ipc",
|
||||
"version": "3.1.0",
|
||||
"description": "ipc",
|
||||
"publishAs": "code-segment",
|
||||
"scripts": {
|
||||
"install": "DEST_PATH=${DEP_BUNDLE_BASE}/foundation/communication/ipc && mkdir -p $DEST_PATH && cp -r ./* $DEST_PATH"
|
||||
},
|
||||
"author": {},
|
||||
"repository": "",
|
||||
"license": "Apache License 2.0",
|
||||
"segment": {
|
||||
"destPath": "foundation/communication/ipc"
|
||||
},
|
||||
"component": {
|
||||
"name": "ipc",
|
||||
"subsystem": "communication",
|
||||
"adapted_system_type": [
|
||||
"standard",
|
||||
"small",
|
||||
"mini"
|
||||
],
|
||||
"features": [],
|
||||
"syscap":[
|
||||
"SystemCapability.Communication.IPC.Core"
|
||||
],
|
||||
"rom": "500KB",
|
||||
"ram": "100KB",
|
||||
"deps": {
|
||||
"components": [
|
||||
"samgr",
|
||||
"hitrace_native",
|
||||
"hiviewdfx_hilog_native",
|
||||
"c_utils",
|
||||
"access_token",
|
||||
"dsoftbus"
|
||||
],
|
||||
"third_party": [
|
||||
"bounds_checking_function"
|
||||
]
|
||||
},
|
||||
"build": {
|
||||
"sub_component": [
|
||||
"//foundation/communication/ipc:ipc_components"
|
||||
],
|
||||
"inner_kits": [
|
||||
{
|
||||
"name": "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core",
|
||||
"header": {
|
||||
"header_files": [
|
||||
"ipc_types.h",
|
||||
"ipc_skeleton.h",
|
||||
"iremote_object.h",
|
||||
"iremote_proxy.h",
|
||||
"iremote_stub.h",
|
||||
"message_parcel.h",
|
||||
"message_option.h",
|
||||
"iremote_broker.h",
|
||||
"ipc_object_proxy.h",
|
||||
"ipc_object_stub.h",
|
||||
"peer_holder.h",
|
||||
"ipc_file_descriptor.h",
|
||||
"jni_help.h"
|
||||
],
|
||||
"header_base": "//foundation/communication/ipc/interfaces/innerkits/ipc_core/include"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "//foundation/communication/ipc/interfaces/innerkits/ipc_single:ipc_single",
|
||||
"header": {
|
||||
"header_files": [
|
||||
"ipc_types.h",
|
||||
"ipc_skeleton.h",
|
||||
"iremote_object.h",
|
||||
"iremote_proxy.h",
|
||||
"iremote_stub.h",
|
||||
"message_parcel.h",
|
||||
"message_option.h",
|
||||
"iremote_broker.h",
|
||||
"ipc_object_proxy.h",
|
||||
"ipc_object_stub.h",
|
||||
"peer_holder.h",
|
||||
"ipc_file_descriptor.h",
|
||||
"jni_help.h"
|
||||
],
|
||||
"header_base": "//foundation/communication/ipc/interfaces/innerkits/ipc_core/include"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "//foundation/communication/ipc/interfaces/innerkits/libdbinder:libdbinder",
|
||||
"header": {
|
||||
"header_files": [
|
||||
"dbinder_service.h",
|
||||
"dbinder_service_stub.h"
|
||||
],
|
||||
"header_base": "//foundation/communication/ipc/interfaces/innerkits/libdbinder/include"
|
||||
}
|
||||
}
|
||||
],
|
||||
"test": [
|
||||
"//foundation/communication/ipc/ipc/test:moduletest",
|
||||
"//foundation/communication/ipc/ipc/native/test:unittest",
|
||||
"//foundation/communication/ipc/ipc/native/test/fuzztest:fuzztest",
|
||||
"//foundation/communication/ipc/services/dbinder/test/unittest:unittest",
|
||||
"//foundation/communication/ipc/services/dbinder/test/fuzztest:fuzztest"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
"name": "@openharmony/ipc",
|
||||
"version": "3.1.0",
|
||||
"description": "ipc",
|
||||
"publishAs": "code-segment",
|
||||
"scripts": {
|
||||
"install": "DEST_PATH=${DEP_BUNDLE_BASE}/foundation/communication/ipc && mkdir -p $DEST_PATH && cp -r ./* $DEST_PATH"
|
||||
},
|
||||
"author": {},
|
||||
"repository": "",
|
||||
"license": "Apache License 2.0",
|
||||
"segment": {
|
||||
"destPath": "foundation/communication/ipc"
|
||||
},
|
||||
"component": {
|
||||
"name": "ipc",
|
||||
"subsystem": "communication",
|
||||
"adapted_system_type": [
|
||||
"standard",
|
||||
"small",
|
||||
"mini"
|
||||
],
|
||||
"features": [],
|
||||
"syscap":[
|
||||
"SystemCapability.Communication.IPC.Core"
|
||||
],
|
||||
"rom": "500KB",
|
||||
"ram": "100KB",
|
||||
"deps": {
|
||||
"components": [
|
||||
"samgr",
|
||||
"hitrace_native",
|
||||
"hiviewdfx_hilog_native",
|
||||
"c_utils",
|
||||
"access_token",
|
||||
"dsoftbus"
|
||||
],
|
||||
"third_party": [
|
||||
"bounds_checking_function"
|
||||
]
|
||||
},
|
||||
"build": {
|
||||
"sub_component": [
|
||||
"//foundation/communication/ipc:ipc_components"
|
||||
],
|
||||
"inner_kits": [
|
||||
{
|
||||
"name": "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core",
|
||||
"header": {
|
||||
"header_files": [
|
||||
"ipc_types.h",
|
||||
"ipc_skeleton.h",
|
||||
"iremote_object.h",
|
||||
"iremote_proxy.h",
|
||||
"iremote_stub.h",
|
||||
"message_parcel.h",
|
||||
"message_option.h",
|
||||
"iremote_broker.h",
|
||||
"ipc_object_proxy.h",
|
||||
"ipc_object_stub.h",
|
||||
"peer_holder.h",
|
||||
"ipc_file_descriptor.h",
|
||||
"jni_help.h"
|
||||
],
|
||||
"header_base": "//foundation/communication/ipc/interfaces/innerkits/ipc_core/include"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "//foundation/communication/ipc/interfaces/innerkits/ipc_single:ipc_single",
|
||||
"header": {
|
||||
"header_files": [
|
||||
"ipc_types.h",
|
||||
"ipc_skeleton.h",
|
||||
"iremote_object.h",
|
||||
"iremote_proxy.h",
|
||||
"iremote_stub.h",
|
||||
"message_parcel.h",
|
||||
"message_option.h",
|
||||
"iremote_broker.h",
|
||||
"ipc_object_proxy.h",
|
||||
"ipc_object_stub.h",
|
||||
"peer_holder.h",
|
||||
"ipc_file_descriptor.h",
|
||||
"jni_help.h"
|
||||
],
|
||||
"header_base": "//foundation/communication/ipc/interfaces/innerkits/ipc_core/include"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "//foundation/communication/ipc/interfaces/innerkits/libdbinder:libdbinder",
|
||||
"header": {
|
||||
"header_files": [
|
||||
"dbinder_service.h",
|
||||
"dbinder_service_stub.h"
|
||||
],
|
||||
"header_base": "//foundation/communication/ipc/interfaces/innerkits/libdbinder/include"
|
||||
}
|
||||
}
|
||||
],
|
||||
"test": [
|
||||
"//foundation/communication/ipc/ipc/test:moduletest",
|
||||
"//foundation/communication/ipc/ipc/native/test:unittest",
|
||||
"//foundation/communication/ipc/ipc/native/test/fuzztest:fuzztest",
|
||||
"//foundation/communication/ipc/services/dbinder/test/unittest:unittest",
|
||||
"//foundation/communication/ipc/services/dbinder/test/fuzztest:fuzztest"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,81 +1,81 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IPC_RPC_SKELETON_H
|
||||
#define OHOS_IPC_RPC_SKELETON_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "serializer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
enum {
|
||||
TF_OP_SYNC = 0x00,
|
||||
TF_OP_ASYNC = 0x01,
|
||||
TF_OP_STATUS_CODE = 0x08,
|
||||
TF_OP_ACCEPT_FDS = 0x10,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint32_t flags;
|
||||
uint32_t waitTime;
|
||||
void *args;
|
||||
} MessageOption;
|
||||
|
||||
typedef int32_t (*OnRemoteRequest)(uint32_t code, IpcIo *data, IpcIo *reply, MessageOption option);
|
||||
typedef void (*OnRemoteDead)(void *args);
|
||||
|
||||
typedef struct {
|
||||
OnRemoteRequest func;
|
||||
void *args;
|
||||
bool isRemote;
|
||||
} IpcObjectStub;
|
||||
|
||||
// default is 4
|
||||
int32_t SetMaxWorkThreadNum(int32_t maxThreadNum);
|
||||
|
||||
// join current thread into work loop.
|
||||
void JoinWorkThread(void);
|
||||
|
||||
pid_t GetCallingPid(void);
|
||||
|
||||
pid_t GetCallingUid(void);
|
||||
|
||||
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 FreeBuffer(void *ptr);
|
||||
|
||||
int32_t AddDeathRecipient(SvcIdentity target, OnRemoteDead deathFunc, void *args, uint32_t *cbId);
|
||||
|
||||
int32_t RemoveDeathRecipient(SvcIdentity target, uint32_t cbId);
|
||||
|
||||
int32_t MessageOptionInit(MessageOption *option);
|
||||
|
||||
int32_t ReleaseSvc(SvcIdentity target);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* OHOS_IPC_RPC_SKELETON_H */
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IPC_RPC_SKELETON_H
|
||||
#define OHOS_IPC_RPC_SKELETON_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "serializer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
enum {
|
||||
TF_OP_SYNC = 0x00,
|
||||
TF_OP_ASYNC = 0x01,
|
||||
TF_OP_STATUS_CODE = 0x08,
|
||||
TF_OP_ACCEPT_FDS = 0x10,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint32_t flags;
|
||||
uint32_t waitTime;
|
||||
void *args;
|
||||
} MessageOption;
|
||||
|
||||
typedef int32_t (*OnRemoteRequest)(uint32_t code, IpcIo *data, IpcIo *reply, MessageOption option);
|
||||
typedef void (*OnRemoteDead)(void *args);
|
||||
|
||||
typedef struct {
|
||||
OnRemoteRequest func;
|
||||
void *args;
|
||||
bool isRemote;
|
||||
} IpcObjectStub;
|
||||
|
||||
// default is 4
|
||||
int32_t SetMaxWorkThreadNum(int32_t maxThreadNum);
|
||||
|
||||
// join current thread into work loop.
|
||||
void JoinWorkThread(void);
|
||||
|
||||
pid_t GetCallingPid(void);
|
||||
|
||||
pid_t GetCallingUid(void);
|
||||
|
||||
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 FreeBuffer(void *ptr);
|
||||
|
||||
int32_t AddDeathRecipient(SvcIdentity target, OnRemoteDead deathFunc, void *args, uint32_t *cbId);
|
||||
|
||||
int32_t RemoveDeathRecipient(SvcIdentity target, uint32_t cbId);
|
||||
|
||||
int32_t MessageOptionInit(MessageOption *option);
|
||||
|
||||
int32_t ReleaseSvc(SvcIdentity target);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* OHOS_IPC_RPC_SKELETON_H */
|
||||
|
@ -1,34 +1,34 @@
|
||||
/*
|
||||
* Copyright (C) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IPC_RPC_ERRNO_H
|
||||
#define OHOS_IPC_RPC_ERRNO_H
|
||||
|
||||
enum IpcRpcErrNo {
|
||||
ERR_NONE = 0,
|
||||
ERR_FAILED = -1,
|
||||
ERR_INVALID_PARAM = -2,
|
||||
ERR_IPC_SKELETON_NOT_INIT = -3,
|
||||
ERR_THREAD_INVOKER_NOT_INIT = -4,
|
||||
ERR_NOT_RPC = -16,
|
||||
ERR_DEAD_OBJECT = -32,
|
||||
IPC_INVOKER_INVALID_DATA = -33,
|
||||
IPC_INVOKER_FAILED_REPLY = -34,
|
||||
IPC_INVOKER_UNKNOWN_CODE = -35,
|
||||
IPC_INVOKER_IOCTL_FAILED = -36,
|
||||
};
|
||||
|
||||
#endif /* OHOS_IPC_RPC_ERRNO_H */
|
||||
|
||||
/*
|
||||
* Copyright (C) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IPC_RPC_ERRNO_H
|
||||
#define OHOS_IPC_RPC_ERRNO_H
|
||||
|
||||
enum IpcRpcErrNo {
|
||||
ERR_NONE = 0,
|
||||
ERR_FAILED = -1,
|
||||
ERR_INVALID_PARAM = -2,
|
||||
ERR_IPC_SKELETON_NOT_INIT = -3,
|
||||
ERR_THREAD_INVOKER_NOT_INIT = -4,
|
||||
ERR_NOT_RPC = -16,
|
||||
ERR_DEAD_OBJECT = -32,
|
||||
IPC_INVOKER_INVALID_DATA = -33,
|
||||
IPC_INVOKER_FAILED_REPLY = -34,
|
||||
IPC_INVOKER_UNKNOWN_CODE = -35,
|
||||
IPC_INVOKER_IOCTL_FAILED = -36,
|
||||
};
|
||||
|
||||
#endif /* OHOS_IPC_RPC_ERRNO_H */
|
||||
|
||||
|
@ -1,137 +1,137 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IPC_RPC_SERIALIZER_H
|
||||
#define OHOS_IPC_RPC_SERIALIZER_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
typedef struct {
|
||||
char *bufferBase;
|
||||
size_t *offsetsBase;
|
||||
char *bufferCur;
|
||||
size_t *offsetsCur;
|
||||
size_t bufferLeft;
|
||||
size_t offsetsLeft;
|
||||
uint32_t flag;
|
||||
} IpcIo;
|
||||
|
||||
typedef struct {
|
||||
int32_t handle;
|
||||
uintptr_t token;
|
||||
uintptr_t cookie;
|
||||
} SvcIdentity;
|
||||
|
||||
typedef enum {
|
||||
SERVICE_TYPE_ANONYMOUS,
|
||||
SERVICE_TYPE_NORMAL
|
||||
} ServiceType;
|
||||
|
||||
#define IPC_INVALID_HANDLE (-1)
|
||||
#define IPC_IO_INITIALIZED 0x01 /* ipc flag indicates whether io is initialized */
|
||||
#define IPC_IO_OVERFLOW 0x02 /* ipc flag indicates whether io is running out of space */
|
||||
#define MAX_IO_SIZE 8192UL
|
||||
#define MAX_OBJ_NUM 32UL
|
||||
|
||||
void IpcIoInit(IpcIo* io, void* buffer, size_t bufferSize, size_t maxobjects);
|
||||
bool IpcIoAppend(IpcIo *dst, IpcIo *src);
|
||||
|
||||
bool WriteRemoteObject(IpcIo *io, const SvcIdentity *svc);
|
||||
bool WriteFileDescriptor(IpcIo *io, uint32_t fd);
|
||||
|
||||
bool ReadRemoteObject(IpcIo *io, SvcIdentity *svc);
|
||||
int32_t ReadFileDescriptor(IpcIo *io);
|
||||
|
||||
bool WriteBool(IpcIo *io, bool value);
|
||||
bool WriteInt8(IpcIo *io, int8_t value);
|
||||
bool WriteInt16(IpcIo *io, int16_t value);
|
||||
bool WriteInt32(IpcIo *io, int32_t value);
|
||||
bool WriteInt64(IpcIo *io, int64_t value);
|
||||
bool WriteUint8(IpcIo *io, uint8_t value);
|
||||
bool WriteUint16(IpcIo *io, uint16_t value);
|
||||
bool WriteUint32(IpcIo *io, uint32_t value);
|
||||
bool WriteUint64(IpcIo *io, uint64_t value);
|
||||
bool WriteBoolUnaligned(IpcIo *io, bool value);
|
||||
bool WriteInt8Unaligned(IpcIo *io, int8_t value);
|
||||
bool WriteInt16Unaligned(IpcIo *io, int16_t value);
|
||||
bool WriteUint8Unaligned(IpcIo *io, uint8_t value);
|
||||
bool WriteUint16Unaligned(IpcIo *io, uint16_t value);
|
||||
bool WriteFloat(IpcIo *io, float value);
|
||||
bool WriteDouble(IpcIo *io, double value);
|
||||
bool WritePointer(IpcIo *io, uintptr_t value);
|
||||
bool WriteString(IpcIo *io, const char *value);
|
||||
|
||||
bool ReadBool(IpcIo *io, bool *value);
|
||||
bool ReadInt8(IpcIo *io, int8_t *value);
|
||||
bool ReadInt16(IpcIo *io, int16_t *value);
|
||||
bool ReadInt32(IpcIo *io, int32_t *value);
|
||||
bool ReadInt64(IpcIo *io, int64_t *value);
|
||||
bool ReadUint8(IpcIo *io, uint8_t *value);
|
||||
bool ReadUint16(IpcIo *io, uint16_t *value);
|
||||
bool ReadUint32(IpcIo *io, uint32_t *value);
|
||||
bool ReadUint64(IpcIo *io, uint64_t *value);
|
||||
bool ReadFloat(IpcIo *io, float *value);
|
||||
bool ReadDouble(IpcIo *io, double *value);
|
||||
uintptr_t ReadPointer(IpcIo *io);
|
||||
bool ReadBoolUnaligned(IpcIo *io, bool *value);
|
||||
bool ReadInt8Unaligned(IpcIo *io, int8_t *value);
|
||||
bool ReadInt16Unaligned(IpcIo *io, int16_t *value);
|
||||
bool ReadUInt8Unaligned(IpcIo *io, uint8_t *value);
|
||||
bool ReadUInt16Unaligned(IpcIo *io, uint16_t *value);
|
||||
uint8_t *ReadString(IpcIo *io, size_t *len);
|
||||
|
||||
bool WriteString16(IpcIo *io, const uint16_t *value, size_t len);
|
||||
bool WriteBuffer(IpcIo *io, const void *data, size_t size);
|
||||
bool WriteInterfaceToken(IpcIo *io, const uint16_t *name, size_t len);
|
||||
bool WriteRawData(IpcIo *io, const void *data, size_t size);
|
||||
bool WriteBoolVector(IpcIo *io, const bool *val, size_t size);
|
||||
bool WriteInt8Vector(IpcIo *io, const int8_t *val, size_t size);
|
||||
bool WriteInt16Vector(IpcIo *io, const int16_t *val, size_t size);
|
||||
bool WriteInt32Vector(IpcIo *io, const int32_t *val, size_t size);
|
||||
bool WriteInt64Vector(IpcIo *io, const int64_t *val, size_t size);
|
||||
bool WriteUInt8Vector(IpcIo *io, const uint8_t *val, size_t size);
|
||||
bool WriteUInt16Vector(IpcIo *io, const uint16_t *val, size_t size);
|
||||
bool WriteUInt32Vector(IpcIo *io, const uint32_t *val, size_t size);
|
||||
bool WriteUInt64Vector(IpcIo *io, const uint64_t *val, size_t size);
|
||||
bool WriteFloatVector(IpcIo *io, const float *val, size_t size);
|
||||
bool WriteDoubleVector(IpcIo *io, const double *val, size_t size);
|
||||
|
||||
uint16_t *ReadString16(IpcIo *io, size_t *size);
|
||||
uint16_t *ReadInterfaceToken(IpcIo *io, size_t *size);
|
||||
const uint8_t *ReadBuffer(IpcIo *io, size_t size);
|
||||
void *ReadRawData(IpcIo *io, size_t size);
|
||||
bool *ReadBoolVector(IpcIo *io, size_t *size);
|
||||
int8_t *ReadInt8Vector(IpcIo *io, size_t *size);
|
||||
int16_t *ReadInt16Vector(IpcIo *io, size_t *size);
|
||||
int32_t *ReadInt32Vector(IpcIo *io, size_t *size);
|
||||
int64_t *ReadInt64Vector(IpcIo *io, size_t *size);
|
||||
uint8_t *ReadUInt8Vector(IpcIo *io, size_t *size);
|
||||
uint16_t *ReadUInt16Vector(IpcIo *io, size_t *size);
|
||||
uint32_t *ReadUInt32Vector(IpcIo *io, size_t *size);
|
||||
uint64_t *ReadUInt64Vector(IpcIo *io, size_t *size);
|
||||
float *ReadFloatVector(IpcIo *io, size_t *size);
|
||||
double *ReadDoubleVector(IpcIo *io, size_t *size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* OHOS_IPC_RPC_SERIALIZER_H */
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IPC_RPC_SERIALIZER_H
|
||||
#define OHOS_IPC_RPC_SERIALIZER_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
typedef struct {
|
||||
char *bufferBase;
|
||||
size_t *offsetsBase;
|
||||
char *bufferCur;
|
||||
size_t *offsetsCur;
|
||||
size_t bufferLeft;
|
||||
size_t offsetsLeft;
|
||||
uint32_t flag;
|
||||
} IpcIo;
|
||||
|
||||
typedef struct {
|
||||
int32_t handle;
|
||||
uintptr_t token;
|
||||
uintptr_t cookie;
|
||||
} SvcIdentity;
|
||||
|
||||
typedef enum {
|
||||
SERVICE_TYPE_ANONYMOUS,
|
||||
SERVICE_TYPE_NORMAL
|
||||
} ServiceType;
|
||||
|
||||
#define IPC_INVALID_HANDLE (-1)
|
||||
#define IPC_IO_INITIALIZED 0x01 /* ipc flag indicates whether io is initialized */
|
||||
#define IPC_IO_OVERFLOW 0x02 /* ipc flag indicates whether io is running out of space */
|
||||
#define MAX_IO_SIZE 8192UL
|
||||
#define MAX_OBJ_NUM 32UL
|
||||
|
||||
void IpcIoInit(IpcIo* io, void* buffer, size_t bufferSize, size_t maxobjects);
|
||||
bool IpcIoAppend(IpcIo *dst, IpcIo *src);
|
||||
|
||||
bool WriteRemoteObject(IpcIo *io, const SvcIdentity *svc);
|
||||
bool WriteFileDescriptor(IpcIo *io, uint32_t fd);
|
||||
|
||||
bool ReadRemoteObject(IpcIo *io, SvcIdentity *svc);
|
||||
int32_t ReadFileDescriptor(IpcIo *io);
|
||||
|
||||
bool WriteBool(IpcIo *io, bool value);
|
||||
bool WriteInt8(IpcIo *io, int8_t value);
|
||||
bool WriteInt16(IpcIo *io, int16_t value);
|
||||
bool WriteInt32(IpcIo *io, int32_t value);
|
||||
bool WriteInt64(IpcIo *io, int64_t value);
|
||||
bool WriteUint8(IpcIo *io, uint8_t value);
|
||||
bool WriteUint16(IpcIo *io, uint16_t value);
|
||||
bool WriteUint32(IpcIo *io, uint32_t value);
|
||||
bool WriteUint64(IpcIo *io, uint64_t value);
|
||||
bool WriteBoolUnaligned(IpcIo *io, bool value);
|
||||
bool WriteInt8Unaligned(IpcIo *io, int8_t value);
|
||||
bool WriteInt16Unaligned(IpcIo *io, int16_t value);
|
||||
bool WriteUint8Unaligned(IpcIo *io, uint8_t value);
|
||||
bool WriteUint16Unaligned(IpcIo *io, uint16_t value);
|
||||
bool WriteFloat(IpcIo *io, float value);
|
||||
bool WriteDouble(IpcIo *io, double value);
|
||||
bool WritePointer(IpcIo *io, uintptr_t value);
|
||||
bool WriteString(IpcIo *io, const char *value);
|
||||
|
||||
bool ReadBool(IpcIo *io, bool *value);
|
||||
bool ReadInt8(IpcIo *io, int8_t *value);
|
||||
bool ReadInt16(IpcIo *io, int16_t *value);
|
||||
bool ReadInt32(IpcIo *io, int32_t *value);
|
||||
bool ReadInt64(IpcIo *io, int64_t *value);
|
||||
bool ReadUint8(IpcIo *io, uint8_t *value);
|
||||
bool ReadUint16(IpcIo *io, uint16_t *value);
|
||||
bool ReadUint32(IpcIo *io, uint32_t *value);
|
||||
bool ReadUint64(IpcIo *io, uint64_t *value);
|
||||
bool ReadFloat(IpcIo *io, float *value);
|
||||
bool ReadDouble(IpcIo *io, double *value);
|
||||
uintptr_t ReadPointer(IpcIo *io);
|
||||
bool ReadBoolUnaligned(IpcIo *io, bool *value);
|
||||
bool ReadInt8Unaligned(IpcIo *io, int8_t *value);
|
||||
bool ReadInt16Unaligned(IpcIo *io, int16_t *value);
|
||||
bool ReadUInt8Unaligned(IpcIo *io, uint8_t *value);
|
||||
bool ReadUInt16Unaligned(IpcIo *io, uint16_t *value);
|
||||
uint8_t *ReadString(IpcIo *io, size_t *len);
|
||||
|
||||
bool WriteString16(IpcIo *io, const uint16_t *value, size_t len);
|
||||
bool WriteBuffer(IpcIo *io, const void *data, size_t size);
|
||||
bool WriteInterfaceToken(IpcIo *io, const uint16_t *name, size_t len);
|
||||
bool WriteRawData(IpcIo *io, const void *data, size_t size);
|
||||
bool WriteBoolVector(IpcIo *io, const bool *val, size_t size);
|
||||
bool WriteInt8Vector(IpcIo *io, const int8_t *val, size_t size);
|
||||
bool WriteInt16Vector(IpcIo *io, const int16_t *val, size_t size);
|
||||
bool WriteInt32Vector(IpcIo *io, const int32_t *val, size_t size);
|
||||
bool WriteInt64Vector(IpcIo *io, const int64_t *val, size_t size);
|
||||
bool WriteUInt8Vector(IpcIo *io, const uint8_t *val, size_t size);
|
||||
bool WriteUInt16Vector(IpcIo *io, const uint16_t *val, size_t size);
|
||||
bool WriteUInt32Vector(IpcIo *io, const uint32_t *val, size_t size);
|
||||
bool WriteUInt64Vector(IpcIo *io, const uint64_t *val, size_t size);
|
||||
bool WriteFloatVector(IpcIo *io, const float *val, size_t size);
|
||||
bool WriteDoubleVector(IpcIo *io, const double *val, size_t size);
|
||||
|
||||
uint16_t *ReadString16(IpcIo *io, size_t *size);
|
||||
uint16_t *ReadInterfaceToken(IpcIo *io, size_t *size);
|
||||
const uint8_t *ReadBuffer(IpcIo *io, size_t size);
|
||||
void *ReadRawData(IpcIo *io, size_t size);
|
||||
bool *ReadBoolVector(IpcIo *io, size_t *size);
|
||||
int8_t *ReadInt8Vector(IpcIo *io, size_t *size);
|
||||
int16_t *ReadInt16Vector(IpcIo *io, size_t *size);
|
||||
int32_t *ReadInt32Vector(IpcIo *io, size_t *size);
|
||||
int64_t *ReadInt64Vector(IpcIo *io, size_t *size);
|
||||
uint8_t *ReadUInt8Vector(IpcIo *io, size_t *size);
|
||||
uint16_t *ReadUInt16Vector(IpcIo *io, size_t *size);
|
||||
uint32_t *ReadUInt32Vector(IpcIo *io, size_t *size);
|
||||
uint64_t *ReadUInt64Vector(IpcIo *io, size_t *size);
|
||||
float *ReadFloatVector(IpcIo *io, size_t *size);
|
||||
double *ReadDoubleVector(IpcIo *io, size_t *size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* OHOS_IPC_RPC_SERIALIZER_H */
|
||||
|
@ -1,52 +1,52 @@
|
||||
{
|
||||
"name": "@openharmony/ipc_js",
|
||||
"version": "3.1.0",
|
||||
"description": "ipc_js",
|
||||
"publishAs": "code-segment",
|
||||
"scripts": {
|
||||
"install": "DEST_PATH=${DEP_BUNDLE_BASE}/foundation/communication/ipc_js && mkdir -p $DEST_PATH && cp -r ./* $DEST_PATH"
|
||||
},
|
||||
"author": {},
|
||||
"repository": "",
|
||||
"license": "Apache License 2.0",
|
||||
"segment": {
|
||||
"destPath": "foundation/communication/ipc/interfaces/kits"
|
||||
},
|
||||
"component": {
|
||||
"name": "ipc_js",
|
||||
"subsystem": "communication",
|
||||
"adapted_system_type": [
|
||||
"standard"
|
||||
],
|
||||
"features": [],
|
||||
"rom": "500KB",
|
||||
"ram": "100KB",
|
||||
"deps": {
|
||||
"components": [
|
||||
"//foundation/arkui/napi:ace_napi",
|
||||
"//third_party/libuv:uv",
|
||||
"//commonlibrary/c_utils/base:utils"
|
||||
],
|
||||
"third_party": [
|
||||
"bounds_checking_function"
|
||||
]
|
||||
},
|
||||
"build": {
|
||||
"sub_component": [
|
||||
"//foundation/communication/ipc/interfaces/kits/js/napi:rpc"
|
||||
],
|
||||
"inner_kits": [
|
||||
{
|
||||
"name": "//foundation/communication/ipc/interfaces/kits/js/napi:rpc",
|
||||
"header": {
|
||||
"header_files": [
|
||||
"napi_remote_object.h"
|
||||
],
|
||||
"header_base": "//foundation/communication/ipc/ipc/native/src/napi/include"
|
||||
}
|
||||
}
|
||||
],
|
||||
"test": [ ]
|
||||
}
|
||||
}
|
||||
{
|
||||
"name": "@openharmony/ipc_js",
|
||||
"version": "3.1.0",
|
||||
"description": "ipc_js",
|
||||
"publishAs": "code-segment",
|
||||
"scripts": {
|
||||
"install": "DEST_PATH=${DEP_BUNDLE_BASE}/foundation/communication/ipc_js && mkdir -p $DEST_PATH && cp -r ./* $DEST_PATH"
|
||||
},
|
||||
"author": {},
|
||||
"repository": "",
|
||||
"license": "Apache License 2.0",
|
||||
"segment": {
|
||||
"destPath": "foundation/communication/ipc/interfaces/kits"
|
||||
},
|
||||
"component": {
|
||||
"name": "ipc_js",
|
||||
"subsystem": "communication",
|
||||
"adapted_system_type": [
|
||||
"standard"
|
||||
],
|
||||
"features": [],
|
||||
"rom": "500KB",
|
||||
"ram": "100KB",
|
||||
"deps": {
|
||||
"components": [
|
||||
"//foundation/arkui/napi:ace_napi",
|
||||
"//third_party/libuv:uv",
|
||||
"//commonlibrary/c_utils/base:utils"
|
||||
],
|
||||
"third_party": [
|
||||
"bounds_checking_function"
|
||||
]
|
||||
},
|
||||
"build": {
|
||||
"sub_component": [
|
||||
"//foundation/communication/ipc/interfaces/kits/js/napi:rpc"
|
||||
],
|
||||
"inner_kits": [
|
||||
{
|
||||
"name": "//foundation/communication/ipc/interfaces/kits/js/napi:rpc",
|
||||
"header": {
|
||||
"header_files": [
|
||||
"napi_remote_object.h"
|
||||
],
|
||||
"header_base": "//foundation/communication/ipc/ipc/native/src/napi/include"
|
||||
}
|
||||
}
|
||||
],
|
||||
"test": [ ]
|
||||
}
|
||||
}
|
||||
}
|
@ -1,213 +1,213 @@
|
||||
/*
|
||||
* 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 "ipc_proxy.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "rpc_errno.h"
|
||||
#include "rpc_log.h"
|
||||
#include "serializer.h"
|
||||
|
||||
static SvcIdentity g_serverSid;
|
||||
static MessageOption g_option;
|
||||
|
||||
int32_t RemoteRequest(uint32_t code, IpcIo *data, IpcIo *reply, MessageOption option)
|
||||
{
|
||||
int32_t result = ERR_NONE;
|
||||
RPC_LOG_INFO("client OnRemoteRequest called....");
|
||||
int a = 0;
|
||||
int b = 0;
|
||||
switch (code) {
|
||||
case CLIENT_OP_ADD: {
|
||||
ReadInt32(data, &a);
|
||||
ReadInt32(data, &b);
|
||||
WriteInt32(reply, a + b);
|
||||
break;
|
||||
}
|
||||
case CLIENT_OP_SUB: {
|
||||
ReadInt32(data, &a);
|
||||
ReadInt32(data, &b);
|
||||
WriteInt32(reply, a - b);
|
||||
break;
|
||||
}
|
||||
case CLIENT_OP_PRINT: {
|
||||
size_t len;
|
||||
char *str = (char *)ReadString(data, &len);
|
||||
RPC_LOG_INFO("client pop string %s....", str);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
RPC_LOG_ERROR("unknown code %d", code);
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void ServerDead1(void)
|
||||
{
|
||||
RPC_LOG_INFO("#### server dead callback11 called ... ");
|
||||
}
|
||||
|
||||
void ServerDead2(void)
|
||||
{
|
||||
RPC_LOG_INFO("#### server dead callback22 called ... ");
|
||||
}
|
||||
|
||||
void ServerDead3(void)
|
||||
{
|
||||
RPC_LOG_INFO("#### server dead callback33 called ... ");
|
||||
}
|
||||
|
||||
static SvcIdentity *g_samgr = NULL;
|
||||
|
||||
static void GetServerOne(void)
|
||||
{
|
||||
IpcIo data1;
|
||||
uint8_t tmpData1[IPC_MAX_SIZE];
|
||||
IpcIoInit(&data1, tmpData1, IPC_MAX_SIZE, 0);
|
||||
WriteInt32(&data1, SERVER_SA_ID1);
|
||||
IpcIo reply1;
|
||||
uintptr_t ptr = 0;
|
||||
int ret = SendRequest(*g_samgr, GET_SYSTEM_ABILITY_TRANSACTION, &data1, &reply1, g_option, &ptr);
|
||||
ReadRemoteObject(&reply1, &g_serverSid);
|
||||
FreeBuffer((void *)ptr);
|
||||
EXPECT_EQ(ret, ERR_NONE);
|
||||
}
|
||||
|
||||
static void CallServerAdd(void)
|
||||
{
|
||||
IpcIo data2;
|
||||
uint8_t tmpData2[IPC_MAX_SIZE];
|
||||
IpcIoInit(&data2, tmpData2, IPC_MAX_SIZE, 0);
|
||||
WriteInt32(&data2, OP_A);
|
||||
WriteInt32(&data2, OP_B);
|
||||
|
||||
IpcIo reply2;
|
||||
uintptr_t ptr2 = 0;
|
||||
int ret = SendRequest(g_serverSid, SERVER_OP_ADD, &data2, &reply2, g_option, &ptr2);
|
||||
int res;
|
||||
ReadInt32(&reply2, &res);
|
||||
RPC_LOG_INFO(" 12 + 17 = %d", res);
|
||||
FreeBuffer((void *)ptr2);
|
||||
EXPECT_EQ(ret, ERR_NONE);
|
||||
int tmpSum = OP_A + OP_B;
|
||||
EXPECT_EQ(res, tmpSum);
|
||||
}
|
||||
|
||||
static void CallServerMulti(void)
|
||||
{
|
||||
RPC_LOG_INFO("====== call serverone OP_MULTI ======");
|
||||
IpcIo data2;
|
||||
uint8_t dataMulti[IPC_MAX_SIZE];
|
||||
IpcIoInit(&data2, dataMulti, IPC_MAX_SIZE, 0);
|
||||
WriteInt32(&data2, OP_A);
|
||||
WriteInt32(&data2, OP_B);
|
||||
IpcIo reply;
|
||||
uintptr_t ptr = 0;
|
||||
int ret = SendRequest(g_serverSid, SERVER_OP_MULTI, &data2, &reply, g_option, &ptr);
|
||||
int res = -1;
|
||||
ReadInt32(&reply, &res);
|
||||
RPC_LOG_INFO(" 12 * 17 = %d", res);
|
||||
FreeBuffer((void *)ptr);
|
||||
EXPECT_EQ(ret, ERR_NONE);
|
||||
int tmpMul = OP_A * OP_B;
|
||||
EXPECT_EQ(res, tmpMul);
|
||||
}
|
||||
|
||||
static IpcObjectStub g_objectStub = {
|
||||
.func = RemoteRequest,
|
||||
.isRemote = false
|
||||
};
|
||||
|
||||
static SvcIdentity g_clientSvc = {
|
||||
.handle = -1,
|
||||
.token = 0,
|
||||
.cookie = &g_objectStub
|
||||
};
|
||||
|
||||
static void AnonymousTest(void)
|
||||
{
|
||||
IpcIo anonymous;
|
||||
uint8_t anonymousData[IPC_MAX_SIZE];
|
||||
IpcIoInit(&anonymous, anonymousData, IPC_MAX_SIZE, 1);
|
||||
WriteRemoteObject(&anonymous, &g_clientSvc);
|
||||
|
||||
IpcIo anonymousreply;
|
||||
uintptr_t anonymousptr = 0;
|
||||
int ret = SendRequest(g_serverSid, SERVER_OP_ADD_SERVICE, &anonymous, &anonymousreply, g_option, &anonymousptr);
|
||||
int res = -1;
|
||||
ReadInt32(&anonymousreply, &res);
|
||||
RPC_LOG_INFO("add self to server = %d", res);
|
||||
FreeBuffer((void *)anonymousptr);
|
||||
EXPECT_EQ(ret, ERR_NONE);
|
||||
EXPECT_EQ(res, ERR_NONE);
|
||||
}
|
||||
|
||||
static void DeathCallbackTest(void)
|
||||
{
|
||||
uint32_t cbId1 = -1;
|
||||
uint32_t cbId2 = -1;
|
||||
uint32_t cbId3 = -1;
|
||||
uint32_t cbId4 = -1;
|
||||
uint32_t cbId5 = -1;
|
||||
RPC_LOG_INFO("============= test case for add death callback ============");
|
||||
int ret = AddDeathRecipient(g_serverSid, ServerDead1, NULL, &cbId1);
|
||||
EXPECT_EQ(ret, ERR_NONE);
|
||||
ret = AddDeathRecipient(g_serverSid, ServerDead2, NULL, &cbId2);
|
||||
EXPECT_EQ(ret, ERR_NONE);
|
||||
ret = AddDeathRecipient(g_serverSid, ServerDead3, NULL, &cbId3);
|
||||
EXPECT_EQ(ret, ERR_NONE);
|
||||
ret = AddDeathRecipient(g_serverSid, ServerDead3, NULL, &cbId4);
|
||||
EXPECT_EQ(ret, ERR_NONE);
|
||||
ret = AddDeathRecipient(g_serverSid, ServerDead3, NULL, &cbId5); // failed
|
||||
EXPECT_EQ(ret, ERR_INVALID_PARAM);
|
||||
|
||||
RPC_LOG_INFO("============= test case for remove death callback ============");
|
||||
ret = RemoveDeathRecipient(g_serverSid, cbId2);
|
||||
EXPECT_EQ(ret, ERR_NONE);
|
||||
ret = RemoveDeathRecipient(g_serverSid, cbId4);
|
||||
EXPECT_EQ(ret, ERR_NONE);
|
||||
ret = RemoveDeathRecipient(g_serverSid, cbId1);
|
||||
EXPECT_EQ(ret, ERR_NONE);
|
||||
ret = RemoveDeathRecipient(g_serverSid, cbId3);
|
||||
EXPECT_EQ(ret, ERR_NONE);
|
||||
++g_serverSid.handle;
|
||||
ret = AddDeathRecipient(g_serverSid, ServerDead3, NULL, &cbId5); // failed
|
||||
EXPECT_EQ(ret, ERR_INVALID_PARAM);
|
||||
ret = RemoveDeathRecipient(g_serverSid, cbId3); // failed
|
||||
EXPECT_EQ(ret, ERR_INVALID_PARAM);
|
||||
|
||||
--g_serverSid.handle;
|
||||
|
||||
ret = AddDeathRecipient(g_serverSid, ServerDead1, NULL, &cbId1);
|
||||
EXPECT_EQ(ret, ERR_NONE);
|
||||
ret = AddDeathRecipient(g_serverSid, ServerDead2, NULL, &cbId2);
|
||||
EXPECT_EQ(ret, ERR_NONE);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
RPC_LOG_INFO("Enter System Ability Client .... ");
|
||||
g_samgr = GetContextObject();
|
||||
MessageOptionInit(&g_option);
|
||||
GetServerOne();
|
||||
CallServerAdd();
|
||||
CallServerMulti();
|
||||
AnonymousTest();
|
||||
DeathCallbackTest();
|
||||
while (1) {}
|
||||
return -1;
|
||||
/*
|
||||
* 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 "ipc_proxy.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "rpc_errno.h"
|
||||
#include "rpc_log.h"
|
||||
#include "serializer.h"
|
||||
|
||||
static SvcIdentity g_serverSid;
|
||||
static MessageOption g_option;
|
||||
|
||||
int32_t RemoteRequest(uint32_t code, IpcIo *data, IpcIo *reply, MessageOption option)
|
||||
{
|
||||
int32_t result = ERR_NONE;
|
||||
RPC_LOG_INFO("client OnRemoteRequest called....");
|
||||
int a = 0;
|
||||
int b = 0;
|
||||
switch (code) {
|
||||
case CLIENT_OP_ADD: {
|
||||
ReadInt32(data, &a);
|
||||
ReadInt32(data, &b);
|
||||
WriteInt32(reply, a + b);
|
||||
break;
|
||||
}
|
||||
case CLIENT_OP_SUB: {
|
||||
ReadInt32(data, &a);
|
||||
ReadInt32(data, &b);
|
||||
WriteInt32(reply, a - b);
|
||||
break;
|
||||
}
|
||||
case CLIENT_OP_PRINT: {
|
||||
size_t len;
|
||||
char *str = (char *)ReadString(data, &len);
|
||||
RPC_LOG_INFO("client pop string %s....", str);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
RPC_LOG_ERROR("unknown code %d", code);
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void ServerDead1(void)
|
||||
{
|
||||
RPC_LOG_INFO("#### server dead callback11 called ... ");
|
||||
}
|
||||
|
||||
void ServerDead2(void)
|
||||
{
|
||||
RPC_LOG_INFO("#### server dead callback22 called ... ");
|
||||
}
|
||||
|
||||
void ServerDead3(void)
|
||||
{
|
||||
RPC_LOG_INFO("#### server dead callback33 called ... ");
|
||||
}
|
||||
|
||||
static SvcIdentity *g_samgr = NULL;
|
||||
|
||||
static void GetServerOne(void)
|
||||
{
|
||||
IpcIo data1;
|
||||
uint8_t tmpData1[IPC_MAX_SIZE];
|
||||
IpcIoInit(&data1, tmpData1, IPC_MAX_SIZE, 0);
|
||||
WriteInt32(&data1, SERVER_SA_ID1);
|
||||
IpcIo reply1;
|
||||
uintptr_t ptr = 0;
|
||||
int ret = SendRequest(*g_samgr, GET_SYSTEM_ABILITY_TRANSACTION, &data1, &reply1, g_option, &ptr);
|
||||
ReadRemoteObject(&reply1, &g_serverSid);
|
||||
FreeBuffer((void *)ptr);
|
||||
EXPECT_EQ(ret, ERR_NONE);
|
||||
}
|
||||
|
||||
static void CallServerAdd(void)
|
||||
{
|
||||
IpcIo data2;
|
||||
uint8_t tmpData2[IPC_MAX_SIZE];
|
||||
IpcIoInit(&data2, tmpData2, IPC_MAX_SIZE, 0);
|
||||
WriteInt32(&data2, OP_A);
|
||||
WriteInt32(&data2, OP_B);
|
||||
|
||||
IpcIo reply2;
|
||||
uintptr_t ptr2 = 0;
|
||||
int ret = SendRequest(g_serverSid, SERVER_OP_ADD, &data2, &reply2, g_option, &ptr2);
|
||||
int res;
|
||||
ReadInt32(&reply2, &res);
|
||||
RPC_LOG_INFO(" 12 + 17 = %d", res);
|
||||
FreeBuffer((void *)ptr2);
|
||||
EXPECT_EQ(ret, ERR_NONE);
|
||||
int tmpSum = OP_A + OP_B;
|
||||
EXPECT_EQ(res, tmpSum);
|
||||
}
|
||||
|
||||
static void CallServerMulti(void)
|
||||
{
|
||||
RPC_LOG_INFO("====== call serverone OP_MULTI ======");
|
||||
IpcIo data2;
|
||||
uint8_t dataMulti[IPC_MAX_SIZE];
|
||||
IpcIoInit(&data2, dataMulti, IPC_MAX_SIZE, 0);
|
||||
WriteInt32(&data2, OP_A);
|
||||
WriteInt32(&data2, OP_B);
|
||||
IpcIo reply;
|
||||
uintptr_t ptr = 0;
|
||||
int ret = SendRequest(g_serverSid, SERVER_OP_MULTI, &data2, &reply, g_option, &ptr);
|
||||
int res = -1;
|
||||
ReadInt32(&reply, &res);
|
||||
RPC_LOG_INFO(" 12 * 17 = %d", res);
|
||||
FreeBuffer((void *)ptr);
|
||||
EXPECT_EQ(ret, ERR_NONE);
|
||||
int tmpMul = OP_A * OP_B;
|
||||
EXPECT_EQ(res, tmpMul);
|
||||
}
|
||||
|
||||
static IpcObjectStub g_objectStub = {
|
||||
.func = RemoteRequest,
|
||||
.isRemote = false
|
||||
};
|
||||
|
||||
static SvcIdentity g_clientSvc = {
|
||||
.handle = -1,
|
||||
.token = 0,
|
||||
.cookie = &g_objectStub
|
||||
};
|
||||
|
||||
static void AnonymousTest(void)
|
||||
{
|
||||
IpcIo anonymous;
|
||||
uint8_t anonymousData[IPC_MAX_SIZE];
|
||||
IpcIoInit(&anonymous, anonymousData, IPC_MAX_SIZE, 1);
|
||||
WriteRemoteObject(&anonymous, &g_clientSvc);
|
||||
|
||||
IpcIo anonymousreply;
|
||||
uintptr_t anonymousptr = 0;
|
||||
int ret = SendRequest(g_serverSid, SERVER_OP_ADD_SERVICE, &anonymous, &anonymousreply, g_option, &anonymousptr);
|
||||
int res = -1;
|
||||
ReadInt32(&anonymousreply, &res);
|
||||
RPC_LOG_INFO("add self to server = %d", res);
|
||||
FreeBuffer((void *)anonymousptr);
|
||||
EXPECT_EQ(ret, ERR_NONE);
|
||||
EXPECT_EQ(res, ERR_NONE);
|
||||
}
|
||||
|
||||
static void DeathCallbackTest(void)
|
||||
{
|
||||
uint32_t cbId1 = -1;
|
||||
uint32_t cbId2 = -1;
|
||||
uint32_t cbId3 = -1;
|
||||
uint32_t cbId4 = -1;
|
||||
uint32_t cbId5 = -1;
|
||||
RPC_LOG_INFO("============= test case for add death callback ============");
|
||||
int ret = AddDeathRecipient(g_serverSid, ServerDead1, NULL, &cbId1);
|
||||
EXPECT_EQ(ret, ERR_NONE);
|
||||
ret = AddDeathRecipient(g_serverSid, ServerDead2, NULL, &cbId2);
|
||||
EXPECT_EQ(ret, ERR_NONE);
|
||||
ret = AddDeathRecipient(g_serverSid, ServerDead3, NULL, &cbId3);
|
||||
EXPECT_EQ(ret, ERR_NONE);
|
||||
ret = AddDeathRecipient(g_serverSid, ServerDead3, NULL, &cbId4);
|
||||
EXPECT_EQ(ret, ERR_NONE);
|
||||
ret = AddDeathRecipient(g_serverSid, ServerDead3, NULL, &cbId5); // failed
|
||||
EXPECT_EQ(ret, ERR_INVALID_PARAM);
|
||||
|
||||
RPC_LOG_INFO("============= test case for remove death callback ============");
|
||||
ret = RemoveDeathRecipient(g_serverSid, cbId2);
|
||||
EXPECT_EQ(ret, ERR_NONE);
|
||||
ret = RemoveDeathRecipient(g_serverSid, cbId4);
|
||||
EXPECT_EQ(ret, ERR_NONE);
|
||||
ret = RemoveDeathRecipient(g_serverSid, cbId1);
|
||||
EXPECT_EQ(ret, ERR_NONE);
|
||||
ret = RemoveDeathRecipient(g_serverSid, cbId3);
|
||||
EXPECT_EQ(ret, ERR_NONE);
|
||||
++g_serverSid.handle;
|
||||
ret = AddDeathRecipient(g_serverSid, ServerDead3, NULL, &cbId5); // failed
|
||||
EXPECT_EQ(ret, ERR_INVALID_PARAM);
|
||||
ret = RemoveDeathRecipient(g_serverSid, cbId3); // failed
|
||||
EXPECT_EQ(ret, ERR_INVALID_PARAM);
|
||||
|
||||
--g_serverSid.handle;
|
||||
|
||||
ret = AddDeathRecipient(g_serverSid, ServerDead1, NULL, &cbId1);
|
||||
EXPECT_EQ(ret, ERR_NONE);
|
||||
ret = AddDeathRecipient(g_serverSid, ServerDead2, NULL, &cbId2);
|
||||
EXPECT_EQ(ret, ERR_NONE);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
RPC_LOG_INFO("Enter System Ability Client .... ");
|
||||
g_samgr = GetContextObject();
|
||||
MessageOptionInit(&g_option);
|
||||
GetServerOne();
|
||||
CallServerAdd();
|
||||
CallServerMulti();
|
||||
AnonymousTest();
|
||||
DeathCallbackTest();
|
||||
while (1) {}
|
||||
return -1;
|
||||
}
|
@ -1,126 +1,126 @@
|
||||
/*
|
||||
* 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 "ipc_proxy.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "rpc_errno.h"
|
||||
#include "rpc_log.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;
|
||||
|
||||
int32_t AddSystemAbility(int32_t saId, SvcIdentity *sid)
|
||||
{
|
||||
if (g_saList == NULL) {
|
||||
return ERR_FAILED;
|
||||
}
|
||||
|
||||
SvcInfo* node = (SvcInfo *)calloc(1, sizeof(SvcInfo));
|
||||
if (node == NULL) {
|
||||
return ERR_FAILED;
|
||||
}
|
||||
node->saId = saId;
|
||||
node->sid = sid;
|
||||
UtilsListAdd(g_saList, &node->list);
|
||||
return ERR_NONE;
|
||||
}
|
||||
|
||||
int32_t GetSystemAbility(int32_t saId, const char* deviceId, SvcIdentity *sid)
|
||||
{
|
||||
(void)deviceId;
|
||||
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 = %u", code);
|
||||
switch (code) {
|
||||
case ADD_SYSTEM_ABILITY_TRANSACTION: {
|
||||
int32_t saId;
|
||||
ReadInt32(data, &saId);
|
||||
SvcIdentity *sid = (SvcIdentity *)malloc(sizeof(SvcIdentity));
|
||||
ReadRemoteObject(data, sid);
|
||||
result = AddSystemAbility(saId, sid);
|
||||
if (result != ERR_NONE) {
|
||||
return result;
|
||||
}
|
||||
WriteInt32(reply, result);
|
||||
break;
|
||||
}
|
||||
case GET_SYSTEM_ABILITY_TRANSACTION: {
|
||||
int32_t saId;
|
||||
ReadInt32(data, &saId);
|
||||
SvcIdentity sid;
|
||||
result = GetSystemAbility(saId, "", &sid);
|
||||
if (result != ERR_NONE) {
|
||||
return result;
|
||||
}
|
||||
WriteRemoteObject(reply, &sid);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
RPC_LOG_ERROR("unknown code %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 = (uintptr_t)&objectStub
|
||||
};
|
||||
|
||||
if (SetContextObject(target) != ERR_NONE) {
|
||||
RPC_LOG_ERROR("SAMGR register samgr failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
JoinWorkThread();
|
||||
return -1;
|
||||
/*
|
||||
* 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 "ipc_proxy.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "rpc_errno.h"
|
||||
#include "rpc_log.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;
|
||||
|
||||
int32_t AddSystemAbility(int32_t saId, SvcIdentity *sid)
|
||||
{
|
||||
if (g_saList == NULL) {
|
||||
return ERR_FAILED;
|
||||
}
|
||||
|
||||
SvcInfo* node = (SvcInfo *)calloc(1, sizeof(SvcInfo));
|
||||
if (node == NULL) {
|
||||
return ERR_FAILED;
|
||||
}
|
||||
node->saId = saId;
|
||||
node->sid = sid;
|
||||
UtilsListAdd(g_saList, &node->list);
|
||||
return ERR_NONE;
|
||||
}
|
||||
|
||||
int32_t GetSystemAbility(int32_t saId, const char* deviceId, SvcIdentity *sid)
|
||||
{
|
||||
(void)deviceId;
|
||||
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 = %u", code);
|
||||
switch (code) {
|
||||
case ADD_SYSTEM_ABILITY_TRANSACTION: {
|
||||
int32_t saId;
|
||||
ReadInt32(data, &saId);
|
||||
SvcIdentity *sid = (SvcIdentity *)malloc(sizeof(SvcIdentity));
|
||||
ReadRemoteObject(data, sid);
|
||||
result = AddSystemAbility(saId, sid);
|
||||
if (result != ERR_NONE) {
|
||||
return result;
|
||||
}
|
||||
WriteInt32(reply, result);
|
||||
break;
|
||||
}
|
||||
case GET_SYSTEM_ABILITY_TRANSACTION: {
|
||||
int32_t saId;
|
||||
ReadInt32(data, &saId);
|
||||
SvcIdentity sid;
|
||||
result = GetSystemAbility(saId, "", &sid);
|
||||
if (result != ERR_NONE) {
|
||||
return result;
|
||||
}
|
||||
WriteRemoteObject(reply, &sid);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
RPC_LOG_ERROR("unknown code %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 = (uintptr_t)&objectStub
|
||||
};
|
||||
|
||||
if (SetContextObject(target) != ERR_NONE) {
|
||||
RPC_LOG_ERROR("SAMGR register samgr failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
JoinWorkThread();
|
||||
return -1;
|
||||
}
|
@ -1,177 +1,177 @@
|
||||
/*
|
||||
* 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 <cstdlib>
|
||||
#include <thread>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ipc_proxy.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "rpc_errno.h"
|
||||
#include "rpc_log.h"
|
||||
#include "serializer.h"
|
||||
|
||||
static SvcIdentity *sid = nullptr;
|
||||
|
||||
static const SvcIdentity *g_samgr;
|
||||
|
||||
static void CallAnonymosFunc(const char *str)
|
||||
{
|
||||
if (sid == nullptr) {
|
||||
RPC_LOG_INFO("invalid anonymous client");
|
||||
return;
|
||||
}
|
||||
RPC_LOG_INFO("now server call client anonymous func");
|
||||
IpcIo data;
|
||||
uint8_t tmpData1[IPC_MAX_SIZE];
|
||||
IpcIoInit(&data, tmpData1, IPC_MAX_SIZE, 1);
|
||||
WriteString(&data, str);
|
||||
|
||||
IpcIo reply;
|
||||
MessageOption option;
|
||||
MessageOptionInit(&option);
|
||||
option.flags = TF_OP_ASYNC;
|
||||
int ret = SendRequest(*sid, CLIENT_OP_PRINT, &data, &reply, option, nullptr);
|
||||
RPC_LOG_INFO("server Async call res = %d", ret);
|
||||
}
|
||||
|
||||
static void ServerDead1(void)
|
||||
{
|
||||
RPC_LOG_INFO("#### server dead callback11 called ... ");
|
||||
}
|
||||
|
||||
static void ThreadHandler()
|
||||
{
|
||||
sleep(IPC_TEST_TIME_INTERVAL); // sleep 2 min
|
||||
const char *str = "server call anonymos service new thread.";
|
||||
CallAnonymosFunc(str);
|
||||
}
|
||||
|
||||
static MessageOption g_option;
|
||||
|
||||
class Ability {
|
||||
public:
|
||||
explicit Ability(int32_t data) : data_(data)
|
||||
{
|
||||
sid_ = (SvcIdentity *)malloc(sizeof(SvcIdentity));
|
||||
objectStub_ = (IpcObjectStub *)malloc(sizeof(IpcObjectStub));
|
||||
objectStub_->func = Ability::MsgHandleInner;
|
||||
objectStub_->args = this;
|
||||
sid_->handle = -1;
|
||||
sid_->token = 1;
|
||||
sid_->cookie = (uintptr_t)objectStub_;
|
||||
}
|
||||
|
||||
static int32_t MsgHandleInner(uint32_t code, IpcIo *data, IpcIo *reply, MessageOption option)
|
||||
{
|
||||
Ability *ability = static_cast<Ability *>(option.args);
|
||||
RPC_LOG_INFO("server MsgHandleInner called...., p = %p, data = %d", ability, ability->data_);
|
||||
|
||||
int32_t result = ERR_NONE;
|
||||
switch (code) {
|
||||
case SERVER_OP_ADD: {
|
||||
int32_t a;
|
||||
ReadInt32(data, &a);
|
||||
int32_t b;
|
||||
ReadInt32(data, &b);
|
||||
WriteInt32(reply, a + b);
|
||||
break;
|
||||
}
|
||||
case SERVER_OP_SUB: {
|
||||
int32_t a;
|
||||
ReadInt32(data, &a);
|
||||
int32_t b;
|
||||
ReadInt32(data, &b);
|
||||
WriteInt32(reply, a - b);
|
||||
break;
|
||||
}
|
||||
case SERVER_OP_MULTI: {
|
||||
int32_t a;
|
||||
ReadInt32(data, &a);
|
||||
int32_t b;
|
||||
ReadInt32(data, &b);
|
||||
WriteInt32(reply, a * b);
|
||||
break;
|
||||
}
|
||||
case SERVER_OP_ADD_SERVICE: {
|
||||
sid = (SvcIdentity *)calloc(1, sizeof(SvcIdentity));
|
||||
ReadRemoteObject(data, sid);
|
||||
WriteInt32(reply, ERR_NONE);
|
||||
uint32_t cbId1 = -1;
|
||||
(void)AddDeathRecipient(*sid, (OnRemoteDead)ServerDead1, (void *)NULL, (uint32_t *)&cbId1);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
RPC_LOG_ERROR("unknown code %d", code);
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
SvcIdentity *sid_;
|
||||
private:
|
||||
int32_t data_;
|
||||
IpcObjectStub *objectStub_;
|
||||
};
|
||||
|
||||
static void AddSaOne(void)
|
||||
{
|
||||
IpcIo data;
|
||||
uint8_t tmpData1[IPC_MAX_SIZE];
|
||||
IpcIoInit(&data, tmpData1, IPC_MAX_SIZE, 1);
|
||||
WriteInt32(&data, SERVER_SA_ID1);
|
||||
|
||||
Ability *ability = new Ability(322516);
|
||||
RPC_LOG_INFO("====== add ability one to samgr ====== %p", ability);
|
||||
WriteRemoteObject(&data, ability->sid_);
|
||||
|
||||
IpcIo reply;
|
||||
uintptr_t ptr = 0;
|
||||
RPC_LOG_INFO("====== add ability one to samgr ======");
|
||||
int ret = SendRequest(*g_samgr, ADD_SYSTEM_ABILITY_TRANSACTION, &data, &reply, g_option, &ptr);
|
||||
int res = -1;
|
||||
ReadInt32(&reply, &res);
|
||||
FreeBuffer((void *)ptr);
|
||||
EXPECT_EQ(ret, ERR_NONE);
|
||||
EXPECT_EQ(res, ERR_NONE);
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
RPC_LOG_INFO("Enter System Ability Server .... ");
|
||||
g_samgr = GetContextObject();
|
||||
MessageOptionInit(&g_option);
|
||||
AddSaOne();
|
||||
|
||||
IpcIo reply;
|
||||
uintptr_t ptr = 0;
|
||||
RPC_LOG_INFO("====== get ability one from samgr ======");
|
||||
IpcIo data1;
|
||||
uint8_t dataGet[IPC_MAX_SIZE];
|
||||
IpcIoInit(&data1, dataGet, IPC_MAX_SIZE, 0);
|
||||
WriteInt32(&data1, SERVER_SA_ID1);
|
||||
int ret = SendRequest(*g_samgr, GET_SYSTEM_ABILITY_TRANSACTION, &data1, &reply, g_option, &ptr);
|
||||
SvcIdentity sidOne;
|
||||
ReadRemoteObject(&reply, &sidOne);
|
||||
FreeBuffer((void *)ptr);
|
||||
EXPECT_EQ(ret, ERR_NONE);
|
||||
sleep(1);
|
||||
|
||||
std::thread task(ThreadHandler);
|
||||
task.detach();
|
||||
JoinWorkThread();
|
||||
return -1;
|
||||
/*
|
||||
* 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 <cstdlib>
|
||||
#include <thread>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ipc_proxy.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "rpc_errno.h"
|
||||
#include "rpc_log.h"
|
||||
#include "serializer.h"
|
||||
|
||||
static SvcIdentity *sid = nullptr;
|
||||
|
||||
static const SvcIdentity *g_samgr;
|
||||
|
||||
static void CallAnonymosFunc(const char *str)
|
||||
{
|
||||
if (sid == nullptr) {
|
||||
RPC_LOG_INFO("invalid anonymous client");
|
||||
return;
|
||||
}
|
||||
RPC_LOG_INFO("now server call client anonymous func");
|
||||
IpcIo data;
|
||||
uint8_t tmpData1[IPC_MAX_SIZE];
|
||||
IpcIoInit(&data, tmpData1, IPC_MAX_SIZE, 1);
|
||||
WriteString(&data, str);
|
||||
|
||||
IpcIo reply;
|
||||
MessageOption option;
|
||||
MessageOptionInit(&option);
|
||||
option.flags = TF_OP_ASYNC;
|
||||
int ret = SendRequest(*sid, CLIENT_OP_PRINT, &data, &reply, option, nullptr);
|
||||
RPC_LOG_INFO("server Async call res = %d", ret);
|
||||
}
|
||||
|
||||
static void ServerDead1(void)
|
||||
{
|
||||
RPC_LOG_INFO("#### server dead callback11 called ... ");
|
||||
}
|
||||
|
||||
static void ThreadHandler()
|
||||
{
|
||||
sleep(IPC_TEST_TIME_INTERVAL); // sleep 2 min
|
||||
const char *str = "server call anonymos service new thread.";
|
||||
CallAnonymosFunc(str);
|
||||
}
|
||||
|
||||
static MessageOption g_option;
|
||||
|
||||
class Ability {
|
||||
public:
|
||||
explicit Ability(int32_t data) : data_(data)
|
||||
{
|
||||
sid_ = (SvcIdentity *)malloc(sizeof(SvcIdentity));
|
||||
objectStub_ = (IpcObjectStub *)malloc(sizeof(IpcObjectStub));
|
||||
objectStub_->func = Ability::MsgHandleInner;
|
||||
objectStub_->args = this;
|
||||
sid_->handle = -1;
|
||||
sid_->token = 1;
|
||||
sid_->cookie = (uintptr_t)objectStub_;
|
||||
}
|
||||
|
||||
static int32_t MsgHandleInner(uint32_t code, IpcIo *data, IpcIo *reply, MessageOption option)
|
||||
{
|
||||
Ability *ability = static_cast<Ability *>(option.args);
|
||||
RPC_LOG_INFO("server MsgHandleInner called...., p = %p, data = %d", ability, ability->data_);
|
||||
|
||||
int32_t result = ERR_NONE;
|
||||
switch (code) {
|
||||
case SERVER_OP_ADD: {
|
||||
int32_t a;
|
||||
ReadInt32(data, &a);
|
||||
int32_t b;
|
||||
ReadInt32(data, &b);
|
||||
WriteInt32(reply, a + b);
|
||||
break;
|
||||
}
|
||||
case SERVER_OP_SUB: {
|
||||
int32_t a;
|
||||
ReadInt32(data, &a);
|
||||
int32_t b;
|
||||
ReadInt32(data, &b);
|
||||
WriteInt32(reply, a - b);
|
||||
break;
|
||||
}
|
||||
case SERVER_OP_MULTI: {
|
||||
int32_t a;
|
||||
ReadInt32(data, &a);
|
||||
int32_t b;
|
||||
ReadInt32(data, &b);
|
||||
WriteInt32(reply, a * b);
|
||||
break;
|
||||
}
|
||||
case SERVER_OP_ADD_SERVICE: {
|
||||
sid = (SvcIdentity *)calloc(1, sizeof(SvcIdentity));
|
||||
ReadRemoteObject(data, sid);
|
||||
WriteInt32(reply, ERR_NONE);
|
||||
uint32_t cbId1 = -1;
|
||||
(void)AddDeathRecipient(*sid, (OnRemoteDead)ServerDead1, (void *)NULL, (uint32_t *)&cbId1);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
RPC_LOG_ERROR("unknown code %d", code);
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
SvcIdentity *sid_;
|
||||
private:
|
||||
int32_t data_;
|
||||
IpcObjectStub *objectStub_;
|
||||
};
|
||||
|
||||
static void AddSaOne(void)
|
||||
{
|
||||
IpcIo data;
|
||||
uint8_t tmpData1[IPC_MAX_SIZE];
|
||||
IpcIoInit(&data, tmpData1, IPC_MAX_SIZE, 1);
|
||||
WriteInt32(&data, SERVER_SA_ID1);
|
||||
|
||||
Ability *ability = new Ability(322516);
|
||||
RPC_LOG_INFO("====== add ability one to samgr ====== %p", ability);
|
||||
WriteRemoteObject(&data, ability->sid_);
|
||||
|
||||
IpcIo reply;
|
||||
uintptr_t ptr = 0;
|
||||
RPC_LOG_INFO("====== add ability one to samgr ======");
|
||||
int ret = SendRequest(*g_samgr, ADD_SYSTEM_ABILITY_TRANSACTION, &data, &reply, g_option, &ptr);
|
||||
int res = -1;
|
||||
ReadInt32(&reply, &res);
|
||||
FreeBuffer((void *)ptr);
|
||||
EXPECT_EQ(ret, ERR_NONE);
|
||||
EXPECT_EQ(res, ERR_NONE);
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
RPC_LOG_INFO("Enter System Ability Server .... ");
|
||||
g_samgr = GetContextObject();
|
||||
MessageOptionInit(&g_option);
|
||||
AddSaOne();
|
||||
|
||||
IpcIo reply;
|
||||
uintptr_t ptr = 0;
|
||||
RPC_LOG_INFO("====== get ability one from samgr ======");
|
||||
IpcIo data1;
|
||||
uint8_t dataGet[IPC_MAX_SIZE];
|
||||
IpcIoInit(&data1, dataGet, IPC_MAX_SIZE, 0);
|
||||
WriteInt32(&data1, SERVER_SA_ID1);
|
||||
int ret = SendRequest(*g_samgr, GET_SYSTEM_ABILITY_TRANSACTION, &data1, &reply, g_option, &ptr);
|
||||
SvcIdentity sidOne;
|
||||
ReadRemoteObject(&reply, &sidOne);
|
||||
FreeBuffer((void *)ptr);
|
||||
EXPECT_EQ(ret, ERR_NONE);
|
||||
sleep(1);
|
||||
|
||||
std::thread task(ThreadHandler);
|
||||
task.detach();
|
||||
JoinWorkThread();
|
||||
return -1;
|
||||
}
|
@ -1,28 +1,28 @@
|
||||
<?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" src="out" />
|
||||
<option name="push" value="communication/ipc/dbinder_send -> /data" src="out" />
|
||||
</preparer>
|
||||
</target>
|
||||
<target name="DbinderTestAgent">
|
||||
<preparer>
|
||||
<option name="push" value="communication/ipc/dbinder_test -> /data" src="out" />
|
||||
<option name="push" value="communication/ipc/dbinder_send -> /data" 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" src="out" />
|
||||
<option name="push" value="communication/ipc/dbinder_send -> /data" src="out" />
|
||||
</preparer>
|
||||
</target>
|
||||
<target name="DbinderTestAgent">
|
||||
<preparer>
|
||||
<option name="push" value="communication/ipc/dbinder_test -> /data" src="out" />
|
||||
<option name="push" value="communication/ipc/dbinder_send -> /data" src="out" />
|
||||
</preparer>
|
||||
</target>
|
||||
</configuration>
|
||||
|
Loading…
Reference in New Issue
Block a user