summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Swiften/Whiteboard/UnitTest/WhiteboardClientTest.cpp108
-rw-r--r--Swiften/Whiteboard/WhiteboardClient.cpp22
-rw-r--r--Swiften/Whiteboard/WhiteboardClient.h6
3 files changed, 71 insertions, 65 deletions
diff --git a/Swiften/Whiteboard/UnitTest/WhiteboardClientTest.cpp b/Swiften/Whiteboard/UnitTest/WhiteboardClientTest.cpp
index e30bd4e..1b89ae4 100644
--- a/Swiften/Whiteboard/UnitTest/WhiteboardClientTest.cpp
+++ b/Swiften/Whiteboard/UnitTest/WhiteboardClientTest.cpp
@@ -34,9 +34,9 @@ public:
WhiteboardClient client;
WhiteboardInsertOperation::ref serverOp;
serverOp = createInsertOperation("0", "", 0);
- std::pair<WhiteboardOperation::ref, WhiteboardOperation::ref> pairResult = client.handleServerOperationReceived(serverOp);
- CPPUNIT_ASSERT_EQUAL(serverOp, boost::dynamic_pointer_cast<WhiteboardInsertOperation>(pairResult.first));
- CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.second);
+ WhiteboardClient::Result pairResult = client.handleServerOperationReceived(serverOp);
+ CPPUNIT_ASSERT_EQUAL(serverOp, boost::dynamic_pointer_cast<WhiteboardInsertOperation>(pairResult.client));
+ CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.server);
//Client receives first local operation, because it's parented off "0" which exists
//in server history and client doesn't wait for any operation ack from server,
@@ -57,8 +57,8 @@ public:
WhiteboardEllipseElement::ref bElement = boost::make_shared<WhiteboardEllipseElement>(0,0,0,0);
serverOp->setElement(bElement);
pairResult = client.handleServerOperationReceived(serverOp);
- checkOperation(pairResult.first, "b", "a", 2, bElement);
- CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.second);
+ checkOperation(pairResult.client, "b", "a", 2, bElement);
+ CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.server);
//Client receives confirmation from the server about processed "a" operation, it had to
//be transformed against "b" on the server side to receive operation parented off "b".
@@ -67,8 +67,8 @@ public:
serverOp = createInsertOperation("a", "b", 1);
serverOp->setOrigin(WhiteboardOperation::Other);
pairResult = client.handleServerOperationReceived(serverOp);
- CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.first);
- CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.second);
+ CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.client);
+ CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.server);
//Client receives local operation, it doesn't have to be transformed against anything
//but operation returned to send to the server should be parented off last server
@@ -86,8 +86,8 @@ public:
clientOp->setOrigin(WhiteboardOperation::Local);
clientOp->setElement(cElement);
pairResult = client.handleServerOperationReceived(clientOp);
- CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.first);
- CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.second);
+ CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.client);
+ CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.server);
//Results:
//Client operations:
@@ -116,9 +116,9 @@ public:
WhiteboardClient client;
WhiteboardInsertOperation::ref serverOp;
serverOp = createInsertOperation("0", "", 0);
- std::pair<WhiteboardOperation::ref, WhiteboardOperation::ref> pairResult = client.handleServerOperationReceived(serverOp);
- CPPUNIT_ASSERT_EQUAL(serverOp, boost::dynamic_pointer_cast<WhiteboardInsertOperation>(pairResult.first));
- CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.second);
+ WhiteboardClient::Result pairResult = client.handleServerOperationReceived(serverOp);
+ CPPUNIT_ASSERT_EQUAL(serverOp, boost::dynamic_pointer_cast<WhiteboardInsertOperation>(pairResult.client));
+ CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.server);
//Client receives first local operation, because it's parented off "0" which exists
//in server history and client doesn't wait for any operation ack from server,
@@ -144,8 +144,8 @@ public:
clientOp->setOrigin(WhiteboardOperation::Local);
clientOp->setElement(cElement);
pairResult = client.handleServerOperationReceived(clientOp);
- checkOperation(pairResult.second, "d", "c", 2, dElement);
- CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.first);
+ checkOperation(pairResult.server, "d", "c", 2, dElement);
+ CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.client);
//Client receives confirmation about processing "d", it should be the same as
//sent operation. There aren't any operations in queue to send.
@@ -153,8 +153,8 @@ public:
clientOp->setOrigin(WhiteboardOperation::Local);
clientOp->setElement(dElement);
pairResult = client.handleServerOperationReceived(clientOp);
- CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.first);
- CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.second);
+ CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.client);
+ CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.server);
//Client receives new operation from server, it's parented off "d" which is at
//the end of local history so it doesn't have to be transformed, so operation
@@ -163,9 +163,9 @@ public:
WhiteboardEllipseElement::ref eElement = boost::make_shared<WhiteboardEllipseElement>(0,0,0,0);
serverOp->setElement(eElement);
pairResult = client.handleServerOperationReceived(serverOp);
- WhiteboardInsertOperation::ref result = boost::dynamic_pointer_cast<WhiteboardInsertOperation>(pairResult.first);
- CPPUNIT_ASSERT_EQUAL(serverOp, boost::dynamic_pointer_cast<WhiteboardInsertOperation>(pairResult.first));
- CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.second);
+ WhiteboardInsertOperation::ref result = boost::dynamic_pointer_cast<WhiteboardInsertOperation>(pairResult.client);
+ CPPUNIT_ASSERT_EQUAL(serverOp, boost::dynamic_pointer_cast<WhiteboardInsertOperation>(pairResult.client));
+ CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.server);
//Client operations:
@@ -193,9 +193,9 @@ public:
WhiteboardClient client;
WhiteboardInsertOperation::ref serverOp;
serverOp = createInsertOperation("0", "", 0);
- std::pair<WhiteboardOperation::ref, WhiteboardOperation::ref> pairResult = client.handleServerOperationReceived(serverOp);
- CPPUNIT_ASSERT_EQUAL(serverOp, boost::dynamic_pointer_cast<WhiteboardInsertOperation>(pairResult.first));
- CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.second);
+ WhiteboardClient::Result pairResult = client.handleServerOperationReceived(serverOp);
+ CPPUNIT_ASSERT_EQUAL(serverOp, boost::dynamic_pointer_cast<WhiteboardInsertOperation>(pairResult.client));
+ CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.server);
//Client receives first local operation, because it's parented off "0" which exists
//in server history and client doesn't wait for any operation ack from server,
@@ -223,8 +223,8 @@ public:
WhiteboardEllipseElement::ref cElement = boost::make_shared<WhiteboardEllipseElement>(0,0,0,0);
serverOp->setElement(cElement);
pairResult = client.handleServerOperationReceived(serverOp);
- checkOperation(pairResult.first, "c", "b", 3, cElement);
- CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.second);
+ checkOperation(pairResult.client, "c", "b", 3, cElement);
+ CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.server);
//Client receives new operation from server, it should be transformed against
//results of previous transformations, returned operation should be parented off
@@ -235,16 +235,16 @@ public:
WhiteboardEllipseElement::ref dElement = boost::make_shared<WhiteboardEllipseElement>(0,0,0,0);
serverOp->setElement(dElement);
pairResult = client.handleServerOperationReceived(serverOp);
- checkOperation(pairResult.first, "d", "c", 4, dElement);
- CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.second);
+ checkOperation(pairResult.client, "d", "c", 4, dElement);
+ CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.server);
//Client receives confirmation about processing "a", it should send next operation
//to server which is "b", but it should be version parented of transformed "a"
serverOp = createInsertOperation("a", "d", 1);
serverOp->setOrigin(WhiteboardOperation::Other);
pairResult = client.handleServerOperationReceived(serverOp);
- checkOperation(pairResult.second, "b", "a", 2, bElement);
- CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.first);
+ checkOperation(pairResult.server, "b", "a", 2, bElement);
+ CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.client);
//Client receives confirmation about processing "b", there aren't any operations
@@ -252,8 +252,8 @@ public:
serverOp = createInsertOperation("b", "a", 2);
serverOp->setOrigin(WhiteboardOperation::Other);
pairResult = client.handleServerOperationReceived(serverOp);
- CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.first);
- CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.second);
+ CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.client);
+ CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.server);
//Client operations:
//ID pos
@@ -285,9 +285,9 @@ public:
WhiteboardClient client;
WhiteboardInsertOperation::ref serverOp;
serverOp = createInsertOperation("0", "", 0);
- std::pair<WhiteboardOperation::ref, WhiteboardOperation::ref> pairResult = client.handleServerOperationReceived(serverOp);
- CPPUNIT_ASSERT_EQUAL(serverOp, boost::dynamic_pointer_cast<WhiteboardInsertOperation>(pairResult.first));
- CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.second);
+ WhiteboardClient::Result pairResult = client.handleServerOperationReceived(serverOp);
+ CPPUNIT_ASSERT_EQUAL(serverOp, boost::dynamic_pointer_cast<WhiteboardInsertOperation>(pairResult.client));
+ CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.server);
//Client receives first local operation, because it's parented off "0" which exists
//in server history and client doesn't wait for any operation ack from server,
@@ -315,8 +315,8 @@ public:
WhiteboardEllipseElement::ref cElement = boost::make_shared<WhiteboardEllipseElement>(0,0,0,0);
serverOp->setElement(cElement);
pairResult = client.handleServerOperationReceived(serverOp);
- checkOperation(pairResult.first, "c", "b", 3, cElement);
- CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.second);
+ checkOperation(pairResult.client, "c", "b", 3, cElement);
+ CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.server);
//Client receives new local operation, client is still waiting for ack so, it
//should return nothing
@@ -334,8 +334,8 @@ public:
WhiteboardEllipseElement::ref dElement = boost::make_shared<WhiteboardEllipseElement>(0,0,0,0);
serverOp->setElement(dElement);
pairResult = client.handleServerOperationReceived(serverOp);
- checkOperation(pairResult.first, "d", "e", 5, dElement);
- CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.second);
+ checkOperation(pairResult.client, "d", "e", 5, dElement);
+ CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.server);
//Client receives confirmation about processing "a", it had to be transformed against
//"c" and "d" and it is now parented off "d", returned value should be next operation
@@ -343,9 +343,9 @@ public:
serverOp = createInsertOperation("a", "d", 1);
serverOp->setOrigin(WhiteboardOperation::Other);
pairResult = client.handleServerOperationReceived(serverOp);
- checkOperation(pairResult.second, "b", "a", 2, bElement);
+ checkOperation(pairResult.server, "b", "a", 2, bElement);
// CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::Other, result->getOrigin());
- CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.first);
+ CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.client);
//Client receives confirmation about processing "b", it is the same operation as sent because
//it didn't have to be transformed, returned value should be next operation
@@ -353,9 +353,9 @@ public:
serverOp = createInsertOperation("b", "a", 2);
serverOp->setOrigin(WhiteboardOperation::Other);
pairResult = client.handleServerOperationReceived(serverOp);
- checkOperation(pairResult.second, "e", "b", 4, eElement);
+ checkOperation(pairResult.server, "e", "b", 4, eElement);
// CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::Other, result->getOrigin());
- CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.first);
+ CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.client);
//Client receives confirmation about processing "b", it is the same operation as sent because
//it didn't have to be transformed, there aren't any operations to send so this function returns
@@ -363,8 +363,8 @@ public:
serverOp = createInsertOperation("e", "b", 4);
serverOp->setOrigin(WhiteboardOperation::Other);
pairResult = client.handleServerOperationReceived(serverOp);
- CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.first);
- CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.second);
+ CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.client);
+ CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.server);
//Result:
//Client operations:
@@ -396,9 +396,9 @@ public:
WhiteboardClient client;
WhiteboardInsertOperation::ref serverOp;
serverOp = createInsertOperation("0", "", 0);
- std::pair<WhiteboardOperation::ref, WhiteboardOperation::ref> pairResult = client.handleServerOperationReceived(serverOp);
- CPPUNIT_ASSERT_EQUAL(serverOp, boost::dynamic_pointer_cast<WhiteboardInsertOperation>(pairResult.first));
- CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.second);
+ WhiteboardClient::Result pairResult = client.handleServerOperationReceived(serverOp);
+ CPPUNIT_ASSERT_EQUAL(serverOp, boost::dynamic_pointer_cast<WhiteboardInsertOperation>(pairResult.client));
+ CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.server);
//Client receives first local operation, because it's parented off "0" which exists
//in server history and client doesn't wait for any operation ack from server,
@@ -426,8 +426,8 @@ public:
WhiteboardEllipseElement::ref cElement = boost::make_shared<WhiteboardEllipseElement>(0,0,0,0);
serverOp->setElement(cElement);
pairResult = client.handleServerOperationReceived(serverOp);
- checkOperation(pairResult.first, "c", "b", 3, cElement);
- CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.second);
+ checkOperation(pairResult.client, "c", "b", 3, cElement);
+ CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.server);
//Client receives confirmation about processing "a", it had to be transformed against
//"c" and it is now parented off "c", returned value should be next operation
@@ -436,9 +436,9 @@ public:
serverOp->setOrigin(WhiteboardOperation::Other);
serverOp->setElement(aElement);
pairResult = client.handleServerOperationReceived(serverOp);
- checkOperation(pairResult.second, "b", "a", 2, bElement);
+ checkOperation(pairResult.server, "b", "a", 2, bElement);
// CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::Other, result->getOrigin());
- CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.first);
+ CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.client);
//Client receives new server operation, to add it to local history it should be transformed
//against result of previous transformation(but only with transformation of "b"), returned
@@ -448,8 +448,8 @@ public:
WhiteboardEllipseElement::ref dElement = boost::make_shared<WhiteboardEllipseElement>(0,0,0,0);
serverOp->setElement(dElement);
pairResult = client.handleServerOperationReceived(serverOp);
- checkOperation(pairResult.first, "d", "c", 4, dElement);
- CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.second);
+ checkOperation(pairResult.client, "d", "c", 4, dElement);
+ CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.server);
//Client receives confirmation about processing "b", it had to be transformed against
//"d" because both operations was parented off server version of "a".
@@ -458,8 +458,8 @@ public:
serverOp->setElement(bElement);
serverOp->setOrigin(WhiteboardOperation::Other);
pairResult = client.handleServerOperationReceived(serverOp);
- CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.first);
- CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.second);
+ CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.client);
+ CPPUNIT_ASSERT_EQUAL(WhiteboardOperation::ref(), pairResult.server);
//Client operations:
//ID pos
diff --git a/Swiften/Whiteboard/WhiteboardClient.cpp b/Swiften/Whiteboard/WhiteboardClient.cpp
index 447e5de..9610247 100644
--- a/Swiften/Whiteboard/WhiteboardClient.cpp
+++ b/Swiften/Whiteboard/WhiteboardClient.cpp
@@ -31,15 +31,17 @@ namespace Swift {
}
}
- std::pair<WhiteboardOperation::ref, WhiteboardOperation::ref> WhiteboardClient::handleServerOperationReceived(WhiteboardOperation::ref operation) {
+ WhiteboardClient::Result WhiteboardClient::handleServerOperationReceived(WhiteboardOperation::ref operation) {
serverOperations_.push_back(operation);
- WhiteboardOperation::ref clientOp;
- WhiteboardOperation::ref serverOp;
+// WhiteboardOperation::ref clientOp;
+// WhiteboardOperation::ref serverOp;
+ Result result;
// if (localOperations_.empty()) {// || localOperations_.back()->getID() == operation->getParentID()) {
//Situation where client and server are in sync
if (localOperations_.size() == serverOperations_.size()-1) {
localOperations_.push_back(operation);
- clientOp = operation;
+// clientOp = operation;
+ result.client = operation;
} else if (lastSentOperationID_ == operation->getID()) {
//Client received confirmation about own operation and it sends next operation to server
if (bridge_.size() > 0 && lastSentOperationID_ == bridge_.front()->getID()) {
@@ -57,11 +59,11 @@ namespace Swift {
if (bridge_.size() > 0 && (bridge_.front())->getParentID() == lastSentOperationID_) {
lastSentOperationID_ = (bridge_.front())->getID();
- serverOp = bridge_.front();
- serverOp->setOrigin(WhiteboardOperation::Other);
+ result.server = bridge_.front();
+ result.server->setOrigin(WhiteboardOperation::Other);
}
- if (!serverOp) {
+ if (!result.server) {
lastSentOperationID_.clear();
}
} else {
@@ -85,7 +87,7 @@ namespace Swift {
temp->setParentID(localOperations_.back()->getID());
localOperations_.push_back(temp);
- clientOp = temp;
+ result.client = temp;
} else {
//doesn't get executed
std::list<WhiteboardOperation::ref>::reverse_iterator it;
@@ -102,7 +104,7 @@ namespace Swift {
bridge_.push_back(opPair.second);
if (it == localOperations_.rbegin()) {
localOperations_.push_back(temp);
- clientOp = temp;
+ result.client = temp;
end = true;
break;
} else {
@@ -116,7 +118,7 @@ namespace Swift {
}
}
- return std::pair<WhiteboardOperation::ref, WhiteboardOperation::ref>(clientOp, serverOp);
+ return result;
}
void WhiteboardClient::print() {
diff --git a/Swiften/Whiteboard/WhiteboardClient.h b/Swiften/Whiteboard/WhiteboardClient.h
index e720d37..066ba9e 100644
--- a/Swiften/Whiteboard/WhiteboardClient.h
+++ b/Swiften/Whiteboard/WhiteboardClient.h
@@ -13,6 +13,10 @@
namespace Swift {
class WhiteboardClient {
public:
+ struct Result {
+ WhiteboardOperation::ref client;
+ WhiteboardOperation::ref server;
+ };
/*!
* @return Operation to send
*/
@@ -20,7 +24,7 @@ namespace Swift {
/*!
* @return pair.first-element to handle locally, pair.second-element to send to server
*/
- std::pair<WhiteboardOperation::ref, WhiteboardOperation::ref> handleServerOperationReceived(WhiteboardOperation::ref operation);
+ Result handleServerOperationReceived(WhiteboardOperation::ref operation);
void print();
private: