Changeset 20847

Show
Ignore:
Timestamp:
09/24/07 16:42:38 (1 year ago)
Author:
patrick
Message:

Use Boost.Filesystem to remove a lot of UNIX-isms from the plug-in search
code.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • juggler/branches/2.2/modules/sonix/snx/SoundFactory.cpp

    r20363 r20847  
    4545#include <vpr/vpr.h> 
    4646#include <vpr/System.h> 
    47 #include <vpr/Util/FileUtils.h> 
    4847#include <vpr/DynLoad/LibraryFinder.h> 
    4948 
     
    5453#include <snx/SoundFactory.h> /* my header. */ 
    5554 
     55 
     56namespace fs = boost::filesystem; 
    5657 
    5758namespace snx 
     
    8283SoundFactory::SoundFactory() 
    8384{ 
    84    std::vector<std::string> search_paths; 
    85  
    8685   const std::string envvar("SNX_BASE_DIR"); 
    87    std::string dummy_result
    88  
    89    if ( ! vpr::System::getenv(envvar, dummy_result) ) 
     86   std::string base_dir_env
     87 
     88   if ( ! vpr::System::getenv(envvar, base_dir_env) ) 
    9089   { 
    9190      vprDEBUG(snxDBG, vprDBG_WARNING_LVL) 
     
    9695   } 
    9796 
     97   const fs::path snx_base_dir(base_dir_env, fs::native); 
     98 
    9899#if defined(VPR_OS_IRIX) && defined(_ABIN32) 
    99    std::string snx_base_dir("${SNX_BASE_DIR}/lib32/")
     100   const fs::path snx_lib_dir = snx_base_dir / "lib32"
    100101#elif defined(VPR_OS_IRIX) && defined(_ABI64) || \ 
    101102      defined(VPR_OS_Linux) && defined(__x86_64__) 
    102    std::string snx_base_dir("${SNX_BASE_DIR}/lib64/"); 
    103 #else 
    104    std::string snx_base_dir("${SNX_BASE_DIR}/lib/"); 
    105 #endif 
    106  
     103   const fs::path snx_lib_dir = snx_base_dir / "lib64"; 
     104#else 
     105   const fs::path snx_lib_dir = snx_base_dir / "lib"; 
     106#endif 
    107107 
    108108#if defined(VPR_OS_Windows) 
     
    130130   } 
    131131 
    132    std::string sonix_subdir(sonix_subdir_base + std::string("-") + 
    133                              sonix_ver_str + "/plugins/"); 
     132   fs::path sonix_subdir( 
     133      snx_lib_dir / (sonix_subdir_base + "-" + sonix_ver_str) / "plugins" 
     134   ); 
    134135 
    135136   // If versioning is not enabled, then the directory containing the 
    136137   // Sonix plug-ins will not incorporate version information. 
    137138#else 
    138    std::string sonix_subdir(sonix_subdir_base + "/plugins/"); 
     139   fs::path sonix_subdir(snx_lib_dir / sonix_subdir_base / "plugins"); 
    139140#endif 
    140141 
    141142#if defined(SNX_DEBUG) 
    142143#if defined(_DEBUG) 
    143    std::string sonix_path(snx_base_dir + sonix_subdir + "dbgrt"); 
    144 #else 
    145    std::string sonix_path(snx_base_dir + sonix_subdir + "dbg"); 
    146 #endif 
    147 #else 
    148    std::string sonix_path(snx_base_dir + sonix_subdir + "opt"); 
    149 #endif 
    150  
    151    search_paths.push_back(sonix_path); 
    152  
    153    search_paths.push_back("${HOME}/.sonix/plugins"); 
    154  
    155    for (unsigned int x = 0; x < search_paths.size(); ++x) 
    156    { 
    157       search_paths[x] = vpr::replaceEnvVars(search_paths[x]); 
    158       vprDEBUG(snxDBG, vprDBG_CONFIG_LVL) << "Finding plugins in " 
    159                                           << search_paths[x] << std::endl 
    160                                           << vprDEBUG_FLUSH; 
     144   sonix_subdir /= "dbgrt"; 
     145#else 
     146   sonix_subdir /= "dbg"; 
     147#endif 
     148#else 
     149   sonix_subdir /= "opt"; 
     150#endif 
     151 
     152   std::vector<fs::path> search_paths; 
     153   search_paths.push_back(sonix_subdir); 
     154 
     155   std::string home_dir; 
     156   if ( vpr::System::getenv("HOME", home_dir) ) 
     157   { 
     158      search_paths.push_back( 
     159         fs::path(home_dir, fs::native) / ".sonix" / "plugins" 
     160      ); 
     161   } 
     162 
     163   typedef std::vector<fs::path>::iterator iter_type; 
     164   for ( iter_type p = search_paths.begin(); p != search_paths.end(); ++p ) 
     165   { 
     166      const std::string cur_dir = (*p).native_directory_string(); 
     167      vprDEBUG(snxDBG, vprDBG_CONFIG_LVL) << "Finding plug-ins in " << cur_dir 
     168                                          << std::endl << vprDEBUG_FLUSH; 
    161169 
    162170      try 
    163171      { 
    164          boost::filesystem::path dirPath(search_paths[x], boost::filesystem::native); 
    165          if (boost::filesystem::exists(dirPath)) 
     172         if ( fs::exists(*p) ) 
    166173         { 
    167             vpr::LibraryFinder finder(search_paths[x], driver_ext); 
     174            vpr::LibraryFinder finder(cur_dir, driver_ext); 
    168175            vpr::LibraryFinder::LibraryList libs = finder.getLibraries(); 
    169             this->loadPlugins( libs ); 
     176            this->loadPlugins(libs); 
    170177 
    171178#ifdef SNX_DEBUG 
    172             vprDEBUG(snxDBG, vprDBG_CONFIG_LVL) << "filelist:\n" 
     179            vprDEBUG(snxDBG, vprDBG_CONFIG_LVL) << "Plug-in file list:\n" 
    173180                                                << vprDEBUG_FLUSH; 
    174181            for ( unsigned int i = 0; i < libs.size(); ++i ) 
    175182            { 
    176                vprDEBUG(snxDBG, vprDBG_CONFIG_LVL) << "\t" << libs[i] 
    177                                                    << std::endl 
    178                                                    << vprDEBUG_FLUSH; 
     183               vprDEBUG_NEXT(snxDBG, vprDBG_CRITICAL_LVL)  
     184                  << libs[i]->getName() << std::endl << vprDEBUG_FLUSH; 
    179185            } 
    180186#endif 
     
    183189         { 
    184190            vprDEBUG(snxDBG, vprDBG_STATE_LVL) 
    185                << "The directory does not exist: '" << search_paths[x] << "'\n" 
     191               << "The directory does not exist: '" << cur_dir << "'\n" 
    186192               << vprDEBUG_FLUSH; 
    187193         } 
    188194      } 
    189       catch (boost::filesystem::filesystem_error& fsEx) 
     195      catch (fs::filesystem_error& fsEx) 
    190196      { 
    191197         vprDEBUG(snxDBG, vprDBG_CRITICAL_LVL)