Code

Tweaked smaller size to be 3/4ths the menu size
[inkscape.git] / src / jabber_whiteboard / message-processors.h
1 /**
2  * Whiteboard session manager
3  * Jabber received message processors
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 __WHITEBOARD_MESSAGE_PROCESSORS_H__
14 #define __WHITEBOARD_MESSAGE_PROCESSORS_H__
16 #include "jabber_whiteboard/typedefs.h"
18 #include "gc-managed.h"
19 #include "gc-finalized.h"
21 namespace Inkscape {
23 namespace Whiteboard {
25 class SessionManager;
27 // Processor forward declarations
28 struct ChangeHandler;
29 struct DocumentSignalHandler;
30 struct ConnectRequestHandler;
31 struct ConnectErrorHandler;
32 struct ChatSynchronizeHandler;
34 /**
35  * Encapsulates a pointer to an LmMessage along with additional information,
36  * such as the message's sequence number, its sender, and its body.
37  *
38  * All of the above data members can be extracted directly from the LmMessage;
39  * they are provided for convenience.
40  */
41 struct JabberMessage {
42 public:
43         /**
44          * Constructor.
45          *
46          * The constructor attaches a reference to the LmMessage to prevent Loudmouth from
47          * freeing the message.
48          */
49         JabberMessage(LmMessage* m) : message(m), sequence(0)
50         {       
51                 lm_message_ref(this->message);
52         }
54         /**
55          * Destructor.
56          *
57          * The destructor deletes a reference to the LmMessage, which, assuming all other
58          * references have been deleted, will allow Loudmouth to free the LmMessage object.
59          */
60         ~JabberMessage() 
61         {
62                 lm_message_unref(this->message);
63         }
66          // TODO: Hide, or, better, remove this.  There's no real reason why it should be here,
67          // and it allows for the possibility of reference count-induced memory leaks.
68         /**
69          * Pointer to original Loudmouth message object.
70          */
71         LmMessage* message;
72         
73         /**
74          * Sequence number of this message.
75          */
76         unsigned int sequence;
77         
78         /**
79          * The JID of this message's sender.
80          */
81         std::string sender;
83         /**
84          * The body of this message.
85          */
86         Glib::ustring body;
88 private:
89         // noncopyable, nonassignable (for now, anyway...)
90 //      JabberMessage(JabberMessage const&);
91 //      JabberMessage& operator=(JabberMessage const&);
92 };
94 /**
95  * A MessageProcessor is a functor that is associated with one or more Inkboard message types.
96  * When an Inkboard client receives an Inkboard message, it passes it to the appropriate
97  * MessageProcessor.
98  */
99 struct MessageProcessor : public GC::Managed<>, public GC::Finalized {
100 public:
101         virtual ~MessageProcessor() 
102         {
104         }
106         /**
107          * Functor action operator.
108          *
109          * \param mode The type of the message being processed.
110          * \param m A reference to the JabberMessage encapsulating the received Jabber message.
111          */
112         virtual LmHandlerResult operator()(MessageType mode, JabberMessage& m) = 0;
114         /**
115          * Constructor.
116          *
117          * \param sm The SessionManager with which a MessageProcessor instance is associated.
118          */
119         MessageProcessor(SessionManager* sm) : _sm(sm) { }
120 protected:
121         /**
122          * Pointer to the associated SessionManager object.
123          */
124         SessionManager *_sm;
126 private:
127         // noncopyable, nonassignable
128         MessageProcessor(MessageProcessor const&);
129         MessageProcessor& operator=(MessageProcessor const&);
130 };
132 /*
133 struct ProcessorShell : public GC::Managed<>, public std::binary_function< MessageType, JabberMessage, LmHandlerResult > {
134 public:
135         ProcessorShell(MessageProcessor* mpm) : _mpm(mpm) { }
137         LmHandlerResult operator()(MessageType type, JabberMessage msg)
138         {
139                 return (*this->_mpm)(type, msg);
140         }
141 private:
142         MessageProcessor* _mpm;
143 };
144 */
146 /**
147  * Initialize the message -> MessageProcessor map.
148  *
149  * \param sm The SessionManager with which all created MessageProcessors should be associated with.
150  * \param mpm Reference to the MessageProcessorMap to initialize.
151  */
152 void initialize_received_message_processors(SessionManager* sm, MessageProcessorMap& mpm);
154 /**
155  * Clean up the message -> MessageProcessor map.
156  *
157  * \param mpm Reference to the MessageProcessorMap to clean up.
158  */
159 void destroy_received_message_processors(MessageProcessorMap& mpm);
165 #endif
167 /*
168   Local Variables:
169   mode:c++
170   c-file-style:"stroustrup"
171   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
172   indent-tabs-mode:nil
173   fill-column:99
174   End:
175 */
176 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :