μHAL (v2.6.5)
Part of the IPbus software repository
ClientInterface.hpp
Go to the documentation of this file.
1 /*
2 ---------------------------------------------------------------------------
3 
4  This file is part of uHAL.
5 
6  uHAL is a hardware access library and programming framework
7  originally developed for upgrades of the Level-1 trigger of the CMS
8  experiment at CERN.
9 
10  uHAL is free software: you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  uHAL is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with uHAL. If not, see <http://www.gnu.org/licenses/>.
22 
23 
24  Andrew Rose, Imperial College, London
25  email: awr01 <AT> imperial.ac.uk
26 
27  Marc Magrans de Abril, CERN
28  email: marc.magrans.de.abril <AT> cern.ch
29 
30 ---------------------------------------------------------------------------
31 */
32 
40 #ifndef _uhal_ClientInterface_hpp_
41 #define _uhal_ClientInterface_hpp_
42 
43 
44 #include <deque>
45 #include <stdint.h>
46 #include <string>
47 #include <utility>
48 #include <vector>
49 
50 #include <boost/date_time/posix_time/posix_time_types.hpp>
51 #include <boost/shared_ptr.hpp>
52 #include <boost/thread/mutex.hpp>
53 
54 #include "uhal/grammars/URI.hpp"
55 #include "uhal/log/exception.hpp"
56 #include "uhal/definitions.hpp"
57 #include "uhal/ValMem.hpp"
58 
59 
60 namespace uhal
61 {
62  // Forward declaration
63  class Buffers;
64  class IPbusCore;
65 
66  namespace exception
67  {
68  // //! Exception class to handle the case where an Atomic Transaction was requested but could not be performed. Uses the base uhal::exception implementation of what()
69  // class AtomicTransactionSize : public exception {};
71  UHAL_DEFINE_EXCEPTION_CLASS ( PingFailed , "Exception class to handle the case where pinging of a client failed." )
72 
73 
74  UHAL_DEFINE_EXCEPTION_CLASS ( BitsSetWhichAreForbiddenByBitMask , "Exception class to handle the case where a masked write was attempted with a data source which has non-zero bits outside the bit-mask's bounds." )
75 
77  UHAL_DEFINE_EXCEPTION_CLASS ( ValidationError , "Exception class to handle the case where we were unable to validate the packet." )
78 
80  UHAL_DEFINE_EXCEPTION_CLASS ( NullBufferException , "Exception class to handle a NULL buffer being passed to the transport class." )
81 
82  UHAL_DEFINE_EXCEPTION_CLASS ( PacketLevelError, "Base exception class covering situations in which a packet-level error occurs.")
83 
84  UHAL_DEFINE_EXCEPTION_CLASS ( TransactionLevelError, "Base exception class covering situations in which a transaction-level error occurs (i.e. error occurs in individual read/write).")
85 
86  UHAL_DEFINE_EXCEPTION_CLASS ( ClientTimeout, "Base exception class covering timeouts when waiting for reply from device")
87 
88  UHAL_DEFINE_EXCEPTION_CLASS ( TransportLayerError, "Base exception class covering non-timeout transport-layer-specific errors.")
89  }
90 
93  {
94  protected:
101  ClientInterface ( const std::string& aId, const URI& aUri , const boost::posix_time::time_duration& aTimeoutPeriod );
102 
103  private:
107  ClientInterface ();
108 
113  ClientInterface ( const ClientInterface& aClientInterface );
114 
120  virtual ClientInterface& operator= ( const ClientInterface& aClientInterface );
121 
122  public:
126  virtual ~ClientInterface();
127 
132  const std::string& id() const;
133 
134  // /**
135  // Ping the target for this client
136  // */
137  // void ping();
138 
143  std::string uri() const;
144 
148  void dispatch ();
149 
155  void setTimeoutPeriod ( const uint32_t& aTimeoutPeriod = 0 );
156 
162  uint64_t getTimeoutPeriod();
163 
164  protected:
170  const boost::posix_time::time_duration& getBoostTimeoutPeriod();
171 
172  public:
173 
179  ValHeader write ( const uint32_t& aAddr, const uint32_t& aValue );
180 
187  ValHeader write ( const uint32_t& aAddr, const uint32_t& aValue, const uint32_t& aMask );
188 
195  ValHeader writeBlock ( const uint32_t& aAddr, const std::vector< uint32_t >& aValues, const defs::BlockReadWriteMode& aMode=defs::INCREMENTAL );
196 
202  ValWord< uint32_t > read ( const uint32_t& aAddr );
203 
210  ValWord< uint32_t > read ( const uint32_t& aAddr, const uint32_t& aMask );
211 
219  ValVector< uint32_t > readBlock ( const uint32_t& aAddr, const uint32_t& aSize, const defs::BlockReadWriteMode& aMode=defs::INCREMENTAL );
220 
228  ValWord< uint32_t > rmw_bits ( const uint32_t& aAddr , const uint32_t& aANDterm , const uint32_t& aORterm );
229 
236  ValWord< uint32_t > rmw_sum ( const uint32_t& aAddr , const int32_t& aAddend );
237 
238  protected:
243  virtual void implementDispatch ( boost::shared_ptr< Buffers > aBuffers ) = 0;
244 
246  virtual void Flush( );
247 
248 
252  virtual ValHeader implementBOT( ) = 0;
253 
259  virtual ValHeader implementWrite ( const uint32_t& aAddr, const uint32_t& aValue ) = 0;
260 
267  virtual ValHeader implementWriteBlock ( const uint32_t& aAddr, const std::vector< uint32_t >& aValues, const defs::BlockReadWriteMode& aMode=defs::INCREMENTAL ) = 0;
268 
275  virtual ValWord< uint32_t > implementRead ( const uint32_t& aAddr, const uint32_t& aMask = defs::NOMASK ) = 0;
276 
284  virtual ValVector< uint32_t > implementReadBlock ( const uint32_t& aAddr, const uint32_t& aSize, const defs::BlockReadWriteMode& aMode=defs::INCREMENTAL ) = 0;
285 
286 
294  virtual ValWord< uint32_t > implementRMWbits ( const uint32_t& aAddr , const uint32_t& aANDterm , const uint32_t& aORterm ) = 0;
295 
302  virtual ValWord< uint32_t > implementRMWsum ( const uint32_t& aAddr , const int32_t& aAddend ) = 0;
303 
307  virtual void preamble ( boost::shared_ptr< Buffers > aBuffers );
308 
312  virtual uint32_t getPreambleSize();
313 
318  virtual void predispatch ( boost::shared_ptr< Buffers > aBuffers );
319 
324  std::pair < ValHeader , _ValHeader_* > CreateValHeader();
331  std::pair < ValWord<uint32_t> , _ValWord_<uint32_t>* > CreateValWord ( const uint32_t& aValue , const uint32_t& aMask = defs::NOMASK );
332 
338  std::pair < ValVector<uint32_t> , _ValVector_<uint32_t>* > CreateValVector ( const uint32_t& aSize );
339 
345  virtual exception::exception* validate ( boost::shared_ptr< Buffers > aBuffers );
346 
347 
348 
349  protected:
358  virtual exception::exception* validate ( uint8_t* aSendBufferStart ,
359  uint8_t* aSendBufferEnd ,
360  std::deque< std::pair< uint8_t* , uint32_t > >::iterator aReplyStartIt ,
361  std::deque< std::pair< uint8_t* , uint32_t > >::iterator aReplyEndIt ) = 0;
362 
364  virtual void dispatchExceptionHandler();
365 
370  void returnBufferToPool ( boost::shared_ptr< Buffers >& aBuffers );
375  void returnBufferToPool ( std::deque< boost::shared_ptr< Buffers > >& aBuffers );
380  void returnBufferToPool ( std::vector< boost::shared_ptr< Buffers > >& aBuffers );
385  void returnBufferToPool ( std::deque< std::vector< boost::shared_ptr< Buffers > > >& aBuffers );
386 
387  private:
392  void updateCurrentBuffers();
393  void deleteBuffers();
394 
395 
396  private:
398  boost::mutex mUserSideMutex;
399 
401  boost::mutex mBufferMutex;
402 
404  std::deque < boost::shared_ptr< Buffers > > mBuffers;
405 
406 #ifdef NO_PREEMPTIVE_DISPATCH
407  std::deque < boost::shared_ptr< Buffers > > mNoPreemptiveDispatchBuffers;
409 #endif
410 
411 
414 
416  std::string mId;
417 
419  boost::posix_time::time_duration mTimeoutPeriod;
420 
421  friend class IPbusCore;
422 
423  protected:
424 
427 
435  virtual boost::shared_ptr< Buffers > checkBufferSpace ( const uint32_t& aSendSize , const uint32_t& aReplySize , uint32_t& aAvailableSendSize , uint32_t& aAvailableReplySize );
436 
437 
442  virtual uint32_t getMaxNumberOfBuffers() = 0;
447  virtual uint32_t getMaxSendSize() = 0;
452  virtual uint32_t getMaxReplySize() = 0;
453  };
454 
455 
456 
457 }
458 
459 #endif
460 
std::deque< boost::shared_ptr< Buffers > > mBuffers
A memory pool of buffers which will be dispatched.
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.
c writeBlock(addr, xx)
A Template helper struct wrapping an IPbus header, a register for storing a single word of data...
Definition: ValMem.hpp:103
#define UHAL_DEFINE_EXCEPTION_CLASS(ClassName, ClassDescription)
Definition: exception.hpp:64
An abstract base exception class providing an interface to a throw/ThrowAsDerivedType mechanism which...
Definition: exception.hpp:89
boost::mutex mUserSideMutex
A MutEx lock used to make sure the access functions are thread safe.
const uint32_t NOMASK
define what it means to have no mask
Definition: definitions.hpp:56
boost::posix_time::time_duration mTimeoutPeriod
Timeout period for transactions.
for(size_t i=0;i< lDepths.size();i++)
Definition: test_block.cpp:126
std::string mId
the identifier of the target for this client
A class providing the core IPbus packing functionality.
An abstract base class for defining the interface to the various IPbus clients as well as providing t...
std::string uri
Definition: test_single.cpp:89
BlockReadWriteMode
define whether transactions target a single register, a block of registers, a block-read/write port o...
Definition: definitions.hpp:53
A class which wraps a single word of data and marks whether or not it is valid.
Definition: ValMem.hpp:156
URI mUri
a struct containing the full URI of the target for this client
c write(addr, xx[0])
Struct to store a URI when parsed by boost spirit.
Definition: URI.hpp:49
A Template helper struct wrapping a block of IPbus header, a register for storing a block of data and...
Definition: ValMem.hpp:131