WIP: adding service files, still not working
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
|
||||
#include <Wt/WContainerWidget>
|
||||
#include <Wt/WBreak>
|
||||
#include <Wt/WLabel>
|
||||
#include <Wt/WBootstrapTheme>
|
||||
#include <Wt/WStackedWidget>
|
||||
#include <Wt/WMenu>
|
||||
#include <Wt/WNavigationBar>
|
||||
#include <Wt/WPopupMenu>
|
||||
#include <Wt/WPopupMenuItem>
|
||||
|
||||
#include "LmsApplication.hpp"
|
||||
|
||||
|
||||
/*
|
||||
* The env argument contains information about the new session, and
|
||||
* the initial request. It must be passed to the Wt::WApplication
|
||||
* constructor so it is typically also an argument for your custom
|
||||
* application constructor.
|
||||
*/
|
||||
LmsApplication::LmsApplication(const Wt::WEnvironment& env)
|
||||
: Wt::WApplication(env)
|
||||
{
|
||||
|
||||
setTheme(new Wt::WBootstrapTheme());
|
||||
|
||||
setTitle("LMS"); // application title
|
||||
|
||||
Wt::WContainerWidget* container (new Wt::WContainerWidget(root()));
|
||||
|
||||
// Create a navigation bar with a link to a web page.
|
||||
Wt::WNavigationBar *navigation = new Wt::WNavigationBar(container);
|
||||
navigation->setTitle("LMS");
|
||||
navigation->setResponsive(true);
|
||||
|
||||
Wt::WStackedWidget *contentsStack = new Wt::WStackedWidget(container);
|
||||
contentsStack->addStyleClass("contents");
|
||||
|
||||
// Setup a Left-aligned menu.
|
||||
Wt::WMenu *leftMenu = new Wt::WMenu(contentsStack, container);
|
||||
navigation->addMenu(leftMenu);
|
||||
|
||||
_audioWidget = new AudioWidget();
|
||||
_videoWidget = new VideoWidget();
|
||||
|
||||
leftMenu->addItem("Audio", _audioWidget);
|
||||
leftMenu->addItem("Video", _videoWidget);
|
||||
|
||||
// Setup a Right-aligned menu.
|
||||
Wt::WMenu *rightMenu = new Wt::WMenu();
|
||||
navigation->addMenu(rightMenu, Wt::AlignRight);
|
||||
|
||||
Wt::WPopupMenu *popup = new Wt::WPopupMenu();
|
||||
popup->addItem("Parameters");
|
||||
popup->addSeparator();
|
||||
popup->addItem("Logout");
|
||||
|
||||
Wt::WMenuItem *item = new Wt::WMenuItem("User");
|
||||
item->setMenu(popup);
|
||||
rightMenu->addItem(item);
|
||||
|
||||
// Add a Search control.
|
||||
_searchEdit = new Wt::WLineEdit();
|
||||
_searchEdit->setEmptyText("Search...");
|
||||
|
||||
_searchEdit->keyWentUp().connect(this, &LmsApplication::handleSearch);
|
||||
|
||||
navigation->addSearch(_searchEdit, Wt::AlignLeft);
|
||||
|
||||
container->addWidget(contentsStack);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
LmsApplication::handleSearch(void)
|
||||
{
|
||||
// Check currently selected menu item and search it
|
||||
_audioWidget->search( _searchEdit->text().toUTF8() );
|
||||
}
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
|
||||
#include <Wt/WApplication>
|
||||
#include <Wt/WLineEdit>
|
||||
|
||||
#include "audio/AudioWidget.hpp"
|
||||
#include "video/VideoWidget.hpp"
|
||||
|
||||
class LmsApplication : public Wt::WApplication
|
||||
{
|
||||
public:
|
||||
|
||||
LmsApplication(const Wt::WEnvironment& env);
|
||||
|
||||
private:
|
||||
|
||||
void handleSearch();
|
||||
|
||||
Wt::WLineEdit* _searchEdit;
|
||||
AudioWidget* _audioWidget;
|
||||
VideoWidget* _videoWidget;
|
||||
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
@@ -0,0 +1,29 @@
|
||||
#ifndef SERVICE_HPP
|
||||
#define SERVICE_HPP
|
||||
|
||||
#include <memory>
|
||||
#include <set>
|
||||
|
||||
// Interface class wrapper for running services
|
||||
class Service
|
||||
{
|
||||
public:
|
||||
|
||||
typedef std::shared_ptr<Service> 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
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
|
||||
#include <csignal>
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
#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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
#ifndef SERVICE_CONTROLER_HPP
|
||||
#define SERVICE_CONTROLER_HPP
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
#include <set>
|
||||
|
||||
#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<Service::pointer> _services;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
#ifndef WEB_SERVER_SERVICE_HPP
|
||||
#define WEB_SERVER_SERVICE_HPP
|
||||
|
||||
#include <Wt/WServer>
|
||||
|
||||
#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
|
||||
|
||||
+30
-37
@@ -1,53 +1,46 @@
|
||||
#include <boost/thread.hpp>
|
||||
|
||||
#include "LmsApplication.hpp"
|
||||
|
||||
#include "metadata/AvFormat.hpp"
|
||||
#include "metadata/Extractor.hpp"
|
||||
#include "database/Database.hpp"
|
||||
#include <memory>
|
||||
#include <Wt/WServer>
|
||||
|
||||
#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<DatabaseRefreshService>( "test.db" ) );
|
||||
serviceManager.startService( std::make_shared<WebServerService>(argc, argv) );
|
||||
serviceManager.startService( std::make_shared<RemoteServerService>( 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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user