Created
March 3, 2014 07:55
-
-
Save Gocrazy/9320333 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #pragma once | |
| #include <string> | |
| #include "soa/service/http_endpoint.h" | |
| #include "soa/service/json_endpoint.h" | |
| #include "soa/service/zmq_named_pub_sub.h" | |
| #include "adserver_connector.h" | |
| namespace RTBKIT { | |
| class SmaatoAdServerHttpEndpoint; | |
| typedef std::function<void (const HttpHeader & header, | |
| const Json::Value & json, | |
| const std::string & jsonStr)> SmaatoAdServerRequestCb; | |
| struct SmaatoAdServerHttpEndpoint : public Datacratic::HttpEndpoint { | |
| SmaatoAdServerHttpEndpoint(int port, | |
| const SmaatoAdServerRequestCb & requestCb | |
| ); | |
| SmaatoAdServerHttpEndpoint(SmaatoAdServerHttpEndpoint && otherEndpoint); | |
| ~SmaatoAdServerHttpEndpoint(); | |
| SmaatoAdServerHttpEndpoint & operator = | |
| (const SmaatoAdServerHttpEndpoint& other); | |
| virtual std::shared_ptr<ConnectionHandler> makeNewHandler(); | |
| int getPort() const; | |
| private: | |
| int port_; | |
| SmaatoAdServerRequestCb requestCb_; | |
| }; | |
| struct SmaatoAdServerConnectionHandler : public Datacratic::JsonConnectionHandler { | |
| SmaatoAdServerConnectionHandler(SmaatoAdServerHttpEndpoint & endpoint, const SmaatoAdServerRequestCb & requestCb); | |
| virtual void handleJson(const HttpHeader & header, | |
| const Json::Value & json, | |
| const std::string & jsonStr); | |
| virtual void handleHttpHeader(const HttpHeader & header); | |
| virtual void handleHttpPayload(const HttpHeader & header, | |
| const std::string & payload); | |
| private: | |
| SmaatoAdServerHttpEndpoint & endpoint_; | |
| const SmaatoAdServerRequestCb & requestCb_; | |
| }; | |
| struct SmaatoAdServerConnector : public AdServerConnector { | |
| SmaatoAdServerConnector(const std::string & serviceName, | |
| const std::shared_ptr<Datacratic::ServiceProxies> & proxy); | |
| SmaatoAdServerConnector(std::shared_ptr<Datacratic::ServiceProxies> const & proxy, | |
| Json::Value const & json); | |
| ~SmaatoAdServerConnector() { | |
| shutdown(); | |
| } | |
| void init(int winsPort, int eventsPort, int externalPort); | |
| void shutdown(); | |
| void bindTcp(); | |
| void start(); | |
| Datacratic::ZmqNamedPublisher publisher_; | |
| private: | |
| std::vector<SmaatoAdServerHttpEndpoint> endpoints_; | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment