- Write interface for History and ConcreteHistory

- Write interface for HistoryObserver
- Remove obsolete interfaces


git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@690 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-07-02 15:27:30 +00:00
parent 759b90b017
commit b8f7083bfc
13 changed files with 236 additions and 431 deletions

View file

@ -23,21 +23,17 @@
#include "config.h"
#include "environment.hh"
#include <glibmm/ustring.h>
#include <stdexcept>
#include <utility>
#include <vector>
#include <iostream>
#include "slice.hh"
#include "observed_subject.hh"
#include "ready_queue.hh"
#include "dynamic_schedulable.hh"
#include "smartp.hh"
// Do not include complete template definition here:
#include "singleton.hh"
namespace sgpem
{
/** \brief Manages the history of the simulation
Manages the history of the simulation from the instant 0 to the current time,
@ -46,59 +42,73 @@ namespace sgpem
In a future iteration it will be possible to revert the entire simulation to a state
present in the history ("undo operation")
*/
class History;
class SG_DLLEXPORT History : public Singleton<History>, public ObservedSubject
// Forward declarations:
class HistoryObserver;
class Resource;
class Process;
class Thread;
class Request;
class SubRequest;
class SG_DLLEXPORT History
{
friend class Singleton<History>;
public:
/**
Gets the \ref Schedulable object running at the specified time.
\param time The inquired time instant.
\return The Schedulable object running at the given time.
*/
virtual memory::smart_ptr<sgpem::DynamicSchedulable> get_scheduled_at(int time) const;
typedef unsigned int size_t;
typedef unsigned int time_t;
typedef int prio_t;
typedef int resource_key_t;
typedef const std::pair<resource_key_t, Resource&> ResourcePair;
/**
Gets the status of simulation at the specified time.
\param time The inquired time instant.
\return The list of Schedulable status objects at the specified time.
*/
virtual memory::smart_ptr<sgpem::ReadyQueue> get_simulation_status_at(int time) const;
virtual ~History() = 0;
virtual size_t get_size() = 0;
virtual const Environment& get_last_environment() const = 0;
virtual const Environment& get_environment_at() const throw(std::out_of_range) = 0;
virtual void remove(const Resource& resource) = 0;
virtual void remove(const Process& process) = 0;
virtual void remove(const Thread& thread) = 0;
virtual void remove(const Request& request) = 0;
virtual void remove(const SubRequest& subrequest) = 0;
/**
Gets the current time.
\return The current history time.
*/
virtual int get_current_time() const;
/**
Sets the status of simulation at the current time.
\param status The list of \ref Schedulable status objects at the current time.
*/
virtual void enqueue_slice(const sgpem::ReadyQueue& status);
virtual ResourcePair& add_resource(const Glib::ustring& name,
bool preemptable = false,
size_t places = 1,
size_t availability = 0) = 0;
/**
Remove all data in History following the specified time.
\param instant Desired cutting time.
*/
virtual void truncate_at(int instant);
virtual Process& add_process(const Glib::ustring& name,
time_t arrival_time,
prio_t base_priority = 0) = 0;
protected:
History(); //private constructor.
History(const History&);
History& operator=(const History&);
virtual Thread& add_thread(const Glib::ustring& name,
Process& parent,
time_t arrival_time = 0,
prio_t base_priority = 0) = 0;
private:
int _total_time_elapsed;
std::vector<sgpem::Slice> _slices;
};
virtual Request& add_request(Thread& owner,
time_t instant) = 0;
virtual SubRequest& add_subrequest(Request& request,
resource_key_t resource_key,
time_t duration,
size_t places = 1) = 0;
virtual void attach(HistoryObserver& observer);
virtual void detach(const HistoryObserver& observer);
protected:
typedef std::vector<HistoryObserver*> RegisteredObservers;
RegisteredObservers _observers;
virtual void notify_change() = 0;
}; //~ class History
}//~ namespace sgpem
#endif //HISTORY_H
#endif //~ HISTORY_HH