InstantIO::OutSlot< T > Class Template Reference

Allows to send data values to other software components. More...

#include <InstantIO/OutSlot.h>

Inheritance diagram for InstantIO::OutSlot< T >:
InstantIO::BasicOutSlot InstantIO::Slot

List of all members.

Public Member Functions

 OutSlot ()
 Creates a new OutSlot object.
 OutSlot (const std::string &description)
 Creates a new OutSlot object.
 OutSlot (const Data< T > &defaultValue)
 Creates a new OutSlot object.
 OutSlot (const std::string &description, const Data< T > &defaultValue)
 Creates a new OutSlot object.
virtual ~OutSlot ()
 Destroys the OutSlot object.
virtual const char * getTypeName () const
 Returns a human-readable string that describes the type that can be sent to this OutSlot.
virtual const std::type_info & getTypeID () const
 Returns the RTTI type info object that describes the type that can be sent to this OutSlot.
bool isConnected () const
 Returns if the OutSlot is connected to an InSlot.
const Data< T > getValue () const
 Returns the last data value written into this OutSlot.
virtual void push (const Data< T > &value)
 Writes a new data value into the OutSlot.
virtual void connect (BasicInSlot *inSlot)
 Connects an InSlot to this OutSlot.
virtual void disconnect (BasicInSlot *inSlot)
 Disconnects an InSlot from this OutSlot.

Friends

class InSlot< T >
 Needs access to the addInSlot and removeInSlot methods.

Detailed Description

template<class T>
class InstantIO::OutSlot< T >

Allows to send data values to other software components.

For each kind of information you want to send to other software components, you have to create an OutSlot. OutSlots have a label and an optional description that you have to specify when creating an OutSlot object.

The type specifies the C++ type of the data you want to send on the OutSlot.

The description simply is a human-readable string that can be used to describe more in detail the purpose of the OutSlot. It is not used by the InstantIO system, but is displayed in user interfaces used to configure the InstantIO system.

Before you can actually send data values via the OutSlot, you have to connect it to one or more InSlots. You can do this manually by calling the connect method of either the OutSlot or the InSlots, but usually you add the OutSlot to a Namespace object. When you add an OutSlot to a Namespace, you have to specify a label. Namespaces automatically connect OutSlots and InSlots contained in the Namespace that fulfill the following constraints:

  1. They have the same C++ type,
  2. and they have the same label, or there is a route defined in the Namespace that maps the OutSlot label to the InSlot label.

An OutSlot can be added to as many Namespaces as necessary.

When you do not need to receive values from the OutSlot anymore, you simply disconnect it from the InSlots by calling the disconnect method or by removing it from all Namespaces.

The following code snippet demonstrates how to send button press events to other software components. These events are boolean values, so we create an OutSlot with the C++ type "bool". Then we add it to the root namespace (the Root singleton), give it the label "Button", and start sending values by using the push method:

 include <InstantIO/OutSlot.h>
 include <InstantIO/Root.h>
 ...
 InstantIO::OutSlot<bool> outSlot;
 InstantIO::Root::the().addOutSlot(outSlot);
 ...
 while (loop == true)
 {
   ...
   bool value = ...;
   outSlot.push(value);
   ...
 }
 ...
 InstantIO::Root::the().removeOutSlot(outSlot);
 ...
 

Sometimes it is important not only to send the data value, but also the timestamp when the data value has been created (by default, the timestamp of each data value is set to the current system time when it is pushed into the OutSlot). The push method actually does not take a data value as parameter, but a Data object. Data values are usually converted automatically into Data objects as demonstrated above, but you can use Data objects to set the timestamp. The timestamp is an unsigned long value that contains the number of milliseconds since midnight January 1., 1970 UTC. The following code snippet demonstrates how to use the push method with Data objects:

 include <InstantIO/Data.h>
 ...
 bool value = ...;
 unsigned long timeStamp = ...;
 Data data;
 data.setValue(value);
 data.setTimeStamp(timeStamp);
 outSlot.push(data);
 ...
 

See also:
InSlot
Namespace
Root
Data
Author:
Patrick Dähne

Constructor & Destructor Documentation

template<class T>
InstantIO::OutSlot< T >::OutSlot ( const std::string &  description  )  [inline, explicit]

Creates a new OutSlot object.

Parameters:
description The description of this OutSlot. This information is not used by the InstantIO system directly, instead it is displayed for information purposes in user interfaces used to configure the InstantIO system.
template<class T>
InstantIO::OutSlot< T >::OutSlot ( const Data< T > &  defaultValue  )  [inline, explicit]

Creates a new OutSlot object.

Parameters:
defaultValue The initial value of this OutSlot.
template<class T>
InstantIO::OutSlot< T >::OutSlot ( const std::string &  description,
const Data< T > &  defaultValue 
) [inline]

Creates a new OutSlot object.

Parameters:
description The description of this OutSlot. This information is not used by the InstantIO system directly, instead it is displayed for information purposes in user interfaces used to configure the InstantIO system.
defaultValue The initial value of this OutSlot.

Member Function Documentation

template<class T>
virtual const char* InstantIO::OutSlot< T >::getTypeName (  )  const [inline, virtual]

Returns a human-readable string that describes the type that can be sent to this OutSlot.

This information is not used by the InstantIO system directly, instead it is displayed for information purposes in user interfaces used to configure the InstantIO system.

Returns:
A string that describes the type that can be sent to this OutSlot.

Implements InstantIO::Slot.

template<class T>
virtual const std::type_info& InstantIO::OutSlot< T >::getTypeID (  )  const [inline, virtual]

Returns the RTTI type info object that describes the type that can be sent to this OutSlot.

Returns:
The RTTI type info object.

Implements InstantIO::Slot.

template<class T>
bool InstantIO::OutSlot< T >::isConnected (  )  const [inline]

Returns if the OutSlot is connected to an InSlot.

When an OutSlot is not connected to an InSlot, it is not necessary to write values into it. This information can be used to improve performance of applications.

Instead of using this method, you can also implement a descendant of the BasicOutSlot::Listener class and add an instance of this class to the OutSlot by using the BasicOutSlot::addListener method.

Returns:
true when the OutSlot is connected to an InSlot, false otherwise.
template<class T>
const Data<T> InstantIO::OutSlot< T >::getValue (  )  const [inline]

Returns the last data value written into this OutSlot.

By using this method, you can check if a new value you want to write into the OutSlot actually differs from the one written previously. In this case, in many cases you can skip writing the new value into the OutSlot. This allows to conserver resources (especially when sending data values via the network).

Returns:
The last data value written into the OutSlot.
template<class T>
virtual void InstantIO::OutSlot< T >::push ( const Data< T > &  value  )  [inline, virtual]

Writes a new data value into the OutSlot.

The data value is send to all InSlots the OutSlot is currently connected to.

Parameters:
value The new data value.
template<class T>
virtual void InstantIO::OutSlot< T >::connect ( BasicInSlot inSlot  )  [inline, virtual]

Connects an InSlot to this OutSlot.

Usually, InSlots and OutSlots are not connected manually. They are connected automatically by adding them to Namespaces. This method just exists for rare special circumstances where it might be helpful to connect slots manually.

It is only possible to connect InSlots to this OutSlot that have the same data type.

It is possible to add the same InSlot more than once to an OutSlot. Nevertheless, just one connection is created. For each call of the connect method, there has to be a corresponding call to the disconnect method. The slots do not get disconnected until the last call of the disconnect method.

Parameters:
inSlot The InSlot.
See also:
disconnect

Implements InstantIO::BasicOutSlot.

template<class T>
virtual void InstantIO::OutSlot< T >::disconnect ( BasicInSlot inSlot  )  [inline, virtual]

Disconnects an InSlot from this OutSlot.

Usually, InSlots and OutSlots are not disconnected manually. The are disconnected automatically by removing them from Namespaces. This method just exists for rare special circumstances where it might be helpful to disconnect slots manually.

It is possible to add the same InSlot more than once to an OutSlot. Nevertheless, just one connection is created. For each call of the connect method, there has to be a corresponding call of the disconnect method. The slots do not get disconnected until the last call of the disconnect method.

Parameters:
inSlot The InSlot.
See also:
connect connect

Implements InstantIO::BasicOutSlot.


The documentation for this class was generated from the following file:
Generated on Thu Jul 31 17:17:32 2014 by  doxygen 1.6.3