From ecf2d8215961ca7c539132b62a72df6072cc3e14 Mon Sep 17 00:00:00 2001 From: guo Date: Sat, 3 Dec 2022 12:07:44 +0800 Subject: sync branch rt-smart. (#6641) * Synchronize the code of the rt mart branch to the master branch. * TTY device * Add lwP code from rt-smart * Add vnode in DFS, but DFS will be re-write for rt-smart * There are three libcpu for rt-smart: * arm/cortex-a, arm/aarch64 * riscv64 Co-authored-by: Rbb666 Co-authored-by: zhkag --- src/object.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) (limited to 'src/object.c') diff --git a/src/object.c b/src/object.c index cb177edbe6..606e4c00ff 100644 --- a/src/object.c +++ b/src/object.c @@ -23,6 +23,17 @@ #include #endif /* RT_USING_MODULE */ +#ifdef RT_USING_LWP +#include +#endif + +struct rt_custom_object +{ + struct rt_object parent; + rt_err_t (*destroy)(void *); + void *data; +}; + /* * define object_info for the number of _object_container items. */ @@ -59,6 +70,12 @@ enum rt_object_info_type #endif #ifdef RT_USING_HEAP RT_Object_Info_Memory, /**< The object is a memory. */ +#endif +#ifdef RT_USING_LWP + RT_Object_Info_Channel, /**< The object is a IPC channel */ +#endif +#ifdef RT_USING_HEAP + RT_Object_Info_Custom, /**< The object is a custom object */ #endif RT_Object_Info_Unknown, /**< The object is unknown. */ }; @@ -112,6 +129,11 @@ static struct rt_object_information _object_container[RT_Object_Info_Unknown] = /* initialize object container - small memory */ {RT_Object_Class_Memory, _OBJ_CONTAINER_LIST_INIT(RT_Object_Info_Memory), sizeof(struct rt_memory)}, #endif +#ifdef RT_USING_LWP + /* initialize object container - module */ + {RT_Object_Class_Channel, _OBJ_CONTAINER_LIST_INIT(RT_Object_Info_Channel), sizeof(struct rt_channel)}, + {RT_Object_Class_Custom, _OBJ_CONTAINER_LIST_INIT(RT_Object_Info_Custom), sizeof(struct rt_custom_object)}, +#endif }; #ifndef __on_rt_object_attach_hook @@ -607,4 +629,60 @@ rt_object_t rt_object_find(const char *name, rt_uint8_t type) return RT_NULL; } +#ifdef RT_USING_HEAP +/** + * This function will create a custom object + * container. + * + * @param name the specified name of object. + * @param type the type of object + * @param data the custom data + * @param data_destroy the custom object destroy callback + * + * @return the found object or RT_NULL if there is no this object + * in object container. + * + * @note this function shall not be invoked in interrupt status. + */ + +rt_object_t rt_custom_object_create(const char *name, void *data, rt_err_t (*data_destroy)(void *)) +{ + struct rt_custom_object *cobj = RT_NULL; + + cobj = (struct rt_custom_object *)rt_object_allocate(RT_Object_Class_Custom, name); + if (!cobj) + { + return RT_NULL; + } + cobj->destroy = data_destroy; + cobj->data = data; + return (struct rt_object *)cobj; +} + +/** + * This function will destroy a custom object + * container. + * + * @param obj the specified name of object. + * + * @note this function shall not be invoked in interrupt status. + */ +rt_err_t rt_custom_object_destroy(rt_object_t obj) +{ + rt_err_t ret = -1; + + struct rt_custom_object *cobj = (struct rt_custom_object *)obj; + + if (obj && obj->type == RT_Object_Class_Custom) + { + if (cobj->destroy) + { + ret = cobj->destroy(cobj->data); + } + rt_object_delete(obj); + } + return ret; +} +#endif + /**@}*/ -- cgit v1.3.1