diff --git a/src/backend/Makefile.am b/src/backend/Makefile.am index 6462b07..111f6b9 100644 --- a/src/backend/Makefile.am +++ b/src/backend/Makefile.am @@ -38,16 +38,24 @@ libbackend_la_CPPFLAGS = -I@top_srcdir@ \ -DPYCDIR="\"$(pycdir)\"" \ -DMODDIR="\"$(moddir)\"" \ -DLOCALEDIR="\"$(localedir)\"" \ - $(PYTHON_CPPFLAGS) + $(PYTHON_CPPFLAGS) \ + $(GLIBMM_CFLAGS) libbackend_la_LIBADD = $(PYTHON_LDFLAGS) \ $(PYTHON_EXTRA_LIBS) -libbackend_la_LDFLAGS = $(PYTHON_EXTRA_LDFLAGS) +libbackend_la_LDFLAGS = $(PYTHON_EXTRA_LDFLAGS) \ + $(GLIBMM_LDFLAGS) # Please keep this in sorted order: libbackend_la_SOURCES = \ process.cc \ - schedulable.cc + schedulable.cc \ + schedulableStatus.cc \ + simulationStatus.cc \ + slice.cc noinst_HEADERS = \ process.hh \ - schedulable.hh + schedulable.hh \ + schedulableStatus.hh \ + simulationStatus.hh \ + slice.hh diff --git a/src/backend/process.cc b/src/backend/process.cc index 488a43a..f3608c9 100644 --- a/src/backend/process.cc +++ b/src/backend/process.cc @@ -22,11 +22,17 @@ using namespace sgpem; -Process::Process(unsigned int arrival, unsigned int total, int priority) - : Schedulable(arrival, total, priority) +Process::Process(const Glib::ustring& name, const unsigned int& arrival, const unsigned int& total, const int& priority) + : Schedulable(name, arrival, total, priority) { } Process::~Process() { } + +Glib::ustring +Process::getType() const +{ + return _("Process"); +} diff --git a/src/backend/process.hh b/src/backend/process.hh index 17b57a4..d98b01a 100644 --- a/src/backend/process.hh +++ b/src/backend/process.hh @@ -22,6 +22,9 @@ #define PROCESS_HH 1 #include "config.h" +#include "gettext.h" +#include "glibmm/ustring.h" + #include "schedulable.hh" namespace sgpem @@ -35,9 +38,10 @@ namespace sgpem class DLLEXPORT Process : public Schedulable { public: - Process(unsigned int arrival, unsigned int total, int priority); + Process(const Glib::ustring& name, const unsigned int& arrival, const unsigned int& total, const int& priority); ~Process(); + Glib::ustring getType() const; private: }; diff --git a/src/backend/schedulable.cc b/src/backend/schedulable.cc index a9095e7..5229949 100644 --- a/src/backend/schedulable.cc +++ b/src/backend/schedulable.cc @@ -22,10 +22,11 @@ using namespace sgpem; -Schedulable::Schedulable(unsigned int arrival, - unsigned int total, - int priority) : - _arrival_time(arrival), _total_time(total), _priority(priority) +Schedulable::Schedulable(const Glib::ustring& name, + const unsigned int& arrival, + const unsigned int& total, + const int& priority): + _name(name), _arrival_time(arrival), _total_time(total), _priority(priority) {} @@ -53,3 +54,8 @@ Schedulable::getPriority() const return _priority; } +Glib::ustring +Schedulable::getName() const +{ + return _name; +} diff --git a/src/backend/schedulable.hh b/src/backend/schedulable.hh index 0b3d038..e6c2f00 100644 --- a/src/backend/schedulable.hh +++ b/src/backend/schedulable.hh @@ -22,6 +22,7 @@ #define SCHEDULABLE_HH 1 #include "config.h" +#include "glibmm/ustring.h" namespace sgpem { @@ -38,17 +39,21 @@ namespace sgpem class DLLEXPORT Schedulable { public: - Schedulable(unsigned int arrival, unsigned int total, int priority); + Schedulable(const Glib::ustring& name, const unsigned int& arrival, const unsigned int& total, const int& priority); virtual ~Schedulable() = 0; - virtual unsigned int getArrivalTime() const; - unsigned int getTotalCPUTime() const; - int getPriority() const; - + virtual unsigned int getArrivalTime() const; + unsigned int getTotalCPUTime() const; + int getPriority() const; + Glib::ustring getName() const; + virtual Glib::ustring getType() const =0; + private: - unsigned int _arrival_time; + Glib::ustring _name; + unsigned int _arrival_time; unsigned int _total_time; int _priority; + }; } diff --git a/src/backend/schedulableStatus.cc b/src/backend/schedulableStatus.cc new file mode 100644 index 0000000..26698e6 --- /dev/null +++ b/src/backend/schedulableStatus.cc @@ -0,0 +1,76 @@ +// src/backend/schedulableStatus.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 + +#include "schedulableStatus.hh" +using namespace sgpem; +using namespace std; + +SchedulableStatus::SchedulableStatus(const Schedulable& obj): + _ref(&obj), _last(-1), _timeLeft(obj.getTotalCPUTime()), _myState(state_future) +{ +} + +int +SchedulableStatus::getCpuTimeLeft() const +{ + return _timeLeft; +} + +void +SchedulableStatus::giveCpuTime(const int& time) +{ + _timeLeft -= time; + if (_timeLeft < 0) + _timeLeft = 0; +} + +void +SchedulableStatus::setLastScheduled(const int& time) +{ + _last = time; +} + +int +SchedulableStatus::getLastScheduled() const +{ + return _last; +} + +SchedulableStatus::state +SchedulableStatus::getState() const +{ + return _myState; +} + +void +SchedulableStatus::setState(state s) +{ + _myState = s; +} + +const Schedulable* +SchedulableStatus::getSchedulable() const +{ + return _ref; +} + + + + \ No newline at end of file diff --git a/src/backend/schedulableStatus.hh b/src/backend/schedulableStatus.hh new file mode 100644 index 0000000..e000d60 --- /dev/null +++ b/src/backend/schedulableStatus.hh @@ -0,0 +1,75 @@ +// src/backend/schedulableStatus.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 + +#ifndef SCHEDULABLESTATUS_HH +#define SCHEDULABLESTATUS_HH 1 + +#include "config.h" +#include "schedulable.hh" + +namespace sgpem +{ + + class SchedulableStatus; + /** \brief Desribes the state of a schedulable entity in a particular moment of the simulation + + This class desribes the state of a schedulable entity in a particular moment of the simulation. + Stores part of informations deeded by Scheduler to manage processes and other ones. + + Objects SchedulableStatus are created by Scheduler and destroyed by SimulationStatus if they are linked to it + or by Scheduler. + */ +class DLLEXPORT SchedulableStatus +{ + public: + enum state + { + state_running, + state_ready, + state_blocked, + state_future, + state_terminated + }; + + + SchedulableStatus(const Schedulable& obj); + //SchedulableStatus(const SchedulableStatus& obj); //copy constructor + //SchedulableStatus& operator=(const SchedulableStatus&); + + int getCpuTimeLeft() const; + void giveCpuTime(const int& time); + void setLastScheduled(const int& time); + int getLastScheduled() const; + state getState() const; + void setState(state s); + const Schedulable* getSchedulable() const; + + private: + const Schedulable* _ref; + int _last; + int _timeLeft; + state _myState; + +}; + +} + +#endif + diff --git a/src/backend/simulationStatus.cc b/src/backend/simulationStatus.cc new file mode 100644 index 0000000..40a4258 --- /dev/null +++ b/src/backend/simulationStatus.cc @@ -0,0 +1,65 @@ +// src/backend/simulationStatus.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 + +#include "simulationStatus.hh" +using namespace sgpem; +using namespace std; + +SimulationStatus::SimulationStatus() +{ +} + +SimulationStatus::SimulationStatus(const SimulationStatus& dx) + :_set(dx._set) +{ +} + + + + /** \brief Adds a SchedulableStatus which represents a running Schedulable object. + + Adds a SchedulableStatus which represents a running Schedulable object. + Note that a copy of SchedulableStatus will be created + */ +void +SimulationStatus::setRunning(SchedulableStatus entity) +{ + if (entity.getState() != SchedulableStatus::state_running) + entity.setState(SchedulableStatus::state_running); + _set.push_back(entity); +} + + /** \brief Looks for a running Schedulable object and returns ist state. + Looks for a running Schedulable object and returns its state. There can be only + one running schedulable object. If no running schedulable object is found will be returned + the NULL pointer. + */ + +auto_ptr +SimulationStatus::getRunning() const +{ + for (uint i=0; i < _set.size(); i++) + if (_set[i].getState() == SchedulableStatus::state_running){ //there can be only ONE running schedulable objext + SchedulableStatus* s = const_cast( &_set[i]); + return auto_ptr(s); + } + return auto_ptr(NULL); +} + diff --git a/src/backend/simulationStatus.hh b/src/backend/simulationStatus.hh new file mode 100644 index 0000000..20690da --- /dev/null +++ b/src/backend/simulationStatus.hh @@ -0,0 +1,55 @@ +// src/backend/simulationStatus.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 + +#ifndef SIMULATIONSTATUS_HH +#define SIMULATIONSTATUS_HH 1 + +#include "config.h" +#include +#include + +#include "schedulableStatus.hh" + +namespace sgpem +{ + class SimulationStatus; + + /** \brief Keeps informatios about the configuration of the simulation + + Keeps informatios about the configuration of the simulation: which process is + running and other infos (since M02+) + */ + + class DLLEXPORT SimulationStatus + { + public: + SimulationStatus(); + SimulationStatus(const SimulationStatus&); + + std::auto_ptr getRunning() const; + void setRunning(SchedulableStatus); + + private: + std::vector _set; + }; + +} + +#endif diff --git a/src/backend/slice.cc b/src/backend/slice.cc new file mode 100644 index 0000000..9dbca12 --- /dev/null +++ b/src/backend/slice.cc @@ -0,0 +1,47 @@ +// src/backend/silce.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 + +#include "slice.hh" +using namespace sgpem; +using namespace std; + + +Slice::Slice(const int& start, const int& duration, const SimulationStatus& status) + : _ref(status), _started_at(start), _duration(duration) +{ +} + +SimulationStatus& +Slice::getSimulationStatus() +{ + return _ref; +} + +int +Slice::getStartedAt() +{ + return _started_at; +} + +int +Slice::getDuration() +{ + return _duration; +} diff --git a/src/backend/slice.hh b/src/backend/slice.hh new file mode 100644 index 0000000..2868e1a --- /dev/null +++ b/src/backend/slice.hh @@ -0,0 +1,56 @@ +// src/backend/slice.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 + +#ifndef SLICE_HH +#define SLICE_HH 1 + +#include "config.h" + +#include "simulationStatus.hh" + +namespace sgpem +{ + class Slice; + + /** \brief Represents a slice of time during which some characteristic of the state of the simulation are constant + + Represents a slice of time during which some characteristic of the state of the simulation are constant. + It holds a SimulationStatus object which can be accesse through getSimulationStatus() + + */ + + class DLLEXPORT Slice + { + public: + Slice(const int& start, const int& duration, const SimulationStatus& status); + + SimulationStatus& getSimulationStatus(); + int getStartedAt(); + int getDuration(); + + private: + SimulationStatus _ref; + int _started_at; + int _duration; + }; + +} + +#endif diff --git a/src/main.cc b/src/main.cc index a54af91..14a1323 100644 --- a/src/main.cc +++ b/src/main.cc @@ -25,17 +25,24 @@ #include "parseopts.hh" #include "startgui.hh" +#include "backend/slice.hh" #include "backend/schedulable.hh" +#include "backend/schedulableStatus.hh" +#include "backend/simulationStatus.hh" #include "backend/process.hh" #include +#include #include #include + using namespace std; + using namespace sgpem; + int main(int argc, char* argv[]) { - using namespace std; + // Set up gettext support setlocale(LC_ALL, ""); @@ -52,11 +59,22 @@ main(int argc, char* argv[]) filenames.insert(filenames.begin(), a_ptr, a_ptr+a_count); } - start_gui(argc, argv); +start_gui(argc, argv); //SMOKE-TEST for backend classes - - sgpem::Process pp(0,10,5); + cout << "\n\n********************************"; + Process p("P1", 0,10,5); + SchedulableStatus ss(p); + SchedulableStatus ss2(ss); + SimulationStatus sim; + sim.setRunning(ss); + + Slice sl(0,5, sim); + + cout << "\n\n"; + + cout << "AAA " <getSchedulable()->getName(); + cout << "\n\n"; return 0; }