~ubuntu-branches/ubuntu/maverick/sflphone/maverick

« back to all changes in this revision

Viewing changes to sflphone-common/src/call.h

  • Committer: Bazaar Package Importer
  • Author(s): Francois Marier
  • Date: 2010-06-03 15:59:46 UTC
  • Revision ID: james.westby@ubuntu.com-20100603155946-ybe8d8o8zx8lp0m8
Tags: upstream-0.9.8.3
ImportĀ upstreamĀ versionĀ 0.9.8.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (C) 2004, 2005, 2006, 2009, 2008, 2009, 2010 Savoir-Faire Linux Inc.
 
3
 *  Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
 
4
 *  Author: Yan Morin <yan.morin@savoirfairelinux.com>
 
5
 *  Author : Laurielle Lea <laurielle.lea@savoirfairelinux.com>
 
6
 *
 
7
 *  This program is free software; you can redistribute it and/or modify
 
8
 *  it under the terms of the GNU General Public License as published by
 
9
 *  the Free Software Foundation; either version 3 of the License, or
 
10
 *  (at your option) any later version.
 
11
 *
 
12
 *  This program is distributed in the hope that it will be useful,
 
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 *  GNU General Public License for more details.
 
16
 *
 
17
 *  You should have received a copy of the GNU General Public License
 
18
 *  along with this program; if not, write to the Free Software
 
19
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
20
 *
 
21
 *  Additional permission under GNU GPL version 3 section 7:
 
22
 *
 
23
 *  If you modify this program, or any covered work, by linking or
 
24
 *  combining it with the OpenSSL project's OpenSSL library (or a
 
25
 *  modified version of that library), containing parts covered by the
 
26
 *  terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
 
27
 *  grants you additional permission to convey the resulting work.
 
28
 *  Corresponding Source for a non-source form of such a combination
 
29
 *  shall include the source code for the parts of OpenSSL used as well
 
30
 *  as that of the covered work.
 
31
 */
 
32
#ifndef CALL_H
 
33
#define CALL_H
 
34
 
 
35
#include <cc++/thread.h> // for mutex
 
36
#include <sstream>
 
37
 
 
38
// #include "plug-in/audiorecorder/audiorecord.h"
 
39
#include "audio/recordable.h"
 
40
 
 
41
#define SIP_SCHEME       "sip:"
 
42
#define SIPS_SCHEME      "sips:"
 
43
 
 
44
#define CallConfigNULL   NULL
 
45
 
 
46
/* 
 
47
 * @file call.h 
 
48
 * @brief A call is the base class for protocol-based calls
 
49
 */
 
50
 
 
51
typedef std::string CallID;
 
52
 
 
53
class Call: public Recordable{
 
54
    public:
 
55
 
 
56
        /**
 
57
         * This determines if the call is a direct IP-to-IP call or a classic call, made with an existing account
 
58
         */
 
59
        enum CallConfiguration {Classic, IPtoIP};
 
60
 
 
61
        /**
 
62
         * This determines if the call originated from the local user (Outgoing)
 
63
         * or from some remote peer (Incoming).
 
64
         */
 
65
        enum CallType {Incoming, Outgoing};
 
66
 
 
67
        /**
 
68
         * Tell where we're at with the call. The call gets Connected when we know
 
69
         * from the other end what happened with out call. A call can be 'Connected'
 
70
         * even if the call state is Busy, Refused, or Error.
 
71
         *
 
72
         * Audio should be transmitted when ConnectionState = Connected AND
 
73
         * CallState = Active.
 
74
         */
 
75
        enum ConnectionState {Disconnected, Trying, Progressing, Ringing, Connected};
 
76
 
 
77
        /**
 
78
         * The Call State.
 
79
         */
 
80
        enum CallState {Inactive, Active, Hold, Busy, Conferencing, Refused, Error};
 
81
 
 
82
        /**
 
83
         * Constructor of a call
 
84
         * @param id Unique identifier of the call
 
85
         * @param type set definitely this call as incoming/outgoing
 
86
         */
 
87
        Call(const CallID& id, Call::CallType type);
 
88
        virtual ~Call();
 
89
 
 
90
        /** 
 
91
         * Return a reference on the call id
 
92
         * @return call id
 
93
         */
 
94
        CallID& getCallId() {return _id; }
 
95
 
 
96
        /** 
 
97
         * Return a reference on the conference id
 
98
         * @return call id
 
99
         */
 
100
        CallID& getConfId() {return _confID; }
 
101
 
 
102
        void setConfId(CallID id) {_confID = id; }
 
103
 
 
104
        inline CallType getCallType (void)
 
105
        {
 
106
            return _type;
 
107
        }
 
108
 
 
109
        /** 
 
110
         * Set the peer number (destination on outgoing)
 
111
         * not protected by mutex (when created)
 
112
         * @param number peer number
 
113
         */
 
114
        void setPeerNumber(const std::string& number) {  _peerNumber = number; }
 
115
 
 
116
        /** 
 
117
         * Get the peer number (destination on outgoing)
 
118
         * not protected by mutex (when created)
 
119
         * @return std::string The peer number
 
120
         */
 
121
        const std::string& getPeerNumber() {  return _peerNumber; }
 
122
 
 
123
        /** 
 
124
         * Set the peer name (caller in ingoing)
 
125
         * not protected by mutex (when created)
 
126
         * @param name The peer name
 
127
         */
 
128
        void setPeerName(const std::string& name) {  _peerName = name; }
 
129
 
 
130
        /** 
 
131
         * Get the peer name (caller in ingoing)
 
132
         * not protected by mutex (when created)
 
133
         * @return std::string The peer name
 
134
         */
 
135
        const std::string& getPeerName() {  return _peerName; }
 
136
 
 
137
        /** 
 
138
         * Set the display name (caller in ingoing)
 
139
         * not protected by mutex (when created)
 
140
         * @return std::string The peer display name
 
141
         */
 
142
        void setDisplayName(const std::string& name) {  _displayName = name; }
 
143
 
 
144
        /** 
 
145
         * Get the peer display name (caller in ingoing)
 
146
         * not protected by mutex (when created)
 
147
         * @return std::string The peer name
 
148
         */
 
149
        const std::string& getDisplayName() {  return _displayName; }
 
150
 
 
151
        /**
 
152
         * Tell if the call is incoming
 
153
         * @return true if yes
 
154
         *            false otherwise
 
155
         */
 
156
        bool isIncoming() { return (_type == Incoming) ? true : false; }
 
157
 
 
158
        /** 
 
159
         * Set the connection state of the call (protected by mutex)
 
160
         * @param state The connection state
 
161
         */
 
162
        void setConnectionState(ConnectionState state);
 
163
 
 
164
        /** 
 
165
         * Get the connection state of the call (protected by mutex)
 
166
         * @return ConnectionState The connection state
 
167
         */
 
168
        ConnectionState getConnectionState();
 
169
 
 
170
        /**
 
171
         * Set the state of the call (protected by mutex)
 
172
         * @param state The call state
 
173
         */
 
174
        void setState(CallState state);
 
175
 
 
176
        /** 
 
177
         * Get the call state of the call (protected by mutex)
 
178
         * @return CallState  The call state
 
179
         */
 
180
        CallState getState();
 
181
        
 
182
        std::string getStateStr ();
 
183
 
 
184
        void setCallConfiguration (Call::CallConfiguration callConfig) { _callConfig = callConfig; }
 
185
        
 
186
        Call::CallConfiguration getCallConfiguration (void) { return _callConfig; }
 
187
        
 
188
        /**
 
189
         * Set the audio start boolean (protected by mutex)
 
190
         * @param start true if we start the audio
 
191
         *                  false otherwise
 
192
         */
 
193
        void setAudioStart(bool start);
 
194
 
 
195
        /**
 
196
         * Tell if the audio is started (protected by mutex)
 
197
         * @return true if it's already started
 
198
         *            false otherwise
 
199
         */
 
200
        bool isAudioStarted();
 
201
 
 
202
        /** 
 
203
         * Set my IP [not protected] 
 
204
         * @param ip  The local IP address
 
205
         */
 
206
        void setLocalIp(const std::string& ip)     { _localIPAddress = ip; }
 
207
 
 
208
        /** 
 
209
         * Set local audio port, as seen by me [not protected]
 
210
         * @param port  The local audio port
 
211
         */
 
212
        void setLocalAudioPort(unsigned int port)  { _localAudioPort = port;}
 
213
 
 
214
        /** 
 
215
         * Set the audio port that remote will see.
 
216
         * @param port  The external audio port
 
217
         */
 
218
        void setLocalExternAudioPort(unsigned int port) { _localExternalAudioPort = port; }
 
219
 
 
220
        /** 
 
221
         * Return the audio port seen by the remote side. 
 
222
         * @return unsigned int The external audio port
 
223
         */
 
224
        unsigned int getLocalExternAudioPort() { return _localExternalAudioPort; }
 
225
 
 
226
        /** 
 
227
         * Return my IP [mutex protected] 
 
228
         * @return std::string The local IP
 
229
         */
 
230
        const std::string& getLocalIp();
 
231
 
 
232
        /** 
 
233
         * Return port used locally (for my machine) [mutex protected] 
 
234
         * @return unsigned int  The local audio port
 
235
         */
 
236
        unsigned int getLocalAudioPort();
 
237
 
 
238
        std::string getRecFileId(){ return getPeerName(); }
 
239
 
 
240
        std::string getFileName() { return _filename; }
 
241
 
 
242
    protected:
 
243
        /** Protect every attribute that can be changed by two threads */
 
244
        ost::Mutex _callMutex;
 
245
 
 
246
        bool _audioStarted;
 
247
 
 
248
        // Informations about call socket / audio
 
249
 
 
250
        /** My IP address */
 
251
        std::string  _localIPAddress;
 
252
 
 
253
        /** Local audio port, as seen by me. */
 
254
        unsigned int _localAudioPort;
 
255
 
 
256
        /** Port assigned to my machine by the NAT, as seen by remote peer (he connects there) */
 
257
        unsigned int _localExternalAudioPort;
 
258
 
 
259
 
 
260
    private:  
 
261
 
 
262
        /** Unique ID of the call */
 
263
        CallID _id;
 
264
 
 
265
        /** Unique conference ID, used exclusively in case of a conferece */
 
266
        CallID _confID;
 
267
 
 
268
        /** Type of the call */
 
269
        CallType _type;
 
270
 
 
271
        /** Disconnected/Progressing/Trying/Ringing/Connected */
 
272
        ConnectionState _connectionState;
 
273
 
 
274
        /** Inactive/Active/Hold/Busy/Refused/Error */
 
275
        CallState _callState;
 
276
 
 
277
        /** Direct IP-to-IP or classic call */
 
278
        CallConfiguration _callConfig;
 
279
 
 
280
        /** Name of the peer */
 
281
        std::string _peerName;
 
282
 
 
283
        /** Number of the peer */
 
284
        std::string _peerNumber;
 
285
 
 
286
        /** Display Name */
 
287
        std::string _displayName;
 
288
 
 
289
        /** File name for his call : time YY-MM-DD */
 
290
        std::string _filename;
 
291
 
 
292
        
 
293
};
 
294
 
 
295
#endif