170 likes | 250 Views
The ADTB Library. N.Leclercq – J.Malik – INF/ICA. ADTB – What is this?. C++ toolbox for TANGO device impl. dependencies: Tango.lib & omnithread.lib but… should be independent Aggregation of software tools recurrent needs >> ! reinvent the wheel code factorization >> maintenance
E N D
The ADTB Library N.Leclercq – J.Malik – INF/ICA
ADTB – What is this? • C++ toolbox for TANGO device impl. • dependencies: Tango.lib & omnithread.lib • but… should be independent • Aggregation of software tools • recurrent needs >> ! reinvent the wheel • code factorization >> maintenance • impl. harmonization >> maintenance
ADTB – Features • Threading support • La classe adtb::DeviceTask • a task = a thread + messageQ • consumes messages [passive approach] • periodic activity and/or stimulated by “external” messages • interface… • go (size_t tmo_ms) [sync.] [!!! no auto start !!!] • post (Message * m) [async.] • wait_msg_handled (Message * m, size_t tmo_ms) [sync.] • abort (bool join, size_t tmo_ms) [sync.] [!!! self delete !!!]
ADTB – Features • Threading support • The adtb::Message class • inherits from adtb::SharedObject • a message can be posted to several tasks • reference counter (release - not delete) • message has a type [user defined] • can carry any kind of data • user : msg->attach_data(any_data_type[& ou *]) • task : ExpectedDataType* d = msg->dettach_data();…; delete msg; • hidden generic container + template method • runtime error on data extraction [!!! programming error !!!] • dynamic_cast >> std::bad_cast
ADTB – Feature • Threading support • go back to adtb::DeviceTask • 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;
ADTB – Feature • Threading support • go back to adtb::DeviceTask • message 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
ADTB – Feature • Threading support • The adtb::DeviceMutex class • omni_mutex interface + … • int try_lock (DeviceMutexStatus & status); • return 0 : ok, locked (status = MTX_LOCKED) • return -1 : ko, could not be locked (status = MTX_BUSY or MTX_ERROR) • may be helpful to avoid deadlock • The adtb::DummyMutex class • empty/do nothing impl. of the DeviceMutex interface • optional ‘ThreadSafety’ [locking overhead] • template <typename LOCK> class MyClass • exemple : galil::HwIO [1 shared connection + 1 private] • The adtb::DeviceMutexLock<LOCK> class • omni_mutex_lock interface • default template arg. = DeviceMutex • The adtb::DeviceCondition class • same as omni_condition but… • maintains «signaled» state [alarm clock rings before sleeping syndrom] • required for DeviceTask impl. • may not be adapted to any situation >> an other class required?
ADTB – Features • Bit fields support [adtb::BitsStream] • Application fields… • management of composite data structures in which the data is coded on 1 to 32 bits (*) • mostly hardware I/O • Principle… • using the provided “user description”, the BitsStream extracts each field, does some byte-swapping (if required) then stores the value into the “explicitly associated” C++ data type • Example… (*) could support >32 bits fields
ADTB – Features • adtb::BitsStream : struct description BEGIN_BITS_RECORD(BR_MotorState) MEMBER(moving,1, bool); IGNORE_MEMBER(reserved_1, 1, bool); MEMBER(forward_ls, 1, bool); MEMBER(backward_ls, 1, bool); IGNORE_MEMBER(reserved_2, 4, unsigned char); MEMBER(error_code, 8, unsigned char); END_BITS_RECORD(BR_MotorState)
ADTB – Features • adtb::BitsStream : data extractor • discribes how to extract the data • BEGIN_BITS_RECORD_EXTRACTOR(BR_MotorState) • EXTRACT_MEMBER(moving); • SKIP_BITS(1); • EXTRACT_MEMBER(forward_ls); • EXTRACT_MEMBER(backward_ls); • SKIP_BITS(4); • EXTRACT_MEMBER(error_code); • END_BITS_RECORD_EXTRACTOR(BR_MotorState)
ADTB – Features • adtb::BitsStream : logging… • useful for debugging… BEGIN_BITS_RECORD_DUMP(BR_MotorState) DUMP_MEMBER(moving); DUMP_SKIP_BITS(1); DUMP_MEMBER(forward_ls); DUMP_MEMBER(backward_ls); DUMP_SKIP_BITS(4); DUMP_MEMBER(error_code); END_BITS_RECORD_DUMP(BR_MotorState)
ADTB – Features • adtb::BitsStream :class specialization… • providing semantically powerful interface • note the () operator class MotorState : public BR_MotorState { public: inline bool any_limit_switch_detected () { return this->forward_ls() || this->backward_ls(); } }
ADTB – Features • Data buffers… (generic containers) • adtb::DataBuffer • template: generic container • adtb::SharedBuffer • : public Buffer<T>, private SharedObject • adtb::CircularBuffer • data historic [ex : post mortem] • const adtb::Buffer<T> & ordered_data (void) const
ADTB – Features • Other classes… • adtb::ThreadSafeDeviceProxy • should be provided by the Tango core lib! • adtb::ThreadSafeDeviceProxyHelper • thread safe version of DeviceProxyHelper • adtb::XString • bidirectional numeric to string conversion • adtb::PluginManager & related classes • provided the basics for plugin support • ultimate hardware abstraction behind a Tango dev. Interface • ex.: SOLEIL image grabber
ADTB – Features • Other classes… • adtb::Work & Workers (in progress – 90% done) • data stream model impl. • each node is a Worker having a Work to do • uses the adtb::DeviceTask from data propagation
ADTB – Features • Other small stuffs… • Inline • inline control: release but not for debug • Developer logging • DEBUG_TRACE • DEBUG_LOG • generates logs in DEBUG mode only
ADTB – Near Future • Client socket class • platform abstraction • Criteria & Filter • generic [composite] filters for data treatment