InstantIO::InSlot< T > Class Template Reference

Allows to receive data values from other software components. More...

#include <InstantIO/InSlot.h>

Inheritance diagram for InstantIO::InSlot< T >:
InstantIO::BasicInSlot InstantIO::Slot InstantIO::BufferedInSlot< T >

List of all members.

Public Member Functions

 InSlot (const std::string &description=std::string())
 Creates a new InSlot object.
virtual ~InSlot ()
 Destroys the InSlot object.
virtual const char * getTypeName () const
 Returns a human-readable string that describes the type that can be received by this InSlot.
virtual const std::type_info & getTypeID () const
 Returns the RTTI type info object that describes the type that can be received by this InSlot.
bool isConnected () const
 Returns if the InSlot is connected to an OutSlot.
virtual bool empty () const
 Returns if data is available on the InSlot.
virtual const Data< T > top ()
 Returns the current data value without removing it from the InSlot.
virtual const Data< T > pop ()
 Removes the current data value from the InSlot and returns it.
virtual void push (const Data< T > &data)
 Writes a new data value into the InSlot.
virtual void connect (BasicOutSlot *outSlot)
 Connects an OutSlot to this InSlot.
virtual void disconnect (BasicOutSlot *outSlot)
 Disconnects an OutSlot from this InSlot.

Friends

class OutSlot< T >
 Needs access to the addOutSlot and removeOutSlot methods.

Detailed Description

template<class T>
class InstantIO::InSlot< T >

Allows to receive data values from other software components.

For each kind of information you want to receive from other software components, you have to create an InSlot. InSlots have a type and an optional description that you have to specify when creating an InSlot object.

The type specifies the C++ type of the data you want to receive on the InSlot.

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

Before you can actually receive data values from the InSlot, you have to connect it to one or more OutSlots. You can do this manually by calling the connect method of either the InSlot or the OutSlots, but usually you add the InSlot to a Namespace object. When you add an InSlot to a Namespace, you have to specify a label. Namespaces automatically connect InSlots and OutSlots 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 InSlot can be added to as many Namespaces as necessary.

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

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

 include <InstantIO/InSlot.h>
 include <InstantIO/Root.h>
 ...
 InstantIO::InSlot<bool> inSlot;
 InstantIO::Root::the().addInSlot("Button", &inSlot);
 ...
 while (loop == true)
 {
   ...
   bool value = inSlot.pop();
   ...
 }
 ...
 InstantIO::Root::the().removeInSlot("Button", &inSlot);
 ...
 

Sometimes it is important not only to receive the data value, but also the timestamp when the data value has been created. The pop method actually does not return the data value directly, but a Data object. This Data object usually gets automatically converted to the data value as demonstrated above, but you can use this Data object to receive 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 Data object:

 include <InstantIO/Data.h>
 ...
 InstantIO::Data<bool> data = inSlot.pop();
 bool value = data.getValue();
 unsigned long timeStamp = data.getTimeStamp();
 ...
 

Please keep in mind that the InSlot does not buffer data values. When a new data value is received before the current data value has been read by the application, the current data value gets overwritten by the new value. Under many circumstances, this behaviour is ok, but when you need to receive all data values, you have to use a BufferedInSlot object.

See also:
OutSlot
Namespace
Root
BufferedInSlot
Data
Author:
Patrick Dähne

Constructor & Destructor Documentation

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

Creates a new InSlot object.

Parameters:
description The description of this InSlot. 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.

Member Function Documentation

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

Returns a human-readable string that describes the type that can be received by this InSlot.

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 received by this InSlot.

Implements InstantIO::Slot.

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

Returns the RTTI type info object that describes the type that can be received by this InSlot.

Returns:
The RTTI type info object.

Implements InstantIO::Slot.

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

Returns if the InSlot is connected to an OutSlot.

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

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

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

Returns if data is available on the InSlot.

All method that receive data values (top, pop) block when no data is available until data is received from an OutSlot. By using this method, you can prevent this blocking by checking if data is actually available.

Returns:
false when data is available, true otherwise.

Implements InstantIO::BasicInSlot.

Reimplemented in InstantIO::BufferedInSlot< T >.

template<class T>
virtual const Data<T> InstantIO::InSlot< T >::top (  )  [inline, virtual]

Returns the current data value without removing it from the InSlot.

To remove the data value from the InSlot, you can call the pop method.

Returns:
The current data value.
Exceptions:
InterruptedException when the interrupt method has been called
See also:
pop

Reimplemented in InstantIO::BufferedInSlot< T >.

template<class T>
virtual const Data<T> InstantIO::InSlot< T >::pop (  )  [inline, virtual]

Removes the current data value from the InSlot and returns it.

This method blocks when no data is available until data is received from an OutSlot. By using the empty method you can check if data is available before calling this method.

To get the data value without removing it from the InSlot, use the top method.

Returns:
The current data value.
Exceptions:
InterruptedException when the interrupt method has been called
See also:
empty
top

Reimplemented in InstantIO::BufferedInSlot< T >.

template<class T>
virtual void InstantIO::InSlot< T >::push ( const Data< T > &  data  )  [inline, virtual]

Writes a new data value into the InSlot.

Usually, you do not write data values directly into an InSlot. InSlots receive data values from OutSlots they are connected to. This method is available for rare special circumstances where it might be helpful to write data values manually into the InSlot.

Parameters:
data A Data object that contains a new data value and the time when it has been created.

Reimplemented in InstantIO::BufferedInSlot< T >.

template<class T>
virtual void InstantIO::InSlot< T >::connect ( BasicOutSlot outSlot  )  [inline, virtual]

Connects an OutSlot to this InSlot.

Usually, OutSlots and InSlots 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 OutSlots and InSlots that have the same C++ data type.

It is possible to add the same OutSlot more than once to an InSlot. 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:
outSlot The OutSlot.
See also:
disconnect

Implements InstantIO::BasicInSlot.

template<class T>
virtual void InstantIO::InSlot< T >::disconnect ( BasicOutSlot outSlot  )  [inline, virtual]

Disconnects an OutSlot from this InSlot.

Usually, OutSlots and InSlots 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 OutSlot more than once to an InSlot. 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:
outSlot The OutSlot.
See also:
connect

Implements InstantIO::BasicInSlot.


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