Removed custom logger(switching to WServer's logger) + removed custom config file
This commit is contained in:
@@ -1,28 +0,0 @@
|
|||||||
|
|
||||||
main = {
|
|
||||||
|
|
||||||
logger = {
|
|
||||||
level = 7; # level common for all loggers
|
|
||||||
file = {
|
|
||||||
enable = true;
|
|
||||||
path = "/var/lms/lms.log"; # comment to disable file logging
|
|
||||||
}
|
|
||||||
console = {
|
|
||||||
enable = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
database = {
|
|
||||||
path = "/var/lms/lms.db";
|
|
||||||
|
|
||||||
audio_extensions = "mp3 ogg oga aac m4a flac wav wma aif aiff ape mpc shn";
|
|
||||||
video_extensions = "flv avi mpg mpeg mp4 m4v mkv mov wmv ogv divx m2ts";
|
|
||||||
}
|
|
||||||
|
|
||||||
cover = {
|
|
||||||
file_extensions = "jpg jpeg";
|
|
||||||
file_max_size = 5000000;
|
|
||||||
file_preferred_names = "cover front";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -43,11 +43,6 @@ AC_CHECK_HEADERS([Wt/WApplication jpeglib.h],
|
|||||||
[],
|
[],
|
||||||
[AC_MSG_ERROR([Header not found or unusable !])])
|
[AC_MSG_ERROR([Header not found or unusable !])])
|
||||||
|
|
||||||
AC_CHECK_LIB([config++],
|
|
||||||
[main],
|
|
||||||
,
|
|
||||||
[AC_MSG_ERROR([config++ not found!])])
|
|
||||||
|
|
||||||
AC_CHECK_LIB([jpeg],
|
AC_CHECK_LIB([jpeg],
|
||||||
[jpeg_destroy],
|
[jpeg_destroy],
|
||||||
,
|
,
|
||||||
@@ -118,16 +113,6 @@ AC_CHECK_LIB( [boost_iostreams],
|
|||||||
,
|
,
|
||||||
[AC_MSG_ERROR([libboost_iostreams not found!])])
|
[AC_MSG_ERROR([libboost_iostreams not found!])])
|
||||||
|
|
||||||
AC_CHECK_LIB( [boost_log],
|
|
||||||
[main],
|
|
||||||
,
|
|
||||||
[AC_MSG_ERROR([libboost_log not found!])])
|
|
||||||
|
|
||||||
AC_CHECK_LIB( [boost_log_setup],
|
|
||||||
[main],
|
|
||||||
,
|
|
||||||
[AC_MSG_ERROR([libboost_log_setup not found!])])
|
|
||||||
|
|
||||||
# TODO -> PARAMETRIZE THIS
|
# TODO -> PARAMETRIZE THIS
|
||||||
AC_CHECK_LIB([wthttp],
|
AC_CHECK_LIB([wthttp],
|
||||||
[main],
|
[main],
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ lms_SOURCES = \
|
|||||||
$(srcdir)/av/FormatContext.cpp \
|
$(srcdir)/av/FormatContext.cpp \
|
||||||
$(srcdir)/av/InputFormatContext.cpp \
|
$(srcdir)/av/InputFormatContext.cpp \
|
||||||
$(srcdir)/av/Stream.cpp \
|
$(srcdir)/av/Stream.cpp \
|
||||||
$(srcdir)/config/ConfigReader.cpp \
|
|
||||||
$(srcdir)/cover/CoverArt.cpp \
|
$(srcdir)/cover/CoverArt.cpp \
|
||||||
$(srcdir)/cover/CoverArtGrabber.cpp \
|
$(srcdir)/cover/CoverArtGrabber.cpp \
|
||||||
$(srcdir)/database/Artist.cpp \
|
$(srcdir)/database/Artist.cpp \
|
||||||
|
|||||||
@@ -26,18 +26,6 @@
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
std::vector<std::string> splitStrings(const std::string& source)
|
|
||||||
{
|
|
||||||
std::vector<std::string> res;
|
|
||||||
std::istringstream oss(source);
|
|
||||||
|
|
||||||
std::string str;
|
|
||||||
while(oss >> str)
|
|
||||||
res.push_back(str);
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
isFileSupported(const boost::filesystem::path& file, const std::vector<boost::filesystem::path> extensions)
|
isFileSupported(const boost::filesystem::path& file, const std::vector<boost::filesystem::path> extensions)
|
||||||
{
|
{
|
||||||
@@ -67,15 +55,6 @@ Grabber::instance()
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
Grabber::init()
|
|
||||||
{
|
|
||||||
for (const std::string& extension : splitStrings( ConfigReader::instance().getString("main.cover.file_extensions")))
|
|
||||||
_fileExtensions.push_back("." + extension);
|
|
||||||
|
|
||||||
_maxFileSize = ConfigReader::instance().getULong("main.cover.file_max_size");
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<CoverArt>
|
std::vector<CoverArt>
|
||||||
Grabber::getFromInputFormatContext(const Av::InputFormatContext& input, std::size_t nbMaxCovers) const
|
Grabber::getFromInputFormatContext(const Av::InputFormatContext& input, std::size_t nbMaxCovers) const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -38,8 +38,6 @@ class Grabber
|
|||||||
|
|
||||||
static Grabber& instance();
|
static Grabber& instance();
|
||||||
|
|
||||||
void init();
|
|
||||||
|
|
||||||
std::vector<boost::filesystem::path> getCoverPaths(const boost::filesystem::path& directoryPath, std::size_t nbMaxCovers = 1) const;
|
std::vector<boost::filesystem::path> getCoverPaths(const boost::filesystem::path& directoryPath, std::size_t nbMaxCovers = 1) const;
|
||||||
std::vector<CoverArt> getFromDirectory(const boost::filesystem::path& path, std::size_t nbMaxCovers = 1) const;
|
std::vector<CoverArt> getFromDirectory(const boost::filesystem::path& path, std::size_t nbMaxCovers = 1) const;
|
||||||
std::vector<CoverArt> getFromInputFormatContext(const Av::InputFormatContext& input, std::size_t nbMaxCovers = 1) const;
|
std::vector<CoverArt> getFromInputFormatContext(const Av::InputFormatContext& input, std::size_t nbMaxCovers = 1) const;
|
||||||
@@ -50,9 +48,11 @@ class Grabber
|
|||||||
private:
|
private:
|
||||||
Grabber();
|
Grabber();
|
||||||
|
|
||||||
std::vector<boost::filesystem::path> _fileExtensions;
|
std::vector<boost::filesystem::path> _fileExtensions
|
||||||
std::size_t _maxFileSize;
|
= {"jpg", "jpeg"};
|
||||||
std::vector<boost::filesystem::path> _preferredFileNames;
|
std::size_t _maxFileSize = 5000000;
|
||||||
|
std::vector<boost::filesystem::path> _preferredFileNames
|
||||||
|
= {"cover", "front"};
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -96,8 +96,11 @@ class Updater
|
|||||||
|
|
||||||
Database::Handler _db;
|
Database::Handler _db;
|
||||||
|
|
||||||
std::vector<boost::filesystem::path> _audioExtensions;
|
std::vector<boost::filesystem::path> _audioExtensions
|
||||||
std::vector<boost::filesystem::path> _videoExtensions;
|
= {"mp3", "ogg", "oga", "aac", "m4a", "flac", "wav", "wma", "aif", "aiff", "ape", "mpc", "shn"};
|
||||||
|
|
||||||
|
std::vector<boost::filesystem::path> _videoExtensions
|
||||||
|
= {"flv", "avi", "mpg", "mpeg", "mp4", "m4v", "mkv", "mov", "wmv", "ogv", "divx", "m2ts"};
|
||||||
|
|
||||||
MetaData::Parser& _metadataParser;
|
MetaData::Parser& _metadataParser;
|
||||||
|
|
||||||
|
|||||||
@@ -155,6 +155,8 @@ Handler::getUser(const Wt::Auth::User& authUser)
|
|||||||
Wt::Dbo::SqlConnectionPool*
|
Wt::Dbo::SqlConnectionPool*
|
||||||
Handler::createConnectionPool(boost::filesystem::path p)
|
Handler::createConnectionPool(boost::filesystem::path p)
|
||||||
{
|
{
|
||||||
|
LMS_LOG(MOD_DB, SEV_INFO) << "Creating connection pool on file " << p;
|
||||||
|
|
||||||
Wt::Dbo::backend::Sqlite3 *connection = new Wt::Dbo::backend::Sqlite3(p.string());
|
Wt::Dbo::backend::Sqlite3 *connection = new Wt::Dbo::backend::Sqlite3(p.string());
|
||||||
|
|
||||||
connection->executeSql("pragma journal_mode=WAL");
|
connection->executeSql("pragma journal_mode=WAL");
|
||||||
|
|||||||
+27
-95
@@ -17,105 +17,37 @@
|
|||||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <boost/log/core.hpp>
|
|
||||||
#include <boost/log/trivial.hpp>
|
|
||||||
#include <boost/log/expressions.hpp>
|
|
||||||
#include <boost/log/sinks/text_file_backend.hpp>
|
|
||||||
#include <boost/log/keywords/filter.hpp>
|
|
||||||
#include <boost/log/utility/setup/file.hpp>
|
|
||||||
#include <boost/log/utility/setup/common_attributes.hpp>
|
|
||||||
#include <boost/log/utility/setup/console.hpp>
|
|
||||||
#include <boost/log/sources/severity_logger.hpp>
|
|
||||||
#include <boost/log/sources/record_ostream.hpp>
|
|
||||||
#include <boost/log/attributes/constant.hpp>
|
|
||||||
#include <boost/log/sources/severity_logger.hpp>
|
|
||||||
#include <boost/log/sources/record_ostream.hpp>
|
|
||||||
#include <boost/log/support/date_time.hpp>
|
|
||||||
#include <boost/log/attributes/named_scope.hpp>
|
|
||||||
|
|
||||||
#include <boost/date_time/posix_time/ptime.hpp>
|
|
||||||
|
|
||||||
#include "config/ConfigReader.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
#include "Logger.hpp"
|
#include "Logger.hpp"
|
||||||
|
|
||||||
Logger&
|
std::string getModuleName(Module mod)
|
||||||
Logger::instance()
|
|
||||||
{
|
{
|
||||||
static Logger instance;
|
switch (mod)
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger::Logger()
|
|
||||||
{
|
|
||||||
// Initialiaz loggers
|
|
||||||
static const std::vector<Module> modules =
|
|
||||||
{
|
{
|
||||||
MOD_AV,
|
case MOD_AV: return "AV";
|
||||||
MOD_COVER,
|
case MOD_COVER: return "COVER";
|
||||||
MOD_DB,
|
case MOD_DB: return "DB";
|
||||||
MOD_DBUPDATER,
|
case MOD_DBUPDATER: return "DB UPDATER";
|
||||||
MOD_MAIN,
|
case MOD_MAIN: return "MAIN";
|
||||||
MOD_METADATA,
|
case MOD_METADATA: return "METADATA";
|
||||||
MOD_REMOTE,
|
case MOD_REMOTE: return "REMOTE";
|
||||||
MOD_SERVICE,
|
case MOD_SERVICE: return "SERVICE";
|
||||||
MOD_TRANSCODE,
|
case MOD_TRANSCODE: return "TRANSCODE";
|
||||||
MOD_UI,
|
case MOD_UI: return "UI";
|
||||||
};
|
|
||||||
|
|
||||||
for(Module module : modules)
|
|
||||||
_loggers[module].add_attribute("Module", boost::log::attributes::constant< Module >(module));
|
|
||||||
}
|
|
||||||
|
|
||||||
boost::log::sources::severity_logger< Severity >&
|
|
||||||
Logger::get(Module module)
|
|
||||||
{
|
|
||||||
return _loggers[module];
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
Logger::init()
|
|
||||||
{
|
|
||||||
boost::log::add_common_attributes();
|
|
||||||
|
|
||||||
boost::log::register_simple_formatter_factory< Severity, char >("Severity");
|
|
||||||
|
|
||||||
if (ConfigReader::instance().getBool("main.logger.console.enable", false))
|
|
||||||
{
|
|
||||||
boost::log::add_console_log(std::cout,
|
|
||||||
boost::log::keywords::format = (
|
|
||||||
boost::log::expressions::stream
|
|
||||||
<< boost::log::expressions::format_date_time< boost::posix_time::ptime >("TimeStamp", "[%Y-%m-%d %H:%M:%S]")
|
|
||||||
<< " [" << boost::log::expressions::attr< Module >("Module") << "]"
|
|
||||||
<< " [" << boost::log::expressions::attr< Severity >("Severity") << "]"
|
|
||||||
<< " " << boost::log::expressions::smessage
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
return "";
|
||||||
if (ConfigReader::instance().getBool("main.logger.file.enable", false))
|
}
|
||||||
{
|
|
||||||
boost::log::add_file_log
|
std::string getSeverityName(Severity sev)
|
||||||
(
|
{
|
||||||
boost::log::keywords::file_name = ConfigReader::instance().getString("main.logger.file.path") + std::string(".%N"),
|
switch (sev)
|
||||||
boost::log::keywords::rotation_size = 10 * 1024 * 1024,
|
{
|
||||||
boost::log::keywords::open_mode = std::ios_base::app,
|
case SEV_CRIT: return "fatal";
|
||||||
boost::log::keywords::auto_flush = true,
|
case SEV_ERROR: return "error";
|
||||||
boost::log::keywords::format = (
|
case SEV_WARNING: return "warning";
|
||||||
boost::log::expressions::stream
|
case SEV_NOTICE:
|
||||||
<< boost::log::expressions::format_date_time< boost::posix_time::ptime >("TimeStamp", "[%Y-%m-%d %H:%M:%S]")
|
case SEV_INFO: return "info";
|
||||||
<< " [" << boost::log::expressions::attr< Module >("Module") << "]"
|
case SEV_DEBUG: return "debug";
|
||||||
<< " [" << boost::log::expressions::attr< Severity >("Severity") << "]"
|
}
|
||||||
<< " " << boost::log::expressions::smessage
|
return "";
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
boost::log::core::get()->set_filter
|
|
||||||
(
|
|
||||||
boost::log::expressions::attr<Severity>("Severity") <= ConfigReader::instance().getULong("main.logger.level", SEV_DEBUG)
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+8
-81
@@ -20,15 +20,11 @@
|
|||||||
#ifndef LOGGER_HPP__
|
#ifndef LOGGER_HPP__
|
||||||
#define LOGGER_HPP__
|
#define LOGGER_HPP__
|
||||||
|
|
||||||
#include <map>
|
#include <Wt/WServer>
|
||||||
|
#include <Wt/WLogger>
|
||||||
|
|
||||||
#include <boost/log/expressions/keyword_fwd.hpp>
|
#include <string>
|
||||||
#include <boost/log/expressions/keyword.hpp>
|
|
||||||
|
|
||||||
#include <boost/log/trivial.hpp>
|
|
||||||
#include <boost/log/attributes/named_scope.hpp>
|
|
||||||
|
|
||||||
#define LMS_LOG(module, level) BOOST_LOG_SEV(Logger::instance().get(module), level)
|
|
||||||
|
|
||||||
enum Severity
|
enum Severity
|
||||||
{
|
{
|
||||||
@@ -42,7 +38,7 @@ enum Severity
|
|||||||
|
|
||||||
enum Module
|
enum Module
|
||||||
{
|
{
|
||||||
MOD_AV = 0,
|
MOD_AV,
|
||||||
MOD_COVER,
|
MOD_COVER,
|
||||||
MOD_DB,
|
MOD_DB,
|
||||||
MOD_DBUPDATER,
|
MOD_DBUPDATER,
|
||||||
@@ -54,78 +50,9 @@ enum Module
|
|||||||
MOD_UI,
|
MOD_UI,
|
||||||
};
|
};
|
||||||
|
|
||||||
BOOST_LOG_ATTRIBUTE_KEYWORD(module, "Module", Module)
|
std::string getModuleName(Module mod);
|
||||||
|
std::string getSeverityName(Severity sev);
|
||||||
|
|
||||||
class Logger
|
#define LMS_LOG(module, level) Wt::WServer::instance()->log(getSeverityName(level)) << Wt::WLogger::sep << "[" << getModuleName(module) << "]" << Wt::WLogger::sep
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
Logger(const Logger&) = delete;
|
|
||||||
Logger& operator=(const Logger&) = delete;
|
|
||||||
|
|
||||||
static Logger& instance();
|
|
||||||
|
|
||||||
void init();
|
|
||||||
|
|
||||||
boost::log::sources::severity_logger< Severity >&
|
|
||||||
get(Module module);
|
|
||||||
|
|
||||||
private:
|
|
||||||
Logger();
|
|
||||||
|
|
||||||
std::map<Module, boost::log::sources::severity_logger< Severity > > _loggers;
|
|
||||||
};
|
|
||||||
|
|
||||||
// The formatting logic for the severity level
|
|
||||||
template< typename CharT, typename TraitsT >
|
|
||||||
inline std::basic_ostream< CharT, TraitsT >& operator<< (
|
|
||||||
std::basic_ostream< CharT, TraitsT >& strm, Severity lvl)
|
|
||||||
{
|
|
||||||
static const char* const str[] =
|
|
||||||
{
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
"CRIT",
|
|
||||||
"ERROR",
|
|
||||||
"WARNING",
|
|
||||||
"NOTICE",
|
|
||||||
"INFO",
|
|
||||||
"DEBUG"
|
|
||||||
};
|
|
||||||
if (static_cast< std::size_t >(lvl) < (sizeof(str) / sizeof(*str)))
|
|
||||||
strm << str[lvl];
|
|
||||||
else
|
|
||||||
strm << static_cast< int >(lvl);
|
|
||||||
return strm;
|
|
||||||
}
|
|
||||||
|
|
||||||
template< typename CharT, typename TraitsT >
|
|
||||||
inline std::basic_ostream< CharT, TraitsT >& operator<< (
|
|
||||||
std::basic_ostream< CharT, TraitsT >& strm, Module val)
|
|
||||||
{
|
|
||||||
const char* res = NULL;
|
|
||||||
|
|
||||||
switch(val)
|
|
||||||
{
|
|
||||||
case MOD_AV: res = "AV"; break;
|
|
||||||
case MOD_COVER: res = "COVER"; break;
|
|
||||||
case MOD_DB: res = "DB"; break;
|
|
||||||
case MOD_DBUPDATER: res = "DBUPDATER"; break;
|
|
||||||
case MOD_MAIN: res = "MAIN"; break;
|
|
||||||
case MOD_METADATA: res = "METADATA"; break;
|
|
||||||
case MOD_REMOTE: res = "REMOTE"; break;
|
|
||||||
case MOD_SERVICE: res = "SERVICE"; break;
|
|
||||||
case MOD_TRANSCODE: res = "TRANSCODE"; break;
|
|
||||||
case MOD_UI: res = "UI"; break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (res)
|
|
||||||
strm << res;
|
|
||||||
else
|
|
||||||
strm << static_cast< int >(val);
|
|
||||||
return strm;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif // LOGGER_HPP__
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
+11
-24
@@ -20,7 +20,6 @@
|
|||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
|
|
||||||
#include "config/config.h"
|
#include "config/config.h"
|
||||||
#include "config/ConfigReader.hpp"
|
|
||||||
#include "transcode/AvConvTranscoder.hpp"
|
#include "transcode/AvConvTranscoder.hpp"
|
||||||
#include "av/Common.hpp"
|
#include "av/Common.hpp"
|
||||||
#include "logger/Logger.hpp"
|
#include "logger/Logger.hpp"
|
||||||
@@ -45,13 +44,8 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Open configuration file
|
Wt::WServer server(argv[0]);
|
||||||
boost::filesystem::path configFilePath("/etc/lms.conf"); // TODO use $confdir from autotools
|
server.setServerConfiguration (argc, argv);
|
||||||
|
|
||||||
ConfigReader::instance().setFile(configFilePath);
|
|
||||||
|
|
||||||
Logger::instance().init();
|
|
||||||
CoverArt::Grabber::instance().init();
|
|
||||||
|
|
||||||
Service::ServiceManager& serviceManager = Service::ServiceManager::instance();
|
Service::ServiceManager& serviceManager = Service::ServiceManager::instance();
|
||||||
|
|
||||||
@@ -61,8 +55,7 @@ int main(int argc, char* argv[])
|
|||||||
Database::Handler::configureAuth();
|
Database::Handler::configureAuth();
|
||||||
|
|
||||||
// Initializing a connection pool to the database that will be shared along services
|
// Initializing a connection pool to the database that will be shared along services
|
||||||
std::unique_ptr<Wt::Dbo::SqlConnectionPool> connectionPool( Database::Handler::createConnectionPool( ConfigReader::instance().getString("main.database.path") ));
|
std::unique_ptr<Wt::Dbo::SqlConnectionPool> connectionPool( Database::Handler::createConnectionPool("/var/lms/lms.db")); // TODO use $datadir from autotools
|
||||||
|
|
||||||
|
|
||||||
serviceManager.add( std::make_shared<Service::DatabaseUpdateService>(*connectionPool));
|
serviceManager.add( std::make_shared<Service::DatabaseUpdateService>(*connectionPool));
|
||||||
|
|
||||||
@@ -70,37 +63,31 @@ int main(int argc, char* argv[])
|
|||||||
serviceManager.add( std::make_shared<Service::LmsAPIService>(*connectionPool));
|
serviceManager.add( std::make_shared<Service::LmsAPIService>(*connectionPool));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Wt::WServer server(argv[0]);
|
|
||||||
server.setServerConfiguration (argc, argv);
|
|
||||||
// bind entry point
|
// bind entry point
|
||||||
server.addEntryPoint(Wt::Application, boost::bind(UserInterface::LmsApplication::create, _1, boost::ref(*connectionPool)));
|
server.addEntryPoint(Wt::Application, boost::bind(UserInterface::LmsApplication::create, _1, boost::ref(*connectionPool)));
|
||||||
|
|
||||||
LMS_LOG(MOD_MAIN, SEV_NOTICE) << "Now running...";
|
LMS_LOG(MOD_MAIN, SEV_NOTICE) << "Now running...";
|
||||||
|
|
||||||
// Start underlying services
|
|
||||||
LMS_LOG(MOD_MAIN, SEV_INFO) << "Starting services...";
|
|
||||||
serviceManager.start();
|
|
||||||
|
|
||||||
// Starting the main server
|
// Starting the main server
|
||||||
LMS_LOG(MOD_MAIN, SEV_INFO) << "Starting server...";
|
LMS_LOG(MOD_MAIN, SEV_INFO) << "Starting server...";
|
||||||
server.start();
|
server.start();
|
||||||
|
|
||||||
|
// Start underlying services
|
||||||
|
LMS_LOG(MOD_MAIN, SEV_INFO) << "Starting services...";
|
||||||
|
serviceManager.start();
|
||||||
|
|
||||||
// Waiting for shutdown command
|
// Waiting for shutdown command
|
||||||
Wt::WServer::waitForShutdown(argv[0]);
|
Wt::WServer::waitForShutdown(argv[0]);
|
||||||
|
|
||||||
|
LMS_LOG(MOD_MAIN, SEV_INFO) << "Stopping services...";
|
||||||
|
serviceManager.stop();
|
||||||
|
serviceManager.clear();
|
||||||
|
|
||||||
LMS_LOG(MOD_MAIN, SEV_INFO) << "Stopping server...";
|
LMS_LOG(MOD_MAIN, SEV_INFO) << "Stopping server...";
|
||||||
server.stop();
|
server.stop();
|
||||||
|
|
||||||
LMS_LOG(MOD_MAIN, SEV_INFO) << "Stopping services...";
|
|
||||||
serviceManager.stop();
|
|
||||||
|
|
||||||
res = EXIT_SUCCESS;
|
res = EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
// TODO catch setting not found exception
|
|
||||||
catch( libconfig::ParseException& e)
|
|
||||||
{
|
|
||||||
std::cerr << "Caught libconfig::ParseException! error='" << e.getError() << "', file = '" << e.getFile() << "', line = " << e.getLine() << std::endl;
|
|
||||||
}
|
|
||||||
catch( Wt::WServer::Exception& e)
|
catch( Wt::WServer::Exception& e)
|
||||||
{
|
{
|
||||||
LMS_LOG(MOD_MAIN, SEV_CRIT) << "Caught a WServer::Exception: " << e.what();
|
LMS_LOG(MOD_MAIN, SEV_CRIT) << "Caught a WServer::Exception: " << e.what();
|
||||||
|
|||||||
@@ -20,51 +20,32 @@
|
|||||||
#include <boost/thread.hpp>
|
#include <boost/thread.hpp>
|
||||||
|
|
||||||
#include "config/ConfigReader.hpp"
|
#include "config/ConfigReader.hpp"
|
||||||
#include "logger/Logger.hpp"
|
|
||||||
|
|
||||||
#include "DatabaseUpdateService.hpp"
|
#include "DatabaseUpdateService.hpp"
|
||||||
|
|
||||||
static std::vector<std::string> splitStrings(const std::string& source)
|
|
||||||
{
|
|
||||||
std::vector<std::string> res;
|
|
||||||
std::istringstream oss(source);
|
|
||||||
|
|
||||||
std::string str;
|
|
||||||
while(oss >> str)
|
|
||||||
res.push_back(str);
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace Service {
|
namespace Service {
|
||||||
|
|
||||||
DatabaseUpdateService::DatabaseUpdateService(Wt::Dbo::SqlConnectionPool &connectionPool)
|
DatabaseUpdateService::DatabaseUpdateService(Wt::Dbo::SqlConnectionPool &connectionPool)
|
||||||
: _metadataParser(),
|
: _metadataParser(),
|
||||||
_databaseUpdater( connectionPool, _metadataParser)
|
_databaseUpdater( connectionPool, _metadataParser)
|
||||||
{
|
{
|
||||||
_databaseUpdater.setAudioExtensions(splitStrings(ConfigReader::instance().getString("main.database.audio_extensions")));
|
|
||||||
_databaseUpdater.setVideoExtensions(splitStrings(ConfigReader::instance().getString("main.database.video_extensions")));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DatabaseUpdateService::start(void)
|
DatabaseUpdateService::start(void)
|
||||||
{
|
{
|
||||||
LMS_LOG(MOD_SERVICE, SEV_DEBUG) << "DatabaseUpdateService, starting...";
|
|
||||||
_databaseUpdater.start();
|
_databaseUpdater.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DatabaseUpdateService::stop(void)
|
DatabaseUpdateService::stop(void)
|
||||||
{
|
{
|
||||||
LMS_LOG(MOD_SERVICE, SEV_DEBUG) << "DatabaseUpdateService, stopping...";
|
|
||||||
_databaseUpdater.stop();
|
_databaseUpdater.stop();
|
||||||
LMS_LOG(MOD_SERVICE, SEV_DEBUG) << "DatabaseUpdateService, stopped";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DatabaseUpdateService::restart(void)
|
DatabaseUpdateService::restart(void)
|
||||||
{
|
{
|
||||||
LMS_LOG(MOD_SERVICE, SEV_DEBUG) << "DatabaseUpdateService, restart";
|
|
||||||
stop();
|
stop();
|
||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,8 +17,6 @@
|
|||||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "logger/Logger.hpp"
|
|
||||||
|
|
||||||
#include "ServiceManager.hpp"
|
#include "ServiceManager.hpp"
|
||||||
|
|
||||||
namespace Service {
|
namespace Service {
|
||||||
@@ -36,7 +34,6 @@ ServiceManager::ServiceManager()
|
|||||||
|
|
||||||
ServiceManager::~ServiceManager()
|
ServiceManager::~ServiceManager()
|
||||||
{
|
{
|
||||||
LMS_LOG(MOD_SERVICE, SEV_NOTICE) << "Stopping services...";
|
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,6 +51,13 @@ ServiceManager::del(Service::pointer service)
|
|||||||
_services.erase(service);
|
_services.erase(service);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ServiceManager::clear(void)
|
||||||
|
{
|
||||||
|
stop();
|
||||||
|
_services.clear();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ServiceManager::start(void)
|
ServiceManager::start(void)
|
||||||
{
|
{
|
||||||
@@ -72,7 +76,6 @@ ServiceManager::stop(void)
|
|||||||
void
|
void
|
||||||
ServiceManager::restart(void)
|
ServiceManager::restart(void)
|
||||||
{
|
{
|
||||||
LMS_LOG(MOD_SERVICE, SEV_NOTICE) << "Restarting services...";
|
|
||||||
for (Service::pointer service : _services)
|
for (Service::pointer service : _services)
|
||||||
service->restart();
|
service->restart();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ class ServiceManager
|
|||||||
|
|
||||||
void add(Service::pointer service);
|
void add(Service::pointer service);
|
||||||
void del(Service::pointer service);
|
void del(Service::pointer service);
|
||||||
|
void clear();
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
void stop();
|
void stop();
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ VideoWidget::search(const std::string& searchText)
|
|||||||
void
|
void
|
||||||
VideoWidget::playVideo(boost::filesystem::path p)
|
VideoWidget::playVideo(boost::filesystem::path p)
|
||||||
{
|
{
|
||||||
LMS_LOG(MOD_UI, SEV_DEBUG) << "Want to play video " << p << "'" << std::endl;
|
LMS_LOG(MOD_UI, SEV_DEBUG) << "Want to play video " << p << "'";
|
||||||
try {
|
try {
|
||||||
|
|
||||||
std::size_t audioBitrate = 0;
|
std::size_t audioBitrate = 0;
|
||||||
@@ -82,7 +82,8 @@ VideoWidget::playVideo(boost::filesystem::path p)
|
|||||||
parameters.setBitrate(Transcode::Stream::Video, 0/*videoBitrate*/);
|
parameters.setBitrate(Transcode::Stream::Video, 0/*videoBitrate*/);
|
||||||
|
|
||||||
VideoMediaPlayerWidget *mediaPlayer = new VideoMediaPlayerWidget(parameters, this);
|
VideoMediaPlayerWidget *mediaPlayer = new VideoMediaPlayerWidget(parameters, this);
|
||||||
mediaPlayer->close().connect(std::bind([=] () {
|
mediaPlayer->close().connect(std::bind([=] ()
|
||||||
|
{
|
||||||
_videoDbWidget->setHidden(false);
|
_videoDbWidget->setHidden(false);
|
||||||
delete mediaPlayer;
|
delete mediaPlayer;
|
||||||
}));
|
}));
|
||||||
@@ -90,7 +91,7 @@ VideoWidget::playVideo(boost::filesystem::path p)
|
|||||||
_videoDbWidget->setHidden(true);
|
_videoDbWidget->setHidden(true);
|
||||||
}
|
}
|
||||||
catch( std::exception& e) {
|
catch( std::exception& e) {
|
||||||
LMS_LOG(MOD_UI, SEV_ERROR) << "Caught exception while loading '" << p << "': " << e.what() << std::endl;
|
LMS_LOG(MOD_UI, SEV_ERROR) << "Caught exception while loading '" << p << "': " << e.what();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user