85 lines
1.8 KiB
C++
85 lines
1.8 KiB
C++
#include "TwitterPlugin.h"
|
|
DEFINE_LOGGER(logger, "Twitter Backend");
|
|
|
|
static void spectrum_sigchld_handler(int sig)
|
|
{
|
|
int status;
|
|
pid_t pid;
|
|
|
|
do {
|
|
pid = waitpid(-1, &status, WNOHANG);
|
|
} while (pid != 0 && pid != (pid_t)-1);
|
|
|
|
if ((pid == (pid_t) - 1) && (errno != ECHILD)) {
|
|
char errmsg[BUFSIZ];
|
|
snprintf(errmsg, BUFSIZ, "Warning: waitpid() returned %d", pid);
|
|
perror(errmsg);
|
|
}
|
|
}
|
|
|
|
|
|
int main (int argc, char* argv[]) {
|
|
std::string host;
|
|
int port;
|
|
|
|
if (signal(SIGCHLD, spectrum_sigchld_handler) == SIG_ERR) {
|
|
std::cout << "SIGCHLD 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()
|
|
("host,h", value<std::string>(&host), "host")
|
|
("port,p", value<int>(&port), "port")
|
|
;
|
|
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);
|
|
}
|
|
catch (std::runtime_error& e)
|
|
{
|
|
std::cout << desc << "\n";
|
|
exit(1);
|
|
}
|
|
catch (...)
|
|
{
|
|
std::cout << desc << "\n";
|
|
exit(1);
|
|
}
|
|
|
|
|
|
if (argc < 5) {
|
|
return 1;
|
|
}
|
|
|
|
Config config;
|
|
if (!config.load(argv[5])) {
|
|
std::cerr << "Can't open " << argv[1] << " configuration file.\n";
|
|
return 1;
|
|
}
|
|
|
|
Logging::initBackendLogging(&config);
|
|
|
|
std::string error;
|
|
StorageBackend *storagebackend;
|
|
|
|
storagebackend = StorageBackend::createBackend(&config, error);
|
|
if (storagebackend == NULL) {
|
|
LOG4CXX_ERROR(logger, "Error creating StorageBackend! " << error)
|
|
return -2;
|
|
}
|
|
|
|
else if (!storagebackend->connect()) {
|
|
LOG4CXX_ERROR(logger, "Can't connect to database!")
|
|
return -1;
|
|
}
|
|
|
|
Swift::SimpleEventLoop eventLoop;
|
|
loop_ = &eventLoop;
|
|
np = new TwitterPlugin(&config, &eventLoop, storagebackend, host, port);
|
|
loop_->run();
|
|
|
|
return 0;
|
|
}
|