RegisterT.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 // (c) 2006 by Basler Vision Technologies
3 // Section: Vision Components
4 // Project: GenApi
5 // Author: Alexander Happe
6 // $Header$
7 //
8 // License: This file is published under the license of the EMVA GenICam Standard Group.
9 // A text file describing the legal terms is included in your installation as 'GenICam_license.pdf'.
10 // If for some reason you are missing this file please contact the EMVA or visit the website
11 // (http://www.genicam.org) for a full copy.
12 //
13 // THIS SOFTWARE IS PROVIDED BY THE EMVA GENICAM STANDARD GROUP "AS IS"
14 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE EMVA GENICAM STANDARD GROUP
17 // OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23 // POSSIBILITY OF SUCH DAMAGE.
24 //-----------------------------------------------------------------------------
31 #ifndef GENAPI_REGISTERT_H
32 #define GENAPI_REGISTERT_H
33 
34 #include "../IRegister.h"
35 #include "GenApi/impl/Log.h"
36 #include "Exception.h"
37 #include "GenApi/Compatibility.h"
38 
39 #ifndef _WIN32
40 # define _snprintf snprintf
41 #endif
42 
43 namespace GENAPI_NAMESPACE
44 {
45 
46 # ifdef _MSC_VER
47 # pragma warning ( push )
48 # pragma warning ( disable : 4996 ) // depcretaced function
49 # endif
50 
53  template <class Base>
54  class RegisterT
55  : public Base
56  {
57  public:
58 
60  virtual void Set(const uint8_t *pBuffer, int64_t Length, bool Verify = true)
61  {
62  // a list of callbacks to fire held outside(!) the autolock on the stack(!)
63  std::list<CNodeCallback*> CallbacksToFire;
64  {
66  typename Base::EntryMethodFinalizer E( this, meSet );
67 
68  if( GENICAM_NAMESPACE::CLog::IsInfoEnabled( Base::m_pValueLog ) && pBuffer )
69  {
70  {
71  static const char fmt[] =
72  "Set( %" FMT_I64 "d, 0x";
73  static const int BufferLen(256);
74  char _pBuffer[256];
75 
76  int BufferLeft(_snprintf(_pBuffer, BufferLen, fmt, Length));
77 
78  /* MANTIS 0000062 */
79  for(int i = 0; i < Length; i++)
80  {
81  const int n =_snprintf(_pBuffer + BufferLeft,
82  BufferLen - BufferLeft,
83  "%02X", (unsigned int) pBuffer[i]);
84 #pragma BullseyeCoverage off
85  #ifdef _MSC_VER
86  if (n < 0)
87  #else
88  if (BufferLeft + n >= BufferLen)
89  #endif
90  break;
91 #pragma BullseyeCoverage on
92  BufferLeft += n;
93  }
94 
95  GCLOGINFOPUSH( Base::m_pValueLog, "%s )...", _pBuffer);
96  }
97  }
98 
99  if( Verify && !IsWritable( this ) )
100  throw ACCESS_EXCEPTION_NODE("Node is not writable");
101 
102  {
103  typename Base::PostSetValueFinalizer PostSetValueCaller(this, CallbacksToFire); // dtor calls Base::PostSetValue
104 
105  Base::PreSetValue(); // invalidates all nodes if this is the first call in a chain of SetValue like calls
106  Base::InternalSet(pBuffer, Length);
107 
108  if( Verify )
109  Base::InternalCheckError();
110  }
111 
112  GCLOGINFOPOP( Base::m_pValueLog, "...Set" );
113 
114  // fire callbacks inside the lock
115  std::list<CNodeCallback*>::iterator ptrCallback;
116  for( ptrCallback = CallbacksToFire.begin(); ptrCallback != CallbacksToFire.end(); ptrCallback++ )
117  {
118  (*ptrCallback)->operator ()(cbPostInsideLock);
119  }
120  }
121 
122  // fire callbacks outside the lock
123  std::list<CNodeCallback*>::iterator ptrCallback;
124  for( ptrCallback = CallbacksToFire.begin(); ptrCallback != CallbacksToFire.end(); ptrCallback++ )
125  {
126  (*ptrCallback)->operator ()(cbPostOutsideLock);
127  }
128  }
129 
130 
132  virtual void Get(uint8_t *pBuffer, int64_t Length, bool Verify = false, bool IgnoreCache = false)
133  {
134  AutoLock l(Base::GetLock());
135  typename Base::EntryMethodFinalizer E( this, meGet, IgnoreCache );
136 
137  GCLOGINFOPUSH( Base::m_pValueLog, "Get...");
138 
139  // Note that readability is tested regardless of Verify
140  if( !IsReadable( this ) )
141  throw ACCESS_EXCEPTION_NODE("Node is not readable");
142 
143  Base::InternalGet(pBuffer, Length, Verify, IgnoreCache );
144 
145  if( Verify )
146  Base::InternalCheckError();
147 
148  if (GENICAM_NAMESPACE::CLog::IsInfoEnabled(Base::m_pValueLog))
149  {
150  static const char fmt[] =
151  "...Get( %" FMT_I64 "d ) = 0x";
152 
153  static const int BufferLen(256);
154  char _pBuffer[256];
155  int BufferLeft(_snprintf(_pBuffer, BufferLen, fmt, Length));
156 
157  /* MANTIS 0000062 */
158  for(int i = 0; i < Length; i++)
159  {
160  const int n = _snprintf(_pBuffer + BufferLeft,
161  BufferLen - BufferLeft,
162  "%02X", (unsigned int) pBuffer[i]);
163 #pragma BullseyeCoverage off
164  #ifdef _MSC_VER
165  if (n < 0)
166  break;
167  #else
168  if (BufferLeft + n >= BufferLen)
169  break;
170  #endif
171 #pragma BullseyeCoverage on
172  BufferLeft += n;
173  }
174  GCLOGINFOPOP( Base::m_pValueLog, "%s", _pBuffer );
175  }
176  }
177 
179  virtual int64_t GetLength()
180  {
181  AutoLock l(Base::GetLock());
182 
183  return Base::InternalGetLength();
184  }
185 
187  virtual int64_t GetAddress()
188  {
189  AutoLock l(Base::GetLock());
190 
191  return Base::InternalGetAddress(false,false);
192  }
193 
194  };
195 # ifdef _MSC_VER
196 # pragma warning ( pop )
197 # endif
198 
199 } // namespace GenApi
200 
201 #endif // GENAPI_REGISTERT_H
#define _snprintf
Definition: RegisterT.h:40
__int64 int64_t
Definition: config-win32.h:21
virtual int64_t GetLength()
Implementation of IRegister::GetLength()
Definition: RegisterT.h:179
Implementation of the IRegister interface.
Definition: RegisterT.h:54
static bool IsInfoEnabled(LOG4CPP_NS::Category *aCategory)
Check whether logging is possible and enabled for a specific category.
bool IsReadable(EAccessMode AccessMode)
Tests if readable.
Definition: INode.h:178
#define ACCESS_EXCEPTION_NODE
Fires a access error exception, e.g. throw ACCESS_ERROR_EXCEPTION("Not everybody") ...
Definition: Exception.h:172
virtual void Get(uint8_t *pBuffer, int64_t Length, bool Verify=false, bool IgnoreCache=false)
Implementation of IRegister::Get()
Definition: RegisterT.h:132
Definition of macros for cross-platform compatibility.
interface GENAPI_DECL_ABSTRACT bool Verify
Definition: IBoolean.h:61
#define GCLOGINFOPUSH(cat,...)
Definition: CLog.h:163
virtual void Set(const uint8_t *pBuffer, int64_t Length, bool Verify=true)
Implementation of IRegister::Set()
Definition: RegisterT.h:60
interface GENAPI_DECL_ABSTRACT int64_t int64_t Length
Definition: IPort.h:57
bool IsWritable(EAccessMode AccessMode)
Tests if writable.
Definition: INode.h:196
#define GCLOGINFOPOP(cat,...)
Definition: CLog.h:164
virtual int64_t GetAddress()
Retrieves the Address of the register.
Definition: RegisterT.h:187
#define FMT_I64
Definition: Compatibility.h:68
Part of the generic device API.
Definition: Autovector.h:48
callback is fired on leaving the tree inside the lock-guarded area
Definition: NodeCallback.h:48
virtual CLock & GetLock() const =0
Returns the lock which guards the node map.


rc_genicam_api
Author(s): Heiko Hirschmueller
autogenerated on Thu Jun 6 2019 19:10:54