|
μHAL (v2.7.9)
Part of the IPbus software repository
|
Go to the documentation of this file.
38 #include <boost/shared_ptr.hpp>
39 #include <boost/thread/lock_guard.hpp>
53 #ifdef NO_PREEMPTIVE_DISPATCH
54 mNoPreemptiveDispatchBuffers(),
57 mTimeoutPeriod ( aTimeoutPeriod ),
66 #ifdef NO_PREEMPTIVE_DISPATCH
67 mNoPreemptiveDispatchBuffers(),
70 mTimeoutPeriod (
boost::posix_time::pos_infin ),
79 #ifdef NO_PREEMPTIVE_DISPATCH
80 mNoPreemptiveDispatchBuffers(),
82 mId ( aClientInterface.mId ),
83 mTimeoutPeriod ( aClientInterface.mTimeoutPeriod ),
84 mUri ( aClientInterface.mUri ),
85 mUriString( aClientInterface.mUriString )
93 mId = aClientInterface.
mId;
150 #ifdef NO_PREEMPTIVE_DISPATCH
151 log (
Info() ,
"mNoPreemptiveDispatchBuffers.size() = " ,
Integer ( mNoPreemptiveDispatchBuffers.size() ) );
153 for ( std::deque <
boost::shared_ptr< Buffers > >::iterator lIt = mNoPreemptiveDispatchBuffers.begin(); lIt != mNoPreemptiveDispatchBuffers.end(); ++lIt )
162 mNoPreemptiveDispatchBuffers.clear();
191 aBuffers->getSendBuffer() + aBuffers->sendCounter() ,
192 aBuffers->getReplyBuffer().begin() ,
193 aBuffers->getReplyBuffer().end() );
198 aBuffers->validate ();
287 log (
Debug() ,
"Checking buffer space" );
293 if ( ( aRequestedSendSize <= lSendBufferFreeSpace ) && ( aRequestedReplySize <= lReplyBufferFreeSpace ) )
295 aAvailableSendSize = aRequestedSendSize;
296 aAvailableReplySize = aRequestedReplySize;
300 if ( ( lSendBufferFreeSpace > 16 ) && ( lReplyBufferFreeSpace > 16 ) )
302 aAvailableSendSize = lSendBufferFreeSpace;
303 aAvailableReplySize = lReplyBufferFreeSpace;
307 #ifdef NO_PREEMPTIVE_DISPATCH
311 log (
Debug() ,
"Triggering automated dispatch" );
330 if ( ( aRequestedSendSize <= lSendBufferFreeSpace ) && ( aRequestedReplySize <= lReplyBufferFreeSpace ) )
332 aAvailableSendSize = aRequestedSendSize;
333 aAvailableReplySize = aRequestedReplySize;
337 aAvailableSendSize = lSendBufferFreeSpace;
338 aAvailableReplySize = lReplyBufferFreeSpace;
353 for ( uint32_t i=0; i!=10; ++i )
373 #ifdef NO_PREEMPTIVE_DISPATCH
374 mNoPreemptiveDispatchBuffers.clear();
394 return std::make_pair ( lReply , & ( * ( lReply.
mMembers ) ) );
401 return std::make_pair ( lReply , & ( * ( lReply.
mMembers ) ) );
408 return std::make_pair ( lReply , & ( * ( lReply.
mMembers ) ) );
424 uint32_t lBitShiftedSource ( aSource << lShiftSize );
426 if ( ( lBitShiftedSource >> lShiftSize ) != aSource )
428 exception::BitsSetWhichAreForbiddenByBitMask lExc;
429 log ( lExc ,
"Source data (" ,
Integer ( aSource ,
IntFmt<hex,fixed>() ) ,
") has bits which would be shifted outside the register " );
433 uint32_t lOverlap ( lBitShiftedSource & ~aMask );
437 exception::BitsSetWhichAreForbiddenByBitMask lExc;
439 " has the following bits set outside the bounds allowed by the bit-mask ( ",
Integer ( aSource ,
IntFmt<hex,fixed>() ) ,
") : " ,
502 if ( aTimeoutPeriod == 0 )
508 mTimeoutPeriod = boost::posix_time::milliseconds ( aTimeoutPeriod );
const std::string & id() const
Return the identifier of the target for this client.
ClientInterface()
Default Constructor.
ValHeader writeBlock(const uint32_t &aAddr, const std::vector< uint32_t > &aValues, const defs::BlockReadWriteMode &aMode=defs::INCREMENTAL)
Write a block of data to a block of registers or a block-write port.
virtual void predispatch(boost::shared_ptr< Buffers > aBuffers)
Finalize the buffer before it is transmitted.
void dispatch()
Method to dispatch all queued transactions, and wait until all corresponding responses have been rece...
boost::shared_ptr< Buffers > mCurrentBuffers
A pointer to a buffer-wrapper object.
virtual ValHeader implementWriteBlock(const uint32_t &aAddr, const std::vector< uint32_t > &aValues, const defs::BlockReadWriteMode &aMode=defs::INCREMENTAL)=0
Write a block of data to a block of registers or a block-write port.
virtual ValWord< uint32_t > implementRMWbits(const uint32_t &aAddr, const uint32_t &aANDterm, const uint32_t &aORterm)=0
Read the value of a register, apply the AND-term, apply the OR-term, set the register to this new val...
An abstract base class for defining the interface to the various IPbus clients as well as providing t...
virtual void dispatchExceptionHandler()
Function which is called when an exception is thrown.
void updateCurrentBuffers()
If the current buffer is null, allocate a buffer from the buffer pool for it If the buffer pool is em...
Empty struct which acts as a dummy variable for passing the formatting information around.
virtual void Flush()
Virtual function to dispatch all buffers and block until all replies are received.
An abstract base exception class, including an interface to throw as the derived type (for passing ex...
virtual void implementDispatch(boost::shared_ptr< Buffers > aBuffers)=0
Pure virtual function which actually performs the dispatch operation.
boost::shared_ptr< _ValWord_< T > > mMembers
A shared pointer to a ValWord struct, so that every copy of this ValWord points to the same underlyin...
virtual uint32_t getMaxSendSize()=0
Return the maximum size to be sent based on the buffer size in the target.
uint64_t getTimeoutPeriod()
A method to retrieve the timeout period currently being used.
virtual boost::shared_ptr< Buffers > checkBufferSpace(const uint32_t &aSendSize, const uint32_t &aReplySize, uint32_t &aAvailableSendSize, uint32_t &aAvailableReplySize)
Function which checks the available space in the currently filling buffer against requested send and ...
std::string mId
the identifier of the target for this client
BlockReadWriteMode
define whether transactions target a single register, a block of registers, a block-read/write port o...
void log(FatalLevel &aFatal, const T0 &aArg0)
Function to add a log entry at Fatal level.
ValWord< uint32_t > read(const uint32_t &aAddr)
Read a single, unmasked, unsigned word.
std::pair< ValHeader, _ValHeader_ * > CreateValHeader()
Helper function to create a ValHeader object.
std::string toString(const URI &aURI)
_Integer< T, IntFmt<> > Integer(const T &aT)
Forward declare a function which creates an instance of the ultra-lightweight wrapper from an integer...
virtual ~ClientInterface()
Destructor.
ValVector< uint32_t > readBlock(const uint32_t &aAddr, const uint32_t &aSize, const defs::BlockReadWriteMode &aMode=defs::INCREMENTAL)
Read a block of unsigned data from a block of registers or a block-read port.
boost::mutex mUserSideMutex
A MutEx lock used to make sure the access functions are thread safe.
virtual ValWord< uint32_t > implementRead(const uint32_t &aAddr, const uint32_t &aMask=defs::NOMASK)=0
Read a single, masked, unsigned word.
ValWord< uint32_t > rmw_bits(const uint32_t &aAddr, const uint32_t &aANDterm, const uint32_t &aORterm)
Read the value of a register, apply the AND-term, apply the OR-term, set the register to this new val...
ValWord< uint32_t > rmw_sum(const uint32_t &aAddr, const int32_t &aAddend)
Read the value of a register, add the addend, set the register to this new value and return a copy of...
virtual ValVector< uint32_t > implementReadBlock(const uint32_t &aAddr, const uint32_t &aSize, const defs::BlockReadWriteMode &aMode=defs::INCREMENTAL)=0
Read a block of unsigned data from a block of registers or a block-read port.
virtual uint32_t getPreambleSize()
Return the size of the preamble.
boost::posix_time::time_duration mTimeoutPeriod
Timeout period for transactions.
A class wrapping the send and recieve buffers that are to be filled and transported and the validated...
std::pair< ValVector< uint32_t >, _ValVector_< uint32_t > * > CreateValVector(const uint32_t &aSize)
Helper function to create a ValVector object.
URI mUri
a struct containing the full URI of the target for this client
void setTimeoutPeriod(const uint32_t &aTimeoutPeriod=0)
A method to modify the timeout period for any pending or future transactions.
const std::string & uri() const
Return the url of the target for this client.
const boost::posix_time::time_duration & getBoostTimeoutPeriod()
A method to retrieve the timeout period currently being used.
void returnBufferToPool(boost::shared_ptr< Buffers > &aBuffers)
Function to return a buffer to the buffer pool.
unsigned int TrailingRightBits(uint32_t aValue)
Helper function to calculate the number of zero-bits at the righthand end of a 32-bit number.
A Template helper struct wrapping a block of IPbus header, a register for storing a block of data and...
std::pair< ValWord< uint32_t >, _ValWord_< uint32_t > * > CreateValWord(const uint32_t &aValue, const uint32_t &aMask=defs::NOMASK)
Helper function to create a ValWord object.
virtual ClientInterface & operator=(const ClientInterface &aClientInterface)
Assignment operator.
A Template helper struct wrapping an IPbus header, a register for storing a single word of data,...
Struct to store a URI when parsed by boost spirit.
virtual ValHeader implementWrite(const uint32_t &aAddr, const uint32_t &aValue)=0
Write a single, unmasked word to a register.
boost::mutex mBufferMutex
A MutEx lock used to make sure the access to the buffers is thread safe.
virtual exception::exception * validate(boost::shared_ptr< Buffers > aBuffers)
Function which dispatch calls when the reply is received to check that the headers are as expected.
boost::shared_ptr< _ValVector_< T > > mMembers
A shared pointer to a ValVector struct, so that every copy of this ValVector points to the same under...
virtual void preamble(boost::shared_ptr< Buffers > aBuffers)
Add a preamble to an IPbus buffer.
virtual ValWord< uint32_t > implementRMWsum(const uint32_t &aAddr, const int32_t &aAddend)=0
Read the value of a register, add the addend, set the register to this new value and return a copy of...
virtual uint32_t getMaxReplySize()=0
Return the maximum size of reply packet based on the buffer size in the target.
std::deque< boost::shared_ptr< Buffers > > mBuffers
A memory pool of buffers which will be dispatched.
ValHeader write(const uint32_t &aAddr, const uint32_t &aValue)
Write a single, unmasked word to a register.