diff options
| author | Shell <[email protected]> | 2024-05-17 13:19:00 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-05-17 13:19:00 +0800 |
| commit | f2d6325b43ea1e390f034e03340b41662351b441 (patch) | |
| tree | 8933d6e52221a7f642148addac77750ef7dbc3a3 /src/object.c | |
| parent | 3d30b56c8631ed3b5fa5fbda71d1ef21853afc9d (diff) | |
[smart] select console device dynamically (#8949)
* [smart] select console device dynamically
- Fixed compiler warning on terminal subsystem for
`components/lwp/terminal/terminal.h`
- Updated default console setup to dynamically select an appropriate tty
device based on the configured console device name.
Signed-off-by: Shell <[email protected]>
* fixup: remove useless codes
---------
Signed-off-by: Shell <[email protected]>
Diffstat (limited to 'src/object.c')
| -rw-r--r-- | src/object.c | 67 |
1 files changed, 58 insertions, 9 deletions
diff --git a/src/object.c b/src/object.c index bdb69364ce..ae62be1fa3 100644 --- a/src/object.c +++ b/src/object.c @@ -575,29 +575,32 @@ rt_uint8_t rt_object_get_type(rt_object_t object) } /** - * @brief This function will find specified name object from object + * @brief This function will iterate through each object from object * container. * - * @param name is the specified name of object. - * * @param type is the type of object + * @param iter is the iterator + * @param data is the specified data passed to iterator * - * @return the found object or RT_NULL if there is no this object - * in object container. + * @return RT_EOK on succeed, otherwise the error from `iter` * * @note this function shall not be invoked in interrupt status. */ -rt_object_t rt_object_find(const char *name, rt_uint8_t type) +rt_err_t rt_object_for_each(rt_uint8_t type, rt_object_iter_t iter, void *data) { struct rt_object *object = RT_NULL; struct rt_list_node *node = RT_NULL; struct rt_object_information *information = RT_NULL; rt_base_t level; + rt_err_t error; information = rt_object_get_information((enum rt_object_class_type)type); /* parameter check */ - if ((name == RT_NULL) || (information == RT_NULL)) return RT_NULL; + if (information == RT_NULL) + { + return -RT_EINVAL; + } /* which is invoke in interrupt status */ RT_DEBUG_NOT_IN_INTERRUPT; @@ -609,16 +612,62 @@ rt_object_t rt_object_find(const char *name, rt_uint8_t type) rt_list_for_each(node, &(information->object_list)) { object = rt_list_entry(node, struct rt_object, list); - if (rt_strncmp(object->name, name, RT_NAME_MAX) == 0) + if ((error = iter(object, data)) != RT_EOK) { rt_spin_unlock_irqrestore(&(information->spinlock), level); - return object; + return error >= 0 ? RT_EOK : error; } } rt_spin_unlock_irqrestore(&(information->spinlock), level); + return RT_EOK; +} + +static rt_err_t _match_name(struct rt_object *obj, void *data) +{ + const char *name = *(const char **)data; + if (rt_strncmp(obj->name, name, RT_NAME_MAX) == 0) + { + *(rt_object_t *)data = obj; + + /* notify an early break of loop, but not on error */ + return 1; + } + + return RT_EOK; +} + +/** + * @brief This function will find specified name object from object + * container. + * + * @param name is the specified name of object. + * + * @param type is the type of object + * + * @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_object_find(const char *name, rt_uint8_t type) +{ + void *data = (void *)name; + + /* parameter check */ + if (name == RT_NULL) return RT_NULL; + + /* which is invoke in interrupt status */ + RT_DEBUG_NOT_IN_INTERRUPT; + + rt_object_for_each(type, _match_name, &data); + if (data != name) + { + return data; + } + return RT_NULL; } |
