From f8f506c5b7500738abf81d74e714c7bdc3765d58 Mon Sep 17 00:00:00 2001 From: daleharvey Date: Fri, 4 Aug 2006 19:24:52 +0000 Subject: [PATCH] finalising session establishment --- src/jabber_whiteboard/defines.cpp | 47 +++++++-------------- src/jabber_whiteboard/defines.h | 28 ++---------- src/jabber_whiteboard/inkboard-document.cpp | 37 ++++++++++++---- src/jabber_whiteboard/inkboard-document.h | 3 +- src/jabber_whiteboard/session-manager.cpp | 9 ++-- 5 files changed, 55 insertions(+), 69 deletions(-) diff --git a/src/jabber_whiteboard/defines.cpp b/src/jabber_whiteboard/defines.cpp index 43a75cb7c..ca2bbab0e 100644 --- a/src/jabber_whiteboard/defines.cpp +++ b/src/jabber_whiteboard/defines.cpp @@ -21,30 +21,30 @@ namespace Whiteboard { namespace Message { - Wrapper PROTOCOL = "protocol"; - Wrapper NEW = "new"; - Wrapper REMOVE = "remove"; - Wrapper CONFIGURE = "configure"; - Wrapper MOVE = "move"; - - Message CONNECT_REQUEST = "connect-request"; - Message CONNECTED = "connected"; - Message ACCEPT_INVITATION = "accept-invitation"; - Message DECLINE_INVITATION = "decline-invitation"; - Message DOCUMENT_BEGIN = "document-begin"; - Message DOCUMENT_END = "document-end"; + Wrapper PROTOCOL ("protocol"); + Wrapper NEW ("new"); + Wrapper REMOVE ("remove"); + Wrapper CONFIGURE ("configure"); + Wrapper MOVE ("move"); + + Message CONNECT_REQUEST ("connect-request"); + Message CONNECTED ("connected"); + Message ACCEPT_INVITATION ("accept-invitation"); + Message DECLINE_INVITATION ("decline-invitation"); + Message DOCUMENT_BEGIN ("document-begin"); + Message DOCUMENT_END ("document-end"); } namespace Vars { - char const* INKBOARD_XMLNS = "http://inkscape.org/inkboard"; + const std::string INKBOARD_XMLNS("http://inkscape.org/inkboard"); } namespace State { - SessionType WHITEBOARD_MUC = "groupchat"; - SessionType WHITEBOARD_PEER = "chat"; + SessionType WHITEBOARD_MUC ("groupchat"); + SessionType WHITEBOARD_PEER ("chat"); } @@ -75,23 +75,6 @@ char const* DOCUMENT_NAMEDVIEW_NODE = "NAMEDVIEW"; char const* DOCUMENT_ROOT_NAME = "svg:svg"; char const* DOCUMENT_NAMEDVIEW_NAME = "sodipodi:namedview"; -// Inkboard client states -int const IN_WHITEBOARD = 0; -int const LOGGED_IN = 1; -int const IN_CHATROOM = 2; -int const WAITING_FOR_INVITE_RESPONSE = 3; -int const CONNECTING_TO_CHAT = 4; -int const WAITING_TO_SYNC_TO_CHAT = 5; -int const SYNCHRONIZING_WITH_CHAT = 6; -int const OPEN_FOR_DOC = 7; -int const PLAYING_SESSION_FILE = 8; - -// TODO: make this user-configurable, within sane limits -// ("sane" limits being roughly in the range (10, 100], from personal testing) -// Based on discussions with Ted, it seems that we're going to make the Jabber guys -// accomodate Inkscape, not the other way around... -// Dispatch interval (in milliseconds) -int const SEND_TIMEOUT = 35; } } diff --git a/src/jabber_whiteboard/defines.h b/src/jabber_whiteboard/defines.h index e1cc8cb8b..19b87624b 100644 --- a/src/jabber_whiteboard/defines.h +++ b/src/jabber_whiteboard/defines.h @@ -67,8 +67,8 @@ namespace Whiteboard { namespace Message { - typedef char const* Wrapper; - typedef char const* Message; + typedef const std::string Wrapper; + typedef const std::string Message; extern Wrapper PROTOCOL; extern Wrapper NEW; @@ -87,13 +87,13 @@ namespace Message { namespace Vars { - extern char const* INKBOARD_XMLNS; + extern const std::string INKBOARD_XMLNS; } namespace State { - typedef char const* SessionType; + typedef const std::string SessionType; extern SessionType WHITEBOARD_MUC; extern SessionType WHITEBOARD_PEER; @@ -233,26 +233,6 @@ extern char const* DOCUMENT_NAMEDVIEW_NODE; extern char const* DOCUMENT_ROOT_NAME; extern char const* DOCUMENT_NAMEDVIEW_NAME; -// Inkboard client states -extern int const IN_WHITEBOARD; -extern int const LOGGED_IN; -extern int const IN_CHATROOM; -extern int const WAITING_FOR_INVITE_RESPONSE; -extern int const CONNECTING_TO_CHAT; -extern int const WAITING_TO_SYNC_TO_CHAT; -extern int const SYNCHRONIZING_WITH_CHAT; -extern int const OPEN_FOR_DOC; -extern int const PLAYING_SESSION_FILE; - -// update this if any other status flags are added - -// TODO: make this user-configurable, within sane limits -// ("sane" limits being roughly in the range (10, 100], from personal testing) -// Based on discussions with Ted, it seems that we're going to make the Jabber guys -// accomodate Inkscape, not the other way around... -// Dispatch interval (in milliseconds) -extern int const SEND_TIMEOUT; - } } diff --git a/src/jabber_whiteboard/inkboard-document.cpp b/src/jabber_whiteboard/inkboard-document.cpp index e8baee4c7..e9363ecd9 100644 --- a/src/jabber_whiteboard/inkboard-document.cpp +++ b/src/jabber_whiteboard/inkboard-document.cpp @@ -65,7 +65,14 @@ InkboardDocument::getSessionId() const void InkboardDocument::startSessionNegotiation() { - sendProtocol(_recipient, Message::PROTOCOL,Message::CONNECT_REQUEST); + if(_type == State::WHITEBOARD_PEER) + sendProtocol(_recipient, Message::PROTOCOL,Message::CONNECT_REQUEST); + + else if(_type == State::WHITEBOARD_MUC) + { + // Check that the MUC room is whiteboard enabled, if not no need to send + // anything, just set the room to be whiteboard enabled + } } void @@ -81,13 +88,26 @@ InkboardDocument::processInkboardEvent(Message::Wrapper &wrapper, Pedro::Element { if(wrapper == Message::PROTOCOL) { - if(data->exists(Message::ACCEPT_INVITATION)); + Glib::ustring message = data->getFirstChild()->getFirstChild()->getFirstChild()->getName(); + + if(message == Message::CONNECT_REQUEST) + { + // An MUC member requesting document + + }else if(message == Message::ACCEPT_INVITATION) { - // TODO : Would be nice to create the desktp + // TODO : Would be nice to create the desktop here sendProtocol(getRecipient(),Message::PROTOCOL, Message::CONNECTED); sendProtocol(getRecipient(),Message::PROTOCOL, Message::DOCUMENT_BEGIN); + + // Send the Document + sendProtocol(getRecipient(),Message::PROTOCOL, Message::DOCUMENT_END); + + }else if(message == Message::DECLINE_INVITATION) + { + this->_sm->terminateSession(this->getSessionId()); } } }else{ @@ -98,7 +118,7 @@ InkboardDocument::processInkboardEvent(Message::Wrapper &wrapper, Pedro::Element bool InkboardDocument::sendProtocol(const Glib::ustring &destJid, Message::Wrapper &wrapper, - Message::Message message) + Message::Message &message) { if(this->handleOutgoingState(wrapper,message)) { @@ -112,8 +132,8 @@ InkboardDocument::sendProtocol(const Glib::ustring &destJid, Message::Wrapper &w ""; if (!_sm->getClient().write(fmt, - _type,_sm->getClient().getJid().c_str(),destJid.c_str(),Vars::INKBOARD_XMLNS, - this->getSessionId().c_str(),wrapper,message,wrapper)) + _type.c_str(),_sm->getClient().getJid().c_str(),destJid.c_str(),Vars::INKBOARD_XMLNS.c_str(), + this->getSessionId().c_str(),wrapper.c_str(),message.c_str(),wrapper.c_str())) { return false; } else @@ -121,7 +141,7 @@ InkboardDocument::sendProtocol(const Glib::ustring &destJid, Message::Wrapper &w }else { - g_warning("Sending Message in invalid state message=%s , state=%d",message,this->state); + g_warning("Sending Message in invalid state message=%s , state=%d",message.c_str(),this->state); return false; } } @@ -164,7 +184,8 @@ InkboardDocument::handleIncomingState(Message::Wrapper &wrapper, Pedro::Element* { Glib::ustring message = data->getFirstChild()->getFirstChild()->getFirstChild()->getName(); - // Connect Requests are handled in SessionManager + if(message == Message::CONNECT_REQUEST) + return this->handleState(State::INITIAL,State::CONNECTING); 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 fcd3bab6a..9eff38003 100644 --- a/src/jabber_whiteboard/inkboard-document.h +++ b/src/jabber_whiteboard/inkboard-document.h @@ -46,8 +46,7 @@ public: void terminateSession(); void processInkboardEvent(Message::Wrapper &wrapper, Pedro::Element* data); - bool sendProtocol(const Glib::ustring &destJid, Message::Wrapper &mwrapper, - Message::Message message); + bool sendProtocol(const Glib::ustring &destJid, Message::Wrapper &mwrapper, Message::Message &message); bool handleOutgoingState(Message::Wrapper &wrapper,Glib::ustring const& message); bool handleIncomingState(Message::Wrapper &wrapper,Pedro::Element* data); diff --git a/src/jabber_whiteboard/session-manager.cpp b/src/jabber_whiteboard/session-manager.cpp index 55b41ac20..3dcb8e217 100644 --- a/src/jabber_whiteboard/session-manager.cpp +++ b/src/jabber_whiteboard/session-manager.cpp @@ -234,6 +234,7 @@ SessionManager::processWhiteboardEvent(Pedro::XmppEvent const& event) } Pedro::DOMString session = root->getTagAttribute("wb", "session"); + Pedro::DOMString type = root->getTagAttribute("session", "type"); Pedro::DOMString domwrapper = root->getFirstChild()->getFirstChild()->getFirstChild()->getName(); if (session.empty()) { @@ -241,15 +242,17 @@ SessionManager::processWhiteboardEvent(Pedro::XmppEvent const& event) return; } - if(root->exists(Message::CONNECT_REQUEST)) + if(root->exists(Message::CONNECT_REQUEST) && type == State::WHITEBOARD_PEER) + { handleIncomingInvitation(Invitation(event.getFrom(),session)); - else + }else { - Message::Wrapper wrapper = static_cast< Message::Wrapper >("protocol"); + Message::Wrapper wrapper = static_cast< Message::Wrapper >(domwrapper); InkboardDocument* doc = getInkboardSession(session); doc->processInkboardEvent(wrapper, root->getFirstChild()); } + } char* -- 2.30.2