XORDE
v1.0
eXtensible Operational Robotic Development Environment
|
The base for the ONB component. More...
#include <ComponentBase.h>
Inherits QObject.
Signals | |
void | objectChanged (QString name) |
[DEPRECATED] More... | |
Public Member Functions | |
ComponentBase (QObject *parent=nullptr) | |
Creates component and binds service objects. | |
ComponentBase (QString name, unsigned long classId, QString description=QString(), QObject *parent=nullptr) | |
Construct the component with given name, classID and description. | |
virtual | ~ComponentBase () |
Deletes all its objects, including service objects. | |
unsigned short | id () const |
Get componentID of the component. More... | |
unsigned long | timestamp () const |
Get current timestamp. More... | |
QJsonObject | getJsonConfig () const |
wut? whatta hell I see?? it is work for the core!! | |
Protected Member Functions | |
void | setIcon (QImage icon) |
Set an icon to the component. More... | |
void | setIcon (QString filename) |
Set an icon to the component from file. More... | |
template<class T > | |
ONBObject< T > & | createInput (QString name, T &var) |
Create an input of the component. More... | |
template<class T > | |
ONBObject< T > & | createOutput (QString name, T &var) |
Create an ouput of the component. More... | |
template<class T > | |
ONBObject< T > & | createSetting (QString name, T &var) |
Create a setting of the component. More... | |
const ObjectInfo * | object (QString name) const |
Get the object by name. More... | |
template<class T > | |
bool | rebindObject (QString name, T &var) |
Rebind the existing object to another variable. More... | |
bool | renameObject (QString oldName, QString newName) |
Rename existing object. More... | |
bool | deleteObject (QString name) |
Delete existing object. More... | |
void | sendObject (QString name) |
Send the object to the core immediately. More... | |
void | touchOutput (QString name, bool notifyAnyway=false) |
Make the object ready to send. More... | |
virtual void | onCreate () |
Component creation event. More... | |
virtual void | onDestroy () |
Component deletion event. More... | |
virtual void | objectRequestEvent (QString name) |
Event of object request. More... | |
virtual void | objectReceiveEvent (QString name) |
Event of object receive. More... | |
virtual void | objectChangeEvent (QString name) |
Event of object change. More... | |
void | log (QString message) |
Send the arbitrary message to the core's log output. | |
Protected Attributes | |
QString | componentName |
The name of the component. Used to name the type, must be unique. | |
unsigned long | classID = 0 |
ClassID of the component. Class identifier, must be unique. There is classification table (must be somewhere). | |
QString | description |
Human-readable description for the help. | |
unsigned long | serialNumber = 0 |
Component's serial number. This field commonly used in devices, contains unique number associated with a certain device. | |
unsigned char & | version |
Major version of the component. | |
unsigned char & | versionMinor |
Minor version of the component. | |
QString | releaseInfo |
This field can be filled with arbitrary information about component release (e.g. build date and time, release number etc.). | |
QString | hardwareInfo |
This field commonly used in devices. Can contain CPU description or something else about hardware. | |
unsigned long | burnCount = 0 |
Historical thing from devices. Indicates how many times the device burned out. ]:-> | |
The base for the ONB component.
To create the component you should derive from this class. Declare the variables to be bound as members of your class. The component description is located in the constructor. There you must complete protected fields with necessary values. The required fields are componentName and classID. Then bind the variables by means of createInput(), createOutput() or createSetting(), set the meta-values with desired info, see ONBObject. Variables must be allocated if they are pointers or items of a container.
Your component should reimplement the virtual methods onCreate(), onDestroy() to initialize and terminate respectively the component logic (e.g. run/stop timers, threads).
Object flow is controlled by following methods: to issue an object use sendObject(), touchOutput(); when an object or object request is received, the virtual methods are called: objectReceiveEvent(), objectChangeEvent(), objectRequestEvent().
The component is able to change its objects at run-time. Just use createInput(), createOutput(), createSetting() during the run-time. Also you can use renameObject() and deleteObject() to modify the component appearance. To modify the object itself use rebindObject(), this method allows you to bind the existing object to another variable. Changing the meta-values associated with the object is not supported yet.
Here is an example of ONB component implementing Gain function.
Gain.h
Gain.cpp
|
inlineprotected |
Create an input of the component.
Creates a volatile writable object bound to a given variable. Also meta-values can be associated with the object.
name | Name of the object. |
var | Reference to variable to bind. |
|
inlineprotected |
Create an ouput of the component.
Creates a volatile readable object bound to a given variable. Also meta-values can be associated with the object.
name | Name of the object. |
var | Reference to variable to bind. |
|
inlineprotected |
Create a setting of the component.
Creates a non-volatile read-write object bound to a given variable. Also meta-values can be associated with the object.
name | Name of the object. |
var | Reference to variable to bind. |
|
protected |
Delete existing object.
Use this method to remove the object from component at run-time.
name | The name of existing object. |
|
inline |
Get componentID of the component.
After connection to the core, the componentID is assigned to the component.
|
protected |
Get the object by name.
If the object with given name is created, the method return a constant pointer to the object base. You can cast it manually to const ONBObject<T>* where T must match the type of bound variable.
name | The object name. |
|
signal |
[DEPRECATED]
|
inlineprotectedvirtual |
Event of object change.
This method is similar to objectReceiveEvent() but it is called when the value of the variable was changed only.
name | The name of the requested object. |
|
inlineprotectedvirtual |
Event of object receive.
It is called when the core sends the object with the given name after its value is written to the bound variable. So you can use the variable with its actual value just inside this method.
name | The name of the requested object. |
|
inlineprotectedvirtual |
Event of object request.
It is called when the core requests the object with the given name or the sampling interval has come. The event is called before sending object to the core. You should complete the bound variable with actual value when the event is arrived.
name | The name of the requested object. |
|
inlineprotectedvirtual |
Component creation event.
It is called when component is created by core. Reimplement this method to initialize your component logic, e.g. run timers, threads, allocate buffers etc.
|
inlineprotectedvirtual |
Component deletion event.
It is called when component is deleted by core. Reimplement this method to terminate your component logic, e.g. stop timers, threads, deallocate buffers etc.
|
inlineprotected |
Rebind the existing object to another variable.
Use this method if the bound variable is moved or reallocated. This method also can be used for changing variable type at run-time.
name | The name of the object. |
var | Reference to variable to bind. |
|
protected |
Rename existing object.
Use this method to rename the existing object at run-time. The new name must not match the existing objects' names.
oldName | The name of existing object. |
newName | The desired name. |
|
protected |
Send the object to the core immediately.
If the object with given name does not exist the method does nothing.
name | The name of the object. |
|
protected |
Set an icon to the component.
Component icon is used in the UI.
icon | The image containing icon. |
|
protected |
Set an icon to the component from file.
This is an overloaded method.
filename | Name of icon file. Supported formats matches ones in Qt's QImage. |
unsigned long ComponentBase::timestamp | ( | ) | const |
Get current timestamp.
The timestamp is measured in milliseconds since system start. Synchronization procedure between components is planned but not implemented yet.
|
protected |
Make the object ready to send.
The object will be sent as soon as its next sampling interval has come. The object is sent immediately if the sampling interval is set to special value of zero. If the object with given name does not exist the method does nothing.
name | The name of the object. |
notifyAnyway | Maybe it's better to use sendObject()? |