managerimpl.h 36.9 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
namespace sfl {
57
class InstantMessaging;
58
}
59

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

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;

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

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

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


        /**
         * 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
         */
135
        void init(std::string config_file="");
Julien Bonjean's avatar
Julien Bonjean committed
136
137
138
139

        /**
         * Terminate all thread (sound, link) and unload AccountMap
         */
140
        void terminate();
Julien Bonjean's avatar
Julien Bonjean committed
141
142
143
144
145
146

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

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

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

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


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

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

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

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

207
208
209
210
211
        /**
         * Attended transfer
         * @param The call id to be transfered
         * @param The target
         */
212
        bool attendedTransfer(const std::string& transferID, const std::string& targetID);
213

Julien Bonjean's avatar
Julien Bonjean committed
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
        /**
         * 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
         */
229
        void refuseCall(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
230
231
232
233
234
235

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

        /**
         * Delete this conference
         * @param the conference ID
         */
242
        void removeConference(const std::string& conference_id);
Julien Bonjean's avatar
Julien Bonjean committed
243
244
245
246
247

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

        /**
         * Hold every participant to a conference
         * @param the conference id
         */
254
        void holdConference(const std::string& conference_id);
Julien Bonjean's avatar
Julien Bonjean committed
255
256
257
258
259

        /**
         * Unhold all conference participants
         * @param the conference id
         */
260
        void unHoldConference(const std::string& conference_id);
Julien Bonjean's avatar
Julien Bonjean committed
261
262
263
264
265

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

        /**
         * Test if a call id particips to this conference
         * @param the call id
         */
272
        bool participToConference(const std::string& call_id);
Julien Bonjean's avatar
Julien Bonjean committed
273
274
275
276
277
278

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

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

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

294
295
296
297
298
        /**
         * Create a conference from a list of participant
         * @param A vector containing the list of participant
         */
        void createConfFromParticipantList(const std::vector< std::string > &);
299

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

        /**
         * Remove the conference participant from a conference
         * @param call id
         */
311
        void removeParticipant(const std::string& call_id);
Julien Bonjean's avatar
Julien Bonjean committed
312
313
314
315

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

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

320
        void removeStream(const std::string& call_id);
Julien Bonjean's avatar
Julien Bonjean committed
321
322
323
324

        /**
         * Save config to file
         */
325
        void saveConfig();
Julien Bonjean's avatar
Julien Bonjean committed
326
327
328
329

        /**
         * @return true if we tried to register once
         */
330
        bool hasTriedToRegister_;
Julien Bonjean's avatar
Julien Bonjean committed
331
332
333
334
335
336

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

        /**
         * Play a ringtone
         */
342
        void playTone();
Julien Bonjean's avatar
Julien Bonjean committed
343
344
345
346

        /**
         * Play a special ringtone ( BUSY ) if there's at least one message on the voice mail
         */
347
        void playToneWithMessage();
Julien Bonjean's avatar
Julien Bonjean committed
348
349
350
351

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

        /**
         * 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
         */
360
        void incomingCall(Call* call, const std::string& accountId);
Julien Bonjean's avatar
Julien Bonjean committed
361
362
363
364
365
366

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

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

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

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

389
390

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

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

        /**
         * Notify the client through DBus that registration state has been updated
         */
408
        void connectionStatusNotification();
Julien Bonjean's avatar
Julien Bonjean committed
409
410
411
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
         *		 0 for unregistration request
         *		 1 for registration request
         */
417
        void sendRegister(const ::std::string& accountId , const int32_t& enable);
Julien Bonjean's avatar
Julien Bonjean committed
418
419
420
421
422

        /**
         * Get account list
         * @return std::vector<std::string> A list of accoundIDs
         */
423
        std::vector<std::string> getAccountList() const;
Julien Bonjean's avatar
Julien Bonjean committed
424
425
426
427

        /**
         * Set the account order in the config file
         */
428
        void setAccountsOrder(const std::string& order);
Julien Bonjean's avatar
Julien Bonjean committed
429
430
431
432
433
434

        /**
         * Retrieve details about a given account
         * @param accountID	  The account identifier
         * @return std::map< std::string, std::string > The account details
         */
435
        std::map<std::string, std::string> getAccountDetails(const std::string& accountID) const;
Julien Bonjean's avatar
Julien Bonjean committed
436
437
438
439
440
441

        /**
         * Retrieve details about a given call
         * @param callID	  The account identifier
         * @return std::map< std::string, std::string > The call details
         */
442
        std::map<std::string, std::string> getCallDetails(const std::string& callID);
Julien Bonjean's avatar
Julien Bonjean committed
443
444
445
446
447

        /**
         * Get call list
         * @return std::vector<std::string> A list of call IDs
         */
448
        std::vector<std::string> getCallList() 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> getConferenceDetails(const std::string& callID) const;
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> getConferenceList() const;
Julien Bonjean's avatar
Julien Bonjean committed
462
463
464
465
466
467


        /**
         * Get a list of participant to a conference
         * @return std::vector<std::string> A list of call IDs
         */
468
        std::vector<std::string> getParticipantList(const std::string& confID) const;
Julien Bonjean's avatar
Julien Bonjean committed
469
470
471
472
473
474
475
476

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

        /**
         * 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
         */
485
        std::string addAccount(const std::map<std::string, std::string> &details);
Julien Bonjean's avatar
Julien Bonjean committed
486
487
488
489
490
491

        /**
         * Delete an existing account, unregister VoIPLink associated, and
         * purge from configuration.
         * @param accountID	The account unique ID
         */
492
        void removeAccount(const std::string& accountID);
Julien Bonjean's avatar
Julien Bonjean committed
493
494
495
496
497
498

        /**
         * Get current codec name
         * @param call id
         * @return std::string The codec name
         */
499
        std::string getCurrentCodecName(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
500
501
502
503
504

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

        /**
508
509
510
511
             * 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
             */
512
        void setAudioDevice(const int index, const int streamType);
Julien Bonjean's avatar
Julien Bonjean committed
513
514
515
516
517

        /**
         * Get list of supported audio output device
         * @return std::vector<std::string> A list of the audio devices supporting playback
         */
518
        std::vector<std::string> getAudioOutputDeviceList();
Julien Bonjean's avatar
Julien Bonjean committed
519
520
521
522
523

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

        /**
527
         * Get string array representing integer indexes of output, input, and ringtone device
Julien Bonjean's avatar
Julien Bonjean committed
528
529
530
531
532
533
534
535
536
         * @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
         */
537
        int getAudioDeviceIndex(const std::string &name);
Julien Bonjean's avatar
Julien Bonjean committed
538
539
540
541
542

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

545
546
547
548
        /**
         * Get the noise reduction engin state from
         * the current audio layer.
         */
549
        std::string getNoiseSuppressState() const;
Julien Bonjean's avatar
Julien Bonjean committed
550

551
552
553
554
        /**
         * Set the noise reduction engin state in the current
         * audio layer.
         */
555
        void setNoiseSuppressState(const std::string &state);
Julien Bonjean's avatar
Julien Bonjean committed
556

557
558
559
560
        /**
         * Get the echo canceller engin state from
         * the current audio layer
         */
561
        bool getEchoCancelState() const;
562
563
564
565

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

568
        int getEchoCancelTailLength() const;
569
570
571

        void setEchoCancelTailLength(int);

572
        int getEchoCancelDelay() const;
573
574
575

        void setEchoCancelDelay(int);

Julien Bonjean's avatar
Julien Bonjean committed
576
577
578
579
580
        /**
         * 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
         */
581
        static std::string serialize(const std::vector<std::string> &v);
Julien Bonjean's avatar
Julien Bonjean committed
582

583
        static std::vector<std::string> unserialize(std::string v);
Julien Bonjean's avatar
Julien Bonjean committed
584
585
586
587
588
589
590

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

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

        /**
         * Get the recording path from configuration tree
         * @return the string correspoding to the path
         */
603
        std::string getRecordPath() const;
Julien Bonjean's avatar
Julien Bonjean committed
604
605
606
607
608

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

611
612
613
        /**
         * Get is always recording functionality
         */
614
        bool getIsAlwaysRecording() const;
615
616
617
618
619
620
621

        /**
         * 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
622
623
624
625
626
        /**
         * Set recording on / off
         * Start recording
         * @param id  The call identifier
         */
627
        void setRecordingCall(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
628
629
630
631

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

634
635
636
637
        /**
         * Start playback fo a recorded file if and only if audio layer is not already started.
         * @param File path of the file to play
             */
638
        bool startRecordedFilePlayback(const std::string&);
639

640
641
642
643
        /**
         * Stop playback of recorded file
         * @param File of the file to stop
         */
644
645
        void stopRecordedFilePlayback(const std::string&);

Julien Bonjean's avatar
Julien Bonjean committed
646
647
648
649
        /**
         * Set the maximum number of days to keep in the history
         * @param calls The number of days
         */
650
        void setHistoryLimit(int days);
Julien Bonjean's avatar
Julien Bonjean committed
651
652
653
654
655

        /**
         * Get the maximum number of days to keep in the history
         * @return double The number of days
         */
656
        int getHistoryLimit() const;
Julien Bonjean's avatar
Julien Bonjean committed
657
658
659
660
661
662

        /**
         * Configure the start-up option
         * @return int	1 if SFLphone should start in the system tray
         *	        0 otherwise
         */
663
        int isStartHidden();
Julien Bonjean's avatar
Julien Bonjean committed
664
665
666
667
668

        /**
         * Configure the start-up option
         * At startup, SFLphone can be displayed or start hidden in the system tray
         */
669
        void startHidden();
Julien Bonjean's avatar
Julien Bonjean committed
670
671
672
673

        /**
         * Set the desktop mail notification level
         */
674
        void setMailNotify();
Julien Bonjean's avatar
Julien Bonjean committed
675
676
677
678
679


        /**
         * Addressbook configuration
         */
680
        std::map<std::string, int32_t> getAddressbookSettings() const;
Julien Bonjean's avatar
Julien Bonjean committed
681
682
683
684

        /**
         * Addressbook configuration
         */
685
        void setAddressbookSettings(const std::map<std::string, int32_t>& settings);
Julien Bonjean's avatar
Julien Bonjean committed
686
687
688
689

        /**
         * Addressbook list
         */
690
        void setAddressbookList(const std::vector<  std::string >& list);
Julien Bonjean's avatar
Julien Bonjean committed
691
692
693
694

        /**
         * Addressbook list
         */
695
        std::vector <std::string> getAddressbookList() const;
Julien Bonjean's avatar
Julien Bonjean committed
696
697
698
699

        /**
         * Hook configuration
         */
700
        std::map<std::string, std::string> getHookSettings() const;
Julien Bonjean's avatar
Julien Bonjean committed
701
702
703
704

        /**
         * Hook configuration
         */
705
        void setHookSettings(const std::map<std::string, std::string>& settings);
Julien Bonjean's avatar
Julien Bonjean committed
706
707
708
709
710


        /**
         * Get the audio manager
         * @return int The audio manager
711
712
         *		    "alsa"
         *		    "pulseaudio"
Julien Bonjean's avatar
Julien Bonjean committed
713
         */
714
        std::string getAudioManager() const;
Julien Bonjean's avatar
Julien Bonjean committed
715
716
717
718

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

721
        void switchAudioManager();
Julien Bonjean's avatar
Julien Bonjean committed
722

723
724
725
726
        /**
         * Set the internal audio sampling rate change. Should close the audio layer and
         * reopen stream at different rate,
         */
727
        void audioSamplingRateChanged(int);
Julien Bonjean's avatar
Julien Bonjean committed
728
729
730
731
732

        /**
         * Get the desktop mail notification level
         * @return int The mail notification level
         */
733
        int32_t getMailNotify(void) const;
Julien Bonjean's avatar
Julien Bonjean committed
734
735
736
737
738

        /**
         * Get the list of the active codecs
         * @return std::vector< ::std::string >  The list of active codecs
         */
739
        std::vector<std::string> getActiveCodecList(void) const;
Julien Bonjean's avatar
Julien Bonjean committed
740
741
742
743
744
745
746
747
748

        /**
         * 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
         */
749
        bool getConfig(const std::string& section, const std::string& name, TokenList& arg) const;
Julien Bonjean's avatar
Julien Bonjean committed
750
751
752
753
754
755
756
757
758
759

        /**
         * 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
         */
760
        bool setConfig(const std::string& section, const std::string& name, const std::string& value);
Julien Bonjean's avatar
Julien Bonjean committed
761
762
763
764
765
766
767
768
769
770

        /**
         * 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
         */
771
        bool setConfig(const std::string& section, const std::string& name, int value);
Julien Bonjean's avatar
Julien Bonjean committed
772
773
774
775
776
777
778
779
780

        /**
         * 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
         */

781
        int getConfigInt(const std::string& section, const std::string& name) const;
Julien Bonjean's avatar
Julien Bonjean committed
782
783
784
785
786
787
788
789
790

        /**
           * 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
           */

791
        bool getConfigBool(const std::string& section, const std::string& name) const;
Julien Bonjean's avatar
Julien Bonjean committed
792
793
794
795
796
797
798
799

        /**
         * 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
         */
800
        std::string getConfigString(const std::string& section, const std::string& name) const;
Julien Bonjean's avatar
Julien Bonjean committed
801
802
803
804
805
806

        /**
         * 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
         */
807
        void selectAudioDriver();
Julien Bonjean's avatar
Julien Bonjean committed
808
809
810
811
812

        /**
         * Handle audio sounds heard by a caller while they wait for their
         * connection to a called party to be completed.
         */
813
        void ringback();
Julien Bonjean's avatar
Julien Bonjean committed
814
815
816
817

        /**
         * Handle played music when an incoming call occurs
         */
818
        void ringtone(const std::string& accountID);
Julien Bonjean's avatar
Julien Bonjean committed
819
820
821
822

        /**
         * Handle played music when a congestion occurs
         */
823
        void congestion();
Julien Bonjean's avatar
Julien Bonjean committed
824
825
826
827

        /**
         * Handle played sound when a call can not be conpleted because of a busy recipient
         */
828
        void callBusy(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
829
830
831
832

        /**
         * Handle played sound when a failure occurs
         */
833
        void callFailure(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850

        /**
         * 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
         */
851
        bool incomingCallWaiting();
Julien Bonjean's avatar
Julien Bonjean committed
852
853
854
855
856
857
858

        /*
         * 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
         */
859
860
        unsigned short getSpkrVolume() const {
            return speakerVolume_;
Julien Bonjean's avatar
Julien Bonjean committed
861
862
863
864
865
866
867
868
        }

        /*
         * 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
         */
869
        void setSpkrVolume(unsigned short spkr_vol);
Julien Bonjean's avatar
Julien Bonjean committed
870
871
872
873
874
875
876

        /*
         * 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
         */
877
878
        unsigned short getMicVolume() const {
            return micVolume_;
Julien Bonjean's avatar
Julien Bonjean committed
879
880
881
882
883
884
885
886
        }

        /*
         * 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
         */
887
        void setMicVolume(unsigned short mic_vol);
Julien Bonjean's avatar
Julien Bonjean committed
888
889
890

        /**
         * Return a new random callid that is not present in the list
891
         * @return std::string A brand new callid
Julien Bonjean's avatar
Julien Bonjean committed
892
         */
893
        std::string getNewCallID();
Julien Bonjean's avatar
Julien Bonjean committed
894
895
896

        /**
         * Get the current call id
897
         * @return std::string	The call id or ""
Julien Bonjean's avatar
Julien Bonjean committed
898
         */
899
        std::string getCurrentCallId() const;
Julien Bonjean's avatar
Julien Bonjean committed
900
901
902
903
904
905

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

908
        void initAudioDriver();
Julien Bonjean's avatar
Julien Bonjean committed
909

910
911
        void audioLayerMutexLock() {
            audiolayerMutex_.enterMutex();
912
        }
913

914
915
        void audioLayerMutexUnlock() {
            audiolayerMutex_.leaveMutex();
916
        }
Julien Bonjean's avatar
Julien Bonjean committed
917

918
919
920
921
        /**
         * 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
         */
922
        std::vector<std::string> loadAccountOrder() const;
923
924
925
926

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

Julien Bonjean's avatar
Julien Bonjean committed
927
    private:
928
929
930
931
        /**
         * Play the dtmf-associated sound
         * @param code  The pressed key
         */
932
        void playDtmf(char code);
933
934
935
936
937
938
939

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

Julien Bonjean's avatar
Julien Bonjean committed
942
        /**
943
         * Create config directory in home user and return configuration file path
Julien Bonjean's avatar
Julien Bonjean committed
944
         */
945
        std::string getConfigFile() const;
Julien Bonjean's avatar
Julien Bonjean committed
946
947
948
949
950


        /*
         * Initialize zeroconf module and scanning
         */
951
        void initZeroconf();
Julien Bonjean's avatar
Julien Bonjean committed
952
953
954
955
956
957
958
959
960
961

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

        /**
         * Switch of current call id
         * @param id The new callid
         */
962
        void switchCall(const std::string& id);
Julien Bonjean's avatar
Julien Bonjean committed
963
964
965
966
967

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

970
        DBusManager dbus_;
971

Julien Bonjean's avatar
Julien Bonjean committed
972
        /** The configuration tree. It contains accounts parameters, general user settings ,audio settings, ... */
973
        Conf::ConfigTree config_;
Julien Bonjean's avatar
Julien Bonjean committed
974
975

        /** Current Call ID */
976
        std::string currentCallId_;
Julien Bonjean's avatar
Julien Bonjean committed
977
978

        /** Protected current call access */
979
        ost::Mutex currentCallMutex_;
Julien Bonjean's avatar
Julien Bonjean committed
980
981

        /** Audio layer */
982
        AudioLayer* audiodriver_;
Julien Bonjean's avatar
Julien Bonjean committed
983
984
985

        // Main thread

986
        DTMF* dtmfKey_;
Julien Bonjean's avatar
Julien Bonjean committed
987
988
989
990

        /////////////////////
        // Protected by Mutex
        /////////////////////
991
992
993
        ost::Mutex toneMutex_;
        TelephoneTone* telephoneTone_;
        AudioFile *audiofile_;
Julien Bonjean's avatar
Julien Bonjean committed
994
995

        // To handle volume control
996
997
        short speakerVolume_;
        short micVolume_;
Julien Bonjean's avatar
Julien Bonjean committed
998
999
        // End of sound variable

1000
        /**
For faster browsing, not all history is shown. View entire blame