WIP. Adding config file handling. UserInterface settings implemented

This commit is contained in:
emeric
2014-08-21 15:24:23 +02:00
parent 2f376fbc7a
commit e8b2412cd6
16 changed files with 211 additions and 23 deletions
+4
View File
@@ -2,6 +2,8 @@
#include "DatabaseUpdateService.hpp"
namespace Service {
DatabaseUpdateService::DatabaseUpdateService(const boost::filesystem::path& p)
: _metadataParser(),
_databaseUpdater( p, _metadataParser)
@@ -30,3 +32,5 @@ DatabaseUpdateService::restart(void)
start();
}
} // namespace Service
+4
View File
@@ -9,6 +9,8 @@
#include "Service.hpp"
namespace Service {
class DatabaseUpdateService : public Service
{
public:
@@ -28,5 +30,7 @@ class DatabaseUpdateService : public Service
DatabaseUpdater::Updater _databaseUpdater; // Todo use handler
};
} // namespace Service
#endif
+4
View File
@@ -1,6 +1,8 @@
#include "RemoteServerService.hpp"
namespace Service {
RemoteServerService::RemoteServerService(const Remote::Server::Server::endpoint_type& endpoint, boost::filesystem::path dbPath)
: _server(endpoint, dbPath)
{
@@ -28,3 +30,5 @@ RemoteServerService::restart(void)
{
std::cout << "RemoteServerService::restart, not implemented!" << std::endl;
}
} // namespace Service
+4
View File
@@ -7,6 +7,8 @@
#include "remote/server/Server.hpp"
namespace Service {
class RemoteServerService : public Service
{
public:
@@ -22,4 +24,6 @@ class RemoteServerService : public Service
Remote::Server::Server _server;
};
} // namespace Service
#endif
+4
View File
@@ -5,6 +5,8 @@
#include <memory>
#include <set>
namespace Service {
// Interface class wrapper for running services
class Service
{
@@ -24,5 +26,7 @@ class Service
};
} // namespace Service
#endif
+4 -2
View File
@@ -1,11 +1,11 @@
//#include <csignal>
#include <boost/foreach.hpp>
#include <boost/bind.hpp>
#include "ServiceManager.hpp"
namespace Service {
ServiceManager&
ServiceManager::instance()
{
@@ -122,3 +122,5 @@ ServiceManager::handleSignal(boost::system::error_code /*ec*/, int signo)
}
}
} // namespace Service
+4
View File
@@ -6,6 +6,8 @@
#include "Service.hpp"
namespace Service {
// Start/Stop/Reload Services
class ServiceManager
{
@@ -63,5 +65,7 @@ ServiceManager::getService()
return std::shared_ptr<T>();
}
} // namespace Service
#endif
+33 -6
View File
@@ -1,17 +1,43 @@
#include <iostream>
#include <iomanip>
#include "UserInterfaceService.hpp"
#include "ui/LmsApplication.hpp"
UserInterfaceService::UserInterfaceService( int argc, char* argv[], boost::filesystem::path dbPath)
: _server(argv[0], "")
namespace Service {
UserInterfaceService::UserInterfaceService( boost::filesystem::path runAppPath, const Config& config)
: _server(runAppPath.string())
{
// TODO configure server using another way (config file?)
_server.setServerConfiguration (argc, argv, WTHTTP_CONFIGURATION);
std::vector<std::string> args;
args.push_back(runAppPath.string());
args.push_back("--docroot=" + config.docRootPath.string());
args.push_back("--approot=" + config.appRootPath.string());
{
std::ostringstream oss; oss << config.httpsPort;
args.push_back("--https-port=" + oss.str());
}
args.push_back("--https-address=" + config.httpsAddress.to_string());
args.push_back("--ssl-certificate=" + config.sslCertificatePath.string());
args.push_back("--ssl-private-key=" + config.sslPrivateKeyPath.string());
args.push_back("--ssl-tmp-dh=" + config.sslTempDhPath.string());
// Construct argc/argv
int argc = args.size();
const char* argv[args.size()];
for (int i = 0; i < argc; ++i)
argv[i] = args[i].c_str();
for(int i = 0; i < argc; ++i)
{
std::cout << "i = " << i << ", arg = '" << argv[i] << "'" << std::endl;
}
_server.setServerConfiguration (argc, const_cast<char**>(argv));
// bind entry point
_server.addEntryPoint(Wt::Application, boost::bind(UserInterface::LmsApplication::create, _1, dbPath));
_server.addEntryPoint(Wt::Application, boost::bind(UserInterface::LmsApplication::create, _1, config.dbPath));
}
void
@@ -35,4 +61,5 @@ UserInterfaceService::restart(void)
}
} // namespace Service
+20 -1
View File
@@ -2,15 +2,32 @@
#define WEB_SERVER_SERVICE_HPP
#include <boost/filesystem.hpp>
#include <boost/asio/ip/address.hpp>
#include <Wt/WServer>
#include "Service.hpp"
namespace Service {
class UserInterfaceService : public Service
{
public:
UserInterfaceService( int argc, char* argv[], boost::filesystem::path dbPath);
struct Config {
bool enable;
boost::filesystem::path docRootPath;
boost::filesystem::path appRootPath;
unsigned short httpsPort;
boost::asio::ip::address httpsAddress;
boost::filesystem::path sslCertificatePath;
boost::filesystem::path sslPrivateKeyPath;
boost::filesystem::path sslTempDhPath;
boost::filesystem::path dbPath;
};
UserInterfaceService(boost::filesystem::path runAppPath,
const Config& config);
void start(void);
void stop(void);
@@ -22,5 +39,7 @@ class UserInterfaceService : public Service
};
} //namespace Service
#endif