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
+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();
}