managerimpl.h 31.5 KB
Newer Older
jpbl's avatar
jpbl committed
1
/*
2
 *  Copyright (C) 2004-2012 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>
47
#include <pthread.h>
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
152
        AudioLayer* getAudioDriver() {
            return audiodriver_;
Julien Bonjean's avatar
Julien Bonjean committed
153
154
        }

155
156
        void startAudioDriverStream();

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

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

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


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

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

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

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

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

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

        /**
         * 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
         */
235
        bool refuseCall(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
236
237
238
239
240
241

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

396
397

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

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

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

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

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

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

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

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

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

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

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

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


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

483
484
        std::string getConferenceId(const std::string& callID);

Julien Bonjean's avatar
Julien Bonjean committed
485
486
487
488
489
490
491
        /**
         * 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
         */
492
493
        void setAccountDetails(const std::string& accountID,
                               const std::map<std::string, ::std::string > &details);
Julien Bonjean's avatar
Julien Bonjean committed
494
495
496
497
498
499

        /**
         * 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
         */
500
        std::string addAccount(const std::map<std::string, std::string> &details);
Julien Bonjean's avatar
Julien Bonjean committed
501
502
503
504
505
506

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

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

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

        /**
524
525
526
527
             * 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
             */
528
        void setAudioDevice(int index, AudioLayer::PCMType streamType);
Julien Bonjean's avatar
Julien Bonjean committed
529
530
531
532
533

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

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

        /**
543
         * Get string array representing integer indexes of output, input, and ringtone device
Julien Bonjean's avatar
Julien Bonjean committed
544
545
546
547
548
549
550
551
552
         * @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
         */
553
        int getAudioDeviceIndex(const std::string &name);
Julien Bonjean's avatar
Julien Bonjean committed
554
555
556
557
558

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

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

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

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

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

Julien Bonjean's avatar
Julien Bonjean committed
584
585
586
587
588
589
        /**
         * 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
         */
590
        int isRingtoneEnabled(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
591
592
593
594
595

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

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

        /**
         * 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
609
610
611
612
        /**
         * Set recording on / off
         * Start recording
         * @param id  The call identifier
613
         * Returns true if the call was set to record
Julien Bonjean's avatar
Julien Bonjean committed
614
         */
615
        bool toggleRecordingCall(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
616
617
618
619

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

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

628
629
        void recordingPlaybackSeek(const double value);

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

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

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

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

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

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

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

674
        void switchAudioManager();
Julien Bonjean's avatar
Julien Bonjean committed
675

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

        /**
         * 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
         */
691
        void setConfig(const std::string& section, const std::string& name, const std::string& value);
Julien Bonjean's avatar
Julien Bonjean committed
692
693
694
695
696
697
698
699
700
701

        /**
         * 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
         */
702
        void setConfig(const std::string& section, const std::string& name, int value);
Julien Bonjean's avatar
Julien Bonjean committed
703
704
705
706
707
708
709
710

        /**
         * 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
         */
711
        std::string getConfigString(const std::string& section, const std::string& name) const;
Julien Bonjean's avatar
Julien Bonjean committed
712
713
714
715
716

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

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

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

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

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

        /**
         * 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
         */
755
        bool incomingCallsWaiting();
Julien Bonjean's avatar
Julien Bonjean committed
756
757
758

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

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

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

776
        void initAudioDriver();
Julien Bonjean's avatar
Julien Bonjean committed
777

778
779
780
781
        /**
         * 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
         */
782
        std::vector<std::string> loadAccountOrder() const;
783
784
785
786

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

Julien Bonjean's avatar
Julien Bonjean committed
787
    private:
788
        bool parseConfiguration();
789

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

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

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

        /**
         * 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
         */
810
        void processRemainingParticipants(Conference &conf);
811

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

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

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

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

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

839
        Client client_;
840

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

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

        /** Protected current call access */
848
        pthread_mutex_t currentCallMutex_;
Julien Bonjean's avatar
Julien Bonjean committed
849
850

        /** Audio layer */
851
        AudioLayer* audiodriver_;
Julien Bonjean's avatar
Julien Bonjean committed
852
853

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

        /////////////////////
        // Protected by Mutex
        /////////////////////
859
        pthread_mutex_t toneMutex_;
860
861
        std::unique_ptr<TelephoneTone> telephoneTone_;
        std::unique_ptr<AudioFile> audiofile_;
Julien Bonjean's avatar
Julien Bonjean committed
862
863

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

868
869
870
        /**
         * Mutex used to protect audio layer
         */
871
        pthread_mutex_t audioLayerMutex_;
Julien Bonjean's avatar
Julien Bonjean committed
872

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

878
879
880
        /**
         * Protect waiting call list, access by many voip/audio threads
         */
881
        pthread_mutex_t waitingCallsMutex_;
Julien Bonjean's avatar
Julien Bonjean committed
882
883
884

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

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

        /**
         * Path of the ConfigFile
         */
898
        std::string path_;
899

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

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

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

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

        /**
         * 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.
         *
         */
926
        MainBuffer mainBuffer_;
Julien Bonjean's avatar
Julien Bonjean committed
927
928
929

    public:

930
931
        void setIPToIPForCall(const std::string& callID, bool IPToIP);

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

Julien Bonjean's avatar
Julien Bonjean committed
940
941
942
        /**
         * Return a pointer to the  instance of the mainbuffer
         */
943
944
        MainBuffer &getMainBuffer() {
            return mainBuffer_;
Julien Bonjean's avatar
Julien Bonjean committed
945
946
947
948
949
950
        }

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

        /**
954
955
         * Return the current Client
         * @return A pointer to the Client instance
Julien Bonjean's avatar
Julien Bonjean committed
956
         */
957
        Client* getClient() {
958
            return &client_;
Julien Bonjean's avatar
Julien Bonjean committed
959
        }
960
#ifdef SFL_VIDEO
961
        VideoControls * getVideoControls() {
962
            return client_.getVideoControls();
963
        }
964
#endif
965

Julien Bonjean's avatar
Julien Bonjean committed
966
967
968
969
970
971
        /**
        * Tell if an account exists
        * @param accountID account ID check
        * @return bool True if the account exists
        *		  false otherwise
        */
972
        bool accountExists(const std::string& accountID);
Julien Bonjean's avatar
Julien Bonjean committed
973

974
        std::vector<std::map<std::string, std::string> > getHistory();
975
        void clearHistory();
976

Julien Bonjean's avatar
Julien Bonjean committed
977
        /**
978
         * Get an account pointer, looks for both SIP and IAX
Julien Bonjean's avatar
Julien Bonjean committed
979
980
981
         * @param accountID account ID to get
         * @return Account*	 The account pointer or 0
         */
982
983
984
985
986
987
988
989
990
        Account* getAccount(const std::string& accountID) const;

        /**
         * Get a SIP account pointer
         * @param accountID account ID to get
         * @return SIPAccount* The account pointer or 0
         */
        SIPAccount *getSipAccount(const std::string& accontID) const;

991
#if HAVE_IAX
992
993
994
995
996
997
        /**
         * Get an IAX account pointer
         * @param accountID account ID to get
         * @return IAXAccount* The account pointer or 0
         */
        IAXAccount *getIaxAccount(const std::string& accountID) const;
998
#endif
999
1000

	/**