8b3c563540f325cdfe77781a5047d9239268669b
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 const std::string Wrapper;
71 typedef std::string 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 const std::string DOCUMENT_ROOT_NODE;
92 extern const std::string INKBOARD_XMLNS;
94 extern const std::string WHITEBOARD_MESSAGE;
95 extern const std::string PROTOCOL_MESSAGE;
96 extern const std::string NEW_MESSAGE;
97 extern const std::string CONFIGURE_MESSAGE;
98 extern const std::string CONFIGURE_TEXT_MESSAGE;
99 extern const std::string MOVE_MESSAGE;
100 extern const std::string REMOVE_MESSAGE;
102 }
104 namespace State {
106 typedef const std::string SessionType;
108 extern SessionType WHITEBOARD_MUC;
109 extern SessionType WHITEBOARD_PEER;
111 enum SessionState {
113 INITIAL = 0,
114 AWAITING_INVITATION_REPLY = 1,
115 CONNECTING = 2,
116 INVITATION_RECIEVED = 3,
117 AWAITING_CONNECTED = 4,
118 CONNECTED = 5,
119 AWAITING_DOCUMENT_BEGIN = 6,
120 SYNCHRONISING = 7,
121 IN_WHITEBOARD = 8
123 };
124 }
126 namespace Dialog {
128 enum DialogReply {
130 ACCEPT_INVITATION = 0,
131 DECLINE_INVITATION = 1
132 };
134 }
136 // message types
137 // explicitly numbered to aid protocol description later on
141 // Message handler modes
142 enum HandlerMode {
143 DEFAULT,
144 PRESENCE,
145 ERROR
146 };
148 // Actions to pass to the node tracker when we modify a node in
149 // the document tree upon event serialization
150 enum NodeTrackerAction {
151 NODE_ADD,
152 NODE_REMOVE,
153 NODE_UNKNOWN
154 };
156 // I am assuming that std::string (which will not properly represent Unicode data) will
157 // suffice for associating (integer, Jabber ID) identifiers with nodes.
158 // We do not need to preserve all semantics handled by Unicode; we just need to have
159 // the byte representation. std::string is good enough for that.
160 //
161 // The reason for this is that comparisons with std::string are much faster than
162 // comparisons with Glib::ustring (simply because the latter is using significantly
163 // more complex text-handling algorithms), and we need speed here. We _could_ use
164 // Glib::ustring::collate_key() here and therefore get the best of both worlds,
165 // but collation keys are rather big.
166 //
167 // XML node tracker maps
169 /// Associates node keys to pointers to XML::Nodes.
170 /// \see Inkscape::Whiteboard::XMLNodeTracker
171 typedef std::map< std::string, XML::Node*, std::less< std::string >, GC::Alloc< std::pair< std::string, XML::Node* >, GC::MANUAL > > KeyToTrackerNodeMap;
173 /// Associates pointers to XML::Nodes with node keys.
174 /// \see Inkscape::Whiteboard::XMLNodeTracker
175 typedef std::map< XML::Node*, std::string, std::less< XML::Node* >, GC::Alloc< std::pair< XML::Node*, std::string >, GC::MANUAL > > TrackerNodeToKeyMap;
178 // TODO: Clean up these typedefs. I'm sure quite a few of these aren't used anymore; additionally,
179 // it's probably possible to consolidate a few of these types into one.
181 // Temporary storage of new object messages and new nodes in said messages
182 typedef std::list< Glib::ustring > NewChildObjectMessageList;
184 typedef std::pair< KeyNodePair, NodeTrackerAction > SerializedEventNodeAction;
186 typedef std::list< SerializedEventNodeAction > KeyToNodeActionList;
188 //typedef std::map< std::string, SerializedEventNodeAction > KeyToNodeActionMap;
190 typedef std::set< std::string > AttributesScannedSet;
191 typedef std::set< XML::Node* > AttributesUpdatedSet;
193 typedef std::map< std::string, XML::Node const* > KeyToNodeMap;
194 typedef std::map< XML::Node const*, std::string > NodeToKeyMap;
197 // Message context verification and processing
198 struct MessageProcessor;
199 class ReceiveMessageQueue;
201 typedef std::map< std::string, ReceiveMessageQueue*, std::less< std::string >, GC::Alloc< std::pair< std::string, ReceiveMessageQueue* >, GC::MANUAL > > RecipientToReceiveQueueMap;
202 typedef std::map< std::string, unsigned int > ReceipientToLatestTransactionMap;
204 typedef std::string ReceivedCommitEvent;
205 typedef std::list< ReceivedCommitEvent > CommitsQueue;
207 // Message serialization
208 typedef std::list< Glib::ustring > SerializedEventList;
211 //typedef std::pair< Glib::ustring, InvitationResponses > Invitation_response_type;
212 //typedef std::list< Invitation_response_type > Invitation_responses_type;
213 // Error handling -- someday
214 // TODO: finish and integrate this
215 //typedef boost::function< LmHandlerResult (unsigned int code) > ErrorHandlerFunctor;
216 //typedef std::map< unsigned int, ErrorHandlerFunctor > ErrorHandlerFunctorMap;
218 // TODO: breaking these up into namespaces would be nice, but it's too much typing
219 // for now
221 // Protocol versions
222 extern char const* MESSAGE_PROTOCOL_V1;
223 extern int const HIGHEST_SUPPORTED;
225 // Node types (as strings)
226 extern char const* NODETYPE_DOCUMENT_STR;
227 extern char const* NODETYPE_ELEMENT_STR;
228 extern char const* NODETYPE_TEXT_STR;
229 extern char const* NODETYPE_COMMENT_STR;
231 // Number of chars to allocate for type field (in SessionManager::sendMessage)
232 extern int const TYPE_FIELD_SIZE;
234 // Number of chars to allocate for sequence number field (in SessionManager::sendMessage)
235 extern int const SEQNUM_FIELD_SIZE;
237 // Designators for certain "special" nodes in the document
238 // These nodes are "special" because they are generally present in all documents
239 extern char const* DOCUMENT_ROOT_NODE;
240 extern char const* DOCUMENT_NAMEDVIEW_NODE;
242 // Names of these special nodes
243 extern char const* DOCUMENT_ROOT_NAME;
244 extern char const* DOCUMENT_NAMEDVIEW_NAME;
246 }
248 }
252 #endif
254 /*
255 Local Variables:
256 mode:c++
257 c-file-style:"stroustrup"
258 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
259 indent-tabs-mode:nil
260 fill-column:99
261 End:
262 */
263 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :