* ./crlcore:
- New: In <tools.configuration.xml>, added parameters for verbosity, info and trace level. - New: Uniform mecanism to get the "/etc" path. Now System reads the environment variables (thanks to boost::program_option). - Change: In Utility, correct "when first called" initialisation of the System singleton. Access to members only through static members that ensure the initialisation of the singleton first. - Change: In System, makes uses of the callback feature of Parameter to initialize the new configuration parameters (verbosity, coredump, ...). - Change: In linefill, build upon mstream instead of ostream. Now dual aspect, inherit ostream and have a mstream member.
This commit is contained in:
parent
82fe4c2348
commit
fcbd24a9e2
|
@ -1,5 +1,12 @@
|
|||
|
||||
<configuration>
|
||||
<!-- Miscellaneous -->
|
||||
<parameter id="misc.catchCore" type="bool" value="true"/>
|
||||
<parameter id="misc.verboseLevel1" type="bool" value="true"/>
|
||||
<parameter id="misc.verboseLevel2" type="bool" value="false"/>
|
||||
<parameter id="misc.info" type="bool" value="false"/>
|
||||
<parameter id="misc.logMode" type="bool" value="true"/>
|
||||
<parameter id="misc.traceLevel" type="int" value="1000" min="0"/>
|
||||
<!-- Nimbus -->
|
||||
<parameter id="nimbus.cellGauge" type="string" value="sxlib"/>
|
||||
<parameter id="nimbus.routingGauge" type="string" value="sxlib"/>
|
||||
|
@ -74,6 +81,16 @@
|
|||
<parameter id="kite.longGlobalRipupLimit" type="int" value="5" min="1"/>
|
||||
<parameter id="kite.eventsLimit" type="int" value="4000000" min="1"/>
|
||||
<layout>
|
||||
<!-- Miscellaneous -->
|
||||
<tab name="Misc.">
|
||||
<widget type="title" label="Miscellaneous"/>
|
||||
<widget id="misc.catchCore" label="Catch Core Dumps" column="1"/>
|
||||
<widget id="misc.verboseLevel1" label="Verbose" column="0"/>
|
||||
<widget id="misc.verboseLevel2" label="Very Verbose" column="0"/>
|
||||
<widget id="misc.info" label="Show Info" column="0"/>
|
||||
<widget id="misc.logMode" label="Output is a TTY" column="0"/>
|
||||
<widget id="misc.traceLevel" label="Trace Level" column="1"/>
|
||||
</tab>
|
||||
<tab name="Mauka">
|
||||
<!-- hMETIS -->
|
||||
<widget type="title" label="hMETIS - Partitionner"/>
|
||||
|
|
|
@ -29,9 +29,72 @@
|
|||
#include <cstring>
|
||||
#include <iomanip>
|
||||
|
||||
#include <boost/program_options.hpp>
|
||||
namespace boptions = boost::program_options;
|
||||
|
||||
#include "hurricane/Warning.h"
|
||||
#include "vlsisapd/configuration/Configuration.h"
|
||||
#include "crlcore/Utilities.h"
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
using namespace Hurricane;
|
||||
using namespace CRL;
|
||||
|
||||
|
||||
void verboseLevel1Changed ( Cfg::Parameter* p )
|
||||
{
|
||||
if ( p->asBool() ) mstream::enable ( mstream::Verbose1 );
|
||||
else mstream::disable ( mstream::Verbose1 );
|
||||
|
||||
//cerr << "Verbose Level 1: " << boolalpha << p->asBool() << endl;
|
||||
}
|
||||
|
||||
|
||||
void verboseLevel2Changed ( Cfg::Parameter* p )
|
||||
{
|
||||
if ( p->asBool() ) mstream::enable ( mstream::Verbose2 );
|
||||
else mstream::disable ( mstream::Verbose2 );
|
||||
}
|
||||
|
||||
|
||||
void infoChanged ( Cfg::Parameter* p )
|
||||
{
|
||||
if ( p->asBool() ) mstream::enable ( mstream::Info );
|
||||
else mstream::disable ( mstream::Info );
|
||||
}
|
||||
|
||||
|
||||
void catchCoreChanged ( Cfg::Parameter* p )
|
||||
{
|
||||
System::setCatchCore ( p->asBool() );
|
||||
}
|
||||
|
||||
|
||||
void logModeChanged ( Cfg::Parameter* p )
|
||||
{
|
||||
if ( p->asBool() ) tty::enable ();
|
||||
else tty::disable ();
|
||||
}
|
||||
|
||||
|
||||
void traceLevelChanged ( Cfg::Parameter* p )
|
||||
{
|
||||
ltracelevel ( p->asInt() );
|
||||
}
|
||||
|
||||
|
||||
std::string environmentMapper ( std::string environmentName )
|
||||
{
|
||||
if ( environmentName == "CORIOLIS_TOP" ) return "coriolis_top";
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
} // End of anonymous namespace.
|
||||
|
||||
|
||||
int tty::_width = 80;
|
||||
bool tty::_enabled = true;
|
||||
unsigned int mstream::_activeMask = mstream::Verbose0;
|
||||
|
@ -132,41 +195,113 @@ namespace CRL {
|
|||
const char* BadColorValue = "%s() :\n\n"
|
||||
" Invalid color value for color \"%s\" : \"%s\".\n";
|
||||
|
||||
System* System::_singleton = System::create ();
|
||||
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Class : "CRL::System".
|
||||
|
||||
|
||||
System *System::create ()
|
||||
{
|
||||
if ( _singleton != NULL ) {
|
||||
cerr << "[WARNING] Attempt to re-create System() singleton." << endl;
|
||||
return _singleton;
|
||||
}
|
||||
System* System::_singleton = System::get();
|
||||
|
||||
_singleton = new System ();
|
||||
|
||||
System::System ()
|
||||
: _catchCore(true)
|
||||
{
|
||||
// Immediate setup to avoid some tiresome looping...
|
||||
_singleton = this;
|
||||
|
||||
// Set the trap function for the SIGINT signal (CTRL-C).
|
||||
//if ( signal(SIGINT,System::TrapSig) == SIG_ERR )
|
||||
// System::TrapSig ( SIGTFLT );
|
||||
|
||||
// Set the trap function for SIGFPE, SIGBUS, SIGABRT and SIGSEGV signals.
|
||||
if ( ( signal(SIGFPE , System::trapSig) == SIG_ERR )
|
||||
|| ( signal(SIGBUS , System::trapSig) == SIG_ERR )
|
||||
|| ( signal(SIGABRT, System::trapSig) == SIG_ERR )
|
||||
|| ( signal(SIGPIPE, System::trapSig) == SIG_ERR )
|
||||
|| ( signal(SIGSEGV, System::trapSig) == SIG_ERR ) )
|
||||
System::trapSig ( SIGTFLT );
|
||||
if ( ( signal(SIGFPE , System::_trapSig) == SIG_ERR )
|
||||
|| ( signal(SIGBUS , System::_trapSig) == SIG_ERR )
|
||||
|| ( signal(SIGABRT, System::_trapSig) == SIG_ERR )
|
||||
|| ( signal(SIGPIPE, System::_trapSig) == SIG_ERR )
|
||||
|| ( signal(SIGSEGV, System::_trapSig) == SIG_ERR ) )
|
||||
System::_trapSig ( SIGTFLT );
|
||||
|
||||
// Environment variables reading.
|
||||
boptions::options_description options ("Environment Variables");
|
||||
options.add_options()
|
||||
( "coriolis_top", boptions::value<string>()
|
||||
, "The root directory of the Coriolis installation tree." );
|
||||
|
||||
boptions::variables_map arguments;
|
||||
boptions::store ( boptions::parse_environment(options,environmentMapper), arguments );
|
||||
boptions::notify ( arguments );
|
||||
|
||||
bfs::path::default_name_check ( bfs::portable_posix_name );
|
||||
|
||||
const string strSysConfDir = SYS_CONF_DIR;
|
||||
bfs::path sysConfDir ( strSysConfDir );
|
||||
if ( not sysConfDir.has_root_path() ) {
|
||||
if ( arguments.count("coriolis_top") ) {
|
||||
sysConfDir = arguments["coriolis_top"].as<string>() / sysConfDir;
|
||||
} else {
|
||||
cerr << Error("Environment variable CORIOLIS_TOP not set,"
|
||||
" may be unable to read configuration...") << endl;
|
||||
}
|
||||
}
|
||||
sysConfDir /= "coriolis2";
|
||||
_pathes.insert ( make_pair("etc",sysConfDir) );
|
||||
|
||||
// Default configuration loading.
|
||||
Cfg::Configuration* conf = Cfg::Configuration::get ();
|
||||
|
||||
Cfg::getParamBool("misc.catchCore" ,true )->registerCb ( catchCoreChanged );
|
||||
Cfg::getParamBool("misc.verboseLevel1",true )->registerCb ( verboseLevel1Changed );
|
||||
Cfg::getParamBool("misc.verboseLevel2",true )->registerCb ( verboseLevel2Changed );
|
||||
Cfg::getParamBool("misc.info" ,false)->registerCb ( infoChanged );
|
||||
Cfg::getParamBool("misc.logMode" ,true )->registerCb ( logModeChanged );
|
||||
Cfg::getParamInt ("misc.traceLevel" ,1000 )->registerCb ( traceLevelChanged );
|
||||
|
||||
// Immediate update from the configuration.
|
||||
catchCoreChanged ( Cfg::getParamBool("misc.catchCore" ) );
|
||||
verboseLevel1Changed ( Cfg::getParamBool("misc.verboseLevel1") );
|
||||
verboseLevel2Changed ( Cfg::getParamBool("misc.verboseLevel2") );
|
||||
infoChanged ( Cfg::getParamBool("misc.info" ) );
|
||||
logModeChanged ( Cfg::getParamBool("misc.logMode" ) );
|
||||
traceLevelChanged ( Cfg::getParamInt ("misc.traceLevel" ) );
|
||||
|
||||
bool systemConfFound = false;
|
||||
bfs::path systemConfFile = sysConfDir / "tools.configuration.xml";
|
||||
if ( bfs::exists(systemConfFile) ) {
|
||||
systemConfFound = true;
|
||||
conf->readFromFile ( systemConfFile.string() );
|
||||
} else {
|
||||
cerr << Warning("System configuration file:\n <%s> not found."
|
||||
,systemConfFile.string().c_str()) << endl;
|
||||
}
|
||||
|
||||
bool dotConfFound = false;
|
||||
bfs::path dotConfFile = "./.coriolis2.configuration.xml";
|
||||
if ( bfs::exists(dotConfFile) ) {
|
||||
dotConfFound = true;
|
||||
conf->readFromFile ( dotConfFile.string() );
|
||||
}
|
||||
|
||||
// Delayed printing, as we known only now whether VerboseLevel1 is requested.
|
||||
if ( cmess1.enabled() ) {
|
||||
cmess1 << " o Reading Configuration. " << endl;
|
||||
if (systemConfFound) cmess1 << " - <" << systemConfFile.string() << ">." << endl;
|
||||
if (dotConfFound) cmess1 << " - <" << dotConfFile.string() << ">." << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
System *System::get ()
|
||||
{
|
||||
if ( _singleton == NULL ) {
|
||||
_singleton = new System ();
|
||||
}
|
||||
|
||||
return _singleton;
|
||||
}
|
||||
|
||||
|
||||
void System::trapSig ( int sig )
|
||||
void System::_trapSig ( int sig )
|
||||
{
|
||||
cerr << "\n\n[CRL ERROR] System::trapSig():\n" << endl;
|
||||
cerr << "\n\n[CRL ERROR] System::_trapSig():\n" << endl;
|
||||
|
||||
switch ( sig ) {
|
||||
case SIGINT:
|
||||
|
@ -193,7 +328,7 @@ namespace CRL {
|
|||
cerr << "\n Please e-mail to <alliance-users@asim.lip6.fr>.\n"
|
||||
<< "\n program terminated ";
|
||||
|
||||
if ( getSystem()->getCatchCore() ) {
|
||||
if ( getCatchCore() ) {
|
||||
cerr << "(core not dumped).\n";
|
||||
exit ( 1 );
|
||||
} else {
|
||||
|
@ -221,7 +356,20 @@ namespace CRL {
|
|||
}
|
||||
|
||||
|
||||
System *System::getSystem () { return _singleton; }
|
||||
const bfs::path& System::_getPath ( const string& key )
|
||||
{
|
||||
static bfs::path nullPath ("no_path");
|
||||
|
||||
cerr << "Looking up: " << key << endl;
|
||||
|
||||
map<const string,bfs::path>::const_iterator ipath = _pathes.find ( key );
|
||||
if ( ipath == _pathes.end() ) return nullPath;
|
||||
|
||||
cerr << "Successfull lookup: "; cerr.flush();
|
||||
cerr << (*ipath).second.string() << endl;
|
||||
|
||||
return (*ipath).second;
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
@ -299,5 +447,5 @@ namespace CRL {
|
|||
// Class : "mstream".
|
||||
|
||||
|
||||
void mstream::enable ( unsigned int mask ) { _activeMask |= mask; }
|
||||
void mstream::disable ( unsigned int mask ) { _activeMask &= ~mask; }
|
||||
void mstream::enable ( unsigned int mask ) { _activeMask |= mask; }
|
||||
void mstream::disable ( unsigned int mask ) { _activeMask &= ~mask; }
|
||||
|
|
|
@ -33,6 +33,9 @@
|
|||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
namespace bfs = boost::filesystem;
|
||||
|
||||
#include "hurricane/Commons.h"
|
||||
#include "hurricane/Error.h"
|
||||
#include "hurricane/Slot.h"
|
||||
|
@ -55,26 +58,30 @@ namespace CRL {
|
|||
|
||||
class System {
|
||||
public:
|
||||
// Constructor & Destructor.
|
||||
static System* create ();
|
||||
// Methods.
|
||||
static System* getSystem ();
|
||||
static void trapSig ( int sig );
|
||||
inline bool getCatchCore ();
|
||||
inline bool setCatchCore ( bool catchCore );
|
||||
|
||||
static System* get ();
|
||||
static inline bool getCatchCore ();
|
||||
static inline const bfs::path& getPath ( const std::string& );
|
||||
static inline bool setCatchCore ( bool catchCore );
|
||||
private:
|
||||
// Internal: Attributes.
|
||||
static System* _singleton;
|
||||
bool _catchCore;
|
||||
|
||||
// Constructors & Destructors.
|
||||
inline System ();
|
||||
std::map<const std::string,bfs::path> _pathes;
|
||||
private:
|
||||
System ();
|
||||
System ( const System &other );
|
||||
System& operator= ( const System &other );
|
||||
static void _trapSig ( int sig );
|
||||
inline bool _getCatchCore ();
|
||||
const bfs::path& _getPath ( const std::string& );
|
||||
inline bool _setCatchCore ( bool catchCore );
|
||||
};
|
||||
|
||||
|
||||
inline bool System::getCatchCore () { return get()->_getCatchCore(); }
|
||||
inline const bfs::path& System::getPath ( const std::string& key ) { return get()->_getPath(key); }
|
||||
inline bool System::setCatchCore ( bool catchCore ) { return get()->_setCatchCore(catchCore); }
|
||||
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Class : "CRL::IoFile ()".
|
||||
//
|
||||
|
@ -123,9 +130,8 @@ namespace CRL {
|
|||
|
||||
|
||||
// Inline Methods.
|
||||
inline System::System (): _catchCore(true) { }
|
||||
inline bool System::getCatchCore () { return _catchCore; }
|
||||
inline bool System::setCatchCore ( bool catchCore ) { return _catchCore = catchCore; }
|
||||
inline bool System::_getCatchCore () { return _catchCore; }
|
||||
inline bool System::_setCatchCore ( bool catchCore ) { return _catchCore = catchCore; }
|
||||
|
||||
inline IoFile::IoFile ( string path ): _file(NULL)
|
||||
, _path(path)
|
||||
|
@ -273,6 +279,7 @@ inline std::string tty::bgcolor ( unsigned int mask )
|
|||
static void disable ( unsigned int mask );
|
||||
inline mstream ( unsigned int mask, std::ostream &s );
|
||||
inline unsigned int getStreamMask() const;
|
||||
static inline unsigned int getActiveMask();
|
||||
inline bool enabled () const;
|
||||
// Overload for formatted outputs.
|
||||
template<typename T> inline mstream& operator<< ( T& t );
|
||||
|
@ -292,6 +299,7 @@ inline std::string tty::bgcolor ( unsigned int mask )
|
|||
|
||||
inline mstream::mstream ( unsigned int mask, std::ostream& s ): std::ostream(s.rdbuf()) , _streamMask(mask) {}
|
||||
inline unsigned int mstream::getStreamMask() const { return _streamMask; }
|
||||
inline unsigned int mstream::getActiveMask() { return _activeMask; }
|
||||
inline bool mstream::enabled () const { return (_streamMask & _activeMask); }
|
||||
inline mstream& mstream::flush () { if (enabled()) static_cast<std::ostream*>(this)->flush(); return *this; }
|
||||
inline mstream& mstream::operator<< ( std::ostream& (*pf)(std::ostream&) ) { if (enabled()) (*pf)(*this); return *this; }
|
||||
|
@ -377,13 +385,13 @@ class Dots {
|
|||
|
||||
class linefill : public std::ostream {
|
||||
public:
|
||||
inline linefill ( const std::string& header, std::ostream &s );
|
||||
inline linefill ( const std::string& header, mstream &s );
|
||||
// Overload for formatted outputs.
|
||||
template<typename T> inline linefill& operator<< ( T& t );
|
||||
template<typename T> inline linefill& operator<< ( T* t );
|
||||
template<typename T> inline linefill& operator<< ( const T& t );
|
||||
template<typename T> inline linefill& operator<< ( const T* t );
|
||||
inline std::ostream& base ();
|
||||
inline mstream& base ();
|
||||
inline void _print ( const std::string& field );
|
||||
inline linefill& flush ();
|
||||
inline linefill& reset ();
|
||||
|
@ -392,17 +400,19 @@ class linefill : public std::ostream {
|
|||
|
||||
// Internal: Attributes.
|
||||
private:
|
||||
mstream& _base;
|
||||
std::string _header;
|
||||
size_t _width;
|
||||
size_t _lines;
|
||||
};
|
||||
|
||||
|
||||
inline linefill::linefill ( const std::string& header, std::ostream& s ): std::ostream(s.rdbuf()) , _header(header), _width(0), _lines(0) {}
|
||||
inline std::ostream& linefill::base () { return (*static_cast<std::ostream*>(this)); }
|
||||
inline linefill& linefill::reset () { (*this) << std::endl; _width=0; return *this; }
|
||||
inline linefill& linefill::flush () { static_cast<std::ostream*>(this)->flush(); return *this; }
|
||||
inline linefill& linefill::operator<< ( std::ostream& (*pf)(std::ostream&) ) { (*pf)(*this); return *this; }
|
||||
inline linefill::linefill ( const std::string& header, mstream& s ): std::ostream(s.rdbuf()), _base(s), _header(header), _width(0), _lines(0) {}
|
||||
//inline std::ostream& linefill::base () { return (*static_cast<std::ostream*>(this)); }
|
||||
inline mstream& linefill::base () { return _base; }
|
||||
inline linefill& linefill::reset () { _base << std::endl; _width=0; return *this; }
|
||||
inline linefill& linefill::flush () { static_cast<mstream&>(_base).flush(); return *this; }
|
||||
inline linefill& linefill::operator<< ( std::ostream& (*pf)(std::ostream&) ) { (*pf)(static_cast<mstream&>(_base)); return *this; }
|
||||
|
||||
inline void linefill::_print ( const std::string& field ) {
|
||||
size_t fieldWidth = field.length();
|
||||
|
|
|
@ -128,7 +128,7 @@ int main ( int argc, char *argv[] )
|
|||
exit ( 0 );
|
||||
}
|
||||
|
||||
System::getSystem()->setCatchCore ( not coreDump );
|
||||
System::get()->setCatchCore ( not coreDump );
|
||||
if ( verbose1 ) mstream::enable ( mstream::VerboseLevel1 );
|
||||
if ( verbose2 ) mstream::enable ( mstream::VerboseLevel2 );
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ int main(int argc, char *argv[]) {
|
|||
exit ( 0 );
|
||||
}
|
||||
|
||||
System::getSystem()->setCatchCore ( not coreDump );
|
||||
System::get()->setCatchCore ( not coreDump );
|
||||
if ( verbose1 ) mstream::enable ( mstream::VerboseLevel1 );
|
||||
if ( verbose2 ) mstream::enable ( mstream::VerboseLevel2 );
|
||||
|
||||
|
|
Loading…
Reference in New Issue