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

an activity to periodically read from Tango. Implements CuContinuousActivity More...

#include <cupollingactivity.h>

Inheritance diagram for CuPollingActivity:
Inheritance graph
[legend]

Public Types

enum  Type { CuPollingActivityType = CuActivity::UserAType + 3 }
 defines the Type of the activity, returned by getType More...
 

Public Member Functions

 CuPollingActivity (const TSource &tsrc, CuDeviceFactory_I *df, const CuData &options, const CuData &tag, int dataupdpo, int interval)
 the class constructor that sets up a Tango polling activity More...
 
 ~CuPollingActivity ()
 the class destructor More...
 
void setArgins (const CuVariant &argins)
 set the input arguments if the poller is used to "read" Tango commands and they require argins More...
 
size_t actionsCount () const
 
size_t srcCount () const
 
void setSlowDownRate (const std::map< int, int > &sr_millis)
 set a custom slow down rate to decrease polling period after consecutive read failures. More...
 
const std::map< int, int > & slowDownRate () const
 returns the currently employed slow down rate policy in case of read errors More...
 
void decreasePolling ()
 
int successfulExecCnt () const
 CuPollingActivity::successfulExecCnt count the number of succesful executions. More...
 
int consecutiveErrCnt () const
 CuPollingActivity::consecutiveErrCnt count the consecutive errors during execution. More...
 
bool matches (const CuData &token) const
 returns true if the passed token's device activity and period values matche this activity token's device and activity and period values. More...
 
void event (CuActivityEvent *e)
 Receive events from the main thread to the CuActivity thread. More...
 
int getType () const
 returns the type of the polling activity More...
 
int repeat () const
 returns the polling period, in milliseconds More...
 

Protected Member Functions

void init ()
 the implementation of the CuActivity::init hook More...
 
void execute ()
 the implementation of the CuActivity::execute hook More...
 
void onExit ()
 the implementation of the CuActivity::onExit hook More...
 

Detailed Description

an activity to periodically read from Tango. Implements CuContinuousActivity

Implementing CuActivity, the work is done in the background by the three methods

They are called from a separate thread. In cumbia-tango, threads are grouped by device.

Apart from the three execution hooks listed above, some other methods have been written to comply with the CuActivityInterface:

Note
CuPollingActivity must stay in execution (must not exit) until CuTReader is stopped (CuTReader::stop). For this reason, CuAUnregisterAfterExec is set to false. When the Tango device is not defined into the database (in CuPollingActivity::execute the Tango::DeviceProxy is NULL) the repeat time is set to a negative number. This suspends the continuous activity without exiting. It will be asked to exit from CuTReader::stop through Cumbia::unregisterActivity.

CuADeleteOnExit is left to true in order to let the activity be deleted by CuThread after onExit.

This combination of the flags guarantees the availability of the CuPollingActivity when CuTReader::stop is called (activity will be either executing the polling loop or suspended) and lets CuTReader not worry about the activity deletion.

See also
CuTReader
CuTReader::stop

Member Enumeration Documentation

◆ Type

defines the Type of the activity, returned by getType

Enumerator
CuPollingActivityType 

Constructor & Destructor Documentation

◆ CuPollingActivity()

CuPollingActivity::CuPollingActivity ( const TSource tsrc,
CuDeviceFactory_I df,
const CuData &  options,
const CuData &  tag,
int  dataupdpo,
int  interval 
)

the class constructor that sets up a Tango polling activity

Parameters
tokena CuData that will describe this activity
dfa pointer to a CuDeviceFactoryService that is used by init and onExit to create/obtain and later get rid of a Tango device, respectively
arginsinput arguments that can optionally be passed to Tango commands as argins
notes
  • the default polling period is 1000 milliseconds
  • if the "period" key is set on the token, then it is converted to int and it will be used to set up the polling period
  • CuADeleteOnExit is active.
  • CuAUnregisterAfterExec is disabled because if the Tango device is not defined into the database the poller is not started and the activity is suspended (repeat will return -1).

◆ ~CuPollingActivity()

CuPollingActivity::~CuPollingActivity ( )

the class destructor

deletes the internal data

Member Function Documentation

◆ actionsCount()

size_t CuPollingActivity::actionsCount ( ) const

◆ consecutiveErrCnt()

int CuPollingActivity::consecutiveErrCnt ( ) const

CuPollingActivity::consecutiveErrCnt count the consecutive errors during execution.

Returns
the number of consecutive errors encountered within the execute method.
Note
Upon each successful execution, the counter is reset to 0
See also
successfulExecCnt

◆ decreasePolling()

void CuPollingActivity::decreasePolling ( )

Referenced by execute().

◆ event()

void CuPollingActivity::event ( CuActivityEvent *  e)

Receive events from the main thread to the CuActivity thread.

