RTBKit
0.9
Open-source framework to create real-time ad bidding systems.
|
00001 /* json_endpoint.h -*- C++ -*- 00002 Jeremy Barnes, 22 February 2011 00003 Copyright (c) 2011 Datacratic. All rights reserved. 00004 00005 Endpoint that does JSON. 00006 */ 00007 00008 #pragma once 00009 00010 00011 #include "soa/service//http_endpoint.h" 00012 #include "soa/jsoncpp/json.h" 00013 00014 00015 namespace Datacratic { 00016 00017 00018 /*****************************************************************************/ 00019 /* JSON CONNECTION HANDLER */ 00020 /*****************************************************************************/ 00021 00029 struct JsonConnectionHandler : public HttpConnectionHandler { 00030 00031 JsonConnectionHandler(); 00032 00033 virtual void handleHttpHeader(const HttpHeader & header); 00034 00035 virtual void handleHttpPayload(const HttpHeader & header, 00036 const std::string & payload); 00037 00038 00040 virtual void handleHttpChunk(const HttpHeader & header, 00041 const std::string & chunkHeader, 00042 const std::string & chunk); 00043 00045 virtual void handleJson(const HttpHeader & header, 00046 const Json::Value & json, 00047 const std::string & jsonStr) = 0; 00048 }; 00049 00050 00051 /*****************************************************************************/ 00052 /* ADHOC JSON CONNECTION HANDLER */ 00053 /*****************************************************************************/ 00054 00057 struct AdHocJsonConnectionHandler : public JsonConnectionHandler { 00058 00059 typedef std::function<void (const HttpHeader & header, 00060 const Json::Value & json, 00061 const std::string & jsonStr, 00062 AdHocJsonConnectionHandler * connection)> 00063 OnJson; 00064 00065 AdHocJsonConnectionHandler() 00066 { 00067 } 00068 00069 AdHocJsonConnectionHandler(OnJson onJson) 00070 : onJson(onJson) 00071 { 00072 } 00073 00074 OnJson onJson; 00075 00076 virtual void handleJson(const HttpHeader & header, 00077 const Json::Value & json, 00078 const std::string & jsonStr) 00079 { 00080 onJson(header, json, jsonStr, this); 00081 } 00082 }; 00083 00084 } // namespace Datacratic