diff options
author | Mateusz Piekos <mateuszpiekos@gmail.com> | 2012-07-13 18:18:37 (GMT) |
---|---|---|
committer | Mateusz Piekos <mateuszpiekos@gmail.com> | 2012-07-13 18:18:37 (GMT) |
commit | 0ba890e7e8c7e09c1257a7c3b1018f396e6896d1 (patch) | |
tree | 13dc4658023e89d48d4e7ae1854f70e827bf9cf6 /Swiften/Whiteboard | |
parent | 4dc0788b78da3fe5a9daed5ab4593ba6423600ec (diff) | |
download | swift-contrib-0ba890e7e8c7e09c1257a7c3b1018f396e6896d1.zip swift-contrib-0ba890e7e8c7e09c1257a7c3b1018f396e6896d1.tar.bz2 |
Integrated WhiteboardClient and WhiteboardServer into rest of the code
Diffstat (limited to 'Swiften/Whiteboard')
-rw-r--r-- | Swiften/Whiteboard/Elements/WhiteboardElement.h | 2 | ||||
-rw-r--r-- | Swiften/Whiteboard/IncomingWhiteboardSession.cpp | 24 | ||||
-rw-r--r-- | Swiften/Whiteboard/IncomingWhiteboardSession.h | 8 | ||||
-rw-r--r-- | Swiften/Whiteboard/OutgoingWhiteboardSession.cpp | 29 | ||||
-rw-r--r-- | Swiften/Whiteboard/OutgoingWhiteboardSession.h | 6 | ||||
-rw-r--r-- | Swiften/Whiteboard/WhiteboardSession.cpp | 18 | ||||
-rw-r--r-- | Swiften/Whiteboard/WhiteboardSession.h | 11 |
7 files changed, 94 insertions, 4 deletions
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_; }; |