Parameters
ethe event. Do not delete e after use. Cumbia will delete it after this method invocation.
See also
CuActivity::event
Note
the CuActivityEvent is forwarded to CuPeriodicActivity::event

References CuAddPollActionEvent::AddPollAction, CuArgsChangeEvent::ArgsChangeEvent, and CuRemovePollActionEvent::RemovePollAction.

◆ execute()

void CuPollingActivity::execute ( )
protected

the implementation of the CuActivity::execute hook

This is repeatedly called in the CuActivity's thread of execution, according to the period chosen for the reader.

If the reader's source is a command, the first time execute is run CuTangoWorld::get_command_info is called, so that the data type and format of the command output argument is detected.

Either command_inout (through CuTangoWorld::cmd_inout) or read_attribute (CuTangoWorld::read_att) are then invoked. They interpret the result and place it in a CuData that is finally delivered to the main thread by means of publishResult.

note
A CuPollingActivity can be started after a CuEventActivity failure to subscribe to the Tango event system. Moreover, polling is the only possible option to read commands.
Error handling
If an operation fails, the next executions are delayed: the next two attempts take place after 5 seconds and the following ones at intervals of 10 seconds until a successful read.
contents of the CuData delivered by publishResult ("key": value)
  • "is_command": bool: true if the source is a command, false if it is an attribute (CuVariant::toBool)
  • "err": bool: true if an error occurred, false otherwise
  • "mode": string: the read mode: "E" or "P" ("P" in this case)
  • "period": integer: the polling period, in milliseconds (CuVariant::toInt)
  • "msg": string: a message describing a read error upon failure. Not set in case of success (since: 1.3.0)
  • refer to md_lib_cudata_for_tango for a complete description of the CuData key/value pairs that result from attribute or command read operations.
See also CuActivity::execute and CuEventActivity

References CuTangoWorld::cmd_inout(), decreasePolling(), CmdData::din, CuTangoWorld::get_command_info(), TSource::getArgs(), CmdData::getCmdInfoRef(), CuTangoWorld::getLastMessage(), TSource::getName(), TSource::getPoint(), CmdData::is_empty, CuTangoWorld::read_atts(), and CuTangoWorld::toDeviceData().

◆ getType()

int CuPollingActivity::getType ( ) const

returns the type of the polling activity

Returns
the CuPollingActivityType value defined in the Type enum

References CuPollingActivityType.

◆ init()

void CuPollingActivity::init ( )
protected

the implementation of the CuActivity::init hook

This is called in the CuActivity's thread of execution.

Notes
See also CuActivity::init, execute and onExit

References CuTThread::CuTThreadType.

◆ matches()

bool CuPollingActivity::matches ( const CuData &  token) const

returns true if the passed token's device activity and period values matche this activity token's device and activity and period values.

Parameters
tokena CuData containg key/value pairs of another activity's token
Returns
true if the input token's "period" device and activity values match this token's "period" device and activity values

Two CuPollingActivity match if they refer to the same device and have the same period.

◆ onExit()

void CuPollingActivity::onExit ( )
protected

the implementation of the CuActivity::onExit hook

This is called in the CuActivity's thread of execution.

  • client reference counter is decreased on the TDevice (TDevice::removeRef)
  • the result of the operation is published to the main thread through publishResult

See also CuActivity::onExit

◆ repeat()

int CuPollingActivity::repeat ( ) const

returns the polling period, in milliseconds

Returns
the polling period, in milliseconds

◆ setArgins()

void CuPollingActivity::setArgins ( const CuVariant &  argins)

set the input arguments if the poller is used to "read" Tango commands and they require argins

Parameters
arginsinput arguments to supply to Tango commands, if the reader's source is a command

◆ setSlowDownRate()

void CuPollingActivity::setSlowDownRate ( const std::map< int, int > &  sr_millis)

set a custom slow down rate to decrease polling period after consecutive read failures.

The default slow down rate policy decreases the read timer to:

  • three times the current period after one error
  • five times the current period after two consecutive errors
  • ten times the current period after four consecutive errors

The default polling period is restored after a successful reading

Parameters
amap defining how to decrease the polling period after read failures
Example
A map defined like this:
std::map<int, int> sd_map;
sd_map[1] = 1.5;
sd_map[2] = 3;
sd_map[4] = 8;
activity->setSlowDownRate(sd_map);

behaves as described in the list above if we deal with a default polling period of one second.

See also
slowDownRate

◆ slowDownRate()

const std::map< int, int > & CuPollingActivity::slowDownRate ( ) const

returns the currently employed slow down rate policy in case of read errors

Refer to setSlowDownRate for further details

◆ srcCount()

size_t CuPollingActivity::srcCount ( ) const

◆ successfulExecCnt()

int CuPollingActivity::successfulExecCnt ( ) const

CuPollingActivity::successfulExecCnt count the number of succesful executions.

Returns
the number of successful executions
See also
consecutiveErrCnt

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