diff --git a/backends/twitter/main.cpp b/backends/twitter/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cf387fd7e878cacf920c492bd852b10c0c8a4bf5 --- /dev/null +++ b/backends/twitter/main.cpp @@ -0,0 +1,85 @@ +#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] \nAllowed options"); + desc.add_options() + ("host,h", value(&host), "host") + ("port,p", value(&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; +}