- Added PoliciesGatekeeper class, but still not integrated it with the rest of the code
git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@610 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
fbe718b69a
commit
e5b90a39ad
|
@ -0,0 +1,87 @@
|
||||||
|
// src/backend/policies_gatekeeper.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 "policies_gatekeeper.hh"
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
using std::vector;
|
||||||
|
using namespace sgpem;
|
||||||
|
|
||||||
|
PoliciesGatekeeper* PoliciesGatekeeper::_instance = NULL;
|
||||||
|
|
||||||
|
PoliciesGatekeeper&
|
||||||
|
PoliciesGatekeeper::get_instance()
|
||||||
|
{
|
||||||
|
if(!_instance)
|
||||||
|
_instance = new PoliciesGatekeeper();
|
||||||
|
return *_instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<PolicyManager*>
|
||||||
|
PoliciesGatekeeper::get_registered() const
|
||||||
|
{
|
||||||
|
return _registered;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PoliciesGatekeeper::register_manager(PolicyManager* manager)
|
||||||
|
{
|
||||||
|
using std::find;
|
||||||
|
|
||||||
|
assert(manager != NULL);
|
||||||
|
|
||||||
|
end = _registered.end();
|
||||||
|
|
||||||
|
if(find(_registered.begin(), end, manager) != end)
|
||||||
|
_registered.push_back(manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PoliciesGatekeeper::unregister_manager(PolicyManager* manager)
|
||||||
|
{
|
||||||
|
using std::find;
|
||||||
|
|
||||||
|
assert(manager != NULL);
|
||||||
|
|
||||||
|
end = _registered.end();
|
||||||
|
pos = find(_registered.begin(), end, manager);
|
||||||
|
|
||||||
|
if(pos != end)
|
||||||
|
_registered.erase(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
Policy*
|
||||||
|
PoliciesGatekeeper::get_current_policy()
|
||||||
|
{
|
||||||
|
return _cur_policy;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PoliciesGatekeeper::activate_policy(Policy* policy)
|
||||||
|
{
|
||||||
|
_cur_policy = policy;
|
||||||
|
}
|
||||||
|
|
||||||
|
PoliciesGatekeeper::PoliciesGatekeeper() :
|
||||||
|
_cur_policy(NULL)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,78 @@
|
||||||
|
// src/backend/policies_gatekeeper.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 POLICIES_GATEKEEPER_HH
|
||||||
|
#define POLICIES_GATEKEEPER_HH 1
|
||||||
|
|
||||||
|
namespace sgpem
|
||||||
|
{
|
||||||
|
class PolicyManager;
|
||||||
|
class Policy;
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace sgpem
|
||||||
|
{
|
||||||
|
class PoliciesGatekeeper;
|
||||||
|
|
||||||
|
/** \brief FIXME document me
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
class PoliciesGatekeeper
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/** \brief Returns the unique instance of this class, conforming to the Singleton pattern.
|
||||||
|
*
|
||||||
|
* \return the unique instance of this class, conforming to the Singleton pattern.
|
||||||
|
*/
|
||||||
|
static PoliciesGatekeeper& get_instance();
|
||||||
|
|
||||||
|
std::vector<PolicyManager*> get_registered() const;
|
||||||
|
|
||||||
|
/** FIXME what to do when the manager was already registered? should we throw an exception?
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void register_manager(PolicyManager* manager);
|
||||||
|
|
||||||
|
/** FIXME what to do when the manager wasn't already registered? should we throw an exception?
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void unregister_manager(PolicyManager* manager);
|
||||||
|
|
||||||
|
Policy* get_current_policy();
|
||||||
|
|
||||||
|
void activate_policy(Policy* policy);
|
||||||
|
|
||||||
|
private:
|
||||||
|
PoliciesGatekeeper(); //private constructor.
|
||||||
|
static PoliciesGatekeeper* _instance;
|
||||||
|
std::vector<PolicyManager*> _registered;
|
||||||
|
Policy* _cur_policy;
|
||||||
|
};
|
||||||
|
|
||||||
|
}//~ namespace sgpem
|
||||||
|
|
||||||
|
#endif //POLICIES_GATEKEEPER_HH
|
||||||
|
|
Loading…
Reference in New Issue