summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/Elements/WhiteboardPayload.h10
-rw-r--r--Swiften/Parser/PayloadParsers/WhiteboardParser.cpp27
-rw-r--r--Swiften/Parser/PayloadParsers/WhiteboardParser.h3
-rw-r--r--Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp18
-rw-r--r--Swiften/Whiteboard/Elements/WhiteboardElement.h2
-rw-r--r--Swiften/Whiteboard/IncomingWhiteboardSession.cpp24
-rw-r--r--Swiften/Whiteboard/IncomingWhiteboardSession.h8
-rw-r--r--Swiften/Whiteboard/OutgoingWhiteboardSession.cpp29
-rw-r--r--Swiften/Whiteboard/OutgoingWhiteboardSession.h6
-rw-r--r--Swiften/Whiteboard/WhiteboardSession.cpp18
-rw-r--r--Swiften/Whiteboard/WhiteboardSession.h11
11 files changed, 149 insertions, 7 deletions
diff --git a/Swiften/Elements/WhiteboardPayload.h b/Swiften/Elements/WhiteboardPayload.h
index c61e4a5..cf22f20 100644
--- a/Swiften/Elements/WhiteboardPayload.h
+++ b/Swiften/Elements/WhiteboardPayload.h
@@ -10,6 +10,7 @@
#include <Swiften/Elements/Payload.h>
#include <Swiften/Whiteboard/Elements/WhiteboardElement.h>
+#include <Swiften/Whiteboard/Operations/WhiteboardOperation.h>
namespace Swift {
class WhiteboardPayload : public Payload {
@@ -46,9 +47,18 @@ namespace Swift {
element_ = element;
}
+ WhiteboardOperation::ref getOperation() const {
+ return operation_;
+ }
+
+ void setOperation(WhiteboardOperation::ref operation) {
+ operation_ = operation;
+ }
+
private:
std::string data_;
Type type_;
WhiteboardElement::ref element_;
+ WhiteboardOperation::ref operation_;
};
}
diff --git a/Swiften/Parser/PayloadParsers/WhiteboardParser.cpp b/Swiften/Parser/PayloadParsers/WhiteboardParser.cpp
index 0f2734c..037eae2 100644
--- a/Swiften/Parser/PayloadParsers/WhiteboardParser.cpp
+++ b/Swiften/Parser/PayloadParsers/WhiteboardParser.cpp
@@ -12,6 +12,7 @@
#include <Swiften/Whiteboard/Elements/WhiteboardEllipseElement.h>
#include <Swiften/Whiteboard/Elements/WhiteboardFreehandPathElement.h>
#include <Swiften/Whiteboard/Elements/Color.h>
+#include <Swiften/Whiteboard/Operations/WhiteboardInsertOperation.h>
#include <boost/optional.hpp>
#include <boost/smart_ptr/make_shared.hpp>
#include <boost/lexical_cast.hpp>
@@ -24,6 +25,18 @@ namespace Swift {
if (level_ == 0) {
getPayloadInternal()->setType(stringToType(attributes.getAttributeValue("type").get_value_or("")));
} else if (level_ == 1) {
+ std::string type = attributes.getAttributeValue("type").get_value_or("");
+ if (type == "insert") {
+ WhiteboardInsertOperation::ref insertOp = boost::make_shared<WhiteboardInsertOperation>();
+ try {
+ insertOp->setID(attributes.getAttributeValue("id").get_value_or(""));
+ insertOp->setParentID(attributes.getAttributeValue("parentid").get_value_or(""));
+ insertOp->setPos(boost::lexical_cast<int>(attributes.getAttributeValue("pos").get_value_or("0")));
+ } catch (boost::bad_lexical_cast&) {
+ }
+ operation = insertOp;
+ }
+ } else if (level_ == 2) {
if (element == "line") {
int x1 = 0;
int y1 = 0;
@@ -50,6 +63,7 @@ namespace Swift {
whiteboardElement->setPenWidth(penWidth);
whiteboardElement->setID(attributes.getAttributeValue("id").get_value_or(""));
getPayloadInternal()->setElement(whiteboardElement);
+ wbElement = whiteboardElement;
} else if (element == "path") {
WhiteboardFreehandPathElement::ref whiteboardElement = boost::make_shared<WhiteboardFreehandPathElement>();
std::string pathData = attributes.getAttributeValue("d").get_value_or("");
@@ -98,6 +112,7 @@ namespace Swift {
whiteboardElement->setColor(color);
whiteboardElement->setID(attributes.getAttributeValue("id").get_value_or(""));
getPayloadInternal()->setElement(whiteboardElement);
+ wbElement = whiteboardElement;
} else if (element == "rect") {
int x = 0;
int y = 0;
@@ -128,6 +143,7 @@ namespace Swift {
whiteboardElement->setBrushColor(brushColor);
whiteboardElement->setID(attributes.getAttributeValue("id").get_value_or(""));
getPayloadInternal()->setElement(whiteboardElement);
+ wbElement = whiteboardElement;
} else if (element == "polygon") {
WhiteboardPolygonElement::ref whiteboardElement = boost::make_shared<WhiteboardPolygonElement>();
@@ -166,6 +182,7 @@ namespace Swift {
whiteboardElement->setBrushColor(brushColor);
whiteboardElement->setID(attributes.getAttributeValue("id").get_value_or(""));
getPayloadInternal()->setElement(whiteboardElement);
+ wbElement = whiteboardElement;
} else if (element == "text") {
int x = 0;
int y = 0;
@@ -190,6 +207,7 @@ namespace Swift {
whiteboardElement->setSize(fontSize);
whiteboardElement->setID(attributes.getAttributeValue("id").get_value_or(""));
getPayloadInternal()->setElement(whiteboardElement);
+ wbElement = whiteboardElement;
} else if (element == "ellipse") {
int cx = 0;
int cy = 0;
@@ -220,6 +238,7 @@ namespace Swift {
whiteboardElement->setBrushColor(brushColor);
whiteboardElement->setID(attributes.getAttributeValue("id").get_value_or(""));
getPayloadInternal()->setElement(whiteboardElement);
+ wbElement = whiteboardElement;
}
}
++level_;
@@ -230,6 +249,12 @@ namespace Swift {
if (level_ == 0) {
getPayloadInternal()->setData(data_);
} else if (level_ == 1) {
+ WhiteboardInsertOperation::ref insertOp = boost::dynamic_pointer_cast<WhiteboardInsertOperation>(operation);
+ if (insertOp) {
+ insertOp->setElement(wbElement);
+ }
+ getPayloadInternal()->setOperation(operation);
+ } else if (level_ == 2) {
if (element == "text") {
actualIsText = false;
}
@@ -237,7 +262,7 @@ namespace Swift {
}
void WhiteboardParser::handleCharacterData(const std::string& data) {
- if (level_ == 2 && actualIsText) {
+ if (level_ == 3 && actualIsText) {
WhiteboardTextElement::ref element = boost::dynamic_pointer_cast<WhiteboardTextElement>(getPayloadInternal()->getElement());
element->setText(data);
}
diff --git a/Swiften/Parser/PayloadParsers/WhiteboardParser.h b/Swiften/Parser/PayloadParsers/WhiteboardParser.h
index 7c93de3..bc4ed2a 100644
--- a/Swiften/Parser/PayloadParsers/WhiteboardParser.h
+++ b/Swiften/Parser/PayloadParsers/WhiteboardParser.h
@@ -9,6 +9,7 @@
#include <Swiften/Elements/WhiteboardPayload.h>
#include <Swiften/Parser/GenericPayloadParser.h>
#include <Swiften/Whiteboard/Elements/WhiteboardElement.h>
+#include <Swiften/Whiteboard/Operations/WhiteboardOperation.h>
namespace Swift {
class WhiteboardParser : public Swift::GenericPayloadParser<WhiteboardPayload> {
@@ -27,5 +28,7 @@ namespace Swift {
bool actualIsText;
int level_;
std::string data_;
+ WhiteboardElement::ref wbElement;
+ WhiteboardOperation::ref operation;
};
}
diff --git a/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp b/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp
index a15d7ae..0cd4779 100644
--- a/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp
+++ b/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp
@@ -9,6 +9,7 @@
#include <boost/smart_ptr/make_shared.hpp>
#include <boost/lexical_cast.hpp>
#include <Swiften/Serializer/XML/XMLTextNode.h>
+#include <Swiften/Whiteboard/Operations/WhiteboardInsertOperation.h>
namespace Swift {
void WhiteboardElementSerializingVisitor::visit(WhiteboardLineElement& line) {
@@ -135,9 +136,22 @@ namespace Swift {
std::string WhiteboardSerializer::serializePayload(boost::shared_ptr<WhiteboardPayload> payload) const {
XMLElement element("wb");
if (payload->getType() == WhiteboardPayload::Data) {
+ XMLElement::ref operationNode = boost::make_shared<XMLElement>("operation");
WhiteboardElementSerializingVisitor visitor;
- payload->getElement()->accept(visitor);
- element.addNode(visitor.getResult());
+// payload->getElement()->accept(visitor);
+ WhiteboardInsertOperation::ref insertOp = boost::dynamic_pointer_cast<WhiteboardInsertOperation>(payload->getOperation());
+ if (insertOp) {
+ try {
+ operationNode->setAttribute("type", "insert");
+ operationNode->setAttribute("pos", boost::lexical_cast<std::string>(insertOp->getPos()));
+ operationNode->setAttribute("id", insertOp->getID());
+ operationNode->setAttribute("parentid", insertOp->getParentID());
+ } catch (boost::bad_lexical_cast&) {
+ }
+ insertOp->getElement()->accept(visitor);
+ operationNode->addNode(visitor.getResult());
+ }
+ element.addNode(operationNode);
}
element.setAttribute("type", typeToString(payload->getType()));
return element.serialize();
diff --git a/Swiften/Whiteboard/Elements/WhiteboardElement.h b/Swiften/Whiteboard/Elements/WhiteboardElement.h
index 5095506..2b84a04 100644
--- a/Swiften/Whiteboard/Elements/WhiteboardElement.h
+++ b/Swiften/Whiteboard/Elements/WhiteboardElement.h
@@ -17,5 +17,7 @@ namespace Swift {
public:
virtual ~WhiteboardElement() {}
virtual void accept(WhiteboardElementVisitor& visitor) = 0;
+ virtual std::string getID() const = 0;
+ virtual void setID(const std::string&) = 0;
};
}
diff --git a/Swiften/Whiteboard/IncomingWhiteboardSession.cpp b/Swiften/Whiteboard/IncomingWhiteboardSession.cpp
index 5cdba1a..60faa2e 100644
--- a/Swiften/Whiteboard/IncomingWhiteboardSession.cpp
+++ b/Swiften/Whiteboard/IncomingWhiteboardSession.cpp
@@ -23,4 +23,28 @@ namespace Swift {
std::string IncomingWhiteboardSession::getClientID() const {
return "b";
}
+
+ void IncomingWhiteboardSession::handleIncomingOperation(WhiteboardOperation::ref operation) {
+// std::cout << "incoming pos: " << operation->getPos() << std::endl;
+ WhiteboardInsertOperation::ref insertOp = boost::dynamic_pointer_cast<WhiteboardInsertOperation>(operation);
+ if (insertOp) {
+ WhiteboardOperation::ref op = server.handleClientOperationReceived(insertOp);
+ //std::cout << "in1: " << operation->getID() << " " << operation->getPos() << " " << operation->getParentID() << std::endl;
+ //std::cout << "in2: " << op->getID() << " " << op->getPos() << " " << op->getParentID() << std::endl;
+ onOperationReceived(op);
+ WhiteboardPayload::ref payload = boost::make_shared<WhiteboardPayload>();
+ payload->setOperation(op);
+ sendPayload(payload);
+ } else {
+ std::cout << "unknown operation" << std::endl;
+ }
+ }
+
+ void IncomingWhiteboardSession::handleSendOperationRequest(WhiteboardOperation::ref operation) {
+ //std::cout << "out: " << operation->getID() << " " << operation->getPos() << " " << operation->getParentID()<< std::endl;
+ server.handleLocalOperationReceived(operation);
+ WhiteboardPayload::ref payload = boost::make_shared<WhiteboardPayload>();
+ payload->setOperation(operation);
+ sendPayload(payload);
+ }
}
diff --git a/Swiften/Whiteboard/IncomingWhiteboardSession.h b/Swiften/Whiteboard/IncomingWhiteboardSession.h
index 9971d75..33c1a78 100644
--- a/Swiften/Whiteboard/IncomingWhiteboardSession.h
+++ b/Swiften/Whiteboard/IncomingWhiteboardSession.h
@@ -7,7 +7,7 @@
#pragma once
#include <Swiften/Whiteboard/WhiteboardSession.h>
-
+#include <Swiften/Whiteboard/WhiteboardServer.h>
#include <boost/shared_ptr.hpp>
namespace Swift {
@@ -21,5 +21,11 @@ namespace Swift {
void accept();
std::string getClientID() const;
+
+ private:
+ void handleIncomingOperation(WhiteboardOperation::ref operation);
+ void handleSendOperationRequest(WhiteboardOperation::ref operation);
+
+ WhiteboardServer server;
};
}
diff --git a/Swiften/Whiteboard/OutgoingWhiteboardSession.cpp b/Swiften/Whiteboard/OutgoingWhiteboardSession.cpp
index f0b6d22..da4d3cf 100644
--- a/Swiften/Whiteboard/OutgoingWhiteboardSession.cpp
+++ b/Swiften/Whiteboard/OutgoingWhiteboardSession.cpp
@@ -33,4 +33,33 @@ namespace Swift {
onRequestRejected(toJID_);
}
}
+
+ void OutgoingWhiteboardSession::handleIncomingOperation(WhiteboardOperation::ref operation) {
+// std::cout << "incoming pos: " << operation->getPos() << std::endl;
+ WhiteboardClient::Result pairResult = client.handleServerOperationReceived(operation);
+ if (pairResult.client) {
+ onOperationReceived(pairResult.client);
+ //std::cout << "in1: " << operation->getID() << " " << operation->getPos() << " " << operation->getParentID() << std::endl;
+ //std::cout << "in2: " << pairResult.client->getID() << " " << pairResult.client->getPos() << " " << pairResult.client->getParentID() << std::endl;
+ }
+
+ if (pairResult.server) {
+ //std::cout << "outts: " << pairResult.server->getID() << " " << pairResult.server->getPos() << std::endl;
+ WhiteboardPayload::ref payload = boost::make_shared<WhiteboardPayload>();
+ payload->setOperation(pairResult.server);
+ sendPayload(payload);
+ }
+ }
+
+ void OutgoingWhiteboardSession::handleSendOperationRequest(WhiteboardOperation::ref operation) {
+ //std::cout << "out1: " << operation->getID() << " " << operation->getPos() << " " << operation->getParentID() << std::endl;
+ WhiteboardOperation::ref result = client.handleLocalOperationReceived(operation);
+
+ if (result) {
+ //std::cout << "out2: " << result->getID() << " " << result->getPos()<< " " << result->getParentID()<< std::endl;
+ WhiteboardPayload::ref payload = boost::make_shared<WhiteboardPayload>();
+ payload->setOperation(result);
+ sendPayload(payload);
+ }
+ }
}
diff --git a/Swiften/Whiteboard/OutgoingWhiteboardSession.h b/Swiften/Whiteboard/OutgoingWhiteboardSession.h
index 5cc0f42..fbd0f20 100644
--- a/Swiften/Whiteboard/OutgoingWhiteboardSession.h
+++ b/Swiften/Whiteboard/OutgoingWhiteboardSession.h
@@ -7,7 +7,7 @@
#pragma once
#include <Swiften/Whiteboard/WhiteboardSession.h>
-
+#include <Swiften/Whiteboard/WhiteboardClient.h>
#include <boost/shared_ptr.hpp>
#include <Swiften/Queries/GenericRequest.h>
@@ -24,5 +24,9 @@ namespace Swift {
private:
void handleRequestResponse(boost::shared_ptr<WhiteboardPayload> payload, ErrorPayload::ref error);
+ void handleIncomingOperation(WhiteboardOperation::ref operation);
+ void handleSendOperationRequest(WhiteboardOperation::ref operation);
+
+ WhiteboardClient client;
};
}
diff --git a/Swiften/Whiteboard/WhiteboardSession.cpp b/Swiften/Whiteboard/WhiteboardSession.cpp
index d9dc592..2828436 100644
--- a/Swiften/Whiteboard/WhiteboardSession.cpp
+++ b/Swiften/Whiteboard/WhiteboardSession.cpp
@@ -27,7 +27,9 @@ namespace Swift {
switch (payload->getType()) {
case WhiteboardPayload::Data:
- onElementReceived(payload->getElement());
+ //onElementReceived(payload->getElement());
+// onOperationReceived(payload->getOperation());
+ handleIncomingOperation(payload->getOperation());
break;
case WhiteboardPayload::SessionAccept:
onRequestAccepted(toJID_);
@@ -42,6 +44,20 @@ namespace Swift {
request->send();
}
+ void WhiteboardSession::sendOperation(const WhiteboardOperation::ref operation) {
+/* boost::shared_ptr<WhiteboardPayload> payload = boost::make_shared<WhiteboardPayload>();
+ // payload->setElement(operation->getElement());
+ payload->setOperation(operation);
+ boost::shared_ptr<GenericRequest<WhiteboardPayload> > request = boost::make_shared<GenericRequest<WhiteboardPayload> >(IQ::Set, toJID_, payload, router_);
+ request->send();*/
+ handleSendOperationRequest(operation);
+ }
+
+ void WhiteboardSession::sendPayload(boost::shared_ptr<WhiteboardPayload> payload) {
+ boost::shared_ptr<GenericRequest<WhiteboardPayload> > request = boost::make_shared<GenericRequest<WhiteboardPayload> >(IQ::Set, toJID_, payload, router_);
+ request->send();
+ }
+
void WhiteboardSession::cancel() {
boost::shared_ptr<WhiteboardPayload> payload = boost::make_shared<WhiteboardPayload>(WhiteboardPayload::SessionTerminate);
boost::shared_ptr<GenericRequest<WhiteboardPayload> > request = boost::make_shared<GenericRequest<WhiteboardPayload> >(IQ::Set, toJID_, payload, router_);
diff --git a/Swiften/Whiteboard/WhiteboardSession.h b/Swiften/Whiteboard/WhiteboardSession.h
index 0d10af3..7fb03e6 100644
--- a/Swiften/Whiteboard/WhiteboardSession.h
+++ b/Swiften/Whiteboard/WhiteboardSession.h
@@ -12,6 +12,7 @@
#include <Swiften/Base/boost_bsignals.h>
#include <Swiften/Queries/GenericRequest.h>
#include <Swiften/Whiteboard/Elements/WhiteboardElement.h>
+#include <Swiften/Whiteboard/Operations/WhiteboardOperation.h>
namespace Swift {
class IQRouter;
@@ -27,18 +28,26 @@ namespace Swift {
virtual ~WhiteboardSession();
void handleIncomingAction(boost::shared_ptr<WhiteboardPayload> payload);
void sendElement(const WhiteboardElement::ref element);
+ void sendOperation(WhiteboardOperation::ref operation);
void cancel();
const JID& getTo() const;
virtual std::string getClientID() const = 0;
public:
- boost::signal< void(const WhiteboardElement::ref element)> onElementReceived;
+ boost::signal< void(const WhiteboardElement::ref element)> onElementReceived;
+ boost::signal< void(const WhiteboardOperation::ref operation)> onOperationReceived;
boost::signal< void(const JID& contact)> onSessionTerminateReceived;
boost::signal< void(const JID& contact)> onRequestAccepted;
boost::signal< void(const JID& contact)> onSessionCancelled;
boost::signal< void(const JID& contact)> onRequestRejected;
+ private:
+ virtual void handleIncomingOperation(WhiteboardOperation::ref operation) = 0;
+ virtual void handleSendOperationRequest(WhiteboardOperation::ref operation) = 0;
+
protected:
+ void sendPayload(boost::shared_ptr<WhiteboardPayload> payload);
+
JID toJID_;
IQRouter* router_;
};