2015-10-09 07:24:12 +08:00
|
|
|
#include <iostream>
|
|
|
|
#include <vector>
|
|
|
|
|
2015-10-12 02:59:27 +08:00
|
|
|
#include "debug/log.hpp"
|
|
|
|
#include "utils/ioc/container.hpp"
|
|
|
|
|
|
|
|
#include "database/db.hpp"
|
|
|
|
|
2015-10-09 07:24:12 +08:00
|
|
|
#include "speedy/speedy.hpp"
|
|
|
|
#include "api/resources/include.hpp"
|
|
|
|
|
2015-10-12 02:59:27 +08:00
|
|
|
#include "threading/pool.hpp"
|
|
|
|
#include "threading/task.hpp"
|
2015-10-09 07:24:12 +08:00
|
|
|
|
2015-11-22 03:34:10 +08:00
|
|
|
#include <execinfo.h>
|
|
|
|
|
|
|
|
// TODO: move to separate header or source file
|
|
|
|
// TODO: log to local file or remote database
|
|
|
|
void stacktrace() noexcept
|
|
|
|
{
|
|
|
|
void *array[50];
|
|
|
|
int size = backtrace(array, 50);
|
|
|
|
std::cout << __FUNCTION__ << " backtrace returned " << size << " frames\n\n";
|
|
|
|
char **messages = backtrace_symbols(array, size);
|
|
|
|
for (int i = 0; i < size && messages != NULL; ++i) {
|
|
|
|
std::cout << "[bt]: (" << i << ") " << messages[i] << std::endl;
|
|
|
|
}
|
|
|
|
std::cout << std::endl;
|
|
|
|
free(messages);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: log to local file or remote database
|
|
|
|
void on_terminate() noexcept
|
|
|
|
{
|
|
|
|
if (auto exc = std::current_exception()) {
|
|
|
|
try {
|
|
|
|
std::rethrow_exception(exc);
|
|
|
|
} catch (std::exception &ex) {
|
|
|
|
std::cout << ex.what() << std::endl << std::endl;
|
|
|
|
stacktrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::_Exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2015-10-12 02:59:27 +08:00
|
|
|
int main()
|
2015-10-09 07:24:12 +08:00
|
|
|
{
|
2015-11-22 03:34:10 +08:00
|
|
|
std::set_terminate(&on_terminate);
|
|
|
|
|
2015-10-12 02:59:27 +08:00
|
|
|
ioc::Container container;
|
|
|
|
|
|
|
|
container.singleton<Db>();
|
|
|
|
|
|
|
|
auto loop = container.singleton<uv::UvLoop>();
|
|
|
|
auto app = container.singleton<sp::Speedy, uv::UvLoop>("/db/data");
|
|
|
|
|
|
|
|
container.singleton<Pool>(4);
|
|
|
|
container.singleton<Task, uv::UvLoop, Pool>();
|
2015-10-09 07:24:12 +08:00
|
|
|
|
2015-10-12 02:59:27 +08:00
|
|
|
init(container);
|
2015-10-09 07:24:12 +08:00
|
|
|
|
2015-10-12 02:59:27 +08:00
|
|
|
http::Ipv4 ip("0.0.0.0", 7474);
|
|
|
|
app->listen(ip);
|
2015-10-09 07:24:12 +08:00
|
|
|
|
2015-10-12 02:59:27 +08:00
|
|
|
loop->run(uv::UvLoop::Mode::Default);
|
2015-10-09 07:24:12 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|