call.h 6.66 KB
Newer Older
yanmorin's avatar
   
yanmorin committed
1
2
/*
 *  Copyright (C) 2004-2006 Savoir-Faire Linux inc.
jpbl's avatar
jpbl committed
3
 *  Author: Yan Morin <yan.morin@savoirfairelinux.com>
yanmorin's avatar
   
yanmorin committed
4
5
 *  Author : Laurielle Lea <laurielle.lea@savoirfairelinux.com>
 *
jpbl's avatar
jpbl committed
6
7
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; either version 3 of the License, or
jpbl's avatar
jpbl committed
9
 *  (at your option) any later version.
yanmorin's avatar
   
yanmorin committed
10
 *
jpbl's avatar
jpbl committed
11
12
13
14
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
yanmorin's avatar
   
yanmorin committed
15
 *
jpbl's avatar
jpbl committed
16
17
18
19
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
yanmorin's avatar
   
yanmorin committed
20
21
#ifndef CALL_H
#define CALL_H
jpbl's avatar
jpbl committed
22

yanmorin's avatar
   
yanmorin committed
23
#include <cc++/thread.h> // for mutex
24
#include <sstream>
25

26
#include "plug-in/audiorecorder/audiorecord.h"
yanmorin's avatar
   
yanmorin committed
27

28
29
30
31
32
/* 
 * @file call.h 
 * @brief A call is the base class for protocol-based calls
 */

yanmorin's avatar
   
yanmorin committed
33
34
typedef std::string CallID;

35
36
class AudioRecord;

yanmorin's avatar
   
yanmorin committed
37
class Call{
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
  public:
    /**
     * This determines if the call originated from the local user (Outgoing)
     * or from some remote peer (Incoming).
     */
    enum CallType {Incoming, Outgoing};

    /**
     * Tell where we're at with the call. The call gets Connected when we know
     * from the other end what happened with out call. A call can be 'Connected'
     * even if the call state is Busy, Refused, or Error.
     *
     * Audio should be transmitted when ConnectionState = Connected AND
     * CallState = Active.
     */
    enum ConnectionState {Disconnected, Trying, Progressing, Ringing, Connected};

    /**
     * The Call State.
     */
    enum CallState {Inactive, Active, Hold, Busy, Refused, Error};
jpbl's avatar
jpbl committed
59

yanmorin's avatar
   
yanmorin committed
60
61
62
63
64
65
66
    /**
     * Constructor of a call
     * @param id Unique identifier of the call
     * @param type set definitely this call as incoming/outgoing
     */
    Call(const CallID& id, Call::CallType type);
    virtual ~Call();
jpbl's avatar
jpbl committed
67

yanmorin's avatar
   
yanmorin committed
68
69
70
71
72
    /** 
     * Return a reference on the call id
     * @return call id
     */
    CallID& getCallId() {return _id; }
jpbl's avatar
jpbl committed
73

yanmorin's avatar
   
yanmorin committed
74
75
76
77
78
79
    /** 
     * Set the peer number (destination on outgoing)
     * not protected by mutex (when created)
     * @param number peer number
     */
    void setPeerNumber(const std::string& number) {  _peerNumber = number; }
80
81
82
83
84
85

    /** 
     * Get the peer number (destination on outgoing)
     * not protected by mutex (when created)
     * @return std::string The peer number
     */
yanmorin's avatar
   
yanmorin committed
86
    const std::string& getPeerNumber() {  return _peerNumber; }
jpbl's avatar
jpbl committed
87

yanmorin's avatar
   
yanmorin committed
88
89
90
    /** 
     * Set the peer name (caller in ingoing)
     * not protected by mutex (when created)
91
     * @param name The peer name
yanmorin's avatar
   
yanmorin committed
92
93
     */
    void setPeerName(const std::string& name) {  _peerName = name; }
94
95
96
97
98
99

    /** 
     * Get the peer name (caller in ingoing)
     * not protected by mutex (when created)
     * @return std::string The peer name
     */
yanmorin's avatar
   
yanmorin committed
100
101
    const std::string& getPeerName() {  return _peerName; }

yanmorin's avatar
   
yanmorin committed
102
103
    /**
     * Tell if the call is incoming
104
105
     * @return true if yes
     *	      false otherwise
yanmorin's avatar
   
yanmorin committed
106
107
108
     */
    bool isIncoming() { return (_type == Incoming) ? true : false; }

yanmorin's avatar
   
yanmorin committed
109
110
    /** 
     * Set the connection state of the call (protected by mutex)
111
     * @param state The connection state
yanmorin's avatar
   
yanmorin committed
112
113
     */
    void setConnectionState(ConnectionState state);
114
    
yanmorin's avatar
   
yanmorin committed
115
    /** 
116
117
     * Get the connection state of the call (protected by mutex)
     * @return ConnectionState The connection state
yanmorin's avatar
   
yanmorin committed
118
119
     */
    ConnectionState getConnectionState();
yanmorin's avatar
   
yanmorin committed
120

yanmorin's avatar
   
yanmorin committed
121
122
    /**
     * Set the state of the call (protected by mutex)
123
     * @param state The call state
yanmorin's avatar
   
yanmorin committed
124
125
     */
    void setState(CallState state);
126

yanmorin's avatar
   
yanmorin committed
127
    /** 
128
129
     * Get the call state of the call (protected by mutex)
     * @return CallState  The call state
yanmorin's avatar
   
yanmorin committed
130
131
     */
    CallState getState();
jpbl's avatar
jpbl committed
132

133
134
135
    /**
     * Set the audio start boolean (protected by mutex)
     * @param start true if we start the audio
136
     *		    false otherwise
137
138
139
140
141
142
     */
    void setAudioStart(bool start);

    /**
     * Tell if the audio is started (protected by mutex)
     * @return true if it's already started
143
     *	      false otherwise
144
145
146
     */
    bool isAudioStarted();

Emmanuel Milou's avatar
Emmanuel Milou committed
147
        /** 
148
149
150
     * Set my IP [not protected] 
     * @param ip  The local IP address
     */
151
152
    void setLocalIp(const std::string& ip)     { _localIPAddress = ip; }

153
154
155
156
    /** 
     * Set local audio port, as seen by me [not protected]
     * @param port  The local audio port
     */
157
158
    void setLocalAudioPort(unsigned int port)  { _localAudioPort = port;}

159
160
161
162
    /** 
     * Set the audio port that remote will see.
     * @param port  The external audio port
     */
163
164
    void setLocalExternAudioPort(unsigned int port) { _localExternalAudioPort = port; }

165
166
167
168
    /** 
     * Return the audio port seen by the remote side. 
     * @return unsigned int The external audio port
    */
169
170
    unsigned int getLocalExternAudioPort() { return _localExternalAudioPort; }

171
172
173
174
    /** 
     * Return my IP [mutex protected] 
     * @return std::string The local IP
     */
175
    const std::string& getLocalIp();
176
177
178
179
180

    /** 
     * Return port used locally (for my machine) [mutex protected] 
     * @return unsigned int  The local audio port
     */
181
    unsigned int getLocalAudioPort();
182

183
184
185
186
187
188
    /**
     * @return Return the file name for this call
     */
    std::string getFileName() {return _filename;}

    /**
189
     * A recorder for this call
190
     */
191
192
193
194
195
196
    AudioRecord recAudio;
  
    /**
     * SetRecording
     */
    void setRecording();
197
198
199
200
201

    /**
     * stopRecording, make sure the recording is stopped (whe transfering call)
     */
    void stopRecording();
alexandresavard's avatar
alexandresavard committed
202
203
204
205
206
    
    /**
     * Return Recording state
     */
    bool isRecording(); 
207

208
209
210
211
212
    /**
     *
     */
    void initRecFileName();

213
  protected:
yanmorin's avatar
   
yanmorin committed
214
215
    /** Protect every attribute that can be changed by two threads */
    ost::Mutex _callMutex;
jpbl's avatar
jpbl committed
216

217
218
219
220
221
222
223
224
225
226
227
228
229
    bool _audioStarted;

    // Informations about call socket / audio

    /** My IP address */
    std::string  _localIPAddress;

    /** Local audio port, as seen by me. */
    unsigned int _localAudioPort;

    /** Port assigned to my machine by the NAT, as seen by remote peer (he connects there) */
    unsigned int _localExternalAudioPort;

230
    
231
  private:  
232
  
yanmorin's avatar
   
yanmorin committed
233
234
    /** Unique ID of the call */
    CallID _id;
jpbl's avatar
jpbl committed
235

yanmorin's avatar
   
yanmorin committed
236
237
238
239
240
241
    /** Type of the call */
    CallType _type;
    /** Disconnected/Progressing/Trying/Ringing/Connected */
    ConnectionState _connectionState;
    /** Inactive/Active/Hold/Busy/Refused/Error */
    CallState _callState;
jpbl's avatar
jpbl committed
242

yanmorin's avatar
   
yanmorin committed
243
244
    /** Name of the peer */
    std::string _peerName;
jpbl's avatar
jpbl committed
245

yanmorin's avatar
   
yanmorin committed
246
247
    /** Number of the peer */
    std::string _peerNumber;
248

249
250
    /** File name for his call : time YY-MM-DD */
    std::string _filename;
jpbl's avatar
jpbl committed
251
252
};

yanmorin's avatar
   
yanmorin committed
253
#endif