From 2f28e64dad69a5273843d2619f30125cce3a31ff Mon Sep 17 00:00:00 2001 From: daleharvey Date: Thu, 3 Aug 2006 17:52:16 +0000 Subject: [PATCH] work on jabber_whiteboard --- src/jabber_whiteboard/inkboard-document.cpp | 47 +++++--- src/jabber_whiteboard/inkboard-document.h | 9 +- src/jabber_whiteboard/session-manager.cpp | 119 ++++++++++---------- 3 files changed, 98 insertions(+), 77 deletions(-) diff --git a/src/jabber_whiteboard/inkboard-document.cpp b/src/jabber_whiteboard/inkboard-document.cpp index 514b3acc4..c46546ebc 100644 --- a/src/jabber_whiteboard/inkboard-document.cpp +++ b/src/jabber_whiteboard/inkboard-document.cpp @@ -75,14 +75,29 @@ InkboardDocument::terminateSession() } void -InkboardDocument::processInkboardEvent(Message::Wrapper mtype, Glib::ustring const& data) +InkboardDocument::processInkboardEvent(Message::Wrapper &wrapper, Pedro::Element* data) { - g_log(NULL, G_LOG_LEVEL_DEBUG, "Processing Inkboard event: mtype=%s data=%s\n",mtype,data.c_str()); - + if(this->handleIncomingState(wrapper,data)) + { + if(wrapper == Message::PROTOCOL) + { + if(data->exists(Message::ACCEPT_INVITATION)); + { + // TODO : Would be nice to create the desktop here + + sendProtocol(getRecipient(),Message::PROTOCOL, Message::CONNECTED); + sendProtocol(getRecipient(),Message::PROTOCOL, Message::DOCUMENT_BEGIN); + sendProtocol(getRecipient(),Message::PROTOCOL, Message::DOCUMENT_END); + } + } + }else{ + g_warning("Recieved Message in invalid state = %d", this->state); + data->print(); + } } bool -InkboardDocument::sendProtocol(const Glib::ustring &destJid, Message::Wrapper wrapper, +InkboardDocument::sendProtocol(const Glib::ustring &destJid, Message::Wrapper &wrapper, Message::Message message) { if(this->handleOutgoingState(wrapper,message)) @@ -99,19 +114,22 @@ InkboardDocument::sendProtocol(const Glib::ustring &destJid, Message::Wrapper wr if (!_sm->getClient().write(fmt, _type,_sm->getClient().getJid().c_str(),destJid.c_str(),Vars::INKBOARD_XMLNS, - this->getSessionId().c_str(),wrapper,message,wrapper)) - return false; + this->getSessionId().c_str(),wrapper,message,wrapper)) + { return false; } - return true; + else + { return true; } - }else - return false; + }else + { + g_warning("Sending Message in invalid state message=%s , state=%d",message,this->state); + return false; + } } bool -InkboardDocument::handleOutgoingState(Message::Wrapper wrapper,Message::Message message) +InkboardDocument::handleOutgoingState(Message::Wrapper &wrapper, Glib::ustring const& message) { - g_warning("state %d, message %s",this->state,message); if(wrapper == Message::PROTOCOL) { if(message == Message::CONNECT_REQUEST) @@ -126,8 +144,9 @@ InkboardDocument::handleOutgoingState(Message::Wrapper wrapper,Message::Message else if(message == Message::DOCUMENT_BEGIN) return this->handleState(State::CONNECTED,State::SYNCHRONISING); - else if(message == Message::DOCUMENT_END) + else if(message == Message::DOCUMENT_END) { return this->handleState(State::SYNCHRONISING,State::IN_WHITEBOARD); + } else return false; @@ -140,10 +159,12 @@ InkboardDocument::handleOutgoingState(Message::Wrapper wrapper,Message::Message } bool -InkboardDocument::handleIncomingState(Message::Wrapper wrapper,Glib::ustring const& message) +InkboardDocument::handleIncomingState(Message::Wrapper &wrapper, Pedro::Element* data) { if(wrapper == Message::PROTOCOL) { + Glib::ustring message = data->getFirstChild()->getFirstChild()->getFirstChild()->getName(); + // Connect Requests are handled in SessionManager if(message == Message::ACCEPT_INVITATION) return this->handleState(State::AWAITING_INVITATION_REPLY,State::INVITATION_RECIEVED); diff --git a/src/jabber_whiteboard/inkboard-document.h b/src/jabber_whiteboard/inkboard-document.h index c09640852..4f0f05e07 100644 --- a/src/jabber_whiteboard/inkboard-document.h +++ b/src/jabber_whiteboard/inkboard-document.h @@ -14,6 +14,7 @@ #include +#include "document.h" #include "xml/document.h" #include "xml/simple-node.h" #include "jabber_whiteboard/defines.h" @@ -43,13 +44,13 @@ public: void startSessionNegotiation(); void terminateSession(); - void processInkboardEvent(Message::Wrapper mtype, Glib::ustring const& data); + void processInkboardEvent(Message::Wrapper &wrapper, Pedro::Element* data); - bool sendProtocol(const Glib::ustring &destJid, Message::Wrapper mwrapper, + bool sendProtocol(const Glib::ustring &destJid, Message::Wrapper &mwrapper, Message::Message message); - bool handleOutgoingState(Message::Wrapper wrapper,Message::Message message); - bool handleIncomingState(Message::Wrapper wrapper,Glib::ustring const& message); + bool handleOutgoingState(Message::Wrapper &wrapper,Glib::ustring const& message); + bool handleIncomingState(Message::Wrapper &wrapper,Pedro::Element* data); bool handleState(State::SessionState expectedState, State::SessionState newstate); diff --git a/src/jabber_whiteboard/session-manager.cpp b/src/jabber_whiteboard/session-manager.cpp index 7ca490212..ef842e339 100644 --- a/src/jabber_whiteboard/session-manager.cpp +++ b/src/jabber_whiteboard/session-manager.cpp @@ -85,62 +85,6 @@ SessionManager::~SessionManager() getClient().disconnect(); } -void -SessionManager::processXmppEvent(const Pedro::XmppEvent &event) -{ - int type = event.getType(); - - switch (type) { - case Pedro::XmppEvent::EVENT_STATUS: - { - break; - } - case Pedro::XmppEvent::EVENT_ERROR: - { - break; - } - case Pedro::XmppEvent::EVENT_CONNECTED: - { - break; - } - case Pedro::XmppEvent::EVENT_DISCONNECTED: - { - break; - } - case Pedro::XmppEvent::EVENT_MUC_MESSAGE: - case Pedro::XmppEvent::EVENT_MESSAGE: - { - g_warning("## SM message:%s\n", event.getFrom().c_str()); - Pedro::Element *root = event.getDOM(); - - if (root && root->getTagAttribute("wb", "xmlns") == Vars::INKBOARD_XMLNS) - processWhiteboardEvent(event); - - break; - } - case Pedro::XmppEvent::EVENT_PRESENCE: - { - break; - } - case Pedro::XmppEvent::EVENT_MUC_JOIN: - { - break; - } - case Pedro::XmppEvent::EVENT_MUC_LEAVE: - { - break; - } - case Pedro::XmppEvent::EVENT_MUC_PRESENCE: - { - break; - } - default: - { - break; - } - } -} - /** * Initiates a shared session with a user or conference room. * @@ -177,6 +121,7 @@ SessionManager::initialiseSession(Glib::ustring const& to, State::SessionType ty inkdoc->setSessionId(sessionId); + makeInkboardDesktop(doc); addSession(WhiteboardRecord(sessionId, inkdoc)); inkdoc->startSessionNegotiation(); @@ -217,6 +162,60 @@ SessionManager::getInkboardSession(Glib::ustring const& sessionId) return NULL; } +void +SessionManager::processXmppEvent(const Pedro::XmppEvent &event) +{ + int type = event.getType(); + + switch (type) { + case Pedro::XmppEvent::EVENT_STATUS: + { + break; + } + case Pedro::XmppEvent::EVENT_ERROR: + { + break; + } + case Pedro::XmppEvent::EVENT_CONNECTED: + { + break; + } + case Pedro::XmppEvent::EVENT_DISCONNECTED: + { + break; + } + case Pedro::XmppEvent::EVENT_MUC_MESSAGE: + case Pedro::XmppEvent::EVENT_MESSAGE: + { + Pedro::Element *root = event.getDOM(); + + if (root && root->getTagAttribute("wb", "xmlns") == Vars::INKBOARD_XMLNS) + processWhiteboardEvent(event); + + break; + } + case Pedro::XmppEvent::EVENT_PRESENCE: + { + break; + } + case Pedro::XmppEvent::EVENT_MUC_JOIN: + { + break; + } + case Pedro::XmppEvent::EVENT_MUC_LEAVE: + { + break; + } + case Pedro::XmppEvent::EVENT_MUC_PRESENCE: + { + break; + } + default: + { + break; + } + } +} /** * Handles all incoming messages from pedro within a valid namespace, CONNECT_REQUEST messages @@ -247,9 +246,9 @@ SessionManager::processWhiteboardEvent(Pedro::XmppEvent const& event) else { - Message::Wrapper wrapper = domwrapper.c_str(); + Message::Wrapper wrapper = static_cast< Message::Wrapper >("protocol"); InkboardDocument* doc = getInkboardSession(session); - doc->processInkboardEvent(wrapper, event.getData()); + doc->processInkboardEvent(wrapper, root->getFirstChild()); } } @@ -313,8 +312,8 @@ SessionManager::checkInvitationQueue() Dialog::DialogReply reply = static_cast< Dialog::DialogReply >(dialog.run()); - - SPDocument* doc = makeInkboardDocument(g_quark_from_static_string("xml"), "svg:svg", State::WHITEBOARD_PEER, from); + SPDocument* doc = makeInkboardDocument( + g_quark_from_static_string("xml"), "svg:svg", State::WHITEBOARD_PEER, from); InkboardDocument* inkdoc = dynamic_cast< InkboardDocument* >(doc->rdoc); if(inkdoc == NULL) return true; -- 2.30.2