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 ) // deprecated 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, Base::IsStreamable());
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 (!Base::CanBeWritten( Verify ))
101  {
102  throw ACCESS_EXCEPTION_NODE( "Node is not writable" );
103  }
104 
105  {
106  typename Base::PostSetValueFinalizer PostSetValueCaller(this, CallbacksToFire); // dtor calls Base::PostSetValue
107 
108  Base::PreSetValue(); // invalidates all nodes if this is the first call in a chain of SetValue like calls
109  Base::InternalSet(pBuffer, Length, Verify);
110 
111  }
112  if (Verify)
113  {
114  Base::InternalCheckError();
115  }
116 
117  GCLOGINFOPOP( Base::m_pValueLog, "...Set" );
118 
119  // fire callbacks inside the lock
120  std::list<CNodeCallback*>::iterator ptrCallback;
121  for( ptrCallback = CallbacksToFire.begin(); ptrCallback != CallbacksToFire.end(); ptrCallback++ )
122  {
123  (*ptrCallback)->operator ()(cbPostInsideLock);
124  }
125  }
126 
127  // fire callbacks outside the lock
128  std::list<CNodeCallback*>::iterator ptrCallback;
129  for( ptrCallback = CallbacksToFire.begin(); ptrCallback != CallbacksToFire.end(); ptrCallback++ )
130  {
131  (*ptrCallback)->operator ()(cbPostOutsideLock);
132  }
133  }
134 
135 
137  virtual void Get(uint8_t *pBuffer, int64_t Length, bool Verify = false, bool IgnoreCache = false)
138  {
139  AutoLock l(Base::GetLock());
140  typename Base::EntryMethodFinalizer E(this, meGet, Base::IsStreamable(), IgnoreCache);
141 
142  GCLOGINFOPUSH( Base::m_pValueLog, "Get...");
143 
144  // Note that readability is tested regardless of Verify
145  if( !IsReadable( this ) )
146  throw ACCESS_EXCEPTION_NODE("Node is not readable");
147 
148  Base::InternalGet(pBuffer, Length, Verify, IgnoreCache );
149 
150  if (Verify)
151  {
152  Base::InternalCheckError();
153  }
154 
155 
156  if (Base::m_pValueLog && GENICAM_NAMESPACE::CLog::Exist(""))
157  {
158  static const char fmt[] =
159  "...Get( %" FMT_I64 "d ) = 0x";
160 
161  static const int BufferLen( 256 );
162  char _pBuffer[256];
163  int BufferLeft( _snprintf( _pBuffer, BufferLen, fmt, Length ) );
164 
165  /* MANTIS 0000062 */
166  for (int i = 0; i < Length; i++)
167  {
168  const int n = _snprintf( _pBuffer + BufferLeft,
169  BufferLen - BufferLeft,
170  "%02X", (unsigned int) pBuffer[i] );
171 #pragma BullseyeCoverage off
172 #ifdef _MSC_VER
173  if (n < 0)
174  break;
175 #else
176  if (BufferLeft + n >= BufferLen)
177  break;
178 #endif
179 #pragma BullseyeCoverage on
180  BufferLeft += n;
181  }
182  Base::m_pValueLog->Log( GENICAM_NAMESPACE::ILogger::INFO, "%s", _pBuffer );
184  }
185  }
186 
188  virtual int64_t GetLength( bool Verify = false )
189  {
190  AutoLock l(Base::GetLock());
191 
192  return Base::InternalGetLength(Verify);
193  }
194 
196  virtual int64_t GetAddress( bool Verify = false )
197  {
198  AutoLock l(Base::GetLock());
199 
200  return Base::InternalGetAddress(Verify,false);
201  }
202 
203  };
204 # ifdef _MSC_VER
205 # pragma warning ( pop )
206 # endif
207 
208 } // namespace GenApi
209 
210 #endif // GENAPI_REGISTERT_H
GENAPI_NAMESPACE
Lexical analyzer for CIntSwissKnife.
Definition: Destructible.h:30
GENICAM_NAMESPACE::CLog::Exist
static bool Exist(const gcstring &LoggerName)
Checks if a category/logger exists First checks the local logger map Finally checks via ILoggerFactor...
GENAPI_NAMESPACE::cbPostOutsideLock
@ cbPostOutsideLock
callback is fired on leaving the tree inside the lock-guarded area
Definition: NodeCallback.h:48
GENAPI_NAMESPACE::RegisterT
Implementation of the IRegister interface.
Definition: RegisterT.h:53
GENAPI_NAMESPACE::GetLock
virtual CLock & GetLock() const =0
Returns the lock which guards the node map.
GENICAM_NAMESPACE::ILogger::INFO
@ INFO
Definition: ILogger.h:18
GENAPI_NAMESPACE::RegisterT::GetLength
virtual int64_t GetLength(bool Verify=false)
Implementation of IRegister::GetLength()
Definition: RegisterT.h:188
GENAPI_NAMESPACE::Verify
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT bool Verify
Definition: IBoolean.h:61
GCLOGINFOPOP
#define GCLOGINFOPOP(cat,...)
Definition: CLog.h:134
Exception.h
GENAPI_NAMESPACE::meSet
@ meSet
Definition: Exception.h:55
GENAPI_NAMESPACE::CanBeWritten
virtual bool CanBeWritten(bool Verify)=0
GENAPI_NAMESPACE::RegisterT::Get
virtual void Get(uint8_t *pBuffer, int64_t Length, bool Verify=false, bool IgnoreCache=false)
Implementation of IRegister::Get()
Definition: RegisterT.h:137
ACCESS_EXCEPTION_NODE
#define ACCESS_EXCEPTION_NODE
Fires a access error exception, e.g. throw ACCESS_ERROR_EXCEPTION("Not everybody")
Definition: Exception.h:179
GENAPI_NAMESPACE::RegisterT::Set
virtual void Set(const uint8_t *pBuffer, int64_t Length, bool Verify=true)
Implementation of IRegister::Set()
Definition: RegisterT.h:59
GENAPI_NAMESPACE::IsReadable
bool IsReadable(EAccessMode AccessMode)
Tests if readable.
Definition: INode.h:178
GENAPI_NAMESPACE::Length
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT int64_t int64_t Length
Definition: IPort.h:57
GENAPI_NAMESPACE::AutoLock
Definition: Synch.h:139
GENICAM_NAMESPACE::CLog::PushIndent
static void PushIndent()
GENAPI_NAMESPACE::meGet
@ meGet
Definition: Exception.h:56
GENAPI_NAMESPACE::RegisterT::GetAddress
virtual int64_t GetAddress(bool Verify=false)
Retrieves the Address of the register.
Definition: RegisterT.h:196
_snprintf
#define _snprintf
Definition: RegisterT.h:39
int64_t
__int64 int64_t
Definition: config-win32.h:21
GENAPI_NAMESPACE::IsStreamable
virtual bool IsStreamable() const =0
True if the node is streamable.
GENAPI_NAMESPACE::cbPostInsideLock
@ cbPostInsideLock
Definition: NodeCallback.h:47
GENICAM_NAMESPACE::CLog::PopIndent
static void PopIndent()
Compatibility.h
Definition of macros for cross-platform compatibility.
GCLOGINFOPUSH
#define GCLOGINFOPUSH(cat,...)
Definition: CLog.h:130
FMT_I64
#define FMT_I64
Definition: GCCompatibility.h:35


rc_genicam_api
Author(s): Heiko Hirschmueller
autogenerated on Wed Dec 4 2024 03:10:11