Ejemplo n.º 1
0
string Rest::buildParams(RequestData const &params) {
	if(params.empty()) {
		return "";
	}
	RequestData::const_iterator pb = params.begin(), pe = params.end();
	string data = pb->first+ "=" + pb->second;
	++ pb;
	if(pb == pe){
		return data;
	}
	for(; pb!= pe; ++ pb){
		data+= "&" + pb->first + "=" + pb->second;
	}

	return data;
}
Ejemplo n.º 2
0
int doSomething(
    Durations &durationsRef,
    std::mutex &lockerRef,
    const AnySessionHdr &sessionHdr,
    const RequestData &inBuffer,
    AnySessionSpecific &sessionSpecific,
    AnyAnswerHdr &answerHdr,
    AnswerData &outBuffer)
{
    const char *tag = "At a session named ";
    outBuffer = AnswerData(tag, tag + strlen(tag));
    std::copy(getName(sessionHdr),
              getName(sessionHdr) + strlen(getName(sessionHdr)),
              std::back_inserter(outBuffer));
    outBuffer.push_back('\n');
    std::copy(inBuffer.begin(),
              inBuffer.end(),
              std::back_inserter(outBuffer));

    uint32_t &numOfRequestsLeft = *getNumPtr(answerHdr);
    numOfRequestsLeft = -- sessionSpecific.numOfRequestsLeft;
    if (!numOfRequestsLeft)
    {
        time_t duration = time(0) - sessionSpecific.startedAt;
        std::stringstream sessionFooter;

        {
            std::lock_guard<std::mutex> lockGuard(lockerRef);
            auto inserted = durationsRef.insert(duration).first;
            sessionFooter << std::endl
                          << " Session duration: " << duration << " second(s); " << std::endl
                          << " Rating position: "  << std::distance(durationsRef.begin(), inserted) + 1 << "; ";
        }

        std::string sessionFooterStr = sessionFooter.str();
        std::copy(sessionFooterStr.begin(),
                  sessionFooterStr.end(),
                  std::back_inserter(outBuffer));
    }

    return numOfRequestsLeft;
}