A component is an object with a life-cycle, requiring services and providing ones, and associated to properties. The code of a component is reduced to its functional purpose: its life-cycle, dependencies, etc. are handled by iPOPO. In iPOPO, a component is an instance of component factory, i.e. a Python class manipulated with the iPOPO decorators.
Due to the use of Python properties, all component factories must be
new-style classes. It is the case of all Python 3 classes, but Python 2.x
classes must explicitly inherit from the
The component life cycle is handled by an instance manager created by the iPOPO service. This instance manager will inject control methods, run-time dependencies, and will register the component services. All changes will be notified to the component using the callback methods it decorated.
|INSTANTIATED||The component has been instantiated. Its constructor has been called and the control methods have been injected|
|VALIDATED||All required dependencies have been injected. All services provided by the component will be registered right after this method returned|
|KILLED||The component has been invalidated and won’t be usable again|
|ERRONEOUS||The component raised an error during its validation. It is not destroyed and a validation can be retried manually|
iPOPO components are handled through the iPOPO core service, which can itself
be accessed through the Pelix API or the utility context manager
The core service provides the
Here are the most commonly used methods from the iPOPO core service to handle components and factories:
A word on Python 3.7 Data classes¶
- All fields of the Data Class must have a default value.
This will let the
@dataclassdecorator generate an
__init__method without explicit arguments, which is a requirement for iPOPO.
- If the
init=Falseargument is given to
@dataclass, it is necessary to implement your own
__init__, defining all fields, otherwise generated methods like
Good to know¶
- Injected fields (
@Requires, …) will lose the default value given in the class definition, in favor to the ones given to the iPOPO decorators. This is due to the redefinition of the fields by those decorators. Other fields are not touched at all.
@dataclassdecorator can be used before or after the iPOPO decorators