A class to hold the queue of component descriptors registered by translation units. This queue is necessary to ensure that component creation continues to work after plugins are unloaded. The typical scenario this aims to solve is: More...
#include <Factory.hh>
Public Member Functions | |
void GZ_SIM_HIDDEN | Add (RegistrationObjectId _regObjId, ComponentDescriptorBase *_comp) |
Add a component descriptor to the queue. More... | |
GZ_SIM_HIDDEN std::unique_ptr< BaseComponent > | Create () const |
Create a component using the latest available component descriptor. This simply forward to ComponentDescriptorBase::Create. More... | |
GZ_SIM_HIDDEN std::unique_ptr< BaseComponent > | Create (const components::BaseComponent *_data) const |
Create a component using the latest available component descriptor. This simply forward to ComponentDescriptorBase::Create. More... | |
bool GZ_SIM_HIDDEN | Empty () |
Check if the queue is empty. More... | |
void GZ_SIM_HIDDEN | Remove (RegistrationObjectId _regObjId) |
Remove a component descriptor from the queue. This also deletes memory allocated for the component descriptor by the static component registration object. More... | |
Detailed Description
A class to hold the queue of component descriptors registered by translation units. This queue is necessary to ensure that component creation continues to work after plugins are unloaded. The typical scenario this aims to solve is:
- Plugin P1 registers component descripter for component C1.
- Plugin P1 gets unloaded.
- Plugin P2 registers a component descriptor for component C1 and tries to create an instance of C1. When P1 gets unloaded, the destructor of the static component registration object calls Factory::Unregister which removes the component descriptor from the queue. Without this step, P2 would attempt to use the component descriptor created by P1 in step 3 and likely segfault because the memory associated with that descriptor has been deleted when P1 was unloaded.
Member Function Documentation
◆ Add()
|
inline |
Add a component descriptor to the queue.
- Parameters
-
[in] _regObjId An ID that identifies the registration object. This is generally derived from the this
pointer of the static component registration object created when calling GZ_SIM_REGISTER_COMPONENT.[in] _comp The component descriptor
◆ Create() [1/2]
|
inline |
Create a component using the latest available component descriptor. This simply forward to ComponentDescriptorBase::Create.
- See also
- ComponentDescriptorBase::Create
◆ Create() [2/2]
|
inline |
Create a component using the latest available component descriptor. This simply forward to ComponentDescriptorBase::Create.
- See also
- ComponentDescriptorBase::Create
◆ Empty()
|
inline |
Check if the queue is empty.
◆ Remove()
|
inline |
Remove a component descriptor from the queue. This also deletes memory allocated for the component descriptor by the static component registration object.
- Parameters
-
[in] _regObjId An ID that identifies the registration object. This is generally derived from the this
pointer of the static component registration object created when calling GZ_SIM_REGISTER_COMPONENT.
References std::find_if(), and std::prev().
The documentation for this class was generated from the following file: