From: daleharvey Date: Mon, 31 Jul 2006 02:19:44 +0000 (+0000) Subject: handling recieved messages X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=53ccd8f8781a1fbad995e7c8464643fb614d0772;p=inkscape.git handling recieved messages --- diff --git a/src/jabber_whiteboard/inkboard-document.cpp b/src/jabber_whiteboard/inkboard-document.cpp index e6bd43713..e2bba2fc0 100644 --- a/src/jabber_whiteboard/inkboard-document.cpp +++ b/src/jabber_whiteboard/inkboard-document.cpp @@ -26,27 +26,39 @@ namespace Whiteboard { InkboardDocument::InkboardDocument(int code, State::SessionType type, Glib::ustring const& to) : XML::SimpleNode(code), _type(type), _recipient(to) { - _initBindings(); + _initBindings(); } void InkboardDocument::_initBindings() { - this->sm = &SessionManager::instance(); - _bindDocument(*this); - _bindLogger(*(new XML::SimpleSession())); + this->_sm = &SessionManager::instance(); + _bindDocument(*this); + _bindLogger(*(new XML::SimpleSession())); } void InkboardDocument::setRecipient(Glib::ustring const& val) { - this->_recipient = val; + this->_recipient = val; } Glib::ustring InkboardDocument::getRecipient() const { - return this->_recipient; + return this->_recipient; +} + +void +InkboardDocument::setSessionIdent(Glib::ustring const& val) +{ + this->_session = val; +} + +Glib::ustring +InkboardDocument::getSessionIdent() const +{ + return this->_session; } void @@ -64,7 +76,7 @@ InkboardDocument::terminateSession() void InkboardDocument::processInkboardEvent(Message::Wrapper mtype, unsigned int seqnum, Glib::ustring const& data) { - g_log(NULL, G_LOG_LEVEL_DEBUG, "Processing Inkboard event: mtype=%d seqnum=%d data=%s\n", mtype, seqnum, data.c_str()); + g_log(NULL, G_LOG_LEVEL_DEBUG, "Processing Inkboard event: mtype=%s seqnum=%d data=%s\n", mtype, seqnum, data.c_str()); } bool @@ -73,15 +85,15 @@ InkboardDocument::sendProtocol(const Glib::ustring &destJid, Message::Wrapper wr { char *fmt= "" - "" + "" "<%s>" "%s" "" "" ""; - if (!sm->getClient().write( - fmt,_type,sm->getClient().getJid().c_str(), - destJid.c_str(),wrapper,Vars::INKBOARD_XMLNS,message,wrapper)) + if (!_sm->getClient().write( + fmt,_type,_sm->getClient().getJid().c_str(),destJid.c_str(), + Vars::INKBOARD_XMLNS,this->getSessionIdent().c_str(),wrapper,message,wrapper)) return false; return true; diff --git a/src/jabber_whiteboard/inkboard-document.h b/src/jabber_whiteboard/inkboard-document.h index 6e04fddac..0b0e5baed 100644 --- a/src/jabber_whiteboard/inkboard-document.h +++ b/src/jabber_whiteboard/inkboard-document.h @@ -37,6 +37,9 @@ public: void setRecipient(Glib::ustring const& val); Glib::ustring getRecipient() const; + void setSessionIdent(Glib::ustring const& val); + Glib::ustring getSessionIdent() const; + void startSessionNegotiation(); void terminateSession(); void processInkboardEvent(Message::Wrapper mtype, unsigned int seqnum, Glib::ustring const& data); @@ -66,8 +69,10 @@ private: void _initBindings(); - SessionManager *sm; + SessionManager *_sm; State::SessionType _type; + + Glib::ustring _session; Glib::ustring _recipient; KeyNodeTable _tracker; diff --git a/src/jabber_whiteboard/session-manager.cpp b/src/jabber_whiteboard/session-manager.cpp index a64efbdb3..72bddcee4 100644 --- a/src/jabber_whiteboard/session-manager.cpp +++ b/src/jabber_whiteboard/session-manager.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -33,8 +34,6 @@ #include "jabber_whiteboard/dialog/choose-desktop.h" -#define INKBOARD_XMLNS "http://inkscape.org/inkboard" - namespace Inkscape { namespace Whiteboard { @@ -78,8 +77,6 @@ SessionManager::processXmppEvent(const Pedro::XmppEvent &event) { int type = event.getType(); - g_warning("recieved pedro"); - switch (type) { case Pedro::XmppEvent::EVENT_STATUS: { @@ -99,13 +96,14 @@ SessionManager::processXmppEvent(const Pedro::XmppEvent &event) } case Pedro::XmppEvent::EVENT_MESSAGE: { - printf("## SM message:%s\n", event.getFrom().c_str()); + g_warning("## SM message:%s\n", event.getFrom().c_str()); Pedro::Element *root = event.getDOM(); + g_warning("hey %s",root->getTagAttribute("wb", "xmlns")); + if (root) { - if (root->getTagAttribute("inkboard", "xmlns") == - INKBOARD_XMLNS) + if (root->getTagAttribute("inkboard", "xmlns") == Vars::INKBOARD_XMLNS) { _processInkboardEvent(event); } @@ -118,12 +116,14 @@ SessionManager::processXmppEvent(const Pedro::XmppEvent &event) } case Pedro::XmppEvent::EVENT_MUC_MESSAGE: { - printf("## SM MUC message:%s\n", event.getFrom().c_str()); + g_warning("## SM MUC message:%s\n", event.getFrom().c_str()); Pedro::Element *root = event.getDOM(); + + g_warning("hey %s",root->getTagAttribute("wb", "xmlns")); + if (root) { - if (root->getTagAttribute("inkboard", "xmlns") == - INKBOARD_XMLNS) + if (root->getTagAttribute("inkboard", "xmlns") == Vars::INKBOARD_XMLNS) { _processInkboardEvent(event); } @@ -158,6 +158,44 @@ SessionManager::processXmppEvent(const Pedro::XmppEvent &event) void SessionManager::doShare(Glib::ustring const& to, State::SessionType type) { + SPDocument* doc = makeInkboardDocument(g_quark_from_static_string("xml"), "svg:svg", type, to); + if(doc == NULL) return; + + InkboardDocument* inkdoc = dynamic_cast< InkboardDocument* >(doc->rdoc); + if (inkdoc == NULL) return; + + + if(type == State::WHITEBOARD_PEER) + { + ChooseDesktop dialog; + int result = dialog.run(); + + if(result == Gtk::RESPONSE_OK) + { + SPDesktop *desktop = dialog.getDesktop(); + + if(desktop != NULL) + { + Inkscape::XML::Document *old_doc = + sp_desktop_document(desktop)->rdoc; + inkdoc->root()->mergeFrom(old_doc->root(),"id"); + } + } + }else{ return; } + + // Create a random session identifier + char * randomString = (char*) malloc (11); + for (int n=0; n<11; n++) + randomString[n]=rand()%26+'a'; + randomString[11]='\0'; + + inkdoc->setSessionIdent(randomString); + + _inkboards.push_back(Inkboard_record_type(randomString, inkdoc)); + + inkdoc->startSessionNegotiation(); + + /* InkboardDocument* doc; SPDesktop* dt; @@ -208,6 +246,7 @@ SessionManager::doShare(Glib::ustring const& to, State::SessionType type) } } } + */ } /** diff --git a/src/jabber_whiteboard/session-manager.h b/src/jabber_whiteboard/session-manager.h index 7e61c6b91..18f6239bb 100644 --- a/src/jabber_whiteboard/session-manager.h +++ b/src/jabber_whiteboard/session-manager.h @@ -146,19 +146,20 @@ public: } private: + // types typedef std::pair< Glib::ustring, InkboardDocument* > Inkboard_record_type; typedef std::vector< Inkboard_record_type, GC::Alloc< Inkboard_record_type, GC::MANUAL > > Inkboards_type; - typedef std::list< Glib::ustring > Pending_invitations_type; + typedef std::list< Glib::ustring > Pending_invitations_type; - typedef std::pair< Glib::ustring, InvitationResponses > Invitation_response_type; - typedef std::list< Invitation_response_type > Invitation_responses_type; + typedef std::pair< Glib::ustring, InvitationResponses > Invitation_response_type; + typedef std::list< Invitation_response_type > Invitation_responses_type; - // functors - struct CheckInvitationSender { - public: - CheckInvitationSender(Glib::ustring const& x) : x(x) { } + // functors + struct CheckInvitationSender { + public: + CheckInvitationSender(Glib::ustring const& x) : x(x) { } ~CheckInvitationSender() { } bool operator()(SessionManager::Invitation_response_type const& y) const { @@ -166,31 +167,31 @@ private: } private: Glib::ustring const& x; - }; + }; - // objects + // objects Pedro::PedroGui gui; SendMessageQueue sendMessageQueue; ReceiveMessageQueue receiveMessageQueue; - // members + // members unsigned long sequenceNumber; Inkboards_type _inkboards; - Pending_invitations_type _pending_invitations; - Invitation_responses_type _invitation_responses; + Pending_invitations_type _pending_invitations; + Invitation_responses_type _invitation_responses; - sigc::connection _check_pending_invitations; - sigc::connection _check_invitation_responses; + sigc::connection _check_pending_invitations; + sigc::connection _check_invitation_responses; // methods void _processInkboardEvent(Pedro::XmppEvent const& event); void _handleSessionEvent(Message::Wrapper mtype, Pedro::XmppEvent const& event); void _handleIncomingInvitation(Glib::ustring const& from); - void _handleInvitationResponse(Glib::ustring const& from, InvitationResponses resp); + void _handleInvitationResponse(Glib::ustring const& from, InvitationResponses resp); - // methods handled externally - bool _checkInvitationQueue(); - bool _checkInvitationResponseQueue(); + // methods handled externally + bool _checkInvitationQueue(); + bool _checkInvitationResponseQueue(); }; } // namespace Whiteboard