From 4e2a6cc36179c1b5ffae707f9485e56c964b8988 Mon Sep 17 00:00:00 2001 From: bernard Date: Mon, 21 Jul 2014 06:28:43 +0800 Subject: [PATCH] [Kernel] The rt_object_find routine can support to find an object inside a module. The usage is: rt_object_find("module_name/object_name"). --- src/object.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 5 deletions(-) diff --git a/src/object.c b/src/object.c index ed3173a0f5..32dc0f2384 100644 --- a/src/object.c +++ b/src/object.c @@ -403,22 +403,77 @@ rt_object_t rt_object_find(const char *name, rt_uint8_t type) { struct rt_object *object; struct rt_list_node *node; - struct rt_object_information *information; - extern volatile rt_uint8_t rt_interrupt_nest; + struct rt_object_information *information = RT_NULL; /* parameter check */ if ((name == RT_NULL) || (type > RT_Object_Class_Unknown)) return RT_NULL; /* which is invoke in interrupt status */ - if (rt_interrupt_nest != 0) - RT_ASSERT(0); + RT_DEBUG_NOT_IN_INTERRUPT; + +#ifdef RT_USING_MODULE + /* check whether to find a object inside a module. */ + { + const char *name_ptr; + int module_name_length; + + name_ptr = name; + while ((*name_ptr != '\0') && (*name_ptr != '/')) + name_ptr ++; + + if (*name_ptr == '/') + { + struct rt_module* module = RT_NULL; + + /* get the name length of module */ + module_name_length = name_ptr - name; + + /* enter critical */ + rt_enter_critical(); + + /* find module */ + information = &rt_object_container[RT_Object_Class_Module]; + for (node = information->object_list.next; + node != &(information->object_list); + node = node->next) + { + object = rt_list_entry(node, struct rt_object, list); + if ((rt_strncmp(object->name, name, module_name_length) == 0) && + module_name_length == RT_NAME_MAX || object->name[module_name_length] == '\0') + { + /* get module */ + module = (struct rt_module*)object; + break; + } + } + rt_exit_critical(); + + /* there is no this module inside the system */ + if (module == RT_NULL) return RT_NULL; + + /* get the object pool of module */ + information = &(module->module_object[type]); + + /* get object name */ + while ((*name_ptr == '/') && (*name_ptr != '\0')) name_ptr ++; + if (*name_ptr == '\0') + { + if (type == RT_Object_Class_Module) return object; + return RT_NULL; + } + + /* point to the object name */ + name = name_ptr; + } + } +#endif /* enter critical */ rt_enter_critical(); /* try to find object */ - information = &rt_object_container[type]; + if (information == RT_NULL) information = &rt_object_container[type]; for (node = information->object_list.next; node != &(information->object_list); node = node->next)