~ubuntu-branches/ubuntu/vivid/sflphone/vivid

« back to all changes in this revision

Viewing changes to daemon/src/managerimpl.h

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2013-06-30 11:40:56 UTC
  • mfrom: (4.1.18 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130630114056-0np50jkyqo6vnmii
Tags: 1.2.3-2
* changeset_r92d62cfc54732bbbcfff2b1d36c096b120b981a5.diff 
  - fixes automatic endian detection 
* Update Vcs: fixes vcs-field-not-canonical

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 *  Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010, 2011 Savoir-Faire Linux Inc.
 
2
 *  Copyright (C) 2004-2012 Savoir-Faire Linux Inc.
3
3
 *  Author: Yan Morin <yan.morin@savoirfairelinux.com>
4
4
 *  Author: Laurielle Lea <laurielle.lea@savoirfairelinux.com>
5
5
 *  Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
18
18
 *
19
19
 *  You should have received a copy of the GNU General Public License
20
20
 *  along with this program; if not, write to the Free Software
21
 
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
21
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
22
22
 *
23
23
 *  Additional permission under GNU GPL version 3 section 7:
24
24
 *
35
35
#ifndef MANAGER_IMPL_H_
36
36
#define MANAGER_IMPL_H_
37
37
 
 
38
#ifdef HAVE_CONFIG_H
 
39
#include "config.h"
 
40
#endif
 
41
 
38
42
#include <string>
39
43
#include <vector>
40
44
#include <set>
41
45
#include <map>
42
46
#include <tr1/memory>
43
 
#include "cc_thread.h"
 
47
 
 
48
#include <pthread.h>
44
49
#include "dbus/dbusmanager.h"
45
50
 
46
51
#include "config/sfl_config.h"
47
52
 
 
53
#include "account.h"
 
54
 
48
55
#include "call.h"
49
56
#include "conference.h"
50
57
 
 
58
#include "audio/audiolayer.h"
51
59
#include "audio/sound/tone.h"  // for Tone::TONEID declaration
52
60
#include "audio/codecs/audiocodecfactory.h"
53
 
 
54
61
#include "audio/mainbuffer.h"
 
62
 
55
63
#include "preferences.h"
56
64
#include "history/history.h"
57
65
#include "noncopyable.h"
74
82
 
75
83
class Account;
76
84
class SIPAccount;
77
 
 
78
 
/** Define a type for a AccountMap container */
79
 
typedef std::map<std::string, Account*> AccountMap;
80
 
 
81
 
/** Define a type for a std::string to std::string Map inside ManagerImpl */
82
 
typedef std::map<std::string, std::string> CallAccountMap;
 
85
class IAXAccount;
83
86
 
84
87
/** To send multiple string */
85
88
typedef std::list<std::string> TokenList;
93
96
class ManagerImpl {
94
97
    public:
95
98
        ManagerImpl();
 
99
        ~ManagerImpl();
96
100
 
97
101
        /**
98
102
         * General preferences configuration
105
109
        VoipPreference voipPreferences;
106
110
 
107
111
        /**
108
 
         * Addressbook related preferences
109
 
         */
110
 
        AddressbookPreference addressbookPreference;
111
 
 
112
 
        /**
113
112
         * Hook preferences
114
113
         */
115
114
        HookPreference hookPreference;
131
130
        void init(const std::string &config_file);
132
131
 
133
132
        /**
134
 
         * Terminate all thread (sound, link) and unload AccountMap
135
 
         */
136
 
        void terminate();
 
133
         * Enter Dbus mainloop
 
134
         */
 
135
        void run();
 
136
 
 
137
        /*
 
138
         * Terminate all threads and exit DBus loop
 
139
         */
 
140
        void finish();
137
141
 
138
142
        /**
139
143
         * Accessor to audiodriver.
144
148
            return audiodriver_;
145
149
        }
146
150
 
 
151
        void startAudioDriverStream();
 
152
 
147
153
        /**
148
154
         * Functions which occur with a user's action
149
155
         * Place a new call
168
174
         * Hangup the call
169
175
         * @param id  The call identifier
170
176
         */
171
 
        void hangupCall(const std::string& id);
 
177
        bool hangupCall(const std::string& id);
172
178
 
173
179
 
174
180
        /**
183
189
         * Put the call on hold
184
190
         * @param id  The call identifier
185
191
         */
186
 
        void onHoldCall(const std::string& id);
 
192
        bool onHoldCall(const std::string& id);
187
193
 
188
194
        /**
189
195
         * Functions which occur with a user's action
190
196
         * Put the call off hold
191
197
         * @param id  The call identifier
192
198
         */
193
 
        void offHoldCall(const std::string& id);
 
199
        bool offHoldCall(const std::string& id);
194
200
 
195
201
        /**
196
202
         * Functions which occur with a user's action
222
228
         * Refuse the call
223
229
         * @param id  The call identifier
224
230
         */
225
 
        void refuseCall(const std::string& id);
 
231
        bool refuseCall(const std::string& id);
226
232
 
227
233
        /**
228
234
         * Create a new conference given two participant
247
253
         * Hold every participant to a conference
248
254
         * @param the conference id
249
255
         */
250
 
        void holdConference(const std::string& conference_id);
 
256
        bool holdConference(const std::string& conference_id);
251
257
 
252
258
        /**
253
259
         * Unhold all conference participants
254
260
         * @param the conference id
255
261
         */
256
 
        void unHoldConference(const std::string& conference_id);
 
262
        bool unHoldConference(const std::string& conference_id);
257
263
 
258
264
        /**
259
265
         * Test if this id is a conference (usefull to test current call)
272
278
         * @param the call id
273
279
         * @param the conference id
274
280
         */
275
 
        void addParticipant(const std::string& call_id, const std::string& conference_id);
 
281
        bool addParticipant(const std::string& call_id, const std::string& conference_id);
276
282
 
277
283
        /**
278
284
         * Bind the main participant to a conference (mainly called on a double click action)
279
285
         * @param the conference id
280
286
         */
281
 
        void addMainParticipant(const std::string& conference_id);
 
287
        bool addMainParticipant(const std::string& conference_id);
282
288
 
283
289
        /**
284
290
         * Join two participants to create a conference
285
291
         * @param the fist call id
286
292
         * @param the second call id
287
293
         */
288
 
        void joinParticipant(const std::string& call_id1, const std::string& call_id2);
 
294
        bool joinParticipant(const std::string& call_id1,
 
295
                             const std::string& call_id2);
289
296
 
290
297
        /**
291
298
         * Create a conference from a list of participant
298
305
         * @param call id
299
306
         * @param the current call id
300
307
         */
301
 
        void detachParticipant(const std::string& call_id, const std::string& current_call_id);
 
308
        bool detachParticipant(const std::string& call_id);
302
309
 
303
310
        /**
304
311
         * Remove the conference participant from a conference
309
316
        /**
310
317
         * Join two conference together into one unique conference
311
318
         */
312
 
        void joinConference(const std::string& conf_id1, const std::string& conf_id2);
 
319
        bool joinConference(const std::string& conf_id1, const std::string& conf_id2);
313
320
 
314
321
        void addStream(const std::string& call_id);
315
322
 
348
355
        void stopTone();
349
356
 
350
357
        /**
351
 
         * When receiving a new incoming call, add it to the callaccount map
352
 
         * and notify user
 
358
         * Handle incoming call and notify user
353
359
         * @param call A call pointer
354
360
         * @param accountId an account id
355
361
         */
375
381
         */
376
382
        void peerHungupCall(const std::string& id);
377
383
 
 
384
#if HAVE_INSTANT_MESSAGING
378
385
        /**
379
386
         * Notify the client with an incoming message
380
387
         * @param accountId     The account identifier
390
397
        * @param from           The sender of this message (could be another participant of a conference)
391
398
         */
392
399
        bool sendTextMessage(const std::string& callID, const std::string& message, const std::string& from);
 
400
#endif // HAVE_INSTANT_MESSAGING
393
401
 
394
402
        /**
395
403
         * Notify the client he has voice mails
408
416
        void sendRegister(const std::string& accountId, bool enable);
409
417
 
410
418
        /**
 
419
         * Register all account in accountMap_
 
420
         */
 
421
        void registerAllAccounts();
 
422
 
 
423
        /**
 
424
         * Unregister all account in accountMap_
 
425
         */
 
426
        void unregisterAllAccounts();
 
427
 
 
428
        /**
411
429
         * Get account list
412
430
         * @return std::vector<std::string> A list of accoundIDs
413
431
         */
489
507
         * @param call id
490
508
         * @return std::string The codec name
491
509
         */
492
 
        std::string getCurrentCodecName(const std::string& id);
 
510
        std::string getCurrentAudioCodecName(const std::string& id);
 
511
        std::string getCurrentVideoCodecName(const std::string& id);
493
512
 
494
513
        /**
495
514
         * Set input audio plugin
502
521
             * @param index The index of the soundcard
503
522
             * @param the type of stream, either SFL_PCM_PLAYBACK, SFL_PCM_CAPTURE, SFL_PCM_RINGTONE
504
523
             */
505
 
        void setAudioDevice(const int index, const int streamType);
 
524
        void setAudioDevice(int index, AudioLayer::PCMType streamType);
506
525
 
507
526
        /**
508
527
         * Get list of supported audio output device
558
577
         */
559
578
        void setEchoCancelState(const std::string &state);
560
579
 
561
 
        int getEchoCancelTailLength() const;
562
 
 
563
 
        void setEchoCancelTailLength(int);
564
 
 
565
 
        int getEchoCancelDelay() const;
566
 
 
567
 
        void setEchoCancelDelay(int);
568
 
 
569
 
        /**
570
 
         * Convert a list of payload in a special format, readable by the server.
571
 
         * Required format: payloads separated with one slash.
572
 
         * @return std::string The serializabled string
573
 
         */
574
 
        static std::string join_string(const std::vector<std::string> &v);
575
 
 
576
 
        static std::vector<std::string> split_string(std::string v);
577
 
 
578
580
        /**
579
581
         * Ringtone option.
580
582
         * If ringtone is enabled, ringtone on incoming call use custom choice. If not, only standart tone.
590
592
        void ringtoneEnabled(const std::string& id);
591
593
 
592
594
        /**
593
 
         * Get the recording path from configuration tree
594
 
         * @return the string correspoding to the path
595
 
         */
596
 
        std::string getRecordPath() const;
597
 
 
598
 
        /**
599
 
         * Set the recoding path in the configuration tree
600
 
         * @param a string reresenting the path
601
 
         */
602
 
        void setRecordPath(const std::string& recPath);
603
 
 
604
 
        /**
605
595
         * Get is always recording functionality
606
596
         */
607
597
        bool getIsAlwaysRecording() const;
630
620
             */
631
621
        bool startRecordedFilePlayback(const std::string&);
632
622
 
 
623
        void recordingPlaybackSeek(const double value);
 
624
 
633
625
        /**
634
626
         * Stop playback of recorded file
635
627
         * @param File of the file to stop
662
654
        void startHidden();
663
655
 
664
656
        /**
665
 
         * Set the desktop mail notification level
666
 
         */
667
 
        void setMailNotify();
668
 
 
669
 
 
670
 
        /**
671
 
         * Addressbook configuration
672
 
         */
673
 
        std::map<std::string, int32_t> getAddressbookSettings() const;
674
 
 
675
 
        /**
676
 
         * Addressbook configuration
677
 
         */
678
 
        void setAddressbookSettings(const std::map<std::string, int32_t>& settings);
679
 
 
680
 
        /**
681
 
         * Addressbook list
682
 
         */
683
 
        void setAddressbookList(const std::vector<  std::string >& list);
684
 
 
685
 
        /**
686
 
         * Addressbook list
687
 
         */
688
 
        std::vector <std::string> getAddressbookList() const;
689
 
 
690
 
        /**
691
657
         * Get the audio manager
692
658
         * @return int The audio manager
693
659
         *                  "alsa"
709
675
        void audioSamplingRateChanged(int);
710
676
 
711
677
        /**
712
 
         * Get the desktop mail notification level
713
 
         * @return int The mail notification level
714
 
         */
715
 
        int32_t getMailNotify() const;
716
 
 
717
 
        /**
718
 
         * Get the list of the active codecs
719
 
         * @return std::vector< ::std::string >  The list of active codecs
720
 
         */
721
 
        std::vector<std::string> getActiveCodecList() const;
722
 
 
723
 
        /**
724
678
         * Change a specific value in the configuration tree.
725
679
         * This value will then be saved in the user config file sflphonedrc
726
680
         * @param section       The section name
823
777
 
824
778
        void initAudioDriver();
825
779
 
826
 
        void audioLayerMutexLock() {
827
 
            audioLayerMutex_.enterMutex();
828
 
        }
829
 
 
830
 
        void audioLayerMutexUnlock() {
831
 
            audioLayerMutex_.leaveMutex();
832
 
        }
833
 
 
834
780
        /**
835
781
         * Load the accounts order set by the user from the sflphonedrc config file
836
782
         * @return std::vector<std::string> A vector containing the account ID's
841
787
        const AudioCodecFactory audioCodecFactory;
842
788
 
843
789
    private:
 
790
 
 
791
        /**
 
792
         * Get the Call referred to by callID. If the Call does not exist, return NULL
 
793
         */
 
794
        Call *getCallFromCallID(const std::string &callID);
 
795
 
844
796
        /**
845
797
         * Play the dtmf-associated sound
846
798
         * @param code  The pressed key
853
805
         * @param current call id
854
806
         * @param conference pointer
855
807
         */
856
 
        void processRemainingParticipants(const std::string &current_call_id, Conference * &conf);
 
808
        void processRemainingParticipants(Conference &conf);
857
809
 
858
810
        /**
859
811
         * Create config directory in home user and return configuration file path
866
818
        void initZeroconf();
867
819
 
868
820
        /**
 
821
         * Set current call ID to empty string
 
822
         */
 
823
        void unsetCurrentCall();
 
824
 
 
825
        /**
869
826
         * Switch of current call id
870
827
         * @param id The new callid
871
828
         */
886
843
        std::string currentCallId_;
887
844
 
888
845
        /** Protected current call access */
889
 
        ost::Mutex currentCallMutex_;
 
846
        pthread_mutex_t currentCallMutex_;
890
847
 
891
848
        /** Audio layer */
892
849
        AudioLayer* audiodriver_;
897
854
        /////////////////////
898
855
        // Protected by Mutex
899
856
        /////////////////////
900
 
        ost::Mutex toneMutex_;
 
857
        pthread_mutex_t toneMutex_;
901
858
        std::tr1::shared_ptr<TelephoneTone> telephoneTone_;
902
859
        std::tr1::shared_ptr<AudioFile> audiofile_;
903
860
 
909
866
        /**
910
867
         * Mutex used to protect audio layer
911
868
         */
912
 
        ost::Mutex audioLayerMutex_;
 
869
        pthread_mutex_t audioLayerMutex_;
913
870
 
914
871
        /**
915
872
         * Waiting Call Vectors
919
876
        /**
920
877
         * Protect waiting call list, access by many voip/audio threads
921
878
         */
922
 
        ost::Mutex waitingCallMutex_;
 
879
        pthread_mutex_t waitingCallMutex_;
923
880
 
924
881
        /**
925
882
         * Number of waiting call, synchronize with waitingcall callidvector
955
912
        DNSService *DNSService_;
956
913
#endif
957
914
 
958
 
        /** Map to associate a CallID to the good account */
959
 
        CallAccountMap callAccountMap_;
960
 
 
961
 
        /** Mutex to lock the call account map (main thread + voiplink thread) */
962
 
        ost::Mutex callAccountMapMutex_;
963
 
 
964
915
        std::map<std::string, bool> IPToIPMap_;
965
916
 
966
 
 
967
917
        bool isIPToIP(const std::string& callID) const;
968
918
 
969
919
        /**
970
 
         *Contains a list of account (sip, aix, etc) and their respective voiplink/calls */
971
 
        AccountMap accountMap_;
972
 
 
973
 
        /**
974
 
         * Unregister all account in accountMap_
975
 
         */
976
 
        void unregisterAllAccounts();
977
 
 
978
 
        /**
979
920
         * Load the account map from configuration
980
921
         */
981
 
        void loadAccountMap(Conf::YamlParser &parser);
 
922
        int loadAccountMap(Conf::YamlParser &parser);
982
923
        /**
983
924
         * Load default account map (no configuration)
984
925
         */
985
926
        void loadDefaultAccountMap();
986
927
 
987
928
        /**
988
 
         * Unload the account (delete them)
989
 
         */
990
 
        void unloadAccountMap();
991
 
 
992
 
        /**
993
929
         * Instance of the MainBuffer for the whole application
994
930
         *
995
931
         * In order to send signal to other parts of the application, one must pass through the mainbuffer.
1002
938
 
1003
939
        void setIPToIPForCall(const std::string& callID, bool IPToIP);
1004
940
 
1005
 
        /** Associate a new std::string to a std::string
1006
 
         * Protected by mutex
1007
 
         * @param callID the new CallID not in the list yet
1008
 
         * @param accountID the known accountID present in accountMap
1009
 
         * @return bool True if the new association is create
1010
 
         */
1011
 
        void associateCallToAccount(const std::string& callID, const std::string& accountID);
1012
 
 
1013
941
        /**
1014
942
         * Test if call is a valid call, i.e. have been created and stored in
1015
943
         * call-account map
1021
949
        /**
1022
950
         * Return a pointer to the  instance of the mainbuffer
1023
951
         */
1024
 
        MainBuffer *getMainBuffer() {
1025
 
            return &mainBuffer_;
 
952
        MainBuffer &getMainBuffer() {
 
953
            return mainBuffer_;
1026
954
        }
1027
955
 
1028
956
        /**
1039
967
            return &dbus_;
1040
968
        }
1041
969
 
 
970
#ifdef SFL_VIDEO
 
971
        VideoControls * getVideoControls() {
 
972
            return dbus_.getVideoControls();
 
973
        }
 
974
#endif
 
975
 
1042
976
        /**
1043
977
        * Tell if an account exists
1044
978
        * @param accountID account ID check
1047
981
        */
1048
982
        bool accountExists(const std::string& accountID);
1049
983
 
1050
 
        std::vector<std::map<std::string, std::string> > getHistory() const;
 
984
        std::vector<std::map<std::string, std::string> > getHistory();
1051
985
        void clearHistory();
1052
986
 
1053
987
        /**
1054
 
         * Get an account pointer
 
988
         * Get an account pointer, looks for both SIP and IAX
1055
989
         * @param accountID account ID to get
1056
990
         * @return Account*      The account pointer or 0
1057
991
         */
1058
 
        Account* getAccount(const std::string& accountID);
1059
 
        SIPAccount* getIP2IPAccount();
 
992
        Account* getAccount(const std::string& accountID) const;
 
993
 
 
994
        /**
 
995
         * Get a SIP account pointer
 
996
         * @param accountID account ID to get
 
997
         * @return SIPAccount* The account pointer or 0
 
998
         */
 
999
        SIPAccount *getSipAccount(const std::string& accontID) const;
 
1000
 
 
1001
#if HAVE_IAX
 
1002
        /**
 
1003
         * Get an IAX account pointer
 
1004
         * @param accountID account ID to get
 
1005
         * @return IAXAccount* The account pointer or 0
 
1006
         */
 
1007
        IAXAccount *getIaxAccount(const std::string& accountID) const;
 
1008
#endif
 
1009
 
 
1010
        /**
 
1011
         * Get a pointer to the IP2IP account
 
1012
         * @return SIPAccount * Pointer to the IP2IP account
 
1013
         */
 
1014
        SIPAccount *getIP2IPAccount() const;
1060
1015
 
1061
1016
        /** Return the std::string from a CallID
1062
1017
         * Protected by mutex
1070
1025
         * @param accountID       Account ID to get
1071
1026
         * @return VoIPLink*   The voip link from the account pointer or 0
1072
1027
         */
1073
 
        VoIPLink* getAccountLink(const std::string& accountID="");
1074
 
 
1075
 
        std::string getAccountIdFromNameAndServer(const std::string& userName, const std::string& server) const;
 
1028
        VoIPLink* getAccountLink(const std::string& accountID);
1076
1029
 
1077
1030
        std::string getStunServer() const;
1078
1031
        void setStunServer(const std::string &server);
1093
1046
        NON_COPYABLE(ManagerImpl);
1094
1047
 
1095
1048
        /**
 
1049
         * Get a map with all the current SIP and IAX accounts
 
1050
         */
 
1051
        AccountMap getAllAccounts() const;
 
1052
 
 
1053
        void
 
1054
        checkAudio();
 
1055
 
 
1056
        /**
1096
1057
          * To handle the persistent history
1097
1058
          * TODO: move this to ConfigurationManager
1098
1059
          */
1099
 
        History history_;
 
1060
        sfl::History history_;
 
1061
        bool finished_;
1100
1062
};
1101
1063
#endif // MANAGER_IMPL_H_