The ADTB Library N.Leclercq – J.Malik – INF/ICA. ADTB – What is this? C++ toolbox for TANGO...

17
The ADTB Library The ADTB Library N.Leclercq – J.Malik – N.Leclercq – J.Malik – INF/ICA INF/ICA

Transcript of The ADTB Library N.Leclercq – J.Malik – INF/ICA. ADTB – What is this? C++ toolbox for TANGO...

Page 1: The ADTB Library N.Leclercq – J.Malik – INF/ICA. ADTB – What is this? C++ toolbox for TANGO device impl. dependencies: Tango.lib & omnithread.lib dependencies:

The ADTB LibraryThe ADTB Library

N.Leclercq – J.Malik – INF/ICAN.Leclercq – J.Malik – INF/ICA

Page 2: The ADTB Library N.Leclercq – J.Malik – INF/ICA. ADTB – What is this? C++ toolbox for TANGO device impl. dependencies: Tango.lib & omnithread.lib dependencies:

ADTB – What is this?ADTB – What is this?

C++ toolbox for TANGO device impl.C++ toolbox for TANGO device impl. dependencies: Tango.lib & omnithread.libdependencies: Tango.lib & omnithread.lib but… should be independentbut… should be independent

Aggregation of software toolsAggregation of software tools recurrent needs >> ! reinvent the wheelrecurrent needs >> ! reinvent the wheel code factorization >> maintenancecode factorization >> maintenance impl. harmonization >> maintenanceimpl. harmonization >> maintenance

Page 3: The ADTB Library N.Leclercq – J.Malik – INF/ICA. ADTB – What is this? C++ toolbox for TANGO device impl. dependencies: Tango.lib & omnithread.lib dependencies:

ADTB – FeaturesADTB – Features

Threading supportThreading support La classe La classe adtb::DeviceTaskadtb::DeviceTask

a task = a thread + messageQa task = a thread + messageQ

consumes messages [passive approach]consumes messages [passive approach]

periodic activity and/or stimulated by “external” messagesperiodic activity and/or stimulated by “external” messages

interface…interface… go (size_t tmo_ms)go (size_t tmo_ms) [sync.] [!!! no auto start !!!] [sync.] [!!! no auto start !!!] post (Message * m)post (Message * m) [async.] [async.] wait_msg_handled (Message * m, size_t tmo_ms)wait_msg_handled (Message * m, size_t tmo_ms) [sync.] [sync.] abort (bool join, size_t tmo_ms)abort (bool join, size_t tmo_ms) [sync.] [!!! self delete !!!] [sync.] [!!! self delete !!!]

Page 4: The ADTB Library N.Leclercq – J.Malik – INF/ICA. ADTB – What is this? C++ toolbox for TANGO device impl. dependencies: Tango.lib & omnithread.lib dependencies:

ADTB – FeaturesADTB – Features

Threading supportThreading support The The adtb::Message adtb::Message classclass

inherits from inherits from adtb::SharedObjectadtb::SharedObject a message can be posted to several tasks a message can be posted to several tasks reference counter (release - not delete) reference counter (release - not delete)

message has a type [user defined]message has a type [user defined]

can carry any kind of datacan carry any kind of data user : user : msg->attach_data(any_data_type[& ou *])msg->attach_data(any_data_type[& ou *]) task : task : ExpectedDataType* d = msg->dettach_data();ExpectedDataType* d = msg->dettach_data();…; delete msg;…; delete msg;

hidden generic container + template methodhidden generic container + template method runtime error on data extraction [!!! programming error !!!]runtime error on data extraction [!!! programming error !!!]

dynamic_cast >> std::bad_castdynamic_cast >> std::bad_cast

Page 5: The ADTB Library N.Leclercq – J.Malik – INF/ICA. ADTB – What is this? C++ toolbox for TANGO device impl. dependencies: Tango.lib & omnithread.lib dependencies:

ADTB – FeatureADTB – Feature

Threading supportThreading support go back to go back to adtb::DeviceTaskadtb::DeviceTask

message handling : predefined messages message handling : predefined messages

class MyTask : public adtb::DeviceTask{protected: ... void handle_message (const adtb::Message& _msg) throw (Tango::DevFailed) { //- !!! you may be under critical section !!! switch ( _msg.type() ) { //- THREAD_INIT ---------------------- case adtb::THREAD_INIT: //- "initialization" code goes here break; //- THREAD_EXIT ---------------------- case adtb::THREAD_EXIT: //- "release" code goes here break;

Page 6: The ADTB Library N.Leclercq – J.Malik – INF/ICA. ADTB – What is this? C++ toolbox for TANGO device impl. dependencies: Tango.lib & omnithread.lib dependencies:

ADTB – FeatureADTB – Feature

Threading supportThreading support go back to go back to adtb::DeviceTaskadtb::DeviceTask

message handling : periodic & user defined messagesmessage handling : periodic & user defined messages

//- THREAD_PERIODIC ------------------ case adtb::THREAD_PERIODIC: //- task's periodic job break; //- USER_DEFINED_MSG ----------------- case kMY_DOUBLE_MSG: //- get msg data... double * double_value = 0; _msg.dettach_data(double_value); //- do somthing with double_value then... delete double_value; break; } // - switch } // - handle_message}; // class MyTask

Page 7: The ADTB Library N.Leclercq – J.Malik – INF/ICA. ADTB – What is this? C++ toolbox for TANGO device impl. dependencies: Tango.lib & omnithread.lib dependencies:

ADTB – FeatureADTB – Feature

Threading supportThreading support The The adtb::DeviceMutex adtb::DeviceMutex classclass

omni_mutex interface + …omni_mutex interface + …int try_lock (DeviceMutexStatus & status);int try_lock (DeviceMutexStatus & status);

return 0 : ok, locked (status = MTX_LOCKED)return 0 : ok, locked (status = MTX_LOCKED) return -1 : ko, could not be locked (status = MTX_BUSY or MTX_ERROR)return -1 : ko, could not be locked (status = MTX_BUSY or MTX_ERROR)

may be helpful to avoid deadlock may be helpful to avoid deadlock The The adtb::DummyMutex adtb::DummyMutex classclass

empty/do nothing impl. of the DeviceMutex interfaceempty/do nothing impl. of the DeviceMutex interfaceoptional ‘ThreadSafety’ [locking overhead]optional ‘ThreadSafety’ [locking overhead]

template <typename LOCK> class MyClass template <typename LOCK> class MyClass exemple : galil::HwIO [1 shared connection + 1 private]exemple : galil::HwIO [1 shared connection + 1 private]

The The adtb::DeviceMutexLock<LOCK> adtb::DeviceMutexLock<LOCK> classclassomni_mutex_lock interfaceomni_mutex_lock interfacedefault template arg. = DeviceMutexdefault template arg. = DeviceMutex

The The adtb::DeviceCondition adtb::DeviceCondition classclasssame as omni_condition but…same as omni_condition but…

maintains «signaled» state [alarm clock rings before sleeping syndrom]maintains «signaled» state [alarm clock rings before sleeping syndrom] required for DeviceTask impl. required for DeviceTask impl. may not be adapted to any situation >> an other class required?may not be adapted to any situation >> an other class required?

Page 8: The ADTB Library N.Leclercq – J.Malik – INF/ICA. ADTB – What is this? C++ toolbox for TANGO device impl. dependencies: Tango.lib & omnithread.lib dependencies:

ADTB – FeaturesADTB – Features

Bit fields support [adtb::BitsStream]Bit fields support [adtb::BitsStream] Application fields…Application fields…

management of composite data structures in which management of composite data structures in which the data is coded on 1 to 32 bits (*) the data is coded on 1 to 32 bits (*) mostly hardware I/Omostly hardware I/O

Principle…Principle…using the provided “user description”, the BitsStream using the provided “user description”, the BitsStream extracts each field, does some byte-swapping (if extracts each field, does some byte-swapping (if required) then stores the value into the “explicitly required) then stores the value into the “explicitly associated” C++ data typeassociated” C++ data type

Example…Example…

(*) could support >32 bits fields(*) could support >32 bits fields

Page 9: The ADTB Library N.Leclercq – J.Malik – INF/ICA. ADTB – What is this? C++ toolbox for TANGO device impl. dependencies: Tango.lib & omnithread.lib dependencies:

ADTB – FeaturesADTB – Features

adtb::BitsStream : struct descriptionadtb::BitsStream : struct description

BEGIN_BITS_RECORD(BR_MotorState)BEGIN_BITS_RECORD(BR_MotorState)MEMBER(moving,1, bool);MEMBER(moving,1, bool);IGNORE_MEMBER(reserved_1, 1, bool);IGNORE_MEMBER(reserved_1, 1, bool);MEMBER(forward_ls, 1, bool);MEMBER(forward_ls, 1, bool);MEMBER(backward_ls, 1, bool);MEMBER(backward_ls, 1, bool);IGNORE_MEMBER(reserved_2, 4, unsigned char);IGNORE_MEMBER(reserved_2, 4, unsigned char);MEMBER(error_code, 8, unsigned char);MEMBER(error_code, 8, unsigned char);

END_BITS_RECORD(BR_MotorState)END_BITS_RECORD(BR_MotorState)

Page 10: The ADTB Library N.Leclercq – J.Malik – INF/ICA. ADTB – What is this? C++ toolbox for TANGO device impl. dependencies: Tango.lib & omnithread.lib dependencies:

ADTB – FeaturesADTB – Features

adtb::BitsStream : data extractoradtb::BitsStream : data extractor discribes how to extract the datadiscribes how to extract the data

BEGIN_BITS_RECORD_EXTRACTOR(BR_MotorState)BEGIN_BITS_RECORD_EXTRACTOR(BR_MotorState)EXTRACT_MEMBER(moving);EXTRACT_MEMBER(moving);SKIP_BITS(1);SKIP_BITS(1);EXTRACT_MEMBER(forward_ls);EXTRACT_MEMBER(forward_ls);EXTRACT_MEMBER(backward_ls);EXTRACT_MEMBER(backward_ls);SKIP_BITS(4);SKIP_BITS(4);EXTRACT_MEMBER(error_code);EXTRACT_MEMBER(error_code);

END_BITS_RECORD_EXTRACTOR(BR_MotorState)END_BITS_RECORD_EXTRACTOR(BR_MotorState)

Page 11: The ADTB Library N.Leclercq – J.Malik – INF/ICA. ADTB – What is this? C++ toolbox for TANGO device impl. dependencies: Tango.lib & omnithread.lib dependencies:

ADTB – FeaturesADTB – Features

adtb::BitsStream : logging…adtb::BitsStream : logging… useful for debugging…useful for debugging…

BEGIN_BITS_RECORD_DUMP(BR_MotorState)BEGIN_BITS_RECORD_DUMP(BR_MotorState)DUMP_MEMBER(moving);DUMP_MEMBER(moving);DUMP_SKIP_BITS(1);DUMP_SKIP_BITS(1);DUMP_MEMBER(forward_ls);DUMP_MEMBER(forward_ls);DUMP_MEMBER(backward_ls);DUMP_MEMBER(backward_ls);DUMP_SKIP_BITS(4);DUMP_SKIP_BITS(4);DUMP_MEMBER(error_code);DUMP_MEMBER(error_code);

END_BITS_RECORD_DUMPEND_BITS_RECORD_DUMP (BR_MotorState)(BR_MotorState)

Page 12: The ADTB Library N.Leclercq – J.Malik – INF/ICA. ADTB – What is this? C++ toolbox for TANGO device impl. dependencies: Tango.lib & omnithread.lib dependencies:

ADTB – FeaturesADTB – Features

adtb::BitsStream :adtb::BitsStream : class class specialization…specialization… providing semantically powerful interfaceproviding semantically powerful interface note the note the ()() operator operator

class MotorState : public BR_MotorStateclass MotorState : public BR_MotorState{{public:public: inline bool any_limit_switch_detected ()inline bool any_limit_switch_detected () {{ return this->forward_lsreturn this->forward_ls()() || this->backward_ls || this->backward_ls()(); }}}}

Page 13: The ADTB Library N.Leclercq – J.Malik – INF/ICA. ADTB – What is this? C++ toolbox for TANGO device impl. dependencies: Tango.lib & omnithread.lib dependencies:

ADTB – FeaturesADTB – Features

Data buffers… (generic containers)Data buffers… (generic containers) adtb::DataBuffer adtb::DataBuffer

template: generic containertemplate: generic container adtb::SharedBufferadtb::SharedBuffer

: public Buffer<T>, private SharedObject: public Buffer<T>, private SharedObject

adtb::CircularBufferadtb::CircularBufferdata historic [ex : post mortem]data historic [ex : post mortem]const adtb::Buffer<T> & ordered_data (void) constconst adtb::Buffer<T> & ordered_data (void) const

Page 14: The ADTB Library N.Leclercq – J.Malik – INF/ICA. ADTB – What is this? C++ toolbox for TANGO device impl. dependencies: Tango.lib & omnithread.lib dependencies:

ADTB – FeaturesADTB – Features

Other classes…Other classes… adtb::ThreadSafeDeviceProxyadtb::ThreadSafeDeviceProxy

should be provided by the Tangoshould be provided by the Tango core lib! core lib! adtb::ThreadSafeDeviceProxyHelperadtb::ThreadSafeDeviceProxyHelper

thread safe version of DeviceProxyHelperthread safe version of DeviceProxyHelper adtb::XStringadtb::XString

bidirectional numeric to string conversionbidirectional numeric to string conversion adtb::PluginManager & related classesadtb::PluginManager & related classes

provided the basics for plugin supportprovided the basics for plugin support

ultimate hardware abstraction behind a Tango dev. Interfaceultimate hardware abstraction behind a Tango dev. Interface

ex.: SOLEIL image grabber ex.: SOLEIL image grabber

Page 15: The ADTB Library N.Leclercq – J.Malik – INF/ICA. ADTB – What is this? C++ toolbox for TANGO device impl. dependencies: Tango.lib & omnithread.lib dependencies:

ADTB – FeaturesADTB – Features

Other classes…Other classes… adtb::Work & Workers (in progress – 90% done)adtb::Work & Workers (in progress – 90% done)

data stream model impl.data stream model impl.

each node is a Worker having a Work to doeach node is a Worker having a Work to do

uses the adtb::DeviceTask from data propagation uses the adtb::DeviceTask from data propagation

Page 16: The ADTB Library N.Leclercq – J.Malik – INF/ICA. ADTB – What is this? C++ toolbox for TANGO device impl. dependencies: Tango.lib & omnithread.lib dependencies:

ADTB – FeaturesADTB – Features

Other small stuffs…Other small stuffs… Inline Inline

inline control: release but not for debug inline control: release but not for debug Developer logging Developer logging

DEBUG_TRACE DEBUG_TRACE

DEBUG_LOGDEBUG_LOG

generates logs in DEBUG mode onlygenerates logs in DEBUG mode only

Page 17: The ADTB Library N.Leclercq – J.Malik – INF/ICA. ADTB – What is this? C++ toolbox for TANGO device impl. dependencies: Tango.lib & omnithread.lib dependencies:

ADTB – Near FutureADTB – Near Future

Client socket class Client socket class platform abstraction platform abstraction

Criteria & FilterCriteria & Filter generic [composite] filters for data treatmentgeneric [composite] filters for data treatment