summaryrefslogtreecommitdiff
path: root/include/tgbot/net
diff options
context:
space:
mode:
authorOleg Morozenkov <omorozenkov@gmail.com>2015-08-12 13:43:02 +0300
committerOleg Morozenkov <omorozenkov@gmail.com>2015-08-12 13:43:02 +0300
commite3490d65bb824a9b4ee0fdc0872753fa295b1087 (patch)
tree0f61ecf6dd0e592c2390a8a93e3794dade2360f8 /include/tgbot/net
parent7b3fa406eb228a00ef9f053bd2177d53b61b1d3d (diff)
Fix some compiler errors with global header file
Diffstat (limited to 'include/tgbot/net')
-rw-r--r--include/tgbot/net/HttpServer.h15
-rw-r--r--include/tgbot/net/TgWebhookLocalServer.h3
-rw-r--r--include/tgbot/net/TgWebhookServer.h14
-rw-r--r--include/tgbot/net/TgWebhookTcpServer.h2
4 files changed, 16 insertions, 18 deletions
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<typename Protocol>
class HttpServer {
-private:
+protected:
class Connection;
public:
typedef std::function<std::string (const std::string&, const std::map<std::string, std::string>)> ServerHandler;
- HttpServer(std::shared_ptr<boost::asio::basic_socket_acceptor<Protocol>>& acceptor, const ServerHandler& handler) : _acceptor(acceptor), _handler(handler) {
+ HttpServer(std::shared_ptr<boost::asio::basic_socket_acceptor<Protocol>> acceptor, const ServerHandler& handler) : _acceptor(acceptor), _handler(handler) {
}
/**
* Starts receiving new connections.
*/
void start() {
- std::shared_ptr<boost::asio::basic_stream_socket<Protocol>> socket(new boost::asio::basic_stream_socket<Protocol>(acceptor->get_io_service()));
- std::shared_ptr<Connection<Protocol>> connection(new Connection<Protocol>(socket, _handler));
- acceptor->async_accept(*connection->socket, [this, connection]() {
+ std::shared_ptr<boost::asio::basic_stream_socket<Protocol>> socket(new boost::asio::basic_stream_socket<Protocol>(_acceptor->get_io_service()));
+ std::shared_ptr<Connection> connection(new Connection(socket, _handler));
+ _acceptor->async_accept(*connection->socket, [this, connection]() {
connection->start();
start();
});
@@ -67,8 +67,7 @@ public:
_ioService.stop();
}
-private:
- template<typename Protocol>
+protected:
class Connection {
public:
@@ -89,7 +88,7 @@ private:
std::shared_ptr<boost::asio::basic_stream_socket<Protocol>> 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<boost::asio::basic_socket_acceptor<boost::asio::local::stream_protocol>>& acceptor, const std::string& path, EventHandler* eventHandler) = delete;
TgWebhookLocalServer(const std::string& path, const EventHandler* eventHandler) :
- TgWebhookServer(std::shared_ptr<boost::asio::basic_socket_acceptor<boost::asio::local::stream_protocol>>(new boost::asio::local::stream_protocol::acceptor(_ioService, boost::asio::local::stream_protocol::endpoint(path))), path, eventHandler)
+ TgWebhookServer<boost::asio::local::stream_protocol>(std::shared_ptr<boost::asio::basic_socket_acceptor<boost::asio::local::stream_protocol>>(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<typename Protocol>
class TgWebhookServer : public HttpServer<Protocol> {
public:
- TgWebhookServer(std::shared_ptr<boost::asio::basic_socket_acceptor<Protocol>>& acceptor, const ServerHandler& handler) = delete;
+ TgWebhookServer(std::shared_ptr<boost::asio::basic_socket_acceptor<Protocol>> acceptor, const typename HttpServer<Protocol>::ServerHandler& handler) = delete;
- TgWebhookServer(std::shared_ptr<boost::asio::basic_socket_acceptor<Protocol>>& acceptor, const std::string& path, const EventHandler* eventHandler) :
- HttpServer(acceptor, [this, eventHandler, &path](const std::string& data, const std::map<std::string, std::string>& headers) -> std::string {
- if (headers["method"] == "POST" && headers["path"] == path) {
- eventHandler->handleUpdate(TgTypeParser::getInstance().parseUpdate(TgTypeParser::getInstance().parseJson(data)));
+ TgWebhookServer(std::shared_ptr<boost::asio::basic_socket_acceptor<Protocol>> acceptor, const std::string& path, const EventHandler* eventHandler) :
+ HttpServer<Protocol>(acceptor, [this, eventHandler, &path](const std::string& data, const std::map<std::string, std::string>& 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<boost::asio::basic_socket_acceptor<Protocol>>& acceptor, const std::string& path, const Bot& bot) :
+ TgWebhookServer(std::shared_ptr<boost::asio::basic_socket_acceptor<Protocol>> 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<boost::asio::ip::tcp> {
public:
- TgWebhookTcpServer(std::shared_ptr<boost::asio::basic_socket_acceptor<boost::asio::ip::tcp>>& acceptor, const std::string& path, EventHandler* eventHandler) = delete;
+ TgWebhookTcpServer(std::shared_ptr<boost::asio::basic_socket_acceptor<boost::asio::ip::tcp>> acceptor, const std::string& path, EventHandler* eventHandler) = delete;
TgWebhookTcpServer(unsigned short port, const std::string& path, const EventHandler* eventHandler) :
TgWebhookServer(std::shared_ptr<boost::asio::basic_socket_acceptor<boost::asio::ip::tcp>>(new boost::asio::ip::tcp::acceptor(_ioService, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port))), path, eventHandler)