From: <den...@us...> - 2010-01-21 13:26:18
|
Revision: 101 http://stdair.svn.sourceforge.net/stdair/?rev=101&view=rev Author: denis_arnaud Date: 2010-01-21 13:26:12 +0000 (Thu, 21 Jan 2010) Log Message: ----------- [Dev] The log output stream initialisation has been moved into the StdAir library. Modified Paths: -------------- trunk/stdair/stdair/STDAIR_Types.hpp trunk/stdair/stdair/basic/sources.mk trunk/stdair/stdair/service/Logger.cpp trunk/stdair/stdair/service/Logger.hpp Added Paths: ----------- trunk/stdair/stdair/basic/BasDBParams.cpp trunk/stdair/stdair/basic/BasDBParams.hpp trunk/stdair/stdair/basic/BasLogParams.cpp trunk/stdair/stdair/basic/BasLogParams.hpp Modified: trunk/stdair/stdair/STDAIR_Types.hpp =================================================================== --- trunk/stdair/stdair/STDAIR_Types.hpp 2010-01-20 21:33:53 UTC (rev 100) +++ trunk/stdair/stdair/STDAIR_Types.hpp 2010-01-21 13:26:12 UTC (rev 101) @@ -22,6 +22,9 @@ class FileNotFoundException : public RootException { }; + class NonInitialisedLogServiceException : public RootException { + }; + class NonInitialisedServiceException : public RootException { }; Added: trunk/stdair/stdair/basic/BasDBParams.cpp =================================================================== --- trunk/stdair/stdair/basic/BasDBParams.cpp (rev 0) +++ trunk/stdair/stdair/basic/BasDBParams.cpp 2010-01-21 13:26:12 UTC (rev 101) @@ -0,0 +1,61 @@ +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <cassert> +#include <istream> +#include <ostream> +#include <sstream> +// StdAir +#include <stdair/basic/BasDBParams.hpp> + +namespace stdair { + + // ////////////////////////////////////////////////////////////////////// + BasDBParams::BasDBParams (const std::string& iDBUser, + const std::string& iDBPasswd, + const std::string& iDBHost, + const std::string& iDBPort, + const std::string& iDBName) + : _user (iDBUser), _passwd (iDBPasswd), _host (iDBHost), _port (iDBPort), + _dbname (iDBName) { + } + + // ////////////////////////////////////////////////////////////////////// + BasDBParams::~BasDBParams() { + } + + // ////////////////////////////////////////////////////////////////////// + void BasDBParams::toStream (std::ostream& ioOut) const { + ioOut << toString(); + } + + // ////////////////////////////////////////////////////////////////////// + void BasDBParams::fromStream (std::istream&) { + } + + // ////////////////////////////////////////////////////////////////////// + std::string BasDBParams::toShortString() const { + std::ostringstream oStr; + oStr << _dbname << "." << _user << "@" << _host << ":" << _port; + return oStr.str(); + } + + // ////////////////////////////////////////////////////////////////////// + std::string BasDBParams::toString() const { + std::ostringstream oStr; + oStr << _dbname << "." << _user << "@" << _host << ":" << _port; + return oStr.str(); + } + + // ////////////////////////////////////////////////////////////////////// + bool BasDBParams::check () const { + if (_user.empty() == true || _passwd.empty() == true + || _host.empty() == true || _port.empty() + || _dbname.empty() == true) { + return false; + } + return true; + } + +} Added: trunk/stdair/stdair/basic/BasDBParams.hpp =================================================================== --- trunk/stdair/stdair/basic/BasDBParams.hpp (rev 0) +++ trunk/stdair/stdair/basic/BasDBParams.hpp 2010-01-21 13:26:12 UTC (rev 101) @@ -0,0 +1,125 @@ +#ifndef __STDAIR_BAS_BASDBPARAMS_HPP +#define __STDAIR_BAS_BASDBPARAMS_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <iosfwd> +#include <string> +// Stdair +#include <stdair/STDAIR_Types.hpp> + +namespace stdair { + + /** Structure holding the parameters for connection to a database. */ + struct BasDBParams { + public: + // ///////// Getters //////// + /** Get the database user name. */ + std::string getUser() const { + return _user; + } + + /** Get the database user password. */ + std::string getPassword() const { + return _passwd; + } + + /** Get the database host name. */ + std::string getHost() const { + return _host; + } + + /** Get the database port number. */ + std::string getPort() const { + return _port; + } + + /** Get the database name. */ + std::string getDBName() const { + return _dbname; + } + + + // ///////// Setters ////////// + /** Set the database user name. */ + void setUser (const std::string& iUser) { + _user = iUser; + } + + /** Set the database password. */ + void setPassword (const std::string& iPasswd) { + _passwd = iPasswd; + } + + /** Set the database host name. */ + void setHost (const std::string& iHost) { + _host = iHost; + } + + /** Set the database port number. */ + void setPort (const std::string& iPort) { + _port = iPort; + } + + /** Set the database name. */ + void setDBName (const std::string& iDBName) { + _dbname = iDBName; + } + + + public: + // ///////// Busines methods //////// + /** Check that all the parameters are fine. */ + bool check () const; + + + public: + // ///////// Display methods //////// + /** Dump a structure into an output stream. + @param ostream& the output stream. */ + void toStream (std::ostream& ioOut) const; + + /** Read a structure from an input stream. + @param istream& the input stream. */ + void fromStream (std::istream&); + + /** Get a short display of the DBParams structure. */ + std::string toShortString() const; + + /** Get the serialised version of the DBParams structure. */ + std::string toString() const; + + + public: + /** Main Constructor. */ + BasDBParams (const std::string& iDBUser, const std::string& iDBPasswd, + const std::string& iDBHost, const std::string& iDBPort, + const std::string& iDBName); + + /** Default Constructor. */ + // BasDBParams (); + /** Default copy constructor. */ + // BasDBParams (const BasDBParams&); + + /** Destructor. */ + ~BasDBParams(); + + + private: + // /////// Attributes ///////// + /** Database user name. */ + std::string _user; + /** Database user password. */ + std::string _passwd; + /** Database host name. */ + std::string _host; + /** Database port number. */ + std::string _port; + /** Database name. */ + std::string _dbname; + }; + +} +#endif // __STDAIR_BAS_BASDBPARAMS_HPP Added: trunk/stdair/stdair/basic/BasLogParams.cpp =================================================================== --- trunk/stdair/stdair/basic/BasLogParams.cpp (rev 0) +++ trunk/stdair/stdair/basic/BasLogParams.cpp 2010-01-21 13:26:12 UTC (rev 101) @@ -0,0 +1,47 @@ +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <cassert> +#include <istream> +#include <ostream> +#include <sstream> +// StdAir +#include <stdair/basic/BasLogParams.hpp> + +namespace stdair { + + // ////////////////////////////////////////////////////////////////////// + BasLogParams::BasLogParams (const LOG::EN_LogLevel iLogLevel, + std::ostream& ioLogOutputStream) + : _logLevel (iLogLevel), _logStream (ioLogOutputStream) { + } + + // ////////////////////////////////////////////////////////////////////// + BasLogParams::~BasLogParams() { + } + + // ////////////////////////////////////////////////////////////////////// + void BasLogParams::toStream (std::ostream& ioOut) const { + ioOut << toString(); + } + + // ////////////////////////////////////////////////////////////////////// + void BasLogParams::fromStream (std::istream&) { + } + + // ////////////////////////////////////////////////////////////////////// + std::string BasLogParams::toShortString() const { + std::ostringstream oStr; + oStr << LOG::_logLevels[_logLevel]; + return oStr.str(); + } + + // ////////////////////////////////////////////////////////////////////// + std::string BasLogParams::toString() const { + std::ostringstream oStr; + oStr << LOG::_logLevels[_logLevel]; + return oStr.str(); + } + +} Added: trunk/stdair/stdair/basic/BasLogParams.hpp =================================================================== --- trunk/stdair/stdair/basic/BasLogParams.hpp (rev 0) +++ trunk/stdair/stdair/basic/BasLogParams.hpp 2010-01-21 13:26:12 UTC (rev 101) @@ -0,0 +1,82 @@ +#ifndef __STDAIR_BAS_BASLOGPARAMS_HPP +#define __STDAIR_BAS_BASLOGPARAMS_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <iosfwd> +#include <string> +// Stdair +#include <stdair/STDAIR_Types.hpp> + +namespace stdair { + + /** Structure holding parameters for logging. */ + struct BasLogParams { + friend class Logger; + public: + // ///////// Getters //////// + /** Get the log level. */ + const LOG::EN_LogLevel& getLogLevel() const { + return _logLevel; + } + + /** Get the log output stream. */ + std::ostream& getLogStream() const { + return _logStream; + } + + + // ///////// Setters ////////// + // No setters + + + public: + // ///////// Busines methods //////// + /** Check that all the parameters are fine. */ + bool check () const; + + + public: + // ///////// Display methods //////// + /** Dump a structure into an output stream. + @param ostream& the output stream. */ + void toStream (std::ostream& ioOut) const; + + /** Read a structure from an input stream. + @param istream& the input stream. */ + void fromStream (std::istream&); + + /** Get a short display of the LOGParams structure. */ + std::string toShortString() const; + + /** Get the serialised version of the LOGParams structure. */ + std::string toString() const; + + + public: + /** Main Constructor. */ + BasLogParams (const LOG::EN_LogLevel iLogLevel, + std::ostream& ioLogOutputStream); + + /** Default Constructor. */ + // BasLogParams (); + /** Default copy constructor. */ + // BasLogParams (const BasLogParams&); + + /** Destructor. */ + ~BasLogParams(); + + + private: + // /////// Attributes ///////// + /** Log level (e.g., LOG::DEBUG). */ + const LOG::EN_LogLevel _logLevel; + + /** Log output stream (e.g., std::cout). */ + std::ostream& _logStream; + }; + +} +#endif // __STDAIR_BAS_BASLOGPARAMS_HPP Modified: trunk/stdair/stdair/basic/sources.mk =================================================================== --- trunk/stdair/stdair/basic/sources.mk 2010-01-20 21:33:53 UTC (rev 100) +++ trunk/stdair/stdair/basic/sources.mk 2010-01-21 13:26:12 UTC (rev 101) @@ -7,8 +7,12 @@ $(top_srcdir)/stdair/basic/BasConst_Period_BOM.hpp \ $(top_srcdir)/stdair/basic/BasConst_TravelSolution.hpp \ $(top_srcdir)/stdair/basic/BasChronometer.hpp \ - $(top_srcdir)/stdair/basic/BasFileMgr.hpp + $(top_srcdir)/stdair/basic/BasFileMgr.hpp \ + $(top_srcdir)/stdair/basic/BasLogParams.hpp \ + $(top_srcdir)/stdair/basic/BasDBParams.hpp bas_cc_sources = \ $(top_srcdir)/stdair/basic/BasConst.cpp \ $(top_srcdir)/stdair/basic/BasChronometer.cpp \ - $(top_srcdir)/stdair/basic/BasFileMgr.cpp + $(top_srcdir)/stdair/basic/BasFileMgr.cpp \ + $(top_srcdir)/stdair/basic/BasLogParams.cpp \ + $(top_srcdir)/stdair/basic/BasDBParams.cpp Modified: trunk/stdair/stdair/service/Logger.cpp =================================================================== --- trunk/stdair/stdair/service/Logger.cpp 2010-01-20 21:33:53 UTC (rev 100) +++ trunk/stdair/stdair/service/Logger.cpp 2010-01-21 13:26:12 UTC (rev 101) @@ -2,63 +2,56 @@ // Import section // ////////////////////////////////////////////////////////////////////// // Stdair Logger -#include <stdair/factory/FacSupervisor.hpp> +//#include <stdair/factory/FacSupervisor.hpp> #include <stdair/service/Logger.hpp> namespace stdair { - Logger* Logger::_instance = NULL; + Logger* Logger::_instance = NULL; - // ////////////////////////////////////////////////////////////////////// - Logger::Logger () : _logStream (&std::cout) { - assert (false); - } + // ////////////////////////////////////////////////////////////////////// + Logger::Logger () : _logStream (std::cout), _level (LOG::DEBUG) { + assert (false); + } - // ////////////////////////////////////////////////////////////////////// - Logger::Logger (const Logger&) : _logStream (&std::cout) { - assert (false); - } + // ////////////////////////////////////////////////////////////////////// + Logger::Logger (const Logger&) : _logStream (std::cout), _level (LOG::DEBUG) { + assert (false); + } - // ////////////////////////////////////////////////////////////////////// - Logger::Logger (const LOG::EN_LogLevel iLevel, std::ostream& ioLogStream) - : _level (iLevel), _logStream (&ioLogStream) { - } + // ////////////////////////////////////////////////////////////////////// + Logger::Logger (const stdair::BasLogParams& iLogParams) + : _level (iLogParams._logLevel), _logStream (iLogParams._logStream) { + } - // ////////////////////////////////////////////////////////////////////// - Logger::~Logger () { - _logStream = NULL; - } + // ////////////////////////////////////////////////////////////////////// + Logger::~Logger () { + } - // ////////////////////////////////////////////////////////////////////// - void Logger::clean() { - delete _instance; _instance = NULL; - } - - // ////////////////////////////////////////////////////////////////////// - LOG::EN_LogLevel Logger::getLogLevel() { - return _level; - } + // ////////////////////////////////////////////////////////////////////// + void Logger::init (const BasLogParams& iLogParams) { + // Sanity check + if (_instance != NULL) { + STDAIR_LOG_ERROR ("Error: the log stream has already been initialised"); + // TODO: throw an exception? - // ////////////////////////////////////////////////////////////////////// - std::ostream& Logger::getLogStream() { - assert (_logStream != NULL); - return *_logStream; + } else { + _instance = new Logger (iLogParams); } + } - // ////////////////////////////////////////////////////////////////////// - void Logger::setLogParameters (const LOG::EN_LogLevel iLogLevel, - std::ostream& ioLogStream) { - _level = iLogLevel; - _logStream = &ioLogStream; + // ////////////////////////////////////////////////////////////////////// + Logger& Logger::instance() { + if (_instance == NULL) { + throw NonInitialisedLogServiceException(); } - - // ////////////////////////////////////////////////////////////////////// - Logger& Logger::instance() { - if (_instance == NULL) { - _instance = new Logger (LOG::DEBUG, std::cout); - } - assert (_instance != NULL); - return *_instance; - } - + assert (_instance != NULL); + return *_instance; + } + + // ////////////////////////////////////////////////////////////////////// + void Logger::clean() { + delete _instance; _instance = NULL; + } + } Modified: trunk/stdair/stdair/service/Logger.hpp =================================================================== --- trunk/stdair/stdair/service/Logger.hpp 2010-01-20 21:33:53 UTC (rev 100) +++ trunk/stdair/stdair/service/Logger.hpp 2010-01-21 13:26:12 UTC (rev 101) @@ -9,8 +9,9 @@ #include <iostream> #include <sstream> #include <string> -// STDAIR +// StdAir #include <stdair/STDAIR_Types.hpp> +#include <stdair/basic/BasLogParams.hpp> // /////////////// LOG MACROS ///////////////// #define STDAIR_LOG_CORE(iLevel, iToBeLogged) \ @@ -52,32 +53,26 @@ void log (const LOG::EN_LogLevel iLevel, const int iLineNumber, const std::string& iFileName, const T& iToBeLogged) { if (iLevel <= _level) { - assert (_logStream != NULL); - *_logStream << "[" << LOG::_logLevels[iLevel] << "]" << iFileName << ":" - << iLineNumber << ": " << iToBeLogged << std::endl; + _logStream << "[" << LOG::_logLevels[iLevel] << "]" << iFileName << ":" + << iLineNumber << ": " << iToBeLogged << std::endl; } } - /** Get the log level. */ - LOG::EN_LogLevel getLogLevel(); + /** Initialise the static Logger instance. */ + static void init (const stdair::BasLogParams&); - /** get the log stream. */ - std::ostream& getLogStream(); - - /** Set the logger parameters (level and stream). */ - void setLogParameters (const LOG::EN_LogLevel iLogLevel, - std::ostream& ioLogStream); - - /** Return the static Logger instance.*/ + /** Return the static Logger instance. */ static Logger& instance(); private: /** Default constructors are private so that only the required constructor can be used. */ + Logger (const stdair::BasLogParams&); + /** Default constructor. It must not be used. */ Logger (); + /** Default copy constructor. It must not be used. */ Logger (const Logger&); - Logger (const LOG::EN_LogLevel iLevel, std::ostream& ioLogStream); /** Destructor. */ ~Logger (); @@ -85,14 +80,14 @@ static void clean(); private: + /** Instance object.*/ + static Logger* _instance; + /** Log level. */ LOG::EN_LogLevel _level; /** Stream dedicated to the logs. */ - std::ostream* _logStream; - - /** Instance object.*/ - static Logger* _instance; + std::ostream& _logStream; }; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |