managerimpl.h 38.1 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 __SFL_MANAGER_H__
#define __SFL_MANAGER_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>
jpbl's avatar
jpbl committed
42
#include <cc++/thread.h>
43
#include "dbus/dbusmanager.h"
jpbl's avatar
jpbl committed
44
45

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

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

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

53
#include "audio/mainbuffer.h"
54
#include "preferences.h"
55

56
57
58
namespace sfl {
    class InstantMessaging;
}
59

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

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

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

75
class HistoryManager;
76
class Account;
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
typedef std::map<std::string, Call::CallConfiguration> CallConfigMap;
Emmanuel Milou's avatar
Emmanuel Milou committed
85

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

Julien Bonjean's avatar
Julien Bonjean committed
89
/** To store conference objects by call ids
90
    used to retreive the conference according to a call */
91
typedef std::map<std::string, Conference*> ConferenceCallMap;
92
93

/** To store conference objects by conference ids */
94
typedef std::map<std::string, Conference*> ConferenceMap;
95

96
static std::string default_conf = "conf";
97

98
/** Manager (controller) of sflphone daemon */
Julien Bonjean's avatar
Julien Bonjean committed
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
131
132
133
134
135
136
137
138
139
class ManagerImpl
{
    public:
        ManagerImpl (void);
        ~ManagerImpl (void);


        /**
         * 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
         */
140
        void init (std::string config_file="");
Julien Bonjean's avatar
Julien Bonjean committed
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159

        /**
         * Terminate all thread (sound, link) and unload AccountMap
         */
        void terminate (void);

        /**
         * Accessor to audiodriver.
         * it's multi-thread and use mutex internally
         * @return AudioLayer*  The audio layer object
         */
        AudioLayer* getAudioDriver (void) const {
            return _audiodriver;
        }

        /**
         * Get a descriptor map of codec available
         * @return CodecDescriptor  The internal codec map
         */
160
161
        AudioCodecFactory& getAudioCodecFactory (void) {
            return _audioCodecFactory;
Julien Bonjean's avatar
Julien Bonjean committed
162
163
164
165
166
167
        }

        /**
         * Functions which occur with a user's action
         * Place a new call
         * @param accountId	The account to make tha call with
168
         * @param call_id  The call identifier
Julien Bonjean's avatar
Julien Bonjean committed
169
         * @param to  The recipient of the call
170
	 * @param conf_id The conference identifier if any
Julien Bonjean's avatar
Julien Bonjean committed
171
172
173
         * @return bool true on success
         *		  false otherwise
         */
174
        bool outgoingCall (const std::string&, const std::string&, const std::string&, const std::string& = "");
Julien Bonjean's avatar
Julien Bonjean committed
175
176
177
178
179
180

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

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


        /**
         * Functions which occur with a user's action
         * Hangup the conference (hangup every participants)
         * @param id  The call identifier
         */
196
        bool hangupConference (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 on hold
         * @param id  The call identifier
         */
203
        void onHoldCall (const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
204
205
206
207
208
209

        /**
         * Functions which occur with a user's action
         * Put the call off hold
         * @param id  The call identifier
         */
210
        void offHoldCall (const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
211
212
213
214
215
216
217

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

220
221
222
223
224
        /**
         * Attended transfer
         * @param The call id to be transfered
         * @param The target
         */
225
        bool attendedTransfer(const std::string& transferID, const std::string& targetID);
226

Julien Bonjean's avatar
Julien Bonjean committed
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
        /**
         * Notify the client the transfer is successful
         */
        void transferSucceded();

        /**
         * 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
         */
242
        bool refuseCall (const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
243
244
245
246
247
248

        /**
         * Create a new conference given two participant
         * @param the first participant ID
         * @param the second participant ID
         */
249
        Conference* createConference (const std::string& id1, const std::string& id2);
Julien Bonjean's avatar
Julien Bonjean committed
250
251
252
253
254

        /**
         * Delete this conference
         * @param the conference ID
         */
255
        void removeConference (const std::string& conference_id);
Julien Bonjean's avatar
Julien Bonjean committed
256
257
258
259
260

        /**
         * Return the conference id for which this call is attached
         * @ param the call id
         */
261
        Conference* getConferenceFromCallID (const std::string& call_id);
Julien Bonjean's avatar
Julien Bonjean committed
262
263
264
265
266

        /**
         * Hold every participant to a conference
         * @param the conference id
         */
267
        void holdConference (const std::string& conference_id);
Julien Bonjean's avatar
Julien Bonjean committed
268
269
270
271
272

        /**
         * Unhold all conference participants
         * @param the conference id
         */
273
        void unHoldConference (const std::string& conference_id);
Julien Bonjean's avatar
Julien Bonjean committed
274
275
276
277
278

        /**
         * Test if this id is a conference (usefull to test current call)
         * @param the call id
         */
279
        bool isConference (const std::string& call_id);
Julien Bonjean's avatar
Julien Bonjean committed
280
281
282
283
284

        /**
         * Test if a call id particips to this conference
         * @param the call id
         */
285
        bool participToConference (const std::string& call_id);
Julien Bonjean's avatar
Julien Bonjean committed
286
287
288
289
290
291

        /**
         * Add a participant to a conference
         * @param the call id
         * @param the conference id
         */
292
        void addParticipant (const std::string& call_id, const std::string& conference_id);
Julien Bonjean's avatar
Julien Bonjean committed
293
294
295
296
297

        /**
         * Bind the main participant to a conference (mainly called on a double click action)
         * @param the conference id
         */
298
        void addMainParticipant (const std::string& conference_id);
Julien Bonjean's avatar
Julien Bonjean committed
299
300
301
302
303
304

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

307
308
309
310
311
312
	/**
	 * Create a conference from a list of participant
	 * @param A vector containing the list of participant
 	 */
	void createConfFromParticipantList(const std::vector< std::string > &);

Julien Bonjean's avatar
Julien Bonjean committed
313
314
315
316
317
        /**
         * Detach a participant from a conference, put the call on hold, do not hangup it
         * @param call id
         * @param the current call id
         */
318
        void detachParticipant (const std::string& call_id, const std::string& current_call_id);
Julien Bonjean's avatar
Julien Bonjean committed
319
320
321
322
323

        /**
         * Remove the conference participant from a conference
         * @param call id
         */
324
        void removeParticipant (const std::string& call_id);
Julien Bonjean's avatar
Julien Bonjean committed
325
326
327
328

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

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

333
        void removeStream (const std::string& call_id);
Julien Bonjean's avatar
Julien Bonjean committed
334
335
336
337

        /**
         * Save config to file
         */
338
        void saveConfig (void);
Julien Bonjean's avatar
Julien Bonjean committed
339
340
341
342
343
344
345
346
347
348
349

        /**
         * @return true if we tried to register once
         */
        bool _hasTriedToRegister;

        /**
         * Handle choice of the DTMF-send-way
         * @param   id: callid of the line.
         * @param   code: pressed key.
         */
350
        bool sendDtmf (const std::string& id, char code);
Julien Bonjean's avatar
Julien Bonjean committed
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377

        /**
         * Play a ringtone
         * @return bool True on success
         *	      false otherwise
         */
        bool playTone ();

        /**
         * Play a special ringtone ( BUSY ) if there's at least one message on the voice mail
         * @return bool True on success
         *	      false otherwise
         */
        bool playToneWithMessage ();

        /**
         * Acts on the audio streams and audio files
         */
        void stopTone (void);

        /**
         * 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
         * @return bool True if the call was added correctly
         */
378
        bool incomingCall (Call* call, const std::string& accountId);
Julien Bonjean's avatar
Julien Bonjean committed
379
380
381
382
383
384

        /**
         * Notify the user that the recipient of the call has answered and the put the
         * call in Current state
         * @param id  The call identifier
         */
385
        void peerAnsweredCall (const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
386
387
388
389
390
391

        /**
         * Rings back because the outgoing call is ringing and the put the
         * call in Ringing state
         * @param id  The call identifier
         */
392
        void peerRingingCall (const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
393
394
395
396
397

        /**
         * Put the call in Hungup state, remove the call from the list
         * @param id  The call identifier
         */
398
        void peerHungupCall (const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
399
400
401
402
403
404

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

407
408

        /**
409
         * Send a new text message to the call, if participate to a conference, send to all participant.
410
411
         * @param callID	The call to send the message
         * @param message	The content of the message
412
413
        * @param from	        The sender of this message (could be another participant of a conference)
         */
414
        bool sendTextMessage (const std::string& callID, const std::string& message, const std::string& from);
415

Julien Bonjean's avatar
Julien Bonjean committed
416
417
418
419
420
        /**
         * Notify the client he has voice mails
         * @param accountId	  The account identifier
         * @param nb_msg The number of messages
         */
421
        void startVoiceMessageNotification (const std::string& accountId, int nb_msg);
Julien Bonjean's avatar
Julien Bonjean committed
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440

        /**
         * Notify the client through DBus that registration state has been updated
         */
        void connectionStatusNotification (void);

        /**
         * ConfigurationManager - Send registration request
         * @param accountId The account to register/unregister
         * @param enable The flag for the type of registration
         *		 0 for unregistration request
         *		 1 for registration request
         */
        void sendRegister (const ::std::string& accountId , const int32_t& enable);

        /**
         * Get account list
         * @return std::vector<std::string> A list of accoundIDs
         */
441
        std::vector< std::string >  getAccountList() const;
Julien Bonjean's avatar
Julien Bonjean committed
442
443
444
445
446
447
448
449
450
451
452

        /**
         * Set the account order in the config file
         */
        void setAccountsOrder (const std::string& order);

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

        /**
         * Retrieve details about a given call
         * @param callID	  The account identifier
         * @return std::map< std::string, std::string > The call details
         */
460
        std::map< std::string, std::string > getCallDetails (const std::string& callID);
Julien Bonjean's avatar
Julien Bonjean committed
461
462
463
464
465

        /**
         * Get call list
         * @return std::vector<std::string> A list of call IDs
         */
466
        std::vector< std::string >  getCallList (void) const;
Julien Bonjean's avatar
Julien Bonjean committed
467
468
469
470
471
472

        /**
         * Retrieve details about a given call
         * @param callID	  The account identifier
         * @return std::map< std::string, std::string > The call details
         */
473
        std::map< std::string, std::string > getConferenceDetails (const std::string& callID) const;
Julien Bonjean's avatar
Julien Bonjean committed
474
475
476
477
478

        /**
         * Get call list
         * @return std::vector<std::string> A list of call IDs
         */
479
        std::vector< std::string >  getConferenceList (void) const;
Julien Bonjean's avatar
Julien Bonjean committed
480
481
482
483
484
485


        /**
         * Get a list of participant to a conference
         * @return std::vector<std::string> A list of call IDs
         */
486
        std::vector< std::string >  getParticipantList (const std::string& confID) const;
Julien Bonjean's avatar
Julien Bonjean committed
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509

        /**
         * 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
         */
        void setAccountDetails (const ::std::string& accountID,
                                const std::map< ::std::string, ::std::string >& details);

        /**
         * 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
         */
        std::string addAccount (const std::map< ::std::string, ::std::string >& details);

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

        /**
         * Get current codec name
         * @param call id
         * @return std::string The codec name
         */
517
        std::string getCurrentCodecName (const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
518
519
520
521
522

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

        /**
526
527
528
529
530
             * 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
             */
        void setAudioDevice (const int index, const int streamType);
Julien Bonjean's avatar
Julien Bonjean committed
531
532
533
534
535
536
537
538
539
540
541
542
543
544

        /**
         * Get list of supported audio output device
         * @return std::vector<std::string> A list of the audio devices supporting playback
         */
        std::vector<std::string> getAudioOutputDeviceList (void);

        /**
         * Get list of supported audio input device
         * @return std::vector<std::string> A list of the audio devices supporting capture
         */
        std::vector<std::string> getAudioInputDeviceList (void);

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

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

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

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

575
576
577
578
        /**
         * Get the echo canceller engin state from
         * the current audio layer
         */
579
        std::string getEchoCancelState(void) const;
580
581
582
583

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

586
        int getEchoCancelTailLength(void) const;
587
588
589

        void setEchoCancelTailLength(int);

590
        int getEchoCancelDelay(void) const;
591
592
593

        void setEchoCancelDelay(int);

Julien Bonjean's avatar
Julien Bonjean committed
594
595
596
597
598
        /**
         * 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
         */
599
        static std::string serialize (const std::vector<std::string> &v);
Julien Bonjean's avatar
Julien Bonjean committed
600

601
        static std::vector<std::string> unserialize (std::string v);
Julien Bonjean's avatar
Julien Bonjean committed
602
603
604
605
606
607
608

        /**
         * 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
         */
609
        int isRingtoneEnabled (const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
610
611
612
613
614

        /**
         * Set the ringtone option
         * Inverse current value
         */
615
        void ringtoneEnabled (const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
616
617
618
619
620

        /**
         * Get the recording path from configuration tree
         * @return the string correspoding to the path
         */
621
        std::string getRecordPath (void) const;
Julien Bonjean's avatar
Julien Bonjean committed
622
623
624
625
626
627
628

        /**
         * Set the recoding path in the configuration tree
         * @param a string reresenting the path
         */
        void setRecordPath (const std::string& recPath);

629
630
631
        /**
         * Get is always recording functionality
         */
632
        bool getIsAlwaysRecording(void) const;
633
634
635
636
637
638
639

        /**
         * 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
640
641
642
643
644
        /**
         * Set recording on / off
         * Start recording
         * @param id  The call identifier
         */
645
        void setRecordingCall (const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
646
647
648
649

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

652
653
654
655
	/**
	 * Start playback fo a recorded file if and only if audio layer is not already started.
 	 * @param File path of the file to play
         */
656
        bool startRecordedFilePlayback(const std::string&);
657
658
659
660
661
662
663

	/**
	 * Stop playback of recorded file
	 * @param File of the file to stop
	 */
        void stopRecordedFilePlayback(const std::string&);

Julien Bonjean's avatar
Julien Bonjean committed
664
665
666
667
        /**
         * Set the maximum number of days to keep in the history
         * @param calls The number of days
         */
668
        void setHistoryLimit (int days);
Julien Bonjean's avatar
Julien Bonjean committed
669
670
671
672
673

        /**
         * Get the maximum number of days to keep in the history
         * @return double The number of days
         */
674
        int getHistoryLimit (void) const;
Julien Bonjean's avatar
Julien Bonjean committed
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697

        /**
         * Configure the start-up option
         * @return int	1 if SFLphone should start in the system tray
         *	        0 otherwise
         */
        int isStartHidden (void);

        /**
         * Configure the start-up option
         * At startup, SFLphone can be displayed or start hidden in the system tray
         */
        void startHidden (void);

        /**
         * Set the desktop mail notification level
         */
        void setMailNotify (void);


        /**
         * Addressbook configuration
         */
698
        std::map<std::string, int32_t> getAddressbookSettings (void) const;
Julien Bonjean's avatar
Julien Bonjean committed
699
700
701
702
703
704
705
706
707
708
709
710
711
712

        /**
         * Addressbook configuration
         */
        void setAddressbookSettings (const std::map<std::string, int32_t>& settings);

        /**
         * Addressbook list
         */
        void setAddressbookList (const std::vector<  std::string >& list);

        /**
         * Addressbook list
         */
713
        std::vector <std::string> getAddressbookList (void) const;
Julien Bonjean's avatar
Julien Bonjean committed
714
715
716
717

        /**
         * Hook configuration
         */
718
        std::map<std::string, std::string> getHookSettings (void) const;
Julien Bonjean's avatar
Julien Bonjean committed
719
720
721
722
723
724
725
726
727
728
729
730
731

        /**
         * Hook configuration
         */
        void setHookSettings (const std::map<std::string, std::string>& settings);


        /**
         * Get the audio manager
         * @return int The audio manager
         *		    0 ALSA
         *		    1 PULSEAUDIO
         */
732
        int32_t getAudioManager (void) const;
Julien Bonjean's avatar
Julien Bonjean committed
733
734
735
736

        /**
         * Set the audio manager
         */
737
        void setAudioManager (int32_t api);
Julien Bonjean's avatar
Julien Bonjean committed
738
739
740

        void switchAudioManager (void);

741
742
743
744
745
        /**
         * Set the internal audio sampling rate change. Should close the audio layer and
         * reopen stream at different rate,
         */
        void audioSamplingRateChanged (int);
Julien Bonjean's avatar
Julien Bonjean committed
746
747
748
749
750

        /**
         * Get the desktop mail notification level
         * @return int The mail notification level
         */
751
        int32_t getMailNotify (void) const;
Julien Bonjean's avatar
Julien Bonjean committed
752
753
754
755
756

        /**
         * Get the list of the active codecs
         * @return std::vector< ::std::string >  The list of active codecs
         */
757
        std::vector< ::std::string > getActiveCodecList (void) const;
Julien Bonjean's avatar
Julien Bonjean committed
758
759
760
761
762
763
764
765
766

        /**
         * Retrieve in the configuration tree the value of a parameter in a specific section
         * @param section	The section to look in
         * @param name	The name of the parameter you want to get
         * @param arg	Undocumented
         * @return bool	true on success
         *			false otherwise
         */
767
        bool getConfig (const std::string& section, const std::string& name, TokenList& arg) const;
Julien Bonjean's avatar
Julien Bonjean committed
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798

        /**
         * 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
         */
        bool setConfig (const std::string& section, const std::string& name, const std::string& value);

        /**
         * 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
         */
        bool setConfig (const std::string& section, const std::string& name, int value);

        /**
         * Get a int 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 int    The int value
         */

799
        int getConfigInt (const std::string& section, const std::string& name) const;
Julien Bonjean's avatar
Julien Bonjean committed
800
801
802
803
804
805
806
807
808

        /**
           * Get a bool 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 bool    The bool value
           */

809
        bool getConfigBool (const std::string& section, const std::string& name) const;
Julien Bonjean's avatar
Julien Bonjean committed
810
811
812
813
814
815
816
817

        /**
         * 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
         */
818
        std::string getConfigString (const std::string& section, const std::string& name) const;
Julien Bonjean's avatar
Julien Bonjean committed
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835

        /**
         * 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
         */
        void selectAudioDriver (void);

        /**
         * Handle audio sounds heard by a caller while they wait for their
         * connection to a called party to be completed.
         */
        void ringback ();

        /**
         * Handle played music when an incoming call occurs
         */
836
        void ringtone (const std::string& accountID);
Julien Bonjean's avatar
Julien Bonjean committed
837
838
839
840
841
842
843
844
845

        /**
         * Handle played music when a congestion occurs
         */
        void congestion ();

        /**
         * Handle played sound when a call can not be conpleted because of a busy recipient
         */
846
        void callBusy (const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
847
848
849
850

        /**
         * Handle played sound when a failure occurs
         */
851
        void callFailure (const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876

        /**
         * 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
         */
        bool incomingCallWaiting (void);

        /*
         * Inline functions to manage speaker volume control
         * Read by main thread and AudioLayer thread
         * Write by main thread only
         * @return unsigned short	The volume value
         */
877
        unsigned short getSpkrVolume (void) const {
Julien Bonjean's avatar
Julien Bonjean committed
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
            return _spkr_volume;
        }

        /*
         * Inline functions to manage speaker volume control
         * Read by main thread and AudioLayer thread
         * Write by main thread only
         * @param spkr_vol	The volume value
         */
        void setSpkrVolume (unsigned short spkr_vol);

        /*
         * Inline functions to manage mic volume control
         * Read by main thread and AudioLayer thread
         * Write by main thread only
         * @return unsigned short	The volume value
         */
895
        unsigned short getMicVolume (void) const {
Julien Bonjean's avatar
Julien Bonjean committed
896
897
898
899
900
901
902
903
904
905
906
907
908
            return _mic_volume;
        }

        /*
         * Inline functions to manage mic volume control
         * Read by main thread and AudioLayer thread
         * Write by main thread only
         * @param mic_vol	The volume value
         */
        void setMicVolume (unsigned short mic_vol);

        /**
         * Return a new random callid that is not present in the list
909
         * @return std::string A brand new callid
Julien Bonjean's avatar
Julien Bonjean committed
910
         */
911
        std::string getNewCallID();
Julien Bonjean's avatar
Julien Bonjean committed
912
913
914

        /**
         * Get the current call id
915
         * @return std::string	The call id or ""
Julien Bonjean's avatar
Julien Bonjean committed
916
         */
917
        const std::string& getCurrentCallId() const;
Julien Bonjean's avatar
Julien Bonjean committed
918
919
920
921
922
923

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

926
        void initAudioDriver (void);
Julien Bonjean's avatar
Julien Bonjean committed
927

928
929
930
        void audioLayerMutexLock(void) { _audiolayerMutex.enterMutex(); }

        void audioLayerMutexUnlock(void) { _audiolayerMutex.leaveMutex(); }
Julien Bonjean's avatar
Julien Bonjean committed
931

932
933
934
935
936
        /**
         * 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
         */
        std::vector<std::string> loadAccountOrder () const;
Julien Bonjean's avatar
Julien Bonjean committed
937
    private:
938
939
940
941
942
943
944
945
946
947
948
949
950
        /**
         * Play the dtmf-associated sound
         * @param code  The pressed key
         */
        bool playDtmf (char code);

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

Julien Bonjean's avatar
Julien Bonjean committed
952
        /**
953
         * Create config directory in home user and return configuration file path
Julien Bonjean's avatar
Julien Bonjean committed
954
         */
955
        std::string getConfigFile (void) const;
Julien Bonjean's avatar
Julien Bonjean committed
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971


        /*
         * Initialize zeroconf module and scanning
         */
        void initZeroconf (void);

        /*
         * Init the volume for speakers/micro from 0 to 100 value
         */
        void initVolume();

        /**
         * Switch of current call id
         * @param id The new callid
         */
972
        void switchCall (const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
973
974
975
976
977
978
979

        /*
         * Play one tone
         * @return false if the driver is uninitialize
         */
        bool playATone (Tone::TONEID toneId);

980
981
        DBusManager _dbus;

Julien Bonjean's avatar
Julien Bonjean committed
982
983
984
985
        /** The configuration tree. It contains accounts parameters, general user settings ,audio settings, ... */
        Conf::ConfigTree _config;

        /** Current Call ID */
986
        std::string _currentCallId2;
Julien Bonjean's avatar
Julien Bonjean committed
987
988
989
990
991
992
993
994
995
996
997
998

        /** Protected current call access */
        ost::Mutex _currentCallMutex;

        /** Audio layer */
        AudioLayer* _audiodriver;

        // Main thread

        DTMF* _dtmfKey;

        // map of codec (for configlist request)
999
        AudioCodecFactory _audioCodecFactory;
Julien Bonjean's avatar
Julien Bonjean committed
1000