1 Star 0 Fork 6

XiYuhao/communication_interfaces_kits_ipc_lite

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
liteipc_adapter.h 3.72 KB
一键复制 编辑 原始数据 按行查看 历史
XiYuhao 提交于 2020-09-16 16:33 +08:00 . spelling error fix:Registe->Register
/*
* 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.
*/
#ifndef _LITEIPC_ADAPTER_H
#define _LITEIPC_ADAPTER_H
#include "pthread.h"
#include "stdint.h"
#include "stdbool.h"
#include "unistd.h"
#include "serializer.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#define MMAP_DEFAULT_SIZE 65536UL /* 64KB */
#define MMAP_MAX_SIZE 262144UL /* 256KB */
#define MAX_DEATHCB_PER_SVC 5
#define IPC_WAIT_FOREVER 0XFFFFFFFF
#define IPC_TIMEOUT_MIN 10 /* unit:ms */
#define IPC_INVAILD_TIMER_ID (timer_t)-1
#define IPC_IO_DATA_MAX 200
typedef enum {
LITEIPC_FLAG_DEFAULT = 0, // send and reply
LITEIPC_FLAG_ONEWAY, // send message only
} IpcFlag;
typedef enum {
ONCE = 0, // Callback will be removed when timeout
RESET_AFTER_USE, // The interval will be refresh when the callback is called
} IpcCbMode;
enum IpcErr {
LITEIPC_EINVAL = -10, /* Invalid argument */
LITEIPC_EBADF, /* Bad file descriptor */
LITEIPC_ENOMEM, /* No memory */
LITEIPC_ENOENT, /* Service is not avaliable; For example, Transact on a timeout ipc callback */
LITEIPC_EINTNL, /* Internal error, check strerrno in log */
LITEIPC_OK = 0,
};
enum { DEATH_CODE = 0 };
typedef struct {
int fd;
size_t mmapSize;
void* mmapAddr;
} IpcContext;
typedef int32_t (*IpcMsgHandler)(const IpcContext* context, void* ipcMsg, IpcIo* data, void* arg);
#define LITEIPC_DEFAULT_MAP_SIZE 0X10000
IpcContext* OpenLiteIpc(size_t mmapSize);
void CloseLiteIpc(IpcContext* context);
/* thread-unsafe, cannot be repeatedly invoked */
int32_t SetSaManager(const IpcContext* context, size_t maxMsgSize);
int32_t AddServiceAccess(SvcIdentity sid, pid_t pid);
int32_t GenServiceHandle(SvcIdentity* sid, pid_t tid);
int32_t StartLoop(const IpcContext* context, IpcMsgHandler func, void* arg);
int32_t GetToken(const void* ipcMsg, uint32_t* token);
int32_t GetCode(const void* ipcMsg, uint32_t* code);
int32_t GetFlag(const void* ipcMsg, uint32_t* flag);
pid_t GetCallingTid(const void* ipcMsg);
pid_t GetCallingPid(const void* ipcMsg);
pid_t GetCallingUid(const void* ipcMsg);
pid_t GetCallingGid(const void* ipcMsg);
int32_t Transact(const IpcContext* context,
SvcIdentity sid,
uint32_t code,
IpcIo* data,
IpcIo* reply,
IpcFlag flag,
uintptr_t* buffer);
int32_t SendReply(const IpcContext* context, void* ipcMsg, IpcIo* reply);
int32_t FreeBuffer(const IpcContext* context, void* ptr);
int32_t RegisterIpcCallback(IpcMsgHandler func,
uint32_t mode,
uint32_t timeoutMs,
SvcIdentity* sid,
void* arg);
int32_t UnregisterIpcCallback(SvcIdentity sid);
int32_t RegisterDeathCallback(const IpcContext* context, SvcIdentity sid, IpcMsgHandler func, void* arg, uint32_t* cbId);
int32_t UnregisterDeathCallback(SvcIdentity sid, uint32_t cbId);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/Xi_Yuhao/communication_interfaces_kits_ipc_lite.git
git@gitee.com:Xi_Yuhao/communication_interfaces_kits_ipc_lite.git
Xi_Yuhao
communication_interfaces_kits_ipc_lite
communication_interfaces_kits_ipc_lite
master

搜索帮助