Skip to content

Instantly share code, notes, and snippets.

@Gocrazy
Created March 3, 2014 07:55
Show Gist options
  • Select an option

  • Save Gocrazy/9320333 to your computer and use it in GitHub Desktop.

Select an option

Save Gocrazy/9320333 to your computer and use it in GitHub Desktop.
#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