![]() |
RTBKit
0.9
Open-source framework to create real-time ad bidding systems.
|
00001 /* exchange_connector.cc 00002 Jeremy Barnes, 13 December 2012 00003 Copyright (c) 2012 Datacratic Inc. All rights reserved. 00004 00005 Exchange connector class. 00006 */ 00007 00008 #include "exchange_connector.h" 00009 #include "rtbkit/core/router/router.h" 00010 00011 using namespace std; 00012 00013 namespace RTBKIT { 00014 00015 ExchangeConnector::CampaignCompatibility:: 00016 CampaignCompatibility(const AgentConfig & config) 00017 : creatives(config.creatives.size()) 00018 { 00019 } 00020 00021 00022 /*****************************************************************************/ 00023 /* EXCHANGE CONNECTOR */ 00024 /*****************************************************************************/ 00025 00026 ExchangeConnector:: 00027 ExchangeConnector(const std::string & name, 00028 ServiceBase & parent) 00029 : ServiceBase(name, parent) 00030 { 00031 onNewAuction = [=] (std::shared_ptr<Auction> a) {cerr << "WARNING: an auction was lost into the void" << endl; }; 00032 onAuctionDone = [=] (std::shared_ptr<Auction> a) {}; 00033 00034 } 00035 00036 ExchangeConnector:: 00037 ExchangeConnector(const std::string & name, 00038 std::shared_ptr<ServiceProxies> proxies) 00039 : ServiceBase(name, proxies) 00040 { 00041 onNewAuction = [=] (std::shared_ptr<Auction> a) {cerr << "WARNING: an auction was lost into the void"; }; 00042 onAuctionDone = [=] (std::shared_ptr<Auction> a) {}; 00043 00044 } 00045 00046 ExchangeConnector:: 00047 ~ExchangeConnector() 00048 { 00049 } 00050 00051 void 00052 ExchangeConnector:: 00053 start() 00054 { 00055 } 00056 00057 void 00058 ExchangeConnector:: 00059 shutdown() 00060 { 00061 } 00062 00063 ExchangeConnector::ExchangeCompatibility 00064 ExchangeConnector:: 00065 getCampaignCompatibility(const AgentConfig & config, 00066 bool includeReasons) const 00067 { 00068 ExchangeCompatibility result; 00069 result.setCompatible(); 00070 return result; 00071 } 00072 00073 ExchangeConnector::ExchangeCompatibility 00074 ExchangeConnector:: 00075 getCreativeCompatibility(const Creative & creative, 00076 bool includeReasons) const 00077 { 00078 ExchangeCompatibility result; 00079 result.setCompatible(); 00080 return result; 00081 } 00082 00083 bool 00084 ExchangeConnector:: 00085 bidRequestPreFilter(const BidRequest & request, 00086 const AgentConfig & config, 00087 const void * info) const 00088 { 00089 return true; 00090 } 00091 00092 bool 00093 ExchangeConnector:: 00094 bidRequestPostFilter(const BidRequest & request, 00095 const AgentConfig & config, 00096 const void * info) const 00097 { 00098 return true; 00099 } 00100 00101 bool 00102 ExchangeConnector:: 00103 bidRequestCreativeFilter(const BidRequest & request, 00104 const AgentConfig & config, 00105 const void * info) const 00106 { 00107 return true; 00108 } 00109 00110 namespace { 00111 typedef std::unordered_map<std::string, ExchangeConnector::Factory> Factories; 00112 static Factories factories; 00113 typedef boost::lock_guard<ML::Spinlock> Guard; 00114 static ML::Spinlock lock; 00115 } // file scope 00116 00117 void 00118 ExchangeConnector:: 00119 registerFactory(const std::string & exchange, Factory factory) 00120 { 00121 Guard guard(lock); 00122 if (!factories.insert(make_pair(exchange, factory)).second) 00123 throw ML::Exception("already had a bid request factory registered"); 00124 } 00125 00126 std::unique_ptr<ExchangeConnector> 00127 ExchangeConnector:: 00128 create(const std::string & exchange, ServiceBase & owner, const std::string & name) 00129 { 00130 00131 Factory factory; 00132 { 00133 Guard guard(lock); 00134 auto it = factories.find(exchange); 00135 if (it == factories.end()) 00136 throw ML::Exception("couldn't find exchange factory for exchange " 00137 + exchange); 00138 factory = it->second; 00139 } 00140 00141 return std::unique_ptr<ExchangeConnector>(factory(&owner, name)); 00142 } 00143 00144 } // namespace RTBKIT