cumbia-tango 1.x
C++ multi threaded library based on cumbia and the Tango control system
Public Types | Public Member Functions | List of all members
CuTReader Class Reference

Low level class to read tango attributes and commands with output arguments. More...

#include <cutreader.h>

Inheritance diagram for CuTReader:
Inheritance graph
[legend]

Public Types

enum  RefreshMode {
  PolledRefresh = 0x01 , ChangeEventRefresh =0x02 , ArchiveEventRefresh =0x04 , PeriodicEventRefresh =0x08 ,
  Manual =0x10
}
 The reader refresh mode. More...
 
- Public Types inherited from CuTangoActionI
enum  Type {
  ActionUnknown = -1 , Reader = 0 , Writer , ReaderConfig ,
  WriterConfig , TaDb
}
 list of types of actions More...
 

Public Member Functions

 CuTReader (const TSource &src, CumbiaTango *ct, const CuData &op=CuData(), const CuData &tag=CuData())
 
 ~CuTReader ()
 
void onProgress (int step, int total, const CuData &data)
 progress notification callback More...
 
void onResult (const CuData &data)
 receives on the main thread the result of a task executed in background. More...
 
void onResult (const std::vector< CuData > &datalist)
 
CuData getToken () const
 returns the CuData storing the token that identifies this action More...
 
TSource getSource () const
 
CuTangoActionI::Type getType () const
 returns the type of CuTangoActionI implemented More...
 
void sendData (const CuData &data)
 Send data with parameters to configure the reader. More...
 
void getData (CuData &inout) const
 Get parameters from the reader. More...
 
void setRefreshMode (RefreshMode rm, int period=-1)
 set or change the reader's refresh mode More...
 
std::string refreshModeStr () const
 
RefreshMode refreshMode () const
 
bool isEventRefresh (RefreshMode rm) const
 returns true if the parameter is an event driven RefreshMode, false otherwise. More...
 
int period () const
 
void setPeriod (int millis)
 
void setOptions (const CuData &options)
 CuTReader::setOptions sets the options on the reader. More...
 
void setTag (const CuData &tag)
 
void start ()
 the method where activities are created and registered More...
 
void stop ()
 the method where activities are unregistered from Cumbia More...
 
void addDataListener (CuDataListener *l)
 insert a CuDataListener to the list of listeners of data updates More...
 
void removeDataListener (CuDataListener *l)
 remove a CuDataListener from the list of listeners of data updates More...
 
size_t dataListenersCount ()
 return the number of registered data listeners More...
 
- Public Member Functions inherited from CuTangoActionI
virtual ~CuTangoActionI ()
 virtual destructor, to make compilers happy More...
 
virtual TSource getSource () const =0
 return a TSource object that stores information about the Tango source More...
 
virtual Type getType () const =0
 returns the type of CuTangoActionI implemented More...
 
virtual void addDataListener (CuDataListener *l)=0
 insert a CuDataListener to the list of listeners of data updates More...
 
virtual void removeDataListener (CuDataListener *l)=0
 remove a CuDataListener from the list of listeners of data updates More...
 
virtual size_t dataListenersCount ()=0
 return the number of registered data listeners More...
 
virtual void start ()=0
 the method where activities are created and registered More...
 
virtual void stop ()=0
 the method where activities are unregistered from Cumbia More...
 
virtual void sendData (const CuData &data)=0
 subclasses will implement the necessary code to set data on themselves or to the activities More...
 
virtual void getData (CuData &d_inout) const =0
 subclasses will implement the necessary code to analyze the request stored in the input argument and fill it in with output data More...
 

Detailed Description

Low level class to read tango attributes and commands with output arguments.

This class implements the CuTangoActionI interface, which in turn implements CuThreadListener.

Programmers of graphical interfaces should employ cumbia-tango-controls CuTControlsReader higher level class to create and communicate with CuTReader.

