可用,并增加fs服务
This commit is contained in:
zhangzheng
2023-09-24 01:26:07 +08:00
parent cdb4adb0ab
commit ef49739ad0
32 changed files with 1180 additions and 245 deletions

10
.vscode/settings.json vendored
View File

@@ -136,7 +136,15 @@
"u_irq_sender.h": "c",
"u_env.h": "c",
"stddef.h": "c",
"u_rpc.h": "c"
"u_rpc.h": "c",
"namespace.h": "c",
"u_rpc_svr.h": "c",
"rpc_prot.h": "c",
"ns_types.h": "c",
"ns_svr.h": "c",
"u_rpc_2.h": "c",
"ns_cli.h": "c",
"fs_cli.h": "c"
},
"cortex-debug.showRTOS": false,
}

View File

@@ -8,6 +8,7 @@ set(CMAKE_ASM_FLAGS ${CMAKE_C_FLAGS})
# add_subdirectory(dietlibc)
add_subdirectory(sys)
add_subdirectory(sys_util)
add_subdirectory(sys_svr)
add_subdirectory(libc_backend)
add_subdirectory(mlibc)
add_subdirectory(cpio)

View File

@@ -0,0 +1,42 @@
cmake_minimum_required(VERSION 3.13)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} \
-fPIC -n -pie -fpie -fpic -msingle-pic-base -mno-pic-data-is-text-relative \
-Wl,--gc-sections -D__dietlibc__ -D__arm__ -D__WORDSIZE=32 -D__ARM_ARCH_7M__ \
" )
set(CMAKE_ASM_FLAGS ${CMAKE_C_FLAGS})
file(GLOB_RECURSE deps *.c *.S)
add_library(
sys_svr
STATIC
${deps}
)
target_include_directories(
sys_svr
PUBLIC
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/sys_svr/inc
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/sys/inc
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/cpio
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/arch/arm/
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/arch/generic
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/obj/src/internal
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/src/include
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/src/internal
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/obj/include
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/include
)
target_link_libraries(
sys_svr
PUBLIC
sys
muslc
cpio
)
add_dependencies(sys_svr sys)
add_dependencies(sys_svr muslc)

View File

@@ -0,0 +1,3 @@
#pragma once
int fs_open(const char *path, int flags, int mode);

View File

@@ -0,0 +1,14 @@
#pragma once
#include "u_rpc_svr.h"
#include "u_types.h"
typedef struct fs
{
rpc_svr_obj_t svr;
obj_handler_t ipc;
} fs_t;
void fs_init(fs_t *fs);
int fs_svr_open(const char *path, int flags, int mode);

View File

View File

@@ -0,0 +1,6 @@
#pragma once
#include "u_types.h"
int ns_register(const char *path, obj_handler_t svr_hd);
int ns_query(const char *path, obj_handler_t *svr_hd);

View File

@@ -0,0 +1,10 @@
#pragma once
#include "u_types.h"
#include "u_rpc.h"
#include "rpc_prot.h"
#include "ns_types.h"
void ns_init(ns_t *ns);
int namespace_register(const char *path, obj_handler_t hd);
int namespace_query(const char *path, obj_handler_t *hd);

View File

@@ -0,0 +1,19 @@
#pragma once
#include "u_types.h"
#include "u_rpc_svr.h"
#define NAMESPACE_PATH_LEN 32
#define NAMESAPCE_NR 32
typedef struct namespace_entry
{
char path[NAMESPACE_PATH_LEN]; //!< 服务的路径名
obj_handler_t hd; //!< 服务的fd
} namespace_entry_t;
typedef struct ns
{
rpc_svr_obj_t svr;
namespace_entry_t ne_list[NAMESAPCE_NR]; //!< 服务列表
obj_handler_t hd;
obj_handler_t ipc_hd; //!< 服务的ipc hd
} ns_t;

View File

@@ -0,0 +1,11 @@
#pragma once
#define NS_PROT 0x0001 //!< namespace的协议
#define NS_REGISTER_OP ((uint16_t)0) //!< ns注册
#define NS_QUERY_OP ((uint16_t)1) //!< ns请求
#define FS_PROT 0x0002
#define FS_OPEN ((uint16_t)0)
#define FS_CLOSE ((uint16_t)1)
#define FS_READ ((uint16_t)2)
#define FS_WRITE ((uint16_t)3)

View File

@@ -0,0 +1,46 @@
#include "u_rpc.h"
#include "u_rpc_svr.h"
#include "ns_types.h"
#include "rpc_prot.h"
#include "u_env.h"
#include "u_prot.h"
#include "u_hd_man.h"
#include "ns_cli.h"
#include <stdio.h>
#include <string.h>
#include <assert.h>
RPC_GENERATION_CALL3(fs_t, FS_OPEN, open,
rpc_ref_array_uint32_t_uint8_t_32_t, rpc_array_uint32_t_uint8_t_32_t, RPC_DIR_IN, RPC_TYPE_DATA, path,
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, flags,
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, mode)
int fs_open(const char *path, int flags, int mode)
{
obj_handler_t hd;
int ret = ns_query("fs", &hd);
if (ret < 0)
{
return ret;
}
rpc_ref_array_uint32_t_uint8_t_32_t rpc_path = {
.data = path,
.len = strlen(path) + 1,
};
rpc_int_t rpc_flags = {
.data = flags,
};
rpc_int_t rpc_mode = {
.data = mode,
};
msg_tag_t tag = fs_t_open_call(hd, &rpc_path, &rpc_flags, &rpc_mode);
if (msg_tag_get_val(tag) < 0)
{
return msg_tag_get_val(tag);
}
return msg_tag_get_val(tag);
}

View File

@@ -0,0 +1,28 @@
#include "rpc_prot.h"
#include "u_rpc.h"
#include "u_rpc_svr.h"
#include "u_hd_man.h"
#include "fs_svr.h"
#include <stdio.h>
RPC_GENERATION_OP3(fs_t, FS_OPEN, open,
rpc_ref_array_uint32_t_uint8_t_32_t, rpc_array_uint32_t_uint8_t_32_t, RPC_DIR_IN, RPC_TYPE_DATA, path,
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, flags,
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, mode)
{
path->data[path->len - 1] = 0;
int ret = fs_svr_open((char *)(path->data), flags->data, mode->data);
return ret;
}
RPC_GENERATION_DISPATCH3(fs_t, FS_OPEN, open,
rpc_ref_array_uint32_t_uint8_t_32_t, rpc_array_uint32_t_uint8_t_32_t, RPC_DIR_IN, RPC_TYPE_DATA, path,
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, flags,
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, mode)
RPC_DISPATCH1(fs_t, typeof(FS_OPEN), FS_OPEN, open)
void fs_init(fs_t *fs)
{
rpc_svr_obj_init(&fs->svr, rpc_fs_t_dispatch, FS_PROT);
}

View File

@@ -0,0 +1,234 @@
#include "u_rpc.h"
#include "u_rpc_svr.h"
#include "ns_types.h"
#include "rpc_prot.h"
#include "u_env.h"
#include "u_prot.h"
#include "u_hd_man.h"
#include <stdio.h>
#include <string.h>
#include <assert.h>
#define NS_CLI_CACHE_NR 8 //!< 一个客户端最多可以请求8个服务
typedef struct ns_cli_entry
{
char path[NAMESPACE_PATH_LEN];
obj_handler_t hd;
} ns_cli_entry_t;
typedef struct ns_cli_cache
{
ns_cli_entry_t cache[NS_CLI_CACHE_NR];
} ns_cli_cache_t;
static ns_cli_cache_t ns_cli_cache;
static obj_handler_t find_hd(const char *path)
{
int i = 0;
int empty = -1;
for (i = 0; i < NS_CLI_CACHE_NR; i++)
{
if (ns_cli_cache.cache[i].path[0] != 0)
{
if (strcmp(ns_cli_cache.cache[i].path, path) == 0)
{
return ns_cli_cache.cache[i].hd;
}
}
}
return HANDLER_INVALID;
}
static bool_t reg_hd(const char *path, obj_handler_t hd)
{
int i = 0;
int empty = -1;
for (i = 0; i < NS_CLI_CACHE_NR; i++)
{
if (ns_cli_cache.cache[i].path[0] == 0)
{
strcpy(ns_cli_cache.cache[i].path, path);
ns_cli_cache.cache[i].hd = hd;
return TRUE;
}
}
return FALSE;
}
RPC_GENERATION_CALL2(ns_t, NS_REGISTER_OP, register,
rpc_ref_array_uint32_t_uint8_t_32_t, rpc_array_uint32_t_uint8_t_32_t, RPC_DIR_IN, RPC_TYPE_DATA, path,
rpc_obj_handler_t_t, rpc_obj_handler_t_t, RPC_DIR_IN, RPC_TYPE_BUF, svr_hd)
// RPC_GENERATION_CALL2(ns_t, NS_QUERY_OP, query,
// rpc_ref_array_uint32_t_uint8_t_32_t, rpc_array_uint32_t_uint8_t_32_t, RPC_DIR_IN, RPC_TYPE_DATA, path,
// rpc_obj_handler_t_t, rpc_obj_handler_t_t, RPC_DIR_INOUT, RPC_TYPE_BUF, cli_hd)
msg_tag_t ns_t_query_call(obj_handler_t hd, rpc_ref_array_uint32_t_uint8_t_32_t *var0, rpc_obj_handler_t_t *var1)
{
void *buf;
ipc_msg_t *msg_ipc;
thread_msg_buf_get(2, (umword_t *)(&buf), ((void *)0));
msg_ipc = (ipc_msg_t *)buf;
int off = 0;
int off_buf = 0;
int ret = -1;
size_t op_val = ((uint16_t)1);
rpc_memcpy(msg_ipc->msg_buf, &op_val, sizeof(op_val));
off += rpc_align(sizeof(op_val), __alignof(((uint16_t)1)));
do
{
if (1 == 1)
{
if (1 == 1 || 1 == 4)
{
int ret = rpc_cli_msg_to_buf_rpc_ref_array_uint32_t_uint8_t_32_t(var0, (uint8_t *)((uint8_t *)msg_ipc->msg_buf), off);
if (ret < 0)
{
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)});
}
off = ret;
}
}
} while (0);
do
{
if (1 == 2)
{
if (1 == 1 || 1 == 4)
{
int ret = rpc_cli_msg_to_buf_rpc_ref_array_uint32_t_uint8_t_32_t(var0, (uint8_t *)((uint8_t *)msg_ipc->map_buf), off_buf);
if (ret < 0)
{
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)});
}
off_buf = ret;
}
}
} while (0);
do
{
if (2 == 1)
{
if (4 == 1 || 4 == 4)
{
int ret = rpc_cli_msg_to_buf_rpc_obj_handler_t_t(var1, (uint8_t *)((uint8_t *)msg_ipc->msg_buf), off);
if (ret < 0)
{
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)});
}
off = ret;
}
}
} while (0);
do
{
if (2 == 2)
{
if (4 == 1 || 4 == 4)
{
int ret = rpc_cli_msg_to_buf_rpc_obj_handler_t_t(var1, (uint8_t *)((uint8_t *)msg_ipc->map_buf), off_buf);
if (ret < 0)
{
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)});
}
off_buf = ret;
}
}
} while (0);
msg_tag_t tag = ipc_call(hd, ((msg_tag_t){.flags = (0), .msg_buf_len = ((((off) / ((sizeof(void *)))) + (((off) % ((sizeof(void *)))) ? 1 : 0))), .map_buf_len = (0), .prot = (0)}), ipc_timeout_create2(0, 0));
if (((int16_t)((tag).prot)) < 0)
{
return tag;
}
off = 0;
do
{
if (1 == 1)
{
if (1 == 2 || 1 == 4)
{
int ret = rpc_cli_buf_to_msg_rpc_ref_array_uint32_t_uint8_t_32_t(var0, (uint8_t *)((uint8_t *)msg_ipc->msg_buf), off, tag.msg_buf_len * (sizeof(void *)));
if (ret < 0)
{
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)});
}
off = ret;
}
}
} while (0);
do
{
if (2 == 1)
{
if (4 == 2 || 4 == 4)
{
int ret = rpc_cli_buf_to_msg_rpc_obj_handler_t_t(var1, (uint8_t *)((uint8_t *)msg_ipc->msg_buf), off, tag.msg_buf_len * (sizeof(void *)));
if (ret < 0)
{
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)});
}
off = ret;
}
}
} while (0);
return tag;
}
int ns_register(const char *path, obj_handler_t svr_hd)
{
assert(path);
rpc_ref_array_uint32_t_uint8_t_32_t rpc_path = {
.data = path,
.len = strlen(path) + 1,
};
rpc_obj_handler_t_t rpc_svr_hd = {
.data = svr_hd,
};
msg_tag_t tag = ns_t_register_call(u_get_global_env()->ns_hd, &rpc_path, &rpc_svr_hd);
return msg_tag_get_val(tag);
}
int ns_query(const char *path, obj_handler_t *svr_hd)
{
assert(path);
assert(svr_hd);
obj_handler_t newfd;
newfd = find_hd(path);
if (newfd != HANDLER_INVALID)
{
return newfd;
}
newfd = handler_alloc();
if (newfd == HANDLER_INVALID)
{
return -ENOENT;
}
rpc_ref_array_uint32_t_uint8_t_32_t rpc_path = {
.data = path,
.len = strlen(path) + 1,
};
rpc_obj_handler_t_t rpc_svr_hd = {
.data = newfd,
};
msg_tag_t tag = ns_t_query_call(u_get_global_env()->ns_hd, &rpc_path, &rpc_svr_hd);
if (msg_tag_get_val(tag) < 0)
{
handler_free(newfd);
return msg_tag_get_val(tag);
}
if (reg_hd(path, newfd) == FALSE)
{
printf("客户端服务缓存区已满.\n");
handler_free_umap(newfd);
return -ENOMEM;
}
*svr_hd = newfd;
return msg_tag_get_val(tag);
}

View File

@@ -0,0 +1,177 @@
#include "rpc_prot.h"
#include "ns_svr.h"
#include "ns_types.h"
#include "u_rpc.h"
#include "u_rpc_svr.h"
#include "u_hd_man.h"
#include <stdio.h>
RPC_GENERATION_OP2(ns_t, NS_REGISTER_OP, register,
rpc_ref_array_uint32_t_uint8_t_32_t, rpc_array_uint32_t_uint8_t_32_t, RPC_DIR_IN, RPC_TYPE_DATA, path,
rpc_obj_handler_t_t, rpc_obj_handler_t_t, RPC_DIR_IN, RPC_TYPE_BUF, svr_hd)
{
path->data[path->len - 1] = 0;
int ret = namespace_register((char *)(path->data), obj->hd);
if (ret >= 0)
{
printf("注册服务[%s]成功.\n", (char *)(path->data));
}
else
{
printf("注册服务[%s]失败.\n", (char *)(path->data));
}
return ret;
}
RPC_GENERATION_DISPATCH2(ns_t, NS_REGISTER_OP, register,
rpc_ref_array_uint32_t_uint8_t_32_t, rpc_array_uint32_t_uint8_t_32_t, RPC_DIR_IN, RPC_TYPE_DATA, path,
rpc_obj_handler_t_t, rpc_obj_handler_t_t, RPC_DIR_IN, RPC_TYPE_BUF, svr_hd)
RPC_GENERATION_OP2(ns_t, NS_QUERY_OP, query,
rpc_ref_array_uint32_t_uint8_t_32_t, rpc_array_uint32_t_uint8_t_32_t, RPC_DIR_IN, RPC_TYPE_DATA, path,
rpc_obj_handler_t_t, rpc_obj_handler_t_t, RPC_DIR_INOUT, RPC_TYPE_BUF, cli_hd)
{
path->data[path->len - 1] = 0;
int ret = namespace_query((char *)(path->data), &cli_hd->data);
if (ret >= 0)
{
printf("请求服务[%s]成功.\n", (char *)(path->data));
}
else
{
printf("请求服务[%s]失败.\n", (char *)(path->data));
}
return ret;
}
// RPC_GENERATION_DISPATCH2(ns_t, NS_QUERY_OP, query,
// rpc_ref_array_uint32_t_uint8_t_32_t, rpc_array_uint32_t_uint8_t_32_t, RPC_DIR_IN, RPC_TYPE_DATA, path,
// rpc_obj_handler_t_t, rpc_obj_handler_t_t, RPC_DIR_INOUT, RPC_TYPE_BUF, cli_hd)
msg_tag_t ns_t_query_dispatch(ns_t *obj, msg_tag_t tag, ipc_msg_t *ipc_msg)
{
rpc_array_uint32_t_uint8_t_32_t var0;
rpc_obj_handler_t_t var1;
size_t op_val;
uint8_t *value = (uint8_t *)(ipc_msg->msg_buf);
int off = 0;
rpc_var_rpc_array_uint32_t_uint8_t_32_t_init(&var0);
rpc_var_rpc_obj_handler_t_t_init(&var1);
op_val = *((typeof(((uint16_t)1)) *)value);
if (op_val != ((uint16_t)1))
{
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (-71)});
}
off += sizeof(typeof(((uint16_t)1)));
off = rpc_align(off, __alignof(typeof(((uint16_t)1))));
do
{
if (1 == 1)
{
if (1 == 1 || 1 == 4)
{
int ret = rpc_svr_buf_to_msg_rpc_array_uint32_t_uint8_t_32_t(&var0, (uint8_t *)(value), off, tag.msg_buf_len * (sizeof(void *)));
if (ret < 0)
{
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)});
}
off = ret;
}
}
} while (0);
do
{
if (2 == 1)
{
if (4 == 1 || 4 == 4)
{
int ret = rpc_svr_buf_to_msg_rpc_obj_handler_t_t(&var1, (uint8_t *)(value), off, tag.msg_buf_len * (sizeof(void *)));
if (ret < 0)
{
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)});
}
off = ret;
}
}
} while (0);
short ret_val = ns_t_query_op(obj, &var0, &var1);
if (ret_val < 0)
{
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret_val)});
}
off = 0;
int off_map = 0;
do
{
if (1 == 1)
{
if (1 == 2 || 1 == 4)
{
int ret = rpc_svr_msg_to_buf_rpc_array_uint32_t_uint8_t_32_t(&var0, (uint8_t *)(value), off);
if (ret < 0)
{
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)});
}
off = ret;
}
}
} while (0);
do
{
if (2 == 1)
{
if (4 == 2 || 4 == 4)
{
int ret = rpc_svr_msg_to_buf_rpc_obj_handler_t_t(&var1, (uint8_t *)(value), off);
if (ret < 0)
{
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)});
}
off = ret;
}
}
} while (0);
do
{
if (1 == 2)
{
if (1 == 2 || 1 == 4)
{
int ret = rpc_svr_msg_to_buf_rpc_array_uint32_t_uint8_t_32_t(&var0, (uint8_t *)(ipc_msg->map_buf), off_map);
if (ret < 0)
{
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)});
}
off_map = ret;
}
}
} while (0);
do
{
if (2 == 2)
{
if (4 == 2 || 4 == 4)
{
int ret = rpc_svr_msg_to_buf_rpc_obj_handler_t_t(&var1, (uint8_t *)(ipc_msg->map_buf), off_map);
if (ret < 0)
{
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)});
}
off_map = ret;
}
}
} while (0);
return ((msg_tag_t){.flags = (0), .msg_buf_len = ((((off) / ((sizeof(void *)))) + (((off) % ((sizeof(void *)))) ? 1 : 0))), .map_buf_len = ((((off_map) / ((sizeof(void *)))) + (((off_map) % ((sizeof(void *)))) ? 1 : 0))), .prot = (ret_val)});
}
RPC_DISPATCH2(ns_t, typeof(NS_REGISTER_OP), NS_REGISTER_OP, register, NS_QUERY_OP, query)
void ns_init(ns_t *ns)
{
rpc_svr_obj_init(&ns->svr, rpc_ns_t_dispatch, NS_PROT);
for (int i = 0; i < NAMESAPCE_NR; i++)
{
ns->ne_list[i].hd = HANDLER_INVALID;
}
ns->hd = HANDLER_INVALID;
}

View File

@@ -1,4 +1,3 @@
/**
* @file u_rpc.h
* @author zhangzheng (1358745329@qq.com)
@@ -9,6 +8,7 @@
* @copyright Copyright (c) 2023
*
*/
#pragma once
#include "u_types.h"
#include "u_thread.h"
@@ -18,7 +18,7 @@
#include "u_task.h"
#include <stddef.h>
#include <sys/types.h>
#include <errno.h>
extern msg_tag_t dispatch_test(msg_tag_t tag, ipc_msg_t *msg);
/*rpc变量定义宏*/
@@ -538,157 +538,78 @@ RPC_TYPE_INIT_WITHOUT_IMPL(rpc_obj_handler_t_t)
} \
} \
} while (0)
/**
* @brief 该宏用于生成一个客户端的调用函数(传递一个参数)
*
*/
#define RPC_GENERATION_CALL1(struct_type, op, func_name, cli_type0, svr_type0, dir0, rpc_type0, name0) \
msg_tag_t struct_type##_##func_name##_call(obj_handler_t hd, cli_type0 *var0) \
#define RPC_DISPATCH1(struct_type, op_type, func0_op, func0_name) \
msg_tag_t rpc_##struct_type##_dispatch(struct_type *obj, msg_tag_t in_tag, ipc_msg_t *ipc_msg) \
{ \
void *buf; \
ipc_msg_t *msg_ipc; \
\
thread_msg_buf_get(THREAD_MAIN, (umword_t *)(&buf), NULL); \
msg_ipc = (ipc_msg_t *)buf; \
\
int off = 0; \
int off_map = 0; \
int ret = -1; \
int op_val = op; \
/*拷贝op*/ \
rpc_memcpy(msg_ipc->msg_buf, &op_val, sizeof(op_val)); \
off += rpc_align(sizeof(op_val), __alignof(op)); \
\
RPC_CLI_MSG_TO_BUF_IN(rpc_type0, cli_type0, var0, dir0, (uint8_t *)msg_ipc->msg_buf, off); \
PRC_CLI_FILL_MAP_BUF(rpc_type0, cli_type0, var0, dir0, (uint8_t *)msg_ipc->map_buf, off_map); \
/*msg_tag_t tag = dispatch_test(msg_tag_init4(0, ROUND_UP(off, WORD_BYTES), ROUND_UP(off_map, WORD_BYTES), 0), msg_ipc);*/ \
msg_tag_t tag = ipc_call(hd, msg_tag_init4(0, ROUND_UP(off, WORD_BYTES), 0, 0), \
ipc_timeout_create2(0, 0)); \
\
if (msg_tag_get_val(tag) < 0) \
{ \
return tag; \
} /*拷贝返回的数据*/ \
off = 0; \
RPC_CLI_BUF_TO_MSG_OUT(rpc_type0, cli_type0, var0, dir0, (uint8_t *)msg_ipc->msg_buf, off, tag.msg_buf_len *WORD_BYTES); \
return tag; \
}
/**
* @brief 该宏用于生成服务端的分发函数(一个参数)
*
*/
#define RPC_GENERATION_DISPATCH1(struct_type, op, func_name, \
cli_type0, svr_type0, dir0, rpc_type0, name0) \
msg_tag_t struct_type##_##func_name##_dispatch(struct_type *obj, msg_tag_t tag, ipc_msg_t *ipc_msg) \
{ \
svr_type0 var0; \
msg_tag_t tag = msg_tag_init4(0, 0, 0, -EPROTO); \
size_t op_val; \
uint8_t *value = (uint8_t *)(ipc_msg->msg_buf); \
int off = 0; \
\
RPC_TYPE_INIT_FUNC_CALL(svr_type0, &var0); \
\
/*取得op*/ \
op_val = *((typeof(op) *)value); \
off += sizeof(typeof(op)); \
off = rpc_align(off, __alignof(typeof(op))); \
\
RPC_SVR_BUF_TO_MSG_IN(rpc_type0, svr_type0, &var0, dir0, value, off, tag.msg_buf_len *WORD_BYTES); \
\
short ret_val = struct_type##_##func_name##_op(obj, &var0); \
\
if (ret_val < 0) \
op_val = *((op_type *)(ipc_msg->msg_buf)); \
switch (op_val) \
{ \
return msg_tag_init4(0, 0, 0, ret_val); \
case func0_op: \
{ \
tag = struct_type##_##func0_name##_dispatch(obj, in_tag, ipc_msg); \
} \
break; \
} \
off = 0; \
int off_map = 0; \
RPC_SVR_MSG_TO_BUF_OUT(rpc_type0, svr_type0, &var0, dir0, value, off); \
PRC_SVR_FILL_MAP_BUF(rpc_type0, svr_type0, &var0, dir0, value, off_map); \
return msg_tag_init4(0, ROUND_UP(off, WORD_BYTES), ROUND_UP(off_map, WORD_BYTES), ret_val); \
}
/**
* @brief 该宏用于生成一个服务端的实现(一个参数)
*
*/
#define RPC_GENERATION_OP1(struct_type, op, func_name, cli_type0, svr_type0, dir0, rpc_type0, name0) \
short struct_type##_##func_name##_op(struct_type *obj, svr_type0 *name0)
#define RPC_GENERATION_CALL2(struct_type, op, func_name, \
cli_type0, svr_type0, dir0, rpc_type0, name0, \
cli_type1, svr_type1, dir1, rpc_type1, name1) \
msg_tag_t struct_type##_##func_name##_call(obj_handler_t hd, cli_type0 *var0, cli_type1 *var1) \
{ \
void *buf; \
ipc_msg_t *msg_ipc; \
\
thread_msg_buf_get(THREAD_MAIN, (umword_t *)(&buf), NULL); \
msg_ipc = (ipc_msg_t *)buf; \
\
int off = 0; \
int off_buf = 0; \
int ret = -1; \
int op_val = op; \
/*拷贝op*/ \
rpc_memcpy(msg_ipc->msg_buf, &op_val, sizeof(op_val)); \
off += rpc_align(sizeof(op_val), __alignof(op)); \
\
RPC_CLI_MSG_TO_BUF_IN(rpc_type0, cli_type0, var0, dir0, (uint8_t *)msg_ipc->msg_buf, off); \
PRC_CLI_FILL_MAP_BUF(rpc_type0, cli_type0, var0, dir0, (uint8_t *)msg_ipc->map_buf, off_buf); \
RPC_CLI_MSG_TO_BUF_IN(rpc_type1, cli_type1, var1, dir1, (uint8_t *)msg_ipc->msg_buf, off); \
PRC_CLI_FILL_MAP_BUF(rpc_type1, cli_type1, var1, dir1, (uint8_t *)msg_ipc->map_buf, off_buf); \
/*msg_tag_t tag = dispatch_test(msg_tag_init4(0, ROUND_UP(off, WORD_BYTES), ROUND_UP(off_buf, WORD_BYTES), 0), msg_ipc); */ \
msg_tag_t tag = ipc_call(hd, msg_tag_init4(0, ROUND_UP(off, WORD_BYTES), 0, 0), \
ipc_timeout_create2(0, 0)); \
\
if (msg_tag_get_val(tag) < 0) \
{ \
return tag; \
} /*拷贝返回的数据*/ \
off = 0; \
RPC_CLI_BUF_TO_MSG_OUT(rpc_type0, cli_type0, var0, dir0, (uint8_t *)msg_ipc->msg_buf, off, tag.msg_buf_len *WORD_BYTES); \
RPC_CLI_BUF_TO_MSG_OUT(rpc_type1, cli_type1, var1, dir1, (uint8_t *)msg_ipc->msg_buf, off, tag.msg_buf_len *WORD_BYTES); \
return tag; \
}
#define RPC_GENERATION_DISPATCH2(struct_type, op, func_name, \
cli_type0, svr_type0, dir0, rpc_type0, name0, \
cli_type1, svr_type1, dir1, rpc_type1, name1) \
msg_tag_t struct_type##_##func_name##_dispatch(struct_type *obj, msg_tag_t tag, ipc_msg_t *ipc_msg) \
#define RPC_DISPATCH2(struct_type, op_type, func0_op, func0_name, func1_op, func1_name) \
msg_tag_t rpc_##struct_type##_dispatch(struct_type *obj, msg_tag_t in_tag, ipc_msg_t *ipc_msg) \
{ \
svr_type0 var0; \
svr_type1 var1; \
msg_tag_t tag = msg_tag_init4(0, 0, 0, -EPROTO); \
size_t op_val; \
uint8_t *value = (uint8_t *)(ipc_msg->msg_buf); \
int off = 0; \
\
RPC_TYPE_INIT_FUNC_CALL(svr_type0, &var0); \
RPC_TYPE_INIT_FUNC_CALL(svr_type1, &var1); \
\
/*取得op*/ \
op_val = *((typeof(op) *)value); \
off += sizeof(typeof(op)); \
off = rpc_align(off, __alignof(typeof(op))); \
\
RPC_SVR_BUF_TO_MSG_IN(rpc_type0, svr_type0, &var0, dir0, value, off, tag.msg_buf_len *WORD_BYTES); \
RPC_SVR_BUF_TO_MSG_IN(rpc_type1, svr_type1, &var1, dir1, value, off, tag.msg_buf_len *WORD_BYTES); \
\
short ret_val = struct_type##_##func_name##_op(obj, &var0, &var1); \
\
if (ret_val < 0) \
op_val = *((op_type *)(ipc_msg->msg_buf)); \
switch (op_val) \
{ \
return msg_tag_init4(0, 0, 0, ret_val); \
case func0_op: \
{ \
tag = struct_type##_##func0_name##_dispatch(obj, in_tag, ipc_msg); \
} \
off = 0; \
int off_map = 0; \
RPC_SVR_MSG_TO_BUF_OUT(rpc_type0, svr_type0, &var0, dir0, value, off); \
RPC_SVR_MSG_TO_BUF_OUT(rpc_type1, svr_type1, &var1, dir1, value, off); \
PRC_SVR_FILL_MAP_BUF(rpc_type0, svr_type0, &var0, dir0, ipc_msg->map_buf, off_map); \
PRC_SVR_FILL_MAP_BUF(rpc_type1, svr_type1, &var1, dir1, ipc_msg->map_buf, off_map); \
return msg_tag_init4(0, ROUND_UP(off, WORD_BYTES), ROUND_UP(off_map, WORD_BYTES), ret_val); \
break; \
case func1_op: \
{ \
tag = struct_type##_##func1_name##_dispatch(obj, in_tag, ipc_msg); \
} \
break; \
} \
return tag; \
}
#define RPC_GENERATION_OP2(struct_type, op, func_name, \
cli_type0, svr_type0, dir0, rpc_type0, name0, \
cli_type1, svr_type1, dir1, rpc_type1, name1) \
short struct_type##_##func_name##_op(struct_type *obj, svr_type0 *name0, svr_type1 *name1)
#define RPC_DISPATCH3(struct_type, op_type, func0_op, func0_name, func1_op, func1_name, func2_op, func2_name) \
msg_tag_t rpc_##struct_type##_dispatch(struct_type *obj, msg_tag_t in_tag, ipc_msg_t *ipc_msg) \
{ \
msg_tag_t tag = msg_tag_init4(0, 0, 0, -EPROTO); \
size_t op_val; \
\
op_val = *((op_type *)(ipc_msg->msg_buf)); \
switch (op_val) \
{ \
case func0_op: \
{ \
tag = struct_type##_##func0_name##_dispatch(obj, in_tag, ipc_msg); \
} \
break; \
case func1_op: \
{ \
tag = struct_type##_##func1_name##_dispatch(obj, in_tag, ipc_msg); \
} \
break; \
case func2_op: \
{ \
tag = struct_type##_##func2_name##_dispatch(obj, in_tag, ipc_msg); \
} \
break; \
} \
return tag; \
}
#include "u_rpc_1.h"
#include "u_rpc_2.h"
#include "u_rpc_3.h"

View File

@@ -0,0 +1,86 @@
#include "u_types.h"
#include "u_thread.h"
#include "u_err.h"
#include "u_prot.h"
#include "u_ipc.h"
#include "u_task.h"
#include <stddef.h>
#include <sys/types.h>
#include <errno.h>
/**
* @brief 该宏用于生成一个客户端的调用函数(传递一个参数)
*
*/
#define RPC_GENERATION_CALL1(struct_type, op, func_name, cli_type0, svr_type0, dir0, rpc_type0, name0) \
msg_tag_t struct_type##_##func_name##_call(obj_handler_t hd, cli_type0 *var0) \
{ \
void *buf; \
ipc_msg_t *msg_ipc; \
\
thread_msg_buf_get(THREAD_MAIN, (umword_t *)(&buf), NULL); \
msg_ipc = (ipc_msg_t *)buf; \
\
int off = 0; \
int off_map = 0; \
int ret = -1; \
int op_val = op; \
/*拷贝op*/ \
rpc_memcpy(msg_ipc->msg_buf, &op_val, sizeof(op_val)); \
off += rpc_align(sizeof(op_val), __alignof(op)); \
\
RPC_CLI_MSG_TO_BUF_IN(rpc_type0, cli_type0, var0, dir0, (uint8_t *)msg_ipc->msg_buf, off); \
PRC_CLI_FILL_MAP_BUF(rpc_type0, cli_type0, var0, dir0, (uint8_t *)msg_ipc->map_buf, off_map); \
/*msg_tag_t tag = dispatch_test(msg_tag_init4(0, ROUND_UP(off, WORD_BYTES), ROUND_UP(off_map, WORD_BYTES), 0), msg_ipc);*/ \
msg_tag_t tag = ipc_call(hd, msg_tag_init4(0, ROUND_UP(off, WORD_BYTES), ROUND_UP(off_buf, WORD_BYTES), 0), \
ipc_timeout_create2(0, 0)); \
\
if (msg_tag_get_val(tag) < 0) \
{ \
return tag; \
} /*拷贝返回的数据*/ \
off = 0; \
RPC_CLI_BUF_TO_MSG_OUT(rpc_type0, cli_type0, var0, dir0, (uint8_t *)msg_ipc->msg_buf, off, tag.msg_buf_len *WORD_BYTES); \
return tag; \
}
/**
* @brief 该宏用于生成服务端的分发函数(一个参数)
*
*/
#define RPC_GENERATION_DISPATCH1(struct_type, op, func_name, \
cli_type0, svr_type0, dir0, rpc_type0, name0) \
msg_tag_t struct_type##_##func_name##_dispatch(struct_type *obj, msg_tag_t tag, ipc_msg_t *ipc_msg) \
{ \
svr_type0 var0; \
size_t op_val; \
uint8_t *value = (uint8_t *)(ipc_msg->msg_buf); \
int off = 0; \
\
RPC_TYPE_INIT_FUNC_CALL(svr_type0, &var0); \
\
/*取得op*/ \
op_val = *((typeof(op) *)value); \
off += sizeof(typeof(op)); \
off = rpc_align(off, __alignof(typeof(op))); \
\
RPC_SVR_BUF_TO_MSG_IN(rpc_type0, svr_type0, &var0, dir0, value, off, tag.msg_buf_len *WORD_BYTES); \
\
short ret_val = struct_type##_##func_name##_op(obj, &var0); \
\
if (ret_val < 0) \
{ \
return msg_tag_init4(0, 0, 0, ret_val); \
} \
off = 0; \
int off_map = 0; \
RPC_SVR_MSG_TO_BUF_OUT(rpc_type0, svr_type0, &var0, dir0, value, off); \
PRC_SVR_FILL_MAP_BUF(rpc_type0, svr_type0, &var0, dir0, value, off_map); \
return msg_tag_init4(0, ROUND_UP(off, WORD_BYTES), ROUND_UP(off_map, WORD_BYTES), ret_val); \
}
/**
* @brief 该宏用于生成一个服务端的实现(一个参数)
*
*/
#define RPC_GENERATION_OP1(struct_type, op, func_name, cli_type0, svr_type0, dir0, rpc_type0, name0) \
short struct_type##_##func_name##_op(struct_type *obj, svr_type0 *name0)

View File

@@ -0,0 +1,92 @@
#include "u_types.h"
#include "u_thread.h"
#include "u_err.h"
#include "u_prot.h"
#include "u_ipc.h"
#include "u_task.h"
#include <stddef.h>
#include <sys/types.h>
#include <errno.h>
#define RPC_GENERATION_CALL2(struct_type, op, func_name, \
cli_type0, svr_type0, dir0, rpc_type0, name0, \
cli_type1, svr_type1, dir1, rpc_type1, name1) \
msg_tag_t struct_type##_##func_name##_call(obj_handler_t hd, cli_type0 *var0, cli_type1 *var1) \
{ \
void *buf; \
ipc_msg_t *msg_ipc; \
\
thread_msg_buf_get(THREAD_MAIN, (umword_t *)(&buf), NULL); \
msg_ipc = (ipc_msg_t *)buf; \
\
int off = 0; \
int off_buf = 0; \
int ret = -1; \
size_t op_val = op; \
/*拷贝op*/ \
rpc_memcpy(msg_ipc->msg_buf, &op_val, sizeof(op_val)); \
off += rpc_align(sizeof(op_val), __alignof(op)); \
\
RPC_CLI_MSG_TO_BUF_IN(rpc_type0, cli_type0, var0, dir0, (uint8_t *)msg_ipc->msg_buf, off); \
PRC_CLI_FILL_MAP_BUF(rpc_type0, cli_type0, var0, dir0, (uint8_t *)msg_ipc->map_buf, off_buf); \
RPC_CLI_MSG_TO_BUF_IN(rpc_type1, cli_type1, var1, dir1, (uint8_t *)msg_ipc->msg_buf, off); \
PRC_CLI_FILL_MAP_BUF(rpc_type1, cli_type1, var1, dir1, (uint8_t *)msg_ipc->map_buf, off_buf); \
/*msg_tag_t tag = dispatch_test(msg_tag_init4(0, ROUND_UP(off, WORD_BYTES), ROUND_UP(off_buf, WORD_BYTES), 0), msg_ipc); */ \
msg_tag_t tag = ipc_call(hd, msg_tag_init4(0, ROUND_UP(off, WORD_BYTES), ROUND_UP(off_buf, WORD_BYTES), 0), \
ipc_timeout_create2(0, 0)); \
\
if (msg_tag_get_val(tag) < 0) \
{ \
return tag; \
} /*拷贝返回的数据*/ \
off = 0; \
RPC_CLI_BUF_TO_MSG_OUT(rpc_type0, cli_type0, var0, dir0, (uint8_t *)msg_ipc->msg_buf, off, tag.msg_buf_len *WORD_BYTES); \
RPC_CLI_BUF_TO_MSG_OUT(rpc_type1, cli_type1, var1, dir1, (uint8_t *)msg_ipc->msg_buf, off, tag.msg_buf_len *WORD_BYTES); \
return tag; \
}
#define RPC_GENERATION_DISPATCH2(struct_type, op, func_name, \
cli_type0, svr_type0, dir0, rpc_type0, name0, \
cli_type1, svr_type1, dir1, rpc_type1, name1) \
msg_tag_t struct_type##_##func_name##_dispatch(struct_type *obj, msg_tag_t tag, ipc_msg_t *ipc_msg) \
{ \
svr_type0 var0; \
svr_type1 var1; \
size_t op_val; \
uint8_t *value = (uint8_t *)(ipc_msg->msg_buf); \
int off = 0; \
\
RPC_TYPE_INIT_FUNC_CALL(svr_type0, &var0); \
RPC_TYPE_INIT_FUNC_CALL(svr_type1, &var1); \
\
/*取得op*/ \
op_val = *((typeof(op) *)value); \
if (op_val != op) \
{ \
return msg_tag_init4(0, 0, 0, -EPROTO); \
} \
off += sizeof(typeof(op)); \
off = rpc_align(off, __alignof(typeof(op))); \
\
RPC_SVR_BUF_TO_MSG_IN(rpc_type0, svr_type0, &var0, dir0, value, off, tag.msg_buf_len *WORD_BYTES); \
RPC_SVR_BUF_TO_MSG_IN(rpc_type1, svr_type1, &var1, dir1, value, off, tag.msg_buf_len *WORD_BYTES); \
\
short ret_val = struct_type##_##func_name##_op(obj, &var0, &var1); \
\
if (ret_val < 0) \
{ \
return msg_tag_init4(0, 0, 0, ret_val); \
} \
off = 0; \
int off_map = 0; \
RPC_SVR_MSG_TO_BUF_OUT(rpc_type0, svr_type0, &var0, dir0, value, off); \
RPC_SVR_MSG_TO_BUF_OUT(rpc_type1, svr_type1, &var1, dir1, value, off); \
PRC_SVR_FILL_MAP_BUF(rpc_type0, svr_type0, &var0, dir0, ipc_msg->map_buf, off_map); \
PRC_SVR_FILL_MAP_BUF(rpc_type1, svr_type1, &var1, dir1, ipc_msg->map_buf, off_map); \
return msg_tag_init4(0, ROUND_UP(off, WORD_BYTES), ROUND_UP(off_map, WORD_BYTES), ret_val); \
}
#define RPC_GENERATION_OP2(struct_type, op, func_name, \
cli_type0, svr_type0, dir0, rpc_type0, name0, \
cli_type1, svr_type1, dir1, rpc_type1, name1) \
short struct_type##_##func_name##_op(struct_type *obj, svr_type0 *name0, svr_type1 *name1)

View File

@@ -0,0 +1,104 @@
#include "u_types.h"
#include "u_thread.h"
#include "u_err.h"
#include "u_prot.h"
#include "u_ipc.h"
#include "u_task.h"
#include <stddef.h>
#include <sys/types.h>
#include <errno.h>
#define RPC_GENERATION_CALL3(struct_type, op, func_name, \
cli_type0, svr_type0, dir0, rpc_type0, name0, \
cli_type1, svr_type1, dir1, rpc_type1, name1, \
cli_type2, svr_type2, dir2, rpc_type2, name2) \
msg_tag_t struct_type##_##func_name##_call(obj_handler_t hd, cli_type0 *var0, cli_type1 *var1, cli_type2 *var2) \
{ \
void *buf; \
ipc_msg_t *msg_ipc; \
\
thread_msg_buf_get(THREAD_MAIN, (umword_t *)(&buf), NULL); \
msg_ipc = (ipc_msg_t *)buf; \
\
int off = 0; \
int off_buf = 0; \
int ret = -1; \
size_t op_val = op; \
/*拷贝op*/ \
rpc_memcpy(msg_ipc->msg_buf, &op_val, sizeof(op_val)); \
off += rpc_align(sizeof(op_val), __alignof(op)); \
\
RPC_CLI_MSG_TO_BUF_IN(rpc_type0, cli_type0, var0, dir0, (uint8_t *)msg_ipc->msg_buf, off); \
PRC_CLI_FILL_MAP_BUF(rpc_type0, cli_type0, var0, dir0, (uint8_t *)msg_ipc->map_buf, off_buf); \
RPC_CLI_MSG_TO_BUF_IN(rpc_type1, cli_type1, var1, dir1, (uint8_t *)msg_ipc->msg_buf, off); \
PRC_CLI_FILL_MAP_BUF(rpc_type1, cli_type1, var1, dir1, (uint8_t *)msg_ipc->map_buf, off_buf); \
RPC_CLI_MSG_TO_BUF_IN(rpc_type2, cli_type2, var2, dir2, (uint8_t *)msg_ipc->msg_buf, off); \
PRC_CLI_FILL_MAP_BUF(rpc_type2, cli_type2, var2, dir2, (uint8_t *)msg_ipc->map_buf, off_buf); \
/*msg_tag_t tag = dispatch_test(msg_tag_init4(0, ROUND_UP(off, WORD_BYTES), ROUND_UP(off_buf, WORD_BYTES), 0), msg_ipc); */ \
msg_tag_t tag = ipc_call(hd, msg_tag_init4(0, ROUND_UP(off, WORD_BYTES), ROUND_UP(off_buf, WORD_BYTES), 0), \
ipc_timeout_create2(0, 0)); \
\
if (msg_tag_get_val(tag) < 0) \
{ \
return tag; \
} /*拷贝返回的数据*/ \
off = 0; \
RPC_CLI_BUF_TO_MSG_OUT(rpc_type0, cli_type0, var0, dir0, (uint8_t *)msg_ipc->msg_buf, off, tag.msg_buf_len *WORD_BYTES); \
RPC_CLI_BUF_TO_MSG_OUT(rpc_type1, cli_type1, var1, dir1, (uint8_t *)msg_ipc->msg_buf, off, tag.msg_buf_len *WORD_BYTES); \
RPC_CLI_BUF_TO_MSG_OUT(rpc_type2, cli_type2, var2, dir2, (uint8_t *)msg_ipc->msg_buf, off, tag.msg_buf_len *WORD_BYTES); \
return tag; \
}
#define RPC_GENERATION_DISPATCH3(struct_type, op, func_name, \
cli_type0, svr_type0, dir0, rpc_type0, name0, \
cli_type1, svr_type1, dir1, rpc_type1, name1, \
cli_type2, svr_type2, dir2, rpc_type2, name2) \
msg_tag_t struct_type##_##func_name##_dispatch(struct_type *obj, msg_tag_t tag, ipc_msg_t *ipc_msg) \
{ \
svr_type0 var0; \
svr_type1 var1; \
svr_type2 var2; \
size_t op_val; \
uint8_t *value = (uint8_t *)(ipc_msg->msg_buf); \
int off = 0; \
\
RPC_TYPE_INIT_FUNC_CALL(svr_type0, &var0); \
RPC_TYPE_INIT_FUNC_CALL(svr_type1, &var1); \
RPC_TYPE_INIT_FUNC_CALL(svr_type2, &var2); \
\
/*取得op*/ \
op_val = *((typeof(op) *)value); \
if (op_val != op) \
{ \
return msg_tag_init4(0, 0, 0, -EPROTO); \
} \
off += sizeof(typeof(op)); \
off = rpc_align(off, __alignof(typeof(op))); \
\
RPC_SVR_BUF_TO_MSG_IN(rpc_type0, svr_type0, &var0, dir0, value, off, tag.msg_buf_len *WORD_BYTES); \
RPC_SVR_BUF_TO_MSG_IN(rpc_type1, svr_type1, &var1, dir1, value, off, tag.msg_buf_len *WORD_BYTES); \
RPC_SVR_BUF_TO_MSG_IN(rpc_type2, svr_type2, &var2, dir2, value, off, tag.msg_buf_len *WORD_BYTES); \
\
short ret_val = struct_type##_##func_name##_op(obj, &var0, &var1, &var2); \
\
if (ret_val < 0) \
{ \
return msg_tag_init4(0, 0, 0, ret_val); \
} \
off = 0; \
int off_map = 0; \
RPC_SVR_MSG_TO_BUF_OUT(rpc_type0, svr_type0, &var0, dir0, value, off); \
RPC_SVR_MSG_TO_BUF_OUT(rpc_type1, svr_type1, &var1, dir1, value, off); \
RPC_SVR_MSG_TO_BUF_OUT(rpc_type2, svr_type2, &var2, dir2, value, off); \
PRC_SVR_FILL_MAP_BUF(rpc_type0, svr_type0, &var0, dir0, ipc_msg->map_buf, off_map); \
PRC_SVR_FILL_MAP_BUF(rpc_type1, svr_type1, &var1, dir1, ipc_msg->map_buf, off_map); \
PRC_SVR_FILL_MAP_BUF(rpc_type2, svr_type2, &var2, dir2, ipc_msg->map_buf, off_map); \
return msg_tag_init4(0, ROUND_UP(off, WORD_BYTES), ROUND_UP(off_map, WORD_BYTES), ret_val); \
}
#define RPC_GENERATION_OP3(struct_type, op, func_name, \
cli_type0, svr_type0, dir0, rpc_type0, name0, \
cli_type1, svr_type1, dir1, rpc_type1, name1, \
cli_type2, svr_type2, dir2, rpc_type2, name2) \
short struct_type##_##func_name##_op(struct_type *obj, svr_type0 *name0, svr_type1 *name1, svr_type2 *name2)

View File

@@ -0,0 +1,21 @@
#pragma once
#include "u_types.h"
#include "u_prot.h"
#include "u_ipc.h"
typedef msg_tag_t (*rpc_dispatch_func)(void *obj, msg_tag_t tag, ipc_msg_t *msg);
typedef struct rpc_svr_obj
{
mword_t prot; //!< 支持的协议
rpc_dispatch_func dispatch; //!< 分发函数
} rpc_svr_obj_t;
static inline int rpc_svr_obj_init(rpc_svr_obj_t *obj, rpc_dispatch_func dis, mword_t prot)
{
obj->dispatch = dis;
obj->prot = prot;
}
int rpc_creaite_bind_ipc(obj_handler_t th, void *obj, obj_handler_t *ipc_hd);
void rpc_loop(obj_handler_t ipc_hd, rpc_svr_obj_t *svr_obj);

View File

@@ -3,16 +3,25 @@
#include "u_factory.h"
#include "u_hd_man.h"
#include "u_thread.h"
#include "u_rpc_svr.h"
#include <errno.h>
#include <assert.h>
#include <stdio.h>
/**
* @brief IPC
*
* @param th
* @param obj
* @param ret_ipc_hd
* @return int
*/
int rpc_creaite_bind_ipc(obj_handler_t th, void *obj, obj_handler_t *ret_ipc_hd)
{
obj_handler_t ipc_hd;
msg_tag_t tag;
assert(ipc_hd);
assert(ret_ipc_hd);
ipc_hd = handler_alloc();
if (ipc_hd == HANDLER_INVALID)
@@ -33,13 +42,22 @@ int rpc_creaite_bind_ipc(obj_handler_t th, void *obj, obj_handler_t *ret_ipc_hd)
*ret_ipc_hd = ipc_hd;
return 0;
}
void rpc_loop(obj_handler_t ipc_hd, msg_tag_t (*rpc_dispatch)(ipc_msg_t *msg))
/**
* @brief RPC循环处理消息
*
* @param ipc_hd
* @param svr_obj
* @param dispatch
*/
void rpc_loop(obj_handler_t ipc_hd, rpc_svr_obj_t *svr_obj)
{
umword_t obj;
msg_tag_t tag;
umword_t buf;
ipc_msg_t *msg;
assert(svr_obj);
thread_msg_buf_get(-1, &buf, NULL);
msg = (ipc_msg_t *)buf;
while (1)
@@ -49,8 +67,9 @@ void rpc_loop(obj_handler_t ipc_hd, msg_tag_t (*rpc_dispatch)(ipc_msg_t *msg))
{
continue;
}
if (rpc_dispatch) {
tag = rpc_dispatch(msg);
if (svr_obj->dispatch)
{
tag = svr_obj->dispatch(svr_obj, tag, msg);
}
ipc_reply(ipc_hd, tag);
}

View File

@@ -13,12 +13,14 @@ target_link_libraries(
muslc
sys
sys_util
sys_svr
${GCC_LIB_PATH}/libgcc.a
)
target_include_directories(
fatfs.elf
PUBLIC
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/sys/inc
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/sys_svr/inc
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/arch/arm/
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/arch/generic

View File

@@ -0,0 +1,61 @@
#include "u_rpc.h"
#include "u_rpc_svr.h"
#include "fs_svr.h"
#include <stdio.h>
#include "ff.h"
static fs_t fs;
void fs_svr_init(obj_handler_t ipc)
{
fs_init(&fs);
fs.ipc = ipc;
}
typedef struct file_desc
{
FIL fp;
} file_desc_t;
#define FILE_DESC_NR 16
static file_desc_t files[FILE_DESC_NR];
file_desc_t *alloc_file(int *fd)
{
for (int i = 0; i < FILE_DESC_NR; i++)
{
if (files[i].fp.obj.fs == NULL)
{
*fd = i;
return &files[i];
}
}
return NULL;
}
void free_file(int fd)
{
files[fd].fp.obj.fs = NULL;
}
int fs_svr_open(const char *path, int flags, int mode)
{
printf("open %s.\n", path);
int fd;
file_desc_t *file = alloc_file(&fd);
if (!file)
{
return -ENOMEM;
}
FRESULT ret = f_open(&file->fp, path, mode);
if (ret != FR_OK)
{
printf("open fail..\n");
free_file(fd);
}
return -ret;
}
void fs_svr_loop(void)
{
rpc_loop(fs.ipc, &fs.svr);
}

View File

@@ -0,0 +1,4 @@
#pragma once
void fs_svr_init(obj_handler_t ipc);
void fs_svr_loop(void);

View File

@@ -1,6 +1,11 @@
#include <ff.h>
#include "u_log.h"
#include "ns_cli.h"
#include "u_rpc_svr.h"
#include "u_prot.h"
#include "fs_rpc.h"
#include <ff.h>
#include <stdio.h>
#include <assert.h>
static FATFS fs;
static BYTE buff[512];
static MKFS_PARM defopt = {FM_ANY, 0, 0, 0};
@@ -30,6 +35,13 @@ int main(int args, char *argv[])
}
}
printf("mount success\n");
obj_handler_t ipc_hd;
int ret = rpc_creaite_bind_ipc(THREAD_MAIN, NULL, &ipc_hd);
assert(ret >= 0);
ns_register("fs", ipc_hd);
fs_svr_init(ipc_hd);
fs_svr_loop();
while (1)
;
return -1;

View File

@@ -2,7 +2,7 @@
#include "u_types.h"
#include "ram_disk.h"
#include <string.h>
#define RAM_DISK_SECTOR_NR 512
#define RAM_DISK_SECTOR_NR 256
static uint8_t ram_disk[RAM_DISK_SECTOR_NR * 512];

View File

@@ -11,6 +11,7 @@ target_link_libraries(init.elf
muslc
sys
sys_util
sys_svr
cpio
${GCC_LIB_PATH}/libgcc.a
)
@@ -19,6 +20,7 @@ target_include_directories(
PUBLIC
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/sys/inc
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/sys_util/inc
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/sys_svr/inc
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/cpio
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/arch/arm/

View File

@@ -13,8 +13,9 @@
#include "u_app_loader.h"
#include "test/test.h"
#include "rpc.h"
#include "u_rpc_svr.h"
#include "namespace.h"
#include "ns_svr.h"
extern void futex_init(void);
int main(int argc, char *args[])
@@ -44,16 +45,14 @@ int main(int argc, char *args[])
{
printf("app load fail, 0x%x\n", ret);
}
ns_init();
ns_pre_alloc_map_fd(thread_get_cur_ipc_msg());
namespace_init(ipc_hd);
ret = app_load("fatfs", &env);
if (ret < 0)
{
printf("app load fail, 0x%x\n", ret);
}
rpc_loop(ipc_hd, ns_dispatch);
namespace_loop();
task_unmap(TASK_THIS, vpage_create_raw3(KOBJ_DELETE_RIGHT, 0, TASK_THIS)); // 删除当前task以及申请得所有对象
printf("exit init.\n");
return 0;

View File

@@ -6,32 +6,19 @@
#include <stdio.h>
#include "u_hd_man.h"
#include "u_ipc.h"
#define NAMESPACE_PATH_LEN 32
#define NAMESAPCE_NR 32
#include "ns_types.h"
#include "ns_svr.h"
#include "namespace.h"
static ns_t ns;
typedef struct namespace_entry
void namespace_init(obj_handler_t ipc)
{
char path[NAMESPACE_PATH_LEN]; //!< 服务的路径名
obj_handler_t hd; //!< 服务的fd
} namespace_entry_t;
typedef struct namespace
{
namespace_entry_t ne_list[NAMESAPCE_NR]; //!< 服务列表
}
namespace_t;
static namespace_t ns;
void ns_init(void)
{
for (int i = 0; i < NAMESAPCE_NR; i++)
{
ns.ne_list[i].hd = HANDLER_INVALID;
}
ns_init(&ns);
namespace_pre_alloc_map_fd();
ns.ipc_hd = ipc;
}
static int ns_alloc(const char *path, obj_handler_t hd)
static int namespace_alloc(const char *path, obj_handler_t hd)
{
for (int i = 0; i < NAMESAPCE_NR; i++)
{
@@ -59,13 +46,14 @@ enum ns_op
* @param hd 注册的hd
* @return int
*/
int ns_register(const char *path, obj_handler_t hd)
int namespace_register(const char *path, obj_handler_t hd)
{
if (ns_alloc(path, hd) < 0)
if (namespace_alloc(path, hd) < 0)
{
return -1;
}
printf("register svr, name is %s, hd is %d\n", path, hd);
namespace_pre_alloc_map_fd();
return 0;
}
/**
@@ -75,7 +63,7 @@ int ns_register(const char *path, obj_handler_t hd)
* @param hd
* @return int
*/
int ns_query(const char *path, obj_handler_t *hd)
int namespace_query(const char *path, obj_handler_t *hd)
{
for (int i = 0; i < NAMESAPCE_NR; i++)
{
@@ -90,61 +78,68 @@ int ns_query(const char *path, obj_handler_t *hd)
}
return -1;
}
obj_handler_t pre_alloc_hd = HANDLER_INVALID; //!< 预备一个可用的fd
int ns_pre_alloc_map_fd(ipc_msg_t *msg)
int namespace_pre_alloc_map_fd(void)
{
ipc_msg_t *msg;
obj_handler_t hd = handler_alloc();
if (hd == HANDLER_INVALID)
{
return -1;
}
thread_msg_buf_get(-1, (umword_t *)(&msg), NULL);
msg->map_buf[0] = vpage_create_raw3(0, 0, hd).raw;
pre_alloc_hd = hd;
ns.hd = hd;
return 0;
}
msg_tag_t ns_dispatch(ipc_msg_t *msg)
void namespace_loop(void)
{
msg_tag_t tag = msg_tag_init4(0, 0, 0, -ENOSYS);
assert(msg);
switch (msg->msg_buf[0])
{
case OP_REGISTER: //!< 服务注册
{
size_t len = msg->msg_buf[1];
if (len > NAMESPACE_PATH_LEN)
{
tag = msg_tag_init4(0, 0, 0, -EINVAL);
break;
}
((char *)&(msg->msg_buf[2]))[len] = 0;
int ret = ns_register((char *)(&msg->msg_buf[2]), pre_alloc_hd);
ns_pre_alloc_map_fd(msg);
tag = msg_tag_init4(0, 0, 0, ret);
}
break;
case OP_QUERY: //!< 服务申请
{
obj_handler_t hd;
int ret = ns_query(((char *)&(msg->msg_buf[2])), &hd);
if (ret < 0)
{
tag = msg_tag_init4(0, 0, 0, ret);
}
else
{
size_t len = msg->msg_buf[1];
msg->map_buf[0] = vpage_create_raw3(0, 0, hd).raw;
printf("query..\n");
tag = msg_tag_init4(0, 0, 1, ret);
}
}
break;
default:
tag = msg_tag_init4(0, 0, 0, -ENOSYS);
break;
}
return tag;
rpc_loop(ns.ipc_hd, &ns.svr);
}
// msg_tag_t ns_dispatch(ipc_msg_t *msg)
// {
// msg_tag_t tag = msg_tag_init4(0, 0, 0, -ENOSYS);
// assert(msg);
// switch (msg->msg_buf[0])
// {
// case OP_REGISTER: //!< 服务注册
// {
// size_t len = msg->msg_buf[1];
// if (len > NAMESPACE_PATH_LEN)
// {
// tag = msg_tag_init4(0, 0, 0, -EINVAL);
// break;
// }
// ((char *)&(msg->msg_buf[2]))[len] = 0;
// int ret = ns_register((char *)(&msg->msg_buf[2]), pre_alloc_hd);
// ns_pre_alloc_map_fd(msg);
// tag = msg_tag_init4(0, 0, 0, ret);
// }
// break;
// case OP_QUERY: //!< 服务申请
// {
// obj_handler_t hd;
// int ret = ns_query(((char *)&(msg->msg_buf[2])), &hd);
// if (ret < 0)
// {
// tag = msg_tag_init4(0, 0, 0, ret);
// }
// else
// {
// size_t len = msg->msg_buf[1];
// msg->map_buf[0] = vpage_create_raw3(0, 0, hd).raw;
// printf("query..\n");
// tag = msg_tag_init4(0, 0, 1, ret);
// }
// }
// break;
// default:
// tag = msg_tag_init4(0, 0, 0, -ENOSYS);
// break;
// }
// return tag;
// }

View File

@@ -2,8 +2,9 @@
#include "u_types.h"
#include "u_prot.h"
void ns_init(void);
int ns_register(const char *path, obj_handler_t hd);
int ns_query(const char *path, obj_handler_t *hd);
msg_tag_t ns_dispatch(ipc_msg_t *msg);
int ns_pre_alloc_map_fd(ipc_msg_t *msg);
void namespace_init(obj_handler_t ipc);
int namespace_register(const char *path, obj_handler_t hd);
int namespace_query(const char *path, obj_handler_t *hd);
// msg_tag_t ns_dispatch(ipc_msg_t *msg);
int namespace_pre_alloc_map_fd(void);
void namespace_loop(void);

View File

@@ -1,6 +0,0 @@
#pragma once
#include "u_types.h"
int rpc_creaite_bind_ipc(obj_handler_t th, void *obj, obj_handler_t *ipc_hd);
void rpc_loop(obj_handler_t ipc_hd, msg_tag_t (*rpc_dispatch)(ipc_msg_t *msg));

View File

@@ -15,6 +15,7 @@ target_link_libraries(shell.elf
muslc
sys
sys_util
sys_svr
${GCC_LIB_PATH}/libgcc.a
)
target_include_directories(
@@ -22,6 +23,7 @@ target_include_directories(
PUBLIC
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/sys/inc
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/sys_util/inc
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/sys_svr/inc
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/arch/arm/
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/arch/generic

View File

@@ -11,6 +11,7 @@
#include "u_ns.h"
#include "test.h"
#include "u_rpc.h"
#include "ns_cli.h"
#include <assert.h>
#include <stdio.h>
#include <malloc.h>
@@ -33,6 +34,7 @@ void malloc_test(void)
}
void ns_test(void)
{
#if 0
int ret;
obj_handler_t tmp_ipc_hd;
@@ -45,6 +47,24 @@ void ns_test(void)
ret = cli_ns_query("shell", &tmp_ipc_hd);
assert(ret >= 0);
ulog_write_str(u_get_global_env()->log_hd, "ns test success.\n");
#endif
obj_handler_t tmp_ipc_hd;
tmp_ipc_hd = handler_alloc();
assert(tmp_ipc_hd != HANDLER_INVALID);
msg_tag_t tag = factory_create_ipc(FACTORY_PROT, vpage_create_raw3(0, 0, tmp_ipc_hd));
assert(ns_register("shell", tmp_ipc_hd) >= 0);
obj_handler_t rcv_ipc_hd;
assert(ns_query("shell", &rcv_ipc_hd) >= 0);
handler_free_umap(rcv_ipc_hd);
}
#include "fs_cli.h"
void fs_test(void)
{
fs_open("/test", 0, 0);
}
int main(int argc, char *args[])
{
@@ -56,6 +76,7 @@ int main(int argc, char *args[])
#endif
rpc_test();
ns_test();
fs_test();
task_unmap(TASK_THIS, vpage_create_raw3(KOBJ_DELETE_RIGHT, 0, TASK_THIS));
ulog_write_str(u_get_global_env()->log_hd, "Error.\n");
return 0;