call.h 8.21 KB
Newer Older
yanmorin's avatar
 
yanmorin committed
1
/*
2
 *  Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
Emmanuel Milou's avatar
Emmanuel Milou committed
3
 *  Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
jpbl's avatar
jpbl committed
4
 *  Author: Yan Morin <yan.morin@savoirfairelinux.com>
yanmorin's avatar
 
yanmorin committed
5 6
 *  Author : Laurielle Lea <laurielle.lea@savoirfairelinux.com>
 *
jpbl's avatar
jpbl committed
7 8
 *  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
9
 *  the Free Software Foundation; either version 3 of the License, or
jpbl's avatar
jpbl committed
10
 *  (at your option) any later version.
yanmorin's avatar
 
yanmorin committed
11
 *
jpbl's avatar
jpbl committed
12 13 14 15
 *  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
16
 *
jpbl's avatar
jpbl committed
17 18
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
19
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
20 21 22 23 24 25 26 27 28 29 30
 *
 *  Additional permission under GNU GPL version 3 section 7:
 *
 *  If you modify this program, or any covered work, by linking or
 *  combining it with the OpenSSL project's OpenSSL library (or a
 *  modified version of that library), containing parts covered by the
 *  terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
 *  grants you additional permission to convey the resulting work.
 *  Corresponding Source for a non-source form of such a combination
 *  shall include the source code for the parts of OpenSSL used as well
 *  as that of the covered work.
jpbl's avatar
jpbl committed
31
 */
32 33
#ifndef __CALL_H__
#define __CALL_H__
jpbl's avatar
jpbl committed
34

35
#include <sstream>
36
#include <map>
37
#include <mutex>
38
#include "audio/recordable.h"
yanmorin's avatar
 
yanmorin committed
39

Julien Bonjean's avatar
Julien Bonjean committed
40 41
/*
 * @file call.h
42 43 44
 * @brief A call is the base class for protocol-based calls
 */

45
class Call : public Recordable {
Emmanuel Milou's avatar
Emmanuel Milou committed
46
    public:
47
        static const char * const DEFAULT_ID;
Emmanuel Milou's avatar
Emmanuel Milou committed
48 49

        /**
50 51
         * This determines if the call originated from the local user (OUTGOING)
         * or from some remote peer (INCOMING, MISSED).
Emmanuel Milou's avatar
Emmanuel Milou committed
52
         */
53
        enum CallType {INCOMING, OUTGOING, MISSED};
Emmanuel Milou's avatar
Emmanuel Milou committed
54 55 56 57 58 59 60 61 62

        /**
         * 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.
         */
63
        enum ConnectionState {DISCONNECTED, TRYING, PROGRESSING, RINGING, CONNECTED};
Emmanuel Milou's avatar
Emmanuel Milou committed
64 65 66 67

        /**
         * The Call State.
         */
68
        enum CallState {INACTIVE, ACTIVE, HOLD, BUSY, CONFERENCING, REFUSED, ERROR};
Emmanuel Milou's avatar
Emmanuel Milou committed
69 70 71 72 73 74

        /**
         * Constructor of a call
         * @param id Unique identifier of the call
         * @param type set definitely this call as incoming/outgoing
         */
75
        Call(const std::string& id, Call::CallType type, const std::string &accountID);
Emmanuel Milou's avatar
Emmanuel Milou committed
76 77
        virtual ~Call();

Julien Bonjean's avatar
Julien Bonjean committed
78
        /**
79
         * Return a copy of the call id
Emmanuel Milou's avatar
Emmanuel Milou committed
80 81
         * @return call id
         */
82
        std::string getCallId() const {
83
            return id_;
Julien Bonjean's avatar
Julien Bonjean committed
84
        }
Emmanuel Milou's avatar
Emmanuel Milou committed
85

Julien Bonjean's avatar
Julien Bonjean committed
86
        /**
87 88 89
         * Return a reference on the conference id
         * @return call id
         */
90
        std::string getConfId() const {
91
            return confID_;
Julien Bonjean's avatar
Julien Bonjean committed
92
        }
Alexandre Savard's avatar
Alexandre Savard committed
93

94
        void setConfId(const std::string &id) {
95
            confID_ = id;
Julien Bonjean's avatar
Julien Bonjean committed
96
        }
Alexandre Savard's avatar
Alexandre Savard committed
97

98 99 100 101
        std::string getAccountId() const {
            return accountID_;
        }

102 103
        CallType getCallType() const {
            return type_;
Emmanuel Milou's avatar
Emmanuel Milou committed
104 105
        }

Julien Bonjean's avatar
Julien Bonjean committed
106
        /**
Emmanuel Milou's avatar
Emmanuel Milou committed
107 108 109 110
         * Set the peer number (destination on outgoing)
         * not protected by mutex (when created)
         * @param number peer number
         */
111
        void setPeerNumber(const std::string& number) {
112
            peerNumber_ = number;
Julien Bonjean's avatar
Julien Bonjean committed
113
        }
Emmanuel Milou's avatar
Emmanuel Milou committed
114

Julien Bonjean's avatar
Julien Bonjean committed
115
        /**
Emmanuel Milou's avatar
Emmanuel Milou committed
116 117 118 119
         * Get the peer number (destination on outgoing)
         * not protected by mutex (when created)
         * @return std::string The peer number
         */
120 121
        std::string getPeerNumber() const {
            return peerNumber_;
Julien Bonjean's avatar
Julien Bonjean committed
122
        }
Emmanuel Milou's avatar
Emmanuel Milou committed
123

Julien Bonjean's avatar
Julien Bonjean committed
124
        /**
125 126 127 128
         * Set the display name (caller in ingoing)
         * not protected by mutex (when created)
         * @return std::string The peer display name
         */
129
        void setDisplayName(const std::string& name) {
130
            displayName_ = name;
Julien Bonjean's avatar
Julien Bonjean committed
131
        }
132

Julien Bonjean's avatar
Julien Bonjean committed
133
        /**
134 135 136 137
         * Get the peer display name (caller in ingoing)
         * not protected by mutex (when created)
         * @return std::string The peer name
         */
138
        const std::string& getDisplayName() const {
139
            return displayName_;
Julien Bonjean's avatar
Julien Bonjean committed
140
        }
141

Emmanuel Milou's avatar
Emmanuel Milou committed
142 143
        /**
         * Tell if the call is incoming
144
         * @return true if yes false otherwise
Emmanuel Milou's avatar
Emmanuel Milou committed
145
         */
146 147
        bool isIncoming() const {
            return type_ == INCOMING;
Julien Bonjean's avatar
Julien Bonjean committed
148
        }
Emmanuel Milou's avatar
Emmanuel Milou committed
149

Julien Bonjean's avatar
Julien Bonjean committed
150
        /**
Emmanuel Milou's avatar
Emmanuel Milou committed
151 152 153
         * Set the connection state of the call (protected by mutex)
         * @param state The connection state
         */
154
        void setConnectionState(ConnectionState state);
Emmanuel Milou's avatar
Emmanuel Milou committed
155

Julien Bonjean's avatar
Julien Bonjean committed
156
        /**
Emmanuel Milou's avatar
Emmanuel Milou committed
157 158 159 160 161 162 163 164 165
         * Get the connection state of the call (protected by mutex)
         * @return ConnectionState The connection state
         */
        ConnectionState getConnectionState();

        /**
         * Set the state of the call (protected by mutex)
         * @param state The call state
         */
166
        void setState(CallState state);
Emmanuel Milou's avatar
Emmanuel Milou committed
167

Julien Bonjean's avatar
Julien Bonjean committed
168
        /**
Emmanuel Milou's avatar
Emmanuel Milou committed
169 170 171 172
         * Get the call state of the call (protected by mutex)
         * @return CallState  The call state
         */
        CallState getState();
Julien Bonjean's avatar
Julien Bonjean committed
173

174
        std::string getStateStr();
Emmanuel Milou's avatar
Emmanuel Milou committed
175

176 177
        void setIPToIP(bool IPToIP) {
            isIPToIP_ = IPToIP;
Julien Bonjean's avatar
Julien Bonjean committed
178 179
        }

180 181
        virtual void answer() = 0;

Julien Bonjean's avatar
Julien Bonjean committed
182 183
        /**
         * Set my IP [not protected]
Emmanuel Milou's avatar
Emmanuel Milou committed
184 185
         * @param ip  The local IP address
         */
186
        void setLocalIp(const std::string& ip) {
187
            localIPAddress_ = ip;
Julien Bonjean's avatar
Julien Bonjean committed
188
        }
Emmanuel Milou's avatar
Emmanuel Milou committed
189

Julien Bonjean's avatar
Julien Bonjean committed
190
        /**
Emmanuel Milou's avatar
Emmanuel Milou committed
191 192 193
         * Set local audio port, as seen by me [not protected]
         * @param port  The local audio port
         */
194
        void setLocalAudioPort(unsigned int port) {
195
            localAudioPort_ = port;
Julien Bonjean's avatar
Julien Bonjean committed
196
        }
Emmanuel Milou's avatar
Emmanuel Milou committed
197

198 199 200 201
        /**
         * Set local video port, as seen by me [not protected]
         * @param port  The local video port
         */
Tristan Matthews's avatar
Tristan Matthews committed
202
        void setLocalVideoPort(unsigned int port)  {
203
            localVideoPort_ = port;
204 205
        }

Julien Bonjean's avatar
Julien Bonjean committed
206 207
        /**
         * Return my IP [mutex protected]
Emmanuel Milou's avatar
Emmanuel Milou committed
208 209
         * @return std::string The local IP
         */
210
        std::string getLocalIp();
Emmanuel Milou's avatar
Emmanuel Milou committed
211

Julien Bonjean's avatar
Julien Bonjean committed
212 213
        /**
         * Return port used locally (for my machine) [mutex protected]
Emmanuel Milou's avatar
Emmanuel Milou committed
214 215 216 217
         * @return unsigned int  The local audio port
         */
        unsigned int getLocalAudioPort();

218 219 220 221 222 223
        /**
         * Return port used locally (for my machine) [mutex protected]
         * @return unsigned int  The local video port
         */
        unsigned int getLocalVideoPort();

224
        void time_stop();
225
        virtual std::map<std::string, std::string> getDetails();
226
        static std::map<std::string, std::string> getNullDetails();
227 228 229 230

        virtual std::map<std::string, std::string>
        createHistoryEntry() const;

231
        virtual bool toggleRecording();
232

233
    private:
234
        std::string getTypeStr() const;
Emmanuel Milou's avatar
Emmanuel Milou committed
235
        /** Protect every attribute that can be changed by two threads */
236
        std::mutex callMutex_;
Emmanuel Milou's avatar
Emmanuel Milou committed
237 238 239 240

        // Informations about call socket / audio

        /** My IP address */
241
        std::string localIPAddress_;
Emmanuel Milou's avatar
Emmanuel Milou committed
242 243

        /** Local audio port, as seen by me. */
244
        unsigned int localAudioPort_;
Emmanuel Milou's avatar
Emmanuel Milou committed
245

246
        /** Local video port, as seen by me. */
247
        unsigned int localVideoPort_;
Emmanuel Milou's avatar
Emmanuel Milou committed
248 249

        /** Unique ID of the call */
250
        std::string id_;
Emmanuel Milou's avatar
Emmanuel Milou committed
251

Julien Bonjean's avatar
Julien Bonjean committed
252
        /** Unique conference ID, used exclusively in case of a conferece */
253
        std::string confID_;
Alexandre Savard's avatar
Alexandre Savard committed
254

Emmanuel Milou's avatar
Emmanuel Milou committed
255
        /** Type of the call */
256
        CallType type_;
257

258 259 260
        /** Associate account ID */
        std::string accountID_;

Emmanuel Milou's avatar
Emmanuel Milou committed
261
        /** Disconnected/Progressing/Trying/Ringing/Connected */
262
        ConnectionState connectionState_;
263

Emmanuel Milou's avatar
Emmanuel Milou committed
264
        /** Inactive/Active/Hold/Busy/Refused/Error */
265
        CallState callState_;
Emmanuel Milou's avatar
Emmanuel Milou committed
266 267

        /** Direct IP-to-IP or classic call */
268
        bool isIPToIP_;
Emmanuel Milou's avatar
Emmanuel Milou committed
269 270

        /** Number of the peer */
271
        std::string peerNumber_;
Emmanuel Milou's avatar
Emmanuel Milou committed
272

Julien Bonjean's avatar
Julien Bonjean committed
273
        /** Display Name */
274
        std::string displayName_;
275 276 277

        time_t timestamp_start_;
        time_t timestamp_stop_;
jpbl's avatar
jpbl committed
278 279
};

280
#endif // __CALL_H__