Function
Instantiates and registers (i.e. starts) either a CuEventActivity or a CuPollingActivity, according to the desired RefreshMode. If the CuEventActivity fails subscribing to the Tango event system, it is replaced by CuPollingActivity (in CuTReader::onResult). In that case, no error event is delivered to CuDataListeners.
Note
CuTReader holds a pointer to the current activity (CuTReaderPrivate: current_activity). Activity and CuTReader's life are independent from each other: if the CuActivity::CuADeleteOnExit flag is active (as in CuPollingActivity), the activity is deleted by CuThread.
Important
As a consequence of the note above, activities must not exit before CuTReader::stop is called. The proper way to stop the activity associated to the reader is through CuTReader::stop.

Member Enumeration Documentation

◆ RefreshMode

The reader refresh mode.

Each refresh mode reflects the way a tango attribute can be read. Commands are always polled with a given period (default: 1000ms). The preferred read mode for attributes is by events (ChangeEventRefresh). If they are not available, the second choice mode is PolledRefresh.

Manual mode starts (or switches to) a polling activity that is immediately paused. A specific argument must be specified to sendData to trigger a manual reading.

Enumerator
PolledRefresh 
ChangeEventRefresh 
ArchiveEventRefresh 
PeriodicEventRefresh 
Manual 

Constructor & Destructor Documentation

◆ CuTReader()

CuTReader::CuTReader ( const TSource src,
CumbiaTango ct,
const CuData &  op = CuData(),
const CuData &  tag = CuData() 
)

References setOptions().

◆ ~CuTReader()

CuTReader::~CuTReader ( )

Member Function Documentation

◆ addDataListener()

void CuTReader::addDataListener ( CuDataListener *  l)
virtual

insert a CuDataListener to the list of listeners of data updates

Parameters
la CuDataListener that receives notifications when data is ready, through CuDataListener::onUpdate

Implements CuTangoActionI.

◆ dataListenersCount()

size_t CuTReader::dataListenersCount ( )
virtual

return the number of registered data listeners

Returns
the number of data listeners currently installed

Implements CuTangoActionI.

◆ getData()

void CuTReader::getData ( CuData &  ino) const
virtual

Get parameters from the reader.

Parameters
d_inouta reference to a CuData bundle containing the parameter names as keys. getData will associate the values to the keys. Unrecognized keys are ignored.
Valid keys
See also
sendData

Implements CuTangoActionI.

References refreshModeStr().

◆ getSource()

TSource CuTReader::getSource ( ) const
virtual

returns the tango source (TSource)

Returns
a TSource object that describes the Tango source

Implements CuTangoActionI.

◆ getToken()

CuData CuTReader::getToken ( ) const

returns the CuData storing the token that identifies this action

Returns
a CuData with the following key/value pairs
  • "source" --> the name of the source (string)
  • "type" --> a constant string: "reader"

Referenced by sendData().

◆ getType()

CuTangoActionI::Type CuTReader::getType ( ) const
virtual

returns the type of CuTangoActionI implemented

Returns
one of the values from the Type enum

Implements CuTangoActionI.

References CuTangoActionI::Reader.

◆ isEventRefresh()

bool CuTReader::isEventRefresh ( CuTReader::RefreshMode  rm) const

returns true if the parameter is an event driven RefreshMode, false otherwise.

Parameters
rma value picked from CuTReader::RefreshMode enumeration
Returns
true if rm is ChangeEventRefresh, PeriodicEventRefresh or ArchiveEventRefresh, false otherwise

References ArchiveEventRefresh, ChangeEventRefresh, and PeriodicEventRefresh.

Referenced by sendData(), and setRefreshMode().

◆ onProgress()

void CuTReader::onProgress ( int  step,
int  total,
const CuData &  data 
)

progress notification callback

Parameters
stepthe completed steps in the background
totalthe total number of steps
dataCuData with data from the background activity

The current implementation does nothing

◆ onResult() [1/2]

