|
enum | rt_object_class_type {
RT_Object_Class_Null = 0x00
, RT_Object_Class_Thread = 0x01
, RT_Object_Class_Semaphore = 0x02
, RT_Object_Class_Mutex = 0x03
,
RT_Object_Class_Event = 0x04
, RT_Object_Class_MailBox = 0x05
, RT_Object_Class_MessageQueue = 0x06
, RT_Object_Class_MemHeap = 0x07
,
RT_Object_Class_MemPool = 0x08
, RT_Object_Class_Device = 0x09
, RT_Object_Class_Timer = 0x0a
, RT_Object_Class_Module = 0x0b
,
RT_Object_Class_Memory = 0x0c
, RT_Object_Class_Channel = 0x0d
, RT_Object_Class_ProcessGroup = 0x0e
, RT_Object_Class_Session = 0x0f
,
RT_Object_Class_Custom = 0x10
, RT_Object_Class_Unknown = 0x11
, RT_Object_Class_Static = 0x80
} |
|
|
struct rt_object_information * | rt_object_get_information (enum rt_object_class_type type) |
|
int | rt_object_get_length (enum rt_object_class_type type) |
|
int | rt_object_get_pointers (enum rt_object_class_type type, rt_object_t *pointers, int maxlen) |
|
void | rt_object_init (struct rt_object *object, enum rt_object_class_type type, const char *name) |
|
void | rt_object_detach (rt_object_t object) |
|
rt_object_t | rt_object_allocate (enum rt_object_class_type type, const char *name) |
|
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_err_t | rt_object_for_each (rt_uint8_t type, rt_object_iter_t iter, void *data) |
|
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) |
|
rt_object_t | rt_custom_object_create (const char *name, void *data, rt_err_t(*data_destroy)(void *)) |
|
rt_err_t | rt_custom_object_destroy (rt_object_t obj) |
|
kernel object management
The Kernel object system can access and manage all of the kernel objects.
Kernel objects include most of the facilities in the kernel:
- thread
- semaphore and mutex
- event/fast event, mailbox, messagequeue
- memory pool
- timer
Figure 2: Kernel Object
Kernel objects can be static objects, whose memory is allocated in compiling. It can be dynamic objects as well, whose memory is allocated from system heaps in runtime.
◆ RT_OBJECT_FLAG_MODULE
#define RT_OBJECT_FLAG_MODULE 0x80 |
◆ _RT_OBJECT_HOOK_CALL
#define _RT_OBJECT_HOOK_CALL |
( |
|
func, |
|
|
|
argv |
|
) |
| __ON_HOOK_ARGS(func, argv) |
Add hook point in the routines.
The hook function call macro
- Note
- Usage: void foo() { do_something();
RT_OBJECT_HOOK_CALL(foo);
do_other_things(); }
◆ rt_object_t
◆ rt_object_iter_t
typedef rt_err_t(* rt_object_iter_t) (rt_object_t object, void *data) |
iterator of rt_object_for_each()
data is the data passing in to rt_object_for_each(). iterator can return RT_EOK to continue the iteration; or any positive value to break the loop successfully; or any negative errno to break the loop on failure.
◆ rt_object_class_type
The object type can be one of the follows with specific macros enabled:
- Thread
- Semaphore
- Mutex
- Event
- MailBox
- MessageQueue
- MemHeap
- MemPool
- Device
- Timer
- Module
- Unknown
- Static
Enumerator |
---|
RT_Object_Class_Null | The object is not used.
|
RT_Object_Class_Thread | The object is a thread.
|
RT_Object_Class_Semaphore | The object is a semaphore.
|
RT_Object_Class_Mutex | The object is a mutex.
|
RT_Object_Class_Event | The object is a event.
|
RT_Object_Class_MailBox | The object is a mail box.
|
RT_Object_Class_MessageQueue | The object is a message queue.
|
RT_Object_Class_MemHeap | The object is a memory heap.
|
RT_Object_Class_MemPool | The object is a memory pool.
|
RT_Object_Class_Device | The object is a device.
|
RT_Object_Class_Timer | The object is a timer.
|
RT_Object_Class_Module | The object is a module.
|
RT_Object_Class_Memory | The object is a memory.
|
RT_Object_Class_Channel | The object is a channel
|
RT_Object_Class_ProcessGroup | The object is a process group
|
RT_Object_Class_Session | The object is a session
|
RT_Object_Class_Custom | The object is a custom object
|
RT_Object_Class_Unknown | The object is unknown.
|
RT_Object_Class_Static | The object is a static object.
|
◆ rt_object_get_information()
This function will return the specified type of object information.
- Parameters
-
type | is the type of object, which can be RT_Object_Class_Thread/Semaphore/Mutex... etc |
- Returns
- the object type information or RT_NULL
◆ rt_object_get_length()
This function will return the length of object list in object container.
- Parameters
-
type | is the type of object, which can be RT_Object_Class_Thread/Semaphore/Mutex... etc |
- Returns
- the length of object list
◆ rt_object_get_pointers()
This function will copy the object pointer of the specified type, with the maximum size specified by maxlen.
- Parameters
-
type | is the type of object, which can be RT_Object_Class_Thread/Semaphore/Mutex... etc |
pointers | is the pointer will be saved to. |
maxlen | is the maximum number of pointers can be saved. |
- Returns
- the copied number of object pointers.
◆ rt_object_init()
This function will initialize an object and add it to object system management.
- Parameters
-
object | is the specified object to be initialized. |
type | is the object type. |
name | is the object name. In system, the object's name must be unique. |
◆ rt_object_detach()
This function will detach a static object from object system, and the memory of static object is not freed.
- Parameters
-
object | the specified object to be detached. |
◆ rt_object_allocate()
This function will allocate an object from object system.
- Parameters
-
type | is the type of object. |
name | is the object name. In system, the object's name must be unique. |
- Returns
- object
◆ rt_object_delete()
This function will delete an object and release object memory.
- Parameters
-
object | is the specified object to be deleted. |
◆ rt_object_is_systemobject()
rt_bool_t rt_object_is_systemobject |
( |
rt_object_t |
object | ) |
|
This function will judge the object is system object or not.
- Note
- Normally, the system object is a static object and the type of object set to RT_Object_Class_Static.
- Parameters
-
object | is the specified object to be judged. |
- Returns
- RT_TRUE if a system object, RT_FALSE for others.
◆ rt_object_get_type()
This function will return the type of object without RT_Object_Class_Static flag.
- Parameters
-
object | is the specified object to be get type. |
- Returns
- the type of object.
◆ rt_object_for_each()
rt_err_t rt_object_for_each |
( |
rt_uint8_t |
type, |
|
|
rt_object_iter_t |
iter, |
|
|
void * |
data |
|
) |
| |
This function will iterate through each object from object container.
- Parameters
-
type | is the type of object |
iter | is the iterator |
data | is the specified data passed to iterator |
- Returns
- RT_EOK on succeed, otherwise the error from
iter
- Note
- this function shall not be invoked in interrupt status.
◆ rt_object_find()
rt_object_t rt_object_find |
( |
const char * |
name, |
|
|
rt_uint8_t |
type |
|
) |
| |
This function will find specified name object from object container.
- Parameters
-
name | is the specified name of object. |
type | is the type of object |
- Returns
- 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_get_name()
rt_err_t rt_object_get_name |
( |
rt_object_t |
object, |
|
|
char * |
name, |
|
|
rt_uint8_t |
name_size |
|
) |
| |
This function will return the name of the specified object container.
- Parameters
-
object | the specified object to be get name |
name | buffer to store the object name string |
name_size | maximum size of the buffer to store object name |
- Returns
- -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_custom_object_create()
rt_object_t rt_custom_object_create |
( |
const char * |
name, |
|
|
void * |
data, |
|
|
rt_err_t(*)(void *) |
data_destroy |
|
) |
| |
This function will create a custom object container.
- Parameters
-
name | the specified name of object. |
data | the custom data |
data_destroy | the custom object destroy callback |
- Returns
- 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_custom_object_destroy()
This function will destroy a custom object container.
- Parameters
-
obj | the specified name of object. |
- Note
- this function shall not be invoked in interrupt status.