-
Notifications
You must be signed in to change notification settings - Fork 4
DataManager
The DataManager manages data channel initialization and modules trying to access them.
Modules don't access the DataManager directly, instead call the
corresponding methods defined in lms::Module
.
For accessing data channels the following methods are available:
template<typename T>
ReadDataChannel<T> readChannel(const std::string &name);
template<typename T>
WriteDataChannel<T> writeChannel(const std::string &name);
- Both access methods return a data channel wrapper type with overloaded
operator *
andoperator ->
for easy transitioning from the old system when usualT*
were returned. -
ReadDataChannel
allows only const methods and read-only access on all attributes. - The requested type can be a supertype of the actual object lying in inside the data channel. The internal object will be casted accordingly.
- Data channel classes should have a default constructor and should be non-abstract if they are not used as a supertype.
- If the data channel's type is not known at compile-time,
lms::Any
can be used for the template parameterT
. - The access methods are usually called in
initialize()
but can be used incycle()
as well.
Channel mapping allows for better reusing of existing modules. Instead of
changing the module's source code and recompiling it, channels can be renamed
to another channel in the config files. This can be done with
<channelMapping>
inside the <module>
tag:
<module>
<name>image_loader</name>
<channelMapping from="IMAGE" to="GREY_IMAGE" />
</module>
If the module requests the data channel IMAGE
it will get GREY_IMAGE
instead. This mapping is transparent. That means the module's source can stay
as-is and the module cannot find out if a request was redirected.
Serialization of data channels requires two steps:
- Access channel with type
lms::Any
. - Serialize or deserialize the channel in to a stream.
// Serialization
ReadDataChannel<lms::Any> ch = readChannel<lms::Any>("CHANNEL");
ch.serialize(outFile);
// Deserialization
WriteDataChannel<lms::Any> ch = writeChannel<lms::Any>("CHANNEL");
ch.deserialize(inFile);
- Only data channels implementing the
lms::Serializable
interface can be serialized.