From 870f7c6f084291c67390c220bea23653628e424c Mon Sep 17 00:00:00 2001 From: buda Date: Thu, 17 Sep 2015 02:26:48 +0200 Subject: [PATCH] Initial version of the router class (not yet implemented) --- server/.gitignore | 1 + server/README.md | 16 +++++++++----- server/application/application.hpp | 3 +++ server/application/router.hpp | 27 ++++++++++++++++++++++++ server/application/router.inl | 34 ++++++++++++++++++++++++++++++ server/test.cpp | 12 +++-------- server/uvmachine.hpp | 2 -- 7 files changed, 79 insertions(+), 16 deletions(-) create mode 100644 server/.gitignore create mode 100644 server/application/application.hpp create mode 100644 server/application/router.hpp create mode 100644 server/application/router.inl delete mode 100644 server/uvmachine.hpp diff --git a/server/.gitignore b/server/.gitignore new file mode 100644 index 000000000..f47cb2045 --- /dev/null +++ b/server/.gitignore @@ -0,0 +1 @@ +*.out diff --git a/server/README.md b/server/README.md index 8dc47dc28..bb526c2e7 100644 --- a/server/README.md +++ b/server/README.md @@ -2,7 +2,7 @@ * https://github.com/libuv/libuv -```{engine='bash'} +``` sh autogen.sh ./configure make @@ -12,14 +12,20 @@ make install * https://github.com/joyent/http-parser -```{engine='bash'} +``` make make install -stdlib=libstdc++ -lstdc++ (OSX) make install ``` +* https://github.com/c9s/r3 + +``` +brew install r3 (OSX) +``` + ## Test compile -```{engine='bash'} -clang++ -std=c++11 test.cpp -o test -luv -lhttp_parser -I../ -``` \ No newline at end of file +``` +clang++ -std=c++11 test.cpp -o test.out -luv -lhttp_parser -I../ +``` diff --git a/server/application/application.hpp b/server/application/application.hpp new file mode 100644 index 000000000..c14a362c3 --- /dev/null +++ b/server/application/application.hpp @@ -0,0 +1,3 @@ +#include "router.hpp" + +#include "router.inl" diff --git a/server/application/router.hpp b/server/application/router.hpp new file mode 100644 index 000000000..080720045 --- /dev/null +++ b/server/application/router.hpp @@ -0,0 +1,27 @@ +#ifndef MEMGRAPH_SERVER_APPLICATION_ROUTER_HPP +#define MEMGRAPH_SERVER_APPLICATION_ROUTER_HPP + +// TODO: find more appropriate way to include header files +#include "../uv/uv.hpp" +#include "../http/http.hpp" + +namespace application +{ + +// TODO: find out more appropriate name, like express +class Router +{ +private: + uv::UvLoop loop; + http::HttpServer server; + http::Ipv4 ip; +public: + Router(const http::Ipv4& ip); + void get(const std::string path, http::request_cb_t callback); + void listen(); + ~Router(); +}; + +} + +#endif diff --git a/server/application/router.inl b/server/application/router.inl new file mode 100644 index 000000000..1c75f8fb0 --- /dev/null +++ b/server/application/router.inl @@ -0,0 +1,34 @@ +#ifndef MEMGRAPH_SERVER_APPLICATION_ROUTER_INL +#define MEMGRAPH_SERVER_APPLICATION_ROUTER_INL + +#include "router.hpp" + +namespace application +{ + +Router::Router(const http::Ipv4& ip) : server(loop), ip(ip) +{ +} + +void Router::get(const std::string path, http::request_cb_t callback) +{ +} + +void Router::listen() +{ + server.listen(ip, [](http::Request& req, http::Response& res) { + res.send(req.url); + }); + + std::cout << "Server is UP" << std::endl; + + loop.run(uv::UvLoop::Mode::Default); +} + +Router::~Router() +{ +} + +} + +#endif diff --git a/server/test.cpp b/server/test.cpp index d37f236ad..74da0ec95 100644 --- a/server/test.cpp +++ b/server/test.cpp @@ -1,19 +1,13 @@ #include -#include "uvmachine.hpp" +#include "application/application.hpp" int main(void) { - uv::UvLoop loop; - http::HttpServer server(loop); - http::Ipv4 ip("0.0.0.0", 3400); - server.listen(ip, [](http::Request& req, http::Response& res) { - res.send(req.url); - }); - - loop.run(uv::UvLoop::Mode::Default); + application::Router router(ip); + router.listen(); return 0; } diff --git a/server/uvmachine.hpp b/server/uvmachine.hpp deleted file mode 100644 index 980ba1209..000000000 --- a/server/uvmachine.hpp +++ /dev/null @@ -1,2 +0,0 @@ -#include "uv/uv.hpp" -#include "http/http.hpp"