managerimpl.h 31.3 KB
Newer Older
jpbl's avatar
jpbl committed
1
/*
2
 *  Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
jpbl's avatar
jpbl committed
3 4
 *  Author: Yan Morin <yan.morin@savoirfairelinux.com>
 *  Author: Laurielle Lea <laurielle.lea@savoirfairelinux.com>
5
 *  Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
6
 *  Author: Guillaume Carmel-Archambault <guillaume.carmel-archambault@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 16 17 18 19 20
 *  (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
 *  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
21
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
22 23 24 25 26 27 28 29 30 31 32
 *
 *  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
33 34
 */

35 36
#ifndef MANAGER_IMPL_H_
#define MANAGER_IMPL_H_
jpbl's avatar
jpbl committed
37

38 39 40 41
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

jpbl's avatar
jpbl committed
42 43
#include <string>
#include <vector>
yanmorin's avatar
 
yanmorin committed
44
#include <set>
yanmorin's avatar
 
yanmorin committed
45
#include <map>
46
#include <memory>
Adrien Béraud's avatar
Adrien Béraud committed
47
#include <mutex>
48

49
#include "client/client.h"
jpbl's avatar
jpbl committed
50

51
#include "config/sfl_config.h"
yanmorin's avatar
 
yanmorin committed
52

53 54
#include "account.h"

yanmorin's avatar
 
yanmorin committed
55
#include "call.h"
56
#include "conference.h"
jpbl's avatar
jpbl committed
57

58
#include "audio/audiolayer.h"
59
#include "audio/sound/tone.h"  // for Tone::TONEID declaration
60
#include "audio/codecs/audiocodecfactory.h"
61
#include "audio/mainbuffer.h"
62

63
#include "preferences.h"
64
#include "history/history.h"
65
#include "noncopyable.h"
66

67
namespace Conf {
68 69
    class YamlParser;
    class YamlEmitter;
70
}
71

72 73
class DTMF;
class AudioFile;
jpbl's avatar
jpbl committed
74
class AudioLayer;
75
class History;
jpbl's avatar
jpbl committed
76 77
class TelephoneTone;
class VoIPLink;
78

jpbl's avatar
jpbl committed
79 80 81 82
#ifdef USE_ZEROCONF
class DNSService;
#endif

83
class Account;
84
class SIPAccount;
85
class IAXAccount;
jpbl's avatar
jpbl committed
86

87
/** To send multiple string */
jpbl's avatar
jpbl committed
88 89
typedef std::list<std::string> TokenList;

90
/** To store conference objects by conference ids */
91
typedef std::map<std::string, Conference*> ConferenceMap;
92

93
static const char * const default_conf = "conf";
94

95
/** Manager (controller) of sflphone daemon */
96
class ManagerImpl {
Julien Bonjean's avatar
Julien Bonjean committed
97
    public:
98
        ManagerImpl();
99
        ~ManagerImpl();
Julien Bonjean's avatar
Julien Bonjean committed
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129

        /**
         * General preferences configuration
         */
        Preferences preferences;

        /**
         * Voip related preferences
         */
        VoipPreference voipPreferences;

        /**
         * Hook preferences
         */
        HookPreference hookPreference;

        /**
         * Audio preferences
         */
        AudioPreference audioPreference;

        /**
         * Shortcut preferences
         */
        ShortcutPreferences shortcutPreferences;

        /**
         * Initialisation of thread (sound) and map.
         * Init a new VoIPLink, audio codec and audio driver
         */
130
        void init(const std::string &config_file);
Julien Bonjean's avatar
Julien Bonjean committed
131

132 133
        void setPath(const std::string &path);

134
#ifdef HAVE_DBUS
135 136 137 138
        /**
         * Enter Dbus mainloop
         */
        void run();
139
#endif
140 141 142 143 144 145

