callmanager.cpp 12.4 KB
Newer Older
1
/*
Adrien Béraud's avatar
Adrien Béraud committed
2
 *  Copyright (C) 2004-2015 Savoir-Faire Linux Inc.
3
 *  Author: Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com>
4
 *  Author: Alexandre Bourget <alexandre.bourget@savoirfairelinux.com>
5
 *
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
9
 *  (at your option) any later version.
10
 *
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.
15
 *
16 17
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
18
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
19 20 21 22 23 24 25 26 27 28 29
 *
 *  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.
30
 */
31
#include <vector>
32
#include <cstring>
33

34
#include "callmanager.h"
35
#include "libav_utils.h"
36
#include "call_factory.h"
37

38
#include "sip/sipcall.h"
39
#include "sip/sipvoiplink.h"
40
#include "audio/audiolayer.h"
41

42
#include "logger.h"
43
#include "manager.h"
44

45 46
namespace ring {

47 48 49 50 51
CallManager::CallManager()
{
    libav_utils::sfl_avcodec_init();
}

Adrien Béraud's avatar
Adrien Béraud committed
52
void CallManager::registerEvHandlers(struct ring_call_ev_handlers* evHandlers)
53 54 55 56
{
    evHandlers_ = *evHandlers;
}

57
bool CallManager::placeCall(const std::string& accountID,
58 59
                            const std::string& callID,
                            const std::string& to)
Emmanuel Milou's avatar
Emmanuel Milou committed
60
{
61
    // Check if a destination number is available
62
    if (to.empty()) {
Adrien Béraud's avatar
Adrien Béraud committed
63
        RING_DBG("No number entered - Call stopped");
64 65 66 67
        return false;
    } else {
        return Manager::instance().outgoingCall(accountID, callID, to);
    }
68 69
}

70
bool
71
CallManager::refuse(const std::string& callID)
Emmanuel Milou's avatar
Emmanuel Milou committed
72
{
73
    return Manager::instance().refuseCall(callID);
74 75
}

76
bool
77
CallManager::accept(const std::string& callID)
Emmanuel Milou's avatar
Emmanuel Milou committed
78
{
79
    return Manager::instance().answerCall(callID);
80 81
}

82
bool
83
CallManager::hangUp(const std::string& callID)
Emmanuel Milou's avatar
Emmanuel Milou committed
84
{
85
    return Manager::instance().hangupCall(callID);
86 87
}

88
bool
89
CallManager::hangUpConference(const std::string& confID)
Emmanuel Milou's avatar
Emmanuel Milou committed
90
{
91
    return Manager::instance().hangupConference(confID);
92 93
}

94
bool
95
CallManager::hold(const std::string& callID)
Emmanuel Milou's avatar
Emmanuel Milou committed
96
{
97
    return Manager::instance().onHoldCall(callID);
98 99
}

100
bool
101
CallManager::unhold(const std::string& callID)
Emmanuel Milou's avatar
Emmanuel Milou committed
102
{
103
    return Manager::instance().offHoldCall(callID);
104 105
}

106
bool
107
CallManager::transfer(const std::string& callID, const std::string& to)
Emmanuel Milou's avatar
Emmanuel Milou committed
108
{
109
    return Manager::instance().transferCall(callID, to);
110 111
}

112 113
bool
CallManager::attendedTransfer(const std::string& transferID, const std::string& targetID)
114
{
115
    return Manager::instance().attendedTransfer(transferID, targetID);
116
}
117

118 119 120
bool
CallManager::joinParticipant(const std::string& sel_callID,
                             const std::string& drag_callID)
Emmanuel Milou's avatar
Emmanuel Milou committed
121
{
122
    return Manager::instance().joinParticipant(sel_callID, drag_callID);
123 124
}

125
void
126
CallManager::createConfFromParticipantList(const std::vector<std::string>& participants)
127
{
128
    Manager::instance().createConfFromParticipantList(participants);
129 130
}

131 132 133 134 135 136 137 138 139 140 141 142
bool
CallManager::isConferenceParticipant(const std::string& callID)
{
    return  Manager::instance().isConferenceParticipant(callID);
}

void
CallManager::removeConference(const std::string& conference_id)
{
    Manager::instance().removeConference(conference_id);
}

143
bool
144
CallManager::addParticipant(const std::string& callID, const std::string& confID)
Emmanuel Milou's avatar
Emmanuel Milou committed
145
{
146
    return  Manager::instance().addParticipant(callID, confID);
147 148
}

149
bool
150
CallManager::addMainParticipant(const std::string& confID)
Emmanuel Milou's avatar
Emmanuel Milou committed
151
{
152
    return Manager::instance().addMainParticipant(confID);
153 154
}

155
bool
156
CallManager::detachParticipant(const std::string& callID)
Emmanuel Milou's avatar
Emmanuel Milou committed
157
{
158
    return Manager::instance().detachParticipant(callID);
159 160
}

161
bool
162
CallManager::joinConference(const std::string& sel_confID, const std::string& drag_confID)
Emmanuel Milou's avatar
Emmanuel Milou committed
163
{
164
    return Manager::instance().joinConference(sel_confID, drag_confID);
165 166
}

167
bool
168
CallManager::holdConference(const std::string& confID)
Emmanuel Milou's avatar
Emmanuel Milou committed
169
{
170
    return Manager::instance().holdConference(confID);
171 172
}

173
bool
174
CallManager::unholdConference(const std::string& confID)
Emmanuel Milou's avatar
Emmanuel Milou committed
175
{
176
    return Manager::instance().unHoldConference(confID);
177 178
}

179
std::map<std::string, std::string>
180
CallManager::getConferenceDetails(const std::string& callID)
Emmanuel Milou's avatar
Emmanuel Milou committed
181
{
182
    return Manager::instance().getConferenceDetails(callID);
183
}
184

185
std::vector<std::string>
186
CallManager::getConferenceList()
Emmanuel Milou's avatar
Emmanuel Milou committed
187
{
188 189
    return Manager::instance().getConferenceList();
}
190

191
std::vector<std::string>
192
CallManager::getParticipantList(const std::string& confID)
Emmanuel Milou's avatar
Emmanuel Milou committed
193
{
194
    return Manager::instance().getParticipantList(confID);
195 196
}

197 198 199 200 201 202
std::vector<std::string>
CallManager::getDisplayNames(const std::string& confID)
{
    return Manager::instance().getDisplayNames(confID);
}

203 204 205 206 207 208
std::string
CallManager::getConferenceId(const std::string& callID)
{
    return Manager::instance().getConferenceId(callID);
}

209
bool
210 211
CallManager::startRecordedFilePlayback(const std::string& filepath)
{
212
    return Manager::instance().startRecordedFilePlayback(filepath);
213 214 215 216 217 218 219 220
}

void
CallManager::stopRecordedFilePlayback(const std::string& filepath)
{
    Manager::instance().stopRecordedFilePlayback(filepath);
}

221 222 223 224 225 226
bool
CallManager::toggleRecording(const std::string& callID)
{
    return Manager::instance().toggleRecordingCall(callID);
}

227
void
228
CallManager::setRecording(const std::string& callID)
Emmanuel Milou's avatar
Emmanuel Milou committed
229
{
230
    toggleRecording(callID);
231 232
}

233
void
234
CallManager::recordPlaybackSeek(double value)
235 236 237 238
{
    Manager::instance().recordingPlaybackSeek(value);
}

239
bool
240
CallManager::getIsRecording(const std::string& callID)
Emmanuel Milou's avatar
Emmanuel Milou committed
241
{
242
    return Manager::instance().isRecording(callID);
243 244
}

245
std::string CallManager::getCurrentAudioCodecName(const std::string& /*callID*/)
Emmanuel Milou's avatar
Emmanuel Milou committed
246
{
Adrien Béraud's avatar
Adrien Béraud committed
247
    RING_WARN("Deprecated");
248
    return "";
Alexandre Savard's avatar
Alexandre Savard committed
249 250
}

251
std::map<std::string, std::string>
252
CallManager::getCallDetails(const std::string& callID)
Emmanuel Milou's avatar
Emmanuel Milou committed
253
{
254
    return Manager::instance().getCallDetails(callID);
255 256
}

257 258
std::vector<std::string>
CallManager::getCallList()
Emmanuel Milou's avatar
Emmanuel Milou committed
259
{
260 261
    return Manager::instance().getCallList();
}
262 263

void
264
CallManager::playDTMF(const std::string& key)
Emmanuel Milou's avatar
Emmanuel Milou committed
265
{
266 267 268 269 270
    auto code = key.data()[0];
    Manager::instance().playDtmf(code);

    if (auto current_call = Manager::instance().getCurrentCall())
        current_call->carryingDTMFdigits(code);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
271 272
}

273
void
274
CallManager::startTone(int32_t start, int32_t type)
Emmanuel Milou's avatar
Emmanuel Milou committed
275
{
276
    if (start) {
277 278 279 280 281
        if (type == 0)
            Manager::instance().playTone();
        else
            Manager::instance().playToneWithMessage();
    } else
282
        Manager::instance().stopTone();
283
}
284

285
void
286
CallManager::setSASVerified(const std::string& callID)
Emmanuel Milou's avatar
Emmanuel Milou committed
287
{
288
    RING_ERR("ZRTP not supported");
289 290 291
}

void
292
CallManager::resetSASVerified(const std::string& callID)
Emmanuel Milou's avatar
Emmanuel Milou committed
293
{
294
    RING_ERR("ZRTP not supported");
295 296 297
}

void
298
CallManager::setConfirmGoClear(const std::string& callID)
Emmanuel Milou's avatar
Emmanuel Milou committed
299
{
300
    RING_ERR("ZRTP not supported");
301 302
}

303 304
void
CallManager::requestGoClear(const std::string& callID)
Emmanuel Milou's avatar
Emmanuel Milou committed
305
{
306
    RING_ERR("ZRTP not supported");
307 308
}

309
void
310
CallManager::acceptEnrollment(const std::string& callID, bool accepted)
Emmanuel Milou's avatar
Emmanuel Milou committed
311
{
312
    RING_ERR("ZRTP not supported");
313 314
}

315 316 317 318 319 320
void CallManager::sendTextMessage(const std::string& callID, const std::string& message, const std::string& from)
{
#if HAVE_INSTANT_MESSAGING
    Manager::instance().sendTextMessage(callID, message, from);
#endif
}
321

322
void
323
CallManager::sendTextMessage(const std::string& callID, const std::string& message)
Emmanuel Milou's avatar
Emmanuel Milou committed
324
{
325
#if HAVE_INSTANT_MESSAGING
326
    if (!Manager::instance().sendTextMessage(callID, message, "Me"))
327
        throw CallManagerException();
328
#else
Adrien Béraud's avatar
Adrien Béraud committed
329
    RING_ERR("Could not send \"%s\" text message to %s since SFLphone daemon does not support it, please recompile with instant messaging support", message.c_str(), callID.c_str());
330
#endif
331
}
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360

void CallManager::callStateChanged(const std::string& callID, const std::string& state)
{
    if (evHandlers_.on_state_change) {
        evHandlers_.on_state_change(callID, state);
    }
}

void CallManager::transferFailed()
{
    if (evHandlers_.on_transfer_fail) {
        evHandlers_.on_transfer_fail();
    }
}

void CallManager::transferSucceeded()
{
    if (evHandlers_.on_transfer_success) {
        evHandlers_.on_transfer_success();
    }
}

void CallManager::recordPlaybackStopped(const std::string& path)
{
    if (evHandlers_.on_record_playback_stopped) {
        evHandlers_.on_record_playback_stopped(path);
    }
}

361
void CallManager::voiceMailNotify(const std::string& callID, int32_t nd_msg)
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395
{
    if (evHandlers_.on_voice_mail_notify) {
        evHandlers_.on_voice_mail_notify(callID, nd_msg);
    }
}

void CallManager::incomingMessage(const std::string& ID, const std::string& from, const std::string& msg)
{
    if (evHandlers_.on_incoming_message) {
        evHandlers_.on_incoming_message(ID, from, msg);
    }
}

void CallManager::incomingCall(const std::string& accountID, const std::string& callID, const std::string& from)
{
    if (evHandlers_.on_incoming_call) {
        evHandlers_.on_incoming_call(accountID, callID, from);
    }
}

void CallManager::recordPlaybackFilepath(const std::string& id, const std::string& filename)
{
    if (evHandlers_.on_record_playback_filepath) {
        evHandlers_.on_record_playback_filepath(id, filename);
    }
}

void CallManager::conferenceCreated(const std::string& confID)
{
    if (evHandlers_.on_conference_created) {
        evHandlers_.on_conference_created(confID);
    }
}

396
void CallManager::conferenceChanged(const std::string& confID, const std::string& state)
397 398 399 400 401 402
{
    if (evHandlers_.on_conference_changed) {
        evHandlers_.on_conference_changed(confID, state);
    }
}

403
void CallManager::updatePlaybackScale(const std::string& filepath, int32_t position, int32_t scale)
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423
{
    if (evHandlers_.on_update_playback_scale) {
        evHandlers_.on_update_playback_scale(filepath, position, scale);
    }
}

void CallManager::conferenceRemoved(const std::string& confID)
{
    if (evHandlers_.on_conference_remove) {
        evHandlers_.on_conference_remove(confID);
    }
}

void CallManager::newCallCreated(const std::string& accountID, const std::string& callID, const std::string& to)
{
    if (evHandlers_.on_new_call) {
        evHandlers_.on_new_call(accountID, callID, to);
    }
}

424
void CallManager::sipCallStateChanged(const std::string& callID, const std::string& state, int32_t code)
425 426 427 428 429 430
{
    if (evHandlers_.on_sip_call_state_change) {
        evHandlers_.on_sip_call_state_change(callID, state, code);
    }
}

431
void CallManager::recordingStateChanged(const std::string& callID, bool state)
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465
{
    if (evHandlers_.on_record_state_change) {
        evHandlers_.on_record_state_change(callID, state);
    }
}

void CallManager::secureSdesOn(const std::string& callID)
{
    if (evHandlers_.on_secure_sdes_on) {
        evHandlers_.on_secure_sdes_on(callID);
    }
}

void CallManager::secureSdesOff(const std::string& callID)
{
    if (evHandlers_.on_secure_sdes_off) {
        evHandlers_.on_secure_sdes_off(callID);
    }
}

void CallManager::secureZrtpOn(const std::string& callID, const std::string& cipher)
{
    if (evHandlers_.on_secure_zrtp_on) {
        evHandlers_.on_secure_zrtp_on(callID, cipher);
    }
}

void CallManager::secureZrtpOff(const std::string& callID)
{
    if (evHandlers_.on_secure_zrtp_off) {
        evHandlers_.on_secure_zrtp_off(callID);
    }
}

466
void CallManager::showSAS(const std::string& callID, const std::string& sas, bool verified)
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492
{
    if (evHandlers_.on_show_sas) {
        evHandlers_.on_show_sas(callID, sas, verified);
    }
}

void CallManager::zrtpNotSuppOther(const std::string& callID)
{
    if (evHandlers_.on_zrtp_not_supp_other) {
        evHandlers_.on_zrtp_not_supp_other(callID);
    }
}

void CallManager::zrtpNegotiationFailed(const std::string& callID, const std::string& reason, const std::string& severity)
{
    if (evHandlers_.on_zrtp_negotiation_fail) {
        evHandlers_.on_zrtp_negotiation_fail(callID, reason, severity);
    }
}

void CallManager::onRtcpReportReceived(const std::string& callID, const std::map<std::string, int>& stats)
{
    if (evHandlers_.on_rtcp_receive_report) {
        evHandlers_.on_rtcp_receive_report(callID, stats);
    }
}
493 494

} // namespace ring