~mc.../inkscape/inkscape

« back to all changes in this revision

Viewing changes to src/jabber_whiteboard/message-processors.h

  • Committer: mental
  • Date: 2006-01-16 02:36:01 UTC
  • Revision ID: mental@users.sourceforge.net-20060116023601-wkr0h7edl5veyudq
moving trunk for module inkscape

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 */
 
12
 
 
13
#ifndef __WHITEBOARD_MESSAGE_PROCESSORS_H__
 
14
#define __WHITEBOARD_MESSAGE_PROCESSORS_H__
 
15
 
 
16
#include "jabber_whiteboard/typedefs.h"
 
17
 
 
18
#include "gc-managed.h"
 
19
#include "gc-finalized.h"
 
20
 
 
21
namespace Inkscape {
 
22
 
 
23
namespace Whiteboard {
 
24
 
 
25
class SessionManager;
 
26
 
 
27
// Processor forward declarations
 
28
struct ChangeHandler;
 
29
struct DocumentSignalHandler;
 
30
struct ConnectRequestHandler;
 
31
struct ConnectErrorHandler;
 
32
struct ChatSynchronizeHandler;
 
33
 
 
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
        }
 
53
 
 
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
        }
 
64
 
 
65
 
 
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;
 
82
 
 
83
        /**
 
84
         * The body of this message.
 
85
         */
 
86
        Glib::ustring body;
 
87
 
 
88
private:
 
89
        // noncopyable, nonassignable (for now, anyway...)
 
90
//      JabberMessage(JabberMessage const&);
 
91
//      JabberMessage& operator=(JabberMessage const&);
 
92
};
 
93
 
 
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
        {
 
103
 
 
104
        }
 
105
 
 
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;
 
113
 
 
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;
 
125
 
 
126
private:
 
127
        // noncopyable, nonassignable
 
128
        MessageProcessor(MessageProcessor const&);
 
129
        MessageProcessor& operator=(MessageProcessor const&);
 
130
};
 
131
 
 
132
/*
 
133
struct ProcessorShell : public GC::Managed<>, public std::binary_function< MessageType, JabberMessage, LmHandlerResult > {
 
134
public:
 
135
        ProcessorShell(MessageProcessor* mpm) : _mpm(mpm) { }
 
136
 
 
137
        LmHandlerResult operator()(MessageType type, JabberMessage msg)
 
138
        {
 
139
                return (*this->_mpm)(type, msg);
 
140
        }
 
141
private:
 
142
        MessageProcessor* _mpm;
 
143
};
 
144
*/
 
145
 
 
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);
 
153
 
 
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);
 
160
 
 
161
}
 
162
 
 
163
}
 
164
 
 
165
#endif
 
166
 
 
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 :