BaseFeature.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:        BaseFeature.cpp
00010 
00011   Description: Implementation of base class AVT::VmbAPI::BaseFeature.
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 #pragma warning(disable:4996)
00029 #include <VimbaCPP/Source/BaseFeature.h>
00030 #pragma warning(default:4996)
00031 
00032 #include <VimbaCPP/Include/FeatureContainer.h>
00033 #include <VimbaCPP/Include/VimbaSystem.h>
00034 #include <VimbaCPP/Source/ConditionHelper.h>
00035 #include <VimbaCPP/Source/Helper.h>
00036 
00037 namespace AVT {
00038 namespace VmbAPI {
00039 
00040 struct BaseFeature::Impl
00041 {
00042     LockableVector<IFeatureObserverPtr> m_observers;
00043 
00044     FeaturePtrVector m_affectedFeatures;
00045     FeaturePtrVector m_selectedFeatures;
00046     bool m_bAffectedFeaturesFetched;
00047     bool m_bSelectedFeaturesFetched;
00048 
00049     ConditionHelper m_observersConditionHelper;
00050     ConditionHelper m_conditionHelper;
00051 
00052     static void VMB_CALL InvalidationCallback( const VmbHandle_t handle, const char *name, void *context );
00053 };
00054 
00055 BaseFeature::BaseFeature( const VmbFeatureInfo_t *pFeatureInfo, FeatureContainer *pFeatureContainer )
00056     :   m_pImpl( new Impl() )
00057     ,   m_pFeatureContainer( pFeatureContainer )
00058 {
00059     m_pImpl->m_bAffectedFeaturesFetched = false;
00060     m_pImpl->m_bSelectedFeaturesFetched = false;
00061 
00062     if ( NULL != pFeatureInfo )
00063     {
00064         m_featureInfo.category.assign( pFeatureInfo->category ? pFeatureInfo->category : "" );
00065         m_featureInfo.description.assign( pFeatureInfo->description ? pFeatureInfo->description : "" );
00066         m_featureInfo.displayName.assign( pFeatureInfo->displayName ? pFeatureInfo->displayName : "" );
00067         m_featureInfo.featureDataType = pFeatureInfo->featureDataType;
00068         m_featureInfo.featureFlags = pFeatureInfo->featureFlags;
00069         m_featureInfo.hasAffectedFeatures = pFeatureInfo->hasAffectedFeatures;
00070         m_featureInfo.hasSelectedFeatures = pFeatureInfo->hasSelectedFeatures;
00071         m_featureInfo.name.assign( pFeatureInfo->name ? pFeatureInfo->name : "" );
00072         m_featureInfo.pollingTime = pFeatureInfo->pollingTime;
00073         m_featureInfo.representation.assign( pFeatureInfo->representation ? pFeatureInfo->representation : "" );
00074         m_featureInfo.sfncNamespace.assign( pFeatureInfo->sfncNamespace ? pFeatureInfo->sfncNamespace : "" );
00075         m_featureInfo.tooltip.assign( pFeatureInfo->tooltip ? pFeatureInfo->tooltip : "" );
00076         m_featureInfo.unit.assign( pFeatureInfo->unit ? pFeatureInfo->unit : "" );
00077         m_featureInfo.visibility = pFeatureInfo->visibility;
00078         m_featureInfo.isStreamable = pFeatureInfo->isStreamable;
00079 
00080         if ( NULL == m_pFeatureContainer ) // m_pFeatureContainer == NULL (Just for safety)
00081         {
00082             // Do some logging
00083             LOG_FREE_TEXT( "No valid feature container pointer passed" );
00084         }
00085     }
00086     else // m_featureInfo == NULL (Just for safety)
00087     {
00088         // Do some logging
00089         LOG_FREE_TEXT( "No valid feature info pointer passed" );
00090     }
00091 }
00092 
00093 BaseFeature::BaseFeature()
00094 {
00095     // No default ctor
00096 }
00097 
00098 BaseFeature::BaseFeature( const BaseFeature& )
00099 {
00100     // No copy ctor
00101 }
00102 
00103 BaseFeature::~BaseFeature()
00104 {
00105     // Before destruction we unregister all observers and all callbacks
00106     ResetFeatureContainer();
00107 
00108     delete m_pImpl;
00109 }
00110 
00111 // Unregisters all observers before it resets the feature container pointer.
00112 void BaseFeature::ResetFeatureContainer()
00113 {
00114     if ( NULL != m_pFeatureContainer )
00115     {
00116         // Camera still open
00117         if ( NULL != m_pFeatureContainer->GetHandle() )
00118         {
00119             VmbFeatureInvalidationUnregister( m_pFeatureContainer->GetHandle(), m_featureInfo.name.c_str(), m_pImpl->InvalidationCallback );
00120         }
00121 
00122         // Begin exclusive write lock this feature
00123         if ( true == m_pImpl->m_conditionHelper.EnterWriteLock( GetMutex(), true ))
00124         {
00125             m_pFeatureContainer = NULL;
00126 
00127             // End write lock this feature
00128             m_pImpl->m_conditionHelper.ExitWriteLock( GetMutex() );
00129         }
00130         else
00131         {
00132             LOG_FREE_TEXT( "Could not reset a feature's feature container reference. ");
00133         }
00134         
00135     }
00136     
00137     // Begin exclusive write lock observer list
00138     if ( true == m_pImpl->m_observersConditionHelper.EnterWriteLock( m_pImpl->m_observers, true ))
00139     {
00140         m_pImpl->m_observers.Vector.clear();
00141         
00142         // End write lock observer list
00143         m_pImpl->m_observersConditionHelper.ExitWriteLock( m_pImpl->m_observers );
00144     }
00145 }
00146 
00147 void VMB_CALL BaseFeature::Impl::InvalidationCallback( const VmbHandle_t handle, const char * /*name*/, void *context )
00148 {
00149     BaseFeature *pFeature = (BaseFeature*)context;
00150     if ( NULL != pFeature )
00151     {
00152         if ( NULL != handle )
00153         {
00154             // Begin read lock this feature
00155             if ( true == pFeature->m_pImpl->m_conditionHelper.EnterReadLock( pFeature->GetMutex() ))
00156             {
00157                 if ( NULL != pFeature->m_pFeatureContainer )
00158                 {
00159                     FeaturePtr pFeaturePtrFromMap;
00160                     if ( VmbErrorSuccess == pFeature->m_pFeatureContainer->GetFeatureByName( pFeature->m_featureInfo.name.c_str(), pFeaturePtrFromMap ) )
00161                     {
00162                         // Begin read lock observer list
00163                         if ( true == pFeature->m_pImpl->m_observersConditionHelper.EnterReadLock( pFeature->m_pImpl->m_observers ))
00164                         {
00165                             for (   IFeatureObserverPtrVector::iterator iter = pFeature->m_pImpl->m_observers.Vector.begin();
00166                                     pFeature->m_pImpl->m_observers.Vector.end() != iter;
00167                                     ++iter)
00168                             {
00169                                 SP_ACCESS(( *iter ))->FeatureChanged( pFeaturePtrFromMap );
00170                             }
00171 
00172                             // End read lock observer list
00173                             pFeature->m_pImpl->m_observersConditionHelper.ExitReadLock( pFeature->m_pImpl->m_observers );
00174                         }
00175                         else
00176                         {
00177                             LOG_FREE_TEXT( "Could not lock feature observer list.")
00178                         }
00179                     }
00180                     else // GetFeatureByName() failed
00181                     {
00182                         // Do some logging
00183                         LOG_FREE_TEXT( "GetFeatureByName failed" )
00184                     }
00185                 }
00186                 else // m_pFeatureContainer == NULL (Feature destroyed or device closed / destroyed)
00187                 {
00188                     // Do some logging
00189                     LOG_FREE_TEXT( "Feature destroyed or device closed / destroyed" );
00190                 }
00191 
00192                 // End read lock this feature
00193                 pFeature->m_pImpl->m_conditionHelper.ExitReadLock( pFeature->GetMutex() );
00194             }
00195             else
00196             {
00197                 LOG_FREE_TEXT( "Could not lock feature.")
00198             }
00199         }
00200         else // m_handle == NULL (device closed / destroyed)
00201         {
00202             // Do some logging
00203             LOG_FREE_TEXT( "Device closed / destroyed" )
00204         }
00205     }
00206     else // pFeature == NULL (Just for safety)
00207     {
00208         // Do some logging
00209         LOG_FREE_TEXT( "Feature pointer is null" )
00210     }
00211 }
00212 
00213 VmbErrorType BaseFeature::RegisterObserver( const IFeatureObserverPtr &rObserver )
00214 {
00215     if ( SP_ISNULL( rObserver ))
00216     {
00217         return VmbErrorBadParameter;
00218     }    
00219 
00220     if ( NULL == m_pFeatureContainer )
00221     {
00222         return VmbErrorDeviceNotOpen;
00223     }
00224 
00225     VmbError_t res = VmbErrorSuccess;
00226 
00227     // Begin write lock observer list
00228     if ( true == m_pImpl->m_observersConditionHelper.EnterWriteLock( m_pImpl->m_observers ))
00229     {
00230         // The very same observer cannot be registered twice
00231         for ( size_t i=0; i<m_pImpl->m_observers.Vector.size(); ++i )
00232         {
00233             if ( SP_ISEQUAL( rObserver, m_pImpl->m_observers.Vector[i] ))
00234             {
00235                 res = VmbErrorInvalidCall;
00236                 break;
00237             }
00238         }
00239 
00240         if ( VmbErrorSuccess == res )
00241         {
00242             if ( 0 == m_pImpl->m_observers.Vector.size() )
00243             {
00244                 res = VmbFeatureInvalidationRegister( m_pFeatureContainer->GetHandle(), m_featureInfo.name.c_str(), m_pImpl->InvalidationCallback, this );
00245             }
00246 
00247             if ( VmbErrorSuccess == res )
00248             {
00249                 m_pImpl->m_observers.Vector.push_back( rObserver );
00250             }
00251         }
00252         
00253         // End write lock observer list
00254         m_pImpl->m_observersConditionHelper.ExitWriteLock( m_pImpl->m_observers );
00255     }
00256 
00257     return (VmbErrorType)res;
00258 }
00259 
00260 VmbErrorType BaseFeature::UnregisterObserver( const IFeatureObserverPtr &rObserver )
00261 {
00262     if ( SP_ISNULL( rObserver ))
00263     {
00264         return VmbErrorBadParameter;
00265     }    
00266 
00267     if ( NULL == m_pFeatureContainer )
00268     {
00269         return VmbErrorDeviceNotOpen;
00270     }
00271 
00272     VmbError_t res = VmbErrorNotFound;
00273 
00274     // Begin exclusive write lock observer list
00275     if ( true == m_pImpl->m_observersConditionHelper.EnterWriteLock( m_pImpl->m_observers, true ))
00276     {
00277         for (   IFeatureObserverPtrVector::iterator iter = m_pImpl->m_observers.Vector.begin();
00278                 m_pImpl->m_observers.Vector.end() != iter;)
00279         {
00280             if ( SP_ISEQUAL( rObserver, *iter ))
00281             {
00282                 // If we are about to unregister the last observer we cancel all invalidation notifications
00283                 if ( 1 == m_pImpl->m_observers.Vector.size() )
00284                 {
00285                     res = VmbFeatureInvalidationUnregister( m_pFeatureContainer->GetHandle(), m_featureInfo.name.c_str(), m_pImpl->InvalidationCallback );
00286                 }
00287                 if (    VmbErrorSuccess == res
00288                      || 1 < m_pImpl->m_observers.Vector.size() )
00289                 {
00290                     iter = m_pImpl->m_observers.Vector.erase( iter );
00291                     res = VmbErrorSuccess;
00292                 }
00293                 break;
00294             }
00295             else
00296             {
00297                 ++iter;
00298             }
00299         }
00300 
00301         // End write lock observer list
00302         m_pImpl->m_observersConditionHelper.ExitWriteLock( m_pImpl->m_observers );
00303     }
00304     else
00305     {
00306         LOG_FREE_TEXT( "Could not lock feature observer list.")
00307         res = VmbErrorInternalFault;
00308     }
00309     
00310     return (VmbErrorType)res;
00311 }
00312 
00313 // Gets the value of a feature of type VmbFeatureDataInt
00314 VmbErrorType BaseFeature::GetValue( VmbInt64_t & /*rnValue*/ ) const
00315 {
00316     return VmbErrorWrongType;
00317 }
00318 
00319 // Sets the value of a feature of type VmbFeatureDataInt
00320 VmbErrorType BaseFeature::SetValue( const VmbInt64_t & /*rnValue*/ )
00321 {
00322     return VmbErrorWrongType;
00323 }
00324 
00325 // Sets the value of a feature of type VmbFeatureDataInt
00326 VmbErrorType BaseFeature::SetValue( const VmbInt32_t & /*rnValue*/ )
00327 {
00328     return VmbErrorWrongType;
00329 }
00330 
00331 // Gets the range of a feature of type VmbFeatureDataInt
00332 VmbErrorType BaseFeature::GetRange( VmbInt64_t & /*rnMinimum*/, VmbInt64_t & /*rnMaximum*/ ) const
00333 {
00334     return VmbErrorWrongType;
00335 }
00336 
00337 VmbErrorType BaseFeature::HasIncrement( VmbBool_t & /*incrementSupported*/) const
00338 {
00339     return VmbErrorWrongType;
00340 }
00341 // Gets the increment of a feature of type VmbFeatureDataInt
00342 VmbErrorType BaseFeature::GetIncrement( VmbInt64_t & /*rnIncrement*/ ) const
00343 {
00344     return VmbErrorWrongType;
00345 }
00346 
00347 // Gets the increment of a feature of type VmbFeatureDataFloat
00348 VmbErrorType BaseFeature::GetIncrement( double & /*rnIncrement*/ ) const
00349 {
00350     return VmbErrorWrongType;
00351 }
00352 
00353 // Gets the value of a feature of type VmbFeatureDataFloat
00354 VmbErrorType BaseFeature::GetValue( double & /*rfValue*/) const
00355 {
00356     return VmbErrorWrongType;
00357 }
00358 
00359 // Sets the value of a feature of type VmbFeatureDataFloat
00360 VmbErrorType BaseFeature::SetValue( const double & /*rfValue*/ )
00361 {
00362     return VmbErrorWrongType;
00363 }
00364 
00365 // Gets the range of a feature of type VmbFeatureDataFloat
00366 VmbErrorType BaseFeature::GetRange( double & /*rfMinimum*/, double & /*rfMaximum*/ ) const
00367 {
00368     return VmbErrorWrongType;
00369 }
00370 
00371 // Sets the value of a feature of type VmbFeatureDataEnum
00372 // Sets the value of a feature of type VmbFeatureDataString
00373 VmbErrorType BaseFeature::SetValue( const char * /*pStrValue*/ )
00374 {
00375     return VmbErrorWrongType;
00376 }
00377 
00378 // Gets the enum entry of a feature of type VmbFeatureDataEnum
00379 VmbErrorType BaseFeature::GetEntry( EnumEntry & /*entry*/, const char * /*pStrEntryName*/ ) const
00380 {
00381     return VmbErrorWrongType;
00382 }
00383 
00384 // Gets all possible enum entries of a feature of type VmbFeatureDataEnum
00385 VmbErrorType BaseFeature::GetEntries( EnumEntry * /*pEnumEntries*/, VmbUint32_t & /*size*/ )
00386 {
00387     return VmbErrorWrongType;
00388 }
00389 
00390 // Gets all possible values as string of a feature of type VmbFeatureDataEnum
00391 VmbErrorType BaseFeature::GetValues( const char ** /*pStrValues*/, VmbUint32_t & /*rnSize*/ )
00392 {
00393     return VmbErrorWrongType;
00394 }
00395 
00396 // Gets all possible values as integer of a feature of type VmbFeatureDataEnum
00397 VmbErrorType BaseFeature::GetValues( VmbInt64_t * /*pnValues*/, VmbUint32_t & /*rnSize*/ )
00398 {
00399     return VmbErrorWrongType;
00400 }
00401 
00402 // Indicates whether a particular enum value as string of a feature of type VmbFeatureDataEnum is available
00403 VmbErrorType BaseFeature::IsValueAvailable( const char * /*pStrValue*/, bool & /*bAvailable*/ ) const
00404 {
00405     return VmbErrorWrongType;
00406 }
00407 
00408 // Indicates whether a particular enum value as integer of a feature of type VmbFeatureDataEnum is available
00409 VmbErrorType BaseFeature::IsValueAvailable( const VmbInt64_t /*nValue*/, bool & /*bAvailable*/ ) const
00410 {
00411     return VmbErrorWrongType;
00412 }
00413 
00414 // Gets the value of a feature of type VmbFeatureDataString
00415 // Gets the value of a feature of type VmbFeatureDataEnum
00416 VmbErrorType BaseFeature::GetValue( char * const /*pStrValue*/, VmbUint32_t & /*length*/ ) const
00417 {
00418     return VmbErrorWrongType;
00419 }
00420 
00421 // Gets the value of a feature of type VmbFeatureDataBool
00422 VmbErrorType BaseFeature::GetValue( bool & /*rbValue*/ ) const
00423 {
00424     return VmbErrorWrongType;
00425 }
00426 
00427 // Sets the value of a feature of type VmbFeatureDataBool
00428 VmbErrorType BaseFeature::SetValue( bool /*bValue*/ )
00429 {
00430     return VmbErrorWrongType;
00431 }
00432 
00433 // Executes a feature of type VmbFeatureDataCommand
00434 VmbErrorType BaseFeature::RunCommand() 
00435 {
00436     return VmbErrorWrongType;
00437 }
00438 
00439 // Indicates whether a feature of type VmbFeatureDataCommand finished execution
00440 VmbErrorType BaseFeature::IsCommandDone( bool & /*bIsDone*/ ) const
00441 {
00442     return VmbErrorWrongType;
00443 }
00444 
00445 // Gets the value of a feature of type VmbFeatureDataRaw
00446 VmbErrorType BaseFeature::GetValue( VmbUchar_t * /*pValue*/, VmbUint32_t & /*rnSize*/, VmbUint32_t & /*rnSizeFilled*/ ) const
00447 {
00448     return VmbErrorWrongType;
00449 }
00450 
00451 // Sets the value of a feature of type VmbFeatureDataRaw
00452 VmbErrorType BaseFeature::SetValue( const VmbUchar_t * /*pValue*/, VmbUint32_t /*nSize*/ )
00453 {
00454     return VmbErrorWrongType;
00455 }
00456 
00457 VmbErrorType BaseFeature::GetName( char * const pStrName, VmbUint32_t &rnLength ) const
00458 {
00459     VmbErrorType res;
00460 
00461     if ( NULL == pStrName )
00462     {
00463         rnLength = (VmbUint32_t)m_featureInfo.name.length();
00464         res = VmbErrorSuccess;
00465     }
00466     else if ( m_featureInfo.name.length() <= rnLength )
00467     {
00468         std::copy( m_featureInfo.name.begin(), m_featureInfo.name.end(), pStrName );
00469         rnLength = (VmbUint32_t)m_featureInfo.name.length();
00470         res = VmbErrorSuccess;
00471     }
00472     else
00473     {
00474         res = VmbErrorMoreData;
00475     }
00476 
00477     return res;
00478 }
00479 
00480 VmbErrorType BaseFeature::GetDisplayName( char * const pStrDisplayName, VmbUint32_t &rnLength ) const
00481 {
00482     VmbErrorType res;
00483 
00484     if ( NULL == pStrDisplayName )
00485     {
00486         rnLength = (VmbUint32_t)m_featureInfo.displayName.length();
00487         res = VmbErrorSuccess;
00488     }
00489     else if ( m_featureInfo.displayName.length() <= rnLength )
00490     {
00491         std::copy( m_featureInfo.displayName.begin(), m_featureInfo.displayName.end(), pStrDisplayName );
00492         rnLength = (VmbUint32_t)m_featureInfo.displayName.length();
00493         res = VmbErrorSuccess;
00494     }
00495     else
00496     {
00497         res = VmbErrorMoreData;
00498     }
00499 
00500     return res;
00501 }
00502 
00503 VmbErrorType BaseFeature::GetDataType( VmbFeatureDataType &reDataType ) const
00504 {
00505     reDataType = (VmbFeatureDataType)m_featureInfo.featureDataType;
00506     
00507     return VmbErrorSuccess;
00508 }
00509 
00510 VmbErrorType BaseFeature::GetFlags( VmbFeatureFlagsType &reFlags ) const
00511 {
00512     reFlags = (VmbFeatureFlagsType)m_featureInfo.featureFlags;
00513         
00514     return VmbErrorSuccess;
00515 }
00516 
00517 VmbErrorType BaseFeature::GetCategory( char * const pStrCategory, VmbUint32_t &rnLength ) const
00518 {
00519     VmbErrorType res;
00520 
00521     if ( NULL == pStrCategory )
00522     {
00523         rnLength = (VmbUint32_t)m_featureInfo.category.length();
00524         res = VmbErrorSuccess;
00525     }
00526     else if ( m_featureInfo.category.length() <= rnLength )
00527     {
00528         std::copy( m_featureInfo.category.begin(), m_featureInfo.category.end(), pStrCategory );
00529         rnLength = (VmbUint32_t)m_featureInfo.category.length();
00530         res = VmbErrorSuccess;
00531     }
00532     else
00533     {
00534         res = VmbErrorMoreData;
00535     }
00536 
00537     return res;
00538 }
00539 
00540 VmbErrorType BaseFeature::GetPollingTime( VmbUint32_t &rnPollingTime ) const
00541 {
00542     rnPollingTime = m_featureInfo.pollingTime;
00543     
00544     return VmbErrorSuccess;
00545 }
00546 
00547 VmbErrorType BaseFeature::GetUnit( char * const pStrUnit, VmbUint32_t &rnLength ) const
00548 {
00549     VmbErrorType res;
00550 
00551     if ( NULL == pStrUnit )
00552     {
00553         rnLength = (VmbUint32_t)m_featureInfo.unit.length();
00554         res = VmbErrorSuccess;
00555     }
00556     else if ( m_featureInfo.unit.length() <= rnLength )
00557     {
00558         std::copy( m_featureInfo.unit.begin(), m_featureInfo.unit.end(), pStrUnit );
00559         rnLength = (VmbUint32_t)m_featureInfo.unit.length();
00560         res = VmbErrorSuccess;
00561     }
00562     else
00563     {
00564         res = VmbErrorMoreData;
00565     }
00566 
00567     return res;
00568 }
00569 
00570 VmbErrorType BaseFeature::GetRepresentation( char * const pStrRepresentation, VmbUint32_t &rnLength ) const
00571 {
00572     VmbErrorType res;
00573 
00574     if ( NULL == pStrRepresentation )
00575     {
00576         rnLength = (VmbUint32_t)m_featureInfo.representation.length();
00577         res = VmbErrorSuccess;
00578     }
00579     else if ( m_featureInfo.representation.length() <= rnLength )
00580     {
00581         std::copy( m_featureInfo.representation.begin(), m_featureInfo.representation.end(), pStrRepresentation );
00582         rnLength = (VmbUint32_t)m_featureInfo.representation.length();
00583         res = VmbErrorSuccess;
00584     }
00585     else
00586     {
00587         res = VmbErrorMoreData;
00588     }
00589 
00590     return res;
00591 }
00592 
00593 VmbErrorType BaseFeature::GetVisibility( VmbFeatureVisibilityType &reVisibility ) const
00594 {
00595     reVisibility = (VmbFeatureVisibilityType)m_featureInfo.visibility;
00596 
00597     return VmbErrorSuccess;
00598 }
00599 
00600 VmbErrorType BaseFeature::GetToolTip( char * const pStrToolTip, VmbUint32_t &rnLength ) const
00601 {
00602     VmbErrorType res;
00603 
00604     if ( NULL == pStrToolTip )
00605     {
00606         rnLength = (VmbUint32_t)m_featureInfo.tooltip.length();
00607         res = VmbErrorSuccess;
00608     }
00609     else if ( m_featureInfo.tooltip.length() <= rnLength )
00610     {
00611         std::copy( m_featureInfo.tooltip.begin(), m_featureInfo.tooltip.end(), pStrToolTip );
00612         rnLength = (VmbUint32_t)m_featureInfo.tooltip.length();
00613         res = VmbErrorSuccess;
00614     }
00615     else
00616     {
00617         res = VmbErrorMoreData;
00618     }
00619 
00620     return res;
00621 }
00622 
00623 VmbErrorType BaseFeature::GetDescription( char * const pStrDescription, VmbUint32_t &rnLength ) const
00624 {
00625     VmbErrorType res;
00626 
00627     if ( NULL == pStrDescription )
00628     {
00629         rnLength = (VmbUint32_t)m_featureInfo.description.length();
00630         res = VmbErrorSuccess;
00631     }
00632     else if ( m_featureInfo.description.length() <= rnLength )
00633     {
00634         std::copy( m_featureInfo.description.begin(), m_featureInfo.description.end(), pStrDescription );
00635         rnLength = (VmbUint32_t)m_featureInfo.description.length();
00636         res = VmbErrorSuccess;
00637     }
00638     else
00639     {
00640         res = VmbErrorMoreData;
00641     }
00642 
00643     return res;
00644 }
00645 
00646 VmbErrorType BaseFeature::GetSFNCNamespace( char * const pStrSFNCNamespace, VmbUint32_t &rnLength ) const
00647 {
00648     VmbErrorType res;
00649 
00650     if ( NULL == pStrSFNCNamespace )
00651     {
00652         rnLength = (VmbUint32_t)m_featureInfo.sfncNamespace.length();
00653         res = VmbErrorSuccess;
00654     }
00655     else if ( m_featureInfo.sfncNamespace.length() <= rnLength )
00656     {
00657         std::copy( m_featureInfo.sfncNamespace.begin(), m_featureInfo.sfncNamespace.end(), pStrSFNCNamespace );
00658         rnLength = (VmbUint32_t)m_featureInfo.sfncNamespace.length();
00659         res = VmbErrorSuccess;
00660     }
00661     else
00662     {
00663         res = VmbErrorMoreData;
00664     }
00665 
00666     return res;
00667 }
00668 
00669 VmbErrorType BaseFeature::GetAffectedFeatures( FeaturePtr *pAffectedFeatures, VmbUint32_t &rnSize )
00670 {
00671     VmbError_t res;
00672 
00673     if ( NULL == pAffectedFeatures )
00674     {
00675         // Affected features were fetched before
00676         if ( true == m_pImpl->m_bAffectedFeaturesFetched )
00677         {
00678             rnSize = (VmbUint32_t)m_pImpl->m_affectedFeatures.size();
00679 
00680             res = VmbErrorSuccess;
00681         }
00682         // Affected features have not been fetched before
00683         else
00684         {
00685             return (VmbErrorType)VmbFeatureListAffected( m_pFeatureContainer->GetHandle(), m_featureInfo.name.c_str(), NULL, 0, &rnSize, sizeof(VmbFeatureInfo_t) );
00686         }
00687     }
00688     else
00689     {
00690         // Affected features were fetched before
00691         if ( true == m_pImpl->m_bAffectedFeaturesFetched )
00692         {
00693             if ( rnSize < m_pImpl->m_affectedFeatures.size() )
00694             {
00695                 return VmbErrorMoreData;
00696             }
00697 
00698             rnSize = (VmbUint32_t)m_pImpl->m_affectedFeatures.size();
00699 
00700             std::copy( m_pImpl->m_affectedFeatures.begin(), m_pImpl->m_affectedFeatures.end(), pAffectedFeatures );
00701 
00702             res = VmbErrorSuccess;
00703         }
00704         // Affected features have not been fetched before
00705         else
00706         {
00707             // Check whether the given array size fits
00708             VmbUint32_t nSize = 0;
00709             res = VmbFeatureListAffected( m_pFeatureContainer->GetHandle(), m_featureInfo.name.c_str(), NULL, 0, &nSize, sizeof(VmbFeatureInfo_t) );
00710 
00711             m_pImpl->m_bAffectedFeaturesFetched = true;
00712 
00713             if ( rnSize < nSize )
00714             {
00715                 return VmbErrorMoreData;
00716             }
00717 
00718             rnSize = (VmbUint32_t)nSize;
00719 
00720             if (    VmbErrorSuccess != res
00721                  || 0 == rnSize )
00722             {
00723                 return (VmbErrorType)res;
00724             }
00725 
00726             // Fetch affected features and store them as well as hand them out
00727             std::vector<VmbFeatureInfo_t> affectedFeatureInfos;
00728             affectedFeatureInfos.resize( rnSize );
00729 
00730             res = VmbFeatureListAffected( m_pFeatureContainer->GetHandle(), m_featureInfo.name.c_str(), &affectedFeatureInfos[0], (VmbUint32_t)affectedFeatureInfos.size(), &nSize, sizeof(VmbFeatureInfo_t) );
00731             
00732             if ( rnSize < nSize )
00733             {
00734                 return VmbErrorMoreData;
00735             }
00736 
00737             rnSize = (VmbUint32_t)nSize;
00738 
00739             for ( VmbUint32_t i=0; i<rnSize; ++i )
00740             {
00741                 FeaturePtr pFeature;
00742                 res = m_pFeatureContainer->GetFeatureByName( affectedFeatureInfos[i].name, pFeature );
00743                 if ( VmbErrorSuccess != res )
00744                 {
00745                     m_pImpl->m_affectedFeatures.clear();
00746                     return (VmbErrorType)res;
00747                 }
00748                 m_pImpl->m_affectedFeatures.push_back( pFeature );
00749                 pAffectedFeatures[i] = m_pImpl->m_affectedFeatures[i];
00750             }
00751         }
00752     }
00753 
00754     return (VmbErrorType)res;
00755 }
00756 
00757 VmbErrorType BaseFeature::GetSelectedFeatures( FeaturePtr *pSelectedFeatures, VmbUint32_t &rnSize )
00758 {
00759     VmbError_t res;
00760 
00761     if ( NULL == pSelectedFeatures )
00762     {
00763         // Selected features were fetched before
00764         if ( true == m_pImpl->m_bSelectedFeaturesFetched )
00765         {
00766             rnSize = (VmbUint32_t)m_pImpl->m_selectedFeatures.size();
00767 
00768             res = VmbErrorSuccess;
00769         }
00770         // Selected features have not been fetched before
00771         else
00772         {
00773             return (VmbErrorType)VmbFeatureListSelected( m_pFeatureContainer->GetHandle(), m_featureInfo.name.c_str(), NULL, 0, &rnSize, sizeof(VmbFeatureInfo_t) );
00774         }
00775     }
00776     else
00777     {
00778         // Selected features were fetched before
00779         if ( true == m_pImpl->m_bSelectedFeaturesFetched )
00780         {
00781             if ( rnSize < m_pImpl->m_selectedFeatures.size() )
00782             {
00783                 return VmbErrorMoreData;
00784             }
00785 
00786             rnSize = (VmbUint32_t)m_pImpl->m_selectedFeatures.size();
00787 
00788             std::copy( m_pImpl->m_selectedFeatures.begin(), m_pImpl->m_selectedFeatures.end(), pSelectedFeatures );
00789 
00790             res = VmbErrorSuccess;
00791         }
00792         // Selected features have not been fetched before
00793         else
00794         {
00795             // Check whether the given array size fits
00796             VmbUint32_t nSize = 0;
00797             res = VmbFeatureListSelected( m_pFeatureContainer->GetHandle(), m_featureInfo.name.c_str(), NULL, 0, &nSize, sizeof(VmbFeatureInfo_t) );
00798 
00799             m_pImpl->m_bSelectedFeaturesFetched = true;
00800 
00801             if ( rnSize < nSize )
00802             {
00803                 return VmbErrorMoreData;
00804             }
00805 
00806             rnSize = (VmbUint32_t)nSize;
00807 
00808             if (    VmbErrorSuccess != res
00809                  || 0 == rnSize )
00810             {
00811                 return (VmbErrorType)res;
00812             }
00813 
00814             // Fetch selected features and store them as well as hand them out
00815             std::vector<VmbFeatureInfo_t> selectedFeatureInfos;
00816             selectedFeatureInfos.resize( rnSize );
00817 
00818             res = VmbFeatureListSelected( m_pFeatureContainer->GetHandle(), m_featureInfo.name.c_str(), &selectedFeatureInfos[0], (VmbUint32_t)selectedFeatureInfos.size(), &nSize, sizeof(VmbFeatureInfo_t) );
00819 
00820             if ( rnSize < nSize )
00821             {
00822                 return VmbErrorMoreData;
00823             }
00824 
00825             rnSize = (VmbUint32_t)nSize;
00826 
00827             for ( VmbUint32_t i=0; i<rnSize; ++i )
00828             {
00829                 FeaturePtr pFeature;
00830                 res = m_pFeatureContainer->GetFeatureByName( selectedFeatureInfos[i].name, pFeature );
00831                 if ( VmbErrorSuccess != res )
00832                 {
00833                     m_pImpl->m_selectedFeatures.clear();
00834                     return (VmbErrorType)res;
00835                 }
00836                 m_pImpl->m_selectedFeatures.push_back( pFeature );
00837                 pSelectedFeatures[i] = m_pImpl->m_selectedFeatures[i];
00838             }
00839         }
00840     }
00841 
00842     return (VmbErrorType)res;
00843 }
00844 
00845 VmbErrorType BaseFeature::IsReadable( bool &rbIsReadable )
00846 {
00847     bool bIsWritable = false;
00848 
00849     if ( NULL == m_pFeatureContainer )
00850     {
00851         return VmbErrorDeviceNotOpen;
00852     }
00853     
00854     return (VmbErrorType)VmbFeatureAccessQuery( m_pFeatureContainer->GetHandle(), m_featureInfo.name.c_str(), &rbIsReadable, &bIsWritable );
00855 }
00856 
00857 VmbErrorType BaseFeature::IsWritable( bool &rbIsWritable )
00858 {
00859     bool bIsReadable = false;
00860 
00861     if ( NULL == m_pFeatureContainer )
00862     {
00863         return VmbErrorDeviceNotOpen;
00864     }
00865 
00866     return (VmbErrorType)VmbFeatureAccessQuery( m_pFeatureContainer->GetHandle(), m_featureInfo.name.c_str(), &bIsReadable, &rbIsWritable );
00867 }
00868 
00869 VmbErrorType BaseFeature::IsStreamable( bool &rbIsStreamable ) const
00870 {
00871     rbIsStreamable = m_featureInfo.isStreamable;
00872 
00873     return VmbErrorSuccess;
00874 }
00875 
00876 
00877 }} // namespace AVT::VmbAPI


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