void CuTReader::onResult ( const CuData &  data)

receives on the main thread the result of a task executed in background.

See md_lib_cudata_for_tango

If the error flag is set by the CuEventActivity because subscribe_event failed, the poller is started and the error is not notified to the listener(s)

◆ onResult() [2/2]

void CuTReader::onResult ( const std::vector< CuData > &  datalist)

◆ period()

int CuTReader::period ( ) const

Referenced by sendData(), and setRefreshMode().

◆ refreshMode()

CuTReader::RefreshMode CuTReader::refreshMode ( ) const

◆ refreshModeStr()

string CuTReader::refreshModeStr ( ) const

◆ removeDataListener()

void CuTReader::removeDataListener ( CuDataListener *  l)
virtual

remove a CuDataListener from the list of listeners of data updates

Parameters
la CuDataListener that will be removed from the list of listeners

Implements CuTangoActionI.

References stop().

◆ sendData()

void CuTReader::sendData ( const CuData &  data)
virtual

Send data with parameters to configure the reader.

Parameters
dataa CuData bundle with the settings to apply to the reader.
Valid keys
  • "period": integer. Change the polling period. Does not imply a change in refresh mode
  • "refresh_mode". A CuTReader::RefreshMode value to change the current refresh mode.
  • "manual" Equivalent to refresh_mode set to CuTReader::Manual, but more "engine unaware", recommended
  • "read" [any value, empty included]: ask an immediate reading
  • "args" [std::vector<std::string>]: change the arguments of an ongoing reading (applies to commands with argins)
Note
period, manual and refresh_mode update internal options.
See also
getData

Implements CuTangoActionI.

References CuPollingService::CuPollingServiceType, CuPollingService::getPoller(), getToken(), isEventRefresh(), Manual, CuPoller::period(), period(), PolledRefresh, and setRefreshMode().

◆ setOptions()

void CuTReader::setOptions ( const CuData &  options)

CuTReader::setOptions sets the options on the reader.

Parameters
optionsCuData key/value bundle
Options
\list
  • manual [bool]: manual mode: the caller will not receive updates
  • refresh_mode [int, one of CuTReader::RefreshMode] set the refresh mode to mode
  • period set the period that will be used to refresh the source if the mode is polled
Note
If the current mode is not CuTReader::PolledRefresh, setting the period is not enough to change the refresh mode. On the other hand, setting a period will save the value shall the refresh mode change to polling
See also
sendData

References Manual, PolledRefresh, setPeriod(), and setRefreshMode().

Referenced by CuTReader().

◆ setPeriod()

void CuTReader::setPeriod ( int  millis)

Referenced by setOptions().

◆ setRefreshMode()

void CuTReader::setRefreshMode ( CuTReader::RefreshMode  rm,
int  period = -1 
)

set or change the reader's refresh mode

If the reading activity hasn't been started yet, the mode is saved for later. If an activity is already running and the requested mode is different, the current activity is unregistered and a new one is started.

Parameters
rma value chosen from CuTReader::RefreshMode.

References CuPollingService::actionRegistered(), CuPollingService::CuPollingServiceType, isEventRefresh(), Manual, period(), and PolledRefresh.

Referenced by sendData(), and setOptions().

◆ setTag()

void CuTReader::setTag ( const CuData &  tag)

◆ start()

void CuTReader::start ( )
virtual

the method where activities are created and registered

This is the place where activities are created and registered to Cumbia through the method Cumbia::registerActivity.

Examples
See also Cumbia::registerActivity

Implements CuTangoActionI.

References ChangeEventRefresh.

◆ stop()

void CuTReader::stop ( )
virtual

the method where activities are unregistered from Cumbia

This is the place where activities are unregistered from Cumbia by the Cumbia::unregisterActivity method

Examples
See also Cumbia::unregisterActivity

Implements CuTangoActionI.

Referenced by removeDataListener().


The documentation for this class was generated from the following files: