From e3490d65bb824a9b4ee0fdc0872753fa295b1087 Mon Sep 17 00:00:00 2001 From: Oleg Morozenkov Date: Wed, 12 Aug 2015 13:43:02 +0300 Subject: Fix some compiler errors with global header file --- include/tgbot/net/HttpServer.h | 15 +++++++-------- include/tgbot/net/TgWebhookLocalServer.h | 3 +-- include/tgbot/net/TgWebhookServer.h | 14 +++++++------- include/tgbot/net/TgWebhookTcpServer.h | 2 +- 4 files changed, 16 insertions(+), 18 deletions(-) (limited to 'include/tgbot/net') diff --git a/include/tgbot/net/HttpServer.h b/include/tgbot/net/HttpServer.h index bac7382..888c0a8 100644 --- a/include/tgbot/net/HttpServer.h +++ b/include/tgbot/net/HttpServer.h @@ -38,22 +38,22 @@ namespace TgBot { template class HttpServer { -private: +protected: class Connection; public: typedef std::function)> ServerHandler; - HttpServer(std::shared_ptr>& acceptor, const ServerHandler& handler) : _acceptor(acceptor), _handler(handler) { + HttpServer(std::shared_ptr> acceptor, const ServerHandler& handler) : _acceptor(acceptor), _handler(handler) { } /** * Starts receiving new connections. */ void start() { - std::shared_ptr> socket(new boost::asio::basic_stream_socket(acceptor->get_io_service())); - std::shared_ptr> connection(new Connection(socket, _handler)); - acceptor->async_accept(*connection->socket, [this, connection]() { + std::shared_ptr> socket(new boost::asio::basic_stream_socket(_acceptor->get_io_service())); + std::shared_ptr connection(new Connection(socket, _handler)); + _acceptor->async_accept(*connection->socket, [this, connection]() { connection->start(); start(); }); @@ -67,8 +67,7 @@ public: _ioService.stop(); } -private: - template +protected: class Connection { public: @@ -89,7 +88,7 @@ private: std::shared_ptr> socket; std::string data; - private: + protected: const ServerHandler _handler; }; diff --git a/include/tgbot/net/TgWebhookLocalServer.h b/include/tgbot/net/TgWebhookLocalServer.h index 8faf61d..6632485 100644 --- a/include/tgbot/net/TgWebhookLocalServer.h +++ b/include/tgbot/net/TgWebhookLocalServer.h @@ -37,12 +37,11 @@ public: TgWebhookLocalServer(std::shared_ptr>& acceptor, const std::string& path, EventHandler* eventHandler) = delete; TgWebhookLocalServer(const std::string& path, const EventHandler* eventHandler) : - TgWebhookServer(std::shared_ptr>(new boost::asio::local::stream_protocol::acceptor(_ioService, boost::asio::local::stream_protocol::endpoint(path))), path, eventHandler) + TgWebhookServer(std::shared_ptr>(new boost::asio::local::stream_protocol::acceptor(_ioService, boost::asio::local::stream_protocol::endpoint(path))), path, eventHandler) { } TgWebhookLocalServer(const std::string& path, const Bot& bot) : TgWebhookLocalServer(path, &bot.getEventHandler()) { - } }; diff --git a/include/tgbot/net/TgWebhookServer.h b/include/tgbot/net/TgWebhookServer.h index f583093..d085331 100644 --- a/include/tgbot/net/TgWebhookServer.h +++ b/include/tgbot/net/TgWebhookServer.h @@ -34,19 +34,19 @@ template class TgWebhookServer : public HttpServer { public: - TgWebhookServer(std::shared_ptr>& acceptor, const ServerHandler& handler) = delete; + TgWebhookServer(std::shared_ptr> acceptor, const typename HttpServer::ServerHandler& handler) = delete; - TgWebhookServer(std::shared_ptr>& acceptor, const std::string& path, const EventHandler* eventHandler) : - HttpServer(acceptor, [this, eventHandler, &path](const std::string& data, const std::map& headers) -> std::string { - if (headers["method"] == "POST" && headers["path"] == path) { - eventHandler->handleUpdate(TgTypeParser::getInstance().parseUpdate(TgTypeParser::getInstance().parseJson(data))); + TgWebhookServer(std::shared_ptr> acceptor, const std::string& path, const EventHandler* eventHandler) : + HttpServer(acceptor, [this, eventHandler, &path](const std::string& data, const std::map& headers) -> std::string { + if (headers.at("method") == "POST" && headers.at("path") == path) { + eventHandler->handleUpdate(TgTypeParser::getInstance().parseJsonAndGetUpdate(TgTypeParser::getInstance().parseJson(data))); } - return HttpParser::generateResponse(""); + return HttpParser::getInstance().generateResponse(""); }) { } - TgWebhookServer(std::shared_ptr>& acceptor, const std::string& path, const Bot& bot) : + TgWebhookServer(std::shared_ptr> acceptor, const std::string& path, const Bot& bot) : TgWebhookServer(acceptor, path, &bot.getEventHandler()) { } diff --git a/include/tgbot/net/TgWebhookTcpServer.h b/include/tgbot/net/TgWebhookTcpServer.h index 417b162..de1f3e7 100644 --- a/include/tgbot/net/TgWebhookTcpServer.h +++ b/include/tgbot/net/TgWebhookTcpServer.h @@ -34,7 +34,7 @@ namespace TgBot { class TgWebhookTcpServer : public TgWebhookServer { public: - TgWebhookTcpServer(std::shared_ptr>& acceptor, const std::string& path, EventHandler* eventHandler) = delete; + TgWebhookTcpServer(std::shared_ptr> acceptor, const std::string& path, EventHandler* eventHandler) = delete; TgWebhookTcpServer(unsigned short port, const std::string& path, const EventHandler* eventHandler) : TgWebhookServer(std::shared_ptr>(new boost::asio::ip::tcp::acceptor(_ioService, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port))), path, eventHandler) -- cgit v1.2.3