Code

a5d2d2ce6a7ec867c66c1d9bc7f577740b083485
[inkscape.git] / src / jabber_whiteboard / defines.h
1 /**
2  * Whiteboard session manager
3  * Definitions
4  * 
5  * Authors:
6  * David Yip <yipdw@rose-hulman.edu>
7  *
8  * Copyright (c) 2005 Authors
9  *
10  * Released under GNU GPL, read the file 'COPYING' for more information
11  */
13 #ifndef __INKSCAPE_WHITEBOARD_DEFINES_H__
14 #define __INKSCAPE_WHITEBOARD_DEFINES_H__
16 #include "jabber_whiteboard/message-tags.h"
18 #include <algorithm>
19 #include <cstring>
20 #include <string>
21 #include <map>
22 #include <set>
23 #include <bitset>
24 #include <vector>
26 #include <glibmm.h>
27 #include <sigc++/sigc++.h>
29 #include "jabber_whiteboard/keynode.h"
31 #include "gc-alloc.h"
33 // Various specializations of std::less for XMLNodeTracker maps.
34 namespace std {
35 using Inkscape::XML::Node;
37 /**
38  * Specialization of std::less<> for pointers to XML::Nodes.a
39  *
40  * \see Inkscape::XML::Node
41  */
42 template<>
43 struct less< Node* > : public binary_function < Node*, Node*, bool >
44 {
45         bool operator()(Node* _x, Node* _y) const
46         {
47                 return _x < _y;
48         }
50 };
52 }
54 namespace Inkscape {
56 namespace XML {
57     class Node;
58 }
60 namespace Util {
61     template< typename T > class ListContainer;
62 }
64 namespace Whiteboard {
66 #define NUM_FLAGS       9
68 namespace Message {
70     typedef char const* Wrapper;
71     typedef char const* Message;
73     extern Wrapper PROTOCOL;
74     extern Wrapper NEW;
75     extern Wrapper REMOVE;
76     extern Wrapper CONFIGURE;
77     extern Wrapper MOVE;
79     extern Message CONNECT_REQUEST;
80     extern Message CONNECTED;
81     extern Message ACCEPT_INVITATION;
82     extern Message DECLINE_INVITATION;
83     extern Message DOCUMENT_BEGIN;
84     extern Message DOCUMENT_END;
86 }
88 namespace Vars {
90     extern char const* INKBOARD_XMLNS; 
92 }
94 namespace State {
96     typedef char const* SessionType;
98     extern SessionType WHITEBOARD_MUC; 
99     extern SessionType WHITEBOARD_PEER;
101     typedef char const* SessionState;
104 // message types
105 // explicitly numbered to aid protocol description later on
108 // Responses to whiteboard invitations
109 enum InvitationResponses {
110         ACCEPT_INVITATION,
111         DECLINE_INVITATION,
112         PEER_ALREADY_IN_SESSION,
113         UNSUPPORTED_PROTOCOL
114 };
116 // Message handler modes
117 enum HandlerMode {
118         DEFAULT,
119         PRESENCE,
120         ERROR
121 };
123 // Actions to pass to the node tracker when we modify a node in 
124 // the document tree upon event serialization
125 enum NodeTrackerAction {
126         NODE_ADD,
127         NODE_REMOVE,
128         NODE_UNKNOWN
129 };
131 // I am assuming that std::string (which will not properly represent Unicode data) will
132 // suffice for associating (integer, Jabber ID) identifiers with nodes. 
133 // We do not need to preserve all semantics handled by Unicode; we just need to have 
134 // the byte representation.  std::string is good enough for that.
135 //
136 // The reason for this is that comparisons with std::string are much faster than 
137 // comparisons with Glib::ustring (simply because the latter is using significantly
138 // more complex text-handling algorithms), and we need speed here.  We _could_ use
139 // Glib::ustring::collate_key() here and therefore get the best of both worlds,
140 // but collation keys are rather big.
141 //
142 // XML node tracker maps
144 /// Associates node keys to pointers to XML::Nodes.
145 /// \see Inkscape::Whiteboard::XMLNodeTracker
146 typedef std::map< std::string, XML::Node*, std::less< std::string >, GC::Alloc< std::pair< std::string, XML::Node* >, GC::MANUAL > > KeyToTrackerNodeMap;
148 /// Associates pointers to XML::Nodes with node keys.
149 /// \see Inkscape::Whiteboard::XMLNodeTracker
150 typedef std::map< XML::Node*, std::string, std::less< XML::Node* >, GC::Alloc< std::pair< XML::Node*, std::string >, GC::MANUAL > > TrackerNodeToKeyMap;
153 // TODO: Clean up these typedefs.  I'm sure quite a few of these aren't used anymore; additionally,
154 // it's probably possible to consolidate a few of these types into one.
156 // Temporary storage of new object messages and new nodes in said messages
157 typedef std::list< Glib::ustring > NewChildObjectMessageList;
159 typedef std::pair< KeyNodePair, NodeTrackerAction > SerializedEventNodeAction;
161 typedef std::list< SerializedEventNodeAction > KeyToNodeActionList;
163 //typedef std::map< std::string, SerializedEventNodeAction > KeyToNodeActionMap;
165 typedef std::set< std::string > AttributesScannedSet;
166 typedef std::set< XML::Node* > AttributesUpdatedSet;
168 typedef std::map< std::string, XML::Node const* > KeyToNodeMap;
169 typedef std::map< XML::Node const*, std::string > NodeToKeyMap;
172 // Message context verification and processing
173 struct MessageProcessor;
174 class ReceiveMessageQueue;
176 typedef std::map< std::string, ReceiveMessageQueue*, std::less< std::string >, GC::Alloc< std::pair< std::string, ReceiveMessageQueue* >, GC::MANUAL > > RecipientToReceiveQueueMap;
177 typedef std::map< std::string, unsigned int > ReceipientToLatestTransactionMap;
179 typedef std::string ReceivedCommitEvent;
180 typedef std::list< ReceivedCommitEvent > CommitsQueue;
182 // Message serialization
183 typedef std::list< Glib::ustring > SerializedEventList;
185 // Error handling -- someday
186 // TODO: finish and integrate this
187 //typedef boost::function< LmHandlerResult (unsigned int code) > ErrorHandlerFunctor;
188 //typedef std::map< unsigned int, ErrorHandlerFunctor > ErrorHandlerFunctorMap;
190 // TODO: breaking these up into namespaces would be nice, but it's too much typing
191 // for now
193 // Protocol versions
194 extern char const* MESSAGE_PROTOCOL_V1;
195 extern int const HIGHEST_SUPPORTED;
197 // Node types (as strings)
198 extern char const* NODETYPE_DOCUMENT_STR;
199 extern char const* NODETYPE_ELEMENT_STR;
200 extern char const* NODETYPE_TEXT_STR;
201 extern char const* NODETYPE_COMMENT_STR;
203 // Number of chars to allocate for type field (in SessionManager::sendMessage)
204 extern int const TYPE_FIELD_SIZE;
206 // Number of chars to allocate for sequence number field (in SessionManager::sendMessage)
207 extern int const SEQNUM_FIELD_SIZE;
209 // Designators for certain "special" nodes in the document
210 // These nodes are "special" because they are generally present in all documents
211 extern char const* DOCUMENT_ROOT_NODE;
212 extern char const* DOCUMENT_NAMEDVIEW_NODE;
214 // Names of these special nodes
215 extern char const* DOCUMENT_ROOT_NAME;
216 extern char const* DOCUMENT_NAMEDVIEW_NAME;
218 // Inkboard client states
219 extern int const IN_WHITEBOARD;
220 extern int const LOGGED_IN;
221 extern int const IN_CHATROOM;
222 extern int const WAITING_FOR_INVITE_RESPONSE;
223 extern int const CONNECTING_TO_CHAT;
224 extern int const WAITING_TO_SYNC_TO_CHAT;
225 extern int const SYNCHRONIZING_WITH_CHAT;
226 extern int const OPEN_FOR_DOC;
227 extern int const PLAYING_SESSION_FILE;
229 // update this if any other status flags are added
231 // TODO: make this user-configurable, within sane limits
232 // ("sane" limits being roughly in the range (10, 100], from personal testing)
233 // Based on discussions with Ted, it seems that we're going to make the Jabber guys
234 // accomodate Inkscape, not the other way around...
235 // Dispatch interval (in milliseconds)
236 extern int const SEND_TIMEOUT;
244 #endif
246 /*
247   Local Variables:
248   mode:c++
249   c-file-style:"stroustrup"
250   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
251   indent-tabs-mode:nil
252   fill-column:99
253   End:
254 */
255 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :