ShoutWiki — express yourself and be heard!
Jump to navigation Jump to search


total lines of code[edit]

find . -name '*.cc' | xargs wc -l 


cc: 214,613

h: 124,482

total: <> 339,000


cc: 52,998

h: 23,084

total: <> 76,000

http client[edit]

here: ~/rtbkit/soa/service/http_client.h

open rtb dpecification[edit]


shared_ptr example[edit]

Really a menuvenet.

#include <iostream>
#include <memory> 
struct A{
  int _d; 
  A(int d):_d(d) {std::cout <<"A"<<_d<<" ctor\n"; }
  ~A() {std::cout <<"A"<<_d<<" dtor\n";}

int main() {
  A *p = new A(6); 
  std::shared_ptr<A> sp = std::shared_ptr<A>(p); 
  std::cout << "pointed value: " << sp->_d << "\n   check done.\n"; 
  return 0; 

my bidder[edit]


CC = g++
CSWITCHES = -Wall -pthread -std=c++11

run: bidder

	$(CC) $(CSWITCHES) $<

app: exchange.o bidder.o
	$(CC) exchange.o bidder.o -o app

	$(CC) $(CSWITCHES) -o $@  

	$(CC) $(CSWITCHES) -o $@
	echo "     *******    "

	rm *.o bidder[edit]

#include <iostream>
#include <string> 
#include <vector> 
#include <memory> 

class Json {
  class Value {}; 


class Url {};

struct BidRequest {
        : auctionType(AuctionType::SECOND_PRICE), timeAvailableMs(0.0),

    Id auctionId;
    AuctionType auctionType;
    double timeAvailableMs;
    Date timestamp;
    bool isTest;

    std::string protocolVersion;  ///< What protocol version, eg OpenRTB
    std::string exchange;
    std::string provider;
    Id userAgentIPHash;  ///< Concatenation of the user agent and IP hashed

    /* The following fields indicate the contents of the OpenRTB bid request
       that is being processed.

    /** Information specific to the site that generated the request.  Only
        one of site or app will be present.
    OpenRTB::Optional<OpenRTB::Site> site;

    /** Information specific to the app that generated the request.  Only
        one of site or app will be present.
    OpenRTB::Optional<OpenRTB::App> app;

    /** Information about the device that generated the request. */
    OpenRTB::Optional<OpenRTB::Device> device;

    /** Information about the user that generated the request. */
    OpenRTB::Optional<OpenRTB::User> user;

    /** The impressions that are available within the bid request. */
    std::vector<AdSpot> imp;

    /** The regulations that are related to this bid request. */
    OpenRTB::Optional<OpenRTB::Regulations> regs;

    /* The following fields are all mirrored from the information in the rest
       of the bid request.  They provide a way for the bid request parser to
       indicate the value of commonly used values in such a way that any
       optimization algorithm can make use of them.
  std::string language;   ///< User's language.  // <-- should be unicode.. 
  Location location;      ///< Best available location information
  Url url;
  std::string ipAddress;
  std::string userAgent;

    /** This field should be used to indicate what User IDs are available
        in the bid request.  These are normally used by the augmentors to
        attach first or third party data to the bid request.
    UserIds userIds;

    SegmentsBySource restrictions;

    /** This field indicates the segments that are available in the bid
        request for the user.
    SegmentsBySource segments;
    Json::Value meta;

    /** Extra fields included in the JSON that are unparseable by the bid
        request parser.  Recorded here so that no information is lost in the
        round trip.
    Json::Value unparseable;

    /** Set of currency codes in which the bid can occur. */
    std::vector<CurrencyCode> bidCurrency;

    /** Blocked Categories. */
    OpenRTB::List<OpenRTB::ContentCategory> blockedCategories;

    /** Blocked TLD Advertisers (badv) */
    std::vector<Datacratic::UnicodeString> badv ;

    /** Amount of extras that will be paid if we win the auction.  These will
        be accumulated in the banker against the winning account.
    LineItems winSurcharges;

    /** Transposition of the "ext" field of the OpenRTB request */
    Json::Value ext;

    /** Return a canonical JSON version of the bid request. */
    Json::Value toJson() const;

    /** Return a canonical stringified JSON version of the bid request. */
    std::string toJsonStr() const;

    /** Create a new BidRequest from a canonical JSON value. */
    static BidRequest createFromJson(const Json::Value & json);

    /** Return the ID for the given domain. */
    Id getUserId(IdDomain domain) const;
    Id getUserId(const std::string & domain) const;

    /** Return the spot number with the given ID.  -1 on not found. */
    int findAdSpotIndex(const Id & adSpotId) const
        for (unsigned i = 0; i < imp.size();  ++i)
            if (imp[i].id == adSpotId)
                return i;
        return -1;
    /** Query the presence of the given segment in the given source. */
    segmentPresent(const std::string & source,
                   const std::string & segment) const;

    /** Query the presence of the given segment in the given source. */
    segmentPresent(const std::string & source, int segment) const;
    void sortAll();

    typedef boost::function<BidRequest * (const std::string)> Parser;

    // FIXME: this is being kept just for compatibility reasons.
    // we don't want to break compatibility now, although this interface does not make
    // sense any longer  
    // so any use of it should be considered deprecated
    static void registerParser(const std::string & source,
			       Parser parser)
        PluginInterface<BidRequest>::registerPlugin(source, parser);
    /** plugin interface requirements */
    typedef Parser Factory; // plugin interface expects this tipe to be called Factory
    /** plugin interface needs to be able to request the root name of the plugin library */
    static const std::string libNameSufix() {return "bid_request";};

    /** Parse the given bid request from the given source.  The correct
        parser will be looked up in a registry based upon the source.*/
    static BidRequest *
    parse(const std::string & source, const std::string & bidRequest);

    static BidRequest *
    parse(const std::string & source, 
          const Datacratic::UnicodeString & bidRequest);

    void serialize(ML::DB::Store_Writer & store) const;
    void reconstitute(ML::DB::Store_Reader & store);

    std::string serializeToString() const;
    static BidRequest createFromString(const std::string & str);

class HttpResponse {
  HttpResponse(int a, std::string str1, std::string str2) {} 

class HttpAuctionHandler{};

class HttpHeader {};  

class Auction{


  class Data {
    std::vector<int> responses; 
    bool hasValidResponse(unsigned spotNum) {return true; } 
    int winningResponse(unsigned spotNum) {return 1; }

  Data* getCurrentData() { return &m_data; } 
  Data m_data; 

// original code taken from:

HttpResponse getResponse(HttpAuctionHandler const & handler,
                                     const HttpHeader & header,
                                     Auction & auction) {
    std::string result;

    // get the auction's result data
    Auction::Data *current = auction.getCurrentData();
    /* orig error handling.. 
    if (current->hasError())
        return getErrorResponse(handler, auction, current->error + ": " + current->details);

    // begin the JSON string that will be returned
    result = "{\"imp\":[ ";      // original was: "{\\"imp\\":[";

    bool first = true;
    for (unsigned spotNum = 0; spotNum < current->responses.size(); ++spotNum) {

        // only process impression with at least one valid response
        if (!current->hasValidResponse(spotNum))

        if (!first) result += ",";
        first = false;

        // simply take the winning response and append it to the JSON string
        //auto & resp = current->winningResponse(spotNum); // this auto type.. I need to understand it better 
        result += "..stuff..";  
	/* orig: 
	  result += ML::format("{\\"id\":\\"%s\",\\"max_price\\":%lld,\\"account\\":\\"%s\\"}",
                             (long long) (MicroUSD_CPM(resp.price.maxPrice)),


    // we're done, send the response back
    result += "]}";
    return HttpResponse(200, "application/json", result);

std::shared_ptr<BidRequest> parseBidRequest(HttpAuctionHandler & handler,
                                            HttpHeader const & header,
                                            std::string const & payload) {
    std::shared_ptr<BidRequest> request;
    request.reset(BidRequest::parse("datacratic", payload));
    return request;

int main() {
  std::cout << "I'm a happy chap!\n"; 
  return 0; 

find in code[edit]

find . -name '*.h' -exec cat {} \; | grep 'struct BidRequest'
grep -r BidRequest *