- Added the LOAD command to TextSimulation, and the classic question made to user on replacing an unsaved simulation
- Changed the way syntactically incorrect python policies are handled, we no more exit abruptly git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@829 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
d72ce96508
commit
0138387a7f
8 changed files with 189 additions and 14 deletions
32
src/backend/malformed_policy_exception.cc
Normal file
32
src/backend/malformed_policy_exception.cc
Normal file
|
@ -0,0 +1,32 @@
|
|||
// src/backend/malformed_policy_exception.cc - Copyright 2005, 2006, University
|
||||
// of Padova, dept. of Pure and Applied
|
||||
// Mathematics
|
||||
//
|
||||
// This file is part of SGPEMv2.
|
||||
//
|
||||
// This is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// SGPEMv2 is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with SGPEMv2; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
// Warning! This exception will be thrown across different libraries.
|
||||
// It could be necessary to do dynamic type-checking when
|
||||
// catching it (with typeinfo).
|
||||
|
||||
#include "malformed_policy_exception.hh"
|
||||
using namespace sgpem;
|
||||
|
||||
MalformedPolicyException::MalformedPolicyException(const char* msg)
|
||||
: std::runtime_error(msg)
|
||||
{}
|
||||
|
||||
MalformedPolicyException::~MalformedPolicyException() throw() {}
|
46
src/backend/malformed_policy_exception.hh
Normal file
46
src/backend/malformed_policy_exception.hh
Normal file
|
@ -0,0 +1,46 @@
|
|||
// src/backend/malformed_policy_exception.hh - Copyright 2005, 2006, University
|
||||
// of Padova, dept. of Pure and Applied
|
||||
// Mathematics
|
||||
//
|
||||
// This file is part of SGPEMv2.
|
||||
//
|
||||
// This is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// SGPEMv2 is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with SGPEMv2; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
// Warning! This exception will be thrown across different libraries.
|
||||
// It could be necessary to do dynamic type-checking when
|
||||
// catching it (with typeinfo).
|
||||
|
||||
#ifndef MALFORMED_POLICY_EXCEPTION
|
||||
#define MALFORMED_POLICY_EXCEPTION 1
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
namespace sgpem
|
||||
{
|
||||
class MalformedPolicyException;
|
||||
|
||||
class SG_DLLEXPORT MalformedPolicyException : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
MalformedPolicyException(const char* msg = "");
|
||||
virtual ~MalformedPolicyException() throw ();
|
||||
|
||||
private:
|
||||
};
|
||||
} //~ namespace sgpem
|
||||
|
||||
#endif
|
|
@ -91,7 +91,8 @@ namespace sgpem
|
|||
}
|
||||
|
||||
|
||||
TextSimulation::TextSimulation()
|
||||
TextSimulation::TextSimulation() :
|
||||
_saved(true)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -116,6 +117,35 @@ TextSimulation::check_arguments_num(const Tokens& arguments, unsigned int num)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
TextSimulation::unsaved_ask_confirm() const
|
||||
{
|
||||
if(!_saved)
|
||||
{
|
||||
p_stderr(_("WARNING: Simulation was not recently saved. "
|
||||
"If you continue some changes to the simulation might be lost.\n"));
|
||||
|
||||
for(bool bad_arg = true; bad_arg;)
|
||||
{
|
||||
p_stdout(_("Continue? [y/n] "));
|
||||
|
||||
ustring buf = readline();
|
||||
|
||||
Tokens tokens = tokenize(buf);
|
||||
|
||||
if(tokens.size() == 1 && tokens[0].size() == 1)
|
||||
{
|
||||
if(tokens[0].lowercase() == _("n"))
|
||||
return false;
|
||||
else if(tokens[0].lowercase() == _("y"))
|
||||
bad_arg = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename Container>
|
||||
void
|
||||
TextSimulation::show(const Container& entities)
|
||||
|
@ -459,7 +489,7 @@ TextSimulation::on_help(const Tokens& arguments)
|
|||
if(command.size() == 0)
|
||||
p_stdout(_("Avaiable commands:\nRUN\nSTOP\nPAUSE\n"
|
||||
"CONFIGURE-CPU-POLICY\nHELP\nGET\nSET\nSHOW\nADD\n"
|
||||
"REMOVE\nQUIT\n\n"
|
||||
"REMOVE\nSAVE\nLOAD\nQUIT\n\n"
|
||||
"HELP followed by a command name shows help about it.\n"
|
||||
"ex. `HELP RUN` shows help about the command RUN\n"));
|
||||
else if(command == "RUN")
|
||||
|
@ -520,6 +550,12 @@ TextSimulation::on_help(const Tokens& arguments)
|
|||
"numeric ids follow the same logic of the previous commands\n"
|
||||
"`REMOVE subrequest <process_id> <thread_id> <request_id> <subrequest_id>` where the "
|
||||
"numeric ids follow the same logic of the previous commands\n"));
|
||||
else if(command == "SAVE")
|
||||
p_stderr(_("-- SAVE COMMAND --\nSaves the simulation.\n\n"
|
||||
"Syntax: SAVE <filename>\n"));
|
||||
else if(command == "LOAD")
|
||||
p_stderr(_("-- LOAD COMMAND --\nLoads the simulation.\n\n"
|
||||
"Syntax: LOAD <filename>\n"));
|
||||
else if(command == "QUIT")
|
||||
p_stderr(_("-- QUIT COMMAND --\nGently closes the program.\n"));
|
||||
else
|
||||
|
@ -531,6 +567,9 @@ TextSimulation::on_quit(const Tokens& arguments)
|
|||
{
|
||||
check_arguments_num(arguments, 0);
|
||||
|
||||
if(!unsaved_ask_confirm())
|
||||
return;
|
||||
|
||||
p_stdout(_("\n\n*** Thank you for using SGPEM by Sirius Cybernetics Corporation ***\n\n"));
|
||||
|
||||
// Is this ok? Really? Oh, sure, if it we always did it in this way, it is surely a Good Thing!
|
||||
|
@ -1303,11 +1342,53 @@ TextSimulation::on_save(const Tokens& arguments)
|
|||
vector<Serializer*> serializers =
|
||||
SerializersGatekeeper::get_instance().get_registered();
|
||||
|
||||
// FIXME using the first serializer available, this
|
||||
// will need to be changed when multiple serializers will
|
||||
// be made available
|
||||
Serializer& serializer = *serializers.at(0);
|
||||
|
||||
const History& history = Simulation::get_instance().get_history();
|
||||
|
||||
serializer.save_snapshot(filename, history);
|
||||
|
||||
_saved = true;
|
||||
}
|
||||
catch(out_of_range e)
|
||||
{
|
||||
p_stderr(_("ERROR: No registered serializer available\n"));
|
||||
}
|
||||
catch(SerializerError e)
|
||||
{
|
||||
string msg = _("ERROR: ");
|
||||
|
||||
p_stderr(msg + e.what() + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
TextSimulation::on_load(const Tokens& arguments)
|
||||
{
|
||||
if(!check_arguments_num(arguments, 1))
|
||||
return;
|
||||
|
||||
ustring filename = arguments[0];
|
||||
|
||||
if(!unsaved_ask_confirm())
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
vector<Serializer*> serializers =
|
||||
SerializersGatekeeper::get_instance().get_registered();
|
||||
|
||||
// FIXME using the first serializer available, this
|
||||
// will need to be changed when multiple serializers will
|
||||
// be made available
|
||||
Serializer& serializer = *serializers.at(0);
|
||||
|
||||
History& history = Simulation::get_instance().get_history();
|
||||
|
||||
serializer.restore_snapshot(filename, history);
|
||||
}
|
||||
catch(out_of_range e)
|
||||
{
|
||||
|
@ -1361,8 +1442,9 @@ TextSimulation::parse_command(TextSimulation& sim, const ustring& str)
|
|||
command_handlers["ADD"] = &TextSimulation::on_add;
|
||||
command_handlers["REMOVE"] = &TextSimulation::on_remove;
|
||||
command_handlers["SAVE"] = &TextSimulation::on_save;
|
||||
command_handlers["LOAD"] = &TextSimulation::on_load;
|
||||
command_handlers["QUIT"] = &TextSimulation::on_quit;
|
||||
|
||||
|
||||
Tokens arguments = tokenize(str);
|
||||
|
||||
if(arguments.size() == 0)
|
||||
|
@ -1379,6 +1461,9 @@ TextSimulation::parse_command(TextSimulation& sim, const ustring& str)
|
|||
arguments.erase(arguments.begin());
|
||||
|
||||
(sim.*(command_handlers[key]))(arguments);
|
||||
|
||||
if(key == "ADD" || key == "REMOVE")
|
||||
sim._saved = false;
|
||||
}
|
||||
|
||||
static ostream&
|
||||
|
|
|
@ -74,6 +74,7 @@ namespace sgpem
|
|||
virtual void update(const History& changed_history);
|
||||
|
||||
bool check_arguments_num(const Tokens& arguments, unsigned int num);
|
||||
bool unsaved_ask_confirm() const;
|
||||
template <typename Container>
|
||||
void show(const Container& entities);
|
||||
template <typename T>
|
||||
|
@ -107,12 +108,15 @@ namespace sgpem
|
|||
void on_remove_request(const Tokens& arguments);
|
||||
void on_remove_subrequest(const Tokens& arguments);
|
||||
void on_save(const Tokens& arguments);
|
||||
void on_load(const Tokens& arguments);
|
||||
|
||||
// FIXME This is a temporary replacement for the
|
||||
// to-be written I/O layer
|
||||
static void p_stdout(const Glib::ustring& str);
|
||||
static void p_stderr(const Glib::ustring& str);
|
||||
static Glib::ustring readline();
|
||||
|
||||
bool _saved;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue