Code

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