Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <string>
00029
00030 #include <VimbaCPP/Include/FeatureContainer.h>
00031
00032 #include <VimbaCPP/Include/VimbaSystem.h>
00033
00034 namespace AVT {
00035 namespace VmbAPI {
00036
00037 struct FeatureContainer::Impl
00038 {
00039 VmbHandle_t m_handle;
00040
00041 bool m_bAllFeaturesFetched;
00042
00043 FeaturePtrMap m_features;
00044 };
00045
00046 FeatureContainer::FeatureContainer()
00047 : m_pImpl ( new Impl() )
00048 {
00049 m_pImpl->m_bAllFeaturesFetched = false;
00050 m_pImpl->m_handle = NULL;
00051 }
00052
00053 FeatureContainer::FeatureContainer( const FeatureContainer& )
00054 {
00055
00056 }
00057
00058 FeatureContainer& FeatureContainer::operator=( const FeatureContainer& )
00059 {
00060
00061 return *this;
00062 }
00063
00064 FeatureContainer::~FeatureContainer()
00065 {
00066 Reset();
00067 RevokeHandle();
00068
00069 delete m_pImpl;
00070 }
00071
00072 VmbErrorType FeatureContainer::GetFeatureByName( const char *name, FeaturePtr &rFeature )
00073 {
00074 VmbError_t res;
00075
00076 if ( NULL == name )
00077 {
00078 return VmbErrorBadParameter;
00079 }
00080
00081 if ( NULL == m_pImpl->m_handle )
00082 {
00083 return VmbErrorDeviceNotOpen;
00084 }
00085
00086 FeaturePtrMap::iterator iter = m_pImpl->m_features.find( name );
00087 if ( iter != m_pImpl->m_features.end() )
00088 {
00089 rFeature = iter->second;
00090 return VmbErrorSuccess;
00091 }
00092
00093 VmbFeatureInfo_t featureInfo;
00094
00095 res = VmbFeatureInfoQuery( m_pImpl->m_handle, name, &featureInfo, sizeof( VmbFeatureInfo_t ));
00096
00097 if ( VmbErrorSuccess == res )
00098 {
00099 rFeature = FeaturePtr( new Feature( &featureInfo, this ));
00100
00101 if ( VmbFeatureVisibilityInvisible != featureInfo.visibility )
00102 {
00103 m_pImpl->m_features[name] = rFeature;
00104 }
00105 }
00106
00107 return (VmbErrorType)res;
00108 }
00109
00110 VmbErrorType FeatureContainer::GetFeatures( FeaturePtr *pFeatures, VmbUint32_t &rnSize )
00111 {
00112 VmbError_t res;
00113
00114 if ( NULL == m_pImpl->m_handle )
00115 {
00116 return VmbErrorDeviceNotOpen;
00117 }
00118
00119
00120 if ( false == m_pImpl->m_bAllFeaturesFetched )
00121 {
00122 std::vector<VmbFeatureInfo_t> featureInfoList;
00123
00124 res = VmbFeaturesList( m_pImpl->m_handle, NULL, 0, &rnSize, sizeof(VmbFeatureInfo_t) );
00125 if ( 0 == rnSize || VmbErrorSuccess != res )
00126 {
00127 return (VmbErrorType)res;
00128 }
00129
00130 featureInfoList.resize( rnSize );
00131 res = VmbFeaturesList( m_pImpl->m_handle, &featureInfoList[0], rnSize, &rnSize, sizeof(VmbFeatureInfo_t) );
00132 if ( VmbErrorSuccess != res )
00133 {
00134 return (VmbErrorType)res;
00135 }
00136
00137 for ( std::vector<VmbFeatureInfo_t>::iterator iter = featureInfoList.begin();
00138 featureInfoList.end() != iter;
00139 ++iter )
00140 {
00141 std::string strName = iter->name;
00142 if ( 0 != strName.length() )
00143 {
00144 if ( SP_ISNULL( m_pImpl->m_features[strName] ))
00145 {
00146 m_pImpl->m_features[strName] = FeaturePtr( new Feature( &(*iter), this ));
00147 }
00148 }
00149 }
00150
00151 m_pImpl->m_bAllFeaturesFetched = true;
00152 }
00153 else
00154 {
00155 res = VmbErrorSuccess;
00156 }
00157
00158 if ( VmbErrorSuccess == res )
00159 {
00160 if ( NULL == pFeatures )
00161 {
00162 rnSize = (VmbUint32_t)m_pImpl->m_features.size();
00163 return VmbErrorSuccess;
00164 }
00165 else if ( m_pImpl->m_features.size() <= rnSize )
00166 {
00167 VmbUint32_t i = 0;
00168 for ( FeaturePtrMap::iterator iter = m_pImpl->m_features.begin();
00169 m_pImpl->m_features.end() != iter;
00170 ++iter, ++i )
00171 {
00172 pFeatures[i] = iter->second;
00173 }
00174 rnSize = (VmbUint32_t)m_pImpl->m_features.size();
00175 return VmbErrorSuccess;
00176 }
00177 else
00178 {
00179 return VmbErrorMoreData;
00180 }
00181 }
00182 else
00183 {
00184 return (VmbErrorType)res;
00185 }
00186 }
00187
00188 VmbHandle_t FeatureContainer::GetHandle() const
00189 {
00190 return m_pImpl->m_handle;
00191 }
00192
00193 void FeatureContainer::SetHandle( const VmbHandle_t handle )
00194 {
00195 if ( NULL == handle )
00196 {
00197 Reset();
00198 RevokeHandle();
00199 }
00200 else
00201 {
00202 m_pImpl->m_handle = handle;
00203 }
00204 }
00205
00206
00207 void FeatureContainer::RevokeHandle()
00208 {
00209 m_pImpl->m_handle = NULL;
00210 }
00211
00212
00213
00214 void FeatureContainer::Reset()
00215 {
00216 for ( FeaturePtrMap::iterator iter = m_pImpl->m_features.begin();
00217 m_pImpl->m_features.end() != iter;
00218 ++iter)
00219 {
00220 SP_ACCESS( iter->second )->ResetFeatureContainer();
00221 }
00222
00223 m_pImpl->m_features.clear();
00224 m_pImpl->m_bAllFeaturesFetched = false;
00225 }
00226
00227 }}