managerimpl.h 33.2 KB
Newer Older
jpbl's avatar
jpbl committed
1
/*
2
 *  Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010, 2011 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 21
 *  (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
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, 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

#include <string>
#include <vector>
yanmorin's avatar
 
yanmorin committed
40
#include <set>
yanmorin's avatar
 
yanmorin committed
41
#include <map>
42
#include <tr1/memory>
43
#include "cc_thread.h"
44
#include "dbus/dbusmanager.h"
jpbl's avatar
jpbl committed
45 46

#include "config/config.h"
yanmorin's avatar
 
yanmorin committed
47 48

#include "call.h"
49
#include "conference.h"
jpbl's avatar
jpbl committed
50

51
#include "audio/sound/tone.h"  // for Tone::TONEID declaration
52
#include "audio/codecs/audiocodecfactory.h"
jpbl's avatar
jpbl committed
53

54
#include "audio/mainbuffer.h"
55
#include "preferences.h"
56
#include "history/history.h"
57
#include "noncopyable.h"
58

59
namespace Conf {
60 61
    class YamlParser;
    class YamlEmitter;
62 63 64 65
}

class DTMF;
class AudioFile;
jpbl's avatar
jpbl committed
66
class AudioLayer;
67
class History;
jpbl's avatar
jpbl committed
68 69
class TelephoneTone;
class VoIPLink;
70

jpbl's avatar
jpbl committed
71 72 73 74
#ifdef USE_ZEROCONF
class DNSService;
#endif

75
class Account;
76
class SIPAccount;
jpbl's avatar
jpbl committed
77

78
/** Define a type for a AccountMap container */
79
typedef std::map<std::string, Account*> AccountMap;
80

81 82
/** Define a type for a std::string to std::string Map inside ManagerImpl */
typedef std::map<std::string, std::string> CallAccountMap;
yanmorin's avatar
 
yanmorin committed
83

84
/** To send multiple string */
jpbl's avatar
jpbl committed
85 86
typedef std::list<std::string> TokenList;

87
/** To store conference objects by conference ids */
88
typedef std::map<std::string, Conference*> ConferenceMap;
89

90
static const char * const default_conf = "conf";
91

92
/** Manager (controller) of sflphone daemon */
93
class ManagerImpl {
Julien Bonjean's avatar
Julien Bonjean committed
94
    public:
95
        ManagerImpl();
Julien Bonjean's avatar
Julien Bonjean committed
96 97 98 99 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 130

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

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

        /**
         * Addressbook related preferences
         */
        AddressbookPreference addressbookPreference;

        /**
         * 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
         */
131
        void init(const std::string &config_file);
Julien Bonjean's avatar
Julien Bonjean committed
132 133 134 135

        /**
         * Terminate all thread (sound, link) and unload AccountMap
         */
136
        void terminate();
Julien Bonjean's avatar
Julien Bonjean committed
137 138 139 140 141 142

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

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

