FrameHandler.cpp
Go to the documentation of this file.
00001 /*=============================================================================
00002   Copyright (C) 2012 Allied Vision Technologies.  All Rights Reserved.
00003 
00004   Redistribution of this file, in original or modified form, without
00005   prior written consent of Allied Vision Technologies is prohibited.
00006 
00007 -------------------------------------------------------------------------------
00008 
00009   File:        FrameHandler.cpp
00010 
00011   Description: Implementation of class AVT::VmbAPI::FrameHandler.
00012 
00013 -------------------------------------------------------------------------------
00014 
00015   THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
00016   WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
00017   NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR  PURPOSE ARE
00018   DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 
00019   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
00020   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00021   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED  
00022   AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 
00023   TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
00024   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00025 
00026 =============================================================================*/
00027 
00028 #include <VimbaCPP/Source/FrameHandler.h>
00029 
00030 #include <VimbaCPP/Include/LoggerDefines.h>
00031 
00032 namespace AVT {
00033 namespace VmbAPI {
00034 
00035 FrameHandler::FrameHandler( FramePtr pFrame, IFrameObserverPtr pFrameObserver )
00036     :   m_pFrame( pFrame )
00037     ,   m_pObserver( pFrameObserver )
00038     ,   m_pMutex( new Mutex() )
00039 {
00040 }
00041 
00042 FramePtr FrameHandler::GetFrame() const
00043 {
00044     return m_pFrame;
00045 }
00046 
00047 bool FrameHandler::EnterWriteLock( bool bExclusive )
00048 {
00049     return m_conditionHelper.EnterWriteLock( m_pMutex, bExclusive );
00050 }
00051 
00052 void FrameHandler::ExitWriteLock()
00053 {
00054     m_conditionHelper.ExitWriteLock( m_pMutex );
00055 }
00056 
00057 bool FrameHandler::EnterReadLock()
00058 {
00059     return m_conditionHelper.EnterReadLock( m_pMutex );
00060 }
00061 
00062 void FrameHandler::ExitReadLock()
00063 {
00064     m_conditionHelper.ExitReadLock( m_pMutex );
00065 }
00066 
00067 void VMB_CALL FrameHandler::FrameDoneCallback( const VmbHandle_t /*handle*/, VmbFrame_t *pVmbFrame )
00068 {
00069     if ( NULL != pVmbFrame )
00070     {
00071         FrameHandler* pFrameHandler = reinterpret_cast<FrameHandler*>( pVmbFrame->context[FRAME_HDL] );
00072         if ( NULL != pFrameHandler)
00073         {            
00074             // Begin read lock frame handler
00075 
00076             if ( true == pFrameHandler->EnterReadLock() )
00077             {
00078                 {
00079                     IFrameObserverPtr pObs;
00080                     if ( true == SP_ACCESS( pFrameHandler->m_pFrame )->GetObserver( pObs ))
00081                     {
00082                         SP_ACCESS( pObs )->FrameReceived( pFrameHandler->m_pFrame );
00083                     }
00084                 }// scope to destroy observer pointer before releasing the lock
00085                 // End read lock frame handler
00086                 pFrameHandler->ExitReadLock();
00087             }
00088             else
00089             {
00090                 LOG_FREE_TEXT( "Could not lock frame handler. Skipping frame." )
00091             }
00092         }
00093         else // No FrameHandler
00094         {
00095             LOG_FREE_TEXT( "No frame handler passed. Frame has been removed from the frame queue." )
00096         }
00097     }
00098     else // pVmbFrame == NULL (Just for safety)
00099     {
00100         LOG_FREE_TEXT( "Received callback for already freed frame." )
00101     }
00102 }
00103 
00104 }}


avt_vimba_camera
Author(s): Miquel Massot , Allied Vision Technologies
autogenerated on Thu Jun 6 2019 18:23:39