/* * Copyright (c) 2011 Jan Kaluza * Licensed under the Simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ #include #include #include #include #include #include "Swiften/SwiftenCompat.h" namespace Swift { StatsSerializer::StatsSerializer() : GenericPayloadSerializer() { } std::string StatsSerializer::serializePayload(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr stats) const { XMLElement queryElement("query", "http://jabber.org/protocol/stats"); BOOST_FOREACH(const StatsPayload::Item& item, stats->getItems()) { SWIFTEN_SHRPTR_NAMESPACE::shared_ptr statElement(new XMLElement("stat")); statElement->setAttribute("name", item.getName()); if (!item.getUnits().empty()) { statElement->setAttribute("units", item.getUnits()); } if (!item.getValue().empty()) { statElement->setAttribute("value", item.getValue()); } queryElement.addNode(statElement); } return queryElement.serialize(); } }