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 "xml/node.h"
17 #include "jabber_whiteboard/message-tags.h"
19 #include <algorithm>
20 #include <cstring>
21 #include <string>
22 #include <map>
23 #include <set>
24 #include <bitset>
25 #include <vector>
27 #include <glibmm.h>
28 #include <sigc++/sigc++.h>
30 #include "gc-alloc.h"
32 // Various specializations of std::less for XMLNodeTracker maps.
33 namespace std {
34 using Inkscape::XML::Node;
36 /**
37 * Specialization of std::less<> for pointers to XML::Nodes.a
38 *
39 * \see Inkscape::XML::Node
40 */
41 template<>
42 struct less< Node* > : public binary_function < Node*, Node*, bool >
43 {
44 bool operator()(Node* _x, Node* _y) const
45 {
46 return _x < _y;
47 }
49 };
51 }
53 namespace Inkscape {
55 namespace XML {
56 class Node;
57 }
59 namespace Util {
60 template< typename T > class ListContainer;
61 }
63 namespace Whiteboard {
65 #define NUM_FLAGS 9
67 namespace Message {
69 typedef const std::string Wrapper;
70 typedef std::string Message;
72 extern Wrapper PROTOCOL;
73 extern Wrapper NEW;
74 extern Wrapper REMOVE;
75 extern Wrapper CONFIGURE;
76 extern Wrapper MOVE;
78 extern Message CONNECT_REQUEST;
79 extern Message CONNECTED;
80 extern Message ACCEPT_INVITATION;
81 extern Message DECLINE_INVITATION;
82 extern Message DOCUMENT_BEGIN;
83 extern Message DOCUMENT_END;
85 }
87 namespace Vars {
89 extern const std::string DOCUMENT_ROOT_NODE;
91 extern const std::string INKBOARD_XMLNS;
93 extern const std::string WHITEBOARD_MESSAGE;
94 extern const std::string PROTOCOL_MESSAGE;
95 extern const std::string NEW_MESSAGE;
96 extern const std::string CONFIGURE_MESSAGE;
97 extern const std::string CONFIGURE_TEXT_MESSAGE;
98 extern const std::string MOVE_MESSAGE;
99 extern const std::string REMOVE_MESSAGE;
101 }
103 namespace State {
105 typedef const std::string SessionType;
107 extern SessionType WHITEBOARD_MUC;
108 extern SessionType WHITEBOARD_PEER;
110 enum SessionState {
112 INITIAL = 0,
113 AWAITING_INVITATION_REPLY = 1,
114 CONNECTING = 2,
115 INVITATION_RECIEVED = 3,
116 AWAITING_CONNECTED = 4,
117 CONNECTED = 5,
118 AWAITING_DOCUMENT_BEGIN = 6,
119 SYNCHRONISING = 7,
120 IN_WHITEBOARD = 8
122 };
123 }
125 namespace Dialog {
127 enum DialogReply {
129 ACCEPT_INVITATION = 0,
130 DECLINE_INVITATION = 1
131 };
133 }
135 class KeyNodePair;
136 class KeyNodeTable;
138 typedef std::pair<Glib::ustring, Glib::ustring> Configure;
140 // Message handler modes
141 enum HandlerMode {
142 DEFAULT,
143 PRESENCE,
144 ERROR
145 };
147 // Actions to pass to the node tracker when we modify a node in
148 // the document tree upon event serialization
149 enum NodeTrackerAction {
150 NODE_ADD,
151 NODE_REMOVE,
152 NODE_UNKNOWN
153 };
155 // I am assuming that std::string (which will not properly represent Unicode data) will
156 // suffice for associating (integer, Jabber ID) identifiers with nodes.
157 // We do not need to preserve all semantics handled by Unicode; we just need to have
158 // the byte representation. std::string is good enough for that.
159 //
160 // The reason for this is that comparisons with std::string are much faster than
161 // comparisons with Glib::ustring (simply because the latter is using significantly
162 // more complex text-handling algorithms), and we need speed here. We _could_ use
163 // Glib::ustring::collate_key() here and therefore get the best of both worlds,
164 // but collation keys are rather big.
165 //
166 // XML node tracker maps
168 /// Associates node keys to pointers to XML::Nodes.
169 /// \see Inkscape::Whiteboard::XMLNodeTracker
170 typedef std::map< std::string, XML::Node*, std::less< std::string >, GC::Alloc< std::pair< std::string, XML::Node* >, GC::MANUAL > > KeyToTrackerNodeMap;
172 /// Associates pointers to XML::Nodes with node keys.
173 /// \see Inkscape::Whiteboard::XMLNodeTracker
174 typedef std::map< XML::Node*, std::string, std::less< XML::Node* >, GC::Alloc< std::pair< XML::Node*, std::string >, GC::MANUAL > > TrackerNodeToKeyMap;
177 // TODO: Clean up these typedefs. I'm sure quite a few of these aren't used anymore; additionally,
178 // it's probably possible to consolidate a few of these types into one.
180 // Temporary storage of new object messages and new nodes in said messages
181 typedef std::list< Glib::ustring > NewChildObjectMessageList;
183 typedef std::pair< KeyNodePair, NodeTrackerAction > SerializedEventNodeAction;
185 typedef std::list< SerializedEventNodeAction > KeyToNodeActionList;
187 //typedef std::map< std::string, SerializedEventNodeAction > KeyToNodeActionMap;
189 typedef std::set< std::string > AttributesScannedSet;
190 typedef std::set< XML::Node* > AttributesUpdatedSet;
192 typedef std::map< std::string, XML::Node const* > KeyToNodeMap;
193 typedef std::map< XML::Node const*, std::string > NodeToKeyMap;
196 // Message context verification and processing
197 struct MessageProcessor;
198 class ReceiveMessageQueue;
200 typedef std::map< std::string, ReceiveMessageQueue*, std::less< std::string >, GC::Alloc< std::pair< std::string, ReceiveMessageQueue* >, GC::MANUAL > > RecipientToReceiveQueueMap;
201 typedef std::map< std::string, unsigned int > ReceipientToLatestTransactionMap;
203 typedef std::string ReceivedCommitEvent;
204 typedef std::list< ReceivedCommitEvent > CommitsQueue;
206 // Message serialization
207 typedef std::list< Glib::ustring > SerializedEventList;
210 //typedef std::pair< Glib::ustring, InvitationResponses > Invitation_response_type;
211 //typedef std::list< Invitation_response_type > Invitation_responses_type;
212 // Error handling -- someday
213 // TODO: finish and integrate this
214 //typedef boost::function< LmHandlerResult (unsigned int code) > ErrorHandlerFunctor;
215 //typedef std::map< unsigned int, ErrorHandlerFunctor > ErrorHandlerFunctorMap;
217 // TODO: breaking these up into namespaces would be nice, but it's too much typing
218 // for now
220 // Protocol versions
221 extern char const* MESSAGE_PROTOCOL_V1;
222 extern int const HIGHEST_SUPPORTED;
224 // Node types (as strings)
225 extern char const* NODETYPE_DOCUMENT_STR;
226 extern char const* NODETYPE_ELEMENT_STR;
227 extern char const* NODETYPE_TEXT_STR;
228 extern char const* NODETYPE_COMMENT_STR;
230 // Number of chars to allocate for type field (in SessionManager::sendMessage)
231 extern int const TYPE_FIELD_SIZE;
233 // Number of chars to allocate for sequence number field (in SessionManager::sendMessage)
234 extern int const SEQNUM_FIELD_SIZE;
236 // Designators for certain "special" nodes in the document
237 // These nodes are "special" because they are generally present in all documents
238 extern char const* DOCUMENT_ROOT_NODE;
239 extern char const* DOCUMENT_NAMEDVIEW_NODE;
241 // Names of these special nodes
242 extern char const* DOCUMENT_ROOT_NAME;
243 extern char const* DOCUMENT_NAMEDVIEW_NAME;
245 }
247 }
251 #endif
253 /*
254 Local Variables:
255 mode:c++
256 c-file-style:"stroustrup"
257 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
258 indent-tabs-mode:nil
259 fill-column:99
260 End:
261 */
262 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :