00001 /* 00002 * Copyright (C) 2003-2009 Olivier Boudeville 00003 * 00004 * This file is part of the Ceylan library. 00005 * 00006 * The Ceylan library is free software: you can redistribute it and/or modify 00007 * it under the terms of either the GNU Lesser General Public License or 00008 * the GNU General Public License, as they are published by the Free Software 00009 * Foundation, either version 3 of these Licenses, or (at your option) 00010 * any later version. 00011 * 00012 * The Ceylan library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU Lesser General Public License and the GNU General Public License 00016 * for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License and the GNU General Public License along with the Ceylan library. 00020 * If not, see <http://www.gnu.org/licenses/>. 00021 * 00022 * Author: Olivier Boudeville (olivier.boudeville@esperide.com) 00023 * 00024 */ 00025 00026 00027 #include "CeylanFeatures.h" 00028 00029 #include "CeylanStringUtils.h" 00030 #include "CeylanOperators.h" 00031 00032 00033 #ifdef CEYLAN_USES_CONFIG_H 00034 #include "CeylanConfig.h" // for configure-time settings 00035 #endif // CEYLAN_USES_CONFIG_H 00036 00037 00038 #include <list> 00039 using std::list ; 00040 00041 00042 using std::string ; 00043 00044 using namespace Ceylan ; 00045 using namespace Ceylan::Features ; 00046 00047 00048 00049 // Binary masks for feature selection must not overlap. 00050 00051 00052 /* 00053 * The regular expression support feature, linked with preprocessor symbol 00054 * CEYLAN_USES_REGEX. 00055 * 00056 * Equal to 0b00000000000000000000000000000001. 00057 * 00058 */ 00059 const Flags Features::RegularExpressions = 0x00000001 ; 00060 00061 00062 00063 /* 00064 * The multithreading support feature, linked with preprocessor symbol 00065 * CEYLAN_USES_THREADS 00066 * 00067 * Equal to 0b00000000000000000000000000000010. 00068 * 00069 */ 00070 const Flags Features::Multithreading = 0x00000002 ; 00071 00072 00073 00074 /* 00075 * The network support feature, linked with preprocessor symbol 00076 * CEYLAN_USES_NETWORK. 00077 * 00078 * Equal to 0b00000000000000000000000000000100. 00079 * 00080 */ 00081 const Flags Features::Networking = 0x00000004 ; 00082 00083 00084 00085 /* 00086 * The file descriptor support feature, linked with preprocessor symbol 00087 * CEYLAN_USES_FILE_DESCRIPTORS. 00088 * 00089 * Equal to 0b00000000000000000000000000001000. 00090 * 00091 */ 00092 const Flags Features::FileDescriptors = 0x00000008 ; 00093 00094 00095 00096 /* 00097 * The symbolic link support feature, linked with preprocessor symbol 00098 * CEYLAN_USES_SYMBOLIC_LINKS. 00099 * 00100 * Equal to 0b00000000000000000000000000010000. 00101 * 00102 */ 00103 const Flags Features::SymbolicLinks = 0x00000010 ; 00104 00105 00106 00107 /* 00108 * The advanced file attribute feature, linked with preprocessor symbol 00109 * CEYLAN_USES_ADVANCED_FILE_ATTRIBUTES. 00110 * 00111 * Equal to 0b00000000000000000000000000100000. 00112 * 00113 */ 00114 const Flags Features::AdvancedFileAttributes = 0x00000020 ; 00115 00116 00117 00118 /* 00119 * The symbolic link support feature, linked with preprocessor symbol 00120 * CEYLAN_USES_FILE_LOCKS. 00121 * 00122 * Equal to 0b00000000000000000000000001000000. 00123 * 00124 */ 00125 const Flags Features::FileLocks = 0x00000040 ; 00126 00127 00128 00129 /* 00130 * The advanced process management feature, linked with preprocessor symbol 00131 * CEYLAN_USES_ADVANCED_PROCESS_MANAGEMENT. 00132 * 00133 * Equal to 0b00000000000000000000000010000000. 00134 * 00135 */ 00136 const Flags Features::AdvancedProcessManagement = 0x00000080 ; 00137 00138 00139 00140 /* 00141 * The plugin feature, linked with preprocessor symbol 00142 * CEYLAN_USES_PLUGINS. 00143 * 00144 * Equal to 0b00000000000000000000000100000000. 00145 * 00146 */ 00147 const Flags Features::Plugins = 0x00000100 ; 00148 00149 00150 00151 /* 00152 * The signal feature, linked with preprocessor symbol 00153 * CEYLAN_USES_SIGNALS. 00154 * 00155 * Equal to 0b00000000000000000000001000000000. 00156 * 00157 */ 00158 const Flags Features::Signals = 0x00000200 ; 00159 00160 00161 00162 00163 FeatureNotAvailableException::FeatureNotAvailableException( 00164 const std::string & message ) : 00165 Ceylan::Exception( message ) 00166 { 00167 00168 } 00169 00170 00171 00172 FeatureNotAvailableException::~FeatureNotAvailableException() throw() 00173 { 00174 00175 } 00176 00177 00178 00179 void Features::checkForSupportedFeatures( Flags featuresFlag ) 00180 { 00181 00182 string endOfMessage = " feature not supported by the version " 00183 "of the Ceylan library currently linked." ; 00184 00185 // Test in turn all specified features: 00186 00187 if ( featuresFlag & RegularExpressions ) 00188 { 00189 if ( ! areRegularExpressionsSupported() ) 00190 throw FeatureNotAvailableException( "Regular expression" 00191 + endOfMessage ) ; 00192 } 00193 00194 00195 00196 if ( featuresFlag & Multithreading ) 00197 { 00198 if ( ! isMultithreadingSupported() ) 00199 throw FeatureNotAvailableException( "Multithreading" 00200 + endOfMessage ) ; 00201 } 00202 00203 00204 00205 if ( featuresFlag & Networking ) 00206 { 00207 if ( ! isNetworkingSupported() ) 00208 throw FeatureNotAvailableException( "Networking" + endOfMessage ) ; 00209 00210 } 00211 00212 00213 00214 if ( featuresFlag & FileDescriptors ) 00215 { 00216 if ( ! areFileDescriptorsSupported() ) 00217 throw FeatureNotAvailableException( "File descriptor" 00218 + endOfMessage ) ; 00219 } 00220 00221 00222 00223 if ( featuresFlag & SymbolicLinks ) 00224 { 00225 if ( ! areSymbolicLinksSupported() ) 00226 throw FeatureNotAvailableException( "Symbolic link" 00227 + endOfMessage ) ; 00228 } 00229 00230 00231 00232 if ( featuresFlag & AdvancedFileAttributes ) 00233 { 00234 if ( ! areAdvancedFileAttributesSupported() ) 00235 throw FeatureNotAvailableException( "Advanced file attribute" 00236 + endOfMessage ) ; 00237 } 00238 00239 00240 00241 if ( featuresFlag & FileLocks ) 00242 { 00243 if ( ! areFileLocksSupported() ) 00244 throw FeatureNotAvailableException( "File lock" + endOfMessage ) ; 00245 } 00246 00247 00248 00249 if ( featuresFlag & AdvancedProcessManagement ) 00250 { 00251 if ( ! isAdvancedProcessManagementSupported() ) 00252 throw FeatureNotAvailableException( 00253 "Advanced process management" + endOfMessage ) ; 00254 } 00255 00256 00257 00258 if ( featuresFlag & AdvancedProcessManagement ) 00259 { 00260 if ( ! arePluginsSupported() ) 00261 throw FeatureNotAvailableException( "Plugin" + endOfMessage ) ; 00262 00263 } 00264 00265 00266 00267 if ( featuresFlag & Signals ) 00268 { 00269 if ( ! areSignalsSupported() ) 00270 throw FeatureNotAvailableException( "Signal" + endOfMessage ) ; 00271 00272 } 00273 00274 00275 } 00276 00277 00278 00279 bool Features::areRegularExpressionsSupported() 00280 { 00281 00282 #if CEYLAN_USES_REGEX 00283 return true ; 00284 #else // CEYLAN_USES_REGEX 00285 return false ; 00286 #endif // CEYLAN_USES_REGEX 00287 00288 } 00289 00290 00291 00292 bool Features::isMultithreadingSupported() 00293 { 00294 00295 #if CEYLAN_USES_THREADS 00296 return true ; 00297 #else // CEYLAN_USES_THREADS 00298 return false ; 00299 #endif // CEYLAN_USES_THREADS 00300 00301 } 00302 00303 00304 00305 bool Features::isNetworkingSupported() 00306 { 00307 00308 #if CEYLAN_USES_NETWORK 00309 return true ; 00310 #else // CEYLAN_USES_NETWORK 00311 return false ; 00312 #endif // CEYLAN_USES_NETWORK 00313 00314 } 00315 00316 00317 00318 bool Features::areFileDescriptorsSupported() 00319 { 00320 00321 #if CEYLAN_USES_FILE_DESCRIPTORS 00322 return true ; 00323 #else // CEYLAN_USES_FILE_DESCRIPTORS 00324 return false ; 00325 #endif // CEYLAN_USES_FILE_DESCRIPTORS 00326 00327 } 00328 00329 00330 00331 bool Features::areSymbolicLinksSupported() 00332 { 00333 00334 #if CEYLAN_USES_SYMBOLIC_LINKS 00335 return true ; 00336 #else // CEYLAN_USES_SYMBOLIC_LINKS 00337 return false ; 00338 #endif // CEYLAN_USES_SYMBOLIC_LINKS 00339 00340 } 00341 00342 00343 00344 bool Features::areAdvancedFileAttributesSupported() 00345 { 00346 00347 #if CEYLAN_USES_ADVANCED_FILE_ATTRIBUTES 00348 return true ; 00349 #else // CEYLAN_USES_ADVANCED_FILE_ATTRIBUTES 00350 return false ; 00351 #endif // CEYLAN_USES_ADVANCED_FILE_ATTRIBUTES 00352 00353 } 00354 00355 00356 00357 bool Features::areFileLocksSupported() 00358 { 00359 00360 #if CEYLAN_USES_FILE_LOCKS 00361 return true ; 00362 #else // CEYLAN_USES_FILE_LOCKS 00363 return false ; 00364 #endif // CEYLAN_USES_FILE_LOCKS 00365 00366 } 00367 00368 00369 00370 bool Features::isAdvancedProcessManagementSupported() 00371 { 00372 00373 #if CEYLAN_USES_ADVANCED_PROCESS_MANAGEMENT 00374 return true ; 00375 #else // CEYLAN_USES_ADVANCED_PROCESS_MANAGEMENT 00376 return false ; 00377 #endif // CEYLAN_USES_ADVANCED_PROCESS_MANAGEMENT 00378 00379 } 00380 00381 00382 00383 bool Features::arePluginsSupported() 00384 { 00385 00386 #if CEYLAN_USES_PLUGINS 00387 return true ; 00388 #else // CEYLAN_USES_PLUGINS 00389 return false ; 00390 #endif // CEYLAN_USES_PLUGINS 00391 00392 } 00393 00394 00395 00396 bool Features::areSignalsSupported() 00397 { 00398 00399 #if CEYLAN_USES_SIGNALS 00400 return true ; 00401 #else // CEYLAN_USES_SIGNALS 00402 return false ; 00403 #endif // CEYLAN_USES_SIGNALS 00404 00405 } 00406 00407 00408 const std::string Features::describeAvailableFeatures() 00409 { 00410 00411 list<string> featureList ; 00412 00413 if ( areRegularExpressionsSupported() ) 00414 featureList.push_back( "Regular expressions are supported" ) ; 00415 else 00416 featureList.push_back( "Regular expressions not supported" ) ; 00417 00418 00419 if ( isMultithreadingSupported() ) 00420 featureList.push_back( "Multithreading is supported" ) ; 00421 else 00422 featureList.push_back( "Multithreading not supported" ) ; 00423 00424 00425 if ( isNetworkingSupported() ) 00426 featureList.push_back( "Networking supported" ) ; 00427 else 00428 featureList.push_back( "Networking not supported" ) ; 00429 00430 00431 if ( areFileDescriptorsSupported() ) 00432 featureList.push_back( "File descriptors are supported" ) ; 00433 else 00434 featureList.push_back( "File descriptors not supported" ) ; 00435 00436 00437 if ( areSymbolicLinksSupported() ) 00438 featureList.push_back( "Symbolic links are supported" ) ; 00439 else 00440 featureList.push_back( "Symbolic links not supported" ) ; 00441 00442 00443 if ( areAdvancedFileAttributesSupported() ) 00444 featureList.push_back( "Advanced file attributes are supported" ) ; 00445 else 00446 featureList.push_back( "Advanced file attributes not supported" ) ; 00447 00448 00449 if ( areFileLocksSupported() ) 00450 featureList.push_back( "File locks are supported" ) ; 00451 else 00452 featureList.push_back( "File locks not supported" ) ; 00453 00454 00455 if ( isAdvancedProcessManagementSupported() ) 00456 featureList.push_back( "Advanced process management is supported" ) ; 00457 else 00458 featureList.push_back( "Advanced process management not supported" ) ; 00459 00460 00461 if ( arePluginsSupported() ) 00462 featureList.push_back( "Plugins are supported" ) ; 00463 else 00464 featureList.push_back( "Plugins are not supported" ) ; 00465 00466 00467 if ( areSignalsSupported() ) 00468 featureList.push_back( "Signals are supported" ) ; 00469 else 00470 featureList.push_back( "Signals are not supported" ) ; 00471 00472 00473 return "Summary of optional features available with " 00474 "the Ceylan library currently linked:" 00475 + Ceylan::formatStringList( featureList ) ; 00476 00477 } 00478