Files
        @ e9e2991f8e18
    
        
              Branch filter: 
        
    Location: libtransport.git/spectrum/src/main.cpp
        
            
            e9e2991f8e18
            2.8 KiB
            text/x-c++hdr
        
        
    
    collectBackend called every hour
    | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | #include "transport/config.h"
#include "transport/transport.h"
#include "transport/usermanager.h"
#include "transport/logger.h"
#include "transport/sqlite3backend.h"
#include "transport/userregistration.h"
#include "transport/networkpluginserver.h"
#include "transport/admininterface.h"
#include "Swiften/EventLoop/SimpleEventLoop.h"
#include "sys/signal.h"
using namespace Transport;
Swift::SimpleEventLoop *eventLoop_ = NULL;
static void spectrum_sigint_handler(int sig) {
	eventLoop_->stop();
}
static void spectrum_sigterm_handler(int sig) {
	eventLoop_->stop();
}
int main(int argc, char **argv)
{
	Config config;
	if (signal(SIGINT, spectrum_sigint_handler) == SIG_ERR) {
		std::cout << "SIGINT handler can't be set\n";
		return -1;
	}
	if (signal(SIGTERM, spectrum_sigterm_handler) == SIG_ERR) {
		std::cout << "SIGTERM handler can't be set\n";
		return -1;
	}
	boost::program_options::options_description desc("Usage: spectrum [OPTIONS] <config_file.cfg>\nAllowed options");
	desc.add_options()
		("help,h", "help")
		("no-daemonize,n", "Do not run spectrum as daemon")
		;
	try
	{
		boost::program_options::variables_map vm;
		boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
		boost::program_options::notify(vm);
		if(vm.count("help"))
		{
			std::cout << desc << "\n";
			return 1;
		}
	}
	catch (std::runtime_error& e)
	{
		std::cout << desc << "\n";
		return 1;
	}
	catch (...)
	{
		std::cout << desc << "\n";
		return 1;
	}
	if (argc != 2) {
		std::cout << desc << "\n";
		return 1;
	}
	if (!config.load(argv[1])) {
		std::cerr << "Can't load configuration file.\n";
		return 1;
	}
	UserRegistry userRegistry(&config);
	Swift::SimpleEventLoop eventLoop;
	Component transport(&eventLoop, &config, NULL, &userRegistry);
// 	Logger logger(&transport);
	StorageBackend *storageBackend = NULL;
	if (CONFIG_STRING(&config, "database.type") == "sqlite3") {
		storageBackend = new SQLite3Backend(&config);
// 		logger.setStorageBackend(storageBackend);
		if (!storageBackend->connect()) {
			std::cerr << "Can't connect to database.\n";
		}
	}
	UserManager userManager(&transport, &userRegistry, storageBackend);
	UserRegistration *userRegistration = NULL;
	if (storageBackend) {
		userRegistration = new UserRegistration(&transport, &userManager, storageBackend);
		userRegistration->start();
// 		logger.setUserRegistration(&userRegistration);
	}
// 	logger.setUserManager(&userManager);
	NetworkPluginServer plugin(&transport, &config, &userManager);
	AdminInterface adminInterface(&transport, &userManager, &plugin, storageBackend);
	eventLoop_ = &eventLoop;
	eventLoop.run();
	if (userRegistration) {
		userRegistration->stop();
		delete userRegistration;
	}
	delete storageBackend;
}
 |