Code

Refactoring Session Establishment
authordaleharvey <daleharvey@users.sourceforge.net>
Wed, 26 Jul 2006 16:30:34 +0000 (16:30 +0000)
committerdaleharvey <daleharvey@users.sourceforge.net>
Wed, 26 Jul 2006 16:30:34 +0000 (16:30 +0000)
src/jabber_whiteboard/Makefile_insert
src/jabber_whiteboard/defines.cpp [new file with mode: 0644]
src/jabber_whiteboard/defines.h
src/jabber_whiteboard/inkboard-document.cpp
src/jabber_whiteboard/session-manager.cpp
src/jabber_whiteboard/session-manager.h

index e3966086e358b4cae53568725e51b0a43f3675c8..252ec49805e522f7d10ff886657454b4561cab0f 100644 (file)
@@ -9,6 +9,7 @@ jabber_whiteboard/clean:
        rm -f jabber_whiteboard/libjabber_whiteboard.a $(jabber_whiteboard_libjabber_whiteboard_a_OBJECTS)
 
 jabber_whiteboard_SOURCES = \
+       jabber_whiteboard/defines.cpp \
        jabber_whiteboard/defines.h \
        jabber_whiteboard/empty.cpp \
        jabber_whiteboard/keynode.cpp \
diff --git a/src/jabber_whiteboard/defines.cpp b/src/jabber_whiteboard/defines.cpp
new file mode 100644 (file)
index 0000000..7e06cd6
--- /dev/null
@@ -0,0 +1,74 @@
+/**
+ * Whiteboard session manager
+ * Definitions
+ * 
+ * Authors:
+ * Dale Harvey <harveyd@gmail.com>
+ *
+ * Copyright (c) 2006 Authors
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#ifndef __INKSCAPE_WHITEBOARD_DEFINES_CPP__
+#define __INKSCAPE_WHITEBOARD_DEFINES_CPP__
+
+#include "jabber_whiteboard/defines.h"
+
+namespace Inkscape {
+
+namespace Whiteboard {
+
+char const * const MessageString[] = {
+    // image and internal data
+        "CHANGE_NOT_REPEATABLE",
+       "CHANGE_REPEATABLE",
+       "DUMMY_CHANGE",
+       "CHANGE_COMMIT",
+       "DOCUMENT_BEGIN",
+       "DOCUMENT_END",
+
+    // 1-1 connections
+        "connect-request",
+       "CONNECT_REQUEST_RESPONSE_USER", 
+    // chat connections
+        "CONNECT_REQUEST_RESPONSE_CHAT",
+
+    // chatroom document synchronization
+       "CHATROOM_SYNCHRONIZE_REQUEST", 
+       "CHATROOM_SYNCHRONIZE_RESPONSE",
+
+    // requests
+        "DOCUMENT_SENDER_REQUEST",
+       "DOCUMENT_SENDER_REQUEST_RESPONSE", 
+       "DOCUMENT_REQUEST",
+
+    // notifications
+        "CONNECTED_SIGNAL",
+       "DISCONNECTED_FROM_USER_SIGNAL",
+
+    // error responses
+       "CONNECT_REQUEST_REFUSED_BY_PEER", 
+       "UNSUPPORTED_PROTOCOL_VERSION",
+       "ALREADY_IN_SESSION",
+       
+    // error cases, i.e. garbled messages or bad clients.  These should
+    // never actually be transmitted
+       "UNKNOWN"
+};
+
+}
+}
+
+#endif
+
+/*
+  Local Variables:
+  mode:c++
+  c-file-style:"stroustrup"
+  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+  indent-tabs-mode:nil
+  fill-column:99
+  End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
index afed3338f654bf08ff7d1e194557ba8d5020441d..587e293762740a645143703abcdd4e18362c18d8 100644 (file)
@@ -24,37 +24,44 @@ namespace Whiteboard {
 // explicitly numbered to aid protocol description later on
 enum MessageType {
     // image and internal data
-    CHANGE_NOT_REPEATABLE = 0,
+        CHANGE_NOT_REPEATABLE = 0,
        CHANGE_REPEATABLE = 1,
        DUMMY_CHANGE = 2,
        CHANGE_COMMIT = 3,
        DOCUMENT_BEGIN = 4,
        DOCUMENT_END = 5,
+
     // 1-1 connections
         CONNECT_REQUEST_USER = 6,
        CONNECT_REQUEST_RESPONSE_USER = 7, 
     // chat connections
-CONNECT_REQUEST_RESPONSE_CHAT = 8,
-       // chatroom document synchronization
+        CONNECT_REQUEST_RESPONSE_CHAT = 8,
+
+    // chatroom document synchronization
        CHATROOM_SYNCHRONIZE_REQUEST = 9, 
        CHATROOM_SYNCHRONIZE_RESPONSE = 10,
+
     // requests
-    DOCUMENT_SENDER_REQUEST = 11,
+        DOCUMENT_SENDER_REQUEST = 11,
        DOCUMENT_SENDER_REQUEST_RESPONSE = 12, 
        DOCUMENT_REQUEST = 13,
+
     // notifications
-    CONNECTED_SIGNAL = 14,
+        CONNECTED_SIGNAL = 14,
        DISCONNECTED_FROM_USER_SIGNAL = 15,
-       // error responses
+
+    // error responses
        CONNECT_REQUEST_REFUSED_BY_PEER = 16, 
        UNSUPPORTED_PROTOCOL_VERSION = 17,
        ALREADY_IN_SESSION = 18,
        
-       // error cases, i.e. garbled messages or bad clients.  These should
-       // never actually be transmitted
+    // error cases, i.e. garbled messages or bad clients.  These should
+    // never actually be transmitted
        UNKNOWN = 21
 };
 
+extern char const * const MessageString[];
+
 // Responses to whiteboard invitations
 enum InvitationResponses {
        ACCEPT_INVITATION,
index a3881af39b66b30c0fde1563984177f4de7814ee..c7e86a5276760db937913e712db974b7655f6f8b 100644 (file)
@@ -58,7 +58,7 @@ InkboardDocument::startSessionNegotiation()
                 break;
             case INKBOARD_PRIVATE:
             default:
-                sm.send(_recipient, CONNECT_REQUEST_USER, " ");
+                sm.sendProtocol(_recipient, CONNECT_REQUEST_USER);
                 break;
         }
 }
index 36bf3615b77a5e54aa6345b16dcd01df5877955e..3c982c4df80676738504691dea423d8c931fccc5 100644 (file)
@@ -29,6 +29,7 @@
 #include "jabber_whiteboard/session-manager.h"
 #include "jabber_whiteboard/inkboard-document.h"
 #include "jabber_whiteboard/new-inkboard-document.h"
+#include "jabber_whiteboard/defines.h"
 
 #include "jabber_whiteboard/dialog/choose-desktop.h"
 
@@ -108,30 +109,26 @@ SessionManager::send(const Glib::ustring &destJid,
 
 bool
 SessionManager::sendProtocol(const Glib::ustring &destJid, 
-                                        const MessageType type,
-                     const Glib::ustring &data)
+                                        const MessageType type)
 {
-    Pedro::DOMString xmlData = Pedro::Parser::encode(data);
     char *fmt=
-    "<message type='chat' from='%s' to='%s' id='ink_%d'>"
-    "<wb xmlns='%s' "
-    "protocol='%d' type='%d' seq='%d'><x:inkboard-data>%s</x:inkboard-data></inkboard>"
-    "<body></body>"
+    "<message type='chat' from='%s' to='%s'>"
+        "<wb xmlns='%s'>"
+            "<protocol>"
+                "<%s />"
+            "</protocol>"
+        "</wb>"
     "</message>";
     if (!getClient().write(fmt, 
                            getClient().getJid().c_str(),
                            destJid.c_str(),
-                           getClient().getMsgId(),
                            INKBOARD_XMLNS,
-                           2,
-                           (MessageType)type,
-                           getSequenceNumber(),
-                           xmlData.c_str()
+                           MessageString[type]
                            ))
         {
         return false;
         }
-        
+
     return true;
 }
 
index 0a2c22f558613fb38a87c69f21333f6815960c14..b07b64906401e090867e77d26c09c1ad3e6605b8 100644 (file)
@@ -79,8 +79,7 @@ public:
      *
      */
     virtual bool sendProtocol(const Glib::ustring &destJid, 
-                      const MessageType type,
-                      const Glib::ustring &data);
+                      const MessageType type);
 
     /**
      *