From 48557de14897afb0965695d272d07f83f0b08c42 Mon Sep 17 00:00:00 2001 From: Fan Yang <93824713+helloeagleyang@users.noreply.github.com> Date: Wed, 17 May 2023 17:40:18 +0800 Subject: [include][src] Add API to get object name and thread name (#7507) Signed-off-by: Fan YANG Co-authored-by: Man, Jianting (Meco) <920369182@qq.com> --- src/object.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/object.c') diff --git a/src/object.c b/src/object.c index 04e0a03551..d1815f7e23 100644 --- a/src/object.c +++ b/src/object.c @@ -635,6 +635,30 @@ rt_object_t rt_object_find(const char *name, rt_uint8_t type) return RT_NULL; } +/** + * @brief This function will return the name of the specified object container + * + * @param object the specified object to be get name + * @param name buffer to store the object name string + * @param name_size maximum size of the buffer to store object name + * + * @return -RT_EINVAL if any parameter is invalid or RT_EOK if the operation is successfully executed + * + * @note this function shall not be invoked in interrupt status + */ +rt_err_t rt_object_get_name(rt_object_t object, char *name, rt_uint8_t name_size) +{ + rt_err_t result = -RT_EINVAL; + if ((object != RT_NULL) && (name != RT_NULL) && (name_size != 0U)) + { + const char *obj_name = object->name; + (void) rt_strncpy(name, obj_name, (rt_size_t)name_size); + result = RT_EOK; + } + + return result; +} + #ifdef RT_USING_HEAP /** * This function will create a custom object -- cgit v1.3.1