From 886b3221f5e90b21d74c5a8d747caefae4b86551 Mon Sep 17 00:00:00 2001 From: emeric Date: Thu, 3 Apr 2014 09:19:35 +0200 Subject: [PATCH] WIP: adding service files, still not working --- Makefile.am | 11 ++- TODO | 13 ++-- configure.ac | 5 ++ main/DatabaseRefreshService.cpp | 37 ++++++++++ main/DatabaseRefreshService.hpp | 26 +++++++ main/RemoteServerService.cpp | 28 ++++++++ main/RemoteServerService.hpp | 24 +++++++ main/Service.hpp | 29 ++++++++ main/ServiceManager.cpp | 95 +++++++++++++++++++++++++ main/ServiceManager.hpp | 41 +++++++++++ main/WebServerService.cpp | 47 ++++++++++++ main/WebServerService.hpp | 24 +++++++ main/main.cpp | 67 ++++++++--------- remote/{server => messages}/Header.hpp | 6 +- remote/server/.Connection.hpp.swp | Bin 12288 -> 0 bytes remote/server/Connection.cpp | 15 ++-- remote/server/Connection.hpp | 35 ++++----- remote/server/ConnectionManager.cpp | 17 +++-- remote/server/ConnectionManager.hpp | 19 ++--- remote/server/RequestHandler.hpp | 4 +- remote/server/Server.cpp | 21 +++--- remote/server/Server.hpp | 14 ++-- {main => ui}/LmsApplication.cpp | 0 {main => ui}/LmsApplication.hpp | 0 24 files changed, 476 insertions(+), 102 deletions(-) create mode 100644 main/DatabaseRefreshService.cpp create mode 100644 main/DatabaseRefreshService.hpp create mode 100644 main/RemoteServerService.cpp create mode 100644 main/RemoteServerService.hpp create mode 100644 main/Service.hpp create mode 100644 main/ServiceManager.cpp create mode 100644 main/ServiceManager.hpp create mode 100644 main/WebServerService.cpp create mode 100644 main/WebServerService.hpp rename remote/{server => messages}/Header.hpp (71%) delete mode 100644 remote/server/.Connection.hpp.swp rename {main => ui}/LmsApplication.cpp (100%) rename {main => ui}/LmsApplication.hpp (100%) diff --git a/Makefile.am b/Makefile.am index fdd85983..9bd12bc1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -7,13 +7,17 @@ bin_PROGRAMS = lms lms_SOURCES = \ $(top_srcdir)/main/main.cpp \ - $(top_srcdir)/main/LmsApplication.cpp \ + $(top_srcdir)/main/ServiceManager.cpp \ + $(top_srcdir)/main/DatabaseRefreshService.cpp \ + $(top_srcdir)/main/RemoteServerService.cpp \ + $(top_srcdir)/main/WebServerService.cpp \ $(top_srcdir)/av/CodecContext.cpp \ $(top_srcdir)/av/Common.cpp \ $(top_srcdir)/av/Dictionary.cpp \ $(top_srcdir)/av/FormatContext.cpp \ $(top_srcdir)/av/InputFormatContext.cpp \ $(top_srcdir)/av/Stream.cpp \ + $(top_srcdir)/ui/LmsApplication.cpp \ $(top_srcdir)/ui/audio/AudioWidget.cpp \ $(top_srcdir)/ui/audio/AudioDatabaseWidget.cpp \ $(top_srcdir)/ui/audio/AudioMediaPlayerWidget.cpp \ @@ -35,6 +39,9 @@ lms_SOURCES = \ $(top_srcdir)/database/SqlQuery.cpp \ $(top_srcdir)/database/Path.cpp \ $(top_srcdir)/database/Video.cpp \ + $(top_srcdir)/remote/server/Connection.cpp \ + $(top_srcdir)/remote/server/ConnectionManager.cpp \ + $(top_srcdir)/remote/server/Server.cpp \ $(top_srcdir)/transcode/AvConvTranscoder.cpp \ $(top_srcdir)/transcode/Format.cpp \ $(top_srcdir)/transcode/Parameters.cpp \ @@ -43,5 +50,5 @@ lms_SOURCES = \ $(top_srcdir)/metadata/Extractor.cpp \ $(top_srcdir)/metadata/Utils.cpp -lms_CXXFLAGS=-std=c++11 -Wall -I$(top_srcdir)/boost/ -I$(top_srcdir)/ui +lms_CXXFLAGS=-std=c++11 -Wall -I$(top_srcdir)/boost/ -I$(top_srcdir)/ui -I$(top_srcdir)/remote diff --git a/TODO b/TODO index 4e5e6fbe..7adb49ee 100644 --- a/TODO +++ b/TODO @@ -2,15 +2,14 @@ [Users] - Do the feature -[Pictures] -- Do the feature (merge the Video/Pictures feature? i.e. for personal holiday data sharing...) - [Database] - When removing a track, make sure to remove genre/artist/release if last - Use Inotify like system to watch modified/added files - Implement a video database cleanup - User access for Video/Pictures (really needed for Audio?) - Create a new type: "share", that handles every other types in a directory based share? +- Group video in "video groups". Each video may has sub groups (current "Path" class) +- Simplify database and remove the Path class [Audio] - TableViewFilter: -> Track count for this speccial category @@ -20,9 +19,15 @@ - TrackView : select only relevant columns to speed up queries (do not get eveything) - OGG metadata -> properly handle metadata nested in the audio stream +[Video] +- View the Videos in a WtTableView ? + [Remote API] -- Think about a remote API to get/retrieve transcoded files (i.e. for mobile apps)? +- Think about a remote API to get/retrieve media (i.e. for mobile apps) [Layout] - Make it mobile browser compatible - Style eveything nicely... + +[Logs] +- Use a logging facility diff --git a/configure.ac b/configure.ac index c2be5149..6010377f 100644 --- a/configure.ac +++ b/configure.ac @@ -16,6 +16,11 @@ AC_CHECK_HEADERS([Wt/WApplication extractor.h], # [], # [AC_MSG_ERROR([Header not found or unusable !])]) +AC_CHECK_LIB([pthread], + [pthread_create], + , + [AC_MSG_ERROR([libpthread not found!])]) + AC_CHECK_LIB([avutil], [av_free], , diff --git a/main/DatabaseRefreshService.cpp b/main/DatabaseRefreshService.cpp new file mode 100644 index 00000000..be61ce16 --- /dev/null +++ b/main/DatabaseRefreshService.cpp @@ -0,0 +1,37 @@ + +#include "DatabaseRefreshService.hpp" + +DatabaseRefreshService::DatabaseRefreshService(const boost::filesystem::path& p) +: _metadataParser(), + _database( p, _metadataParser) +{ + + // TODO read from the database itself! + // Move this code in the database class + _database.watchDirectory( WatchedDirectory("/storage/common/Media/Son/Metal", WatchedDirectory::Audio) ); + _database.watchDirectory( WatchedDirectory("/storage/common/Media/Video", WatchedDirectory::Video) ); + + // TODO launch thread + // boost::thread refreshThread(boost::bind(&Database::refresh, &database)); +} + +void +DatabaseRefreshService::start(void) +{ + std::cout << "DatabaseRefreshService::start, not implemented" << std::endl; + +} + +void +DatabaseRefreshService::stop(void) +{ + std::cout << "DatabaseRefreshService::stop, not implemented" << std::endl; +} + +void +DatabaseRefreshService::restart(void) +{ + std::cout << "DatabaseRefreshService::restart, not implemented" << std::endl; +} + + diff --git a/main/DatabaseRefreshService.hpp b/main/DatabaseRefreshService.hpp new file mode 100644 index 00000000..b30ac0cd --- /dev/null +++ b/main/DatabaseRefreshService.hpp @@ -0,0 +1,26 @@ +#ifndef DB_REFRESH_SERVICE_HPP +#define DB_REFRESH_SERVICE_HPP + +#include "metadata/AvFormat.hpp" +#include "database/Database.hpp" + +#include "Service.hpp" + +class DatabaseRefreshService : public Service +{ + public: + + DatabaseRefreshService(const boost::filesystem::path& p); + + void start(void); + void stop(void); + void restart(void); + + private: + + MetaData::AvFormat _metadataParser; + Database _database; +}; + +#endif + diff --git a/main/RemoteServerService.cpp b/main/RemoteServerService.cpp new file mode 100644 index 00000000..93fee736 --- /dev/null +++ b/main/RemoteServerService.cpp @@ -0,0 +1,28 @@ + +#include "RemoteServerService.hpp" + +RemoteServerService::RemoteServerService(const Remote::Server::Server::endpoint_type& endpoint) +: _server(endpoint) +{ +} + +void +RemoteServerService::start(void) +{ + std::cout << "émoteServerService::start, starting..." << std::endl; + _server.run(); +} + + +void +RemoteServerService::stop(void) +{ + std::cout << "émoteServerService::stop, stopping..." << std::endl; + _server.stop(); +} + +void +RemoteServerService::restart(void) +{ + std::cout << "émoteServerService::restart, not implemented!" << std::endl; +} diff --git a/main/RemoteServerService.hpp b/main/RemoteServerService.hpp new file mode 100644 index 00000000..6c4db5b2 --- /dev/null +++ b/main/RemoteServerService.hpp @@ -0,0 +1,24 @@ +#ifndef REMOTE_SERVER_SERVICE_HPP +#define REMOTE_SERVER_SERVICE_HPP + + +#include "Service.hpp" + +#include "remote/server/Server.hpp" + +class RemoteServerService : public Service +{ + public: + + RemoteServerService(const Remote::Server::Server::endpoint_type& endpoint); + + void start(void); + void stop(void); + void restart(void); + + private: + + Remote::Server::Server _server; +}; + +#endif diff --git a/main/Service.hpp b/main/Service.hpp new file mode 100644 index 00000000..0f88de1f --- /dev/null +++ b/main/Service.hpp @@ -0,0 +1,29 @@ +#ifndef SERVICE_HPP +#define SERVICE_HPP + +#include +#include + +// Interface class wrapper for running services +class Service +{ + public: + + typedef std::shared_ptr pointer; + + Service(const Service&) = delete; + Service& operator=(const Service&) = delete; + + Service() {} + virtual ~Service() {} + + virtual void start(void) = 0; + virtual void stop(void) = 0; + virtual void restart(void) = 0; + + private: + +}; + +#endif + diff --git a/main/ServiceManager.cpp b/main/ServiceManager.cpp new file mode 100644 index 00000000..33d64732 --- /dev/null +++ b/main/ServiceManager.cpp @@ -0,0 +1,95 @@ + +#include + +#include +#include + +#include "ServiceManager.hpp" + +ServiceManager::ServiceManager() +: _signalSet(_ioService) +{ + _signalSet.add(SIGINT); + _signalSet.add(SIGTERM); +#if defined(SIGQUIT) + _signalSet.add(SIGQUIT); +#endif // defined(SIGQUIT) + + _signalSet.add(SIGHUP); +} + +void +ServiceManager::run() +{ + + asyncWaitSignals(); + + // Wait for events + _ioService.run(); + +} + +void +ServiceManager::asyncWaitSignals(void) +{ + _signalSet.async_wait(boost::bind(&ServiceManager::handleSignal, + this, + boost::asio::placeholders::error, + boost::asio::placeholders::signal_number)); +} + +void +ServiceManager::startService(Service::pointer service) +{ + _services.insert(service); + service->start(); +} + +void +ServiceManager::stopService(Service::pointer service) +{ + _services.erase(service); + service->stop(); +} + +void +ServiceManager::stopServices(void) +{ + BOOST_FOREACH(Service::pointer service, _services) + service->stop(); +} + + +void +ServiceManager::restartServices(void) +{ + BOOST_FOREACH(Service::pointer service, _services) + service->restart(); +} + +void +ServiceManager::handleSignal(boost::system::error_code /*ec*/, int signo) +{ + std::cout << "Received signal " << signo << std::endl; + + switch (signo) + { + case SIGINT: + case SIGTERM: + case SIGQUIT: + std::cout << "Stopping services..." << std::endl; + stopServices(); + + // Do not listen for signals, this will make the ioservice.run return + break; + case SIGHUP: + std::cout << "Restarting services..." << std::endl; + + restartServices(); + asyncWaitSignals(); + break; + default: + assert(0); + } +} + diff --git a/main/ServiceManager.hpp b/main/ServiceManager.hpp new file mode 100644 index 00000000..7e1ee48b --- /dev/null +++ b/main/ServiceManager.hpp @@ -0,0 +1,41 @@ +#ifndef SERVICE_CONTROLER_HPP +#define SERVICE_CONTROLER_HPP + +#include +#include + +#include "Service.hpp" + +// Start/Stop/Reload Services +class ServiceManager +{ + public: + + ServiceManager(); + + void stopService(Service::pointer service); + void startService(Service::pointer service); + + // Return in case of failure/stop by user + void run(); + + private: + + void restartServices(void); + void stopServices(void); + + void asyncWaitSignals(void); + + void handleSignal(boost::system::error_code error, int signo); + + boost::asio::io_service _ioService; + + // Listen for interesting signals + boost::asio::signal_set _signalSet; + + std::set _services; +}; + + +#endif + diff --git a/main/WebServerService.cpp b/main/WebServerService.cpp new file mode 100644 index 00000000..adbbaa63 --- /dev/null +++ b/main/WebServerService.cpp @@ -0,0 +1,47 @@ + +#include "WebServerService.hpp" +#include "ui/LmsApplication.hpp" + + +Wt::WApplication *createApplication(const Wt::WEnvironment& env) +{ + /* + * You could read information from the environment to decide whether + * the user has permission to start a new application + */ + return new LmsApplication(env); +} + + +WebServerService::WebServerService( int argc, char* argv[]) +: _server(argv[0]) +{ + + // TODO configure server + _server.setServerConfiguration (argc, argv, WTHTTP_CONFIGURATION); + + // bind entry point + + _server.addEntryPoint(Wt::Application, createApplication); + +} + +void +WebServerService::start(void) +{ + _server.start(); +} + +void +WebServerService::stop(void) +{ + _server.stop(); +} + +void +WebServerService::restart(void) +{ + +} + + diff --git a/main/WebServerService.hpp b/main/WebServerService.hpp new file mode 100644 index 00000000..172efee3 --- /dev/null +++ b/main/WebServerService.hpp @@ -0,0 +1,24 @@ +#ifndef WEB_SERVER_SERVICE_HPP +#define WEB_SERVER_SERVICE_HPP + +#include + +#include "Service.hpp" + +class WebServerService : public Service +{ + public: + WebServerService( int argc, char* argv[]); + + void start(void); + void stop(void); + void restart(void); + + private: + + Wt::WServer _server; + +}; + +#endif + diff --git a/main/main.cpp b/main/main.cpp index 5ffda280..a14912e4 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -1,53 +1,46 @@ -#include - -#include "LmsApplication.hpp" - -#include "metadata/AvFormat.hpp" -#include "metadata/Extractor.hpp" -#include "database/Database.hpp" +#include +#include #include "transcode/AvConvTranscoder.hpp" - #include "av/Common.hpp" -Wt::WApplication *createApplication(const Wt::WEnvironment& env) -{ - /* - * You could read information from the environment to decide whether - * the user has permission to start a new application - */ - return new LmsApplication(env); -} +#include "ServiceManager.hpp" +#include "DatabaseRefreshService.hpp" +#include "WebServerService.hpp" +#include "RemoteServerService.hpp" int main(int argc, char* argv[]) { - Av::AvInit(); - Transcode::AvConvTranscoder::init(); + int res = EXIT_FAILURE; -// std::locale::global(std::locale("")); - MetaData::AvFormat metadataParser; -// MetaData::Extractor metadataParser; + try + { + ServiceManager serviceManager; - // Set up the long living database session - Database database("test.db", metadataParser); + // lib init + Av::AvInit(); + Transcode::AvConvTranscoder::init(); -// database.watchDirectory( WatchedDirectory("/storage/common/Media/Son", WatchedDirectory::Audio )); - database.watchDirectory(WatchedDirectory("/storage/common/Media/Son/Metal", WatchedDirectory::Audio)); -// database.watchDirectory("/storage/common/Media/Son/Metal/Iced Earth/2004 - The Glorious Burden"); -// database.watchDirectory("/storage/common/Media/Son/Metal/System Of a Down"); -// database.watchDirectory("/storage/common/Media/Son/Metal/Leprous"); -// database.watchDirectory("/storage/common/Media/Son/Electro"); -// database.watchDirectory( WatchedDirectory("/storage/common/Media/Son/Electro", WatchedDirectory::Audio) ); -// database.watchDirectory("/storage/common/Media/Son/Metal/Lacuna Coil"); - database.watchDirectory( WatchedDirectory("/storage/common/Media/Video", WatchedDirectory::Video) ); -// database.watchDirectory( WatchedDirectory("/storage/common/Media/Video/Films", WatchedDirectory::Video) ); -// database.watchDirectory( WatchedDirectory("/storage/common/Media/Video/Series", WatchedDirectory::Video) ); + serviceManager.startService( std::make_shared( "test.db" ) ); + serviceManager.startService( std::make_shared(argc, argv) ); + serviceManager.startService( std::make_shared( Remote::Server::Server::endpoint_type() ) ); - std::cout << "Starting refresh..." << std::endl; -// boost::thread refreshThread(boost::bind(&Database::refresh, &database)); + serviceManager.run(); + res = EXIT_SUCCESS; - return Wt::WRun(argc, argv, &createApplication); + } + catch( Wt::WServer::Exception& e) + { + std::cerr << "Caught WServer::Exception: " << e.what() << std::endl; + + } + catch( std::exception& e) + { + std::cerr << "Caught std::exception: " << e.what() << std::endl; + } + + return res; } diff --git a/remote/server/Header.hpp b/remote/messages/Header.hpp similarity index 71% rename from remote/server/Header.hpp rename to remote/messages/Header.hpp index da68b0f9..1aadf1c0 100644 --- a/remote/server/Header.hpp +++ b/remote/messages/Header.hpp @@ -7,10 +7,10 @@ namespace Remote class Header { - static const std::size_t size = 8; - -} + public: + static const std::size_t size = 8; +}; diff --git a/remote/server/.Connection.hpp.swp b/remote/server/.Connection.hpp.swp deleted file mode 100644 index 99b89596a132145056b95c8572b06dbb1008316a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2O>Z1E7{?tXXa`6^<;sgmq$o(C)0Rqal$OxI8>gD-8d38ok0jI!S73iDpv*#ztb7#+-wzkt#Pt(UvzJAwX z&cG?)6mSYS1)Ks-0jGddz$xGq`2Q$i@(J=jmUCaVr1k1PF?O#W-OVZB6mSYS1)Ks- z0jGddz$xGqa0)mDoB~dP|DXaaCgh`Ig#30K!Q=n`_22(LKSId2;1;+JJ^>$t55QX> z1ZTk+@Hn_1{BnYj@41NyuN|Huw|V0^fjZ;39YuJOOS$jDBz( zd-aLJa8QR z=n?WYxC!>aF4zGtf&jb#&Vwm%0!)HGpxy7lYWSzqZL_KeBL+scEASku*c;(6M{LBNz^ zgN1&k#dgMH8ugf(qbr=nTm^v^@9;%0>=lnM_q$!L=JD%^?|F*n$$%E0q4nis?skut zE!0Tb;Z*a?&<=|(+h>E$C=qBnReN~5&$S72rVtheHXlcPRu)~U3NIpyWGb@lddR51 zx^=|EAwz7)w7v1l2JLHvY7}Q_r&uA*gL>X(8O{pJ;)JUi8jdzJm)t9Dte@DfG*>d> zS|1v#MzEeYJSe)xGPYg#KhV~kA}!5mDS^;58Xh&Z4m(n6gIsDMgFxg#U?O~I8C~Xv zhULBXw^g>*YL0o@ks_w$iY_Q&_$>N0vRF=_2iov72)I&Gg^`T;4CT+%o=dS1Tbd`_ z9)qQ_OBvm@eyGg3V#V258*sJx?EVVjePFl_jbfR`4pTfXTsA`4#0I>FNao<#Zp1qT zf)vNiIJ{hm9cFl7BPwRoM&`5o>)FB+Wl2Jr9%NBZ$xQb3(1Aufq!sWG(_LYDiQFxL15th`5dZ^8|*x^}YT=6oPLC#~|#Vd$vq)~o&9OgzX z441t~b15=Y)E+PIcM=f=m)p^e0G&gL(>y_VK`)QuC~o2 zs!Bev15n?5h?6UB3mCFYHL6Y0Oa!&g>>}%eHXci*HnK1*$Yt@RR~k*WMx%jDqd+D7 znA54zGHB0{Pc?c+Q#RgPjXl_mQe8F>S9w$T;0xUfXCdkAJC6i*9B&$Kk#I06k5xga7~l diff --git a/remote/server/Connection.cpp b/remote/server/Connection.cpp index 5af03cbb..c817c3d8 100644 --- a/remote/server/Connection.cpp +++ b/remote/server/Connection.cpp @@ -1,4 +1,5 @@ +#include #include #include @@ -10,10 +11,12 @@ namespace Remote { namespace Server { -Connection::Connection(boost::asio::io_service& ioService, Connection_manager& manager, RequestHandler& handler) -: _socket(ioService), +Connection::Connection(boost::asio::ip::tcp::socket socket, + ConnectionManager& manager, + RequestHandler& handler) +: _socket(std::move(socket)), _connectionManager(manager), -request_handler_(handler) +_requestHandler(handler) { } @@ -58,16 +61,16 @@ Connection::handleRead(const boost::system::error_code& error, std::size_t bytes } } -void Connection::handleWrite(const boost::system::error_code& e) +void Connection::handleWrite(const boost::system::error_code& error) { - if (!e) + if (!error) { // Initiate graceful Connection closure. boost::system::error_code ignored_ec; _socket.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored_ec); } - if (e != boost::asio::error::operation_aborted) + if (error != boost::asio::error::operation_aborted) { std::cerr << "Connection::handleWrite: " << error.message() << std::endl; _connectionManager.stop(shared_from_this()); diff --git a/remote/server/Connection.hpp b/remote/server/Connection.hpp index d45134e9..552633dd 100644 --- a/remote/server/Connection.hpp +++ b/remote/server/Connection.hpp @@ -1,33 +1,33 @@ #ifndef REMOTE_CONNECTION_HPP #define REMOTE_CONNECTION_HPP +#include #include -#include #include -#include -#include - -#include "reply.hpp" -#include "request.hpp" #include "RequestHandler.hpp" -#include "request_parser.hpp" -namespace http { -namespace server { +#include "messages/Header.hpp" + +namespace Remote { + +namespace Server { class ConnectionManager; /// Represents a single connection from a client. -class Connection : public boost::enable_shared_from_this, boost::noncopyable +class Connection : public std::enable_shared_from_this { public: - typedef std::shared_ptr pointer; + Connection(const Connection&) = delete; + Connection& operator=(const Connection&) = delete; + + typedef std::shared_ptr pointer; /// Construct a connection with the given io_service. - Connection(boost::asio::io_service& io_service, + explicit Connection(boost::asio::ip::tcp::socket socket, ConnectionManager& manager, RequestHandler& handler); boost::asio::ip::tcp::socket& socket(); @@ -50,10 +50,10 @@ class Connection : public boost::enable_shared_from_this, boost::non boost::asio::ip::tcp::socket _socket; /// The manager for this connection. - ConnectionManager& _ConnectionManager; + ConnectionManager& _connectionManager; /// The handler used to process the incoming requests. - RequestHandler& _RequestHandler; + RequestHandler& _requestHandler; // TODO use streambuffers @@ -70,9 +70,10 @@ class Connection : public boost::enable_shared_from_this, boost::non }; -} // namespace server -} // namespace http +} // namespace Server -#endif // HTTP_CONNECTION_HPP +} // namespace Remote + +#endif diff --git a/remote/server/ConnectionManager.cpp b/remote/server/ConnectionManager.cpp index e6a8ffd7..fd1b599f 100644 --- a/remote/server/ConnectionManager.cpp +++ b/remote/server/ConnectionManager.cpp @@ -1,6 +1,6 @@ - #include -#include + +#include #include "ConnectionManager.hpp" @@ -8,24 +8,29 @@ namespace Remote { namespace Server { +ConnectionManager::ConnectionManager() +{ +} + + void -ConnectionManager::start(connection::pointer c) +ConnectionManager::start(Connection::pointer c) { _connections.insert(c); c->start(); } void -ConnectionManager::stop(connection::pointer c) +ConnectionManager::stop(Connection::pointer c) { _connections.erase(c); c->stop(); } void -ConnectionManager::stop_all() +ConnectionManager::stopAll() { - BOOST_FOREACH(connection::pointer c, _connections) + BOOST_FOREACH(Connection::pointer c, _connections) { c->stop(); } diff --git a/remote/server/ConnectionManager.hpp b/remote/server/ConnectionManager.hpp index 1624639f..9579aa01 100644 --- a/remote/server/ConnectionManager.hpp +++ b/remote/server/ConnectionManager.hpp @@ -3,9 +3,7 @@ #include -#include - -#include "connection.hpp" +#include "Connection.hpp" namespace Remote { @@ -14,21 +12,26 @@ namespace Server { /// Manages open connections so that they may be cleanly stopped when the server /// needs to shut down. -class ConnectionManager : boost::noncopyable +class ConnectionManager { public: + ConnectionManager(const ConnectionManager&) = delete; + ConnectionManager& operator=(const ConnectionManager&) = delete; + + ConnectionManager(); + /// Add the specified connection to the manager and start it. - void start(connection::pointer c); + void start(Connection::pointer c); /// Stop the specified connection. - void stop(connection::pointer c); + void stop(Connection::pointer c); /// Stop all connections. - void stop_all(); + void stopAll(); private: /// The managed connections. - std::set _connections; + std::set _connections; }; } // namespace Server diff --git a/remote/server/RequestHandler.hpp b/remote/server/RequestHandler.hpp index c4d54963..f111f325 100644 --- a/remote/server/RequestHandler.hpp +++ b/remote/server/RequestHandler.hpp @@ -1,14 +1,16 @@ #ifndef REMOTE_REQUEST_HANDLER #define REMOTE_REQUEST_HANDLER - +// #include "remote/messages/ class RequestHandler { + public: + private: }; diff --git a/remote/server/Server.cpp b/remote/server/Server.cpp index 2f600b73..6920988c 100644 --- a/remote/server/Server.cpp +++ b/remote/server/Server.cpp @@ -9,18 +9,17 @@ namespace Remote { namespace Server { -server::server(boost::asio::io_service& ioService, const endpoint_type& endpoint) -: _ioService(ioService), +Server::Server(const endpoint_type& endpoint) +: _acceptor(_ioService), _connectionManager(), -_socket(io_service_), -_requestHandler(doc_root) +_socket(_ioService) { // Open the acceptor with the option to reuse the address (i.e. SO_REUSEADDR). boost::asio::ip::tcp::resolver resolver(_ioService); - boost::asio::ip::tcp::endpoint endpoint = *resolver.resolve(endpoint); + boost::asio::ip::tcp::endpoint resolvedEndpoint = *resolver.resolve(endpoint); - _acceptor.open(endpoint.protocol()); + _acceptor.open(resolvedEndpoint.protocol()); _acceptor.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true)); _acceptor.bind(endpoint); _acceptor.listen(); @@ -33,11 +32,11 @@ Server::run() // While the server is running, there is always at least one // asynchronous operation outstanding: the asynchronous accept call waiting // for new incoming connections. - async_accept(); + asyncAccept(); } void -Server::async_accept() +Server::asyncAccept() { _acceptor.async_accept(_socket, boost::bind(&Server::handleAccept, this, boost::asio::placeholders::error)); } @@ -54,9 +53,9 @@ Server::handleAccept(boost::system::error_code ec) if (!ec) { - _connectionManager.start(std::make_shared(std::move(_socket), _connectionManager, _requestHandler)); + _connectionManager.start(std::make_shared(std::move(_socket), _connectionManager, _requestHandler)); - async_accept(); + asyncAccept(); } else std::cerr << "handleAccept: " << ec.message() << std::endl; @@ -69,7 +68,7 @@ Server::stop() // The server is stopped by cancelling all outstanding asynchronous // operations. _acceptor.close(); - _connectionManager.stop_all(); + _connectionManager.stopAll(); } } // namespace Server diff --git a/remote/server/Server.hpp b/remote/server/Server.hpp index 2939112b..9cd76605 100644 --- a/remote/server/Server.hpp +++ b/remote/server/Server.hpp @@ -3,8 +3,6 @@ #include -#include - #include "Connection.hpp" #include "ConnectionManager.hpp" @@ -18,11 +16,13 @@ class Server { public: - typedef std::string endpoint_type; + Server(const Server&) = delete; + Server& operator=(const Server&) = delete; + + typedef boost::asio::ip::tcp::endpoint endpoint_type; // Serve up data from the given database - Server(boost::asio::io_service& ioService, - const endpoint_type& endpoint); + Server(const endpoint_type& endpoint); // Run the server's io_service loop. void run(); @@ -34,13 +34,13 @@ class Server void asyncAccept(); void handleAccept(boost::system::error_code ec); - boost::asio::io_service& _ioService; + boost::asio::io_service _ioService; /// Acceptor used to listen for incoming connections. boost::asio::ip::tcp::acceptor _acceptor; /// The connection manager which owns all live connections. - connection_manager _connectionManager; + ConnectionManager _connectionManager; /// The next socket to be accepted. boost::asio::ip::tcp::socket _socket; diff --git a/main/LmsApplication.cpp b/ui/LmsApplication.cpp similarity index 100% rename from main/LmsApplication.cpp rename to ui/LmsApplication.cpp diff --git a/main/LmsApplication.hpp b/ui/LmsApplication.hpp similarity index 100% rename from main/LmsApplication.hpp rename to ui/LmsApplication.hpp