summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Serializer')
-rw-r--r--Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp27
-rw-r--r--Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h14
2 files changed, 39 insertions, 2 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp b/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp
index 578b0ab..def21b1 100644
--- a/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp
+++ b/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp
@@ -5,13 +5,36 @@
*/
#include <Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h>
-#include <Swiften/Serializer/XML/XMLElement.h>
+
+#include <boost/smart_ptr/make_shared.hpp>
#include <Swiften/Serializer/XML/XMLTextNode.h>
namespace Swift {
+ void WhiteboardElementSerializingVisitor::visit(const WhiteboardLineElement* line) {
+ element = boost::make_shared<XMLElement>("line");
+ element->setAttribute("x1", intToStr(line->x1()));
+ element->setAttribute("y1", intToStr(line->y1()));
+ element->setAttribute("x2", intToStr(line->x2()));
+ element->setAttribute("y2", intToStr(line->y2()));
+ }
+
+ std::string WhiteboardElementSerializingVisitor::intToStr(const int t) {
+ std::stringstream ss;
+ ss << t;
+ return ss.str();
+ }
+
+ XMLElement::ref WhiteboardElementSerializingVisitor::getResult() const {
+ return element;
+ }
+
std::string WhiteboardSerializer::serializePayload(boost::shared_ptr<WhiteboardPayload> payload) const {
XMLElement element("wb");
- element.addNode(XMLTextNode::ref(new XMLTextNode(payload->getData())));
+ if (payload->getType() == WhiteboardPayload::Data) {
+ WhiteboardElementSerializingVisitor visitor;
+ payload->getElement()->accept(visitor);
+ element.addNode(visitor.getResult());
+ }
element.setAttribute("type", typeToString(payload->getType()));
return element.serialize();
}
diff --git a/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h b/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h
index 975d537..219ebcc 100644
--- a/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h
+++ b/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h
@@ -7,9 +7,23 @@
#pragma once
#include <Swiften/Elements/WhiteboardPayload.h>
+#include <Swiften/Whiteboard/Elements/WhiteboardLineElement.h>
+#include <Swiften/Whiteboard/Elements/WhiteboardElementVisitor.h>
#include <Swiften/Serializer/GenericPayloadSerializer.h>
+#include <Swiften/Serializer/XML/XMLElement.h>
namespace Swift {
+ class WhiteboardElementSerializingVisitor : public WhiteboardElementVisitor {
+ public:
+ void visit(const WhiteboardLineElement* line);
+ XMLElement::ref getResult() const;
+
+ private:
+ std::string intToStr(const int t);
+
+ XMLElement::ref element;
+ };
+
class WhiteboardSerializer : public GenericPayloadSerializer<WhiteboardPayload> {
public:
std::string serializePayload(boost::shared_ptr<WhiteboardPayload> payload) const;