/* **************************************************************************** * * Subject::toJson - */ std::string Subject::toJson() { JsonHelper jh; jh.addRaw("entities", vectorToJson(this->entities)); jh.addRaw("condition", this->condition.toJson()); return jh.str(); }
/* **************************************************************************** * * Condition::toJson - */ std::string Condition::toJson() { JsonHelper jh; jh.addRaw("attributes", vectorToJson(this->attributes)); { JsonHelper jhe; jhe.addString("q", this->expression.q); jhe.addString("geometry", this->expression.geometry); jhe.addString("coords", this->expression.coords); jh.addRaw("expression", jhe.str()); } return jh.str(); }
/* **************************************************************************** * * EntID::toJson - */ std::string EntID::toJson() { JsonHelper jh; jh.addString("id", this->id); jh.addString("idPattern", this->idPattern); jh.addString("type", this->type); return jh.str(); }
/* **************************************************************************** * * Condition::toJson - */ std::string Condition::toJson() { JsonHelper jh; jh.addRaw("attrs", vectorToJson(this->attributes)); JsonHelper jhe; if (this->expression.q != "") jhe.addString("q", this->expression.q); if (this->expression.mq != "") jhe.addString("mq", this->expression.mq); if (this->expression.geometry != "") jhe.addString("geometry", this->expression.geometry); if (this->expression.coords != "") jhe.addString("coords", this->expression.coords); if (this->expression.georel != "") jhe.addString("georel", this->expression.georel); std::string expressionString = jhe.str(); if (expressionString != "{}") jh.addRaw("expression", expressionString); return jh.str(); }
/* **************************************************************************** * * Subscription::toJson - */ std::string Subscription::toJson() { JsonHelper jh; jh.addString("id", this->id); if (this->expires > 0) { jh.addDate("expires", this->expires); } jh.addString("status", this->status); jh.addRaw("subject", this->subject.toJson()); jh.addRaw("notification", this->notification.toJson()); return jh.str(); }
/* **************************************************************************** * * Notification::toJson - */ std::string Notification::toJson() { JsonHelper jh; jh.addString("callback", this->callback); if (this->throttling > 0) { jh.addNumber("throttling", this->throttling); } if (this->timesSent > 0) { jh.addNumber("timesSent", this->timesSent); } if (this->lastNotification > 0) { jh.addDate("lastNotification", this->lastNotification); } jh.addRaw("attributes", vectorToJson(this->attributes)); return jh.str(); }
/* **************************************************************************** * * Notification::toJson - * * FIXME P2: we should move 'attrsFormat' from Subject class to Notification * class, to avoid passing attrsFormat as argument * */ std::string Notification::toJson(const std::string& attrsFormat) { JsonHelper jh; if (this->timesSent > 0) { jh.addNumber("timesSent", this->timesSent); } if (this->lastNotification > 0) { jh.addDate("lastNotification", this->lastNotification); } if (!this->blacklist) { jh.addRaw("attrs", vectorToJson(this->attributes)); } else { jh.addRaw("exceptAttrs", vectorToJson(this->attributes)); } jh.addString("attrsFormat", attrsFormat); if (this->httpInfo.custom) { jh.addRaw("httpCustom", this->httpInfo.toJson()); } else { jh.addRaw("http", this->httpInfo.toJson()); } if (this->metadata.size() > 0) { jh.addRaw("metadata", vectorToJson(this->metadata)); } return jh.str(); }
/* **************************************************************************** * * EntID::toJson - */ std::string EntID::toJson() { JsonHelper jh; if (!this->id.empty()) { jh.addString("id", this->id); } if (!this->idPattern.empty()) { jh.addString("idPattern", this->idPattern); } if (!this->type.empty()) { jh.addString("type", this->type); } if (!this->typePattern.empty()) { jh.addString("typePattern", this->typePattern); } return jh.str(); }
/* **************************************************************************** * * Subscription::toJson - */ std::string Subscription::toJson() { JsonHelper jh; jh.addString("id", this->id); if (this->description != "") { jh.addString("description", this->description); } if (this->expires != PERMANENT_SUBS_DATETIME) { jh.addDate("expires", this->expires); } jh.addString("status", this->status); jh.addRaw("subject", this->subject.toJson()); jh.addRaw("notification", this->notification.toJson(renderFormatToString(this->attrsFormat, true, true))); if (this->throttling > 0) { jh.addNumber("throttling", this->throttling); } return jh.str(); }
/* **************************************************************************** * * renderTimingStatistics - * * xxxReqTime - the total time that the LAST request took. * Measuring from the first MHD callback to 'connectionTreat', * until the MHD callback to 'requestCompleted'. * xxxXmlParseTime - the time that the XML Parse of the LAST request took. * xxxJsonV1ParseTime - the time that the JSON parse+treat of the LAST request took. * xxxJsonV2ParseTime - the time that the JSON parse+treat of the LAST request took. * xxxMongoBackendTime - the time that the mongoBackend took to treat the last request * xxxReadWaitTime - * xxxWriteWaitTime - * xxxCommandWaitTime - * xxxRenderTime - the time that the last render took to render the response * */ std::string renderTimingStatistics(void) { timeStatSemTake(__FUNCTION__, "putting stats together"); bool accJsonV1ParseTime = (accTimeStat.jsonV1ParseTime.tv_sec != 0) || (accTimeStat.jsonV1ParseTime.tv_nsec != 0); bool accJsonV2ParseTime = (accTimeStat.jsonV2ParseTime.tv_sec != 0) || (accTimeStat.jsonV2ParseTime.tv_nsec != 0); bool accMongoBackendTime = (accTimeStat.mongoBackendTime.tv_sec != 0) || (accTimeStat.mongoBackendTime.tv_nsec != 0); bool accMongoReadWaitTime = (accTimeStat.mongoReadWaitTime.tv_sec != 0) || (accTimeStat.mongoReadWaitTime.tv_nsec != 0); bool accMongoWriteWaitTime = (accTimeStat.mongoWriteWaitTime.tv_sec != 0) || (accTimeStat.mongoWriteWaitTime.tv_nsec != 0); bool accMongoCommandWaitTime = (accTimeStat.mongoCommandWaitTime.tv_sec != 0) || (accTimeStat.mongoCommandWaitTime.tv_nsec != 0); bool accRenderTime = (accTimeStat.renderTime.tv_sec != 0) || (accTimeStat.renderTime.tv_nsec != 0); bool accReqTime = (accTimeStat.reqTime.tv_sec != 0) || (accTimeStat.reqTime.tv_nsec != 0); bool accXmlParseTime = (accTimeStat.xmlParseTime.tv_sec != 0) || (accTimeStat.xmlParseTime.tv_nsec != 0); bool lastJsonV1ParseTime = (lastTimeStat.jsonV1ParseTime.tv_sec != 0) || (lastTimeStat.jsonV1ParseTime.tv_nsec != 0); bool lastJsonV2ParseTime = (lastTimeStat.jsonV2ParseTime.tv_sec != 0) || (lastTimeStat.jsonV2ParseTime.tv_nsec != 0); bool lastMongoBackendTime = (lastTimeStat.mongoBackendTime.tv_sec != 0) || (lastTimeStat.mongoBackendTime.tv_nsec != 0); bool lastMongoReadWaitTime = (lastTimeStat.mongoReadWaitTime.tv_sec != 0) || (lastTimeStat.mongoReadWaitTime.tv_nsec != 0); bool lastMongoWriteWaitTime = (lastTimeStat.mongoWriteWaitTime.tv_sec != 0) || (lastTimeStat.mongoWriteWaitTime.tv_nsec != 0); bool lastMongoCommandWaitTime = (lastTimeStat.mongoCommandWaitTime.tv_sec != 0) || (lastTimeStat.mongoCommandWaitTime.tv_nsec != 0); bool lastRenderTime = (lastTimeStat.renderTime.tv_sec != 0) || (lastTimeStat.renderTime.tv_nsec != 0); bool lastReqTime = (lastTimeStat.reqTime.tv_sec != 0) || (lastTimeStat.reqTime.tv_nsec != 0); bool lastXmlParseTime = (lastTimeStat.xmlParseTime.tv_sec != 0) || (lastTimeStat.xmlParseTime.tv_nsec != 0); bool last = lastJsonV1ParseTime || lastJsonV2ParseTime || lastMongoBackendTime || lastRenderTime || lastReqTime || lastXmlParseTime; bool acc = accJsonV1ParseTime || accJsonV2ParseTime || accMongoBackendTime || accRenderTime || accReqTime || accXmlParseTime; if (!acc && !last) { timeStatSemGive(__FUNCTION__, "no stats to report"); return "{}"; } JsonHelper jh; if (acc) { JsonHelper accJh; if (accJsonV1ParseTime) accJh.addFloat("jsonV1Parse", timeSpecToFloat(accTimeStat.jsonV1ParseTime)); if (accJsonV2ParseTime) accJh.addFloat("jsonV2Parse", timeSpecToFloat(accTimeStat.jsonV2ParseTime)); if (accMongoBackendTime) accJh.addFloat("mongoBackend", timeSpecToFloat(accTimeStat.mongoBackendTime)); if (accMongoReadWaitTime) accJh.addFloat("mongoReadWait", timeSpecToFloat(accTimeStat.mongoReadWaitTime)); if (accMongoWriteWaitTime) accJh.addFloat("mongoWriteWait", timeSpecToFloat(accTimeStat.mongoWriteWaitTime)); if (accMongoCommandWaitTime) accJh.addFloat("mongoCommandWait", timeSpecToFloat(accTimeStat.mongoCommandWaitTime)); if (accRenderTime) accJh.addFloat("render", timeSpecToFloat(accTimeStat.renderTime)); if (accReqTime) accJh.addFloat("total", timeSpecToFloat(accTimeStat.reqTime)); if (accXmlParseTime) accJh.addFloat("xmlParse", timeSpecToFloat(accTimeStat.xmlParseTime)); jh.addRaw("accumulated", accJh.str()); } if (last) { JsonHelper lastJh; if (lastJsonV1ParseTime) lastJh.addFloat("jsonV1Parse", timeSpecToFloat(lastTimeStat.jsonV1ParseTime)); if (lastJsonV2ParseTime) lastJh.addFloat("jsonV2Parse", timeSpecToFloat(lastTimeStat.jsonV2ParseTime)); if (lastMongoBackendTime) lastJh.addFloat("mongoBackend", timeSpecToFloat(lastTimeStat.mongoBackendTime)); if (lastMongoReadWaitTime) lastJh.addFloat("mongoReadWait", timeSpecToFloat(lastTimeStat.mongoReadWaitTime)); if (lastMongoWriteWaitTime) lastJh.addFloat("mongoWriteWait", timeSpecToFloat(lastTimeStat.mongoWriteWaitTime)); if (lastMongoCommandWaitTime) lastJh.addFloat("mongoCommandWait", timeSpecToFloat(lastTimeStat.mongoCommandWaitTime)); if (lastRenderTime) lastJh.addFloat("render", timeSpecToFloat(lastTimeStat.renderTime)); if (lastReqTime) lastJh.addFloat("total", timeSpecToFloat(lastTimeStat.reqTime)); if (lastXmlParseTime) lastJh.addFloat("xmlParse", timeSpecToFloat(lastTimeStat.xmlParseTime)); jh.addRaw("last", lastJh.str()); } timeStatSemGive(__FUNCTION__, "putting stats together"); return jh.str(); }