ChibiOS/RT
5.1.0
|
The object factory is a subsystem that allows to:
Allocated OS objects are handled using a reference counter, only when all references have been released then the object memory is freed in a pool.
CH_CFG_USE_MEMCORE
and CH_CFG_USE_MEMPOOLS
options to be set to TRUE
. The option CH_CFG_USE_HEAP
is also required if the support for variable length objects is enabled. Macros | |
#define | CH_CFG_FACTORY_MAX_NAMES_LENGTH 8 |
Maximum length for object names. More... | |
#define | CH_CFG_FACTORY_OBJECTS_REGISTRY TRUE |
Enables the registry of generic objects. More... | |
#define | CH_CFG_FACTORY_GENERIC_BUFFERS TRUE |
Enables factory for generic buffers. More... | |
#define | CH_CFG_FACTORY_SEMAPHORES TRUE |
Enables factory for semaphores. More... | |
#define | CH_CFG_FACTORY_SEMAPHORES FALSE |
Enables factory for semaphores. More... | |
#define | CH_CFG_FACTORY_MAILBOXES TRUE |
Enables factory for mailboxes. More... | |
#define | CH_CFG_FACTORY_MAILBOXES FALSE |
Enables factory for mailboxes. More... | |
#define | CH_CFG_FACTORY_OBJ_FIFOS TRUE |
Enables factory for objects FIFOs. More... | |
#define | CH_CFG_FACTORY_OBJ_FIFOS FALSE |
Enables factory for objects FIFOs. More... | |
Typedefs | |
typedef struct ch_dyn_element | dyn_element_t |
Type of a dynamic object list element. More... | |
typedef struct ch_dyn_list | dyn_list_t |
Type of a dynamic object list. More... | |
typedef struct ch_registered_static_object | registered_object_t |
Type of a registered object. More... | |
typedef struct ch_dyn_object | dyn_buffer_t |
Type of a dynamic buffer object. More... | |
typedef struct ch_dyn_semaphore | dyn_semaphore_t |
Type of a dynamic semaphore. More... | |
typedef struct ch_dyn_mailbox | dyn_mailbox_t |
Type of a dynamic buffer object. More... | |
typedef struct ch_dyn_objects_fifo | dyn_objects_fifo_t |
Type of a dynamic buffer object. More... | |
typedef struct ch_objects_factory | objects_factory_t |
Type of the factory main object. More... | |
Data Structures | |
struct | ch_dyn_element |
Type of a dynamic object list element. More... | |
struct | ch_dyn_list |
Type of a dynamic object list. More... | |
struct | ch_registered_static_object |
Type of a registered object. More... | |
struct | ch_dyn_object |
Type of a dynamic buffer object. More... | |
struct | ch_dyn_semaphore |
Type of a dynamic semaphore. More... | |
struct | ch_dyn_mailbox |
Type of a dynamic buffer object. More... | |
struct | ch_dyn_objects_fifo |
Type of a dynamic buffer object. More... | |
struct | ch_objects_factory |
Type of the factory main object. More... | |
Functions | |
void | _factory_init (void) |
Initializes the objects factory. More... | |
registered_object_t * | chFactoryRegisterObject (const char *name, void *objp) |
Registers a generic object. More... | |
registered_object_t * | chFactoryFindObject (const char *name) |
Retrieves a registered object. More... | |
registered_object_t * | chFactoryFindObjectByPointer (void *objp) |
Retrieves a registered object by pointer. More... | |
void | chFactoryReleaseObject (registered_object_t *rop) |
Releases a registered object. More... | |
dyn_buffer_t * | chFactoryCreateBuffer (const char *name, size_t size) |
Creates a generic dynamic buffer object. More... | |
dyn_buffer_t * | chFactoryFindBuffer (const char *name) |
Retrieves a dynamic buffer object. More... | |
void | chFactoryReleaseBuffer (dyn_buffer_t *dbp) |
Releases a dynamic buffer object. More... | |
dyn_semaphore_t * | chFactoryCreateSemaphore (const char *name, cnt_t n) |
Creates a dynamic semaphore object. More... | |
dyn_semaphore_t * | chFactoryFindSemaphore (const char *name) |
Retrieves a dynamic semaphore object. More... | |
void | chFactoryReleaseSemaphore (dyn_semaphore_t *dsp) |
Releases a dynamic semaphore object. More... | |
dyn_mailbox_t * | chFactoryCreateMailbox (const char *name, size_t n) |
Creates a dynamic mailbox object. More... | |
dyn_mailbox_t * | chFactoryFindMailbox (const char *name) |
Retrieves a dynamic mailbox object. More... | |
void | chFactoryReleaseMailbox (dyn_mailbox_t *dmp) |
Releases a dynamic mailbox object. More... | |
dyn_objects_fifo_t * | chFactoryCreateObjectsFIFO (const char *name, size_t objsize, size_t objn, unsigned objalign) |
Creates a dynamic "objects FIFO" object. More... | |
dyn_objects_fifo_t * | chFactoryFindObjectsFIFO (const char *name) |
Retrieves a dynamic "objects FIFO" object. More... | |
void | chFactoryReleaseObjectsFIFO (dyn_objects_fifo_t *dofp) |
Releases a dynamic "objects FIFO" object. More... | |
static dyn_element_t * | chFactoryDuplicateReference (dyn_element_t *dep) |
Duplicates an object reference. More... | |
static void * | chFactoryGetObject (registered_object_t *rop) |
Returns the pointer to the inner registered object. More... | |
static size_t | chFactoryGetBufferSize (dyn_buffer_t *dbp) |
Returns the size of a generic dynamic buffer object. More... | |
static uint8_t * | chFactoryGetBuffer (dyn_buffer_t *dbp) |
Returns the pointer to the inner buffer. More... | |
static semaphore_t * | chFactoryGetSemaphore (dyn_semaphore_t *dsp) |
Returns the pointer to the inner semaphore. More... | |
static mailbox_t * | chFactoryGetMailbox (dyn_mailbox_t *dmp) |
Returns the pointer to the inner mailbox. More... | |
static objects_fifo_t * | chFactoryGetObjectsFIFO (dyn_objects_fifo_t *dofp) |
Returns the pointer to the inner objects FIFO. More... | |
Variables | |
objects_factory_t | ch_factory |
Factory object static instance. More... | |
#define CH_CFG_FACTORY_MAX_NAMES_LENGTH 8 |
Maximum length for object names.
If the specified length is zero then the name is stored by pointer but this could have unintended side effects.
Definition at line 51 of file chfactory.h.
#define CH_CFG_FACTORY_OBJECTS_REGISTRY TRUE |
Enables the registry of generic objects.
Definition at line 58 of file chfactory.h.
#define CH_CFG_FACTORY_GENERIC_BUFFERS TRUE |
Enables factory for generic buffers.
Definition at line 65 of file chfactory.h.
#define CH_CFG_FACTORY_SEMAPHORES TRUE |
Enables factory for semaphores.
Definition at line 96 of file chfactory.h.
#define CH_CFG_FACTORY_SEMAPHORES FALSE |
Enables factory for semaphores.
Definition at line 96 of file chfactory.h.
#define CH_CFG_FACTORY_MAILBOXES TRUE |
Enables factory for mailboxes.
Definition at line 103 of file chfactory.h.
#define CH_CFG_FACTORY_MAILBOXES FALSE |
Enables factory for mailboxes.
Definition at line 103 of file chfactory.h.
#define CH_CFG_FACTORY_OBJ_FIFOS TRUE |
Enables factory for objects FIFOs.
Definition at line 110 of file chfactory.h.
#define CH_CFG_FACTORY_OBJ_FIFOS FALSE |
Enables factory for objects FIFOs.
Definition at line 110 of file chfactory.h.
typedef struct ch_dyn_element dyn_element_t |
Type of a dynamic object list element.
typedef struct ch_dyn_list dyn_list_t |
Type of a dynamic object list.
typedef struct ch_registered_static_object registered_object_t |
Type of a registered object.
typedef struct ch_dyn_object dyn_buffer_t |
Type of a dynamic buffer object.
typedef struct ch_dyn_semaphore dyn_semaphore_t |
Type of a dynamic semaphore.
typedef struct ch_dyn_mailbox dyn_mailbox_t |
Type of a dynamic buffer object.
typedef struct ch_dyn_objects_fifo dyn_objects_fifo_t |
Type of a dynamic buffer object.
typedef struct ch_objects_factory objects_factory_t |
Type of the factory main object.
void _factory_init | ( | void | ) |
Initializes the objects factory.
Definition at line 245 of file chfactory.c.
References ch_objects_factory::buf_list, chCoreAllocAlignedI(), chMtxObjectInit(), chPoolObjectInit(), chSemObjectInit(), ch_objects_factory::fifo_list, ch_objects_factory::mbx_list, ch_objects_factory::mtx, ch_objects_factory::obj_list, ch_objects_factory::obj_pool, ch_objects_factory::sem_list, and ch_objects_factory::sem_pool.
Referenced by chSysInit().
registered_object_t * chFactoryRegisterObject | ( | const char * | name, |
void * | objp | ||
) |
Registers a generic object.
[in] | name | name to be assigned to the registered object |
[in] | objp | pointer to the object to be registered |
NULL | if the object to be registered cannot be allocated or a registered object with the same name exists. |
Definition at line 291 of file chfactory.c.
References ch_objects_factory::obj_list, ch_objects_factory::obj_pool, and ch_registered_static_object::objp.
registered_object_t * chFactoryFindObject | ( | const char * | name | ) |
Retrieves a registered object.
[in] | name | name of the registered object |
NULL | if a registered object with the specified name does not exist. |
Definition at line 323 of file chfactory.c.
References ch_objects_factory::obj_list.
registered_object_t * chFactoryFindObjectByPointer | ( | void * | objp | ) |
Retrieves a registered object by pointer.
[in] | objp | pointer to the object to be retrieved |
NULL | if a registered object with the specified pointer does not exist. |
Definition at line 348 of file chfactory.c.
References ch_registered_static_object::element, ch_dyn_element::next, ch_objects_factory::obj_list, ch_registered_static_object::objp, and ch_dyn_element::refs.
void chFactoryReleaseObject | ( | registered_object_t * | rop | ) |
Releases a registered object.
The reference counter of the registered object is decreased by one, if reaches zero then the registered object memory is freed.
[in] | rop | registered object reference |
Definition at line 381 of file chfactory.c.
References ch_registered_static_object::element, ch_objects_factory::obj_list, and ch_objects_factory::obj_pool.
dyn_buffer_t * chFactoryCreateBuffer | ( | const char * | name, |
size_t | size | ||
) |
Creates a generic dynamic buffer object.
[in] | name | name to be assigned to the new dynamic buffer object |
[in] | size | payload size of the dynamic buffer object to be created |
NULL | if the dynamic buffer object cannot be allocated or a dynamic buffer object with the same name exists. |
Definition at line 409 of file chfactory.c.
References ch_objects_factory::buf_list, and ch_dyn_object::buffer.
dyn_buffer_t * chFactoryFindBuffer | ( | const char * | name | ) |
Retrieves a dynamic buffer object.
[in] | name | name of the dynamic buffer object |
NULL | if a dynamic buffer object with the specified name does not exist. |
Definition at line 440 of file chfactory.c.
References ch_objects_factory::buf_list.
void chFactoryReleaseBuffer | ( | dyn_buffer_t * | dbp | ) |
Releases a dynamic buffer object.
The reference counter of the dynamic buffer object is decreased by one, if reaches zero then the dynamic buffer object memory is freed.
[in] | dbp | dynamic buffer object reference |
Definition at line 462 of file chfactory.c.
References ch_objects_factory::buf_list, and ch_dyn_object::element.
dyn_semaphore_t * chFactoryCreateSemaphore | ( | const char * | name, |
cnt_t | n | ||
) |
Creates a dynamic semaphore object.
[in] | name | name to be assigned to the new dynamic semaphore object |
[in] | n | dynamic semaphore object counter initialization value |
NULL | if the dynamic semaphore object cannot be allocated or a dynamic semaphore with the same name exists. |
Definition at line 488 of file chfactory.c.
References chSemObjectInit(), ch_dyn_semaphore::sem, ch_objects_factory::sem_list, and ch_objects_factory::sem_pool.
dyn_semaphore_t * chFactoryFindSemaphore | ( | const char * | name | ) |
Retrieves a dynamic semaphore object.
[in] | name | name of the dynamic semaphore object |
NULL | if a dynamic semaphore object with the specified name does not exist. |
Definition at line 519 of file chfactory.c.
References ch_objects_factory::sem_list.
void chFactoryReleaseSemaphore | ( | dyn_semaphore_t * | dsp | ) |
Releases a dynamic semaphore object.
The reference counter of the dynamic semaphore object is decreased by one, if reaches zero then the dynamic semaphore object memory is freed.
[in] | dsp | dynamic semaphore object reference |
Definition at line 541 of file chfactory.c.
References ch_dyn_semaphore::element, ch_objects_factory::sem_list, and ch_objects_factory::sem_pool.
dyn_mailbox_t * chFactoryCreateMailbox | ( | const char * | name, |
size_t | n | ||
) |
Creates a dynamic mailbox object.
[in] | name | name to be assigned to the new dynamic mailbox object |
[in] | n | mailbox buffer size as number of messages |
NULL | if the dynamic mailbox object cannot be allocated or a dynamic mailbox object with the same name exists. |
Definition at line 569 of file chfactory.c.
References chMBObjectInit(), ch_dyn_mailbox::mbx, ch_objects_factory::mbx_list, and ch_dyn_mailbox::msgbuf.
dyn_mailbox_t * chFactoryFindMailbox | ( | const char * | name | ) |
Retrieves a dynamic mailbox object.
[in] | name | name of the dynamic mailbox object |
NULL | if a dynamic mailbox object with the specified name does not exist. |
Definition at line 601 of file chfactory.c.
References ch_objects_factory::mbx_list.
void chFactoryReleaseMailbox | ( | dyn_mailbox_t * | dmp | ) |
Releases a dynamic mailbox object.
The reference counter of the dynamic mailbox object is decreased by one, if reaches zero then the dynamic mailbox object memory is freed.
[in] | dmp | dynamic mailbox object reference |
Definition at line 623 of file chfactory.c.
References ch_dyn_mailbox::element, and ch_objects_factory::mbx_list.
dyn_objects_fifo_t * chFactoryCreateObjectsFIFO | ( | const char * | name, |
size_t | objsize, | ||
size_t | objn, | ||
unsigned | objalign | ||
) |
Creates a dynamic "objects FIFO" object.
[in] | name | name to be assigned to the new dynamic "objects FIFO" object |
[in] | objsize | size of objects |
[in] | objn | number of objects available |
[in] | objalign | required objects alignment |
NULL | if the dynamic "objects FIFO" object cannot be allocated or a dynamic "objects FIFO" object with the same name exists. |
Definition at line 653 of file chfactory.c.
References chFifoObjectInit(), ch_dyn_objects_fifo::fifo, ch_objects_factory::fifo_list, and ch_dyn_objects_fifo::msgbuf.
dyn_objects_fifo_t * chFactoryFindObjectsFIFO | ( | const char * | name | ) |
Retrieves a dynamic "objects FIFO" object.
[in] | name | name of the dynamic "objects FIFO" object |
NULL | if a dynamic "objects FIFO" object with the specified name does not exist. |
Definition at line 691 of file chfactory.c.
References ch_objects_factory::fifo_list.
void chFactoryReleaseObjectsFIFO | ( | dyn_objects_fifo_t * | dofp | ) |
Releases a dynamic "objects FIFO" object.
The reference counter of the dynamic "objects FIFO" object is decreased by one, if reaches zero then the dynamic "objects FIFO" object memory is freed.
[in] | dofp | dynamic "objects FIFO" object reference |
Definition at line 713 of file chfactory.c.
References ch_dyn_objects_fifo::element, and ch_objects_factory::fifo_list.
|
inlinestatic |
Duplicates an object reference.
[in] | dep | pointer to the element field of the object |
Definition at line 387 of file chfactory.h.
References ch_dyn_element::refs.
|
inlinestatic |
Returns the pointer to the inner registered object.
[in] | rop | registered object reference |
Definition at line 403 of file chfactory.h.
References ch_registered_static_object::objp.
|
inlinestatic |
Returns the size of a generic dynamic buffer object.
[in] | dbp | dynamic buffer object reference |
Definition at line 418 of file chfactory.h.
References chHeapGetSize().
|
inlinestatic |
Returns the pointer to the inner buffer.
[in] | dbp | dynamic buffer object reference |
Definition at line 431 of file chfactory.h.
References ch_dyn_object::buffer.
|
inlinestatic |
Returns the pointer to the inner semaphore.
[in] | dsp | dynamic semaphore object reference |
Definition at line 446 of file chfactory.h.
References ch_dyn_semaphore::sem.
|
inlinestatic |
Returns the pointer to the inner mailbox.
[in] | dmp | dynamic mailbox object reference |
Definition at line 461 of file chfactory.h.
References ch_dyn_mailbox::mbx.
|
inlinestatic |
Returns the pointer to the inner objects FIFO.
[in] | dofp | dynamic "objects FIFO" object reference |
Definition at line 476 of file chfactory.h.
References ch_dyn_objects_fifo::fifo.
objects_factory_t ch_factory |
Factory object static instance.
Definition at line 72 of file chfactory.c.