sipvoiplink.h 7.8 KB
Newer Older
jpbl's avatar
jpbl committed
1
/*
2
 *  Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010, 2011 Savoir-Faire Linux Inc.
3
 *
4
 *  Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
Emmanuel Milou's avatar
Emmanuel Milou committed
5
 *  Author: Yun Liu <yun.liu@savoirfairelinux.com>
6
 *  Author: Pierre-Luc Bacon <pierre-luc.bacon@savoirfairelinux.com>
7
 *  Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
jpbl's avatar
jpbl committed
8 9 10
 *
 *  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
11
 *  the Free Software Foundation; either version 3 of the License, or
jpbl's avatar
jpbl committed
12 13 14 15
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16

jpbl's avatar
jpbl committed
17 18 19 20 21
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
22
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 24 25 26 27 28 29 30 31 32 33
 *
 *  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
34
 */
35

36 37
#ifndef SIPVOIPLINK_H_
#define SIPVOIPLINK_H_
jpbl's avatar
jpbl committed
38

39
#include <map>
40

41 42 43
#include <pjsip.h>
#include <pjlib.h>
#include <pjsip_ua.h>
Emmanuel Milou's avatar
Emmanuel Milou committed
44
#include <pjlib-util.h>
45
#include <pjnath.h>
Emmanuel Milou's avatar
Emmanuel Milou committed
46
#include <pjnath/stun_config.h>
47

Rafaël Carré's avatar
Rafaël Carré committed
48
#include "sipaccount.h"
49
#include "voiplink.h"
50
#include "siptransport.h"
51
#include "eventthread.h"
52

yanmorin's avatar
 
yanmorin committed
53
class SIPCall;
Rafaël Carré's avatar
Rafaël Carré committed
54
class SIPAccount;
55

yanmorin's avatar
 
yanmorin committed
56
/**
57
 * @file sipvoiplink.h
Emmanuel Milou's avatar
Emmanuel Milou committed
58 59 60
 * @brief Specific VoIPLink for SIP (SIP core for incoming and outgoing events).
 *          This class is based on the singleton design pattern.
 *          One SIPVoIPLink can handle multiple SIP accounts, but all the SIP accounts have all the same SIPVoIPLink
yanmorin's avatar
 
yanmorin committed
61
 */
Alexandre Bourget's avatar
Alexandre Bourget committed
62

63 64
class SIPVoIPLink : public VoIPLink {
    public:
65

66
        /**
Emmanuel Milou's avatar
Emmanuel Milou committed
67 68
         * Singleton method. Enable to retrieve the unique static instance
         * @return SIPVoIPLink* A pointer on the object
69
         */
70
        static SIPVoIPLink* instance();
71

72 73 74 75 76
        /**
         * Destroy the singleton instance
         */
        static void destroy();

77 78 79
        /**
         * Event listener. Each event send by the call manager is received and handled from here
         */
80
        virtual bool getEvent();
81 82 83 84

        /**
         * Build and send SIP registration request
         */
85
        virtual void sendRegister(Account *a);
86 87 88 89

        /**
         * Build and send SIP unregistration request
         */
90
        virtual void sendUnregister(Account *a);
91

92 93 94 95 96 97 98 99
        /**
         * Register a new keepalive registration timer to this endpoint
         */
        void registerKeepAliveTimer(pj_timer_entry& timer, pj_time_val& delay);

        /**
         * Abort currently registered timer
         */
100
        void cancelKeepAliveTimer(pj_timer_entry& timer);
101

102 103 104 105 106 107
        /**
         * Place a new call
         * @param id  The call identifier
         * @param toUrl  The Sip address of the recipient of the call
         * @return Call* The current call
         */
108
        virtual Call* newOutgoingCall(const std::string& id, const std::string& toUrl);
109

110 111 112 113 114 115 116 117 118 119 120 121 122 123
        /**
         * Start a new SIP call using the IP2IP profile
         * @param The call id
         * @param The target sip uri
         */
        Call *SIPNewIpToIpCall(const std::string& id, const std::string& to);

        /**
         * Place a call using the currently selected account
         * @param The call id
         * @param The target sip uri
         */
        Call *newRegisteredAccountCall(const std::string& id, const std::string& toUrl);

124 125
        /**
         * Answer the call
126
         * @param c The call
127
         */
128
        virtual void answer(Call *c);
129 130 131 132 133

