Code

handling recieved messages
authordaleharvey <daleharvey@users.sourceforge.net>
Mon, 31 Jul 2006 02:19:44 +0000 (02:19 +0000)
committerdaleharvey <daleharvey@users.sourceforge.net>
Mon, 31 Jul 2006 02:19:44 +0000 (02:19 +0000)
src/jabber_whiteboard/inkboard-document.cpp
src/jabber_whiteboard/inkboard-document.h
src/jabber_whiteboard/session-manager.cpp
src/jabber_whiteboard/session-manager.h

index e6bd4371396d6e7360a8781d906ade4ea60a0c9c..e2bba2fc02329766c7012d4a7bd3642d5003b967 100644 (file)
@@ -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=
         "<message type='%s' from='%s' to='%s'>"
-            "<wb xmlns='%s'>"
+            "<wb xmlns='%s' session='%s'>"
                 "<%s>"
                     "%s"
                 "</%s>"
             "</wb>"
         "</message>";
-    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;
index 6e04fddac9ac8fe44b9a733b8069c5bc80e8dcfb..0b0e5baed2790b2dad9d6e59b41674a452b533e9 100644 (file)
@@ -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;
index a64efbdb33efe821fd8be87c0695cadbd849b310..72bddcee4bb42c2335b994dd9eadd6d9e3078145 100644 (file)
@@ -13,6 +13,7 @@
 #include <functional>
 #include <algorithm>
 #include <iostream>
+#include <time.h>
 
 #include <gtkmm.h>
 #include <glibmm/i18n.h>
@@ -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)
             }
         }
     }
+    */
 }
 
 /**
index 7e61c6b91957ad0bcd0afce006a72688815213e6..18f6239bbf03acb3dc4e27a1676770a17f3ca922 100644 (file)
@@ -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