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


rc_genicam_api
Author(s): Heiko Hirschmueller
autogenerated on Wed Mar 17 2021 02:48:41