From: daleharvey Date: Thu, 3 Aug 2006 01:55:09 +0000 (+0000) Subject: added StateHandling to whiteboard X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=4b5f0fbb80d1f807a63d2e28ab9e2ff076b35f6b;p=inkscape.git added StateHandling to whiteboard --- diff --git a/src/jabber_whiteboard/defines.h b/src/jabber_whiteboard/defines.h index e08d876a6..e1cc8cb8b 100644 --- a/src/jabber_whiteboard/defines.h +++ b/src/jabber_whiteboard/defines.h @@ -98,16 +98,28 @@ namespace State { extern SessionType WHITEBOARD_MUC; extern SessionType WHITEBOARD_PEER; - typedef char const* SessionState; + enum SessionState { + + INITIAL = 0, + AWAITING_INVITATION_REPLY = 1, + CONNECTING = 2, + INVITATION_RECIEVED = 3, + AWAITING_CONNECTED = 4, + CONNECTED = 5, + AWAITING_DOCUMENT_BEGIN = 6, + SYNCHRONISING = 7, + IN_WHITEBOARD = 8 + + }; } namespace Dialog { -enum DialogReply { + enum DialogReply { - ACCEPT_INVITATION = 0, - DECLINE_INVITATION = 1 -}; + ACCEPT_INVITATION = 0, + DECLINE_INVITATION = 1 + }; } diff --git a/src/jabber_whiteboard/inkboard-document.cpp b/src/jabber_whiteboard/inkboard-document.cpp index bf72d3c2a..514b3acc4 100644 --- a/src/jabber_whiteboard/inkboard-document.cpp +++ b/src/jabber_whiteboard/inkboard-document.cpp @@ -33,6 +33,7 @@ void InkboardDocument::_initBindings() { this->_sm = &SessionManager::instance(); + this->state = State::INITIAL; _bindDocument(*this); _bindLogger(*(new XML::SimpleSession())); } @@ -50,13 +51,13 @@ InkboardDocument::getRecipient() const } void -InkboardDocument::setSessionIdent(Glib::ustring const& val) +InkboardDocument::setSessionId(Glib::ustring const& val) { this->_session = val; } Glib::ustring -InkboardDocument::getSessionIdent() const +InkboardDocument::getSessionId() const { return this->_session; } @@ -77,29 +78,108 @@ void InkboardDocument::processInkboardEvent(Message::Wrapper mtype, Glib::ustring const& data) { g_log(NULL, G_LOG_LEVEL_DEBUG, "Processing Inkboard event: mtype=%s data=%s\n",mtype,data.c_str()); + } bool InkboardDocument::sendProtocol(const Glib::ustring &destJid, Message::Wrapper wrapper, Message::Message message) { - char *fmt= - "" - "" - "<%s>" - "<%s />" - "" - "" - " " - ""; - if (!_sm->getClient().write( - fmt,_type,_sm->getClient().getJid().c_str(),destJid.c_str(), - Vars::INKBOARD_XMLNS,this->getSessionIdent().c_str(),wrapper,message,wrapper)) + if(this->handleOutgoingState(wrapper,message)) + { + char *fmt= + "" + "" + "<%s>" + "<%s />" + "" + "" + " " + ""; + + 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; + + return true; + + }else return false; +} + +bool +InkboardDocument::handleOutgoingState(Message::Wrapper wrapper,Message::Message message) +{ + g_warning("state %d, message %s",this->state,message); + if(wrapper == Message::PROTOCOL) + { + if(message == Message::CONNECT_REQUEST) + return this->handleState(State::INITIAL,State::AWAITING_INVITATION_REPLY); + + else if(message == Message::ACCEPT_INVITATION) + return this->handleState(State::CONNECTING,State::AWAITING_CONNECTED); + + else if(message == Message::CONNECTED) + return this->handleState(State::INVITATION_RECIEVED,State::CONNECTED); + + else if(message == Message::DOCUMENT_BEGIN) + return this->handleState(State::CONNECTED,State::SYNCHRONISING); - return true; + else if(message == Message::DOCUMENT_END) + return this->handleState(State::SYNCHRONISING,State::IN_WHITEBOARD); + + else + return false; + + } else + if(this->state == State::SYNCHRONISING && wrapper == Message::NEW) + return true; + + return this->state == State::IN_WHITEBOARD; } +bool +InkboardDocument::handleIncomingState(Message::Wrapper wrapper,Glib::ustring const& message) +{ + if(wrapper == Message::PROTOCOL) + { + // Connect Requests are handled in SessionManager + if(message == Message::ACCEPT_INVITATION) + return this->handleState(State::AWAITING_INVITATION_REPLY,State::INVITATION_RECIEVED); + + else if(message == Message::CONNECTED) + return this->handleState(State::AWAITING_CONNECTED,State::AWAITING_DOCUMENT_BEGIN); + + else if(message == Message::DOCUMENT_BEGIN) + return this->handleState(State::AWAITING_DOCUMENT_BEGIN,State::SYNCHRONISING); + + else if(message == Message::DOCUMENT_END) + return this->handleState(State::SYNCHRONISING,State::IN_WHITEBOARD); + + else + return false; + + } else + if(this->state == State::SYNCHRONISING && wrapper == Message::NEW) + return true; + + return this->state == State::IN_WHITEBOARD; +} + +bool +InkboardDocument::handleState(State::SessionState expectedState, State::SessionState newState) +{ + if(this->state == expectedState) + { + this->state = newState; + return true; + } + + return false; +} + + } // namespace Whiteboard } // namespace Inkscape diff --git a/src/jabber_whiteboard/inkboard-document.h b/src/jabber_whiteboard/inkboard-document.h index 71de75e19..c09640852 100644 --- a/src/jabber_whiteboard/inkboard-document.h +++ b/src/jabber_whiteboard/inkboard-document.h @@ -38,8 +38,8 @@ public: void setRecipient(Glib::ustring const& val); Glib::ustring getRecipient() const; - void setSessionIdent(Glib::ustring const& val); - Glib::ustring getSessionIdent() const; + void setSessionId(Glib::ustring const& val); + Glib::ustring getSessionId() const; void startSessionNegotiation(); void terminateSession(); @@ -48,6 +48,10 @@ public: 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 handleState(State::SessionState expectedState, State::SessionState newstate); protected: /** @@ -72,6 +76,7 @@ private: SessionManager *_sm; State::SessionType _type; + State::SessionState state; Glib::ustring _session; Glib::ustring _recipient; diff --git a/src/jabber_whiteboard/inkboard-session.h b/src/jabber_whiteboard/inkboard-session.h index 28e844f23..9b1209e05 100644 --- a/src/jabber_whiteboard/inkboard-session.h +++ b/src/jabber_whiteboard/inkboard-session.h @@ -49,46 +49,46 @@ public: virtual void setName(const Glib::ustring &val) { _name = val; } - /** - * Returns status attributes of this session. - * - * \return Status of this session. - */ - virtual std::bitset< NUM_FLAGS > const& getStatus() const - { - return status; - } - - // - // XML::TransactionLogger methods - // - Session& session() - { - return *this; - } - - // - // XML::Session methods - // - bool inTransaction() - { - return _in_transaction; - } - - void beginTransaction(); - void rollback(); - void commit(); - - XML::Event* commitUndoable(); - - XML::Node* createElementNode(char const* name); - XML::Node* createTextNode(char const* content); - XML::Node* createCommentNode(char const* content); - - // - // XML::NodeObserver methods - // (inherited from XML::TransactionLogger) - // + /** + * Returns status attributes of this session. + * + * \return Status of this session. + */ + virtual std::bitset< NUM_FLAGS > const& getStatus() const + { + return status; + } + + // + // XML::TransactionLogger methods + // + Session& session() + { + return *this; + } + + // + // XML::Session methods + // + bool inTransaction() + { + return _in_transaction; + } + + void beginTransaction(); + void rollback(); + void commit(); + + XML::Event* commitUndoable(); + + XML::Node* createElementNode(char const* name); + XML::Node* createTextNode(char const* content); + XML::Node* createCommentNode(char const* content); + + // + // XML::NodeObserver methods + // (inherited from XML::TransactionLogger) + // void notifyChildAdded(Inkscape::XML::Node &parent, Inkscape::XML::Node &child, Inkscape::XML::Node *prev); void notifyChildRemoved(Inkscape::XML::Node &parent, Inkscape::XML::Node &child, Inkscape::XML::Node *prev); @@ -105,13 +105,14 @@ public: Util::ptr_shared new_value); private: + InkboardSession(InkboardSession const &); // no copy void operator=(InkboardSession const &); // no assign - bool _in_transaction; + bool _in_transaction; std::bitset< NUM_FLAGS > status; - Glib::ustring _name; + Glib::ustring _name; }; } diff --git a/src/jabber_whiteboard/session-manager.cpp b/src/jabber_whiteboard/session-manager.cpp index dd392c845..7ca490212 100644 --- a/src/jabber_whiteboard/session-manager.cpp +++ b/src/jabber_whiteboard/session-manager.cpp @@ -175,7 +175,7 @@ SessionManager::initialiseSession(Glib::ustring const& to, State::SessionType ty char * sessionId = createSessionId(10); - inkdoc->setSessionIdent(sessionId); + inkdoc->setSessionId(sessionId); addSession(WhiteboardRecord(sessionId, inkdoc)); @@ -315,9 +315,12 @@ SessionManager::checkInvitationQueue() 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; + inkdoc->handleState(State::INITIAL,State::CONNECTING); + inkdoc->setSessionId(sessionId); addSession(WhiteboardRecord(sessionId, inkdoc)); switch (reply) {