Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[include][src] Add API to get object name and thread name #7507

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/rtthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ void rt_object_delete(rt_object_t object);
rt_bool_t rt_object_is_systemobject(rt_object_t object);
rt_uint8_t rt_object_get_type(rt_object_t object);
rt_object_t rt_object_find(const char *name, rt_uint8_t type);
rt_err_t rt_object_get_name(rt_object_t object, char *name, rt_uint8_t name_size);

#ifdef RT_USING_HEAP
/* custom object */
Expand Down Expand Up @@ -169,6 +170,8 @@ void rt_thread_wakeup_set(struct rt_thread *thread, rt_wakeup_func_t func, void*
#endif
void rt_thread_timeout(void *parameter);

rt_err_t rt_thread_get_name(rt_thread_t thread, char *name, rt_uint8_t name_size);

#ifdef RT_USING_SIGNALS
void rt_thread_alloc_sig(rt_thread_t tid);
void rt_thread_free_sig(rt_thread_t tid);
Expand Down
24 changes: 24 additions & 0 deletions src/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions src/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -1142,4 +1142,22 @@ rt_thread_t rt_thread_find(char *name)

RTM_EXPORT(rt_thread_find);

/**
* @brief This function will return the name of the specified thread
*
* @note Please don't invoke this function in interrupt status
*
* @param thread the thread to retrieve thread name
* @param name buffer to store the thread name string
* @param name_size maximum size of the buffer to store the thread name
*
* @return If the return value is RT_EOK, the function is successfully executed
* If the return value is -RT_EINVAL, it means this operation failed
*/
rt_err_t rt_thread_get_name(rt_thread_t thread, char *name, rt_uint8_t name_size)
{
return (thread == RT_NULL) ? -RT_EINVAL : rt_object_get_name(&thread->parent, name, name_size);
}
RTM_EXPORT(rt_thread_get_name);

/**@}*/