        /*
         * Terminate all threads and exit DBus loop
         */
        void finish();

Julien Bonjean's avatar
Julien Bonjean committed
146 147 148 149 150
        /**
         * Accessor to audiodriver.
         * it's multi-thread and use mutex internally
         * @return AudioLayer*  The audio layer object
         */
151
        AudioLayer* getAudioDriver();
Julien Bonjean's avatar
Julien Bonjean committed
152

153 154
        void startAudioDriverStream();

Julien Bonjean's avatar
Julien Bonjean committed
155 156 157 158
        /**
         * Functions which occur with a user's action
         * Place a new call
         * @param accountId	The account to make tha call with
159
         * @param call_id  The call identifier
Julien Bonjean's avatar
Julien Bonjean committed
160
         * @param to  The recipient of the call
161
         * @param conf_id The conference identifier if any
Julien Bonjean's avatar
Julien Bonjean committed
162 163 164
         * @return bool true on success
         *		  false otherwise
         */
165
        bool outgoingCall(const std::string&, const std::string&, const std::string&, const std::string& = "");
Julien Bonjean's avatar
Julien Bonjean committed
166 167 168 169 170 171

        /**
         * Functions which occur with a user's action
         * Answer the call
         * @param id  The call identifier
         */
172
        bool answerCall(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
173 174 175 176 177 178

        /**
         * Functions which occur with a user's action
         * Hangup the call
         * @param id  The call identifier
         */
179
        bool hangupCall(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
180 181 182 183 184 185 186


        /**
         * Functions which occur with a user's action
         * Hangup the conference (hangup every participants)
         * @param id  The call identifier
         */
187
        bool hangupConference(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
188 189 190 191 192 193

        /**
         * Functions which occur with a user's action
         * Put the call on hold
         * @param id  The call identifier
         */
194
        bool onHoldCall(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
195 196 197 198 199 200

        /**
         * Functions which occur with a user's action
         * Put the call off hold
         * @param id  The call identifier
         */
201
        bool offHoldCall(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
202 203 204 205 206 207 208

        /**
         * Functions which occur with a user's action
         * Transfer the call
         * @param id  The call identifier
         * @param to  The recipient of the transfer
         */
209
        bool transferCall(const std::string& id, const std::string& to);
Julien Bonjean's avatar
Julien Bonjean committed
210

211 212 213 214 215
        /**
         * Attended transfer
         * @param The call id to be transfered
         * @param The target
         */
216
        bool attendedTransfer(const std::string& transferID, const std::string& targetID);
217

Julien Bonjean's avatar
Julien Bonjean committed
218 219 220
        /**
         * Notify the client the transfer is successful
         */
221
        void transferSucceeded();
Julien Bonjean's avatar
Julien Bonjean committed
222 223 224 225 226 227 228 229 230 231 232

        /**
         * Notify the client that the transfer failed
         */
        void transferFailed();

        /**
         * Functions which occur with a user's action
         * Refuse the call
         * @param id  The call identifier
         */
233
        bool refuseCall(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
234 235 236 237 238 239

        /**
         * Create a new conference given two participant
         * @param the first participant ID
         * @param the second participant ID
         */
240
        Conference* createConference(const std::string& id1, const std::string& id2);
Julien Bonjean's avatar
Julien Bonjean committed
241 242 243 244 245

        /**
         * Delete this conference
         * @param the conference ID
         */
246
        void removeConference(const std::string& conference_id);
Julien Bonjean's avatar
Julien Bonjean committed
247 248 249 250 251

        /**
         * Return the conference id for which this call is attached
         * @ param the call id
         */
252
        Conference* getConferenceFromCallID(const std::string& call_id);
Julien Bonjean's avatar
Julien Bonjean committed
253 254 255 256 257

        /**
         * Hold every participant to a conference
         * @param the conference id
         */
258
        bool holdConference(const std::string& conference_id);
Julien Bonjean's avatar
Julien Bonjean committed
259 260 261 262 263

        /**
         * Unhold all conference participants
         * @param the conference id
         */
264
        bool unHoldConference(const std::string& conference_id);
Julien Bonjean's avatar
Julien Bonjean committed
265 266 267 268 269

        /**
         * Test if this id is a conference (usefull to test current call)
         * @param the call id
         */
270
        bool isConference(const std::string& call_id) const;
Julien Bonjean's avatar
Julien Bonjean committed
271 272

        /**
273
         * Test if a call id corresponds to a conference participant
Julien Bonjean's avatar
Julien Bonjean committed
274 275
         * @param the call id
         */
276
        bool isConferenceParticipant(const std::string& call_id);
Julien Bonjean's avatar
Julien Bonjean committed
277 278 279 280 281 282

        /**
         * Add a participant to a conference
         * @param the call id
         * @param the conference id
         */
283
        bool addParticipant(const std::string& call_id, const std::string& conference_id);
Julien Bonjean's avatar
Julien Bonjean committed
284 285 286 287 288

        /**
         * Bind the main participant to a conference (mainly called on a double click action)
         * @param the conference id
         */
289
        bool addMainParticipant(const std::string& conference_id);
Julien Bonjean's avatar
Julien Bonjean committed
290 291 292 293 294 295

        /**
         * Join two participants to create a conference
         * @param the fist call id
         * @param the second call id
         */
296 297
        bool joinParticipant(const std::string& call_id1,
                             const std::string& call_id2);
Julien Bonjean's avatar
Julien Bonjean committed
298

299 300 301 302 303
        /**
         * Create a conference from a list of participant
         * @param A vector containing the list of participant
         */
        void createConfFromParticipantList(const std::vector< std::string > &);
304

Julien Bonjean's avatar
Julien Bonjean committed
305 306 307 308 309
        /**
         * Detach a participant from a conference, put the call on hold, do not hangup it
         * @param call id
         * @param the current call id
         */
310
        bool detachParticipant(const std::string& call_id);
Julien Bonjean's avatar
Julien Bonjean committed
311 312 313 314 315

        /**
         * Remove the conference participant from a conference
         * @param call id
         */
316
        void removeParticipant(const std::string& call_id);
Julien Bonjean's avatar
Julien Bonjean committed
317 318 319 320

        /**
         * Join two conference together into one unique conference
         */
321
        bool joinConference(const std::string& conf_id1, const std::string& conf_id2);
Julien Bonjean's avatar
Julien Bonjean committed
322

323
        void addStream(const std::string& call_id);
Julien Bonjean's avatar
Julien Bonjean committed
324

325
        void removeStream(const std::string& call_id);
Julien Bonjean's avatar
Julien Bonjean committed
326 327 328 329

        /**
         * Save config to file
         */
330
        void saveConfig();
Julien Bonjean's avatar
Julien Bonjean committed
331 332 333 334

        /**
         * @return true if we tried to register once
         */
335
        bool hasTriedToRegister_;
Julien Bonjean's avatar
Julien Bonjean committed
336 337 338 339 340 341

        /**
         * Handle choice of the DTMF-send-way
         * @param   id: callid of the line.
         * @param   code: pressed key.
         */
342
        void sendDtmf(const std::string& id, char code);
Julien Bonjean's avatar
Julien Bonjean committed
343 344 345 346

        /**
         * Play a ringtone
         */
347
        void playTone();
Julien Bonjean's avatar
Julien Bonjean committed
348 349 350 351

        /**
         * Play a special ringtone ( BUSY ) if there's at least one message on the voice mail
         */
352
        void playToneWithMessage();
Julien Bonjean's avatar
Julien Bonjean committed
353 354 355 356

        /**
         * Acts on the audio streams and audio files
         */
357
        void stopTone();
Julien Bonjean's avatar
Julien Bonjean committed
358 359

        /**
360
         * Handle incoming call and notify user
Julien Bonjean's avatar
Julien Bonjean committed
361 362 363
         * @param call A call pointer
         * @param accountId an account id
         */
364
        void incomingCall(Call &call, const std::string& accountId);
Julien Bonjean's avatar
Julien Bonjean committed
365 366 367 368 369 370

        /**
         * Notify the user that the recipient of the call has answered and the put the
         * call in Current state
         * @param id  The call identifier
         */
371
        void peerAnsweredCall(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
372 373 374 375 376 377

        /**
         * Rings back because the outgoing call is ringing and the put the
         * call in Ringing state
         * @param id  The call identifier
         */
378
        void peerRingingCall(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
379 380 381 382 383

        /**
         * Put the call in Hungup state, remove the call from the list
         * @param id  The call identifier
         */
384
        void peerHungupCall(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
385

386
#if HAVE_INSTANT_MESSAGING
Julien Bonjean's avatar
Julien Bonjean committed
387 388 389 390 391
        /**
         * Notify the client with an incoming message
         * @param accountId	The account identifier
         * @param message The content of the message
         */
392
        void incomingMessage(const std::string& callID, const std::string& from, const std::string& message);
Julien Bonjean's avatar
Julien Bonjean committed
393

394 395

        /**
396
         * Send a new text message to the call, if participate to a conference, send to all participant.
397 398
         * @param callID	The call to send the message
         * @param message	The content of the message
399 400
        * @param from	        The sender of this message (could be another participant of a conference)
         */
401
        bool sendTextMessage(const std::string& callID, const std::string& message, const std::string& from);
402
#endif // HAVE_INSTANT_MESSAGING
403

Julien Bonjean's avatar
Julien Bonjean committed
404 405 406 407 408
        /**
         * Notify the client he has voice mails
         * @param accountId	  The account identifier
         * @param nb_msg The number of messages
         */
409
        void startVoiceMessageNotification(const std::string& accountId, int nb_msg);
Julien Bonjean's avatar
Julien Bonjean committed
410 411 412 413 414

        /**
         * ConfigurationManager - Send registration request
         * @param accountId The account to register/unregister
         * @param enable The flag for the type of registration
415 416
         *		 false for unregistration request
         *		 true for registration request
Julien Bonjean's avatar
Julien Bonjean committed
417
         */
418
        void sendRegister(const std::string& accountId, bool enable);
Julien Bonjean's avatar
Julien Bonjean committed
419

420 421 422 423 424 425 426 427 428 429
        /**
         * Register all account in accountMap_
         */
        void registerAllAccounts();

        /**
         * Unregister all account in accountMap_
         */
        void unregisterAllAccounts();

Julien Bonjean's avatar
Julien Bonjean committed
430 431 432 433
        /**
         * Get account list
         * @return std::vector<std::string> A list of accoundIDs
         */
434
        std::vector<std::string> getAccountList() const;
Julien Bonjean's avatar
Julien Bonjean committed
435 436 437 438

        /**
         * Set the account order in the config file
         */
439
        void setAccountsOrder(const std::string& order);
Julien Bonjean's avatar
Julien Bonjean committed
440 441 442 443 444 445

        /**
         * Retrieve details about a given account
         * @param accountID	  The account identifier
         * @return std::map< std::string, std::string > The account details
         */
446
        std::map<std::string, std::string> getAccountDetails(const std::string& accountID) const;
Julien Bonjean's avatar
Julien Bonjean committed
447 448 449 450 451 452

        /**
         * Retrieve details about a given call
         * @param callID	  The account identifier
         * @return std::map< std::string, std::string > The call details
         */
453
        std::map<std::string, std::string> getCallDetails(const std::string& callID);
Julien Bonjean's avatar
Julien Bonjean committed
454 455 456 457 458

        /**
         * Get call list
         * @return std::vector<std::string> A list of call IDs
         */
459
        std::vector<std::string> getCallList() const;
Julien Bonjean's avatar
Julien Bonjean committed
460 461 462 463 464 465

        /**
         * Retrieve details about a given call
         * @param callID	  The account identifier
         * @return std::map< std::string, std::string > The call details
         */
466
        std::map<std::string, std::string> getConferenceDetails(const std::string& callID) const;
Julien Bonjean's avatar
Julien Bonjean committed
467 468 469 470 471

        /**
         * Get call list
         * @return std::vector<std::string> A list of call IDs
         */
472
        std::vector<std::string> getConferenceList() const;
Julien Bonjean's avatar
Julien Bonjean committed
473 474 475 476 477 478


        /**
         * Get a list of participant to a conference
         * @return std::vector<std::string> A list of call IDs
         */
479
        std::vector<std::string> getParticipantList(const std::string& confID) const;
Julien Bonjean's avatar
Julien Bonjean committed
480

481 482
        std::string getConferenceId(const std::string& callID);

Julien Bonjean's avatar
Julien Bonjean committed
483 484 485 486 487 488 489
        /**
         * Save the details of an existing account, given the account ID
         * This will load the configuration map with the given data.
         * It will also register/unregister links where the 'Enabled' switched.
         * @param accountID	  The account identifier
         * @param details	  The account parameters
         */
490 491
        void setAccountDetails(const std::string& accountID,
                               const std::map<std::string, ::std::string > &details);
Julien Bonjean's avatar
Julien Bonjean committed
492 493 494 495 496 497

        /**
         * Add a new account, and give it a new account ID automatically
         * @param details The new account parameters
         * @return The account Id given to the new account
         */
498
        std::string addAccount(const std::map<std::string, std::string> &details);
Julien Bonjean's avatar
Julien Bonjean committed
499 500 501 502 503 504

        /**
         * Delete an existing account, unregister VoIPLink associated, and
         * purge from configuration.
         * @param accountID	The account unique ID
         */
505
        void removeAccount(const std::string& accountID);
Julien Bonjean's avatar
Julien Bonjean committed
506 507 508 509 510 511

        /**
         * Get current codec name
         * @param call id
         * @return std::string The codec name
         */
512
        std::string getCurrentAudioCodecName(const std::string& id);
513
        std::string getCurrentVideoCodecName(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
514 515 516 517 518

        /**
         * Set input audio plugin
         * @param audioPlugin The audio plugin
         */
519
        void setAudioPlugin(const std::string& audioPlugin);
Julien Bonjean's avatar
Julien Bonjean committed
520 521

        /**
522 523 524 525
             * Set audio device
             * @param index The index of the soundcard
             * @param the type of stream, either SFL_PCM_PLAYBACK, SFL_PCM_CAPTURE, SFL_PCM_RINGTONE
             */
526
        void setAudioDevice(int index, AudioLayer::PCMType streamType);
Julien Bonjean's avatar
Julien Bonjean committed
527 528 529 530 531

        /**
         * Get list of supported audio output device
         * @return std::vector<std::string> A list of the audio devices supporting playback
         */
532
        std::vector<std::string> getAudioOutputDeviceList();
Julien Bonjean's avatar
Julien Bonjean committed
533 534 535 536 537

        /**
         * Get list of supported audio input device
         * @return std::vector<std::string> A list of the audio devices supporting capture
         */
538
        std::vector<std::string> getAudioInputDeviceList();
Julien Bonjean's avatar
Julien Bonjean committed
539 540

        /**
541
         * Get string array representing integer indexes of output, input, and ringtone device
Julien Bonjean's avatar
Julien Bonjean committed
542 543 544 545 546 547 548 549 550
         * @return std::vector<std::string> A list of the current audio devices
         */
        std::vector<std::string> getCurrentAudioDevicesIndex();

        /**
         * Get index of an audio device
         * @param name The string description of an audio device
         * @return int  His index
         */
551
        int getAudioDeviceIndex(const std::string &name);
Julien Bonjean's avatar
Julien Bonjean committed
552 553 554 555 556

        /**
         * Get current alsa plugin
         * @return std::string  The Alsa plugin
         */
557
        std::string getCurrentAudioOutputPlugin() const;
Julien Bonjean's avatar
Julien Bonjean committed
558

559 560 561 562
        /**
         * Get the noise reduction engin state from
         * the current audio layer.
         */
563
        std::string getNoiseSuppressState() const;
Julien Bonjean's avatar
Julien Bonjean committed
564

565 566 567 568
        /**
         * Set the noise reduction engin state in the current
         * audio layer.
         */
569
        void setNoiseSuppressState(const std::string &state);
Julien Bonjean's avatar
Julien Bonjean committed
570

571 572 573 574
        /**
         * Get the echo canceller engin state from
         * the current audio layer
         */
575
        bool getEchoCancelState() const;
576 577 578 579

        /**
         * Set the echo canceller engin state
         */
580
        void setEchoCancelState(const std::string &state);
581

Julien Bonjean's avatar
Julien Bonjean committed
582 583 584 585 586 587
        /**
         * Ringtone option.
         * If ringtone is enabled, ringtone on incoming call use custom choice. If not, only standart tone.
         * @return int	1 if enabled
         *	        0 otherwise
         */
588
        int isRingtoneEnabled(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
589 590 591 592 593

        /**
         * Set the ringtone option
         * Inverse current value
         */
594
        void ringtoneEnabled(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
595

596 597 598
        /**
         * Get is always recording functionality
         */
599
        bool getIsAlwaysRecording() const;
600 601 602 603 604 605 606

        /**
         * Set is always recording functionality, every calls will then be set in RECORDING mode
         * once answered
         */
        void setIsAlwaysRecording(bool isAlwaysRec);

Julien Bonjean's avatar
Julien Bonjean committed
607 608 609 610
        /**
         * Set recording on / off
         * Start recording
         * @param id  The call identifier
611
         * Returns true if the call was set to record
Julien Bonjean's avatar
Julien Bonjean committed
612
         */
613
        bool toggleRecordingCall(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
614 615 616 617

        /**
         * Return true if the call is currently recorded
         */
618
        bool isRecording(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
619

620 621 622 623
        /**
         * Start playback fo a recorded file if and only if audio layer is not already started.
         * @param File path of the file to play
             */
624
        bool startRecordedFilePlayback(const std::string&);
625

626 627
        void recordingPlaybackSeek(const double value);

628 629 630 631
        /**
         * Stop playback of recorded file
         * @param File of the file to stop
         */
632 633
        void stopRecordedFilePlayback(const std::string&);

Julien Bonjean's avatar
Julien Bonjean committed
634 635 636 637
        /**
         * Set the maximum number of days to keep in the history
         * @param calls The number of days
         */
638
        void setHistoryLimit(int days);
Julien Bonjean's avatar
Julien Bonjean committed
639 640 641 642 643

        /**
         * Get the maximum number of days to keep in the history
         * @return double The number of days
         */
644
        int getHistoryLimit() const;
Julien Bonjean's avatar
Julien Bonjean committed
645 646 647 648 649 650

        /**
         * Configure the start-up option
         * @return int	1 if SFLphone should start in the system tray
         *	        0 otherwise
         */
651
        int isStartHidden();
Julien Bonjean's avatar
Julien Bonjean committed
652 653 654 655 656

        /**
         * Configure the start-up option
         * At startup, SFLphone can be displayed or start hidden in the system tray
         */
657
        void startHidden();
Julien Bonjean's avatar
Julien Bonjean committed
658 659 660 661

        /**
         * Get the audio manager
         * @return int The audio manager
662 663
         *		    "alsa"
         *		    "pulseaudio"
Julien Bonjean's avatar
Julien Bonjean committed
664
         */
665
        std::string getAudioManager() const;
Julien Bonjean's avatar
Julien Bonjean committed
666 667 668 669

        /**
         * Set the audio manager
         */
670
        void setAudioManager(const std::string &api);
Julien Bonjean's avatar
Julien Bonjean committed
671

672
        void switchAudioManager();
Julien Bonjean's avatar
Julien Bonjean committed
673

674 675 676 677
        /**
         * Set the internal audio sampling rate change. Should close the audio layer and
         * reopen stream at different rate,
         */
678
        void audioSamplingRateChanged(int);
Julien Bonjean's avatar
Julien Bonjean committed
679 680 681 682 683 684 685 686 687 688

        /**
         * Change a specific value in the configuration tree.
         * This value will then be saved in the user config file sflphonedrc
         * @param section	The section name
         * @param name	The parameter name
         * @param value	The new string value
         * @return bool	true on success
         *		      false otherwise
         */
689
        void setConfig(const std::string& section, const std::string& name, const std::string& value);
Julien Bonjean's avatar
Julien Bonjean committed
690 691 692 693 694 695 696 697 698 699

        /**
         * Change a specific value in the configuration tree.
         * This value will then be saved in the user config file sflphonedrc
         * @param section	The section name
         * @param name	The parameter name
         * @param value	The new int value
         * @return bool	true on success
         *		      false otherwise
         */
700
        void setConfig(const std::string& section, const std::string& name, int value);
Julien Bonjean's avatar
Julien Bonjean committed
701 702 703 704 705 706 707 708

        /**
         * Get a string from the configuration tree
         * Throw an Conf::ConfigTreeItemException if not found
         * @param section The section name to look in
         * @param name    The parameter name
         * @return sdt::string    The string value
         */
709
        std::string getConfigString(const std::string& section, const std::string& name) const;
Julien Bonjean's avatar
Julien Bonjean committed
710 711 712 713 714

        /**
         * Handle audio sounds heard by a caller while they wait for their
         * connection to a called party to be completed.
         */
715
        void ringback();
Julien Bonjean's avatar
Julien Bonjean committed
716 717 718 719

        /**
         * Handle played music when an incoming call occurs
         */
720
        void playRingtone(const std::string& accountID);
Julien Bonjean's avatar
Julien Bonjean committed
721 722 723 724

        /**
         * Handle played music when a congestion occurs
         */
725
        void congestion();
Julien Bonjean's avatar
Julien Bonjean committed
726 727 728 729

        /**
         * Handle played sound when a call can not be conpleted because of a busy recipient
         */
730
        void callBusy(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
731 732 733 734

        /**
         * Handle played sound when a failure occurs
         */
735
        void callFailure(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752

        /**
         * Retrieve the current telephone tone
         * @return AudioLoop*   The audio tone or 0 if no tone (init before calling this function)
         */
        AudioLoop* getTelephoneTone();

        /**
         * Retrieve the current telephone file
         * @return AudioLoop* The audio file or 0 if the wav is stopped
         */
        AudioLoop* getTelephoneFile();

        /**
         * @return true is there is one or many incoming call waiting
         * new call, not anwsered or refused
         */
753
        bool incomingCallsWaiting();
Julien Bonjean's avatar
Julien Bonjean committed
754 755 756

        /**
         * Return a new random callid that is not present in the list
757
         * @return std::string A brand new callid
Julien Bonjean's avatar
Julien Bonjean committed
758
         */
759
        std::string getNewCallID();
Julien Bonjean's avatar
Julien Bonjean committed
760 761 762

        /**
         * Get the current call id
763
         * @return std::string	The call id or ""
Julien Bonjean's avatar
Julien Bonjean committed
764
         */
765
        std::string getCurrentCallId() const;
Julien Bonjean's avatar
Julien Bonjean committed
766 767 768 769 770 771

        /**
         * Check if a call is the current one
         * @param callId the new callid
         * @return bool   True if the id is the current call
         */
772
        bool isCurrentCall(const std::string& callId) const;
Julien Bonjean's avatar
Julien Bonjean committed
773

774
        void initAudioDriver();
Julien Bonjean's avatar
Julien Bonjean committed
775

776 777 778 779
        /**
         * Load the accounts order set by the user from the sflphonedrc config file
         * @return std::vector<std::string> A vector containing the account ID's
         */
780
        std::vector<std::string> loadAccountOrder() const;
781 782 783 784

        // map of codec (for configlist request)
        const AudioCodecFactory audioCodecFactory;

Julien Bonjean's avatar
Julien Bonjean committed
785
    private:
786
        bool parseConfiguration();
787

788 789
        // Set the ringtone or recorded call to be played
        void updateAudioFile(const std::string &file, int sampleRate);
790 791 792 793 794 795

        /**
         * Get the Call referred to by callID. If the Call does not exist, return NULL
         */
        Call *getCallFromCallID(const std::string &callID);

796 797 798 799
        /**
         * Play the dtmf-associated sound
         * @param code  The pressed key
         */
800
        void playDtmf(char code);
801 802 803 804 805 806 807

        /**
         * Process remaining participant given a conference and the current call id.
         * Mainly called when a participant is detached or hagned up
         * @param current call id
         * @param conference pointer
         */
808
        void processRemainingParticipants(Conference &conf);
809

Julien Bonjean's avatar
Julien Bonjean committed
810
        /**
811
         * Create config directory in home user and return configuration file path
Julien Bonjean's avatar
Julien Bonjean committed
812
         */
813
        std::string retrieveConfigPath() const;
Julien Bonjean's avatar
Julien Bonjean committed
814 815 816 817

        /*
         * Initialize zeroconf module and scanning
         */
818
        void initZeroconf();
Julien Bonjean's avatar
Julien Bonjean committed
819

820 821 822 823 824
        /**
         * Set current call ID to empty string
         */
        void unsetCurrentCall();

Julien Bonjean's avatar
Julien Bonjean committed
825 826 827 828
        /**
         * Switch of current call id
         * @param id The new callid
         */
829
        void switchCall(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
830 831 832 833 834

        /*
         * Play one tone
         * @return false if the driver is uninitialize
         */
835
        void playATone(Tone::TONEID toneId);
Julien Bonjean's avatar
Julien Bonjean committed
836

837
        Client client_;
838

Julien Bonjean's avatar
Julien Bonjean committed
839
        /** The configuration tree. It contains accounts parameters, general user settings ,audio settings, ... */
840
        Conf::ConfigTree config_;
Julien Bonjean's avatar
Julien Bonjean committed
841 842

        /** Current Call ID */
843
        std::string currentCallId_;
Julien Bonjean's avatar
Julien Bonjean committed
844 845

        /** Protected current call access */
Adrien Béraud's avatar
Adrien Béraud committed
846
        std::mutex currentCallMutex_;
Julien Bonjean's avatar
Julien Bonjean committed
847 848

        /** Audio layer */
849
        AudioLayer* audiodriver_;
Julien Bonjean's avatar
Julien Bonjean committed
850 851

        // Main thread
852
        std::unique_ptr<DTMF> dtmfKey_;
Julien Bonjean's avatar
Julien Bonjean committed
853 854 855 856

        /////////////////////
        // Protected by Mutex
        /////////////////////
Adrien Béraud's avatar
Adrien Béraud committed
857
        std::mutex toneMutex_;
858 859
        std::unique_ptr<TelephoneTone> telephoneTone_;
        std::unique_ptr<AudioFile> audiofile_;
Julien Bonjean's avatar
Julien Bonjean committed
860 861

        // To handle volume control
862 863
        // short speakerVolume_;
        // short micVolume_;
Julien Bonjean's avatar
Julien Bonjean committed
864 865
        // End of sound variable

866 867 868
        /**
         * Mutex used to protect audio layer
         */
Adrien Béraud's avatar
Adrien Béraud committed
869
        std::mutex audioLayerMutex_;
Julien Bonjean's avatar
Julien Bonjean committed
870

871 872 873
        /**
         * Waiting Call Vectors
         */
874
        CallIDSet waitingCalls_;
Julien Bonjean's avatar
Julien Bonjean committed
875

876 877 878
        /**
         * Protect waiting call list, access by many voip/audio threads
         */
Adrien Béraud's avatar
Adrien Béraud committed
879
        std::mutex waitingCallsMutex_;
Julien Bonjean's avatar
Julien Bonjean committed
880 881 882

        /**
         * Add incoming callid to the waiting list
883
         * @param id std::string to add
Julien Bonjean's avatar
Julien Bonjean committed
884
         */
885
        void addWaitingCall(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
886 887 888

        /**
         * Remove incoming callid to the waiting list
889
         * @param id std::string to remove
Julien Bonjean's avatar
Julien Bonjean committed
890
         */
891
        void removeWaitingCall(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
892 893 894 895

        /**
         * Path of the ConfigFile
         */
896
        std::string path_;
897

jpbl's avatar
jpbl committed
898
#ifdef USE_ZEROCONF
Julien Bonjean's avatar
Julien Bonjean committed
899 900
        // DNSService contain every zeroconf services
        //  configuration detected on the network
901
        DNSService *DNSService_;
jpbl's avatar
jpbl committed
902 903
#endif

904
        std::map<std::string, bool> IPToIPMap_;
Julien Bonjean's avatar
Julien Bonjean committed
905

906
        bool isIPToIP(const std::string& callID) const;
Julien Bonjean's avatar
Julien Bonjean committed
907 908

        /**
909
         * Load the account map from configuration
Julien Bonjean's avatar
Julien Bonjean committed
910
         */
911
        int loadAccountMap(Conf::YamlParser &parser);
912 913
        /**
         * Load default account map (no configuration)
Julien Bonjean's avatar
Julien Bonjean committed
914
         */
915
        void loadDefaultAccountMap();
Julien Bonjean's avatar
Julien Bonjean committed
916 917 918 919 920 921 922 923

        /**
         * Instance of the MainBuffer for the whole application
         *
         * In order to send signal to other parts of the application, one must pass through the mainbuffer.
         * Audio instances must be registered into the MainBuffer and bound together via the ManagerImpl.
         *
         */
924
        MainBuffer mainBuffer_;
Julien Bonjean's avatar
Julien Bonjean committed
925 926 927

    public:

928 929
        void setIPToIPForCall(const std::string& callID, bool IPToIP);

930 931 932
        /**
         * Test if call is a valid call, i.e. have been created and stored in
         * call-account map
933
         * @param callID the std::string to be tested
934 935
         * @return true if call is created and present in the call-account map
         */
936
        bool isValidCall(const std::string& callID);
937

Julien Bonjean's avatar
Julien Bonjean committed
938 939 940
        /**
         * Return a pointer to the  instance of the mainbuffer
         */
941
        MainBuffer &getMainBuffer();
Julien Bonjean's avatar
Julien Bonjean committed
942 943 944 945 946

        /**
         * Tell if there is a current call processed
         * @return bool True if there is a current call
         */
947
        bool hasCurrentCall() const;
Julien Bonjean's avatar
Julien Bonjean committed
948 949

        /**
950 951
         * Return the current Client
         * @return A pointer to the Client instance
Julien Bonjean's avatar
Julien Bonjean committed
952
         */
953
        Client* getClient();
954
#ifdef SFL_VIDEO
955
        VideoControls * getVideoControls();
956
#endif
957

Julien Bonjean's avatar
Julien Bonjean committed
958 959 960 961 962 963
        /**
        * Tell if an account exists
        * @param accountID account ID check
        * @return bool True if the account exists
        *		  false otherwise
        */
964
        bool