factory.cpp

00001 /*
00002  *  TOPPERS/FDMP Kernel
00003  *      Toyohashi Open Platform for Embedded Real-Time Systems/
00004  *      Function Distributed Multiprocessor Kernel
00005  *
00006  *  Copyright (C) 2004 by Witz Corporation, JAPAN  
00007  *  Copyright (C) 2005 by Takagi Nobuhisa
00008  * 
00009  *  上記著作権者は,以下の (1)〜(4) の条件か,Free Software Foundation 
00010  *  によって公表されている GNU General Public License の Version 2 に記
00011  *  述されている条件を満たす場合に限り,本ソフトウェア(本ソフトウェア
00012  *  を改変したものを含む.以下同じ)を使用・複製・改変・再配布(以下,
00013  *  利用と呼ぶ)することを無償で許諾する.
00014  *  (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
00015  *      権表示,この利用条件および下記の無保証規定が,そのままの形でソー
00016  *      スコード中に含まれていること.
00017  *  (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
00018  *      用できる形で再配布する場合には,再配布に伴うドキュメント(利用
00019  *      者マニュアルなど)に,上記の著作権表示,この利用条件および下記
00020  *      の無保証規定を掲載すること.
00021  *  (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
00022  *      用できない形で再配布する場合には,次のいずれかの条件を満たすこ
00023  *      と.
00024  *    (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
00025  *        作権表示,この利用条件および下記の無保証規定を掲載すること.
00026  *    (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
00027  *        報告すること.
00028  *  (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
00029  *      害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
00030  * 
00031  *  本ソフトウェアは,無保証で提供されているものである.上記著作権者お
00032  *  よびTOPPERSプロジェクトは,本ソフトウェアに関して,その適用可能性も
00033  *  含めて,いかなる保証も行わない.また,本ソフトウェアの利用により直
00034  *  接的または間接的に生じたいかなる損害に関しても,その責任を負わない.
00035  * 
00036  */
00037 
00038 /*
00039  *  toppers/factory.cpp
00040  */
00041 #include "toppers/factory.hpp"
00042 #include "toppers/reporter.hpp"
00043 #include <boost/filesystem/path.hpp>
00044 #include <boost/filesystem/operations.hpp>
00045 #include <boost/filesystem/exception.hpp>
00046 
00047 namespace toppers
00048 {
00049 
00055   factory::factory( const cmdline::option_array& options, const std::string& version )
00056     : options_( new cmdline::option_array( options ) ), version_( version )
00057   {
00058   }
00059 
00064   const boost::shared_ptr<kernel_id> factory::create_kernel_id() const
00065   {
00066     return do_create_kernel_id( get_cfg_file_name( "-id", "kernel_id.h" ) );
00067   }
00068 
00073   const boost::shared_ptr<kernel_cfg> factory::create_kernel_cfg() const
00074   {
00075     std::string file( get_cfg_file_name( "-cfg", "kernel_cfg.c" ) );
00076 
00077     // get_cfg_file_name を使うと、-nオプションによるディレクトリ名が付随してくるので、
00078     // ここでは使用できない
00079     std::string id_file( "kernel_id.h" );
00080     options_->find( "-id", id_file );
00081 
00082     return do_create_kernel_cfg( file, id_file );
00083   }
00084 
00089   const boost::shared_ptr<std::vector<factory::kernel_cfg_generator_type> > factory::create_kernel_cfg_generators() const
00090   {
00091     return do_create_kernel_cfg_generators();
00092   }
00093 
00098   const boost::shared_ptr<std::vector<factory::kernel_id_generator_type> > factory::create_kernel_id_generators() const
00099   {
00100     return do_create_kernel_id_generators();
00101   }
00102 
00107   const boost::shared_ptr<cmdline::option_array>& factory::options() const
00108   {
00109     return options_;
00110   }
00111 
00116   const std::string& factory::version() const
00117   {
00118     return version_;
00119   }
00120 
00132   const std::string factory::get_cfg_file_name( const std::string& option, const std::string& default_name ) const
00133   {
00134     std::string file;
00135     options_->find( option, file );
00136     if ( file.empty() )
00137     {
00138       file = default_name;
00139     }
00140     return get_cfg_file_name( file );
00141   }
00142 
00148   const std::string factory::do_get_cfg_file_name( const std::string& file ) const
00149   {
00150     boost::filesystem::path file_name( file, boost::filesystem::native );
00151     if ( !file_name.has_root_path() )
00152     {
00153       std::string dir_name;
00154       if ( options_->find( "-n", dir_name ) && !dir_name.empty() )
00155       {
00156         create_sub_directory( dir_name );
00157         boost::filesystem::path dir( dir_name, boost::filesystem::native );
00158         file_name = dir/file_name;
00159       }
00160     }
00161     return file_name.native_file_string();
00162   }
00163 
00168   void factory::create_sub_directory( const std::string& dir )
00169   {
00170     boost::filesystem::path path( dir, boost::filesystem::native );
00171     if ( exists( path ) )
00172     {
00173       if ( !is_directory( path ) )
00174       {
00175         rout.error( _( "%1% is not directory" ) % path.string() );
00176       }
00177     }
00178     else
00179     {
00180       try
00181       {
00182         create_directory( path );
00183       }
00184       catch ( boost::filesystem::filesystem_error& )
00185       {
00186         rout.error( _( "cannot make directory `%1%\'" ) % path.string() );
00187       }
00188     }
00189   }
00190 
00215 }
00216 

Copyright © 2006 by TAKAGI Nobuhisa.
このページは Wed Apr 12 16:31:55 2006 に Doxygen によって生成されました。