Camera.cpp
Go to the documentation of this file.
00001 /*=============================================================================
00002   Copyright (C) 2012 - 2016 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:        Camera.cpp
00010 
00011   Description: Implementation of class AVT::VmbAPI::Camera.
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 #pragma warning(disable:4996)
00028 #include <sstream>
00029 #pragma warning(default:4996)
00030 #include <cstring>
00031 
00032 #include <VimbaCPP/Include/Camera.h>
00033 
00034 #include <VimbaCPP/Include/LoggerDefines.h>
00035 #include <VimbaCPP/Source/ConditionHelper.h>
00036 #include <VimbaCPP/Source/FrameImpl.h>
00037 #include <VimbaCPP/Source/FrameHandler.h>
00038 #include <VimbaCPP/Source/Helper.h>
00039 #include <VimbaCPP/Source/MutexGuard.h>
00040 
00041 namespace AVT {
00042 namespace VmbAPI {
00043 
00044 // Method: GetFeatureValueInt
00045 //
00046 //Purpose: helper function to read integer value from camera.
00047 //
00048 // Parameters:
00049 //
00050 // [in] cam        camera to get integer value from
00051 // [in] name       name of the feature
00052 // [out] val       returns integer value of feature on VmbErrorSuccess
00053 //
00054 VmbErrorType GetFeatureValueInt( Camera&cam,const char* name, VmbInt64_t &val)
00055 {
00056     if( NULL == name)
00057     {
00058         LOG_FREE_TEXT("feature name is NULL");
00059         return VmbErrorBadParameter;
00060     }
00061     FeaturePtr      pFeature;
00062     VmbErrorType    res         = cam.GetFeatureByName( name, pFeature );
00063     if ( VmbErrorSuccess != res )
00064     {
00065         LOG_FREE_TEXT( std::string("Could not get feature by name for ") + name);
00066         return res;
00067     }
00068     res = SP_ACCESS(pFeature)->GetValue( val );
00069     if( VmbErrorSuccess != res)
00070     {
00071         LOG_FREE_TEXT( std::string("Could not get value of feature ") + name);
00072     }
00073     return res;
00074 }
00075 //
00076 // Method: RunFeatureCommand
00077 //
00078 // Purpose: helper to run a command feature for camera.
00079 //
00080 // Parameters:
00081 //
00082 // [in] cam        camera to run command on
00083 // [in] name       command name to run
00084 //
00085 VmbErrorType RunFeatureCommand( Camera&cam,const char* name)
00086 {
00087     if( NULL == name)
00088     {
00089         LOG_FREE_TEXT("feature name is NULL");
00090         return VmbErrorBadParameter;
00091     }
00092     FeaturePtr      pFeature;
00093     VmbErrorType    res         = cam.GetFeatureByName( name, pFeature );
00094     if ( VmbErrorSuccess != res )
00095     {
00096         LOG_FREE_TEXT( std::string("Could not get feature by name for ") + name);
00097         return res;
00098     }
00099     res = SP_ACCESS(pFeature)->RunCommand();
00100     if( VmbErrorSuccess != res)
00101     {
00102         LOG_FREE_TEXT( std::string("Could not run feature command ") + name);
00103     }
00104     return res;
00105 }
00106 
00107 // small helper class that keeps track of resources needed for image acquisition
00108 struct AcquireImageHelper
00109 {
00110 private:
00111     //clean up tasks
00112     enum tear_down_tasks
00113     {
00114         RevokeFrame,
00115         FlushQueue,
00116         EndCapture,
00117         AcquisitionStop,
00118     };
00119     typedef std::vector<tear_down_tasks>    task_storage;
00120     task_storage                            m_Tasks;        // storage for cleanup tasks
00121     Camera&                                 m_Camera;
00123     tear_down_tasks GetTask()
00124     {
00125         tear_down_tasks current_task = m_Tasks.back();
00126         m_Tasks.pop_back();
00127         return current_task;
00128     }
00129     const AcquireImageHelper& operator=( const AcquireImageHelper &o);
00130     // Method: SetupFrame
00131     //
00132     // Purpose: prepare a frame with given payload size.
00133     //
00134     // Parameters:
00135     // [in,out] pFrame         a frame pointer that can point to Null
00136     // [in]     payload_size   payload size for frame
00137     //
00138     static VmbErrorType SetupFrame(FramePtr &pFrame, VmbInt64_t PayloadSize)
00139     {
00140         if( PayloadSize <= 0)
00141         {
00142             LOG_FREE_TEXT("payload size has to be larger than 0");
00143             return VmbErrorBadParameter;
00144         }
00145         VmbUint32_t     buffer_size(0);
00146         VmbErrorType    Result;
00147         if( ! SP_ISNULL( pFrame) )  // if frame already exists, check its buffer size
00148         {
00149             Result = SP_ACCESS( pFrame) ->GetBufferSize(buffer_size);
00150             if( VmbErrorSuccess != Result)
00151             {
00152                 LOG_FREE_TEXT("Could not get frame buffer size");
00153                 return Result;
00154             }
00155             if( buffer_size >= PayloadSize) // buffer is large enough, no need to create new frame
00156             {
00157                 return VmbErrorSuccess;
00158             }
00159         }
00160         try
00161         {
00162             SP_SET( pFrame, new Frame( PayloadSize));
00163             if( SP_ISNULL( pFrame) ) // in case we find a not throwing new
00164             {
00165                 LOG_FREE_TEXT("error allocating frame");
00166                 return VmbErrorResources;
00167             }
00168         }
00169         catch(...)
00170         {
00171             LOG_FREE_TEXT("error allocating frame");
00172             return VmbErrorResources;
00173         }
00174         return VmbErrorSuccess;
00175     }
00176 public:
00177     // construct helper from camera
00178     AcquireImageHelper(Camera &Cam)
00179         : m_Camera( Cam)
00180     {}
00181     // destroy will tear all down
00182     ~AcquireImageHelper()
00183     {
00184         TearDown();
00185     }
00186     //
00187     // Method:: AnnounceFrames
00188     //
00189     // Purpose: helper to announce a list of frames to the camera.
00190     //
00191     // Parameters:
00192     //
00193     // [in]        Camera              Camera to announce the frames too
00194     // [in,out]    pFrames             storage for frame pointer, if they are NULL or have no sufficient space the frames will be created
00195     // [in]        nFrameCount         number of frame pointers in pFrames
00196     // [in]        nPayloadSize        payload size for one frame
00197     // [out]       nFramesAnnounced    returns number of successful announced frames
00198     // Returns:
00199     //
00200     // the first error that occurred or VmbErrorSuccess if non occurred 
00201     // Details: note the function will try to construct and announce nFrameCount frames t o the camera, even if some of them can not be created or announced, only if nFramesAnnounced == 0 the function was unsuccessful
00202     //
00203     static VmbErrorType AnnounceFrames(Camera &Camera, FramePtr *pFrames, VmbUint32_t nFrameCount, VmbInt64_t nPayloadSize, VmbUint32_t &nFramesAnnounced)
00204     {
00205         VmbErrorType    Result  = VmbErrorSuccess;
00206         nFramesAnnounced        = 0;
00207         for( VmbUint32_t FrameNumber= 0; FrameNumber < nFrameCount; ++FrameNumber)
00208         {
00209             VmbErrorType LocalResult = SetupFrame( pFrames[ FrameNumber ], nPayloadSize);         //< try to init frame
00210             if( VmbErrorSuccess == LocalResult)
00211             {
00212                 LocalResult = Camera.AnnounceFrame( pFrames[ FrameNumber] );       //< announce frame if successful initialized
00213                 if ( VmbErrorSuccess == LocalResult )
00214                 {
00215                     ++nFramesAnnounced;
00216                 }
00217                 else
00218                 {
00219                     std::stringstream strMsg("Could only successfully announce ");
00220                     strMsg << nFramesAnnounced << " of " <<  nFrameCount  << " frames. Will continue with queuing those.";
00221                     LOG_FREE_TEXT( strMsg.str() );
00222                 }
00223             }
00224             if( VmbErrorSuccess == Result )
00225             {
00226                 Result = LocalResult;
00227             }
00228         }
00229         return Result;
00230     }
00231     //
00232     // Method: AnnounceFrames
00233     //
00234     // Purpose: announce a FramePtrVector to the camera.
00235     //
00236     // Parameters:
00237     // [in]        Camera          camera to announce the frames to
00238     // [in,out]    Frames          vector of frame pointers that will contain the announced frames on return, can be empty on input
00239     // [in]        nBufferCount    number of frames to announce, if nBufferCount > Frames.size() on return, some frames could not be announced
00240     // [in]        nPayloadSize    frame payload size
00241     // [in]        Observer        observer to attach to frames
00242     //
00243     static VmbErrorType AnnounceFrames(Camera &Camera, FramePtrVector &Frames, VmbUint32_t nBufferCount, VmbInt64_t nPayloadSize, const IFrameObserverPtr& Observer)
00244     {
00245         try
00246         {
00247             Frames.reserve( nBufferCount);
00248         }
00249         catch(...)
00250         {
00251             LOG_FREE_TEXT("could not allocate frames");
00252             return VmbErrorResources;
00253         }
00254         VmbErrorType Result = VmbErrorSuccess;
00255         for( VmbUint32_t i=0; i < nBufferCount; ++i)
00256         {
00257             FramePtr tmpFrame;
00258             VmbErrorType LocalResult = SetupFrame( tmpFrame, nPayloadSize );
00259             if( ! SP_ISNULL( tmpFrame) )
00260             {
00261                 LocalResult = SP_ACCESS( tmpFrame)->RegisterObserver( Observer );
00262                 if( VmbErrorSuccess == LocalResult )
00263                 {
00264                     LocalResult = Camera.AnnounceFrame( tmpFrame);
00265                     if( VmbErrorSuccess == LocalResult )
00266                     {
00267                         Frames.push_back( tmpFrame );
00268                     }
00269                     else
00270                     {
00271                         LOG_FREE_TEXT("could not announce frame");
00272                     }
00273                 }
00274                 else
00275                 {
00276                     LOG_FREE_TEXT("could not register frame observer");
00277                 }
00278             }
00279             else
00280             {
00281                 LOG_FREE_TEXT("could not allocate frame");
00282             }
00283             if( VmbErrorSuccess == Result)
00284             {
00285                 Result = LocalResult;
00286             }
00287         }
00288         return Result;
00289     }
00290     //
00291     // Method: Prepare
00292     //
00293     // Purpose: prepare image grab for single image.
00294     //
00295     // Parameters:
00296     //
00297     // [in,out]    pFrame          frame to hold the image
00298     // [in]        PayloadSize     frame payload size
00299     //
00300     VmbErrorType Prepare(FramePtr &pFrame, VmbInt64_t PayloadSize)
00301     {
00302         VmbErrorType res;
00303         res = SetupFrame( pFrame, PayloadSize);                     // init frame if necessary
00304         if ( VmbErrorSuccess != res )
00305         {
00306             LOG_FREE_TEXT("Could not create frame");
00307             return res;
00308         }
00309         res = m_Camera.AnnounceFrame( pFrame );                     // announce frame to camera
00310         if ( VmbErrorSuccess != res )
00311         {
00312             LOG_FREE_TEXT("Could not Announce frame");
00313             return res;
00314         }
00315         m_Tasks.push_back( RevokeFrame);                            // if successful announced we need to revoke frames
00316         res = m_Camera.StartCapture();                              // start capture logic
00317         if ( VmbErrorSuccess != res )
00318         {
00319             LOG_FREE_TEXT( "Could not Start Capture" );
00320             return res;
00321         }
00322         m_Tasks.push_back( EndCapture);                             // if capture logic is started we need end capture task
00323         res = m_Camera.QueueFrame( pFrame );                        // queue frame in processing logic
00324         if ( VmbErrorSuccess != res )
00325         {
00326             LOG_FREE_TEXT( "Could not queue frame");
00327             return res;
00328         }
00329         m_Tasks.pop_back();
00330         m_Tasks.push_back( FlushQueue);                             // if frame queued we need flush queue task
00331         m_Tasks.push_back( EndCapture);
00332         FeaturePtr pFeature;
00333         res = RunFeatureCommand( m_Camera, "AcquisitionStart" );    // start acquisition
00334         if ( VmbErrorSuccess != res )
00335         {
00336             LOG_FREE_TEXT("Could not run command AcquisitionStart");
00337             return res;
00338         }
00339         m_Tasks.push_back( AcquisitionStop);
00340         return res;
00341     }
00342     // Method: Prepare
00343     //
00344     // Purpose: prepare image acquisition for multiple frames.
00345     //
00346     // Parameters:
00347     //
00348     // [in,out]     pFrames         non NULL pointer to field of frame pointers (can point to NULL) that hold the captured images
00349     // [in]         nFrameCount     number of frames in vector
00350     // [in]         nPayLoadSize    payload size
00351     // [out]        nFramesQueued   returns number of successful queued images
00352     //
00353     VmbErrorType Prepare(FramePtr *pFrames, VmbUint32_t nFrameCount, VmbInt64_t nPayloadSize, VmbUint32_t &nFramesQueued )
00354     {
00355         if( NULL == pFrames || 0 == nFrameCount)                            // sanity check
00356         {
00357             return VmbErrorBadParameter;
00358         }
00359         nFramesQueued = 0;
00360         VmbErrorType    Result          = VmbErrorSuccess;
00361         VmbUint32_t     FramesAnnounced = 0;
00362         Result = AnnounceFrames( m_Camera, pFrames, nFrameCount, nPayloadSize, FramesAnnounced);
00363         if( 0 == FramesAnnounced)
00364         {
00365             return Result;
00366         }
00367         m_Tasks.push_back( RevokeFrame);                                    // add cleanup task for announced frames
00368         Result = m_Camera.StartCapture();                                   // start capture logic
00369         if ( VmbErrorSuccess != Result)
00370         {
00371             LOG_FREE_TEXT( "Could not Start Capture" );
00372             return Result;
00373         }
00374         m_Tasks.push_back( EndCapture);                                     // add cleanup task to end capture
00375         for( VmbUint32_t FrameNumber = 0; FrameNumber < FramesAnnounced; ++FrameNumber)
00376         {
00377             Result = m_Camera.QueueFrame( pFrames[ FrameNumber ] );         // try queuing frame
00378             if ( VmbErrorSuccess != Result )
00379             {
00380                 std::stringstream strMsg("Could only successfully queue ");
00381                 strMsg << nFramesQueued << " of " << nFrameCount << " frames. Will continue with filling those.";
00382                 LOG_FREE_TEXT( strMsg.str() );
00383                 break;
00384             }
00385             else
00386             {
00387                 ++nFramesQueued;
00388             }
00389         }
00390         if( 0 == nFramesQueued) // we cannot capture anything, there are no frames queued
00391         {
00392             return Result;
00393         }
00394         m_Tasks.pop_back();
00395         m_Tasks.push_back( FlushQueue);                         // if any frame was queued we need a cleanup task
00396         m_Tasks.push_back( EndCapture);
00397         FeaturePtr pFeature;
00398         Result = RunFeatureCommand( m_Camera, "AcquisitionStart" ); // start acquisition logic
00399         if ( VmbErrorSuccess != Result )
00400         {
00401             LOG_FREE_TEXT("Could not run command AcquisitionStart");
00402             return Result;
00403         }
00404         m_Tasks.push_back( AcquisitionStop);
00405         return Result;
00406     }
00407     //
00408     // Method: TearDown
00409     //
00410     // Purpose: free all acquired resources.
00411     //
00412     VmbErrorType TearDown()
00413     {
00414         VmbErrorType res = VmbErrorSuccess;
00415         while( ! m_Tasks.empty() )
00416         {
00417             VmbErrorType local_result = VmbErrorSuccess;
00418             switch( GetTask() )
00419             {
00420             case AcquisitionStop:
00421                     local_result = RunFeatureCommand(m_Camera, "AcquisitionStop");
00422                     if( VmbErrorSuccess != local_result)
00423                     {
00424                         LOG_FREE_TEXT("Could not run command AquireStop");
00425                     }
00426                     break;
00427             case EndCapture:
00428                     local_result = m_Camera.EndCapture();
00429                     if( VmbErrorSuccess != local_result)
00430                     {
00431                         LOG_FREE_TEXT("Could Not run EndCapture");
00432                     }
00433                     break;
00434             case FlushQueue:
00435                     local_result = m_Camera.FlushQueue();
00436                     if( VmbErrorSuccess != local_result)
00437                     {
00438                         LOG_FREE_TEXT("Could not run Flush Queue command");
00439                     }
00440                     break;
00441             case RevokeFrame:
00442                     local_result = m_Camera.RevokeAllFrames();
00443                     if( VmbErrorSuccess != local_result)
00444                     {
00445                         LOG_FREE_TEXT("Could Not Run Revoke Frames command");
00446                     }
00447                     break;
00448             }
00449             if( VmbErrorSuccess == res)
00450                 res = local_result;
00451         }
00452         return res;
00453     }
00454 };
00455 
00456 
00457 struct Camera::Impl
00458 {
00459     // Copy of camera infos
00460     struct CameraInfo
00461     {
00462         std::string     cameraIdString;             // Unique identifier for each camera
00463         std::string     cameraIdStringGigE;         // GigE cameras can also be opened by IP or MAC address
00464         std::string     cameraName;                 // Name of the camera
00465         std::string     modelName;                  // Model name
00466         std::string     serialString;               // Serial number
00467         std::string     interfaceIdString;          // Unique value for each interface or bus
00468     } m_cameraInfo;
00469 
00470     VmbInterfaceType m_eInterfaceType;              // The type of the interface the camera is connected to
00471 
00472     LockableVector<FrameHandlerPtr> m_frameHandlers;
00473     ConditionHelper                 m_conditionHelper;
00474 
00475     MutexPtr                        m_pQueueFrameMutex;
00476     bool                            m_bAllowQueueFrame;
00477 
00478     VmbErrorType AppendFrameToVector( const FramePtr &frame );
00479 };
00480 
00481 Camera::Camera()
00482 {
00483     // No default ctor
00484 }
00485 
00486 Camera::Camera( const Camera& )
00487 {
00488     // No copy ctor
00489 }
00490 
00491 Camera& Camera::operator=( const Camera& )
00492 {
00493     // No assignment operator
00494     return *this;
00495 }
00496 
00497 Camera::Camera( const char *pID,
00498                 const char *pName,
00499                 const char *pModel,
00500                 const char *pSerialNumber,
00501                 const char *pInterfaceID,
00502                 VmbInterfaceType eInterfaceType )
00503     :   m_pImpl( new Impl() )
00504     ,   m_persistType( -1 )
00505     ,   m_maxIterations( -1 )
00506     ,   m_loggingLevel( -1 )
00507 {
00508     m_pImpl->m_cameraInfo.cameraIdString.assign( pID ? pID : "" );
00509     // TODO: Remove this with interface change
00510     const char* pIDGigE = strstr( pID, AVT_IP_OR_MAC_ADDRESS);
00511     if ( pIDGigE )
00512     {
00513         m_pImpl->m_cameraInfo.cameraIdStringGigE.assign( pIDGigE );
00514         m_pImpl->m_cameraInfo.cameraIdStringGigE.erase( 0, strlen( AVT_IP_OR_MAC_ADDRESS ));
00515         m_pImpl->m_cameraInfo.cameraIdString.erase( m_pImpl->m_cameraInfo.cameraIdString.find( AVT_IP_OR_MAC_ADDRESS ), std::string::npos );
00516     }
00517     m_pImpl->m_cameraInfo.cameraName.assign( pName ? pName : "" );
00518     m_pImpl->m_cameraInfo.interfaceIdString.assign( pInterfaceID ? pInterfaceID : "" );
00519     m_pImpl->m_cameraInfo.modelName.assign( pModel ? pModel : "" );
00520     m_pImpl->m_cameraInfo.serialString.assign( pSerialNumber ? pSerialNumber : "" );
00521     m_pImpl->m_eInterfaceType = eInterfaceType;
00522     m_pImpl->m_bAllowQueueFrame = true;
00523     SP_SET( m_pImpl->m_pQueueFrameMutex, new Mutex );
00524 }
00525 
00526 Camera::~Camera()
00527 {
00528     Close();
00529 
00530     delete m_pImpl;
00531 }
00532 
00533 VmbErrorType Camera::Open( VmbAccessModeType eAccessMode )
00534 {
00535     VmbError_t res;
00536     VmbHandle_t hHandle;
00537 
00538     if ( false == m_pImpl->m_cameraInfo.cameraIdStringGigE.empty() )
00539     {
00540         res = VmbCameraOpen( m_pImpl->m_cameraInfo.cameraIdStringGigE.c_str(), (VmbAccessMode_t)eAccessMode, &hHandle );        
00541     }
00542     else
00543     {
00544         res = VmbCameraOpen( m_pImpl->m_cameraInfo.cameraIdString.c_str(), (VmbAccessMode_t)eAccessMode, &hHandle );
00545     }
00546 
00547     if ( VmbErrorSuccess == res )
00548     {
00549         SetHandle( hHandle );
00550     }
00551     
00552     return (VmbErrorType)res;
00553 }
00554 
00555 VmbErrorType Camera::Close()
00556 {
00557     VmbError_t res = VmbErrorSuccess;
00558 
00559     if ( NULL != GetHandle() )
00560     {
00561         if (    0 < m_pImpl->m_frameHandlers.Vector.size()
00562              && (   VmbErrorSuccess != EndCapture()
00563                  || VmbErrorSuccess != FlushQueue()
00564                  || VmbErrorSuccess != RevokeAllFrames()) )
00565         {
00566             // Do some logging
00567             LOG_FREE_TEXT( "Could not successfully revoke all frames")
00568         }
00569 
00570         Reset();
00571 
00572         res = VmbCameraClose( GetHandle() );
00573 
00574         RevokeHandle();
00575     }
00576 
00577     return (VmbErrorType)res;
00578 }
00579 
00580 VmbErrorType Camera::GetID( char * const pStrID, VmbUint32_t &rnLength ) const
00581 {
00582     VmbErrorType res;
00583 
00584     if ( NULL == pStrID )
00585     {
00586         rnLength = (VmbUint32_t)m_pImpl->m_cameraInfo.cameraIdString.length();
00587         res = VmbErrorSuccess;
00588     }
00589     else if ( m_pImpl->m_cameraInfo.cameraIdString.length() <= rnLength )
00590     {
00591         std::copy( m_pImpl->m_cameraInfo.cameraIdString.begin(), m_pImpl->m_cameraInfo.cameraIdString.end(), pStrID );
00592         pStrID[m_pImpl->m_cameraInfo.cameraIdString.length()] = '\0';
00593         rnLength = (VmbUint32_t)m_pImpl->m_cameraInfo.cameraIdString.length();
00594         res = VmbErrorSuccess;
00595     }
00596     else
00597     {
00598         res = VmbErrorMoreData;
00599     }
00600 
00601     return res;
00602 }
00603 
00604 VmbErrorType Camera::GetName( char * const pStrName, VmbUint32_t &rnLength ) const
00605 {
00606     VmbErrorType res;
00607 
00608     if ( NULL == pStrName )
00609     {
00610         rnLength = (VmbUint32_t)m_pImpl->m_cameraInfo.cameraName.length();
00611         res = VmbErrorSuccess;
00612     }
00613     else if ( m_pImpl->m_cameraInfo.cameraName.length() <= rnLength )
00614     {
00615         std::copy( m_pImpl->m_cameraInfo.cameraName.begin(), m_pImpl->m_cameraInfo.cameraName.end(), pStrName );
00616         pStrName[m_pImpl->m_cameraInfo.cameraName.length()] = '\0';
00617         rnLength = (VmbUint32_t)m_pImpl->m_cameraInfo.cameraName.length();
00618         res = VmbErrorSuccess;
00619     }
00620     else
00621     {
00622         res = VmbErrorMoreData;
00623     }
00624 
00625     return res;
00626 }
00627 
00628 VmbErrorType Camera::GetModel( char * const pStrModel, VmbUint32_t &rnLength ) const
00629 {
00630     VmbErrorType res;
00631 
00632     if ( NULL == pStrModel )
00633     {
00634         rnLength = (VmbUint32_t)m_pImpl->m_cameraInfo.modelName.length();
00635         res = VmbErrorSuccess;
00636     }
00637     else if ( m_pImpl->m_cameraInfo.modelName.length() <= rnLength )
00638     {
00639         std::copy( m_pImpl->m_cameraInfo.modelName.begin(), m_pImpl->m_cameraInfo.modelName.end(), pStrModel );
00640         pStrModel[m_pImpl->m_cameraInfo.modelName.length()] = '\0';
00641         rnLength = (VmbUint32_t)m_pImpl->m_cameraInfo.modelName.length();
00642         res = VmbErrorSuccess;
00643     }
00644     else
00645     {
00646         res = VmbErrorMoreData;
00647     }
00648 
00649     return res;
00650 }
00651 
00652 VmbErrorType Camera::GetSerialNumber( char * const pStrSerial, VmbUint32_t &rnLength ) const
00653 {
00654     VmbErrorType res;
00655 
00656     if ( NULL == pStrSerial )
00657     {
00658         rnLength = (VmbUint32_t)m_pImpl->m_cameraInfo.serialString.length();
00659         res = VmbErrorSuccess;
00660     }
00661     else if ( m_pImpl->m_cameraInfo.serialString.length() <= rnLength )
00662     {
00663         std::copy( m_pImpl->m_cameraInfo.serialString.begin(), m_pImpl->m_cameraInfo.serialString.end(), pStrSerial );
00664         pStrSerial[m_pImpl->m_cameraInfo.serialString.length()] = '\0';
00665         rnLength = (VmbUint32_t)m_pImpl->m_cameraInfo.serialString.length();
00666         res = VmbErrorSuccess;
00667     }
00668     else
00669     {
00670         res = VmbErrorMoreData;
00671     }
00672 
00673     return res;
00674 }
00675 
00676 VmbErrorType Camera::GetInterfaceID( char * const pStrInterfaceID, VmbUint32_t &rnLength ) const
00677 {    
00678     VmbErrorType res;
00679 
00680     if ( NULL == pStrInterfaceID )
00681     {
00682         rnLength = (VmbUint32_t)m_pImpl->m_cameraInfo.interfaceIdString.length();
00683         res = VmbErrorSuccess;
00684     }
00685     else if ( m_pImpl->m_cameraInfo.interfaceIdString.length() <= rnLength )
00686     {
00687         std::copy( m_pImpl->m_cameraInfo.interfaceIdString.begin(), m_pImpl->m_cameraInfo.interfaceIdString.end(), pStrInterfaceID );
00688         pStrInterfaceID[m_pImpl->m_cameraInfo.interfaceIdString.length()] = '\0';
00689         rnLength = (VmbUint32_t)m_pImpl->m_cameraInfo.interfaceIdString.length();
00690         res = VmbErrorSuccess;
00691     }
00692     else
00693     {
00694         res = VmbErrorMoreData;
00695     }
00696 
00697     return res;
00698 }
00699 
00700 VmbErrorType Camera::GetInterfaceType( VmbInterfaceType &reInterfaceType ) const
00701 {
00702     reInterfaceType = m_pImpl->m_eInterfaceType;
00703 
00704     return VmbErrorSuccess;
00705 }
00706 
00707 VmbErrorType Camera::GetPermittedAccess( VmbAccessModeType &rePermittedAccess ) const
00708 {
00709     VmbError_t res;
00710     VmbCameraInfo_t info;
00711 
00712     if ( false == m_pImpl->m_cameraInfo.cameraIdStringGigE.empty() )
00713     {
00714         res = VmbCameraInfoQuery( m_pImpl->m_cameraInfo.cameraIdStringGigE.c_str(), &info, sizeof( VmbCameraInfo_t ));
00715     }
00716     else
00717     {
00718         res = VmbCameraInfoQuery( m_pImpl->m_cameraInfo.cameraIdString.c_str(), &info, sizeof( VmbCameraInfo_t ));
00719     }
00720 
00721     if ( VmbErrorSuccess == res )
00722     {
00723         rePermittedAccess = (VmbAccessModeType)info.permittedAccess;
00724     }
00725 
00726     return (VmbErrorType)res;
00727 }
00728 
00729 VmbErrorType Camera::ReadRegisters( const VmbUint64_t *pAddressArray, VmbUint32_t nAddressSize, VmbUint64_t *pDataArray, VmbUint32_t *pCompletedReads ) const
00730 {
00731     return static_cast<VmbErrorType>( VmbRegistersRead( GetHandle(), nAddressSize, pAddressArray, pDataArray, pCompletedReads ) );
00732 }
00733 
00734 VmbErrorType Camera::WriteRegisters( const VmbUint64_t *pAddressArray, VmbUint32_t nAddressSize, const VmbUint64_t *pDataArray, VmbUint32_t *pCompletedWrites )
00735 {
00736     return static_cast<VmbErrorType>( VmbRegistersWrite( GetHandle(), nAddressSize, pAddressArray, pDataArray, pCompletedWrites ) );
00737 }
00738 
00739 VmbErrorType Camera::ReadMemory( const VmbUint64_t address, VmbUchar_t *pBuffer, VmbUint32_t nBufferSize, VmbUint32_t *pSizeComplete ) const
00740 {
00741     return static_cast<VmbErrorType>( VmbMemoryRead( GetHandle(), address, nBufferSize, (char*)pBuffer, pSizeComplete ) );
00742 }
00743 
00744 VmbErrorType Camera::WriteMemory( const VmbUint64_t address, const VmbUchar_t *pBuffer, VmbUint32_t nBufferSize, VmbUint32_t *pSizeComplete )
00745 {
00746     return static_cast<VmbErrorType>( VmbMemoryWrite( GetHandle(), address, nBufferSize, (char *)pBuffer, pSizeComplete ) );
00747 }
00748 
00749 //Get one image synchronously.
00750 VmbErrorType Camera::AcquireSingleImage( FramePtr &rFrame, VmbUint32_t nTimeout )
00751 {
00752     VmbErrorType    res;
00753     VmbInt64_t      PayloadSize;
00754     FeaturePtr      pFeature;
00755 
00756     res = GetFeatureValueInt( *this, "PayloadSize", PayloadSize );
00757     if ( VmbErrorSuccess == res )
00758     {
00759         AcquireImageHelper AcquireHelper( *this );
00760         res = AcquireHelper.Prepare( rFrame, PayloadSize );
00761         if ( VmbErrorSuccess == res )
00762         {
00763             res = (VmbErrorType)VmbCaptureFrameWait( GetHandle(), &(SP_ACCESS( rFrame )->m_pImpl->m_frame), nTimeout );
00764             if ( VmbErrorSuccess != res )
00765             {
00766                 LOG_FREE_TEXT( "Could not acquire single image." )
00767             }
00768         }
00769         else
00770         {
00771             LOG_FREE_TEXT( "Preparing image acquisition failed." );
00772         }
00773         VmbErrorType local_result = AcquireHelper.TearDown();
00774         if( VmbErrorSuccess != local_result )
00775         {
00776             LOG_FREE_TEXT( "Tear down capture logic failed." )
00777             if( VmbErrorSuccess == res)
00778             {
00779                 res = local_result;
00780             }
00781         }
00782     }
00783     else
00784     {
00785         LOG_FREE_TEXT( "Could not get payload size" );
00786     }
00787 
00788     return res;
00789 }
00790 
00791 VmbErrorType Camera::AcquireMultipleImages( FramePtr *pFrames, VmbUint32_t nSize, VmbUint32_t nTimeout, VmbUint32_t *pNumFramesCompleted )
00792 {
00793     VmbErrorType res = VmbErrorBadParameter;
00794 
00795     if (    NULL == pFrames
00796          || 0 == nSize )
00797     {
00798         return res;
00799     }
00800 
00801     if ( NULL != pNumFramesCompleted )
00802     {
00803         *pNumFramesCompleted = 0;
00804     }
00805 
00806     VmbInt64_t nPayloadSize;
00807     FeaturePtr pFeature;
00808 
00809     res = GetFeatureValueInt( *this, "PayloadSize", nPayloadSize );
00810     if ( VmbErrorSuccess == res )
00811     {
00812         AcquireImageHelper AquireHelper( *this );
00813         VmbUint32_t nFramesQueued = 0;
00814         res = AquireHelper.Prepare( pFrames, nSize, nPayloadSize, nFramesQueued);
00815 
00816         if ( VmbErrorSuccess == res )
00817         {
00818             for ( VmbUint32_t nFrameCount = 0; nFrameCount <nFramesQueued; ++ nFrameCount )
00819             {
00820                 res = (VmbErrorType)VmbCaptureFrameWait( GetHandle(), &(SP_ACCESS( pFrames[nFrameCount] )->m_pImpl->m_frame), nTimeout );
00821                 if ( VmbErrorSuccess != res )
00822                 {
00823                     std::stringstream strMsg("Could only successfully fill ");
00824                     strMsg << nFrameCount-1 << " of " << nSize << " frames. Will stop acquisition now.";
00825                     LOG_FREE_TEXT( strMsg.str() );
00826                     break;
00827                 }
00828                 else if ( NULL !=  pNumFramesCompleted )
00829                 {
00830                     ++(*pNumFramesCompleted);
00831                 }
00832             }
00833             VmbErrorType local_res = AquireHelper.TearDown();
00834             if( VmbErrorSuccess == res)
00835             {
00836                 res = local_res;
00837             }
00838         }
00839         else
00840         {
00841             LOG_FREE_TEXT( "Could not start capture" )
00842         }
00843     }
00844     else
00845     {
00846         LOG_FREE_TEXT( "Could not get feature PayloadSize");
00847     }
00848 
00849     return res;
00850 }
00851 
00852 VmbErrorType Camera::StartContinuousImageAcquisition( int nBufferCount, const IFrameObserverPtr &rObserver )
00853 {
00854     VmbErrorType        res;
00855     FramePtrVector      Frames;
00856     VmbInt64_t          nPayloadSize;
00857 
00858     res = GetFeatureValueInt(*this,"PayloadSize", nPayloadSize );
00859     if ( VmbErrorSuccess == res )
00860     {
00861         res = AcquireImageHelper::AnnounceFrames( *this, Frames, nBufferCount, nPayloadSize, rObserver );
00862         if( Frames.empty() )
00863         {
00864             return res;
00865         }
00866         res = StartCapture();
00867         if ( VmbErrorSuccess == res )
00868         {
00869             VmbUint32_t FramesQueued = 0;
00870             for (   size_t FrameNumber = 0; FrameNumber < Frames.size(); ++ FrameNumber )
00871             {
00872                 VmbErrorType LocalResult =  QueueFrame( Frames[ FrameNumber] );
00873                 if ( VmbErrorSuccess == LocalResult)
00874                 {
00875                     ++FramesQueued;
00876                 }
00877                 else
00878                 {
00879                     LOG_FREE_TEXT( "Could not queue frame" )
00880                 }
00881                 if( VmbErrorSuccess == res)
00882                 {
00883                     res = LocalResult;
00884                 }
00885             }
00886             if( 0 != FramesQueued)
00887             {
00888                 res = RunFeatureCommand(*this, "AcquisitionStart" );
00889                 if ( VmbErrorSuccess != res )
00890                 {
00891                     EndCapture();
00892                     FlushQueue();
00893                     RevokeAllFrames();
00894                     LOG_FREE_TEXT( "Could not start acquisition" )
00895                     return res;
00896                 }
00897 
00898             }
00899             else
00900             {
00901                 EndCapture();
00902                 RevokeAllFrames();
00903                 LOG_FREE_TEXT( "Could not queue frames" )
00904                 return res;
00905             }
00906 
00907         }
00908         else
00909         {
00910             RevokeAllFrames();
00911             LOG_FREE_TEXT( "Could not start capturing" )
00912         }
00913     }
00914     else
00915     {
00916         LOG_FREE_TEXT( "Could not get feature PayloadSize" )
00917     }
00918 
00919     return res;
00920 }
00921 
00922 VmbErrorType Camera::StopContinuousImageAcquisition()
00923 {
00924     VmbErrorType    res;
00925     FeaturePtr      pFeature;
00926 
00927     // Prevent queuing of new frames while stopping
00928     MutexGuard guard( m_pImpl->m_pQueueFrameMutex );
00929     m_pImpl->m_bAllowQueueFrame = false;
00930     guard.Release();
00931 
00932     res = RunFeatureCommand( *this, "AcquisitionStop" );
00933     if ( VmbErrorSuccess != res )
00934     {
00935         LOG_FREE_TEXT( "Could not run feature AcquisitionStop" )
00936     }
00937 
00938     res = EndCapture();
00939     if ( VmbErrorSuccess == res )
00940     {
00941         res = FlushQueue();
00942         if( VmbErrorSuccess != res)
00943         {
00944             LOG_FREE_TEXT( "Could not flush queue" )
00945         }
00946         res = RevokeAllFrames();
00947         if ( VmbErrorSuccess != res )
00948         {
00949             LOG_FREE_TEXT( "Could not revoke frames" )
00950         }
00951     }
00952     else
00953     {
00954         LOG_FREE_TEXT("Could not stop capture, unable to revoke frames")
00955     }
00956 
00957     guard.Protect( m_pImpl->m_pQueueFrameMutex );
00958     m_pImpl->m_bAllowQueueFrame = true;
00959 
00960     return res;
00961 }
00962 
00963 VmbErrorType Camera::AnnounceFrame( const FramePtr &frame ) 
00964 {
00965     if ( SP_ISNULL( frame ))
00966     {
00967         return VmbErrorBadParameter;
00968     }
00969 
00970     if (    true == SP_ACCESS( frame )->m_pImpl->m_bAlreadyAnnounced
00971          || true == SP_ACCESS( frame )->m_pImpl->m_bAlreadyQueued )
00972     {
00973         return VmbErrorInvalidCall;
00974     }
00975 
00976     VmbError_t res = VmbFrameAnnounce( GetHandle(), &(SP_ACCESS( frame )->m_pImpl->m_frame), sizeof SP_ACCESS( frame )->m_pImpl->m_frame );
00977     
00978     if ( VmbErrorSuccess == res )
00979     {
00980         // Begin write lock frame handler list
00981         if ( true == m_pImpl->m_conditionHelper.EnterWriteLock( m_pImpl->m_frameHandlers ))
00982         {
00983             res = m_pImpl->AppendFrameToVector( frame ) ;
00984             if( VmbErrorSuccess == res )
00985             {
00986                 SP_ACCESS( frame )->m_pImpl->m_bAlreadyAnnounced = true;
00987             }
00988             else
00989             {
00990                 LOG_FREE_TEXT("could not append frame to internal vector");
00991             }
00992             // End write lock frame handler list
00993             m_pImpl->m_conditionHelper.ExitWriteLock( m_pImpl->m_frameHandlers );
00994         }
00995         else
00996         {
00997             LOG_FREE_TEXT( "Could not lock announced frame queue for appending frame." );
00998             res = VmbErrorResources;
00999         }
01000     }
01001 
01002     return static_cast<VmbErrorType>( res );
01003 }
01004 
01005 VmbErrorType Camera::RevokeFrame( const FramePtr &frame )
01006 {
01007     if ( SP_ISNULL( frame ))
01008     {
01009         return VmbErrorBadParameter;
01010     }
01011 
01012     VmbError_t res = VmbFrameRevoke( GetHandle(), &(SP_ACCESS( frame )->m_pImpl->m_frame) );
01013 
01014     if ( VmbErrorSuccess == res )
01015     {
01016         // Begin (exclusive) write lock frame handler list
01017         if ( true == m_pImpl->m_conditionHelper.EnterWriteLock( m_pImpl->m_frameHandlers, true ))
01018         {
01019             // Dequeue, revoke and delete frame
01020             for(    FrameHandlerPtrVector::iterator iter = m_pImpl->m_frameHandlers.Vector.begin();
01021                     m_pImpl->m_frameHandlers.Vector.end() != iter;)
01022             {
01023                 // Begin exclusive write lock frame handler
01024                 if ( true == SP_ACCESS(( *iter ))->EnterWriteLock( true ))
01025                 {
01026                     if ( SP_ISEQUAL( frame, SP_ACCESS(( *iter ))->GetFrame() ))
01027                     {
01028                         SP_ACCESS( frame )->m_pImpl->m_frame.context[FRAME_HDL] = NULL;
01029                         SP_ACCESS( frame )->m_pImpl->m_bAlreadyQueued = false;
01030                         SP_ACCESS( frame )->m_pImpl->m_bAlreadyAnnounced = false;
01031                         // End exclusive write lock frame handler
01032                         SP_ACCESS(( *iter ))->ExitWriteLock();
01033                         iter = m_pImpl->m_frameHandlers.Vector.erase( iter );
01034                         return VmbErrorSuccess;
01035                     }
01036                     else
01037                     {
01038                         // End exclusive write lock frame handler
01039                         SP_ACCESS(( *iter ))->ExitWriteLock();
01040                         
01041                         ++iter;
01042                     }
01043                 }
01044             }
01045 
01046             // End (exclusive) write lock frame handler list
01047             m_pImpl->m_conditionHelper.ExitWriteLock( m_pImpl->m_frameHandlers );
01048         }
01049         else
01050         {
01051             LOG_FREE_TEXT( "Could not lock announced frame queue for removing frame." );
01052             res = VmbErrorResources;
01053         }
01054     }
01055     else
01056     {
01057         LOG_FREE_TEXT( "Could not revoke frames" )
01058     }
01059 
01060     return (VmbErrorType)res;
01061 }
01062 
01063 VmbErrorType Camera::RevokeAllFrames() 
01064 {
01065     VmbError_t res;
01066 
01067     res = VmbFrameRevokeAll( GetHandle() );
01068 
01069     if ( VmbErrorSuccess == res )
01070     {
01071         // Begin (exclusive) write lock frame handler list
01072         if ( true == m_pImpl->m_conditionHelper.EnterWriteLock( m_pImpl->m_frameHandlers, true ))
01073         {
01074             // Dequeue, revoke and delete frames
01075             for (   FrameHandlerPtrVector::iterator iter = m_pImpl->m_frameHandlers.Vector.begin();
01076                     m_pImpl->m_frameHandlers.Vector.end() != iter;
01077                     ++iter )
01078             {
01079                 // Begin exclusive write lock frame handler
01080                 if ( true == SP_ACCESS(( *iter ))->EnterWriteLock( true ))
01081                 {
01082                     SP_ACCESS( SP_ACCESS(( *iter ))->GetFrame() )->m_pImpl->m_frame.context[FRAME_HDL] = NULL;
01083                     SP_ACCESS( SP_ACCESS(( *iter ))->GetFrame() )->m_pImpl->m_bAlreadyQueued = false;
01084                     SP_ACCESS (SP_ACCESS(( *iter ))->GetFrame() )->m_pImpl->m_bAlreadyAnnounced = false;
01085                     // End exclusive write lock frame handler
01086                     SP_ACCESS(( *iter ))->ExitWriteLock();
01087                 }
01088                 else
01089                 {
01090                     LOG_FREE_TEXT( "Could not lock frame handler.")
01091                 }
01092             }
01093 
01094             m_pImpl->m_frameHandlers.Vector.clear();
01095             
01096             // End exclusive write lock frame handler list
01097             m_pImpl->m_conditionHelper.ExitWriteLock( m_pImpl->m_frameHandlers );
01098         }
01099         else
01100         {
01101             LOG_FREE_TEXT( "Could not lock frame handler list.")
01102         }
01103     }
01104 
01105     return (VmbErrorType)res;
01106 }
01107 
01108 VmbErrorType Camera::QueueFrame( const FramePtr &frame )
01109 {
01110     if ( SP_ISNULL( frame ))
01111     {
01112         return VmbErrorBadParameter;
01113     }
01114 
01115     MutexGuard guard( m_pImpl->m_pQueueFrameMutex );
01116     if ( false == m_pImpl->m_bAllowQueueFrame )
01117     {
01118         LOG_FREE_TEXT( "Queuing of new frames is not possible while flushing and revoking the currently queued frames." );
01119         return VmbErrorInvalidCall;
01120     }
01121 
01122     // HINT: The same frame cannot be queued twice (VmbErrorOther)
01123     VmbError_t res = VmbCaptureFrameQueue( GetHandle(), &(SP_ACCESS( frame )->m_pImpl->m_frame), FrameHandler::FrameDoneCallback );
01124 
01125     if (    VmbErrorSuccess == res
01126          && false == SP_ACCESS( frame )->m_pImpl->m_bAlreadyQueued )
01127     {
01128         if ( false == SP_ACCESS( frame )->m_pImpl->m_bAlreadyAnnounced )
01129         {
01130             // Begin write lock frame handler list
01131             if ( true == m_pImpl->m_conditionHelper.EnterWriteLock( m_pImpl->m_frameHandlers ))
01132             {
01133                 m_pImpl->AppendFrameToVector( frame );
01134                 SP_ACCESS( frame )->m_pImpl->m_bAlreadyQueued = true;
01135                 
01136                 // End write lock frame handler list
01137                 m_pImpl->m_conditionHelper.ExitWriteLock( m_pImpl->m_frameHandlers );
01138             }
01139             else
01140             {
01141                 LOG_FREE_TEXT( "Could not lock frame queue for appending frame." );
01142                 res = VmbErrorResources;
01143             }
01144         }
01145     }
01146 
01147     return static_cast<VmbErrorType>( res );
01148 }
01149 
01150 VmbErrorType Camera::FlushQueue()
01151 {
01152     VmbError_t res = VmbCaptureQueueFlush( GetHandle() );
01153 
01154     if ( VmbErrorSuccess == res )
01155     {
01156         // Begin exclusive write lock frame handler list
01157         if ( true == m_pImpl->m_conditionHelper.EnterWriteLock( m_pImpl->m_frameHandlers, true ))
01158         {
01159             for (   FrameHandlerPtrVector::iterator iter = m_pImpl->m_frameHandlers.Vector.begin();
01160                     m_pImpl->m_frameHandlers.Vector.end() != iter;)
01161             {
01162                 // Begin exclusive write lock of every single frame handler
01163                 if ( true == SP_ACCESS(( *iter ))->EnterWriteLock( true ))
01164                 {
01165                     // Dequeue frame
01166                     SP_ACCESS( SP_ACCESS(( *iter ))->GetFrame() )->m_pImpl->m_bAlreadyQueued = false;
01167                     if ( false == SP_ACCESS( SP_ACCESS(( *iter ))->GetFrame() )->m_pImpl->m_bAlreadyAnnounced )
01168                     {
01169                         // Delete frame if it was not announced / was revoked before
01170                         SP_ACCESS( SP_ACCESS(( *iter ))->GetFrame() )->m_pImpl->m_frame.context[FRAME_HDL] = NULL;
01171                         // End write lock frame handler
01172                         SP_ACCESS(( *iter ))->ExitWriteLock();
01173                         iter = m_pImpl->m_frameHandlers.Vector.erase( iter );
01174                     }
01175                     else
01176                     {
01177                         // End write lock frame handler
01178                         SP_ACCESS(( *iter ))->ExitWriteLock();
01179                         ++iter;
01180                     }
01181                 }
01182                 else
01183                 {
01184                     LOG_FREE_TEXT( "Could not lock frame handler." );
01185                 }
01186             }
01187             // End write lock frame handler list
01188             m_pImpl->m_conditionHelper.ExitWriteLock( m_pImpl->m_frameHandlers );
01189         }
01190         else
01191         {
01192             LOG_FREE_TEXT( "Could not lock frame handler list." )
01193         }
01194     }
01195     else
01196     {
01197         LOG_FREE_TEXT( "Could not flush frame queue" )
01198     }
01199     
01200     return static_cast<VmbErrorType>( res );
01201 }
01202 
01203 VmbErrorType Camera::StartCapture() 
01204 {
01205     return static_cast<VmbErrorType>( VmbCaptureStart( GetHandle() ) );
01206 }
01207 
01208 VmbErrorType Camera::EndCapture() 
01209 {
01210     VmbError_t res = VmbCaptureEnd( GetHandle() );
01211 
01212     return static_cast<VmbErrorType>( res );
01213 }
01214 
01215 VmbErrorType Camera::Impl::AppendFrameToVector( const FramePtr &rFrame )
01216 {
01217     try
01218     {
01219         FrameHandlerPtr pFH( new FrameHandler( rFrame, SP_ACCESS( rFrame )->m_pImpl->m_pObserver ));
01220         if( SP_ISNULL( pFH ) )
01221         {
01222             return VmbErrorResources;
01223         }
01224         SP_ACCESS( rFrame )->m_pImpl->m_frame.context[FRAME_HDL] = SP_ACCESS(pFH);    
01225         m_frameHandlers.Vector.push_back( pFH );
01226         return VmbErrorSuccess;
01227     }
01228     catch(...)
01229     {
01230         return VmbErrorResources;
01231     }
01232 }
01233 
01234 //
01235 // Method:      SaveCameraSettings()
01236 //
01237 // Purpose:     Saves the current camera setup to an XML file
01238 //
01239 // Parameters:
01240 //
01241 //  [in]    pStrFileName    xml file name
01242 //  [in]    pSettings       pointer to settings struct
01243 //
01244 // Returns:
01245 //
01246 //  - VmbErrorSuccess:          If no error
01247 //  - VmbErrorApiNotStarted:    VmbStartup() was not called before the current command
01248 //  - VmbErrorBadHandle:        The given handle is not valid
01249 //  - VmbErrorInternalFault:    When something unexpected happens in VimbaC function
01250 //  - VmbErrorOther:            Every other failure in load/save settings implementation class
01251 //
01252 VmbErrorType Camera::SaveCameraSettings( const char * const pStrFileName, VmbFeaturePersistSettings_t *pSettings ) const
01253 {
01254     VmbErrorType err = VmbErrorSuccess;
01255 
01256 //  parameter check
01257     if( NULL == pStrFileName )
01258     {
01259         return VmbErrorBadParameter;
01260     }
01261 
01262 //  get handle
01263     VmbHandle_t handle = GetHandle();
01264 
01265     if( NULL == pSettings )
01266     {
01267         err = (VmbErrorType)VmbCameraSettingsSave( handle, pStrFileName, NULL, 0 );
01268     }
01269     else
01270     {
01271         err = (VmbErrorType)VmbCameraSettingsSave( handle, pStrFileName, pSettings, sizeof(pSettings) );
01272     }
01273 
01274     return err;
01275 }
01276 
01277 //
01278 // Method:      LoadCameraSettings()
01279 //
01280 // Purpose:     Loads the current camera setup from an XML file into the camera
01281 //
01282 // Parameters:
01283 //
01284 //  [in]    pStrFileName    xml file name
01285 //  [in]    pSettings       pointer to settings struct
01286 //
01287 // Returns:
01288 //
01289 //  - VmbErrorSuccess:          If no error
01290 //  - VmbErrorApiNotStarted:    VmbStartup() was not called before the current command
01291 //  - VmbErrorBadHandle:        The given handle is not valid
01292 //  - VmbErrorInternalFault:    When something unexpected happens in VimbaC function
01293 //  - VmbErrorOther:            Every other failure in load/save settings implementation class
01294 //
01295 VmbErrorType Camera::LoadCameraSettings( const char * const pStrFileName, VmbFeaturePersistSettings_t *pSettings ) const
01296 {
01297     VmbErrorType err = VmbErrorSuccess;
01298 
01299 //  parameter check
01300     if( NULL == pStrFileName )
01301     {
01302         return VmbErrorBadParameter;
01303     }
01304 
01305 //  get handle
01306     VmbHandle_t handle = GetHandle();
01307 
01308     if( NULL == pSettings )
01309     {
01310         err = (VmbErrorType)VmbCameraSettingsLoad( handle, pStrFileName, NULL, 0 );
01311     }
01312     else
01313     {
01314         err = (VmbErrorType)VmbCameraSettingsLoad( handle, pStrFileName, pSettings, sizeof(pSettings) );
01315     }
01316 
01317     return err;
01318 }
01319 
01320 //
01321 // Method:      LoadSaveSettingsSetup()
01322 //
01323 // Purpose:     Sets Load/Save settings behaviour (alternative to settings struct)
01324 //
01325 // Parameters:
01326 //
01327 //  [in]    persistType      determines which feature shall be considered during load/save settings
01328 //  [in]    maxIterations    determines how many 'tries' during loading feature values shall be performed
01329 //  [in]    loggingLevel     determines level of detail for load/save settings logging
01330 //
01331 void Camera::LoadSaveSettingsSetup( VmbFeaturePersist_t persistType, VmbUint32_t maxIterations, VmbUint32_t loggingLevel )
01332 {
01333     if( true == ((VmbFeaturePersistAll != persistType) && (VmbFeaturePersistStreamable != persistType) && (VmbFeaturePersistNoLUT != persistType)) )
01334     {
01335         m_persistType = VmbFeaturePersistNoLUT;
01336     }
01337     else
01338     {
01339         m_persistType = persistType;
01340     }
01341 
01342     if( false == ((0 < maxIterations) && (6 > maxIterations)) )
01343     {
01344         m_maxIterations = 5;
01345     }
01346     else
01347     {
01348         m_maxIterations = maxIterations;
01349     }
01350 
01351     if( false == ((0 < loggingLevel) && (5 > loggingLevel)) )
01352     {
01353         m_loggingLevel = 4;
01354     }
01355     else
01356     {
01357         m_loggingLevel = loggingLevel;
01358     }
01359 }
01360 
01361 }} // namespace AVT::VmbAPI


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