        /**
         * Functions which occur with a user's action
         * Answer the call
         * @param id  The call identifier
         */
164
        bool answerCall(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
165 166 167 168 169 170

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


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

        /**
         * Functions which occur with a user's action
         * Put the call on hold
         * @param id  The call identifier
         */
186
        void onHoldCall(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
187 188 189 190 191 192

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

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

203 204 205 206 207
        /**
         * Attended transfer
         * @param The call id to be transfered
         * @param The target
         */
208
        bool attendedTransfer(const std::string& transferID, const std::string& targetID);
209

Julien Bonjean's avatar
Julien Bonjean committed
210 211 212
        /**
         * Notify the client the transfer is successful
         */
Tristan Matthews's avatar
Tristan Matthews committed
213
        void transferSucceeded();
Julien Bonjean's avatar
Julien Bonjean committed
214 215 216 217 218 219 220 221 222 223 224

        /**
         * 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
         */
225
        void refuseCall(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
226 227 228 229 230 231

        /**
         * Create a new conference given two participant
         * @param the first participant ID
         * @param the second participant ID
         */
232
        Conference* createConference(const std::string& id1, const std::string& id2);
Julien Bonjean's avatar
Julien Bonjean committed
233 234 235 236 237

        /**
         * Delete this conference
         * @param the conference ID
         */
238
        void removeConference(const std::string& conference_id);
Julien Bonjean's avatar
Julien Bonjean committed
239 240 241 242 243

        /**
         * Return the conference id for which this call is attached
         * @ param the call id
         */
244
        Conference* getConferenceFromCallID(const std::string& call_id);
Julien Bonjean's avatar
Julien Bonjean committed
245 246 247 248 249

        /**
         * Hold every participant to a conference
         * @param the conference id
         */
250
        void holdConference(const std::string& conference_id);
Julien Bonjean's avatar
Julien Bonjean committed
251 252 253 254 255

        /**
         * Unhold all conference participants
         * @param the conference id
         */
256
        void unHoldConference(const std::string& conference_id);
Julien Bonjean's avatar
Julien Bonjean committed
257 258 259 260 261

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

        /**
265
         * Test if a call id corresponds to a conference participant
Julien Bonjean's avatar
Julien Bonjean committed
266 267
         * @param the call id
         */
268
        bool isConferenceParticipant(const std::string& call_id);
Julien Bonjean's avatar
Julien Bonjean committed
269 270 271 272 273 274

        /**
         * Add a participant to a conference
         * @param the call id
         * @param the conference id
         */
275
        void addParticipant(const std::string& call_id, const std::string& conference_id);
Julien Bonjean's avatar
Julien Bonjean committed
276 277 278 279 280

        /**
         * Bind the main participant to a conference (mainly called on a double click action)
         * @param the conference id
         */
281
        void addMainParticipant(const std::string& conference_id);
Julien Bonjean's avatar
Julien Bonjean committed
282 283 284 285 286 287

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

290 291 292 293 294
        /**
         * Create a conference from a list of participant
         * @param A vector containing the list of participant
         */
        void createConfFromParticipantList(const std::vector< std::string > &);
295

Julien Bonjean's avatar
Julien Bonjean committed
296 297 298 299 300
        /**
         * Detach a participant from a conference, put the call on hold, do not hangup it
         * @param call id
         * @param the current call id
         */
301
        void detachParticipant(const std::string& call_id, const std::string& current_call_id);
Julien Bonjean's avatar
Julien Bonjean committed
302 303 304 305 306

        /**
         * Remove the conference participant from a conference
         * @param call id
         */
307
        void removeParticipant(const std::string& call_id);
Julien Bonjean's avatar
Julien Bonjean committed
308 309 310 311

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

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

316
        void removeStream(const std::string& call_id);
Julien Bonjean's avatar
Julien Bonjean committed
317 318 319 320

        /**
         * Save config to file
         */
321
        void saveConfig();
Julien Bonjean's avatar
Julien Bonjean committed
322 323 324 325

        /**
         * @return true if we tried to register once
         */
326
        bool hasTriedToRegister_;
Julien Bonjean's avatar
Julien Bonjean committed
327 328 329 330 331 332

        /**
         * Handle choice of the DTMF-send-way
         * @param   id: callid of the line.
         * @param   code: pressed key.
         */
333
        void sendDtmf(const std::string& id, char code);
Julien Bonjean's avatar
Julien Bonjean committed
334 335 336 337

        /**
         * Play a ringtone
         */
338
        void playTone();
Julien Bonjean's avatar
Julien Bonjean committed
339 340 341 342

        /**
         * Play a special ringtone ( BUSY ) if there's at least one message on the voice mail
         */
343
        void playToneWithMessage();
Julien Bonjean's avatar
Julien Bonjean committed
344 345 346 347

        /**
         * Acts on the audio streams and audio files
         */
348
        void stopTone();
Julien Bonjean's avatar
Julien Bonjean committed
349 350 351 352 353 354 355

        /**
         * When receiving a new incoming call, add it to the callaccount map
         * and notify user
         * @param call A call pointer
         * @param accountId an account id
         */
356
        void incomingCall(Call &call, const std::string& accountId);
Julien Bonjean's avatar
Julien Bonjean committed
357 358 359 360 361 362

        /**
         * Notify the user that the recipient of the call has answered and the put the
         * call in Current state
         * @param id  The call identifier
         */
363
        void peerAnsweredCall(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
364 365 366 367 368 369

        /**
         * Rings back because the outgoing call is ringing and the put the
         * call in Ringing state
         * @param id  The call identifier
         */
370
        void peerRingingCall(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
371 372 373 374 375

        /**
         * Put the call in Hungup state, remove the call from the list
         * @param id  The call identifier
         */
376
        void peerHungupCall(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
377 378 379 380 381 382

        /**
         * Notify the client with an incoming message
         * @param accountId	The account identifier
         * @param message The content of the message
         */
383
        void incomingMessage(const std::string& callID, const std::string& from, const std::string& message);
Julien Bonjean's avatar
Julien Bonjean committed
384

385 386

        /**
387
         * Send a new text message to the call, if participate to a conference, send to all participant.
388 389
         * @param callID	The call to send the message
         * @param message	The content of the message
390 391
        * @param from	        The sender of this message (could be another participant of a conference)
         */
392
        bool sendTextMessage(const std::string& callID, const std::string& message, const std::string& from);
393

Julien Bonjean's avatar
Julien Bonjean committed
394 395 396 397 398
        /**
         * Notify the client he has voice mails
         * @param accountId	  The account identifier
         * @param nb_msg The number of messages
         */
399
        void startVoiceMessageNotification(const std::string& accountId, int nb_msg);
Julien Bonjean's avatar
Julien Bonjean committed
400 401 402 403 404

        /**
         * ConfigurationManager - Send registration request
         * @param accountId The account to register/unregister
         * @param enable The flag for the type of registration
405 406
         *		 false for unregistration request
         *		 true for registration request
Julien Bonjean's avatar
Julien Bonjean committed
407
         */
408
        void sendRegister(const std::string& accountId, bool enable);
Julien Bonjean's avatar
Julien Bonjean committed
409 410 411 412 413

        /**
         * Get account list
         * @return std::vector<std::string> A list of accoundIDs
         */
414
        std::vector<std::string> getAccountList() const;
Julien Bonjean's avatar
Julien Bonjean committed
415 416 417 418

        /**
         * Set the account order in the config file
         */
419
        void setAccountsOrder(const std::string& order);
Julien Bonjean's avatar
Julien Bonjean committed
420 421 422 423 424 425

        /**
         * Retrieve details about a given account
         * @param accountID	  The account identifier
         * @return std::map< std::string, std::string > The account details
         */
426
        std::map<std::string, std::string> getAccountDetails(const std::string& accountID) const;
Julien Bonjean's avatar
Julien Bonjean committed
427 428 429 430 431 432

        /**
         * Retrieve details about a given call
         * @param callID	  The account identifier
         * @return std::map< std::string, std::string > The call details
         */
433
        std::map<std::string, std::string> getCallDetails(const std::string& callID);
Julien Bonjean's avatar
Julien Bonjean committed
434 435 436 437 438

        /**
         * Get call list
         * @return std::vector<std::string> A list of call IDs
         */
439
        std::vector<std::string> getCallList() const;
Julien Bonjean's avatar
Julien Bonjean committed
440 441 442 443 444 445

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

        /**
         * Get call list
         * @return std::vector<std::string> A list of call IDs
         */
452
        std::vector<std::string> getConferenceList() const;
Julien Bonjean's avatar
Julien Bonjean committed
453 454 455 456 457 458


        /**
         * Get a list of participant to a conference
         * @return std::vector<std::string> A list of call IDs
         */
459
        std::vector<std::string> getParticipantList(const std::string& confID) const;
Julien Bonjean's avatar
Julien Bonjean committed
460 461 462 463 464 465 466 467

        /**
         * 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
         */
468 469
        void setAccountDetails(const std::string& accountID,
                               const std::map<std::string, ::std::string > &details);
Julien Bonjean's avatar
Julien Bonjean committed
470 471 472 473 474 475

        /**
         * 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
         */
476
        std::string addAccount(const std::map<std::string, std::string> &details);
Julien Bonjean's avatar
Julien Bonjean committed
477 478 479 480 481 482

        /**
         * Delete an existing account, unregister VoIPLink associated, and
         * purge from configuration.
         * @param accountID	The account unique ID
         */
483
        void removeAccount(const std::string& accountID);
Julien Bonjean's avatar
Julien Bonjean committed
484 485 486 487 488 489

        /**
         * Get current codec name
         * @param call id
         * @return std::string The codec name
         */
490
        std::string getCurrentCodecName(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
491 492 493 494 495

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

        /**
499 500 501 502
             * 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
             */
503
        void setAudioDevice(const int index, const int streamType);
Julien Bonjean's avatar
Julien Bonjean committed
504 505 506 507 508

        /**
         * Get list of supported audio output device
         * @return std::vector<std::string> A list of the audio devices supporting playback
         */
509
        std::vector<std::string> getAudioOutputDeviceList();
Julien Bonjean's avatar
Julien Bonjean committed
510 511 512 513 514

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

        /**
518
         * Get string array representing integer indexes of output, input, and ringtone device
Julien Bonjean's avatar
Julien Bonjean committed
519 520 521 522 523 524 525 526 527
         * @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
         */
528
        int getAudioDeviceIndex(const std::string &name);
Julien Bonjean's avatar
Julien Bonjean committed
529 530 531 532 533

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

536 537 538 539
        /**
         * Get the noise reduction engin state from
         * the current audio layer.
         */
540
        std::string getNoiseSuppressState() const;
Julien Bonjean's avatar
Julien Bonjean committed
541

542 543 544 545
        /**
         * Set the noise reduction engin state in the current
         * audio layer.
         */
546
        void setNoiseSuppressState(const std::string &state);
Julien Bonjean's avatar
Julien Bonjean committed
547

548 549 550 551
        /**
         * Get the echo canceller engin state from
         * the current audio layer
         */
552
        bool getEchoCancelState() const;
553 554 555 556

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

559
        int getEchoCancelTailLength() const;
560 561 562

        void setEchoCancelTailLength(int);

563
        int getEchoCancelDelay() const;
564 565 566

        void setEchoCancelDelay(int);

Julien Bonjean's avatar
Julien Bonjean committed
567 568 569 570 571
        /**
         * Convert a list of payload in a special format, readable by the server.
         * Required format: payloads separated with one slash.
         * @return std::string The serializabled string
         */
572
        static std::string serialize(const std::vector<std::string> &v);
Julien Bonjean's avatar
Julien Bonjean committed
573

574
        static std::vector<std::string> unserialize(std::string v);
Julien Bonjean's avatar
Julien Bonjean committed
575 576 577 578 579 580 581

        /**
         * 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
         */
582
        int isRingtoneEnabled(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
583 584 585 586 587

        /**
         * Set the ringtone option
         * Inverse current value
         */
588
        void ringtoneEnabled(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
589 590 591 592 593

        /**
         * Get the recording path from configuration tree
         * @return the string correspoding to the path
         */
594
        std::string getRecordPath() const;
Julien Bonjean's avatar
Julien Bonjean committed
595 596 597 598 599

        /**
         * Set the recoding path in the configuration tree
         * @param a string reresenting the path
         */
600
        void setRecordPath(const std::string& recPath);
Julien Bonjean's avatar
Julien Bonjean committed
601

602 603 604
        /**
         * Get is always recording functionality
         */
605
        bool getIsAlwaysRecording() const;
606 607 608 609 610 611 612

        /**
         * 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
613 614 615 616 617
        /**
         * Set recording on / off
         * Start recording
         * @param id  The call identifier
         */
618
        void setRecordingCall(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
619 620 621 622

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

625 626 627 628
        /**
         * Start playback fo a recorded file if and only if audio layer is not already started.
         * @param File path of the file to play
             */
629
        bool startRecordedFilePlayback(const std::string&);
630

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

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

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

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

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

        /**
         * Set the desktop mail notification level
         */
665
        void setMailNotify();
Julien Bonjean's avatar
Julien Bonjean committed
666 667 668 669 670


        /**
         * Addressbook configuration
         */
671
        std::map<std::string, int32_t> getAddressbookSettings() const;
Julien Bonjean's avatar
Julien Bonjean committed
672 673 674 675

        /**
         * Addressbook configuration
         */
676
        void setAddressbookSettings(const std::map<std::string, int32_t>& settings);
Julien Bonjean's avatar
Julien Bonjean committed
677 678 679 680

        /**
         * Addressbook list
         */
681
        void setAddressbookList(const std::vector<  std::string >& list);
Julien Bonjean's avatar
Julien Bonjean committed
682 683 684 685

        /**
         * Addressbook list
         */
686
        std::vector <std::string> getAddressbookList() const;
Julien Bonjean's avatar
Julien Bonjean committed
687 688 689 690

        /**
         * Get the audio manager
         * @return int The audio manager
691 692
         *		    "alsa"
         *		    "pulseaudio"
Julien Bonjean's avatar
Julien Bonjean committed
693
         */
694
        std::string getAudioManager() const;
Julien Bonjean's avatar
Julien Bonjean committed
695 696 697 698

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

701
        void switchAudioManager();
Julien Bonjean's avatar
Julien Bonjean committed
702

703 704 705 706
        /**
         * Set the internal audio sampling rate change. Should close the audio layer and
         * reopen stream at different rate,
         */
707
        void audioSamplingRateChanged(int);
Julien Bonjean's avatar
Julien Bonjean committed
708 709 710 711 712

        /**
         * Get the desktop mail notification level
         * @return int The mail notification level
         */
713
        int32_t getMailNotify() const;
Julien Bonjean's avatar
Julien Bonjean committed
714 715 716 717 718

        /**
         * Get the list of the active codecs
         * @return std::vector< ::std::string >  The list of active codecs
         */
719
        std::vector<std::string> getActiveCodecList() const;
Julien Bonjean's avatar
Julien Bonjean committed
720 721 722 723 724 725 726 727 728 729

        /**
         * 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
         */
730
        void setConfig(const std::string& section, const std::string& name, const std::string& value);
Julien Bonjean's avatar
Julien Bonjean committed
731 732 733 734 735 736 737 738 739 740

        /**
         * 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
         */
741
        void setConfig(const std::string& section, const std::string& name, int value);
Julien Bonjean's avatar
Julien Bonjean committed
742 743 744 745 746 747 748 749

        /**
         * 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
         */
750
        std::string getConfigString(const std::string& section, const std::string& name) const;
Julien Bonjean's avatar
Julien Bonjean committed
751 752 753 754 755 756

        /**
         * Retrieve the soundcards index in the user config file and try to open audio devices
         * with a specific alsa plugin.
         * Set the audio layer sample rate
         */
757
        void selectAudioDriver();
Julien Bonjean's avatar
Julien Bonjean committed
758 759 760 761 762

        /**
         * Handle audio sounds heard by a caller while they wait for their
         * connection to a called party to be completed.
         */
763
        void ringback();
Julien Bonjean's avatar
Julien Bonjean committed
764 765 766 767

        /**
         * Handle played music when an incoming call occurs
         */
768
        void ringtone(const std::string& accountID);
Julien Bonjean's avatar
Julien Bonjean committed
769 770 771 772

        /**
         * Handle played music when a congestion occurs
         */
773
        void congestion();
Julien Bonjean's avatar
Julien Bonjean committed
774 775 776 777

        /**
         * Handle played sound when a call can not be conpleted because of a busy recipient
         */
778
        void callBusy(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
779 780 781 782

        /**
         * Handle played sound when a failure occurs
         */
783
        void callFailure(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800

        /**
         * 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
         */
Tristan Matthews's avatar
cleanup  
Tristan Matthews committed
801
        bool incomingCallWaiting() const;
Julien Bonjean's avatar
Julien Bonjean committed
802 803 804

        /**
         * Return a new random callid that is not present in the list
805
         * @return std::string A brand new callid
Julien Bonjean's avatar
Julien Bonjean committed
806
         */
807
        std::string getNewCallID();
Julien Bonjean's avatar
Julien Bonjean committed
808 809 810

        /**
         * Get the current call id
811
         * @return std::string	The call id or ""
Julien Bonjean's avatar
Julien Bonjean committed
812
         */
813
        std::string getCurrentCallId() const;
Julien Bonjean's avatar
Julien Bonjean committed
814 815 816 817 818 819

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

822
        void initAudioDriver();
Julien Bonjean's avatar
Julien Bonjean committed
823

824
        void audioLayerMutexLock() {
825
            audioLayerMutex_.enterMutex();
826
        }
827

828
        void audioLayerMutexUnlock() {
829
            audioLayerMutex_.leaveMutex();
830
        }
Julien Bonjean's avatar
Julien Bonjean committed
831

832 833 834 835
        /**
         * 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
         */
836
        std::vector<std::string> loadAccountOrder() const;
837 838 839 840

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

Julien Bonjean's avatar
Julien Bonjean committed
841
    private:
842 843 844 845
        /**
         * Play the dtmf-associated sound
         * @param code  The pressed key
         */
846
        void playDtmf(char code);
847 848 849 850 851 852 853

        /**
         * 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
         */
854
        void processRemainingParticipants(const std::string &current_call_id, Conference * &conf);
855

Julien Bonjean's avatar
Julien Bonjean committed
856
        /**
857
         * Create config directory in home user and return configuration file path
Julien Bonjean's avatar
Julien Bonjean committed
858
         */
859
        std::string createConfigFile() const;
Julien Bonjean's avatar
Julien Bonjean committed
860 861 862 863

        /*
         * Initialize zeroconf module and scanning
         */
864
        void initZeroconf();
Julien Bonjean's avatar
Julien Bonjean committed
865 866 867 868 869

        /**
         * Switch of current call id
         * @param id The new callid
         */
870
        void switchCall(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
871 872 873 874 875

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

878
        DBusManager dbus_;
879

Julien Bonjean's avatar
Julien Bonjean committed
880
        /** The configuration tree. It contains accounts parameters, general user settings ,audio settings, ... */
881
        Conf::ConfigTree config_;
Julien Bonjean's avatar
Julien Bonjean committed
882 883

        /** Current Call ID */
884
        std::string currentCallId_;
Julien Bonjean's avatar
Julien Bonjean committed
885 886

        /** Protected current call access */
887
        ost::Mutex currentCallMutex_;
Julien Bonjean's avatar
Julien Bonjean committed
888 889

        /** Audio layer */
890
        AudioLayer* audiodriver_;
Julien Bonjean's avatar
Julien Bonjean committed
891 892

        // Main thread
893
        std::tr1::shared_ptr<DTMF> dtmfKey_;
Julien Bonjean's avatar
Julien Bonjean committed
894 895 896 897

        /////////////////////
        // Protected by Mutex
        /////////////////////
898
        ost::Mutex toneMutex_;
899 900
        std::tr1::shared_ptr<TelephoneTone> telephoneTone_;
        std::tr1::shared_ptr<AudioFile> audiofile_;
Julien Bonjean's avatar
Julien Bonjean committed
901 902

        // To handle volume control
903 904
        // short speakerVolume_;
        // short micVolume_;
Julien Bonjean's avatar
Julien Bonjean committed
905 906
        // End of sound variable

907 908 909
        /**
         * Mutex used to protect audio layer
         */
910
        ost::Mutex audioLayerMutex_;
Julien Bonjean's avatar
Julien Bonjean committed
911

912 913 914
        /**
         * Waiting Call Vectors
         */
915
        CallIDSet waitingCall_;
Julien Bonjean's avatar
Julien Bonjean committed
916

917 918 919
        /**
         * Protect waiting call list, access by many voip/audio threads
         */
920
        ost::Mutex waitingCallMutex_;
Julien Bonjean's avatar
Julien Bonjean committed
921

922 923 924
        /**
         * Number of waiting call, synchronize with waitingcall callidvector
         */
925
        unsigned int nbIncomingWaitingCall_;
Julien Bonjean's avatar
Julien Bonjean committed
926 927 928

        /**
         * Add incoming callid to the waiting list
929
         * @param id std::string to add
Julien Bonjean's avatar
Julien Bonjean committed
930
         */
931
        void addWaitingCall(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
932 933 934

        /**
         * Remove incoming callid to the waiting list
935
         * @param id std::string to remove
Julien Bonjean's avatar
Julien Bonjean committed
936
         */
937
        void removeWaitingCall(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
938

939 940 941 942
        /** Remove a CallID/std::string association
         * Protected by mutex
         * @param callID the CallID to remove
         */
943
        void removeCallAccount(const std::string& callID);
944

Julien Bonjean's avatar
Julien Bonjean committed
945 946 947
        /**
         * Path of the ConfigFile
         */
948
        std::string path_;
949

jpbl's avatar
jpbl committed
950
#ifdef USE_ZEROCONF
Julien Bonjean's avatar
Julien Bonjean committed
951 952
        // DNSService contain every zeroconf services
        //  configuration detected on the network
953
        DNSService *DNSService_;
jpbl's avatar
jpbl committed
954 955
#endif

Julien Bonjean's avatar
Julien Bonjean committed
956
        /** Map to associate a CallID to the good account */
957
        CallAccountMap callAccountMap_;
Julien Bonjean's avatar
Julien Bonjean committed
958 959

        /** Mutex to lock the call account map (main thread + voiplink thread) */
960
        ost::Mutex callAccountMapMutex_;
Julien Bonjean's avatar
Julien Bonjean committed
961

962
        std::map<std::string, bool> IPToIPMap_;
Julien Bonjean's avatar
Julien Bonjean committed
963 964


965
        bool isIPToIP(const std::string& callID) const;
Julien Bonjean's avatar
Julien Bonjean committed
966 967 968

        /**
         *Contains a list of account (sip, aix, etc) and their respective voiplink/calls */
969
        AccountMap accountMap_;
Julien Bonjean's avatar
Julien Bonjean committed
970 971

        /**
972
         * Load the account map from configuration
Julien Bonjean's avatar
Julien Bonjean committed
973
         */
974 975 976 977 978
        void loadAccountMap(Conf::YamlParser &parser);
        /**
         * Load default account map (no configuration)
         */
        void loadDefaultAccountMap();
Julien Bonjean's avatar
Julien Bonjean committed
979 980 981 982 983 984 985 986 987 988 989 990 991

        /**
         * Unload the account (delete them)
         */
        void unloadAccountMap();

        /**
         * 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.
         *
         */
992
        MainBuffer mainBuffer_;
Julien Bonjean's avatar
Julien Bonjean committed
993 994 995

    public:

996 997
        void setIPToIPForCall(const std::string& callID, bool IPToIP);

998
        /** Associate a new std::string to a std::string
999 1000 1001 1002 1003
         * Protected by mutex
         * @param callID the new CallID not in the list yet
         * @param accountID the known accountID present in accountMap
         * @return bool True if the new association is create
         */
1004
        bool associateCallToAccount(const std::string& callID, const std::string& accountID);
1005

1006 1007 1008
        /**
         * Test if call is a valid call, i.e. have been created and stored in
         * call-account map
1009
         * @param callID the std::string to be tested
1010 1011
         * @return true if call is created and present in the call-account map
         */
1012
        bool isValidCall(const std::string& callID);
1013

Julien Bonjean's avatar
Julien Bonjean committed
1014 1015 1016
        /**
         * Return a pointer to the  instance of the mainbuffer
         */
1017 1018
        MainBuffer *getMainBuffer() {
            return &mainBuffer_;