- 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
5 changed files with 79 additions and 12 deletions
|
@ -24,15 +24,20 @@
|
|||
#include <Python.h>
|
||||
#include <glibmm/ustring.h>
|
||||
#include <glibmm/timer.h>
|
||||
#include <glibmm/fileutils.h>
|
||||
#include <glibmm/pattern.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
using namespace sgpem;
|
||||
|
||||
using std::vector;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
|
||||
// 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::get_instance()
|
||||
{
|
||||
|
@ -108,8 +118,49 @@ PythonPolicyManager::init()
|
|||
// Okay, here we go.
|
||||
// Black magic at work.
|
||||
|
||||
// FIXME : Hardcoded policy name
|
||||
char* policy_name = "fcfs";
|
||||
//char* policy_name = "sjf";
|
||||
_python_policy = std::auto_ptr<PythonPolicy>(new PythonPolicy(policy_name));
|
||||
collect_policies();
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
std::vector<Policy*> get_avail_policies()
|
||||
{
|
||||
//FIXME write code for me
|
||||
return std::vector<Policy*>();
|
||||
}
|
||||
std::vector<Policy*> get_avail_policies();
|
||||
|
||||
/** \brief Returns the singleton instance of
|
||||
* PythonPolicyManager.
|
||||
|
@ -76,7 +72,11 @@ namespace sgpem
|
|||
protected:
|
||||
/** The selected and active PyhonPolicy object. */
|
||||
PythonPolicyManager();
|
||||
std::auto_ptr<PythonPolicy> _python_policy;
|
||||
~PythonPolicyManager();
|
||||
|
||||
void collect_policies();
|
||||
|
||||
PythonPolicy* _python_policy;
|
||||
|
||||
private:
|
||||
PythonPolicyManager(const PythonPolicyManager&);
|
||||
|
|
|
@ -43,7 +43,7 @@ class TestPythonPolicyManager : public PythonPolicyManager {
|
|||
public:
|
||||
void test_init(const char* policy_name) {
|
||||
init();
|
||||
_python_policy = std::auto_ptr<PythonPolicy>(new PythonPolicy(policy_name));
|
||||
_python_policy = new PythonPolicy(policy_name);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue