RegisterT.h
Go to the documentation of this file.
00001 //-----------------------------------------------------------------------------
00002 //  (c) 2006 by Basler Vision Technologies
00003 //  Section: Vision Components
00004 //  Project: GenApi
00005 //  Author:  Alexander Happe
00006 //  $Header$
00007 //
00008 //  License: This file is published under the license of the EMVA GenICam  Standard Group.
00009 //  A text file describing the legal terms is included in  your installation as 'GenICam_license.pdf'.
00010 //  If for some reason you are missing  this file please contact the EMVA or visit the website
00011 //  (http://www.genicam.org) for a full copy.
00012 //
00013 //  THIS SOFTWARE IS PROVIDED BY THE EMVA GENICAM STANDARD GROUP "AS IS"
00014 //  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
00015 //  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00016 //  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE EMVA GENICAM STANDARD  GROUP
00017 //  OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,  SPECIAL,
00018 //  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT  LIMITED TO,
00019 //  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,  DATA, OR PROFITS;
00020 //  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY  THEORY OF LIABILITY,
00021 //  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE)
00022 //  ARISING IN ANY WAY OUT OF THE USE  OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00023 //  POSSIBILITY OF SUCH DAMAGE.
00024 //-----------------------------------------------------------------------------
00031 #ifndef GENAPI_REGISTERT_H
00032 #define GENAPI_REGISTERT_H
00033 
00034 #include "../IRegister.h"
00035 #include "GenApi/impl/Log.h"
00036 #include "Exception.h"
00037 #include "GenApi/Compatibility.h"
00038 
00039 #ifndef _WIN32
00040 #  define _snprintf snprintf
00041 #endif
00042 
00043 namespace GENAPI_NAMESPACE
00044 {
00045 
00046 #   ifdef _MSC_VER
00047 #       pragma warning ( push )
00048 #       pragma warning ( disable : 4996 ) // depcretaced function
00049 #   endif
00050 
00053     template <class Base>
00054     class RegisterT
00055         : public Base
00056     {
00057     public:
00058 
00060         virtual void Set(const uint8_t *pBuffer, int64_t Length, bool Verify = true)
00061         {
00062             // a list of callbacks to fire held outside(!) the autolock on the stack(!)
00063             std::list<CNodeCallback*> CallbacksToFire;
00064             {
00065                 AutoLock l(Base::GetLock());
00066                 typename Base::EntryMethodFinalizer E( this, meSet );
00067 
00068                 if( GENICAM_NAMESPACE::CLog::IsInfoEnabled( Base::m_pValueLog ) && pBuffer )
00069                 {
00070                     {
00071                         static const char fmt[] =
00072                             "Set( %" FMT_I64 "d, 0x";
00073                         static const int BufferLen(256);
00074                         char _pBuffer[256];
00075 
00076                         int BufferLeft(_snprintf(_pBuffer, BufferLen, fmt, Length));
00077 
00078                         /* MANTIS 0000062 */
00079                         for(int i = 0; i < Length; i++)
00080                         {
00081                             const int n =_snprintf(_pBuffer + BufferLeft,
00082                                                    BufferLen - BufferLeft,
00083                                                    "%02X", (unsigned int) pBuffer[i]);
00084 #pragma BullseyeCoverage off
00085                             #ifdef _MSC_VER
00086                 if (n < 0)
00087                             #else
00088                 if (BufferLeft + n >= BufferLen)
00089                             #endif
00090                                 break;
00091 #pragma BullseyeCoverage on
00092                             BufferLeft += n;
00093                         }
00094 
00095                         GCLOGINFOPUSH( Base::m_pValueLog, "%s )...", _pBuffer);
00096                     }
00097                 }
00098 
00099                 if( Verify && !IsWritable( this ) )
00100                     throw  ACCESS_EXCEPTION_NODE("Node is not writable");
00101 
00102                 {
00103                     typename Base::PostSetValueFinalizer PostSetValueCaller(this, CallbacksToFire);  // dtor calls Base::PostSetValue
00104 
00105                     Base::PreSetValue(); // invalidates all nodes if this is the first call in a chain of SetValue like calls
00106                     Base::InternalSet(pBuffer, Length);
00107 
00108                     if( Verify )
00109                         Base::InternalCheckError();
00110                 }
00111 
00112                 GCLOGINFOPOP( Base::m_pValueLog, "...Set" );
00113 
00114                 // fire callbacks inside the lock
00115                 std::list<CNodeCallback*>::iterator ptrCallback;
00116                 for( ptrCallback = CallbacksToFire.begin(); ptrCallback != CallbacksToFire.end(); ptrCallback++ )
00117                 {
00118                     (*ptrCallback)->operator ()(cbPostInsideLock);
00119                 }
00120             }
00121 
00122             // fire callbacks outside the lock
00123             std::list<CNodeCallback*>::iterator ptrCallback;
00124             for( ptrCallback = CallbacksToFire.begin(); ptrCallback != CallbacksToFire.end(); ptrCallback++ )
00125             {
00126                 (*ptrCallback)->operator ()(cbPostOutsideLock);
00127             }
00128         }
00129 
00130 
00132         virtual void Get(uint8_t *pBuffer, int64_t Length, bool Verify = false, bool IgnoreCache = false)
00133         {
00134             AutoLock l(Base::GetLock());
00135             typename Base::EntryMethodFinalizer E( this, meGet, IgnoreCache );
00136 
00137             GCLOGINFOPUSH( Base::m_pValueLog, "Get...");
00138 
00139             // Note that readability is tested regardless of Verify
00140             if( !IsReadable( this ) )
00141                 throw ACCESS_EXCEPTION_NODE("Node is not readable");
00142 
00143             Base::InternalGet(pBuffer, Length, Verify, IgnoreCache );
00144 
00145             if( Verify )
00146                 Base::InternalCheckError();
00147 
00148             if (GENICAM_NAMESPACE::CLog::IsInfoEnabled(Base::m_pValueLog))
00149             {
00150                 static const char fmt[] =
00151                     "...Get( %" FMT_I64 "d ) = 0x";
00152 
00153                 static const int BufferLen(256);
00154                 char _pBuffer[256];
00155                 int BufferLeft(_snprintf(_pBuffer, BufferLen, fmt, Length));
00156 
00157                 /* MANTIS 0000062 */
00158                 for(int i = 0; i < Length; i++)
00159                 {
00160                     const int n = _snprintf(_pBuffer + BufferLeft,
00161                                             BufferLen - BufferLeft,
00162                                             "%02X", (unsigned int) pBuffer[i]);
00163 #pragma BullseyeCoverage off
00164                     #ifdef _MSC_VER
00165                         if (n < 0)
00166                             break;
00167                     #else
00168                         if (BufferLeft + n >= BufferLen)
00169                             break;
00170                     #endif
00171 #pragma BullseyeCoverage on
00172                     BufferLeft += n;
00173                 }
00174                 GCLOGINFOPOP( Base::m_pValueLog, "%s", _pBuffer );
00175             }
00176         }
00177 
00179         virtual int64_t GetLength()
00180         {
00181             AutoLock l(Base::GetLock());
00182 
00183             return Base::InternalGetLength();
00184         }
00185 
00187         virtual int64_t GetAddress()
00188         {
00189             AutoLock l(Base::GetLock());
00190 
00191             return Base::InternalGetAddress(false,false);
00192         }
00193 
00194     };
00195 #   ifdef _MSC_VER
00196 #       pragma warning ( pop )
00197 #   endif
00198 
00199 } // namespace GenApi
00200 
00201 #endif // GENAPI_REGISTERT_H


rc_genicam_api
Author(s): Heiko Hirschmueller
autogenerated on Thu Jun 6 2019 18:42:47