WIP. Logger for every modules

This commit is contained in:
emeric
2014-08-27 21:25:02 +02:00
parent 6afc4ac291
commit 07624995e7
42 changed files with 292 additions and 223 deletions
+3 -1
View File
@@ -2,6 +2,8 @@
#include <stdexcept>
#include <iostream>
#include "logger/Logger.hpp"
#include "Codec.hpp"
Codec::Codec(enum CodecID codec, Type type )
@@ -13,7 +15,7 @@ Codec::Codec(enum CodecID codec, Type type )
_codec = avcodec_find_decoder(codec);
if (_codec == nullptr) {
std::cerr << "Codec constructor failed! codec = " << codec << ", type = " << type << std::endl;
LMS_LOG(MOD_AV, SEV_ERROR) << "Codec constructor failed! codec = " << codec << ", type = " << type;
throw std::runtime_error("can't find codec using this id!");
}
}
+5 -3
View File
@@ -1,7 +1,9 @@
#include "Common.hpp"
#include <boost/array.hpp>
#include "logger/Logger.hpp"
#include "Common.hpp"
namespace Av
{
@@ -28,7 +30,7 @@ void AvInit()
/* register all the codecs */
avcodec_register_all();
av_register_all();
std::cout << "AVCDOEC VERSION = " << avcodec_version() << std::endl;
LMS_LOG(MOD_AV, SEV_INFO) << "AVCDOEC VERSION = " << avcodec_version();
}
} // namespace Av
+5 -3
View File
@@ -1,6 +1,8 @@
#include <stdexcept>
#include <iostream>
#include "logger/Logger.hpp"
#include "InputFormatContext.hpp"
namespace Av
@@ -17,7 +19,7 @@ InputFormatContext::InputFormatContext(const boost::filesystem::path& p)
AvError error = avformat_open_input(&context, p.string().c_str(), nullptr, nullptr);
if (error)
{
std::cerr << "Cannot open '" << p.string() << "', avformat_open_input returned " << error << std::endl;
LMS_LOG(MOD_AV, SEV_ERROR) << "Cannot open '" << p.string() << "', avformat_open_input returned " << error;
throw std::runtime_error("avformat_open_input failed: " + error.to_str());
}
@@ -57,7 +59,7 @@ InputFormatContext::getBestStreamIdx(AVMediaType type, Stream::Idx& index)
AvError error(res);
if (error) {
std::cerr << "Cannot get best stream for type " << type << ": " << error << std::endl;
LMS_LOG(MOD_AV, SEV_DEBUG) << "Cannot get best stream for type " << type << ": " << error;
return false;
}
else {
@@ -72,7 +74,7 @@ InputFormatContext::findStreamInfo(void)
native()->max_analyze_duration = 10 * AV_TIME_BASE; // 10 secs
AvError err = avformat_find_stream_info(native(), NULL);
if (err) {
std::cerr << "Couldn't find stream information: " << err << std::endl;
LMS_LOG(MOD_AV, SEV_ERROR) << "Couldn't find stream information: " << err;
throw std::runtime_error("av_find_stream_info failed!");
}
}
+3 -1
View File
@@ -5,6 +5,8 @@
#include <boost/gil/extension/numeric/resample.hpp>
#include <boost/gil/extension/io_new/jpeg_all.hpp>
#include "logger/Logger.hpp"
#include "CoverArt.hpp"
namespace CoverArt {
@@ -46,7 +48,7 @@ CoverArt::scale(std::size_t size)
}
catch(std::exception& e)
{
std::cerr << "Caught exception: " << e.what() << std::endl;
LMS_LOG(MOD_COVER, SEV_ERROR) << "Caught exception: " << e.what();
}
return res;
+5 -3
View File
@@ -1,9 +1,11 @@
#include <boost/foreach.hpp>
#include "logger/Logger.hpp"
#include "av/InputFormatContext.hpp"
#include "CoverArtGrabber.hpp"
#include "av/InputFormatContext.hpp"
namespace CoverArt {
@@ -25,7 +27,7 @@ Grabber::getFromInputFormatContext(const Av::InputFormatContext& input)
}
catch(std::exception& e)
{
std::cerr << "Cannot get pictures: " << e.what() << std::endl;
LMS_LOG(MOD_COVER, SEV_ERROR) << "Cannot get pictures: " << e.what();
}
return res;
@@ -50,7 +52,7 @@ Grabber::getFromTrack(Database::Track::pointer track)
}
catch(std::exception& e)
{
std::cerr << "Cannot get pictures: " << e.what();
LMS_LOG(MOD_COVER, SEV_ERROR) << "Cannot get pictures: " << e.what();
}
return res;
+3 -1
View File
@@ -3,6 +3,8 @@
#include <boost/crc.hpp> // for boost::crc_32_type
#include "logger/Logger.hpp"
#include "Checksum.hpp"
typedef boost::crc_32_type crc_type;
@@ -26,7 +28,7 @@ void computeCrc(const boost::filesystem::path& p, std::vector<unsigned char>& cr
}
else
{
std::cerr << "Failed to open file '" << p << "'" << std::endl;
LMS_LOG(MOD_DBUPDATER, SEV_ERROR) << "Failed to open file '" << p << "'";
throw std::runtime_error("Failed to open file '" + p.string() + "'" );
}
+32 -30
View File
@@ -4,6 +4,8 @@
#include <boost/thread.hpp>
#include <boost/asio/placeholders.hpp>
#include "logger/Logger.hpp"
#include "database/MediaDirectory.hpp"
#include "database/AudioTypes.hpp"
@@ -109,7 +111,7 @@ Updater::processNextJob(void)
MediaDirectorySettings::pointer settings = MediaDirectorySettings::get(_db.getSession());
if (settings->getManualScanRequested()) {
std::cout << "Manual scan requested!" << std::endl;
LMS_LOG(MOD_DBUPDATER, SEV_NOTICE) << "Manual scan requested!";
scheduleScan( boost::posix_time::seconds(0) );
}
else
@@ -152,7 +154,7 @@ Updater::processNextJob(void)
void
Updater::scheduleScan( boost::posix_time::time_duration duration)
{
std::cout << "Scheduling next scan in " << duration << std::endl;
LMS_LOG(MOD_DBUPDATER, SEV_NOTICE) << "Scheduling next scan in " << duration;
_scheduleTimer.expires_from_now(duration);
_scheduleTimer.async_wait( boost::bind( &Updater::process, this, boost::asio::placeholders::error) );
}
@@ -160,7 +162,7 @@ Updater::scheduleScan( boost::posix_time::time_duration duration)
void
Updater::scheduleScan( boost::posix_time::ptime time)
{
std::cout << "Scheduling next scan at " << time << std::endl;
LMS_LOG(MOD_DBUPDATER, SEV_NOTICE) << "Scheduling next scan at " << time;
_scheduleTimer.expires_at(time);
_scheduleTimer.async_wait( boost::bind( &Updater::process, this, boost::asio::placeholders::error) );
}
@@ -188,7 +190,7 @@ Updater::process(boost::system::error_code err)
BOOST_FOREACH( RootDirectory rootDirectory, rootDirectories)
processDirectory(rootDirectory.first, rootDirectory.first, rootDirectory.second, stats);
std::cout << "Changes = " << stats.nbChanges() << std::endl;
LMS_LOG(MOD_DBUPDATER, SEV_INFO) << "Changes = " << stats.nbChanges();
// Update database stats
boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
@@ -240,7 +242,7 @@ Updater::processAudioFile( const boost::filesystem::path& file, Stats& stats)
if (items.find(MetaData::AudioStreams) == items.end()
|| boost::any_cast<std::vector<MetaData::AudioStream> >(items[MetaData::AudioStreams]).empty())
{
std::cerr << "Skipped '" << file << "' (no audio stream found)" << std::endl;
LMS_LOG(MOD_DBUPDATER, SEV_DEBUG) << "Skipped '" << file << "' (no audio stream found)";
// If Track exists here, delete it!
if (track) {
@@ -252,7 +254,7 @@ Updater::processAudioFile( const boost::filesystem::path& file, Stats& stats)
if (items.find(MetaData::Duration) == items.end()
|| boost::any_cast<boost::posix_time::time_duration>(items[MetaData::Duration]).total_seconds() == 0)
{
std::cerr << "Skipped '" << file << "' (no duration or duration 0)" << std::endl;
LMS_LOG(MOD_DBUPDATER, SEV_DEBUG) << "Skipped '" << file << "' (no duration or duration 0)";
// If Track exists here, delete it!
if (track) {
@@ -330,12 +332,12 @@ Updater::processAudioFile( const boost::filesystem::path& file, Stats& stats)
{
// Create a new song
track = Track::create(_db.getSession(), file, artist, release);
std::cout << "Adding '" << file << "'" << std::endl;
LMS_LOG(MOD_DBUPDATER, SEV_INFO) << "Adding '" << file << "'";
stats.nbAdded++;
}
else
{
std::cout << "Updating '" << file << "'" << std::endl;
LMS_LOG(MOD_DBUPDATER, SEV_INFO) << "Updating '" << file << "'";
stats.nbModified++;
}
@@ -375,7 +377,7 @@ Updater::processAudioFile( const boost::filesystem::path& file, Stats& stats)
}
catch( std::exception& e ) {
std::cerr << "Exception while parsing audio file : '" << file << "': '" << e.what() << "' => skipping!" << std::endl;
LMS_LOG(MOD_DBUPDATER, SEV_ERROR) << "Exception while parsing audio file : '" << file << "': '" << e.what() << "' => skipping!";
}
}
@@ -427,7 +429,7 @@ Updater::checkFile(const boost::filesystem::path& p, const std::vector<boost::fi
if (!boost::filesystem::exists( p )
|| !boost::filesystem::is_regular( p ) )
{
std::cerr << "Missing file '" << p << "'" << std::endl;
LMS_LOG(MOD_DBUPDATER, SEV_INFO) << "Missing file '" << p << "'";
status = false;
}
else
@@ -444,7 +446,7 @@ Updater::checkFile(const boost::filesystem::path& p, const std::vector<boost::fi
if (!foundRoot)
{
std::cerr << "Out of root file '" << p << "'" << std::endl;
LMS_LOG(MOD_DBUPDATER, SEV_INFO) << "Out of root file '" << p << "'";
status = false;
}
}
@@ -457,12 +459,12 @@ void
Updater::checkAudioFiles( Stats& stats )
{
std::cerr << "Checking audio files..." << std::endl;
LMS_LOG(MOD_DBUPDATER, SEV_DEBUG) << "Checking audio files...";
Wt::Dbo::Transaction transaction(_db.getSession());
std::vector<boost::filesystem::path> rootDirs = getRootDirectoriesByType(_db.getSession(), Database::MediaDirectory::Audio);
std::cerr << "Checking tracks..." << std::endl;
LMS_LOG(MOD_DBUPDATER, SEV_DEBUG) << "Checking tracks...";
typedef Wt::Dbo::collection< Wt::Dbo::ptr<Track> > Tracks;
Tracks tracks = Track::getAll(_db.getSession());
@@ -477,29 +479,30 @@ Updater::checkAudioFiles( Stats& stats )
}
}
std::cerr << "Checking Artists..." << std::endl;
LMS_LOG(MOD_DBUPDATER, SEV_DEBUG) << "Checking Artists...";
// Now process orphan Artists (no track)
typedef Wt::Dbo::collection< Wt::Dbo::ptr<Artist> > Artists;
Artists artists = Artist::getAllOrphans(_db.getSession());
for (Artists::iterator it = artists.begin(); it != artists.end(); ++it)
{
std::cout << "Removing orphan artist " << (*it)->getName() << std::endl;
LMS_LOG(MOD_DBUPDATER, SEV_INFO) << "Removing orphan artist " << (*it)->getName();
(*it).remove();
}
std::cerr << "Checking Releases..." << std::endl;
LMS_LOG(MOD_DBUPDATER, SEV_DEBUG) << "Checking Releases...";
// Now process orphan Release (no track)
typedef Wt::Dbo::collection< Wt::Dbo::ptr<Release> > Releases;
Releases releases = Release::getAllOrphans(_db.getSession());
for (Releases::iterator it = releases.begin(); it != releases.end(); ++it)
{
std::cout << "Removing orphan release " << (*it)->getName() << std::endl;
LMS_LOG(MOD_DBUPDATER, SEV_INFO) << "Removing orphan release " << (*it)->getName();
(*it).remove();
}
std::cerr << "Checking Genres..." << std::endl;
// Now process orphan Genre (no track)
LMS_LOG(MOD_DBUPDATER, SEV_DEBUG) << "Checking Genres...";
typedef Wt::Dbo::collection< Wt::Dbo::ptr<Genre> > Genres;
Genres genres = Genre::getAll(_db.getSession());
@@ -511,9 +514,8 @@ Updater::checkAudioFiles( Stats& stats )
genre.remove();
}
// Now process orphan Genre (no track)
std::cerr << "Check audio files done!" << std::endl;
LMS_LOG(MOD_DBUPDATER, SEV_DEBUG) << "Check audio files done!";
}
Path::pointer
@@ -542,7 +544,7 @@ Updater::getAddPath(const boost::filesystem::path& path)
/*void
Updater::refreshVideoDirectory( const boost::filesystem::path& path)
{
std::cout << "Refreshing video directory " << path << std::endl;
LMS_LOG(MOD_DBUPDATER, SEV_DEBUG) << "Refreshing video directory " << path;
if (boost::filesystem::exists(path) && boost::filesystem::is_directory(path))
{
@@ -571,11 +573,11 @@ Updater::refreshVideoDirectory( const boost::filesystem::path& path)
processVideoFile( pathChild );
}
else {
std::cout << "Skipped '" << pathChild << "' (not regular)" << std::endl;
LMS_LOG(MOD_DBUPDATER, SEV_DEBUG) << "Skipped '" << pathChild << "' (not regular)";
}
}
}
std::cout << "Refreshing video directory " << path << ": DONE" << std::endl;
LMS_LOG(MOD_DBUPDATER, SEV_DEBUG) << "Refreshing video directory " << path << ": DONE";
}*/
/*
void
@@ -592,12 +594,12 @@ Updater::processVideoFile( const boost::filesystem::path& file)
Path::pointer dbPath = Path::getByPath(_db.getSession(), file);
if (dbPath && dbPath->getLastWriteTime() == lastWriteTime)
{
std::cerr << "Skipped '" << file << "' (last write time match)" << std::endl;
LMS_LOG(MOD_DBUPDATER, SEV_ERROR) << "Skipped '" << file << "' (last write time match)";
return;
}
std::cout << "Video, parsing file " << file << std::endl;
LMS_LOG(MOD_DBUPDATER, SEV_DEBUG) << "Video, parsing file " << file;
MetaData::Items items;
_metadataParser.parse(file, items);
@@ -608,7 +610,7 @@ Updater::processVideoFile( const boost::filesystem::path& file)
if (items.find(MetaData::VideoStreams) == items.end()
|| boost::any_cast<std::vector<MetaData::VideoStream> >(items[MetaData::VideoStreams]).empty())
{
std::cerr << "Skipped '" << file << "' (no video stream found)" << std::endl;
LMS_LOG(MOD_DBUPDATER, SEV_ERROR) << "Skipped '" << file << "' (no video stream found)";
// If Track exists here, delete it!
if (dbPath)
@@ -617,7 +619,7 @@ Updater::processVideoFile( const boost::filesystem::path& file)
else if (items.find(MetaData::Duration) == items.end()
|| boost::any_cast<boost::posix_time::time_duration>(items[MetaData::Duration]).total_seconds() == 0)
{
std::cerr << "Skipped '" << file << "' (no duration or duration 0)" << std::endl;
LMS_LOG(MOD_DBUPDATER, SEV_ERROR) << "Skipped '" << file << "' (no duration or duration 0)";
// If Track exists here, delete it!
if (dbPath)
@@ -639,10 +641,10 @@ Updater::processVideoFile( const boost::filesystem::path& file)
Video::pointer video = dbPath.modify()->getVideo();
if (!video) {
video = Video::create(_db.getSession(), dbPath);
std::cout << "Adding '" << file << "'" << std::endl;
LMS_LOG(MOD_DBUPDATER, SEV_DEBUG) << "Adding '" << file << "'";
}
else
std::cout << "Updating '" << file << "'" << std::endl;
LMS_LOG(MOD_DBUPDATER, SEV_DEBUG) << "Updating '" << file << "'";
assert(video);
@@ -653,7 +655,7 @@ Updater::processVideoFile( const boost::filesystem::path& file)
transaction.commit();
}
catch( std::exception& e ) {
std::cerr << "Exception while parsing video file : '" << file << "': '" << e.what() << "' => skipping!" << std::endl;
LMS_LOG(MOD_DBUPDATER, SEV_ERROR) << "Exception while parsing video file : '" << file << "': '" << e.what() << "' => skipping!";
}
}
*/
+4 -2
View File
@@ -6,6 +6,8 @@
#include <Wt/Auth/PasswordStrengthValidator>
#include <Wt/Auth/PasswordVerifier>
#include "logger/Logger.hpp"
// Db types
#include "AudioTypes.hpp"
#include "FileTypes.hpp"
@@ -79,7 +81,7 @@ _dbBackend( db.string() )
_session.createTables();
}
catch(std::exception& e) {
std::cerr << "Cannot create tables: " << e.what() << std::endl;
LMS_LOG(MOD_DB, SEV_ERROR) << "Cannot create tables: " << e.what();
}
_dbBackend.executeSql("pragma journal_mode=WAL");
@@ -112,7 +114,7 @@ Handler::getUser(const Wt::Auth::User& authUser)
{
if (!authUser.isValid()) {
std::cerr << "Handler::getUser: invalid authUser" << std::endl;
LMS_LOG(MOD_DB, SEV_ERROR) << "Handler::getUser: invalid authUser";
return User::pointer();
}
+22 -11
View File
@@ -14,6 +14,7 @@
#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>
@@ -30,21 +31,31 @@ Logger::instance()
Logger::Logger()
{
// Initialiaz loggers
static const struct LoggerDef {
Module module;
std::string name;
} loggers[] = {
{MOD_MAIN, "MAIN"},
{MOD_UI, "UI"},
{MOD_REMOTE, "REMOTE"}
static const std::vector<Module> modules =
{
MOD_AV,
MOD_COVER,
MOD_DB,
MOD_DBUPDATER,
MOD_MAIN,
MOD_METADATA,
MOD_REMOTE,
MOD_SERVICE,
MOD_TRANSCODE,
MOD_UI,
};
BOOST_FOREACH(const struct LoggerDef& logger, loggers) {
std::cout << "Adding attribute" << std::endl;
_loggers[logger.module].add_attribute("Module", boost::log::attributes::constant< Module >(logger.module));
}
BOOST_FOREACH(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(const Config& config)
{
+33 -16
View File
@@ -7,25 +7,32 @@
#include <boost/log/expressions/keyword.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/sources/severity_logger.hpp>
#include <boost/log/attributes/named_scope.hpp>
#define LMS_LOG(module, level) BOOST_LOG_SEV(Logger::instance().get(module), level)
enum Severity
{
SEV_DEBUG = 7,
SEV_INFO = 6,
SEV_NOTICE = 5,
SEV_WARNING = 4,
SEV_ERROR = 3,
SEV_CRIT = 2,
SEV_ERROR = 3,
SEV_WARNING = 4,
SEV_NOTICE = 5,
SEV_INFO = 6,
SEV_DEBUG = 7,
};
enum Module
{
MOD_MAIN = 0,
MOD_UI,
MOD_AV = 0,
MOD_COVER,
MOD_DB,
MOD_DBUPDATER,
MOD_MAIN,
MOD_METADATA,
MOD_REMOTE,
MOD_SERVICE,
MOD_TRANSCODE,
MOD_UI,
};
BOOST_LOG_ATTRIBUTE_KEYWORD(module, "Module", Module)
@@ -47,7 +54,7 @@ class Logger
void init(const Config& config);
boost::log::sources::severity_logger< Severity >&
get(Module module) { return _loggers[module]; }
get(Module module);
private:
@@ -83,14 +90,24 @@ template< typename CharT, typename TraitsT >
inline std::basic_ostream< CharT, TraitsT >& operator<< (
std::basic_ostream< CharT, TraitsT >& strm, Module val)
{
static const char* const str[] =
const char* res = NULL;
switch(val)
{
"MAIN",
"UI",
"REMOTE",
};
if (static_cast< std::size_t >(val) < (sizeof(str) / sizeof(*str)))
strm << str[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;
+5 -4
View File
@@ -48,6 +48,7 @@ int main(int argc, char* argv[])
Logger::instance().init(loggerConfig);
}
LMS_LOG(MOD_MAIN, SEV_INFO) << "Reading service configurations...";
Service::DatabaseUpdateService::Config dbUpdateConfig;
configReader.getDatabaseUpdateConfig(dbUpdateConfig);
@@ -65,7 +66,7 @@ int main(int argc, char* argv[])
Transcode::AvConvTranscoder::init();
Database::Handler::configureAuth();
std::cout << "Starting services..." << std::endl;
LMS_LOG(MOD_MAIN, SEV_INFO) << "Starting services...";
if (dbUpdateConfig.enable)
serviceManager.startService( std::make_shared<Service::DatabaseUpdateService>( dbUpdateConfig ) );
@@ -76,7 +77,7 @@ int main(int argc, char* argv[])
if (uiConfig.enable)
serviceManager.startService( std::make_shared<Service::UserInterfaceService>(boost::filesystem::path(argv[0]), uiConfig));
std::cout << "Running..." << std::endl;
LMS_LOG(MOD_MAIN, SEV_NOTICE) << "Now running...";
serviceManager.run();
@@ -89,11 +90,11 @@ int main(int argc, char* argv[])
}
catch( Wt::WServer::Exception& e)
{
std::cerr << "Caught WServer::Exception: " << e.what() << std::endl;
LMS_LOG(MOD_MAIN, SEV_CRIT) << "Caught a WServer::Exception: " << e.what();
}
catch( std::exception& e)
{
std::cerr << "Caught std::exception: " << e.what() << std::endl;
LMS_LOG(MOD_MAIN, SEV_CRIT) << "Caught std::exception: " << e.what();
}
return res;
+4 -3
View File
@@ -6,6 +6,8 @@
#include "av/InputFormatContext.hpp"
#include "logger/Logger.hpp"
#include "Utils.hpp"
namespace MetaData
@@ -134,17 +136,16 @@ AvFormat::parse(const boost::filesystem::path& p, Items& items)
}
/* else
std::cout << "key = " << it->first << ", value = " << it->second << std::endl;
LMS_LOG(MOD_METADATA, SEV_DEBUG) << "key = " << it->first << ", value = " << it->second;
*/
}
}
catch(std::exception &e)
{
std::cerr << "Parsing of '" << p << "' failed!" << std::endl;
LMS_LOG(MOD_METADATA, SEV_ERROR) << "Parsing of '" << p << "' failed!";
}
}
} // namespace MetaData
+4 -2
View File
@@ -1,6 +1,8 @@
#ifndef REMOTE_HEADER_HPP
#define REMOTE_HEADER_HPP
#include "logger/Logger.hpp"
#include <iomanip>
namespace Remote
@@ -33,7 +35,7 @@ class Header
bool from_buffer(const std::array<unsigned char, size>& buffer)
{
if (decode32(&buffer[0]) != _magic) {
std::cerr << "Header: bad magic ('" << std::hex << std::setfill('0') << std::setw(8) << decode32(&buffer[0]) << "' instead of '" << std::hex << std::setfill('0') << std::setw(8) << _magic << "')" << std::endl;
LMS_LOG(MOD_REMOTE, SEV_ERROR) << "Header: bad magic ('" << std::hex << std::setfill('0') << std::setw(8) << decode32(&buffer[0]) << "' instead of '" << std::hex << std::setfill('0') << std::setw(8) << _magic << "')";
return false;
}
else
@@ -41,7 +43,7 @@ class Header
_dataSize = decode32(&buffer[4]);
if (_dataSize > max_data_size)
std::cerr << "Header: msg too big (" << _dataSize << ")!" << std::endl;
LMS_LOG(MOD_REMOTE, SEV_ERROR) << "Header: msg too big (" << _dataSize << ")!";
return _dataSize <= max_data_size;
}
+13 -11
View File
@@ -4,6 +4,8 @@
#include <boost/uuid/sha1.hpp>
#include <boost/foreach.hpp>
#include "logger/Logger.hpp"
#include "AudioCollectionRequestHandler.hpp"
#include "database/AudioTypes.hpp"
@@ -34,7 +36,7 @@ AudioCollectionRequestHandler::process(const AudioCollectionRequest& request, Au
response.set_type(AudioCollectionResponse::TypeRevision);
}
else
std::cerr << "Bad AudioCollectionRequest::TypeGetRevision" << std::endl;
LMS_LOG(MOD_REMOTE, SEV_ERROR) << "Bad AudioCollectionRequest::TypeGetRevision";
break;
case AudioCollectionRequest::TypeGetGenreList:
@@ -45,7 +47,7 @@ AudioCollectionRequestHandler::process(const AudioCollectionRequest& request, Au
response.set_type(AudioCollectionResponse::TypeArtistList);
}
else
std::cerr << "Bad AudioCollectionRequest::TypeGetGenreList" << std::endl;
LMS_LOG(MOD_REMOTE, SEV_ERROR) << "Bad AudioCollectionRequest::TypeGetGenreList";
break;
case AudioCollectionRequest::TypeGetArtistList:
@@ -57,7 +59,7 @@ AudioCollectionRequestHandler::process(const AudioCollectionRequest& request, Au
}
else
std::cerr << "Bad AudioCollectionRequest::TypeGetArtistList message!" << std::endl;
LMS_LOG(MOD_REMOTE, SEV_ERROR) << "Bad AudioCollectionRequest::TypeGetArtistList message!";
break;
case AudioCollectionRequest::TypeGetReleaseList:
@@ -69,7 +71,7 @@ AudioCollectionRequestHandler::process(const AudioCollectionRequest& request, Au
}
else
std::cerr << "Bad AudioCollectionRequest::TypeGetReleaseList message!" << std::endl;
LMS_LOG(MOD_REMOTE, SEV_ERROR) << "Bad AudioCollectionRequest::TypeGetReleaseList message!";
break;
case AudioCollectionRequest::TypeGetTrackList:
@@ -81,18 +83,18 @@ AudioCollectionRequestHandler::process(const AudioCollectionRequest& request, Au
}
else
std::cerr << "Bad AudioCollectionRequest::TypeGetTrackList message!" << std::endl;
LMS_LOG(MOD_REMOTE, SEV_ERROR) << "Bad AudioCollectionRequest::TypeGetTrackList message!";
break;
case AudioCollectionRequest::TypeGetCoverArt:
if (request.has_get_cover_art())
res = processGetCoverArt(request.get_cover_art(), response);
else
std::cerr << "Bad AudioCollectionRequest::TypeGetCoverArt message!" << std::endl;
LMS_LOG(MOD_REMOTE, SEV_ERROR) << "Bad AudioCollectionRequest::TypeGetCoverArt message!";
break;
default:
std::cerr << "Unhandled AudioCollectionRequest_Type = " << request.type() << std::endl;
LMS_LOG(MOD_REMOTE, SEV_ERROR) << "Unhandled AudioCollectionRequest_Type = " << request.type();
}
@@ -106,7 +108,7 @@ AudioCollectionRequestHandler::processGetGenres(const AudioCollectionRequest::Ge
// sanity checks
if (!request.has_batch_parameter())
{
std::cerr << "No batch parameters found!" << std::endl;
LMS_LOG(MOD_REMOTE, SEV_ERROR) << "No batch parameters found!";
return false;
}
@@ -138,7 +140,7 @@ AudioCollectionRequestHandler::processGetArtists(const AudioCollectionRequest::G
// sanity checks
if (!request.has_batch_parameter())
{
std::cerr << "No batch parameters found!" << std::endl;
LMS_LOG(MOD_REMOTE, SEV_ERROR) << "No batch parameters found!";
return false;
}
@@ -172,7 +174,7 @@ AudioCollectionRequestHandler::processGetReleases(const AudioCollectionRequest::
// sanity checks
if (!request.has_batch_parameter())
{
std::cerr << "No batch parameters found!" << std::endl;
LMS_LOG(MOD_REMOTE, SEV_ERROR) << "No batch parameters found!";
return false;
}
@@ -208,7 +210,7 @@ AudioCollectionRequestHandler::processGetTracks(const AudioCollectionRequest::Ge
// sanity checks
if (!request.has_batch_parameter())
{
std::cerr << "No batch parameters found!" << std::endl;
LMS_LOG(MOD_REMOTE, SEV_ERROR) << "No batch parameters found!";
return false;
}
+4 -2
View File
@@ -1,5 +1,7 @@
#include <Wt/Auth/Identity>
#include "logger/Logger.hpp"
#include "AuthRequestHandler.hpp"
namespace Remote {
@@ -25,7 +27,7 @@ AuthRequestHandler::process(const AuthRequest& request, AuthResponse& response)
response.set_type(AuthResponse::TypePasswordResult);
}
else
std::cerr << "Bad AuthRequest::TypePassword" << std::endl;
LMS_LOG(MOD_REMOTE, SEV_ERROR) << "Bad AuthRequest::TypePassword";
break;
}
@@ -69,7 +71,7 @@ AuthRequestHandler::processPassword(const AuthRequest::Password& request, AuthRe
}
else
{
std::cerr << "Invalid user '" << request.user_login() << std::endl;
LMS_LOG(MOD_REMOTE, SEV_ERROR) << "Invalid user '" << request.user_login();
response.set_type(AuthResponse::PasswordResult::TypePasswordInvalid);
}
+21 -24
View File
@@ -5,6 +5,8 @@
#include <boost/bind.hpp>
#include <boost/foreach.hpp>
#include "logger/Logger.hpp"
#include "messages/messages.pb.h"
#include "RequestHandler.hpp"
@@ -24,13 +26,13 @@ _socket(ioService, context),
_connectionManager(manager),
_requestHandler(dbPath)
{
std::cout << "Server::Connection::Connection, Creating connection" << std::endl;
LMS_LOG(MOD_REMOTE, SEV_DEBUG) << "Server::Connection::Connection, Creating connection";
}
void
Connection::start()
{
std::cout << "Starting connection..." << std::endl;
LMS_LOG(MOD_REMOTE, SEV_DEBUG) << "Starting connection...";
_socket.async_handshake(boost::asio::ssl::stream_base::server,
boost::bind(&Connection::handleHandshake, this,
boost::asio::placeholders::error));
@@ -41,16 +43,16 @@ Connection::handleHandshake(const boost::system::error_code& error)
{
if (!error)
{
std::cout << "Handshake successfully performed... Now reading messages" << std::endl;
LMS_LOG(MOD_REMOTE, SEV_DEBUG) << "Handshake successfully performed... Now reading messages";
readMsg();
}
else if (error != boost::asio::error::operation_aborted)
{
std::cerr << "Connection::handleHandshake: " << error.message() << std::endl;
LMS_LOG(MOD_REMOTE, SEV_ERROR) << "Connection::handleHandshake: " << error.message();
_connectionManager.stop(shared_from_this());
}
else
std::cerr << "Handshake error: " << error.message() << std::endl;
LMS_LOG(MOD_REMOTE, SEV_ERROR) << "Handshake error: " << error.message();
}
@@ -76,16 +78,16 @@ Connection::stop()
boost::system::error_code ec;
_closing = true;
std::cout << "Server::Connection::stop, Stopping connection " << this << std::endl;
LMS_LOG(MOD_REMOTE, SEV_DEBUG) << "Server::Connection::stop, Stopping connection " << this;
_socket.shutdown(ec);
if (ec)
std::cerr << "Error while shutting down connection " << this << ": " << ec.message() << std::endl;
LMS_LOG(MOD_REMOTE, SEV_ERROR) << "Error while shutting down connection " << this << ": " << ec.message();
std::cout << "Server::Connection::stop, connection stopped " << this << std::endl;
LMS_LOG(MOD_REMOTE, SEV_DEBUG) << "Server::Connection::stop, connection stopped " << this;
}
else
std::cout << "Stop: close already in progress..." << std::endl;
LMS_LOG(MOD_REMOTE, SEV_DEBUG) << "Stop: close already in progress...";
}
void
@@ -95,7 +97,7 @@ Connection::handleReadHeader(const boost::system::error_code& error, std::size_t
{
if (bytes_transferred != Remote::Header::size)
{
std::cerr << "bytes_transferred (" << bytes_transferred << ") != Remote::Header::size!" << std::endl;
LMS_LOG(MOD_REMOTE, SEV_ERROR) << "bytes_transferred (" << bytes_transferred << ") != Remote::Header::size!";
_connectionManager.stop(shared_from_this());
return;
}
@@ -107,7 +109,7 @@ Connection::handleReadHeader(const boost::system::error_code& error, std::size_t
Remote::Header header;
if (!header.from_istream(is))
{
std::cerr << "Cannot read header from buffer!" << std::endl;
LMS_LOG(MOD_REMOTE, SEV_ERROR) << "Cannot read header from buffer!";
_connectionManager.stop(shared_from_this());
return;
}
@@ -125,7 +127,7 @@ Connection::handleReadHeader(const boost::system::error_code& error, std::size_t
}
else if (error != boost::asio::error::operation_aborted)
{
std::cerr << "Connection::handleReadHeader: " << error.message() << std::endl;
LMS_LOG(MOD_REMOTE, SEV_ERROR) << "Connection::handleReadHeader: " << error.message();
_connectionManager.stop(shared_from_this());
}
}
@@ -145,14 +147,14 @@ Connection::handleReadMsg(const boost::system::error_code& error, std::size_t by
if (!request.ParseFromIstream(&is))
{
std::cerr << "Cannot parse request!" << std::endl;
LMS_LOG(MOD_REMOTE, SEV_ERROR) << "Parse request failed!";
_connectionManager.stop(shared_from_this());
return;
}
if (!_requestHandler.process(request, response))
{
std::cerr << "Cannot process request!" << std::endl;
LMS_LOG(MOD_REMOTE, SEV_ERROR) << "Process request failed!";
_connectionManager.stop(shared_from_this());
return;
}
@@ -162,14 +164,14 @@ Connection::handleReadMsg(const boost::system::error_code& error, std::size_t by
if (!response.SerializeToOstream(&os))
{
std::cerr << "Cannot serialize to ostream!" << std::endl;
LMS_LOG(MOD_REMOTE, SEV_ERROR) << "Cannot serialize to ostream!";
_connectionManager.stop(shared_from_this());
return;
}
if (_outputStreamBuf.size() >= Remote::Header::max_data_size)
{
std::cerr << "output message is too big! " << _outputStreamBuf.size() << " > " << Remote::Header::max_data_size << std::endl;
LMS_LOG(MOD_REMOTE, SEV_ERROR) << "output message is too big! " << _outputStreamBuf.size() << " > " << Remote::Header::max_data_size;
_connectionManager.stop(shared_from_this());
return;
}
@@ -187,7 +189,7 @@ Connection::handleReadMsg(const boost::system::error_code& error, std::size_t by
ec);
if (ec)
{
std::cerr << "cannot write header: " << error.message() << std::endl;
LMS_LOG(MOD_REMOTE, SEV_ERROR) << "cannot write header: " << error.message();
_connectionManager.stop(shared_from_this());
}
else
@@ -203,7 +205,7 @@ Connection::handleReadMsg(const boost::system::error_code& error, std::size_t by
if (ec)
{
std::cerr << "cannot write msg: " << error.message() << std::endl;
LMS_LOG(MOD_REMOTE, SEV_ERROR) << "cannot write msg: " << error.message();
_connectionManager.stop(shared_from_this());
}
else
@@ -216,15 +218,10 @@ Connection::handleReadMsg(const boost::system::error_code& error, std::size_t by
// All good here, read another message
readMsg();
// Initiate graceful Connection closure.
// boost::system::error_code ignored_ec;
// _socket.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored_ec);
}
else if (error != boost::asio::error::operation_aborted)
{
std::cerr << "Connection::handleRead: " << error.message() << std::endl;
LMS_LOG(MOD_REMOTE, SEV_ERROR) << "Connection::handleRead: " << error.message();
_connectionManager.stop(shared_from_this());
}
}
+12 -10
View File
@@ -1,3 +1,5 @@
#include "logger/Logger.hpp"
#include "MediaRequestHandler.hpp"
#include "database/AudioTypes.hpp"
@@ -23,31 +25,31 @@ MediaRequestHandler::process(const MediaRequest& request, MediaResponse& respons
if (request.prepare().has_audio())
res = processAudioPrepare(request.prepare().audio(), response);
else if (request.prepare().has_video())
;// TODO;
LMS_LOG(MOD_REMOTE, SEV_ERROR) << "Video prepare not supported!";
else
std::cerr << "Bad MediaRequest::TypeMediaPrepare!" << std::endl;
LMS_LOG(MOD_REMOTE, SEV_ERROR) << "Bad MediaRequest::TypeMediaPrepare!";
}
else
std::cerr << "Bad MediaRequest::TypeMediaPrepare!" << std::endl;
LMS_LOG(MOD_REMOTE, SEV_ERROR) << "Bad MediaRequest::TypeMediaPrepare!";
break;
case MediaRequest::TypeMediaGetPart:
if (request.has_get_part())
res = processGetPart(request.get_part(), response);
else
std::cerr << "Bad MediaRequest::TypeMediaGet!" << std::endl;
LMS_LOG(MOD_REMOTE, SEV_ERROR) << "Bad MediaRequest::TypeMediaGet!";
break;
case MediaRequest::TypeMediaTerminate:
if (request.has_terminate())
res = processTerminate(request.terminate(), response);
else
std::cerr << "Bad MediaRequest::TypeMediaTerminate!" << std::endl;
LMS_LOG(MOD_REMOTE, SEV_ERROR) << "Bad MediaRequest::TypeMediaTerminate!";
break;
default:
std::cerr << "Unhandled MediaRequest type = " << request.type() << std::endl;
LMS_LOG(MOD_REMOTE, SEV_ERROR) << "Unhandled MediaRequest type = " << request.type();
}
return res;
@@ -68,7 +70,7 @@ MediaRequestHandler::processAudioPrepare(const MediaRequest::Prepare::Audio& req
format = Transcode::Format::OGA;
break;
default:
std::cerr << "Unhandled codec type = " << request.codec_type() << std::endl;
LMS_LOG(MOD_REMOTE, SEV_ERROR) << "Unhandled codec type = " << request.codec_type();
return false;
}
}
@@ -108,7 +110,7 @@ MediaRequestHandler::processAudioPrepare(const MediaRequest::Prepare::Audio& req
}
catch(std::exception& e)
{
std::cerr << "Caught exception: " << e.what() << std::endl;
LMS_LOG(MOD_REMOTE, SEV_ERROR) << "Caught exception: " << e.what();
response.mutable_error()->set_error(true);
response.mutable_error()->set_message("exception: " + std::string(e.what()));
response.set_type(MediaResponse::TypeError);
@@ -135,7 +137,7 @@ MediaRequestHandler::processGetPart(const MediaRequest::GetPart& request, MediaR
while (!_transcoder->isComplete() && _transcoder->getOutputData().size() < dataSize)
_transcoder->process();
std::cout << "MediaRequestHandler::processGetPart, isComplete = " << std::boolalpha << _transcoder->isComplete() << ", size = " << _transcoder->getOutputData().size() << std::endl;
LMS_LOG(MOD_REMOTE, SEV_DEBUG) << "MediaRequestHandler::processGetPart, isComplete = " << std::boolalpha << _transcoder->isComplete() << ", size = " << _transcoder->getOutputData().size();
Transcode::AvConvTranscoder::data_type::iterator itEnd;
if (_transcoder->getOutputData().size() > dataSize)
@@ -156,7 +158,7 @@ MediaRequestHandler::processGetPart(const MediaRequest::GetPart& request, MediaR
bool
MediaRequestHandler::processTerminate(const MediaRequest::Terminate& /*request*/, MediaResponse& response)
{
std::cout << "MediaRequestHandler: resetting transcoder" << std::endl;
LMS_LOG(MOD_REMOTE, SEV_DEBUG) << "MediaRequestHandler: resetting transcoder";
_transcoder.reset();
assert(!_transcoder);
+5 -4
View File
@@ -1,3 +1,4 @@
#include "logger/Logger.hpp"
#include "RequestHandler.hpp"
@@ -34,7 +35,7 @@ RequestHandler::process(const ClientMessage& request, ServerMessage& response)
response.set_type(ServerMessage::AuthResponse);
}
else
std::cerr << "Bad ClientMessage::AuthRequest !" << std::endl;
LMS_LOG(MOD_REMOTE, SEV_ERROR) << "Bad ClientMessage::AuthRequest !";
break;
case ClientMessage::AudioCollectionRequest:
// Not allowed if the user is not logged in
@@ -47,7 +48,7 @@ RequestHandler::process(const ClientMessage& request, ServerMessage& response)
response.set_type( ServerMessage::AudioCollectionResponse);
}
else
std::cerr << "Bad ClientMessage::AudioCollectionRequest message!" << std::endl;
LMS_LOG(MOD_REMOTE, SEV_ERROR) << "Bad ClientMessage::AudioCollectionRequest message!";
}
break;
@@ -62,12 +63,12 @@ RequestHandler::process(const ClientMessage& request, ServerMessage& response)
response.set_type( ServerMessage::MediaResponse);
}
else
std::cerr << "Malformed ClientMessage::MediaRequest message!" << std::endl;
LMS_LOG(MOD_REMOTE, SEV_ERROR) << "Malformed ClientMessage::MediaRequest message!";
}
break;
default:
std::cerr << "Unhandled message type = " << request.type() << std::endl;
LMS_LOG(MOD_REMOTE, SEV_ERROR) << "Unhandled message type = " << request.type();
}
return res;
+3 -2
View File
@@ -4,6 +4,8 @@
#include <boost/asio/placeholders.hpp>
#include <boost/bind.hpp>
#include "logger/Logger.hpp"
#include "Server.hpp"
namespace Remote {
@@ -56,7 +58,6 @@ Server::asyncAccept()
void
Server::handleAccept(std::shared_ptr<Connection> newConnection, boost::system::error_code ec)
{
std::cout << "Server::handleAccept..." << std::endl;
// Check whether the server was stopped before this
// completion handler had a chance to run.
if (!_acceptor.is_open())
@@ -73,7 +74,7 @@ Server::handleAccept(std::shared_ptr<Connection> newConnection, boost::system::e
asyncAccept();
}
else
std::cerr << "handleAccept: " << ec.message() << std::endl;
LMS_LOG(MOD_REMOTE, SEV_ERROR) << "handleAccept: " << ec.message();
}
+6 -3
View File
@@ -1,5 +1,7 @@
#include <boost/thread.hpp>
#include "logger/Logger.hpp"
#include "DatabaseUpdateService.hpp"
namespace Service {
@@ -13,21 +15,22 @@ DatabaseUpdateService::DatabaseUpdateService(const Config& config)
void
DatabaseUpdateService::start(void)
{
LMS_LOG(MOD_SERVICE, SEV_DEBUG) << "DatabaseUpdateService, starting...";
_databaseUpdater.start();
}
void
DatabaseUpdateService::stop(void)
{
std::cout << "DatabaseUpdateService::stop, processing..." << std::endl;
LMS_LOG(MOD_SERVICE, SEV_DEBUG) << "DatabaseUpdateService, stopping...";
_databaseUpdater.stop();
std::cout << "DatabaseUpdateService::stop, process done" << std::endl;
LMS_LOG(MOD_SERVICE, SEV_DEBUG) << "DatabaseUpdateService, stopped";
}
void
DatabaseUpdateService::restart(void)
{
std::cout << "DatabaseUpdateService::restart" << std::endl;
LMS_LOG(MOD_SERVICE, SEV_DEBUG) << "DatabaseUpdateService, restart";
stop();
start();
}
+6 -5
View File
@@ -1,3 +1,4 @@
#include "logger/Logger.hpp"
#include "RemoteServerService.hpp"
@@ -15,24 +16,24 @@ RemoteServerService::RemoteServerService(const Config& config)
void
RemoteServerService::start(void)
{
std::cout << "RemoteServerService::start, starting..." << std::endl;
LMS_LOG(MOD_SERVICE, SEV_DEBUG) << "RemoteServerService::start, starting...";
_server.start();
std::cout << "RemoteServerService::start, started!" << std::endl;
LMS_LOG(MOD_SERVICE, SEV_DEBUG) << "RemoteServerService::start, started!";
}
void
RemoteServerService::stop(void)
{
std::cout << "RemoteServerService::stop, stopping..." << std::endl;
LMS_LOG(MOD_SERVICE, SEV_DEBUG) << "RemoteServerService::stop, stopping...";
_server.stop();
std::cout << "RemoteServerService::stop, stopped!" << std::endl;
LMS_LOG(MOD_SERVICE, SEV_DEBUG) << "RemoteServerService::stop, stopped!";
}
void
RemoteServerService::restart(void)
{
std::cout << "RemoteServerService::restart, not implemented!" << std::endl;
LMS_LOG(MOD_SERVICE, SEV_DEBUG) << "RemoteServerService::restart, not implemented!";
}
} // namespace Service
+7 -8
View File
@@ -1,3 +1,4 @@
#include "logger/Logger.hpp"
#include <boost/foreach.hpp>
#include <boost/bind.hpp>
@@ -40,20 +41,20 @@ ServiceManager::run()
asyncWaitSignals();
std::cout << "ServiceManager::run Waiting for events..." << std::endl;
LMS_LOG(MOD_SERVICE, SEV_DEBUG) << "ServiceManager: waiting for events...";
try {
// Wait for events
_ioService.run();
}
catch( std::exception& e )
{
std::cerr << "Caugh exception in service : " << e.what() << std::endl;
LMS_LOG(MOD_SERVICE, SEV_ERROR) << "ServiceManager: exception in ioService::run: " << e.what();
}
// Stopping services
stopServices();
std::cout << "ServiceManager::run complete!" << std::endl;
LMS_LOG(MOD_SERVICE, SEV_DEBUG) << "ServiceManager: run complete !";
}
void
@@ -68,10 +69,8 @@ ServiceManager::asyncWaitSignals(void)
void
ServiceManager::startService(Service::pointer service)
{
std::cout << "ServiceManager::startService" << std::endl;
_services.insert(service);
service->start();
std::cout << "ServiceManager::startService done" << std::endl;
}
void
@@ -99,20 +98,20 @@ ServiceManager::restartServices(void)
void
ServiceManager::handleSignal(boost::system::error_code /*ec*/, int signo)
{
std::cout << "Received signal " << signo << std::endl;
LMS_LOG(MOD_SERVICE, SEV_INFO) << "Received signal " << signo;
switch (signo)
{
case SIGINT:
case SIGTERM:
case SIGQUIT:
std::cout << "Stopping services..." << std::endl;
LMS_LOG(MOD_SERVICE, SEV_NOTICE) << "Stopping services...";
stopServices();
// Do not listen for signals, this will make the ioservice.run return
break;
case SIGHUP:
std::cout << "Restarting services..." << std::endl;
LMS_LOG(MOD_SERVICE, SEV_NOTICE) << "Restarting services...";
restartServices();
asyncWaitSignals();
+5 -5
View File
@@ -1,4 +1,4 @@
#include <iostream>
#include "logger/Logger.hpp"
#include "UserInterfaceService.hpp"
#include "ui/LmsApplication.hpp"
@@ -30,7 +30,7 @@ UserInterfaceService::UserInterfaceService( boost::filesystem::path runAppPath,
for(int i = 0; i < argc; ++i)
{
std::cout << "i = " << i << ", arg = '" << argv[i] << "'" << std::endl;
LMS_LOG(MOD_SERVICE, SEV_DEBUG) << "i = " << i << ", arg = '" << argv[i] << "'";
}
_server.setServerConfiguration (argc, const_cast<char**>(argv));
@@ -44,15 +44,15 @@ void
UserInterfaceService::start(void)
{
_server.start();
std::cout << "UserInterfaceService::start -> Service started..." << std::endl;
LMS_LOG(MOD_SERVICE, SEV_DEBUG) << "UserInterfaceService::start -> Service started...";
}
void
UserInterfaceService::stop(void)
{
std::cout << "UserInterfaceService::stop -> stopping..." << std::endl;
LMS_LOG(MOD_SERVICE, SEV_DEBUG) << "UserInterfaceService::stop -> stopping...";
_server.stop();
std::cout << "UserInterfaceService::stop -> stopped!" << std::endl;
LMS_LOG(MOD_SERVICE, SEV_DEBUG) << "UserInterfaceService::stop -> stopped!";
}
void
+8 -4
View File
@@ -6,6 +6,7 @@ check_PROGRAMS = database-integrity sql-query database-basics database-user remo
remote_SOURCES = \
$(srcdir)/RemoteClientServer.cpp \
$(srcdir)/TestDatabase.cpp \
$(top_srcdir)/logger/Logger.cpp \
$(top_srcdir)/remote/messages/auth.pb.cc \
$(top_srcdir)/remote/messages/collection.pb.cc \
$(top_srcdir)/remote/messages/common.pb.cc \
@@ -21,10 +22,11 @@ remote_SOURCES = \
$(top_srcdir)/database/Path.cpp \
$(top_srcdir)/database/Video.cpp
remote_CXXFLAGS=-std=c++11 -Wall -Wextra -I$(top_srcdir) -I$(top_srcdir)/remote -I$(top_srcdir)/boost
remote_CXXFLAGS=-std=c++11 -Wall -Wextra -DBOOST_LOG_DYN_LINK -I$(top_srcdir) -I$(top_srcdir)/remote -I$(top_srcdir)/boost
database_user_SOURCES = \
$(srcdir)/CheckDatabaseUser.cpp \
$(top_srcdir)/logger/Logger.cpp \
$(top_srcdir)/database/Artist.cpp \
$(top_srcdir)/database/Genre.cpp \
$(top_srcdir)/database/Release.cpp \
@@ -35,11 +37,12 @@ database_user_SOURCES = \
$(top_srcdir)/database/User.cpp \
$(top_srcdir)/database/Video.cpp
database_user_CXXFLAGS=-std=c++11 -Wall -Wextra -I$(top_srcdir)
database_user_CXXFLAGS=-std=c++11 -Wall -Wextra -DBOOST_LOG_DYN_LINK -I$(top_srcdir)
database_integrity_SOURCES = \
$(srcdir)/DatabaseIntegrity.cpp \
$(top_srcdir)/logger/Logger.cpp \
$(top_srcdir)/database/Artist.cpp \
$(top_srcdir)/database/Genre.cpp \
$(top_srcdir)/database/Release.cpp \
@@ -50,10 +53,11 @@ database_integrity_SOURCES = \
$(top_srcdir)/database/User.cpp \
$(top_srcdir)/database/Video.cpp
database_integrity_CXXFLAGS=-std=c++11 -Wall -Wextra -I$(top_srcdir)
database_integrity_CXXFLAGS=-std=c++11 -Wall -Wextra -DBOOST_LOG_DYN_LINK -I$(top_srcdir)
database_basics_SOURCES = \
$(srcdir)/CheckDatabaseBasics.cpp \
$(top_srcdir)/logger/Logger.cpp \
$(top_srcdir)/database/Artist.cpp \
$(top_srcdir)/database/Genre.cpp \
$(top_srcdir)/database/Release.cpp \
@@ -65,7 +69,7 @@ database_basics_SOURCES = \
$(top_srcdir)/database/User.cpp \
$(top_srcdir)/database/Video.cpp
database_basics_CXXFLAGS=-std=c++11 -Wall -Wextra -I$(top_srcdir)
database_basics_CXXFLAGS=-std=c++11 -Wall -Wextra -DBOOST_LOG_DYN_LINK -I$(top_srcdir)
sql_query_SOURCES = \
+4 -4
View File
@@ -715,7 +715,7 @@ class TestClient
int main()
{
try {
bool extendedTests = true;
bool extendedTests = false;
bool writeCovers = false;
std::cout << "Running test... extendedTests = " << std::boolalpha << extendedTests << std::endl;
@@ -811,16 +811,16 @@ int main()
// ****** Transcode test ********
{
std::vector<unsigned char> data;
client.getMediaAudio(1, data);
client.getMediaAudio(30000, data);
std::cout << "Media size = " << data.size() << std::endl;
}
{
/* {
std::vector<unsigned char> data;
client.getMediaAudio(100, data);
std::cout << "Media size = " << data.size() << std::endl;
}
}*/
std::cout << "End of tests!" << std::endl;
Executable → Regular
View File
+13 -14
View File
@@ -1,11 +1,11 @@
#include <iostream>
#include <sstream>
#include <boost/iostreams/stream.hpp>
#include <boost/process.hpp>
#include <boost/foreach.hpp>
#include "logger/Logger.hpp"
#include "AvConvTranscoder.hpp"
namespace Transcode
@@ -19,7 +19,7 @@ void
AvConvTranscoder::init()
{
_avConvPath = boost::process::search_path("avconv");
std::cout << "Using execPath " << _avConvPath << std::endl;
LMS_LOG(MOD_TRANSCODE, SEV_INFO) << "Using execPath " << _avConvPath;
}
@@ -41,7 +41,7 @@ AvConvTranscoder::AvConvTranscoder(const Parameters& parameters)
throw std::runtime_error("File " + _parameters.getInputMediaFile().getPath().string() + " is not regular!");
}
std::cout << "Transcoding file '" << _parameters.getInputMediaFile().getPath() << "'" << std::endl;
LMS_LOG(MOD_TRANSCODE, SEV_INFO) << "Transcoding file '" << _parameters.getInputMediaFile().getPath() << "'";
// Launch a process to handle the conversion
boost::iostreams::file_descriptor_sink sink(_outputPipe.sink, boost::iostreams::close_handle);
@@ -108,8 +108,7 @@ AvConvTranscoder::AvConvTranscoder(const Parameters& parameters)
}
oss << " -"; // output to stdout
std::cout << "executing... '" << oss.str() << "'" << std::endl;
LMS_LOG(MOD_TRANSCODE, SEV_DEBUG) << "Executing '" << oss.str() << "'";
// make sure only one thread is executing this part of code
// See boost process FAQ
@@ -141,7 +140,7 @@ AvConvTranscoder::process(void)
}
if (!_in || _in.fail() || _in.eof()) {
std::cout << "Transcode complete!" << std::endl;
LMS_LOG(MOD_TRANSCODE, SEV_DEBUG) << "Transcode complete!";
waitChild();
_isComplete = true;
@@ -151,7 +150,7 @@ AvConvTranscoder::process(void)
AvConvTranscoder::~AvConvTranscoder()
{
std::cout << "AvConvTranscoder::~AvConvTranscoder called!" << std::endl;
LMS_LOG(MOD_TRANSCODE, SEV_DEBUG) << "~AvConvTranscoder called!";
if (_in.eof())
waitChild();
@@ -166,12 +165,12 @@ AvConvTranscoder::waitChild()
{
boost::system::error_code ec;
std::cout << "waiting for child!" << std::endl;
LMS_LOG(MOD_TRANSCODE, SEV_DEBUG) << "Waiting for child...";
boost::process::wait_for_exit(*_child, ec);
std::cout << "waiting for child! DONE." << std::endl;
LMS_LOG(MOD_TRANSCODE, SEV_DEBUG) << "Waiting for child: OK";
if (ec)
std::cerr << "AvConvTranscoder::waitChild: error: " << ec.message() << std::endl;
LMS_LOG(MOD_TRANSCODE, SEV_ERROR) << "AvConvTranscoder::waitChild: error: " << ec.message();
_child.reset();
}
@@ -184,13 +183,13 @@ AvConvTranscoder::killChild()
{
boost::system::error_code ec;
std::cout << "Killing child! pid = " << _child->pid << std::endl;
LMS_LOG(MOD_TRANSCODE, SEV_DEBUG) << "Killing child! pid = " << _child->pid;
boost::process::terminate(*_child, ec);
std::cout << "Killing child DONE" << std::endl;
LMS_LOG(MOD_TRANSCODE, SEV_DEBUG) << "Killing child DONE";
// If an error occured, force kill the child
if (ec)
std::cerr << "AvConvTranscoder::killChild: error: " << ec.message() << std::endl;
LMS_LOG(MOD_TRANSCODE, SEV_ERROR) << "AvConvTranscoder::killChild: error: " << ec.message();
_child.reset();
}
+4 -3
View File
@@ -1,13 +1,14 @@
#include <list>
#include <boost/foreach.hpp>
#include "InputMediaFile.hpp"
#include "logger/Logger.hpp"
#include "av/InputFormatContext.hpp"
#include "cover/CoverArtGrabber.hpp"
#include "InputMediaFile.hpp"
namespace Transcode
{
@@ -71,7 +72,7 @@ InputMediaFile::InputMediaFile(const boost::filesystem::path& p)
_bestStreams.insert(std::make_pair( streamType, index) );
}
else
std::cerr << "Cannot find best stream for type " << type << std::endl;
LMS_LOG(MOD_TRANSCODE, SEV_WARNING) << "Cannot find best stream for type " << type;
}
_covers = CoverArt::Grabber::getFromInputFormatContext(input);
-1
View File
@@ -13,7 +13,6 @@ LmsApplication::create(const Wt::WEnvironment& env, boost::filesystem::path dbPa
* You could read information from the environment to decide whether
* the user has permission to start a new application
*/
std::cout << "Creating new Application" << std::endl;
return new LmsApplication(env, dbPath);
}
-5
View File
@@ -72,15 +72,12 @@ AudioDatabaseWidget::handleFilterUpdated(std::size_t idFilterUpdated)
_refreshingFilters = true;
std::cout << "FILTER " << idFilterUpdated << " has been UPDATED!" << std::endl;
FilterWidget::Constraint currentConstraint;
currentConstraint.where.And( WhereClause( "track.artist_id = artist.id and track.release_id = release.id and track_genre.track_id = track.id and genre.id = track_genre.genre_id"));
for (std::size_t idFilter = 0; idFilter < _filters.size(); ++idFilter)
{
std::cout << "Processing Filter INDEX " << idFilter << std::endl;
FilterWidget* filter = _filters.at(idFilter);
// Apply contraints created by previous filters
@@ -100,8 +97,6 @@ AudioDatabaseWidget::handleFilterUpdated(std::size_t idFilterUpdated)
void
AudioDatabaseWidget::selectNextTrack(void)
{
std::cout << "Wants to select next track!" << std::endl;
TrackWidget* trackWidget ( dynamic_cast<TrackWidget*>(_filters.back() ) );
trackWidget->selectNextTrack();
+4 -10
View File
@@ -94,8 +94,6 @@ AudioMediaPlayerWidget::handlePlayOffset(int offsetSecs)
if (!_currentParameters)
return;
std::cout << "Want to play at offset " << offsetSecs << std::endl;;
_currentParameters->setOffset( boost::posix_time::seconds(offsetSecs) );
loadPlayer();
@@ -107,41 +105,37 @@ AudioMediaPlayerWidget::handlePlayOffset(int offsetSecs)
void
AudioMediaPlayerWidget::handlePlayNext(void)
{
std::cout << "Want to play next!" << std::endl;
// TODO
}
void
AudioMediaPlayerWidget::handlePlayPrev(void)
{
std::cout << "Want to play prev!" << std::endl;
// TODO
}
void
AudioMediaPlayerWidget::handleTrackEnded(void)
{
std::cout << "Track playback ended!" << std::endl;
_playbackEnded.emit();
}
void
AudioMediaPlayerWidget::handleValueChanged(double value)
{
std::cout << "Value changed!" << std::endl;
// TODO
}
void
AudioMediaPlayerWidget::handleSliderMoved(int value)
{
std::cout << "Slider moved to " << value << std::endl;
;
}
void
AudioMediaPlayerWidget::handleTimeUpdated(void)
{
std::cout << "Time updated to " << _mediaPlayer->currentTime() << std::endl;
if (!_currentParameters)
return;
+8 -6
View File
@@ -1,5 +1,7 @@
#include <Wt/WBreak>
#include "logger/Logger.hpp"
#include "AudioWidget.hpp"
namespace UserInterface {
@@ -37,7 +39,7 @@ AudioWidget::search(const std::string& searchText)
void
AudioWidget::playTrack(boost::filesystem::path p)
{
std::cout << "play track '" << p << "'" << std::endl;
LMS_LOG(MOD_UI, SEV_DEBUG) << "play track '" << p << "'";
try {
std::size_t bitrate = 0;
@@ -65,15 +67,15 @@ AudioWidget::playTrack(boost::filesystem::path p)
if (!covers.empty())
{
std::cout << "Cover found!" << std::endl;
LMS_LOG(MOD_UI, SEV_DEBUG) << "Cover found!";
if (!covers.front().scale(256))
std::cerr << "Cannot resize!" << std::endl;
LMS_LOG(MOD_UI, SEV_ERROR) << "Cannot resize!";
//_imgResource->setMimeType(covers.front().getMimeType());
_imgResource->setData(covers.front().getData());
}
else {
std::cout << "No cover found!" << std::endl;
LMS_LOG(MOD_UI, SEV_DEBUG) << "No cover found!";
_imgResource->setData( std::vector<unsigned char>());
}
@@ -82,14 +84,14 @@ AudioWidget::playTrack(boost::filesystem::path p)
}
catch( std::exception &e)
{
std::cerr <<"Caught exception while loading '" << p << "': " << e.what() << std::endl;
LMS_LOG(MOD_UI, SEV_ERROR) << "Caught exception while loading '" << p << "': " << e.what();
}
}
void
AudioWidget::handleTrackEnded(void)
{
std::cout << "Track playback ended!" << std::endl;
LMS_LOG(MOD_UI, SEV_DEBUG) << "Track playback ended!";
_audioDbWidget->selectNextTrack();
}
+5 -3
View File
@@ -1,5 +1,7 @@
#include <boost/foreach.hpp>
#include "logger/Logger.hpp"
#include "TableFilterWidget.hpp"
namespace UserInterface {
@@ -41,20 +43,20 @@ TableFilterWidget::refresh(const Constraint& constraint)
SqlQuery AllSqlQuery;
AllSqlQuery.select("'<All>',0,1 AS ORDERBY");
std::cout << _table << ", generated query = '" << sqlQuery.get() + " UNION " + AllSqlQuery.get() << "'" << std::endl;
LMS_LOG(MOD_UI, SEV_DEBUG) << _table << ", generated query = '" << sqlQuery.get() + " UNION " + AllSqlQuery.get() << "'";
Wt::Dbo::Query<ResultType> query = _db.getSession().query<ResultType>( sqlQuery.get() + " UNION " + AllSqlQuery.get() );
query.orderBy("ORDERBY DESC," + _table + "." + _field);
BOOST_FOREACH(const std::string& bindArg, sqlQuery.where().getBindArgs()) {
std::cout << "Binding value '" << bindArg << "'" << std::endl;
LMS_LOG(MOD_UI, SEV_DEBUG) << "Binding value '" << bindArg << "'";
query.bind(bindArg);
}
_queryModel.setQuery( query, true /* Keep columns */);
std::cout << "Finish !" << std::endl;
LMS_LOG(MOD_UI, SEV_DEBUG) << "Finish !";
}
// Get constraint created by this filter
+4 -2
View File
@@ -4,6 +4,8 @@
#include <Wt/WItemDelegate>
#include <Wt/WBreak>
#include "logger/Logger.hpp"
#include "TrackWidget.hpp"
namespace UserInterface {
@@ -76,14 +78,14 @@ TrackWidget::refresh(const Constraint& constraint)
sqlQuery.from().And( FromClause("artist,release,track,genre,track_genre"));
sqlQuery.where().And(constraint.where);
std::cout << "TRACK REQ = '" << sqlQuery.get() << "'" << std::endl;
LMS_LOG(MOD_UI, SEV_DEBUG) << "TRACK REQ = '" << sqlQuery.get() << "'";
Wt::Dbo::Query<ResultType> query = _db.getSession().query<ResultType>( sqlQuery.get() );
query.groupBy("track").orderBy("artist.name,track.creation_time,release.name,track.disc_number,track.track_number");
BOOST_FOREACH(const std::string& bindArg, sqlQuery.where().getBindArgs()) {
std::cout << "Binding value '" << bindArg << "'" << std::endl;
LMS_LOG(MOD_UI, SEV_DEBUG) << "Binding value '" << bindArg << "'";
query.bind(bindArg);
}
+10 -7
View File
@@ -1,6 +1,9 @@
#include <Wt/Http/Request>
#include <Wt/Http/Response>
#include "logger/Logger.hpp"
#include "AvConvTranscodeStreamResource.hpp"
namespace UserInterface {
@@ -9,12 +12,12 @@ AvConvTranscodeStreamResource::AvConvTranscodeStreamResource(const Transcode::Pa
: Wt::WResource(parent),
_parameters( parameters )
{
std::cout << "CONSTRUCTING RESOURCE" << std::endl;
LMS_LOG(MOD_UI, SEV_DEBUG) << "CONSTRUCTING RESOURCE";
}
AvConvTranscodeStreamResource::~AvConvTranscodeStreamResource()
{
std::cout << "DESTRUCTING RESOURCE" << std::endl;
LMS_LOG(MOD_UI, SEV_DEBUG) << "DESTRUCTING RESOURCE";
beingDeleted();
}
@@ -31,7 +34,7 @@ AvConvTranscodeStreamResource::handleRequest(const Wt::Http::Request& request,
if (!transcoder)
{
std::cout << "Launching transcoder" << std::endl;
LMS_LOG(MOD_UI, SEV_DEBUG) << "Launching transcoder";
transcoder = std::make_shared<Transcode::AvConvTranscoder>( _parameters);
response.setMimeType(_parameters.getOutputFormat().getMimeType());
@@ -56,10 +59,10 @@ AvConvTranscodeStreamResource::handleRequest(const Wt::Http::Request& request,
copiedSize++;
}
std::cout << "Wrote " << copiedSize << " bytes" << std::endl;
LMS_LOG(MOD_UI, SEV_DEBUG) << "Wrote " << copiedSize << " bytes";
if (!copySuccess)
std::cerr << "** Write failed!" << std::endl;
LMS_LOG(MOD_UI, SEV_ERROR) << "** Write failed!";
// Consume copied bytes
data.erase(data.begin(), data.begin() + copiedSize);
@@ -67,10 +70,10 @@ AvConvTranscodeStreamResource::handleRequest(const Wt::Http::Request& request,
if (copySuccess && !transcoder->isComplete()) {
continuation = response.createContinuation();
continuation->setData(transcoder);
std::cout << "Continuation set!" << std::endl;
LMS_LOG(MOD_UI, SEV_DEBUG) << "Continuation set!";
}
else
std::cout << "No more data!" << std::endl;
LMS_LOG(MOD_UI, SEV_DEBUG) << "No more data!";
}
} // namespace UserInterface
+3 -1
View File
@@ -10,6 +10,8 @@
#include "SettingsMediaDirectories.hpp"
#include "SettingsUsers.hpp"
#include "logger/Logger.hpp"
#include "service/ServiceManager.hpp"
#include "service/DatabaseUpdateService.hpp"
@@ -67,7 +69,7 @@ _sessionData(sessionData)
void
Settings::handleDatabaseDirectoriesChanged()
{
std::cout << "Media directories have changed: requesting imediate scan" << std::endl;
LMS_LOG(MOD_UI, SEV_NOTICE) << "Media directories have changed: requesting imediate scan";
// On directory add or delete, request an immediate scan
{
Wt::Dbo::Transaction transaction(_sessionData.getDatabaseHandler().getSession());
+3 -1
View File
@@ -8,6 +8,8 @@
#include <Wt/WPushButton>
#include <Wt/Auth/Identity>
#include "logger/Logger.hpp"
#include "common/Validators.hpp"
#include "SettingsAccountFormView.hpp"
@@ -96,7 +98,7 @@ class AccountFormModel : public Wt::WFormModel
}
catch(Wt::Dbo::Exception& exception)
{
std::cerr << "Dbo exception: " << exception.what() << std::endl;
LMS_LOG(MOD_UI, SEV_ERROR) << "Dbo exception: " << exception.what();
return false;
}
+3 -1
View File
@@ -5,6 +5,8 @@
#include <Wt/WComboBox>
#include <Wt/WPushButton>
#include "logger/Logger.hpp"
#include "common/Validators.hpp"
#include "SettingsAudioFormView.hpp"
@@ -64,7 +66,7 @@ class AudioFormModel : public Wt::WFormModel
}
catch(Wt::Dbo::Exception& exception)
{
std::cerr << "Dbo exception: " << exception.what() << std::endl;
LMS_LOG(MOD_UI, SEV_ERROR) << "Dbo exception: " << exception.what();
return false;
}
+2 -1
View File
@@ -7,6 +7,7 @@
#include <Wt/WFormModel>
#include <Wt/WStringListModel>
#include "logger/Logger.hpp"
#include "database/MediaDirectory.hpp"
#include "common/DirectoryValidator.hpp"
@@ -88,7 +89,7 @@ class DatabaseFormModel : public Wt::WFormModel
}
catch(Wt::Dbo::Exception& exception)
{
std::cerr << "Dbo exception: " << exception.what() << std::endl;
LMS_LOG(MOD_UI, SEV_ERROR) << "Dbo exception: " << exception.what();
return false;
}
@@ -6,6 +6,7 @@
#include <Wt/WComboBox>
#include <Wt/WPushButton>
#include "logger/Logger.hpp"
#include "database/MediaDirectory.hpp"
#include "common/DirectoryValidator.hpp"
@@ -62,7 +63,7 @@ class MediaDirectoryFormModel : public Wt::WFormModel
}
catch(Wt::Dbo::Exception& exception)
{
std::cerr << "Dbo exception: " << exception.what() << std::endl;
LMS_LOG(MOD_UI, SEV_ERROR) << "Dbo exception: " << exception.what();
return false;
}
+5 -3
View File
@@ -8,6 +8,8 @@
#include <Wt/WPushButton>
#include <Wt/Auth/Identity>
#include "logger/Logger.hpp"
#include "common/Validators.hpp"
#include "SettingsUserFormView.hpp"
@@ -147,12 +149,12 @@ class UserFormModel : public Wt::WFormModel
// user may have been deleted by someone else
if (!authUser.isValid()) {
std::cerr << "user identity does not exist!" << std::endl;
LMS_LOG(MOD_UI, SEV_ERROR) << "user identity does not exist!";
return false;
}
else if(!user)
{
std::cerr << "User not found!" << std::endl;
LMS_LOG(MOD_UI, SEV_ERROR) << "User not found!";
return false;
}
@@ -185,7 +187,7 @@ class UserFormModel : public Wt::WFormModel
}
catch(Wt::Dbo::Exception& exception)
{
std::cerr << "Dbo exception: " << exception.what() << std::endl;
LMS_LOG(MOD_UI, SEV_ERROR) << "Dbo exception: " << exception.what();
return false;
}
+4 -2
View File
@@ -6,6 +6,8 @@
#include <Wt/Auth/Identity>
#include "logger/Logger.hpp"
#include "SettingsUserFormView.hpp"
#include "SettingsUsers.hpp"
@@ -77,12 +79,12 @@ Users::refresh(void)
}
catch(Wt::Dbo::Exception& e)
{
std::cerr << "Caught exception when getting userId=" << userId << ": " << e.code() << std::endl;
LMS_LOG(MOD_UI, SEV_ERROR) << "Caught exception when getting userId=" << userId << ": " << e.code();
continue;
}
if (!authUser.isValid()) {
std::cerr << "Users::refresh: skipping invalid userId = " << userId << std::endl;
LMS_LOG(MOD_UI, SEV_ERROR) << "Users::refresh: skipping invalid userId = " << userId;
continue;
}