Stxxl  1.4.0
mng/config.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002  *  mng/config.cpp
00003  *
00004  *  Part of the STXXL. See http://stxxl.sourceforge.net
00005  *
00006  *  Copyright (C) 2002 Roman Dementiev <dementiev@mpi-sb.mpg.de>
00007  *  Copyright (C) 2007, 2009 Johannes Singler <singler@ira.uka.de>
00008  *  Copyright (C) 2008, 2009 Andreas Beckmann <beckmann@cs.uni-frankfurt.de>
00009  *
00010  *  Distributed under the Boost Software License, Version 1.0.
00011  *  (See accompanying file LICENSE_1_0.txt or copy at
00012  *  http://www.boost.org/LICENSE_1_0.txt)
00013  **************************************************************************/
00014 
00015 #include <fstream>
00016 #include <stxxl/bits/mng/mng.h>
00017 #include <stxxl/version.h>
00018 #include <stxxl/bits/common/log.h>
00019 #include <stxxl/bits/common/error_handling.h>
00020 
00021 #ifdef BOOST_MSVC
00022  #include <windows.h>
00023 #endif
00024 
00025 __STXXL_BEGIN_NAMESPACE
00026 
00027 void config::init(const char * config_path)
00028 {
00029     logger::get_instance();
00030     STXXL_MSG(get_version_string());
00031     std::vector<DiskEntry> flash_props;
00032     std::ifstream cfg_file(config_path);
00033     if (!cfg_file)
00034     {
00035         STXXL_ERRMSG("Warning: no config file found.");
00036         STXXL_ERRMSG("Using default disk configuration.");
00037 #ifndef BOOST_MSVC
00038         DiskEntry entry1 = { "/var/tmp/stxxl", "syscall", 1000 * 1024 * 1024, true, false };
00039 #else
00040         DiskEntry entry1 = { "", "wincall", 1000 * 1024 * 1024, true, false };
00041         char * tmpstr = new char[255];
00042         stxxl_check_ne_0(GetTempPath(255, tmpstr), resource_error);
00043         entry1.path = tmpstr;
00044         entry1.path += "stxxl";
00045         delete[] tmpstr;
00046 #endif
00047 #if 0
00048         DiskEntry entry2 =
00049         { "/tmp/stxxl1", "mmap", 100 * 1024 * 1024, true };
00050         DiskEntry entry3 =
00051         { "/tmp/stxxl2", "simdisk", 1000 * 1024 * 1024, false };
00052 #endif
00053         disks_props.push_back(entry1);
00054         //disks_props.push_back(entry2);
00055         //disks_props.push_back(entry3);
00056     }
00057     else
00058     {
00059         std::string line;
00060 
00061         while (cfg_file >> line)
00062         {
00063             std::vector<std::string> tmp = split(line, "=");
00064             bool is_disk;
00065 
00066             if (tmp[0][0] == '#')
00067             { }
00068             else if ((is_disk = (tmp[0] == "disk")) || tmp[0] == "flash")
00069             {
00070                 tmp = split(tmp[1], ",");
00071                 DiskEntry entry = {
00072                     tmp[0], tmp[2],
00073                     int64(atoi(tmp[1].c_str())) * int64(1024 * 1024),
00074                     false,
00075                     false
00076                 };
00077                 if (entry.size == 0)
00078                     entry.autogrow = true;
00079                 if (is_disk)
00080                     disks_props.push_back(entry);
00081                 else
00082                     flash_props.push_back(entry);
00083             }
00084             else
00085             {
00086                 std::cerr << "Unknown token " <<
00087                 tmp[0] << std::endl;
00088             }
00089         }
00090         cfg_file.close();
00091     }
00092 
00093     // put flash devices after regular disks
00094     first_flash = disks_props.size();
00095     disks_props.insert(disks_props.end(), flash_props.begin(), flash_props.end());
00096 
00097     if (disks_props.empty())
00098         STXXL_THROW(std::runtime_error, "config::config", "No disks found in '" << config_path << "' .");
00099 
00100 #ifdef STXXL_VERBOSE_DISKS
00101     for (std::vector<DiskEntry>::const_iterator it = disks_props.begin(); it != disks_props.end(); it++)
00102     {
00103         STXXL_MSG("Disk '" << (*it).path << "' is allocated, space: " <<
00104                   ((*it).size) / (1024 * 1024) <<
00105                   " MiB, I/O implementation: " << (*it).io_impl);
00106     }
00107 #else
00108     int64 total_size = 0;
00109     for (std::vector<DiskEntry>::const_iterator it = disks_props.begin(); it != disks_props.end(); it++)
00110         total_size += (*it).size;
00111 
00112     STXXL_MSG("" << disks_props.size() << " disks are allocated, total space: " <<
00113               (total_size / (1024 * 1024)) <<
00114               " MiB");
00115 #endif
00116 }
00117 
00118 __STXXL_END_NAMESPACE
00119 // vim: et:ts=4:sw=4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines