38 #include <boost/shared_ptr.hpp> 39 #include <boost/thread/lock_guard.hpp> 44 #include "uhal/log/log.hpp" 53 #ifdef NO_PREEMPTIVE_DISPATCH
54 mNoPreemptiveDispatchBuffers(),
58 mTimeoutPeriod ( aTimeoutPeriod ),
68 #ifdef NO_PREEMPTIVE_DISPATCH
69 mNoPreemptiveDispatchBuffers(),
83 #ifdef NO_PREEMPTIVE_DISPATCH
84 mNoPreemptiveDispatchBuffers(),
87 mId ( aClientInterface.
mId ),
98 mId = aClientInterface.
mId;
144 std::stringstream lReturn;
166 uhal::NameValuePairVectorType::const_iterator lIt =
mUri.
mArguments.begin();
170 lReturn << lIt->first <<
"=" << lIt->second;
181 return lReturn.str();
192 #ifdef NO_PREEMPTIVE_DISPATCH 193 log (
Info() ,
"mNoPreemptiveDispatchBuffers.size() = " ,
Integer ( mNoPreemptiveDispatchBuffers.size() ) );
195 for ( std::deque <
boost::shared_ptr< Buffers > >::iterator lIt = mNoPreemptiveDispatchBuffers.begin(); lIt != mNoPreemptiveDispatchBuffers.end(); ++lIt )
204 mNoPreemptiveDispatchBuffers.clear();
239 aBuffers->getSendBuffer() + aBuffers->sendCounter() ,
240 aBuffers->getReplyBuffer().begin() ,
241 aBuffers->getReplyBuffer().end() );
246 aBuffers->validate ();
337 log (
Debug() ,
"Checking buffer space" );
356 if ( ( aRequestedSendSize <= lSendBufferFreeSpace ) && ( aRequestedReplySize <= lReplyBufferFreeSpace ) )
358 aAvailableSendSize = aRequestedSendSize;
359 aAvailableReplySize = aRequestedReplySize;
363 if ( ( lSendBufferFreeSpace > 16 ) && ( lReplyBufferFreeSpace > 16 ) )
365 aAvailableSendSize = lSendBufferFreeSpace;
366 aAvailableReplySize = lReplyBufferFreeSpace;
370 #ifdef NO_PREEMPTIVE_DISPATCH 378 log (
Debug() ,
"Triggering automated dispatch" );
410 if ( ( aRequestedSendSize <= lSendBufferFreeSpace ) && ( aRequestedReplySize <= lReplyBufferFreeSpace ) )
412 aAvailableSendSize = aRequestedSendSize;
413 aAvailableReplySize = aRequestedReplySize;
417 aAvailableSendSize = lSendBufferFreeSpace;
418 aAvailableReplySize = lReplyBufferFreeSpace;
433 for ( uint32_t i=0; i!=10; ++i )
465 #ifdef NO_PREEMPTIVE_DISPATCH 474 mNoPreemptiveDispatchBuffers.clear();
500 return std::make_pair ( lReply , & ( * ( lReply.
mMembers ) ) );
506 return std::make_pair ( lReply , & ( * ( lReply.
mMembers ) ) );
512 return std::make_pair ( lReply , & ( * ( lReply.
mMembers ) ) );
528 uint32_t lBitShiftedSource ( aSource << lShiftSize );
530 if ( ( lBitShiftedSource >> lShiftSize ) != aSource )
532 exception::BitsSetWhichAreForbiddenByBitMask lExc;
533 log ( lExc ,
"Source data (" ,
Integer ( aSource ,
IntFmt<hex,fixed>() ) ,
") has bits which would be shifted outside the register " );
537 uint32_t lOverlap ( lBitShiftedSource & ~aMask );
541 exception::BitsSetWhichAreForbiddenByBitMask lExc;
543 " has the following bits set outside the bounds allowed by the bit-mask ( ",
Integer ( aSource ,
IntFmt<hex,fixed>() ) ,
") : " ,
609 if ( aTimeoutPeriod == 0 )
615 mTimeoutPeriod = boost::posix_time::milliseconds ( aTimeoutPeriod );
virtual ValHeader implementWrite(const uint32_t &aAddr, const uint32_t &aValue)=0
Write a single, unmasked word to a register.
void returnBufferToPool(boost::shared_ptr< Buffers > &aBuffers)
Function to return a buffer to the buffer pool.
std::deque< boost::shared_ptr< Buffers > > mBuffers
A memory pool of buffers which will be dispatched.
virtual uint32_t getPreambleSize()
Return the size of the preamble.
ValWord< uint32_t > read(const uint32_t &aAddr)
Read a single, unmasked, unsigned word.
virtual ~ClientInterface()
Destructor.
void dispatch()
Method to dispatch all IPbus packets which are in the queue of IPbusPacketInfo's and wait until all q...
boost::shared_ptr< Buffers > mCurrentBuffers
A pointer to a buffer-wrapper object.
boost::mutex mBufferMutex
A MutEx lock used to make sure the access to the buffers is thread safe.
void setTimeoutPeriod(const uint32_t &aTimeoutPeriod=0)
A method to modify the timeout period for any pending or future transactions.
std::string mHostname
The "host" part of a URI of the form "protocol://host:port/patha/pathb/blah.ext?key1=val1&key2=val2&k...
virtual void preamble(boost::shared_ptr< Buffers > aBuffers)
Add a preamble to an IPbus buffer.
A class wrapping the send and recieve buffers that are to be filled and transported and the validated...
virtual ClientInterface & operator=(const ClientInterface &aClientInterface)
Assignment operator.
boost::shared_ptr< _ValWord_< T > > mMembers
Return a std::deque containing all the IPbus headers returned during the transaction.
A Template helper struct wrapping an IPbus header, a register for storing a single word of data...
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_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...
An abstract base exception class providing an interface to a throw/ThrowAsDerivedType mechanism which...
ValHeader write(const uint32_t &aAddr, const uint32_t &aValue)
Write a single, unmasked word to a register.
ClientInterface()
Default Constructor.
boost::mutex mUserSideMutex
A MutEx lock used to make sure the access functions are thread safe.
boost::posix_time::time_duration mTimeoutPeriod
Timeout period for transactions.
virtual void dispatchExceptionHandler()
Function which is called when an exception is thrown.
virtual void implementDispatch(boost::shared_ptr< Buffers > aBuffers)=0
Pure virtual function which actually performs the dispatch operation.
std::string uri() const
Ping the target for this client.
virtual void predispatch(boost::shared_ptr< Buffers > aBuffers)
Finalize the buffer before it is transmitted.
std::string mPort
The "port" part of a URI of the form "protocol://host:port/patha/pathb/blah.ext?key1=val1&key2=val2&k...
if(hw.uri().find("ipbusudp-1.3://") !=std::string::npos||hw.uri().find("ipbustcp-1.3://") !=std::string::npos||hw.uri().find("chtcp-1.3://") !=std::string::npos)
std::pair< ValVector< uint32_t >, _ValVector_< uint32_t > *> CreateValVector(const uint32_t &aSize)
Helper function to create a ValVector object.
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.
NameValuePairVectorType mArguments
The "key1=val1&key2=val2&key3=val3" part of a URI of the form "protocol://host:port/patha/pathb/blah...
virtual void Flush()
Virtual function to dispatch all buffers and block until all replies are received.
std::string mId
the identifier of the target for this client
Empty struct which acts as a dummy variable for passing the formatting information around...
std::pair< ValHeader, _ValHeader_ *> CreateValHeader()
Helper function to create a ValHeader object.
boost::shared_ptr< _ValVector_< T > > mMembers
Return a std::deque containing all the IPbus headers returned during the transaction.
uint64_t getTimeoutPeriod()
A method to retrieve the timeout period currently being used.
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.
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 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.
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.
An abstract base class for defining the interface to the various IPbus clients as well as providing t...
std::string mExtension
The "ext" part of a URI of the form "protocol://host:port/patha/pathb/blah.ext?key1=val1&key2=val2&ke...
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...
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 mProtocol
The "protocol" part of a URI of the form "protocol://host:port/patha/pathb/blah.ext?key1=val1&key2=val2&key3=val3".
std::string mPath
The "patha/pathb/blah" part of a URI of the form "protocol://host:port/patha/pathb/blah.ext?key1=val1&key2=val2&key3=val3".
BlockReadWriteMode
define whether transactions target a single register, a block of registers, a block-read/write port o...
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...
void updateCurrentBuffers()
If the current buffer is null, allocate a buffer from the buffer pool for it If the buffer pool is em...
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...
unsigned int TrailingRightBits(uint32_t aValue)
Helper function to calculate the number of zero-bits at the righthand end of a 32-bit number...
virtual uint32_t getMaxReplySize()=0
Return the maximum size of reply packet based on the buffer size in the target.
const std::string & id() const
Return the identifier of the target for this client.
URI mUri
a struct containing the full URI of the target for this client
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.
_Integer< T, IntFmt<> > Integer(const T &aT)
Forward declare a function which creates an instance of the ultra-lightweight wrapper from an integer...
Struct to store a URI when parsed by boost spirit.
A Template helper struct wrapping a block of IPbus header, a register for storing a block of data and...
const boost::posix_time::time_duration & getBoostTimeoutPeriod()
A method to retrieve the timeout period currently being used.
virtual uint32_t getMaxSendSize()=0
Return the maximum size to be sent based on the buffer size in the target.