User Manual, Developers Guide and API Documentation

OutputPreparation.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002  * This file is part of openWNS (open Wireless Network Simulator)
00003  * _____________________________________________________________________________
00004  *
00005  * Copyright (C) 2004-2007
00006  * Chair of Communication Networks (ComNets)
00007  * Kopernikusstr. 16, D-52074 Aachen, Germany
00008  * phone: ++49-241-80-27910,
00009  * fax: ++49-241-80-22242
00010  * email: info@openwns.org
00011  * www: http://www.openwns.org
00012  * _____________________________________________________________________________
00013  *
00014  * openWNS is free software; you can redistribute it and/or modify it under the
00015  * terms of the GNU Lesser General Public License version 2 as published by the
00016  * Free Software Foundation;
00017  *
00018  * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY
00019  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
00020  * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00021  * details.
00022  *
00023  * You should have received a copy of the GNU Lesser General Public License
00024  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00025  *
00026  ******************************************************************************/
00027 
00028 #include <WNS/simulator/OutputPreparation.hpp>
00029 
00030 #include <boost/date_time/posix_time/posix_time.hpp>
00031 #include <sys/types.h>
00032 #include <sys/stat.h>
00033 #include <errno.h>
00034 #include <stdio.h>
00035 
00036 #include <iomanip>
00037 
00038 using namespace wns::simulator;
00039 
00040 STATIC_FACTORY_REGISTER(Move, OutputPreparationStrategy, "Move");
00041 STATIC_FACTORY_REGISTER(Delete, OutputPreparationStrategy, "Delete");
00042 
00043 void
00044 Move::prepare(const std::string& path)
00045 {
00046     struct stat buf;
00047 
00048     if(-1 == lstat(path.c_str(), &buf)) {
00049             // we encountered problems accessing the output directory.
00050             // the only acceptable error here is ENOENT (the directory
00051             // does not exist.)
00052             // all other errors should probably terminate the simulation.
00053 
00054         if(errno != ENOENT) {
00055             throw(wns::Exception("Couldn't access output directory."));
00056         }
00057     } else {
00058             // now we know the output path already exists.
00059             // let's just move it out of our way.
00060 
00061         boost::posix_time::ptime date(boost::posix_time::second_clock::local_time());
00062 
00063         std::stringstream ss;
00064         ss << path << "." << boost::posix_time::to_simple_string(date);
00065 
00066         rename(path.c_str(), ss.str().c_str());
00067     }
00068 
00069     system(("mkdir -p " + path).c_str());
00070 } // Move::prepare
00071 
00072 
00073 void
00074 Delete::prepare(const std::string& path)
00075 {
00076     system(("rm -fr " + path).c_str());
00077     system(("mkdir " + path).c_str());
00078 } // Delete::prepare
00079 
00080 
00081 
00082 

Generated on Fri May 25 03:31:56 2012 for openWNS by  doxygen 1.5.5