76 lines
2.2 KiB
C++
76 lines
2.2 KiB
C++
#include "CCServer.h"
|
|
|
|
#include "LicenseClient.h"
|
|
#include "SystemParamsProvider.h"
|
|
|
|
#include <boost/program_options.hpp>
|
|
#include <boost/asio/signal_set.hpp>
|
|
#include <iostream>
|
|
#include <memory>
|
|
#include <chrono>
|
|
#include <thread>
|
|
|
|
namespace po = boost::program_options;
|
|
namespace net = boost::asio; // from <boost/asio.hpp>
|
|
|
|
volatile bool signalCaught = false;
|
|
|
|
void signalHandler(int signum) {
|
|
std::cout << "Interrupt signal (" << signum << ") received.\n";
|
|
|
|
signalCaught = true;
|
|
}
|
|
|
|
int main(int argc, const char* argv[])
|
|
{
|
|
// Declare the supported options.
|
|
po::options_description desc("Allowed options");
|
|
desc.add_options()
|
|
("help", "produce help message")
|
|
("bind_ip", po::value<std::string>()->default_value("0.0.0.0"), "ip address to listen for connections")
|
|
("port", po::value<uint16_t>()->default_value(8080), "port")
|
|
("data_root", po::value<std::string>()->default_value("."), "root directory with data")
|
|
("threads", po::value<int>()->default_value(4), "port")
|
|
;
|
|
|
|
po::variables_map vm;
|
|
po::store(po::parse_command_line(argc, argv, desc), vm);
|
|
po::notify(vm);
|
|
|
|
if (vm.count("help")) {
|
|
std::cout << desc << "\n";
|
|
return 1;
|
|
}
|
|
|
|
SystemParamsProvider systemParamsProvider;
|
|
LicenseClient licenseClient(systemParamsProvider, "license.dat");
|
|
licenseClient.init();
|
|
|
|
if (!licenseClient.isActivated()) {
|
|
std::cerr << "Application is not activated. Please contact Catalogue of Currencies support. Exiting..." << std::endl;
|
|
std::cout << "Activation request: " << licenseClient.buildActivationRequest() << std::endl;
|
|
return -2;
|
|
}
|
|
|
|
if (vm.count("port")) {
|
|
std::cout << "Port "
|
|
<< vm["port"].as<uint16_t>() << ".\n";
|
|
}
|
|
|
|
auto addressToListen = vm["bind_ip"].as<std::string>();
|
|
auto portToListen = vm["port"].as<uint16_t>();
|
|
auto docRoot = vm["data_root"].as<std::string>();
|
|
auto threads = vm["threads"].as<int>();
|
|
|
|
|
|
auto ccServer = std::make_unique<CCServer>(addressToListen, portToListen, docRoot, threads);
|
|
ccServer->run();
|
|
while (!signalCaught)
|
|
{
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
|
}
|
|
ccServer->shutdown();
|
|
|
|
return 0;
|
|
}
|