2012-06-03 22:34:33 +05:30
|
|
|
#include "TwitterPlugin.h"
|
2012-05-24 01:40:17 +05:30
|
|
|
DEFINE_LOGGER(logger, "Twitter Backend");
|
|
|
|
|
2012-11-28 10:02:27 +04:00
|
|
|
#ifndef _WIN32
|
2012-05-24 01:40:17 +05:30
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 10:02:27 +04:00
|
|
|
#endif
|
2012-05-24 01:40:17 +05:30
|
|
|
|
|
|
|
|
|
|
|
int main (int argc, char* argv[]) {
|
|
|
|
std::string host;
|
|
|
|
int port;
|
2012-11-28 10:02:27 +04:00
|
|
|
#ifndef _WIN32
|
2012-05-24 01:40:17 +05:30
|
|
|
if (signal(SIGCHLD, spectrum_sigchld_handler) == SIG_ERR) {
|
|
|
|
std::cout << "SIGCHLD handler can't be set\n";
|
|
|
|
return -1;
|
|
|
|
}
|
2012-11-28 10:02:27 +04:00
|
|
|
#endif
|
2012-05-24 01:40:17 +05:30
|
|
|
|
2012-10-22 12:26:44 +02:00
|
|
|
std::string error;
|
|
|
|
Config *cfg = Config::createFromArgs(argc, argv, error, host, port);
|
|
|
|
if (cfg == NULL) {
|
|
|
|
std::cerr << error;
|
2012-05-24 01:40:17 +05:30
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-10-22 12:26:44 +02:00
|
|
|
Logging::initBackendLogging(cfg);
|
2012-05-24 01:40:17 +05:30
|
|
|
|
2012-06-03 22:34:33 +05:30
|
|
|
StorageBackend *storagebackend;
|
2012-10-22 12:26:44 +02:00
|
|
|
storagebackend = StorageBackend::createBackend(cfg, error);
|
2012-05-27 22:55:23 +05:30
|
|
|
if (storagebackend == NULL) {
|
2012-11-27 10:33:04 +01:00
|
|
|
LOG4CXX_ERROR(logger, "Error creating StorageBackend! " << error);
|
|
|
|
LOG4CXX_ERROR(logger, "Twitter backend needs storage backend configured to work! " << error);
|
2012-11-27 10:50:49 +01:00
|
|
|
return NetworkPlugin::StorageBackendNeeded;
|
2012-05-27 21:26:51 +05:30
|
|
|
}
|
|
|
|
|
2012-05-27 22:55:23 +05:30
|
|
|
else if (!storagebackend->connect()) {
|
2017-06-12 00:41:35 +02:00
|
|
|
LOG4CXX_ERROR(logger, "Can't connect to database!");
|
2012-05-27 21:26:51 +05:30
|
|
|
return -1;
|
|
|
|
}
|
2012-05-24 01:40:17 +05:30
|
|
|
|
|
|
|
Swift::SimpleEventLoop eventLoop;
|
|
|
|
loop_ = &eventLoop;
|
2012-10-22 12:26:44 +02:00
|
|
|
np = new TwitterPlugin(cfg, &eventLoop, storagebackend, host, port);
|
2012-05-24 01:40:17 +05:30
|
|
|
loop_->run();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|