From: <den...@us...> - 2010-01-20 20:09:43
|
Revision: 99 http://stdair.svn.sourceforge.net/stdair/?rev=99&view=rev Author: denis_arnaud Date: 2010-01-20 20:09:35 +0000 (Wed, 20 Jan 2010) Log Message: ----------- [Dev] Implemented the Logger service. Modified Paths: -------------- trunk/stdair/stdair/Makefile.am trunk/stdair/stdair/STDAIR_Types.hpp trunk/stdair/stdair/basic/sources.mk trunk/stdair/stdair/core/Makefile.am trunk/stdair/stdair/factory/FacSupervisor.cpp trunk/stdair/stdair/factory/FacSupervisor.hpp Added Paths: ----------- trunk/stdair/stdair/basic/BasFileMgr.cpp trunk/stdair/stdair/basic/BasFileMgr.hpp trunk/stdair/stdair/service/Logger.cpp trunk/stdair/stdair/service/Logger.hpp trunk/stdair/stdair/service/Makefile.am trunk/stdair/stdair/service/sources.mk Property Changed: ---------------- trunk/stdair/stdair/service/ Modified: trunk/stdair/stdair/Makefile.am =================================================================== --- trunk/stdair/stdair/Makefile.am 2010-01-20 17:07:06 UTC (rev 98) +++ trunk/stdair/stdair/Makefile.am 2010-01-20 20:09:35 UTC (rev 99) @@ -1,3 +1,4 @@ +# stdair include $(top_srcdir)/Makefile.common include $(srcdir)/core/sources.mk @@ -5,7 +6,7 @@ MAINTAINERCLEANFILES = Makefile.in -SUBDIRS = basic bom factory core config +SUBDIRS = basic bom factory config service core #EXTRA_DIST = config_msvc.h EXTRA_DIST = Modified: trunk/stdair/stdair/STDAIR_Types.hpp =================================================================== --- trunk/stdair/stdair/STDAIR_Types.hpp 2010-01-20 17:07:06 UTC (rev 98) +++ trunk/stdair/stdair/STDAIR_Types.hpp 2010-01-20 20:09:35 UTC (rev 99) @@ -7,7 +7,7 @@ // STL #include <string> #include <vector> -#include <list> +#include <map> // Boost (Extended STL) #include <boost/date_time/gregorian/gregorian.hpp> #include <boost/date_time/posix_time/posix_time.hpp> @@ -15,7 +15,7 @@ namespace stdair { - // ///////// Exceptions /////////// + // ///////// Exceptions /////////// class RootException : public std::exception { }; @@ -46,6 +46,9 @@ VERBOSE, LAST_VALUE } EN_LogLevel; + + static const std::string _logLevels[LAST_VALUE] = + {"C", "E", "N", "W", "D", "V"}; } // //////// Type definitions ///////// Added: trunk/stdair/stdair/basic/BasFileMgr.cpp =================================================================== --- trunk/stdair/stdair/basic/BasFileMgr.cpp (rev 0) +++ trunk/stdair/stdair/basic/BasFileMgr.cpp 2010-01-20 20:09:35 UTC (rev 99) @@ -0,0 +1,29 @@ +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <cassert> +// Boost (STL Extension) +// Boost Filesystem (http://www.boost.org/doc/libs/1_41_0/libs/filesystem/doc/index.htm) +#include <boost/filesystem.hpp> +// StdAir +#include <stdair/basic/BasFileMgr.hpp> + +namespace boostfs = boost::filesystem; + +namespace stdair { + + // ////////////////////////////////////////////////////////////////////// + bool BasFileMgr::doesExistAndIsReadable (const std::string& iFilepath) { + bool oFine = false; + + boostfs::path lPath (iFilepath); + + if (boostfs::exists (lPath) == true && boostfs::is_regular (lPath) == true) { + oFine = true; + } + + return true; + } + +} Added: trunk/stdair/stdair/basic/BasFileMgr.hpp =================================================================== --- trunk/stdair/stdair/basic/BasFileMgr.hpp (rev 0) +++ trunk/stdair/stdair/basic/BasFileMgr.hpp 2010-01-20 20:09:35 UTC (rev 99) @@ -0,0 +1,22 @@ +#ifndef __STDAIR_BAS_BASFILEMGR_HPP +#define __STDAIR_BAS_BASFILEMGR_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <string> + +namespace stdair { + + /** Helper class for operations on files and on the file-system. */ + struct BasFileMgr { + public: + + // //////////// Functional Support Methods //////////// + static bool doesExistAndIsReadable (const std::string& iFilepath); + + }; + +} +#endif // __STDAIR_BAS_BASFILEMGR_HPP Modified: trunk/stdair/stdair/basic/sources.mk =================================================================== --- trunk/stdair/stdair/basic/sources.mk 2010-01-20 17:07:06 UTC (rev 98) +++ trunk/stdair/stdair/basic/sources.mk 2010-01-20 20:09:35 UTC (rev 99) @@ -6,7 +6,9 @@ $(top_srcdir)/stdair/basic/BasConst_Yield.hpp \ $(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/BasChronometer.hpp \ + $(top_srcdir)/stdair/basic/BasFileMgr.hpp bas_cc_sources = \ $(top_srcdir)/stdair/basic/BasConst.cpp \ - $(top_srcdir)/stdair/basic/BasChronometer.cpp + $(top_srcdir)/stdair/basic/BasChronometer.cpp \ + $(top_srcdir)/stdair/basic/BasFileMgr.cpp Modified: trunk/stdair/stdair/core/Makefile.am =================================================================== --- trunk/stdair/stdair/core/Makefile.am 2010-01-20 17:07:06 UTC (rev 98) +++ trunk/stdair/stdair/core/Makefile.am 2010-01-20 20:09:35 UTC (rev 99) @@ -1,3 +1,4 @@ +# core include $(top_srcdir)/Makefile.common include $(srcdir)/sources.mk @@ -15,6 +16,8 @@ libstdair_la_LIBADD = \ $(top_builddir)/stdair/basic/libbas.la \ $(top_builddir)/stdair/bom/libbom.la \ - $(top_builddir)/stdair/factory/libfac.la + $(top_builddir)/stdair/factory/libfac.la \ + $(top_builddir)/stdair/service/libsvc.la libstdair_la_LDFLAGS = \ - $(BOOST_DATE_TIME_LIB) -version-info $(GENERIC_LIBRARY_VERSION) + $(BOOST_DATE_TIME_LIB) $(BOOST_PROGRAM_OPTIONS_LIB) $(BOOST_FILESYSTEM_LIB) \ + -version-info $(GENERIC_LIBRARY_VERSION) Modified: trunk/stdair/stdair/factory/FacSupervisor.cpp =================================================================== --- trunk/stdair/stdair/factory/FacSupervisor.cpp 2010-01-20 17:07:06 UTC (rev 98) +++ trunk/stdair/stdair/factory/FacSupervisor.cpp 2010-01-20 20:09:35 UTC (rev 99) @@ -1,12 +1,14 @@ // ////////////////////////////////////////////////////////////////////// // Import section // ////////////////////////////////////////////////////////////////////// -// C -#include <assert.h> -// STDAIR +// STL +#include <cassert> +#include <ostream> +// StdAir #include <stdair/factory/FacBomStructure.hpp> #include <stdair/factory/FacBomContent.hpp> #include <stdair/factory/FacSupervisor.hpp> +#include <stdair/service/Logger.hpp> namespace stdair { @@ -70,10 +72,16 @@ } // ////////////////////////////////////////////////////////////////////// + void FacSupervisor::cleanLoggerService() { + Logger::clean(); + } + + // ////////////////////////////////////////////////////////////////////// void FacSupervisor::cleanFactory () { if (_instance != NULL) { - _instance->cleanBomStructureLayer(); - _instance->cleanBomContentLayer(); + _instance->cleanBomStructureLayer(); + _instance->cleanBomContentLayer(); + _instance->cleanLoggerService(); } delete _instance; _instance = NULL; } Modified: trunk/stdair/stdair/factory/FacSupervisor.hpp =================================================================== --- trunk/stdair/stdair/factory/FacSupervisor.hpp 2010-01-20 17:07:06 UTC (rev 98) +++ trunk/stdair/stdair/factory/FacSupervisor.hpp 2010-01-20 20:09:35 UTC (rev 99) @@ -5,7 +5,10 @@ // Import section // ////////////////////////////////////////////////////////////////////// // STL +#include <iosfwd> #include <vector> +// StdAir +#include <stdair/STDAIR_Types.hpp> namespace stdair { @@ -48,6 +51,9 @@ for the BomContent layer. */ void cleanBomContentLayer(); + /** Delete the Logger object. */ + void cleanLoggerService(); + /** Clean the static instance. <br> The singleton is deleted.*/ static void cleanFactory (); Property changes on: trunk/stdair/stdair/service ___________________________________________________________________ Added: svn:ignore + .deps .libs Makefile Makefile.in Added: trunk/stdair/stdair/service/Logger.cpp =================================================================== --- trunk/stdair/stdair/service/Logger.cpp (rev 0) +++ trunk/stdair/stdair/service/Logger.cpp 2010-01-20 20:09:35 UTC (rev 99) @@ -0,0 +1,64 @@ +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// Stdair Logger +#include <stdair/factory/FacSupervisor.hpp> +#include <stdair/service/Logger.hpp> + +namespace stdair { + + Logger* Logger::_instance = NULL; + + // ////////////////////////////////////////////////////////////////////// + Logger::Logger () : _logStream (&std::cout) { + assert (false); + } + + // ////////////////////////////////////////////////////////////////////// + Logger::Logger (const Logger&) : _logStream (&std::cout) { + assert (false); + } + + // ////////////////////////////////////////////////////////////////////// + Logger::Logger (const LOG::EN_LogLevel iLevel, std::ostream& ioLogStream) + : _level (iLevel), _logStream (&ioLogStream) { + } + + // ////////////////////////////////////////////////////////////////////// + Logger::~Logger () { + _logStream = NULL; + } + + // ////////////////////////////////////////////////////////////////////// + void Logger::clean() { + delete _instance; _instance = NULL; + } + + // ////////////////////////////////////////////////////////////////////// + LOG::EN_LogLevel Logger::getLogLevel() { + return _level; + } + + // ////////////////////////////////////////////////////////////////////// + std::ostream& Logger::getLogStream() { + assert (_logStream != NULL); + return *_logStream; + } + + // ////////////////////////////////////////////////////////////////////// + void Logger::setLogParameters (const LOG::EN_LogLevel iLogLevel, + std::ostream& ioLogStream) { + _level = iLogLevel; + _logStream = &ioLogStream; + } + + // ////////////////////////////////////////////////////////////////////// + Logger& Logger::instance() { + if (_instance == NULL) { + _instance = new Logger (LOG::DEBUG, std::cout); + } + assert (_instance != NULL); + return *_instance; + } + +} Added: trunk/stdair/stdair/service/Logger.hpp =================================================================== --- trunk/stdair/stdair/service/Logger.hpp (rev 0) +++ trunk/stdair/stdair/service/Logger.hpp 2010-01-20 20:09:35 UTC (rev 99) @@ -0,0 +1,100 @@ +#ifndef __STDAIR_SVC_LOGGER_HPP +#define __STDAIR_SVC_LOGGER_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <cassert> +#include <iostream> +#include <sstream> +#include <string> +// STDAIR +#include <stdair/STDAIR_Types.hpp> + +// /////////////// LOG MACROS ///////////////// +#define STDAIR_LOG_CORE(iLevel, iToBeLogged) \ + { std::ostringstream ostr; ostr << iToBeLogged; \ + stdair::Logger::instance().log (iLevel, __LINE__, __FILE__, ostr.str()); } + +#define STDAIR_LOG_CRITICAL(iToBeLogged) \ + STDAIR_LOG_CORE (stdair::LOG::CRITICAL, iToBeLogged) + +#define STDAIR_LOG_ERROR(iToBeLogged) \ + STDAIR_LOG_CORE (stdair::LOG::ERROR, iToBeLogged) + +#define STDAIR_LOG_NOTIFICATION(iToBeLogged) \ + STDAIR_LOG_CORE (stdair::LOG::NOTIFICATION, iToBeLogged) + +#define STDAIR_LOG_WARNING(iToBeLogged) \ + STDAIR_LOG_CORE (stdair::LOG::WARNING, iToBeLogged) + +#define STDAIR_LOG_DEBUG(iToBeLogged) \ + STDAIR_LOG_CORE (stdair::LOG::DEBUG, iToBeLogged) + +#define STDAIR_LOG_VERBOSE(iToBeLogged) \ + STDAIR_LOG_CORE (stdair::LOG::VERBOSE, iToBeLogged) +// /////////// (END OF) LOG MACROS ///////////// + + +namespace stdair { + + /** Class holding the stream for logs. + <br>Note that the error logs are seen as standard output logs, + but with a higher level of visibility. */ + class Logger { + // Friend classes + friend class FacSupervisor; + public: + + /** Main log entry. */ + template <typename T> + 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; + } + } + + /** Get the log level. */ + LOG::EN_LogLevel getLogLevel(); + + /** 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.*/ + static Logger& instance(); + + + private: + /** Default constructors are private so that only the required + constructor can be used. */ + Logger (); + Logger (const Logger&); + Logger (const LOG::EN_LogLevel iLevel, std::ostream& ioLogStream); + /** Destructor. */ + ~Logger (); + + /** Delete the static Logger instance.*/ + static void clean(); + + private: + /** Log level. */ + LOG::EN_LogLevel _level; + + /** Stream dedicated to the logs. */ + std::ostream* _logStream; + + /** Instance object.*/ + static Logger* _instance; + }; + +} +#endif // __STDAIR_SVC_LOGGER_HPP + Added: trunk/stdair/stdair/service/Makefile.am =================================================================== --- trunk/stdair/stdair/service/Makefile.am (rev 0) +++ trunk/stdair/stdair/service/Makefile.am 2010-01-20 20:09:35 UTC (rev 99) @@ -0,0 +1,11 @@ +## service sub-directory +include $(top_srcdir)/Makefile.common +include $(srcdir)/sources.mk + +noinst_LTLIBRARIES= libsvc.la + +libsvc_la_SOURCES= $(svc_h_sources) $(svc_cc_sources) +libsvc_la_CXXFLAGS = + +#pkgincludedir = $(includedir)/@PACKAGE@/service +#pkginclude_HEADERS = $(svc_h_sources) Added: trunk/stdair/stdair/service/sources.mk =================================================================== --- trunk/stdair/stdair/service/sources.mk (rev 0) +++ trunk/stdair/stdair/service/sources.mk 2010-01-20 20:09:35 UTC (rev 99) @@ -0,0 +1,2 @@ +svc_h_sources = $(top_srcdir)/stdair/service/Logger.hpp +svc_cc_sources = $(top_srcdir)/stdair/service/Logger.cpp This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |