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
00029 #include <VimbaCPP/Source/EnumFeature.h>
00030 #include <memory.h>
00031
00032 namespace AVT {
00033 namespace VmbAPI {
00034
00035 EnumFeature::EnumFeature( const VmbFeatureInfo_t *featureInfo, FeatureContainer* const pFeatureContainer )
00036 :BaseFeature( featureInfo, pFeatureContainer )
00037 {
00038 }
00039
00040 VmbErrorType EnumFeature::GetValue( char * const pStrValue, VmbUint32_t &rnSize ) const
00041 {
00042 VmbErrorType res;
00043 if ( NULL == m_pFeatureContainer )
00044 {
00045 return VmbErrorDeviceNotOpen;
00046 }
00047
00048 const char* pStrTempValue;
00049 res = (VmbErrorType)VmbFeatureEnumGet( m_pFeatureContainer->GetHandle(), m_featureInfo.name.c_str(), &pStrTempValue );
00050
00051 if ( VmbErrorSuccess == res )
00052 {
00053 VmbUint32_t nLength=0;
00054 while ( pStrTempValue[nLength] != '\0' )
00055 {
00056 ++nLength;
00057 }
00058
00059 if ( NULL == pStrValue )
00060 {
00061 rnSize = nLength;
00062 }
00063 else if ( nLength <= rnSize )
00064 {
00065 ::memcpy( pStrValue, pStrTempValue, (size_t)nLength );
00066 rnSize = nLength;
00067 }
00068 else
00069 {
00070 res = VmbErrorMoreData;
00071 }
00072 }
00073
00074 return res;
00075 }
00076
00077 VmbErrorType EnumFeature::GetValue( VmbInt64_t &rnValue ) const
00078 {
00079 if ( NULL == m_pFeatureContainer )
00080 {
00081 return VmbErrorDeviceNotOpen;
00082 }
00083
00084 const char *pName = NULL;
00085 VmbError_t res = VmbFeatureEnumGet( m_pFeatureContainer->GetHandle(), m_featureInfo.name.c_str(), &pName );
00086 if ( VmbErrorSuccess == res )
00087 {
00088 res = VmbFeatureEnumAsInt( m_pFeatureContainer->GetHandle(), m_featureInfo.name.c_str(), pName, &rnValue );
00089 }
00090
00091 return (VmbErrorType)res;
00092 }
00093
00094 VmbErrorType EnumFeature::GetEntry( EnumEntry &rEntry, const char * pStrEntryName ) const
00095 {
00096 if ( NULL == m_pFeatureContainer )
00097 {
00098 return VmbErrorDeviceNotOpen;
00099 }
00100
00101 VmbFeatureEnumEntry_t entry;
00102 VmbError_t res = VmbFeatureEnumEntryGet( m_pFeatureContainer->GetHandle(), m_featureInfo.name.c_str(), pStrEntryName, &entry, sizeof( VmbFeatureEnumEntry_t ));
00103 if ( VmbErrorSuccess == res )
00104 {
00105 rEntry = EnumEntry( entry.name, entry.displayName, entry.description, entry.tooltip, entry.sfncNamespace, entry.visibility, entry.intValue );
00106 }
00107
00108 return (VmbErrorType)res;
00109 }
00110
00111 VmbErrorType EnumFeature::SetValue( const char *pStrValue )
00112 {
00113 if ( NULL == m_pFeatureContainer )
00114 {
00115 return VmbErrorDeviceNotOpen;
00116 }
00117
00118 return (VmbErrorType)VmbFeatureEnumSet( m_pFeatureContainer->GetHandle(), m_featureInfo.name.c_str(), pStrValue );
00119 }
00120
00121 VmbErrorType EnumFeature::SetValue( const VmbInt64_t &rnValue )
00122 {
00123 if ( NULL == m_pFeatureContainer )
00124 {
00125 return VmbErrorDeviceNotOpen;
00126 }
00127
00128 const char *pName = NULL;
00129 VmbError_t res = VmbFeatureEnumAsString( m_pFeatureContainer->GetHandle(), m_featureInfo.name.c_str(), rnValue, &pName );
00130 if ( VmbErrorSuccess == res )
00131 {
00132 res = VmbFeatureEnumSet( m_pFeatureContainer->GetHandle(), m_featureInfo.name.c_str(), pName );
00133 }
00134
00135 return (VmbErrorType)res;
00136 }
00137
00138 VmbErrorType EnumFeature::GetValues( const char **pRange, VmbUint32_t &rnSize )
00139 {
00140 if ( NULL == m_pFeatureContainer )
00141 {
00142 return VmbErrorDeviceNotOpen;
00143 }
00144
00145 VmbUint32_t nCount = 0;
00146 VmbError_t res = VmbFeatureEnumRangeQuery( m_pFeatureContainer->GetHandle(), m_featureInfo.name.c_str(), NULL, 0, &nCount );
00147
00148 if ( VmbErrorSuccess == res
00149 && 0 < nCount )
00150 {
00151 std::vector<const char*> data( nCount );
00152
00153 res = VmbFeatureEnumRangeQuery( m_pFeatureContainer->GetHandle(), m_featureInfo.name.c_str(), &data[0], nCount, &nCount );
00154
00155 if ( VmbErrorSuccess == res )
00156 {
00157 m_EnumStringValues.clear();
00158
00159 for ( std::vector<const char*>::iterator iter = data.begin();
00160 data.end() != iter;
00161 ++iter )
00162 {
00163 m_EnumStringValues.push_back( std::string( *iter ));
00164 }
00165
00166 if ( NULL == pRange )
00167 {
00168 rnSize = (VmbUint32_t)m_EnumStringValues.size();
00169 res = VmbErrorSuccess;
00170 }
00171 else if ( m_EnumStringValues.size() <= rnSize )
00172 {
00173 VmbUint32_t i = 0;
00174 for ( StringVector::iterator iter = m_EnumStringValues.begin();
00175 m_EnumStringValues.end() != iter;
00176 ++iter, ++i )
00177 {
00178 pRange[i] = iter->c_str();
00179 }
00180 rnSize = (VmbUint32_t)m_EnumStringValues.size();
00181 res = VmbErrorSuccess;
00182 }
00183 else
00184 {
00185 res = VmbErrorMoreData;
00186 }
00187 }
00188 }
00189
00190 return (VmbErrorType)res;
00191 }
00192
00193 VmbErrorType EnumFeature::GetValues( VmbInt64_t *pValues, VmbUint32_t &rnSize )
00194 {
00195 if ( NULL == m_pFeatureContainer )
00196 {
00197 return VmbErrorDeviceNotOpen;
00198 }
00199
00200 VmbUint32_t nCount = 0;
00201 VmbError_t res = GetValues( (const char**)NULL, nCount );
00202
00203 if ( VmbErrorSuccess == res
00204 && 0 < nCount )
00205 {
00206 std::vector<const char*> data( nCount );
00207
00208 res = GetValues( &data[0], nCount );
00209
00210 if ( VmbErrorSuccess == res )
00211 {
00212 m_EnumIntValues.clear();
00213
00214 VmbInt64_t nValue;
00215 for ( std::vector<const char*>::iterator iter = data.begin();
00216 data.end() != iter;
00217 ++iter )
00218 {
00219 res = VmbFeatureEnumAsInt( m_pFeatureContainer->GetHandle(), m_featureInfo.name.c_str(), (*iter), &nValue );
00220
00221 if ( VmbErrorSuccess == res )
00222 {
00223 m_EnumIntValues.push_back( nValue );
00224 }
00225 else
00226 {
00227 m_EnumIntValues.clear();
00228 break;
00229 }
00230 }
00231
00232 if ( VmbErrorSuccess == res )
00233 {
00234 if ( NULL == pValues )
00235 {
00236 rnSize = (VmbUint32_t)m_EnumIntValues.size();
00237 }
00238 else if ( m_EnumIntValues.size() <= rnSize )
00239 {
00240 VmbUint32_t i = 0;
00241 for ( Int64Vector::iterator iter = m_EnumIntValues.begin();
00242 m_EnumIntValues.end() != iter;
00243 ++iter, ++i )
00244 {
00245 pValues[i] = (*iter);
00246 }
00247 rnSize = (VmbUint32_t)m_EnumIntValues.size();
00248 }
00249 else
00250 {
00251 res = VmbErrorMoreData;
00252 }
00253 }
00254 }
00255 }
00256
00257 return (VmbErrorType)res;
00258 }
00259
00260 VmbErrorType EnumFeature::GetEntries( EnumEntry *pEntries, VmbUint32_t &rnSize )
00261 {
00262 VmbErrorType res = GetValues( (const char**)NULL, rnSize );
00263
00264 if ( 0 < m_EnumStringValues.size()
00265 && VmbErrorSuccess == res )
00266 {
00267 m_EnumEntries.clear();
00268
00269 for ( StringVector::iterator iter = m_EnumStringValues.begin();
00270 m_EnumStringValues.end() != iter;
00271 ++iter )
00272 {
00273 EnumEntry entry;
00274 res = GetEntry( entry, (*iter).c_str() );
00275 if ( VmbErrorSuccess == res )
00276 {
00277 m_EnumEntries.push_back( entry );
00278 }
00279 else
00280 {
00281 m_EnumEntries.clear();
00282 break;
00283 }
00284 }
00285
00286 if ( VmbErrorSuccess == res )
00287 {
00288 if ( NULL == pEntries )
00289 {
00290 rnSize = (VmbUint32_t)m_EnumEntries.size();
00291 }
00292 else if ( m_EnumEntries.size() <= rnSize )
00293 {
00294 VmbUint32_t i = 0;
00295 for ( EnumEntryVector::iterator iter = m_EnumEntries.begin();
00296 m_EnumEntries.end() != iter;
00297 ++iter, ++i )
00298 {
00299 pEntries[i] = (*iter);
00300 }
00301 rnSize = (VmbUint32_t)m_EnumIntValues.size();
00302 }
00303 else
00304 {
00305 res = VmbErrorMoreData;
00306 }
00307 }
00308 }
00309
00310 return res;
00311 }
00312
00313 VmbErrorType EnumFeature::IsValueAvailable( const char *pStrValue, bool &bAvailable ) const
00314 {
00315 if ( NULL == m_pFeatureContainer )
00316 {
00317 return VmbErrorDeviceNotOpen;
00318 }
00319
00320 return (VmbErrorType)VmbFeatureEnumIsAvailable( m_pFeatureContainer->GetHandle(), m_featureInfo.name.c_str(), pStrValue, &bAvailable );
00321 }
00322
00323 VmbErrorType EnumFeature::IsValueAvailable( const VmbInt64_t nValue, bool &rbAvailable ) const
00324 {
00325 if ( NULL == m_pFeatureContainer )
00326 {
00327 return VmbErrorDeviceNotOpen;
00328 }
00329
00330 const char* pName = NULL;
00331 VmbError_t res = VmbFeatureEnumAsString( m_pFeatureContainer->GetHandle(), m_featureInfo.name.c_str(), nValue, &pName );
00332 if ( VmbErrorSuccess == res )
00333 {
00334 res = IsValueAvailable( pName, rbAvailable );
00335 }
00336
00337 return (VmbErrorType)res;
00338 }
00339
00340 }}
00341