- Implemented PythonPolicyManager::collect_policies()
- Integrated PythonPolicyManager with PoliciesGatekeeper git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@620 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
c5d78f3547
commit
65ed285807
|
@ -24,15 +24,20 @@
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
#include <glibmm/ustring.h>
|
#include <glibmm/ustring.h>
|
||||||
#include <glibmm/timer.h>
|
#include <glibmm/timer.h>
|
||||||
|
#include <glibmm/fileutils.h>
|
||||||
|
#include <glibmm/pattern.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
using namespace sgpem;
|
using namespace sgpem;
|
||||||
|
using std::vector;
|
||||||
|
using std::cout;
|
||||||
|
using std::endl;
|
||||||
|
|
||||||
|
|
||||||
// Concatenate a string with all the policies directories
|
// Concatenate a string with all the policies directories
|
||||||
|
@ -63,6 +68,11 @@ PythonPolicyManager::PythonPolicyManager()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PythonPolicyManager::~PythonPolicyManager()
|
||||||
|
{
|
||||||
|
for_each(_policies.begin(), _policies.end(), ptr_fun(operator delete));
|
||||||
|
}
|
||||||
|
|
||||||
PythonPolicyManager* const
|
PythonPolicyManager* const
|
||||||
PythonPolicyManager::get_instance()
|
PythonPolicyManager::get_instance()
|
||||||
{
|
{
|
||||||
|
@ -108,8 +118,49 @@ PythonPolicyManager::init()
|
||||||
// Okay, here we go.
|
// Okay, here we go.
|
||||||
// Black magic at work.
|
// Black magic at work.
|
||||||
|
|
||||||
// FIXME : Hardcoded policy name
|
collect_policies();
|
||||||
char* policy_name = "fcfs";
|
|
||||||
//char* policy_name = "sjf";
|
|
||||||
_python_policy = std::auto_ptr<PythonPolicy>(new PythonPolicy(policy_name));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vector<Policy*>
|
||||||
|
PythonPolicyManager::get_avail_policies()
|
||||||
|
{
|
||||||
|
return _policies;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PythonPolicyManager::collect_policies()
|
||||||
|
{
|
||||||
|
GlobalSettings::dir_iterator dir_it = GlobalSettings::instance().policies_dir_begin();
|
||||||
|
GlobalSettings::dir_iterator dir_end = GlobalSettings::instance().policies_dir_end();
|
||||||
|
|
||||||
|
for(; dir_it != dir_end; ++dir_it)
|
||||||
|
{
|
||||||
|
Glib::Dir dir(dir_it->c_str());
|
||||||
|
|
||||||
|
cout << "Opening directory " << *dir_it << "..." << endl;
|
||||||
|
|
||||||
|
for(Glib::DirIterator file_it = dir.begin(); file_it != dir.end(); ++file_it)
|
||||||
|
{
|
||||||
|
cout << "\tChecking if " << *file_it << " is a Python script... " << endl;
|
||||||
|
|
||||||
|
Glib::PatternSpec dot_py("*.py");
|
||||||
|
|
||||||
|
if(dot_py.match(*file_it))
|
||||||
|
{
|
||||||
|
cout << "\t\tIt is.\n";
|
||||||
|
|
||||||
|
//strip extension
|
||||||
|
std::string policy_name = (*file_it).substr(0, (*file_it).size() - 3);
|
||||||
|
|
||||||
|
PythonPolicy *pypolicy = new PythonPolicy(policy_name.c_str());
|
||||||
|
|
||||||
|
_policies.push_back(pypolicy);
|
||||||
|
|
||||||
|
//FIXME remove me when get_policy is dropped
|
||||||
|
if(policy_name == "fcfs")
|
||||||
|
_python_policy = pypolicy;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,11 +58,7 @@ namespace sgpem
|
||||||
*/
|
*/
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
std::vector<Policy*> get_avail_policies()
|
std::vector<Policy*> get_avail_policies();
|
||||||
{
|
|
||||||
//FIXME write code for me
|
|
||||||
return std::vector<Policy*>();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** \brief Returns the singleton instance of
|
/** \brief Returns the singleton instance of
|
||||||
* PythonPolicyManager.
|
* PythonPolicyManager.
|
||||||
|
@ -76,7 +72,11 @@ namespace sgpem
|
||||||
protected:
|
protected:
|
||||||
/** The selected and active PyhonPolicy object. */
|
/** The selected and active PyhonPolicy object. */
|
||||||
PythonPolicyManager();
|
PythonPolicyManager();
|
||||||
std::auto_ptr<PythonPolicy> _python_policy;
|
~PythonPolicyManager();
|
||||||
|
|
||||||
|
void collect_policies();
|
||||||
|
|
||||||
|
PythonPolicy* _python_policy;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PythonPolicyManager(const PythonPolicyManager&);
|
PythonPolicyManager(const PythonPolicyManager&);
|
||||||
|
|
|
@ -43,7 +43,7 @@ class TestPythonPolicyManager : public PythonPolicyManager {
|
||||||
public:
|
public:
|
||||||
void test_init(const char* policy_name) {
|
void test_init(const char* policy_name) {
|
||||||
init();
|
init();
|
||||||
_python_policy = std::auto_ptr<PythonPolicy>(new PythonPolicy(policy_name));
|
_python_policy = new PythonPolicy(policy_name);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -20,20 +20,27 @@
|
||||||
|
|
||||||
|
|
||||||
#include "policy_manager.hh"
|
#include "policy_manager.hh"
|
||||||
|
#include "policies_gatekeeper.hh"
|
||||||
|
|
||||||
PolicyManager*
|
PolicyManager*
|
||||||
PolicyManager::_registered = NULL;
|
PolicyManager::_registered = NULL;
|
||||||
|
|
||||||
PolicyManager::PolicyManager()
|
PolicyManager::PolicyManager()
|
||||||
{
|
{
|
||||||
|
//FIXME remove this when get_registered_manager is dropped
|
||||||
_registered = this;
|
_registered = this;
|
||||||
|
|
||||||
|
PoliciesGatekeeper::get_instance().register_manager(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PolicyManager::~PolicyManager()
|
PolicyManager::~PolicyManager()
|
||||||
{
|
{
|
||||||
// This check is necessary:
|
// This check is necessary:
|
||||||
|
//FIXME remove this when get_registered_manager is dropped
|
||||||
if(_registered == this) _registered = NULL;
|
if(_registered == this) _registered = NULL;
|
||||||
|
|
||||||
|
PoliciesGatekeeper::get_instance().unregister_manager(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
PolicyManager&
|
PolicyManager&
|
||||||
|
@ -41,3 +48,4 @@ PolicyManager::get_registered_manager()
|
||||||
{
|
{
|
||||||
return *_registered;
|
return *_registered;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,22 +53,30 @@ namespace sgpem
|
||||||
Gets THE policy (the only today) used.
|
Gets THE policy (the only today) used.
|
||||||
Next versions will implement some other kind.
|
Next versions will implement some other kind.
|
||||||
\return A reference to the policy.
|
\return A reference to the policy.
|
||||||
|
FIXME deprecated
|
||||||
*/
|
*/
|
||||||
virtual Policy& get_policy() = 0;
|
virtual Policy& get_policy() = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Init (or reset if yet initialized) the manager.
|
Init (or reset if yet initialized) the manager.
|
||||||
|
FIXME deprecated
|
||||||
*/
|
*/
|
||||||
virtual void init() = 0;
|
virtual void init() = 0;
|
||||||
|
|
||||||
virtual std::vector<Policy*> get_avail_policies() = 0;
|
virtual std::vector<Policy*> get_avail_policies() = 0;
|
||||||
|
|
||||||
/** \brief Get the registered manager instance
|
/** \brief Get the registered manager instance
|
||||||
|
* FIXME deprecated
|
||||||
*
|
*
|
||||||
* \return The registered policy manager instance.
|
* \return The registered policy manager instance.
|
||||||
*/
|
*/
|
||||||
static PolicyManager& get_registered_manager();
|
static PolicyManager& get_registered_manager();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void collect_policies() = 0;
|
||||||
|
|
||||||
|
std::vector<Policy*> _policies;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** A pointer to the registered instance */
|
/** A pointer to the registered instance */
|
||||||
static PolicyManager* _registered;
|
static PolicyManager* _registered;
|
||||||
|
|
Loading…
Reference in New Issue