- Cleanup GlobalPreferences badly cluttered interface, removing
deprecated methods and things that don't exist in the design - Put the ``sgpemrc'' application configuration file into the proper place (``$HOME/.sgpemv2''), creating the directory if it doesn't exist, as per specs - Disable test-global_preferences_serialization building since it doesn't work with the new interface (todo: create a class inheriting from GlobalPreferences, and redefining get_config_filename() to return a tmpname to a mkfifo() pipe connected to the stdout. If you don't understand a word of this, you're not a Real Unix Programmer(tm)) - Update other files to use the new interface git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@1178 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
bd1b8f879b
commit
93feee1ee5
21
Makefile.am
21
Makefile.am
|
@ -455,13 +455,13 @@ if COND_TESTS
|
|||
|
||||
noinst_PROGRAMS = \
|
||||
src/testsuite/test-cairo_widget \
|
||||
src/testsuite/test-global_preferences_serialization \
|
||||
src/testsuite/test-history \
|
||||
src/testsuite/test-holt_widget \
|
||||
src/testsuite/test-key_file \
|
||||
src/testsuite/test-simulation_widget
|
||||
|
||||
# disable :
|
||||
# src/testsuite/test-global_preferences_serialization
|
||||
# src/testsuite/test-parse_command
|
||||
# src/testsuite/test-stepforward
|
||||
|
||||
|
@ -488,14 +488,14 @@ src_testsuite_test_history_SOURCES = \
|
|||
src/backend/static_thread.cc \
|
||||
src/testsuite/test-history.cc
|
||||
|
||||
src_testsuite_test_global_preferences_serialization_CPPFLAGS = \
|
||||
-I@top_srcdir@/src/backend \
|
||||
$(GLIBMM_CFLAGS)
|
||||
src_testsuite_test_global_preferences_serialization_LDFLAGS = \
|
||||
src/backend/libbackend.la \
|
||||
$(GLIBMM_LIBS)
|
||||
src_testsuite_test_global_preferences_serialization_SOURCES = \
|
||||
src/testsuite/test-global_preferences_serialization.cc
|
||||
#src_testsuite_test_global_preferences_serialization_CPPFLAGS = \
|
||||
# -I@top_srcdir@/src/backend \
|
||||
# $(GLIBMM_CFLAGS)
|
||||
#src_testsuite_test_global_preferences_serialization_LDFLAGS = \
|
||||
# src/backend/libbackend.la \
|
||||
# $(GLIBMM_LIBS)
|
||||
#src_testsuite_test_global_preferences_serialization_SOURCES = \
|
||||
# src/testsuite/test-global_preferences_serialization.cc
|
||||
|
||||
src_testsuite_test_key_file_CPPFLAGS = \
|
||||
-I@top_srcdir@/src/backend \
|
||||
|
@ -592,11 +592,12 @@ src_testsuite_test_holt_widget_SOURCES = \
|
|||
# while it's finishing the distcheck target
|
||||
CLEANFILES += \
|
||||
src/testsuite/.libs/test-cairo_widget \
|
||||
src/testsuite/.libs/test-global_preferences_serialization \
|
||||
src/testsuite/.libs/test-history \
|
||||
src/testsuite/.libs/test-holt_widget \
|
||||
src/testsuite/.libs/test-key_file \
|
||||
src/testsuite/.libs/test-simulation_widget
|
||||
# disabled:
|
||||
# src/testsuite/.libs/test-global_preferences_serialization
|
||||
|
||||
endif #~ if COND_TESTS
|
||||
|
||||
|
|
|
@ -72,8 +72,8 @@ PythonCPUPolicyManager::PythonCPUPolicyManager()
|
|||
GlobalPreferences& prefs = GlobalPreferences::get_instance();
|
||||
Glib::ustring importdirs = "import sys\n"
|
||||
"sys.path[:0] = [ ";
|
||||
for_each(prefs.policies_dir_begin(),
|
||||
prefs.policies_dir_end(),
|
||||
for_each(prefs.get_policy_dirs().begin(),
|
||||
prefs.get_policy_dirs().end(),
|
||||
pol_dirs_concat(importdirs));
|
||||
importdirs += " '" SHAREDIR "' ]\n";
|
||||
|
||||
|
@ -101,8 +101,8 @@ void
|
|||
PythonCPUPolicyManager::collect_policies()
|
||||
{
|
||||
GlobalPreferences& prefs = GlobalPreferences::get_instance();
|
||||
GlobalPreferences::dir_iterator dir_it = prefs.policies_dir_begin();
|
||||
GlobalPreferences::dir_iterator dir_end = prefs.policies_dir_end();
|
||||
GlobalPreferences::DirVectorIt dir_it = prefs.get_policy_dirs().begin();
|
||||
GlobalPreferences::DirVectorIt dir_end = prefs.get_policy_dirs().end();
|
||||
|
||||
for (; dir_it != dir_end; ++dir_it)
|
||||
{
|
||||
|
|
|
@ -65,8 +65,11 @@ main(int argc, char** argv)
|
|||
exit(-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Add argv[1] as the directory to search for uninstalled policies
|
||||
sgpem::GlobalPreferences::get_instance().add_policies_dir(argv[1]);
|
||||
GlobalPreferences::DirVector& pol_dirs = GlobalPreferences::get_instance().get_policy_dirs();
|
||||
pol_dirs.insert(pol_dirs.begin(), argv[1]);
|
||||
}
|
||||
|
||||
// Self-register itself to PoliciesGatekeeper, however we don't care about it
|
||||
PythonCPUPolicyManager polman;
|
||||
|
|
|
@ -20,12 +20,13 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
#include <glib/gstdio.h>
|
||||
#include <glibmm/miscutils.h>
|
||||
|
||||
#include <sgpemv2/global_preferences.hh>
|
||||
#include <sgpemv2/key_file.hh>
|
||||
#include <sgpemv2/string_utils.hh>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
// Do not include in header file:
|
||||
#include <sgpemv2/templates/singleton.tcc>
|
||||
|
||||
|
@ -39,61 +40,35 @@ GlobalPreferences::GlobalPreferences()
|
|||
{}
|
||||
|
||||
|
||||
GlobalPreferences::dir_iterator
|
||||
GlobalPreferences::policies_dir_begin() const
|
||||
const Glib::ustring&
|
||||
GlobalPreferences::get_preferences_dir() const throw(Glib::FileError)
|
||||
{
|
||||
return _pol_dirs.begin();
|
||||
using namespace Glib;
|
||||
static const ustring dir = get_home_dir() + G_DIR_SEPARATOR_S + ".sgpemv2";
|
||||
if(!file_test(dir, FILE_TEST_EXISTS & FILE_TEST_IS_DIR))
|
||||
{
|
||||
const int err = g_mkdir(dir.c_str(), 0755);
|
||||
if(err != 0)
|
||||
throw FileError(FileError::FAILED, g_strerror(err));
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
|
||||
|
||||
GlobalPreferences::dir_iterator
|
||||
GlobalPreferences::policies_dir_end() const
|
||||
const Glib::ustring&
|
||||
GlobalPreferences::get_config_filename() const throw(Glib::FileError)
|
||||
{
|
||||
return _pol_dirs.end();
|
||||
static const Glib::ustring filename = get_preferences_dir() + G_DIR_SEPARATOR_S + Glib::ustring("sgpemrc");
|
||||
return filename;
|
||||
}
|
||||
|
||||
|
||||
GlobalPreferences::dir_iterator
|
||||
GlobalPreferences::modules_dir_begin() const
|
||||
{
|
||||
return _mod_dirs.begin();
|
||||
}
|
||||
|
||||
|
||||
GlobalPreferences::dir_iterator
|
||||
GlobalPreferences::modules_dir_end() const
|
||||
{
|
||||
return _mod_dirs.end();
|
||||
}
|
||||
|
||||
|
||||
const
|
||||
Glib::ustring
|
||||
GlobalPreferences::get_config_filename()
|
||||
{
|
||||
return Glib::ustring("sgpem.cfg");
|
||||
}
|
||||
|
||||
void
|
||||
GlobalPreferences::add_modules_dir(const Glib::ustring& moddir)
|
||||
{
|
||||
_mod_dirs.insert(_mod_dirs.begin(), moddir);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GlobalPreferences::add_policies_dir(const Glib::ustring& poldir)
|
||||
{
|
||||
_pol_dirs.insert(_pol_dirs.begin(), poldir);
|
||||
}
|
||||
|
||||
std::vector<Glib::ustring>&
|
||||
GlobalPreferences::DirVector&
|
||||
GlobalPreferences::get_policy_dirs()
|
||||
{
|
||||
return _pol_dirs;
|
||||
}
|
||||
|
||||
std::vector<Glib::ustring>&
|
||||
GlobalPreferences::DirVector&
|
||||
GlobalPreferences::get_plugin_dirs()
|
||||
{
|
||||
return _mod_dirs;
|
||||
|
@ -113,7 +88,7 @@ GlobalPreferences::set_speed(int new_speed)
|
|||
return old_speed;
|
||||
}
|
||||
|
||||
Glib::ustring
|
||||
const Glib::ustring
|
||||
GlobalPreferences::get_schedulable_color(Schedulable::state st) const
|
||||
{
|
||||
switch(st)
|
||||
|
@ -133,7 +108,7 @@ GlobalPreferences::get_schedulable_color(Schedulable::state st) const
|
|||
}
|
||||
}
|
||||
|
||||
Glib::ustring
|
||||
const Glib::ustring
|
||||
GlobalPreferences::get_request_color(Request::state st) const
|
||||
{
|
||||
switch(st)
|
||||
|
@ -154,7 +129,7 @@ GlobalPreferences::get_request_color(Request::state st) const
|
|||
}
|
||||
|
||||
void
|
||||
GlobalPreferences::write_configrc()
|
||||
GlobalPreferences::write_configrc() throw(Glib::FileError)
|
||||
{
|
||||
KeyFile kf;
|
||||
|
||||
|
@ -163,7 +138,7 @@ GlobalPreferences::write_configrc()
|
|||
}
|
||||
|
||||
void
|
||||
GlobalPreferences::load_configrc()
|
||||
GlobalPreferences::load_configrc() throw(Glib::FileError)
|
||||
{
|
||||
KeyFile kf;
|
||||
|
||||
|
@ -171,24 +146,6 @@ GlobalPreferences::load_configrc()
|
|||
key_file_read(kf);
|
||||
}
|
||||
|
||||
void
|
||||
GlobalPreferences::write_configrc(std::ostream &os)
|
||||
{
|
||||
KeyFile kf;
|
||||
|
||||
key_file_write(kf);
|
||||
kf.file_write(os);
|
||||
}
|
||||
|
||||
void
|
||||
GlobalPreferences::load_configrc(std::istream &is)
|
||||
{
|
||||
KeyFile kf;
|
||||
|
||||
kf.file_read(is);
|
||||
key_file_read(kf);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GlobalPreferences::key_file_read(KeyFile& kf)
|
||||
|
@ -277,8 +234,8 @@ GlobalPreferences::key_file_write(KeyFile& kf)
|
|||
/*
|
||||
GlobalPreferences::dir_iterator iter=_globalPreferences.modules_dir_begin();
|
||||
*/
|
||||
dir_iterator iter = _mod_dirs.begin();
|
||||
dir_iterator end = _mod_dirs.end();
|
||||
DirVectorConstIt iter = _mod_dirs.begin();
|
||||
DirVectorConstIt end = _mod_dirs.end();
|
||||
int n = 0;
|
||||
while (iter != end)
|
||||
{
|
||||
|
@ -300,8 +257,8 @@ GlobalPreferences::key_file_write(KeyFile& kf)
|
|||
/*
|
||||
GlobalPreferences::dir_iterator iter=_globalPreferences.policies_dir_begin();
|
||||
*/
|
||||
dir_iterator iter = _pol_dirs.begin();
|
||||
dir_iterator end = _pol_dirs.end();
|
||||
DirVectorConstIt iter = _pol_dirs.begin();
|
||||
DirVectorConstIt end = _pol_dirs.end();
|
||||
int n = 0;
|
||||
while (iter != end)
|
||||
{
|
||||
|
|
|
@ -55,12 +55,13 @@ PluginManager::rescan_dirs()
|
|||
_modules.clear();
|
||||
|
||||
GlobalPreferences& prefs = GlobalPreferences::get_instance();
|
||||
GlobalPreferences::dir_iterator it = prefs.modules_dir_begin();
|
||||
GlobalPreferences::DirVector& plugin_dirs = prefs.get_plugin_dirs();
|
||||
GlobalPreferences::DirVectorIt it = plugin_dirs.begin();
|
||||
|
||||
|
||||
Glib::PatternSpec shared_obj(Glib::ustring("*.") + G_MODULE_SUFFIX);
|
||||
|
||||
while (it != prefs.modules_dir_end())
|
||||
while (it != plugin_dirs.end())
|
||||
{
|
||||
Glib::Dir dir(*it);
|
||||
|
||||
|
|
|
@ -23,7 +23,9 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
#include <glibmm/fileutils.h>
|
||||
#include <glibmm/ustring.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
|
@ -47,47 +49,29 @@ namespace sgpem
|
|||
class SG_DLLEXPORT GlobalPreferences : public Singleton<GlobalPreferences>
|
||||
{
|
||||
friend class Singleton<GlobalPreferences>;
|
||||
|
||||
public:
|
||||
|
||||
typedef std::vector<Glib::ustring>::const_iterator dir_iterator;
|
||||
|
||||
dir_iterator modules_dir_begin() const;
|
||||
dir_iterator modules_dir_end() const;
|
||||
|
||||
dir_iterator policies_dir_begin() const;
|
||||
dir_iterator policies_dir_end() const;
|
||||
|
||||
|
||||
typedef std::vector<Glib::ustring> DirVector;
|
||||
typedef DirVector::iterator DirVectorIt;
|
||||
typedef DirVector::const_iterator DirVectorConstIt;
|
||||
|
||||
/**
|
||||
\return GlobalPreferences configuration filename
|
||||
*/
|
||||
const Glib::ustring get_config_filename();
|
||||
|
||||
/**
|
||||
\brief Adds a directory search entry to modules dirs
|
||||
*/
|
||||
void add_modules_dir(const Glib::ustring& moddir);
|
||||
|
||||
/**
|
||||
\brief Adds a directory search entry to policies dirs
|
||||
*/
|
||||
void add_policies_dir(const Glib::ustring& poldir);
|
||||
const Glib::ustring& get_config_filename() const throw(Glib::FileError);
|
||||
|
||||
/**
|
||||
\brief Returns configured Policy directories
|
||||
|
||||
\return ::_policy_dirs
|
||||
*/
|
||||
std::vector<Glib::ustring>& get_policy_dirs();
|
||||
DirVector& get_policy_dirs();
|
||||
|
||||
/**
|
||||
\brief Returns configured Plugin directories
|
||||
|
||||
\return ::_plugin_dirs
|
||||
*/
|
||||
std::vector<Glib::ustring>& get_plugin_dirs();
|
||||
DirVector& get_plugin_dirs();
|
||||
|
||||
/**
|
||||
\brief Returns the simumulation speed
|
||||
|
@ -106,14 +90,14 @@ namespace sgpem
|
|||
/**
|
||||
\return A HTML color name or hexadecimal code
|
||||
*/
|
||||
Glib::ustring get_schedulable_color(Schedulable::state st) const;
|
||||
const Glib::ustring get_schedulable_color(Schedulable::state st) const;
|
||||
|
||||
/**
|
||||
\brief Also works with SubRequest::state
|
||||
|
||||
\return A HTML color name or hexadecimal code
|
||||
*/
|
||||
Glib::ustring get_request_color(Request::state st) const;
|
||||
const Glib::ustring get_request_color(Request::state st) const;
|
||||
|
||||
/**
|
||||
\brief Writes preferences to disk
|
||||
|
@ -126,7 +110,7 @@ namespace sgpem
|
|||
We advice using a key=value text format.
|
||||
#- Close the configuration file.
|
||||
*/
|
||||
void write_configrc();
|
||||
void write_configrc() throw(Glib::FileError);
|
||||
/**
|
||||
\brief Load global preferences from disk
|
||||
|
||||
|
@ -135,10 +119,17 @@ namespace sgpem
|
|||
|
||||
\throw std::io_error
|
||||
*/
|
||||
void load_configrc();
|
||||
void load_configrc() throw(Glib::FileError);
|
||||
|
||||
/** \brief Prepare directory to read/write preferences to disk
|
||||
*
|
||||
* This method should make sure that an appropriate directory
|
||||
* for saving preferences exists; in Windows it will be
|
||||
* %ApplicationData%/sgpemv2, on *nix systems $HOME/.sgpemv2.
|
||||
* If it doesn't exist, attempt to create it.
|
||||
*/
|
||||
const Glib::ustring& get_preferences_dir() const throw(Glib::FileError);
|
||||
|
||||
void write_configrc(std::ostream &os);
|
||||
void load_configrc(std::istream &is);
|
||||
private:
|
||||
GlobalPreferences();
|
||||
GlobalPreferences(const GlobalPreferences&);
|
||||
|
@ -150,11 +141,13 @@ namespace sgpem
|
|||
/**
|
||||
\brief Returns directories to search for plugins
|
||||
*/
|
||||
std::vector<Glib::ustring> _mod_dirs;
|
||||
DirVector _mod_dirs;
|
||||
|
||||
/**
|
||||
\brief Returns directories to search for policies
|
||||
*/
|
||||
std::vector<Glib::ustring> _pol_dirs;
|
||||
DirVector _pol_dirs;
|
||||
|
||||
/*
|
||||
These directories can be added to SGPEM in the following ways:
|
||||
-# Hardcoded (usually done for the default installation directory on *n?x-systems, but NOT for Microsoft Windows)
|
||||
|
|
|
@ -115,11 +115,11 @@ parse_options(int argc, char** argv)
|
|||
|
||||
for (Glib::OptionGroup::vecustrings::const_iterator it = policies_dir_val.begin();
|
||||
it != policies_dir_val.end(); ++it)
|
||||
prefs.add_policies_dir(*it);
|
||||
prefs.get_policy_dirs().push_back(*it);
|
||||
|
||||
for (Glib::OptionGroup::vecustrings::const_iterator it = modules_dir_val.begin();
|
||||
it != modules_dir_val.end(); ++it)
|
||||
prefs.add_modules_dir(*it);
|
||||
prefs.get_plugin_dirs().push_back(*it);
|
||||
|
||||
|
||||
// Now that GlobalPreferences has been initialized properly,
|
||||
|
|
|
@ -55,13 +55,13 @@ main(int argc, char** argv)
|
|||
int i = 1;
|
||||
while (i < argc && (*argv[i] != '%'))
|
||||
{
|
||||
gp.add_modules_dir( Glib::ustring(argv[i]) );
|
||||
gp.get_plugin_dirs().push_back( Glib::ustring(argv[i]) );
|
||||
i++;
|
||||
}
|
||||
i++;
|
||||
while (i < argc)
|
||||
{
|
||||
gp.add_policies_dir( Glib::ustring(argv[i]) );
|
||||
gp.get_policy_dirs().push_back( Glib::ustring(argv[i]) );
|
||||
i++;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue