- Added some source in the backend lib

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@293 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
fpaparel 2006-02-06 21:37:32 +00:00
parent 7ecc9ab822
commit 8f02d11b0a
12 changed files with 442 additions and 21 deletions

View File

@ -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

View File

@ -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");
}

View File

@ -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:
};

View File

@ -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;
}

View File

@ -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;
};
}

View File

@ -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;
}

View File

@ -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

View File

@ -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<SchedulableStatus>
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<SchedulableStatus*>( &_set[i]);
return auto_ptr<SchedulableStatus>(s);
}
return auto_ptr<SchedulableStatus>(NULL);
}

View File

@ -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 <stdlib.h>
#include <vector>
#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<SchedulableStatus> getRunning() const;
void setRunning(SchedulableStatus);
private:
std::vector<SchedulableStatus> _set;
};
}
#endif

47
src/backend/slice.cc Normal file
View File

@ -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;
}

56
src/backend/slice.hh Normal file
View File

@ -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

View File

@ -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 <iostream>
#include <stdlib.h>
#include <string>
#include <vector>
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
cout << "\n\n********************************";
Process p("P1", 0,10,5);
SchedulableStatus ss(p);
SchedulableStatus ss2(ss);
SimulationStatus sim;
sim.setRunning(ss);
sgpem::Process pp(0,10,5);
Slice sl(0,5, sim);
cout << "\n\n";
cout << "AAA " <<sl.getSimulationStatus().getRunning()->getSchedulable()->getName();
cout << "\n\n";
return 0;
}