From 3d881ddd0b65d3a2bc1213386fb75fd95e4de691 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Thu, 30 Jan 2014 14:08:25 +0100 Subject: Update user tune & geoloc serializer Change-Id: I0657f752e78e050798b42876ae256eff64c8e325 diff --git a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp index 16c79d5..cd9b4d7 100644 --- a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp +++ b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp @@ -117,8 +117,8 @@ FullPayloadSerializerCollection::FullPayloadSerializerCollection() { serializers_.push_back(new ReplaceSerializer()); serializers_.push_back(new LastSerializer()); serializers_.push_back(new WhiteboardSerializer()); - serializers_.push_back(new UserLocationSerializer()); - serializers_.push_back(new UserTuneSerializer()); + serializers_.push_back(new UserLocationSerializer(this)); + serializers_.push_back(new UserTuneSerializer(this)); serializers_.push_back(new IdleSerializer()); serializers_.push_back(new StreamInitiationFileInfoSerializer()); diff --git a/Swiften/Serializer/PayloadSerializers/UserLocationSerializer.cpp b/Swiften/Serializer/PayloadSerializers/UserLocationSerializer.cpp index e257654..3c8dde1 100644 --- a/Swiften/Serializer/PayloadSerializers/UserLocationSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/UserLocationSerializer.cpp @@ -4,91 +4,97 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include +#pragma clang diagnostic ignored "-Wunused-private-field" -#include -#include +#include +#include +#include #include +#include -#include -#include +#include #include -namespace Swift { +using namespace Swift; + +UserLocationSerializer::UserLocationSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { +} -UserLocationSerializer::UserLocationSerializer() { +UserLocationSerializer::~UserLocationSerializer() { } -std::string UserLocationSerializer::serializePayload( - boost::shared_ptr payload) const { - XMLElement result("geoloc", "http://jabber.org/protocol/geoloc"); - if (boost::optional value = payload->getArea()) { - result.addNode(boost::make_shared("area", "", *value)); +std::string UserLocationSerializer::serializePayload(boost::shared_ptr payload) const { + if (!payload) { + return ""; } - if (boost::optional value = payload->getAltitude()) { - result.addNode(boost::make_shared("alt", "", boost::lexical_cast(*value))); + XMLElement element("geoloc", "http://jabber.org/protocol/geoloc"); + if (payload->getArea()) { + element.addNode(boost::make_shared("area", "", *payload->getArea())); } - if (boost::optional value = payload->getLocality()) { - result.addNode(boost::make_shared("locality", "", *value)); + if (payload->getAltitude()) { + element.addNode(boost::make_shared("alt", "", boost::lexical_cast(*payload->getAltitude()))); } - if (boost::optional value = payload->getLatitude()) { - result.addNode(boost::make_shared("lat", "", boost::lexical_cast(*value))); + if (payload->getLocality()) { + element.addNode(boost::make_shared("locality", "", *payload->getLocality())); } - if (boost::optional value = payload->getAccuracy()) { - result.addNode(boost::make_shared("accuracy", "", boost::lexical_cast(*value))); + if (payload->getLatitude()) { + element.addNode(boost::make_shared("lat", "", boost::lexical_cast(*payload->getLatitude()))); } - if (boost::optional value = payload->getDescription()) { - result.addNode(boost::make_shared("description", "", *value)); + if (payload->getAccuracy()) { + element.addNode(boost::make_shared("accuracy", "", boost::lexical_cast(*payload->getAccuracy()))); } - if (boost::optional value = payload->getCountryCode()) { - result.addNode(boost::make_shared("countrycode", "", *value)); + if (payload->getDescription()) { + element.addNode(boost::make_shared("description", "", *payload->getDescription())); } - if (boost::optional value = payload->getTimestamp()) { - result.addNode(boost::make_shared("timestamp", "", dateTimeToString(*value))); + if (payload->getCountryCode()) { + element.addNode(boost::make_shared("countrycode", "", *payload->getCountryCode())); } - if (boost::optional value = payload->getFloor()) { - result.addNode(boost::make_shared("floor", "", *value)); + if (payload->getTimestamp()) { + element.addNode(boost::make_shared("timestamp", "", dateTimeToString(*payload->getTimestamp()))); } - if (boost::optional value = payload->getBuilding()) { - result.addNode(boost::make_shared("building", "", *value)); + if (payload->getFloor()) { + element.addNode(boost::make_shared("floor", "", *payload->getFloor())); } - if (boost::optional value = payload->getRoom()) { - result.addNode(boost::make_shared("room", "", *value)); + if (payload->getBuilding()) { + element.addNode(boost::make_shared("building", "", *payload->getBuilding())); } - if (boost::optional value = payload->getCountry()) { - result.addNode(boost::make_shared("country", "", *value)); + if (payload->getRoom()) { + element.addNode(boost::make_shared("room", "", *payload->getRoom())); } - if (boost::optional value = payload->getRegion()) { - result.addNode(boost::make_shared("region", "", *value)); + if (payload->getCountry()) { + element.addNode(boost::make_shared("country", "", *payload->getCountry())); } - if (boost::optional value = payload->getURI()) { - result.addNode(boost::make_shared("uri", "", *value)); + if (payload->getRegion()) { + element.addNode(boost::make_shared("region", "", *payload->getRegion())); } - if (boost::optional value = payload->getLongitude()) { - result.addNode(boost::make_shared("lon", "", boost::lexical_cast(*value))); + if (payload->getURI()) { + element.addNode(boost::make_shared("uri", "", *payload->getURI())); } - if (boost::optional value = payload->getError()) { - result.addNode(boost::make_shared("error", "", boost::lexical_cast(*value))); + if (payload->getLongitude()) { + element.addNode(boost::make_shared("lon", "", boost::lexical_cast(*payload->getLongitude()))); } - if (boost::optional value = payload->getPostalCode()) { - result.addNode(boost::make_shared("postalcode", "", *value)); + if (payload->getError()) { + element.addNode(boost::make_shared("error", "", boost::lexical_cast(*payload->getError()))); } - if (boost::optional value = payload->getBearing()) { - result.addNode(boost::make_shared("bearing", "", boost::lexical_cast(*value))); + if (payload->getPostalCode()) { + element.addNode(boost::make_shared("postalcode", "", *payload->getPostalCode())); } - if (boost::optional value = payload->getText()) { - result.addNode(boost::make_shared("text", "", *value)); + if (payload->getBearing()) { + element.addNode(boost::make_shared("bearing", "", boost::lexical_cast(*payload->getBearing()))); } - if (boost::optional value = payload->getDatum()) { - result.addNode(boost::make_shared("datum", "", *value)); + if (payload->getText()) { + element.addNode(boost::make_shared("text", "", *payload->getText())); } - if (boost::optional value = payload->getStreet()) { - result.addNode(boost::make_shared("street", "", *value)); + if (payload->getDatum()) { + element.addNode(boost::make_shared("datum", "", *payload->getDatum())); } - if (boost::optional value = payload->getSpeed()) { - result.addNode(boost::make_shared("speed", "", boost::lexical_cast(*value))); + if (payload->getStreet()) { + element.addNode(boost::make_shared("street", "", *payload->getStreet())); } - return result.serialize(); + if (payload->getSpeed()) { + element.addNode(boost::make_shared("speed", "", boost::lexical_cast(*payload->getSpeed()))); + } + return element.serialize(); } -} + diff --git a/Swiften/Serializer/PayloadSerializers/UserLocationSerializer.h b/Swiften/Serializer/PayloadSerializers/UserLocationSerializer.h index 28a5fe8..d00187e 100644 --- a/Swiften/Serializer/PayloadSerializers/UserLocationSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/UserLocationSerializer.h @@ -6,14 +6,26 @@ #pragma once +#include +#include #include #include +#include namespace Swift { - class UserLocationSerializer : public GenericPayloadSerializer { + class PayloadSerializerCollection; + + class SWIFTEN_API UserLocationSerializer : public GenericPayloadSerializer { public: - UserLocationSerializer(); + UserLocationSerializer(PayloadSerializerCollection* serializers); + virtual ~UserLocationSerializer(); + + virtual std::string serializePayload(boost::shared_ptr) const SWIFTEN_OVERRIDE; + + private: + - virtual std::string serializePayload(boost::shared_ptr) const; + private: + PayloadSerializerCollection* serializers; }; } diff --git a/Swiften/Serializer/PayloadSerializers/UserTuneSerializer.cpp b/Swiften/Serializer/PayloadSerializers/UserTuneSerializer.cpp index 6c7799e..c27259c 100644 --- a/Swiften/Serializer/PayloadSerializers/UserTuneSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/UserTuneSerializer.cpp @@ -4,45 +4,51 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include +#pragma clang diagnostic ignored "-Wunused-private-field" -#include -#include +#include +#include #include +#include -#include +#include #include -namespace Swift { +using namespace Swift; -UserTuneSerializer::UserTuneSerializer() { +UserTuneSerializer::UserTuneSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { } -std::string UserTuneSerializer::serializePayload( - boost::shared_ptr payload) const { - XMLElement result("tune", "http://jabber.org/protocol/tune"); - if (boost::optional value = payload->getArtist()) { - result.addNode(boost::make_shared("artist", "", *value)); +UserTuneSerializer::~UserTuneSerializer() { +} + +std::string UserTuneSerializer::serializePayload(boost::shared_ptr payload) const { + if (!payload) { + return ""; + } + XMLElement element("tune", "http://jabber.org/protocol/tune"); + if (payload->getRating()) { + element.addNode(boost::make_shared("rating", "", boost::lexical_cast(*payload->getRating()))); } - if (boost::optional value = payload->getLength()) { - result.addNode(boost::make_shared("length", "", boost::lexical_cast(*value))); + if (payload->getTitle()) { + element.addNode(boost::make_shared("title", "", *payload->getTitle())); } - if (boost::optional value = payload->getRating()) { - result.addNode(boost::make_shared("rating", "", boost::lexical_cast(*value))); + if (payload->getTrack()) { + element.addNode(boost::make_shared("track", "", *payload->getTrack())); } - if (boost::optional value = payload->getSource()) { - result.addNode(boost::make_shared("source", "", *value)); + if (payload->getArtist()) { + element.addNode(boost::make_shared("artist", "", *payload->getArtist())); } - if (boost::optional value = payload->getTitle()) { - result.addNode(boost::make_shared("title", "", *value)); + if (payload->getURI()) { + element.addNode(boost::make_shared("uri", "", *payload->getURI())); } - if (boost::optional value = payload->getTrack()) { - result.addNode(boost::make_shared("track", "", *value)); + if (payload->getSource()) { + element.addNode(boost::make_shared("source", "", *payload->getSource())); } - if (boost::optional value = payload->getURI()) { - result.addNode(boost::make_shared("uri", "", *value)); + if (payload->getLength()) { + element.addNode(boost::make_shared("length", "", boost::lexical_cast(*payload->getLength()))); } - return result.serialize(); + return element.serialize(); } -} + diff --git a/Swiften/Serializer/PayloadSerializers/UserTuneSerializer.h b/Swiften/Serializer/PayloadSerializers/UserTuneSerializer.h index 8c20cbd..62be6f2 100644 --- a/Swiften/Serializer/PayloadSerializers/UserTuneSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/UserTuneSerializer.h @@ -6,14 +6,26 @@ #pragma once +#include +#include #include #include +#include namespace Swift { - class UserTuneSerializer : public GenericPayloadSerializer { + class PayloadSerializerCollection; + + class SWIFTEN_API UserTuneSerializer : public GenericPayloadSerializer { public: - UserTuneSerializer(); + UserTuneSerializer(PayloadSerializerCollection* serializers); + virtual ~UserTuneSerializer(); + + virtual std::string serializePayload(boost::shared_ptr) const SWIFTEN_OVERRIDE; + + private: + - virtual std::string serializePayload(boost::shared_ptr) const; + private: + PayloadSerializerCollection* serializers; }; } -- cgit v0.10.2-6-g49f6