- Give code a round of indentation. Thank astyle, not me.

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@837 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-08-09 14:38:45 +00:00
parent aaf8e068d3
commit d3c7b46853
108 changed files with 3196 additions and 3180 deletions

View file

@ -26,29 +26,29 @@
using namespace sgpem;
// Is this OK? If not, we must use a function with a local static variable...
PythonCPUPolicyManager* _policy_manager = NULL;
PythonCPUPolicyManager* _policy_manager = NULL;
void
void
sgpem__Plugin__on_init()
{
if(_policy_manager == NULL)
if (_policy_manager == NULL)
_policy_manager = new sgpem::PythonCPUPolicyManager();
}
void
void
sgpem__Plugin__on_exit()
{
delete _policy_manager;
_policy_manager = NULL;
}
const char*
const char*
sgpem__Plugin__describe()
{
return "This plugin manages policies written in the Python scripting language";
}
const char*
const char*
sgpem__Plugin__get_name()
{
return "Pyloader";

View file

@ -39,9 +39,9 @@ PythonCPUPolicy::PythonCPUPolicy(const char* name) throw(MalformedPolicyExceptio
PyObject* pUserCPUPolicyModule = PyImport_Import(pLoadmeStr);
Py_DECREF(pLoadmeStr);
if(pUserCPUPolicyModule == NULL)
if (pUserCPUPolicyModule == NULL)
throw MalformedPolicyException(get_exception_information().c_str());
// Dictionary with defined ``symbols'' for .pyc file
_upolicy_dict = PyModule_GetDict(pUserCPUPolicyModule);
assert(_upolicy_dict);
@ -66,24 +66,24 @@ PythonCPUPolicy::PythonCPUPolicy(const char* name) throw(MalformedPolicyExceptio
PyTuple_SetItem(pAdapterCtorParam, 0, pCPUPolicyClass);
_adapter = PyInstance_New(pAdapterClass, pAdapterCtorParam, NULL);
Py_DECREF(pAdapterCtorParam);
Py_DECREF(pScriptAdapterModule);
if(_adapter == NULL)
if (_adapter == NULL)
throw MalformedPolicyException(get_exception_information().c_str());
// And now, who's your daddy, huh?
}
PythonCPUPolicy::~PythonCPUPolicy()
{
if(_adapter) Py_DECREF(_adapter);
if (_adapter) Py_DECREF(_adapter);
// We keep this alive until dtor time, because
// the user may have defined some static global-space
// variables and they make use of them.
if(_upolicy_dict) Py_DECREF(_upolicy_dict);
if (_upolicy_dict) Py_DECREF(_upolicy_dict);
}
void
@ -122,7 +122,7 @@ PythonCPUPolicy::sort_queue() const throw(UserInterruptException)
PyObject* retval = PyObject_CallMethod(_adapter, "async_sort_queue", NULL);
// Do minimal debugging
if(!retval) PyErr_Print();
if (!retval) PyErr_Print();
else Py_DECREF(retval);
wait_unlock();
@ -163,9 +163,9 @@ int
PythonCPUPolicy::get_time_slice() const throw(UserInterruptException)
{
PyObject* retval = PyObject_CallMethod(_adapter, "async_get_time_slice", NULL);
// Do minimal debugging
if(!retval) PyErr_Print();
if (!retval) PyErr_Print();
else Py_DECREF(retval);
wait_unlock();
@ -193,13 +193,13 @@ PythonCPUPolicy::wait_unlock() const throw(UserInterruptException)
Py_UNBLOCK_THREADS;
usleep(WAIT_FOR); // hack'a'ton! magggggiccc nummmbeeerrrrrs!!
Py_BLOCK_THREADS;
PyObject* retval = PyObject_CallMethod(_adapter, "mutex_test_lock", NULL);
assert(retval);
still_locked = PyObject_IsTrue(retval);
Py_DECREF(retval);
if(i++ > 12) /* waits for WAIT_FOR * 12 microseconds == 3 secs */
if (i++ > 12) /* waits for WAIT_FOR * 12 microseconds == 3 secs */
{
PyThreadState_Clear(_save);
// As the API documentation says, the caller of PyEval_RestoreThread
@ -209,10 +209,10 @@ PythonCPUPolicy::wait_unlock() const throw(UserInterruptException)
throw UserInterruptException(_("User-defined policy is "
"taking too long to terminate."));
"taking too long to terminate."));
}
}
while(still_locked);
while (still_locked);
// What we should really do here:
/* do {
@ -234,9 +234,9 @@ PythonCPUPolicy::wait_unlock() const throw(UserInterruptException)
string
PythonCPUPolicy::get_exception_information()
{
if(PyErr_Occurred() == NULL)
if (PyErr_Occurred() == NULL)
return _("no error");
PyObject* pType = NULL;
PyObject* pValue = NULL;
PyObject* pTraceback = NULL;
@ -245,7 +245,7 @@ PythonCPUPolicy::get_exception_information()
string msg;
if(pValue != NULL)
if (pValue != NULL)
{
PyObject* pValueStr = PyObject_Str(pValue);
@ -256,9 +256,9 @@ PythonCPUPolicy::get_exception_information()
else
msg = string(_("no available information for this error"));
if(pType != NULL) Py_DECREF(pType);
if(pValue != NULL) Py_DECREF(pValue);
if(pTraceback != NULL) Py_DECREF(pTraceback);
if (pType != NULL) Py_DECREF(pType);
if (pValue != NULL) Py_DECREF(pValue);
if (pTraceback != NULL) Py_DECREF(pTraceback);
return msg;
}

View file

@ -74,7 +74,7 @@ PythonCPUPolicyManager::~PythonCPUPolicyManager()
void
PythonCPUPolicyManager::init()
{
if(_initialized)
if (_initialized)
// No-op
return;
@ -114,35 +114,35 @@ PythonCPUPolicyManager::collect_policies()
GlobalPreferences::dir_iterator dir_it = prefs.policies_dir_begin();
GlobalPreferences::dir_iterator dir_end = prefs.policies_dir_end();
for(; dir_it != dir_end; ++dir_it)
for (; dir_it != dir_end; ++dir_it)
{
Glib::Dir dir(dir_it->c_str());
cout << "Opening directory " << *dir_it << " looking for python policies..." << endl;
for(Glib::DirIterator file_it = dir.begin(); file_it != dir.end(); ++file_it)
for (Glib::DirIterator file_it = dir.begin(); file_it != dir.end(); ++file_it)
{
cout << "\tChecking if " << *file_it << " is a valid Python script... ";
Glib::PatternSpec dot_py("*.py");
if(dot_py.match(*file_it))
if (dot_py.match(*file_it))
{
cout << "yes" << endl;
cout << "yes" << endl;
//strip extension
std::string policy_name = (*file_it).substr(0, (*file_it).size() - 3);
try
{
PythonCPUPolicy *pypolicy = new PythonCPUPolicy(policy_name.c_str());
{
PythonCPUPolicy *pypolicy = new PythonCPUPolicy(policy_name.c_str());
_policies.push_back(pypolicy);
}
catch(MalformedPolicyException e)
{
std::cerr << "POLICY LOAD ERROR: " << e.what() << endl;
}
_policies.push_back(pypolicy);
}
catch (MalformedPolicyException e)
{
std::cerr << "POLICY LOAD ERROR: " << e.what() << endl;
}
}
else
cout << "no" << endl;

View file

@ -57,7 +57,7 @@ namespace sgpem
/** The selected and active PyhonCPUPolicy object. */
void collect_policies();
private:
private:
PythonCPUPolicyManager(const PythonCPUPolicyManager&);
PythonCPUPolicyManager& operator=(const PythonCPUPolicyManager&);

View file

@ -45,11 +45,11 @@ using namespace std;
static CPUPolicy*
find_pol_by_name(const vector<CPUPolicy*>& pols, const Glib::ustring& name)
{
vector<CPUPolicy*>::const_iterator it = pols.begin();
for( ; it != pols.end(); it++)
if((*it)->get_name() == name)
return *it;
return NULL;
vector<CPUPolicy*>::const_iterator it = pols.begin();
for ( ; it != pols.end(); it++)
if ((*it)->get_name() == name)
return *it;
return NULL;
}
@ -58,7 +58,7 @@ main(int argc, char** argv)
{
int successes = 0;
if(argc != 2)
if (argc != 2)
{
std::cout << "[EE] Usage:\n\t" << argv[0] <<
" path/to/uninstalled/test/policies" << std::endl;
@ -72,29 +72,29 @@ main(int argc, char** argv)
PythonCPUPolicyManager polman;
polman.init();
Simulation& sim = Simulation::get_instance();
History& his = sim.get_history();
CPUPoliciesGatekeeper& pgk = CPUPoliciesGatekeeper::get_instance();
Simulation& sim = Simulation::get_instance();
History& his = sim.get_history();
CPUPoliciesGatekeeper& pgk = CPUPoliciesGatekeeper::get_instance();
const std::vector<CPUPolicy*>& policies = polman.get_avail_policies();
const std::vector<CPUPolicy*>& policies = polman.get_avail_policies();
// Print out avail policies
cout << "These are the policies I found:" << endl;
vector<CPUPolicy*>::const_iterator it = policies.begin();
for(; it != policies.end(); it++)
cout << "\t * " << (*it)->get_name() << endl;
// Print out avail policies
cout << "These are the policies I found:" << endl;
vector<CPUPolicy*>::const_iterator it = policies.begin();
for (; it != policies.end(); it++)
cout << "\t * " << (*it)->get_name() << endl;
try
{
CPUPolicy* pol = find_pol_by_name(policies, "python_loader_configure");
assert(pol != NULL);
CPUPolicy* pol = find_pol_by_name(policies, "python_loader_configure");
assert(pol != NULL);
// FIXME : Maybe activating a policy only to configure it is an overkill?
// Who gives a fuck about it?
// FIXME : Maybe activating a policy only to configure it is an overkill?
// Who gives a fuck about it?
pgk.activate_policy(&his, pol);
pol->configure();
}
catch(UserInterruptException e)
catch (UserInterruptException e)
{
cout << "configure: Caught UserInterruptException" << endl;
successes++;
@ -103,12 +103,12 @@ main(int argc, char** argv)
try
{
CPUPolicy* pol = find_pol_by_name(policies, "python_loader_is_preemptive");
assert(pol != NULL);
CPUPolicy* pol = find_pol_by_name(policies, "python_loader_is_preemptive");
assert(pol != NULL);
pgk.activate_policy(&his, pol);
pol->is_pre_emptive();
}
catch(UserInterruptException e)
catch (UserInterruptException e)
{
cout << "is_preemptive: Caught UserInterruptException" << endl;
successes++;
@ -117,12 +117,12 @@ main(int argc, char** argv)
try
{
CPUPolicy* pol = find_pol_by_name(policies, "python_loader_get_time_slice");
assert(pol != NULL);
CPUPolicy* pol = find_pol_by_name(policies, "python_loader_get_time_slice");
assert(pol != NULL);
pgk.activate_policy(&his, pol);
pol->get_time_slice();
}
catch(UserInterruptException e)
catch (UserInterruptException e)
{
cout << "get_time_slice: Caught UserInterruptException" << endl;
successes++;
@ -132,12 +132,12 @@ main(int argc, char** argv)
try
{
CPUPolicy* pol = find_pol_by_name(policies, "python_loader_get_time_slice");
assert(pol != NULL);
CPUPolicy* pol = find_pol_by_name(policies, "python_loader_get_time_slice");
assert(pol != NULL);
pgk.activate_policy(&his, pol);
pol->sort_queue();
}
catch(UserInterruptException e)
catch (UserInterruptException e)
{
cout << "sort_queue: Caught UserInterruptException" << endl;
successes++;