        /**
         * Hang up the call
         * @param id The call identifier
         */
134
        virtual void hangup(const std::string& id);
135

136 137 138 139
        /**
         * Hang up the call
         * @param id The call identifier
         */
140
        virtual void peerHungup(const std::string& id);
141

142 143 144 145 146
        /**
         * Put the call on hold
         * @param id The call identifier
         * @return bool True on success
         */
147
        virtual void onhold(const std::string& id);
148 149 150 151 152 153

        /**
         * Put the call off hold
         * @param id The call identifier
         * @return bool True on success
         */
154
        virtual void offhold(const std::string& id);
155

Rafaël Carré's avatar
Rafaël Carré committed
156 157
        bool transferCommon(SIPCall *call, pj_str_t *dst);

158 159 160 161 162
        /**
         * Transfer the call
         * @param id The call identifier
         * @param to The recipient of the transfer
         */
163
        virtual void transfer(const std::string& id, const std::string& to);
164

165 166 167 168 169 170
        /**
         * Attended transfer
         * @param The transfered call id
         * @param The target call id
         * @return True on success
         */
171
        virtual bool attendedTransfer(const std::string&, const std::string&);
172

173 174 175 176
        /**
         * Refuse the call
         * @param id The call identifier
         */
177
        virtual void refuse(const std::string& id);
178 179

        /**
180
         * Send DTMF refering to account configuration
181 182 183
         * @param id The call identifier
         * @param code  The char code
         */
184
        virtual void carryingDTMFdigits(const std::string& id, char code);
185 186 187 188 189

        /**
         * Tell the user that the call was answered
         * @param
         */
190
        void SIPCallAnswered(SIPCall *call, pjsip_rx_data *rdata);
191 192 193

        /**
         * Handling 5XX/6XX error
Julien Bonjean's avatar
Julien Bonjean committed
194
         * @param
195
         */
196
        void SIPCallServerFailure(SIPCall *call);
197 198 199 200 201

        /**
         * Peer close the connection
         * @param
         */
202
        void SIPCallClosed(SIPCall *call);
203

204
        pj_caching_pool *getMemoryPoolFactory();
205

Alexandre Savard's avatar
Alexandre Savard committed
206
        /**
207 208 209
         * SIPCall accessor
         * @param id  The call identifier
         * @return SIPCall*	  A pointer on SIPCall object
Alexandre Savard's avatar
Alexandre Savard committed
210
         */
211
        SIPCall* getSIPCall(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
212 213 214

        /**
         * Return the codec protocol used for this call
Rafaël Carré's avatar
Rafaël Carré committed
215
         * @param c The call identifier
Julien Bonjean's avatar
Julien Bonjean committed
216
         */
217
        std::string getCurrentCodecName(Call *c) const;
Julien Bonjean's avatar
Julien Bonjean committed
218

219 220 221
        /**
         * Retrive useragent name from account
         */
222
        std::string getUseragentName(SIPAccount *) const;
223

224
        /**
225 226
         * Send a SIP message to a call identified by its callid
         *
227 228 229 230
         * @param The Id of the call to send the message to
         * @param The actual message to be transmitted
         * @param The sender of this message (could be another participant of a conference)
         */
231
        void sendTextMessage(const std::string& callID,
232 233
                             const std::string& message,
                             const std::string& from);
234

235 236 237
        /**
         * Create the default UDP transport according ot Ip2Ip profile settings
         */
238
        void createDefaultSipUdpTransport();
239

240
        SipTransport sipTransport;
241

242
    private:
243 244 245 246 247

        NON_COPYABLE(SIPVoIPLink);

        SIPVoIPLink();
        ~SIPVoIPLink();
248 249 250 251 252
        /**
         * Start a SIP Call
         * @param call  The current call
         * @return true if all is correct
         */
253
        bool SIPStartCall(SIPCall* call);
Rafaël Carré's avatar
Rafaël Carré committed
254

255
        void dtmfSend(SIPCall *call, char code, const std::string &type);
256

257 258 259
        /**
         * Threading object
         */
260
        EventThread evThread_;
Julien Bonjean's avatar
Julien Bonjean committed
261

262
        friend class SIPTest;
263 264
        static bool destroyed_;
        static SIPVoIPLink *instance_;
jpbl's avatar
jpbl committed
265 266
};

267
#endif // SIPVOIPLINK_H_