managerimpl.h 19.7 KB
Newer Older
jpbl's avatar
jpbl committed
1
2
3
4
/*
 *  Copyright (C) 2004-2005 Savoir-Faire Linux inc.
 *  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>
jpbl's avatar
jpbl committed
7
8
9
 *
 *  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
10
 *  the Free Software Foundation; either version 3 of the License, or
jpbl's avatar
jpbl committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 *  (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.
 */

#ifndef __MANAGER_H__
#define __MANAGER_H__

yanmorin's avatar
   
yanmorin committed
26
27
//#define TEST

jpbl's avatar
jpbl committed
28
29
#include <string>
#include <vector>
yanmorin's avatar
   
yanmorin committed
30
#include <set>
yanmorin's avatar
   
yanmorin committed
31
#include <map>
jpbl's avatar
jpbl committed
32
#include <cc++/thread.h>
33
#include "dbus/dbusmanager.h"
jpbl's avatar
jpbl committed
34
35
36
37

#include "stund/stun.h"
#include "observer.h"
#include "config/config.h"
yanmorin's avatar
   
yanmorin committed
38

yanmorin's avatar
   
yanmorin committed
39
#include "account.h"
yanmorin's avatar
   
yanmorin committed
40
#include "call.h"
jpbl's avatar
jpbl committed
41
42
43
44
45
46

#include "audio/tonelist.h" // for Tone::TONEID declaration
#include "audio/audiofile.h"
#include "audio/dtmf.h"
#include "audio/codecDescriptor.h"

47

48

jpbl's avatar
jpbl committed
49
50
51
52
53
class AudioLayer;
class CodecDescriptor;
class GuiFramework;
class TelephoneTone;
class VoIPLink;
yanmorin's avatar
   
yanmorin committed
54

jpbl's avatar
jpbl committed
55
56
57
58
#ifdef USE_ZEROCONF
class DNSService;
#endif

yanmorin's avatar
   
yanmorin committed
59
60
/**
 * Define a type for a AccountMap container
jpbl's avatar
jpbl committed
61
 */
yanmorin's avatar
   
yanmorin committed
62
63
typedef std::map<AccountID, Account*> AccountMap;
 
yanmorin's avatar
   
yanmorin committed
64
65
66
/**
 * Define a type for a CallID to AccountID Map inside ManagerImpl
 */
yanmorin's avatar
   
yanmorin committed
67
typedef std::map<CallID, AccountID> CallAccountMap;
yanmorin's avatar
   
yanmorin committed
68
69

/**
yanmorin's avatar
   
yanmorin committed
70
 * Define a type for CallID vector (waiting list, incoming not answered)
yanmorin's avatar
   
yanmorin committed
71
 */
yanmorin's avatar
   
yanmorin committed
72
73
typedef std::set<CallID> CallIDSet;

jpbl's avatar
jpbl committed
74
75
76
77
78
/**
 * To send multiple string
 */
typedef std::list<std::string> TokenList;

yanmorin's avatar
   
yanmorin committed
79
80
81
/**
 * Manager (controller) of sflphone daemon
 */
jpbl's avatar
jpbl committed
82
83
84
85
86
class ManagerImpl {
public:
  ManagerImpl (void);
  ~ManagerImpl (void);

yanmorin's avatar
   
yanmorin committed
87
  /**
88
89
90
   * Initialisation of thread (sound) and map.
   *
   * Init a new VoIPLink, audio codec and audio driver
yanmorin's avatar
   
yanmorin committed
91
   */
jpbl's avatar
jpbl committed
92
  void init (void);
yanmorin's avatar
   
yanmorin committed
93
94

  /**
95
   * Terminate all thread (sound, link) and unload AccountMap
yanmorin's avatar
   
yanmorin committed
96
   */
jpbl's avatar
jpbl committed
97
98
  void terminate (void);

yanmorin's avatar
   
yanmorin committed
99
  /**
100
101
   * Set user interface manaager.
   * @param man The DBUS interface implementation
yanmorin's avatar
   
yanmorin committed
102
   */
103
  void setDBusManager (DBusManagerImpl* man) { _dbus = man; }
jpbl's avatar
jpbl committed
104

105
106
107
108
109
  /**
   * Accessor to audiodriver.
   *
   * it's multi-thread and use mutex internally
   */
110
  AudioLayer* getAudioDriver(void) const { return _audiodriver; }
jpbl's avatar
jpbl committed
111

yanmorin's avatar
   
yanmorin committed
112
113
114
  /**
   * Get a descriptor map of codec available
   */
115
  CodecDescriptor& getCodecDescriptorMap(void) {return _codecDescriptorMap;}
jpbl's avatar
jpbl committed
116

yanmorin's avatar
   
yanmorin committed
117
  /**
jpbl's avatar
jpbl committed
118
119
   * Functions which occur with a user's action
   */
yanmorin's avatar
   
yanmorin committed
120
121
122
123
124
125
126
  bool outgoingCall(const AccountID& accountId, const CallID& id, const std::string& to);
  bool answerCall(const CallID& id);
  bool hangupCall(const CallID& id);
  bool cancelCall(const CallID& id);
  bool onHoldCall(const CallID& id);
  bool offHoldCall(const CallID& id);
  bool transferCall(const CallID& id, const std::string& to);
jpbl's avatar
jpbl committed
127
128
  void mute();
  void unmute();
yanmorin's avatar
   
yanmorin committed
129
  bool refuseCall(const CallID& id);
jpbl's avatar
jpbl committed
130

131
  /** Save config to file */
jpbl's avatar
jpbl committed
132
  bool saveConfig (void);
133

yanmorin's avatar
   
yanmorin committed
134
  /**
135
136
137
138
139
140
141
   * Send registration information (shake hands) for a specific AccountID
   *
   * @param accountId Account to register
   * @return true if sendRegister was called without failure, else return false
   */
  bool registerAccount(const AccountID& accountId);

yanmorin's avatar
   
yanmorin committed
142
  /**
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
   * Send unregistration for a specific account. If the protocol
   * doesn't need to send anything, then the state of the account
   * will be set to 'Unregistered', and related objects destroyed.
   *
   * @param accountId Account to unregister
   * @return true if the unregister method is send correctly
   */
  bool unregisterAccount(const AccountID& accountId);

  /**
   * Send registration to all enabled accounts
   * 
   * @return false if exosip or the network checking fails
   */
  bool initRegisterAccounts();

  /**
   * True if we tried to register Once
   */
  bool _hasTriedToRegister;

jpbl's avatar
jpbl committed
164

165
166
167
  /**
   * Undocumented
   */
yanmorin's avatar
   
yanmorin committed
168
  bool sendTextMessage(const AccountID& accountId, const std::string& to, const std::string& message);
jpbl's avatar
jpbl committed
169
	
yanmorin's avatar
   
yanmorin committed
170
  /*
jpbl's avatar
jpbl committed
171
172
173
174
175
   * Handle choice of the DTMF-send-way
   *
   * @param   id: callid of the line.
   * @param   code: pressed key.
   */
yanmorin's avatar
   
yanmorin committed
176
  bool sendDtmf(const CallID& id, char code);
Emmanuel Milou's avatar
Emmanuel Milou committed
177
  bool playDtmf(char code, bool isTalking);
jpbl's avatar
jpbl committed
178
  bool playTone ();
179
  bool playToneWithMessage ();
180
  void stopTone(bool stopAudio/*=true*/);
yanmorin's avatar
   
yanmorin committed
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199

  // From links
  /**
   * 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 true if the call was added correctly
   */
  bool incomingCall(Call* call, const AccountID& accountId);
  void peerAnsweredCall(const CallID& id);
  void peerRingingCall(const CallID& id);
  void peerHungupCall(const CallID& id);
  void incomingMessage(const AccountID& accountId, const std::string& message);

  void displayTextMessage (const CallID& id, const std::string& message);
  void displayErrorText (const CallID& id, const std::string& message);
  void displayError(const std::string& error);
  void displayStatus(const std::string& status);
jpbl's avatar
jpbl committed
200
201
  void displayConfigError(const std::string& message);

yanmorin's avatar
   
yanmorin committed
202
203
  void startVoiceMessageNotification(const AccountID& accountId, const std::string& nb_msg);
  void stopVoiceMessageNotification(const AccountID& accountId);
jpbl's avatar
jpbl committed
204

yanmorin's avatar
   
yanmorin committed
205
206
  /** Notify the user that registration succeeded  */
  void registrationSucceed(const AccountID& accountId);
207
208
209
  /** Notify the user that unregistration succeeded  */
  void unregistrationSucceed(const AccountID& accountId);
  /** Notify the user that registration failed  */
yanmorin's avatar
   
yanmorin committed
210
  void registrationFailed(const AccountID& accountId);
Emmanuel Milou's avatar
nothing    
Emmanuel Milou committed
211
212
  /** Notify the user that registration is trying  */
  void registrationTrying(const AccountID& accountId);
213
  void sendRegister( const AccountID& accountId , bool expire );
jpbl's avatar
jpbl committed
214
  // configuration function requests
215
216
217
218
219
220
221
222

  /**
   * Start events thread. This function actually only calls the private
   * initRegisterVoIPLink().
   *
   * This function should definitively be renamed!
   *
   * @todo Receive account name (???)
223
224
   *
   * DEPRECATED
225
   */
226
  //bool getEvents();
yanmorin's avatar
   
yanmorin committed
227
228

  //
jpbl's avatar
jpbl committed
229
230
231
232
  bool getZeroconf(const std::string& sequenceId);
  bool attachZeroconfEvents(const std::string& sequenceId, Pattern::Observer& observer);
  bool detachZeroconfEvents(Pattern::Observer& observer);
  bool getCallStatus(const std::string& sequenceId);
233

234
  /** 
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
235
236
   * Get account list 
   * @return A list of accoundIDs
237
   */
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
238
  std::vector< std::string >  getAccountList();
239
240
241
242

  /**
   * Retrieve details about a given account
   */
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
243
  std::map< std::string, std::string > getAccountDetails(const AccountID& accountID);
244
245
246

  /**
   * Save the details of an existing account, given the account ID
247
248
249
   *
   * This will load the configuration map with the given data.
   * It will also register/unregister links where the 'Enabled' switched.
250
   */
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
251
252
  void setAccountDetails( const ::DBus::String& accountID, 
                   const std::map< ::DBus::String, ::DBus::String >& details );
253
254
255
256
257
258
259
260
261
262

  /**
   * Add a new account, and give it a new account ID automatically
   */
  void addAccount(const std::map< ::DBus::String, ::DBus::String >& details);

  /**
   * Delete an existing account, unregister VoIPLink associated, and
   * purge from configuration.
   */
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
263
  void removeAccount(const AccountID& accountID);
264
265
  
  /*
266
267
   * Get the default account
   * @return The default account
268
269
   */
  std::string getDefaultAccount();
270

271

272
  /**
Emmanuel Milou's avatar
Emmanuel Milou committed
273
   * Get the list of codecs we supports, not ordered
274
   * @return The list of the codecs
275
   */  
276
  std::vector< ::DBus::String > getCodecList( void );
Emmanuel Milou's avatar
Emmanuel Milou committed
277
278
279
280
281
282
283
284
  /**
   * Get the info about one codec
   * Name / CLock rate / bitrate / bandwidth
   * @param payload The payload of the codec
   * @return The information
   */
  std::vector< ::DBus::String > getCodecDetails( const ::DBus::Int32& payload);

285
  /**
286
   * Get a list of supported input audio plugin
287
288
   * @return List of names
   */
289
  std::vector< std::string> getInputAudioPluginList(void);
290
291
  
  /**
292
293
294
295
296
297
298
299
300
301
302
303
   * Get a list of supported output audio plugin
   * @return List of names
   */
  std::vector< std::string> getOutputAudioPluginList(void);
  
  /**
   * Set input audio plugin 
   */
  void setInputAudioPlugin(const std::string& audioPlugin);
  
  /**
   * Set output audio plugin 
304
   */
305
  void setOutputAudioPlugin(const std::string& audioPlugin);
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
  
  /**
   * Get list of supported audio output device
   */
  std::vector<std::string> getAudioOutputDeviceList(void);

  /**
   * Set audio output device
   */
  void setAudioOutputDevice(const int index);

  /**
   * Get list of supported audio input device
   */
  std::vector<std::string> getAudioInputDeviceList(void);

  /**
   * Set audio input device
   */
  void setAudioInputDevice(const int index);

  /**
   * Get string array representing integer indexes of output and input device
   */
  std::vector<std::string> getCurrentAudioDevicesIndex();
  
  /**
333
   * Get index of an audio device
334
   */
335
  int getAudioDeviceIndex( const std::string name );
336
337
338
339
340

  /*
   * Get current alsa plugin
   */
  std::string getCurrentAudioOutputPlugin( void ); 
341
  
Emmanuel Milou's avatar
Emmanuel Milou committed
342
343
344
345
346
347
  /**
   * 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
   */
  std::string serialize(std::vector<std::string> v);
348

Emmanuel Milou's avatar
Emmanuel Milou committed
349
  int isIax2Enabled( void ); 
350
351
  int isRingtoneEnabled( void ); 
  void ringtoneEnabled( void ); 
352
353
  std::string getRingtoneChoice( void );
  void setRingtoneChoice( const std::string& );
Emmanuel Milou's avatar
Emmanuel Milou committed
354
355
356
357
  int getDialpad( void );
  void setDialpad( void );
  int isStartHidden( void );
  void startHidden( void );
358
359
  int popupMode( void );
  void switchPopupMode( void );
Emmanuel Milou's avatar
Emmanuel Milou committed
360
361


362
  /**
Emmanuel Milou's avatar
Emmanuel Milou committed
363
364
365
366
367
368
   * Inverse of serialize
   */
  std::vector<std::string> retrieveActiveCodecs( void );
  
  /**
   * Get and set the list of the active codecs
369
   */  
370
371
  std::vector< ::DBus::String > getActiveCodecList( void ); 
  void setActiveCodecList( const std::vector< ::DBus::String >& list);
372
373
374

  /*
   * Set an account as default
375
   * @param The ID of the account we want to set as default
376
   */
377
378
  void setDefaultAccount(const AccountID& accountID);

379
380
381
382
  /*
   * Notify the client that an error occured
   * @param errMsg The error message that should popup on the client side
   */
Emmanuel Milou's avatar
Emmanuel Milou committed
383
  void notifyErrClient( const ::DBus::Int32& errCode );
384

jpbl's avatar
jpbl committed
385
386
387
388
389
390
  bool getConfigAll(const std::string& sequenceId);
  bool getConfig(const std::string& section, const std::string& name, TokenList& arg);
  bool setConfig(const std::string& section, const std::string& name, const std::string& value);
  bool setConfig(const std::string& section, const std::string& name, int value);
  bool getConfigList(const std::string& sequenceId, const std::string& name);
  void selectAudioDriver(void);
391

yanmorin's avatar
   
yanmorin committed
392
393
394
395
396
397
398
  /** 
   * Set Audio Driver with switchName == audiodriver 
   * @param sflphoned internal parameter to change
   * @param message to return to the user
   * @return true if everything is ok
   */
  bool setSwitch(const std::string& switchName, std::string& message);
jpbl's avatar
jpbl committed
399
400
401

  // configuration function for extern
  // throw an Conf::ConfigTreeItemException if not found
yanmorin's avatar
   
yanmorin committed
402
  /** Get a int from the config tree */
jpbl's avatar
jpbl committed
403
  int getConfigInt(const std::string& section, const std::string& name);
yanmorin's avatar
   
yanmorin committed
404
  /** Get a string from the config tree */
jpbl's avatar
jpbl committed
405
406
  std::string getConfigString(const std::string& section, const std::string& name);

yanmorin's avatar
   
yanmorin committed
407
	/**
jpbl's avatar
jpbl committed
408
409
410
411
412
	 * Handle audio sounds heard by a caller while they wait for their 
	 * connection to a called party to be completed.
	 */
  void ringback ();

yanmorin's avatar
   
yanmorin committed
413
	/**
jpbl's avatar
jpbl committed
414
415
416
417
	 * Handle played music when an incoming call occurs
	 */
  void ringtone ();
  void congestion ();
yanmorin's avatar
   
yanmorin committed
418
419
  void callBusy(const CallID& id);
  void callFailure(const CallID& id);
jpbl's avatar
jpbl committed
420

yanmorin's avatar
   
yanmorin committed
421
  /** @return 0 if no tone (init before calling this function) */
jpbl's avatar
jpbl committed
422
  AudioLoop* getTelephoneTone();
yanmorin's avatar
   
yanmorin committed
423
  /** @return 0 if the wav is stopped */
jpbl's avatar
jpbl committed
424
425
426
427
428
429
430
  AudioLoop* getTelephoneFile();

  /**
   * @return true is there is one or many incoming call waiting
   * new call, not anwsered or refused
   */
  bool incomingCallWaiting(void);
yanmorin's avatar
   
yanmorin committed
431
	/**
jpbl's avatar
jpbl committed
432
433
	 * Notification of incoming call when you are already busy
	 */
yanmorin's avatar
   
yanmorin committed
434
435
  void notificationIncomingCall(void);

jpbl's avatar
jpbl committed
436
437
438
439
440
441
442
443
444
445
446

  /*
   * Inline functions to manage volume control
   * Read by main thread and AudioLayer thread
   * Write by main thread only
   */
  unsigned short getSpkrVolume(void) { return _spkr_volume; }
  void setSpkrVolume(unsigned short spkr_vol) {  _spkr_volume = spkr_vol; }
  unsigned short getMicVolume(void) {  return _mic_volume;  }
  void setMicVolume(unsigned short mic_vol) {    _mic_volume = mic_vol;   }

yanmorin's avatar
   
yanmorin committed
447
  // Manage information about firewall
jpbl's avatar
jpbl committed
448
  /*
yanmorin's avatar
   
yanmorin committed
449
450
451
452
   * Get information about firewall 
   * @param  stunSvrAddr: stun server
   * @param  port         port number to open to test the connection
   * @return true if the connection is successful
jpbl's avatar
jpbl committed
453
   */
yanmorin's avatar
   
yanmorin committed
454
455
  bool getStunInfo(StunAddress4& stunSvrAddr, int port);

yanmorin's avatar
   
yanmorin committed
456
457
  inline int getFirewallPort(void) 		{ return _firewallPort; }
  inline void setFirewallPort(int port) 	{ _firewallPort = port; }
jpbl's avatar
jpbl committed
458
459
  inline std::string getFirewallAddress (void) 	{ return _firewallAddr; }

yanmorin's avatar
   
yanmorin committed
460
461
462
463
464
  /**
   * If you are behind a NAT, you have to use STUN server, specified in 
   * STUN configuration(you can change this one by default) to give you an 
   * public IP address and assign a port number.
   * Note: Set firewall port/address retreive
yanmorin's avatar
   
yanmorin committed
465
466
   * @param svr  : serveur on which to send request
   * @param port : on which port we want to listen to
yanmorin's avatar
   
yanmorin committed
467
468
469
   * 
   * Return true if we are behind a NAT (without error)
   */
yanmorin's avatar
   
yanmorin committed
470
  bool behindNat(const std::string& svr, int port);
yanmorin's avatar
   
yanmorin committed
471

472
473
474
475
476
477
  /**
   * Init default values for the different fields in the config file.
   * Fills the local _config (Conf::ConfigTree) with the default contents.
   *
   * Called in main.cpp, just before Manager::init().
   */
jpbl's avatar
jpbl committed
478
  void initConfigFile (void);
yanmorin's avatar
   
yanmorin committed
479
480
481
482

  /**
   * Tell if the setup was already loaded
   */
jpbl's avatar
jpbl committed
483
484
  bool hasLoadedSetup() { return _setupLoaded; }
	
yanmorin's avatar
   
yanmorin committed
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
  /** Return a new random callid that is not present in the list
   * @return a brand new callid
   */
  CallID getNewCallID();

  /**
   * Get the current call id
   * @return the call id or ""
   */
  const CallID& getCurrentCallId();

  /**
   * Check if a call is the current one
   * @param id the new callid
   * @return if the id is the current call
   */
  bool isCurrentCall(const CallID& callId);

Emmanuel Milou's avatar
nothing    
Emmanuel Milou committed
503
504
505
506
  /**
   * Map accounts parameters ( authname - hostname ) to an account ID
   */
 AccountID getAccountFromEvent( std::string authname );
jpbl's avatar
jpbl committed
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
private:
 /**
  * Create .PROGNAME directory in home user and create 
  * configuration tree from the settings file if this file exists.
  *
  * @return	0 if creating file failed
  *			1 if config-file exists
  *			2 if file doesn't exist yet.
  */
  int createSettingsPath (void);

  /*
   * Initialize audiocodec with config setting
   */
  void initAudioCodec(void);
522

jpbl's avatar
jpbl committed
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
  /*
   * Initialize audiodriver
   */
  void initAudioDriver(void);

  /*
   * Initialize zeroconf module and scanning
   */
  void initZeroconf(void);
  
  /*
   * Init the Gui interface (after setting it) inside setGui
   */
  void initGui();

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

  /**
   * Configuration
   */
  bool getDirListing(const std::string& sequenceId, const std::string& path, int *nbFile);
  bool getAudioDeviceList(const std::string& sequenceId, int ioDeviceMask);
  Conf::ConfigTree _config;
  bool getCountryTones(const std::string& sequenceId);
  void sendCountryTone(const std::string& sequenceId, int index, const std::string& name);
551
   
552

jpbl's avatar
jpbl committed
553

yanmorin's avatar
   
yanmorin committed
554
555
556
557
558
559
560
561
562
  /**
   * Tell if there is a current call processed
   * @return true if there is a current call
   */
  bool hasCurrentCall();

  /**
   * Switch of current call id
   * @param id the new callid
jpbl's avatar
jpbl committed
563
   */
yanmorin's avatar
   
yanmorin committed
564
565
566
567
568
569
570
571
  void switchCall(const CallID& id);

  /** Current Call ID */
  CallID _currentCallId2;

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

jpbl's avatar
jpbl committed
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587

  /*
   * Play one tone
   * @return false if the driver is uninitialize
   */
  bool playATone(Tone::TONEID toneId);
  
  //
  // Multithread variable with extern accessor and change only inside the main thread
  //
  /** Vector of CodecDescriptor */
  CodecDescriptor* _codecBuilder;

  //
  // Sound variable
  //
588
  AudioLayer* _audiodriver;
jpbl's avatar
jpbl committed
589
590
591
592
593

  // Main thread
  DTMF* _dtmfKey;

  // map of codec (for configlist request)
594
  CodecDescriptor _codecDescriptorMap;
jpbl's avatar
jpbl committed
595
596
597
598
599
600
601
602
603
604
605
606
607

  /////////////////////
  // Protected by Mutex
  /////////////////////
  ost::Mutex _toneMutex;
  TelephoneTone* _telephoneTone;
  AudioFile _audiofile;

  // To handle volume control
  short _spkr_volume;
  short _mic_volume;
  short _mic_volume_before_mute;
  // End of sound variable
yanmorin's avatar
   
yanmorin committed
608

jpbl's avatar
jpbl committed
609
610
611
612
613
614
615
616
617

  // Multithread variable (protected by _mutex)
  // 
  /** Mutex to protect access to code section */
  ost::Mutex _mutex;

  //
  // Multithread variable (non protected)
  //
618
  DBusManagerImpl * _dbus;
jpbl's avatar
jpbl committed
619

yanmorin's avatar
   
yanmorin committed
620
621
622
623
624
625
  /** Waiting Call Vectors */
  CallIDSet _waitingCall;
  /** Protect waiting call list, access by many voip/audio threads */
  ost::Mutex _waitingCallMutex;
  /** Number of waiting call, synchronize with waitingcall callidvector */
  unsigned int _nbIncomingWaitingCall;
jpbl's avatar
jpbl committed
626
  /**
yanmorin's avatar
   
yanmorin committed
627
628
   * Add incoming callid to the waiting list
   * @param id CallID to add
jpbl's avatar
jpbl committed
629
   */
yanmorin's avatar
   
yanmorin committed
630
631
632
633
634
635
636
637
638
639
640
641
  void addWaitingCall(const CallID& id);
  /**
   * Remove incoming callid to the waiting list
   * @param id CallID to remove
   */
  void removeWaitingCall(const CallID& id);
  /**
   * Tell if a call is waiting and should be remove
   * @param id CallID to test
   * @return true if the call is waiting
   */
  bool isWaitingCall(const CallID& id);
jpbl's avatar
jpbl committed
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662

	/**
   * Path of the ConfigFile 
	 */
  std::string 	_path;
  int _exist;
  int _setupLoaded;

	// To handle firewall
  int _firewallPort;
  std::string _firewallAddr;

  // tell if we have zeroconf is enabled
  int _hasZeroconf;

#ifdef USE_ZEROCONF
  // DNSService contain every zeroconf services
  //  configuration detected on the network
  DNSService *_DNSService;
#endif

yanmorin's avatar
   
yanmorin committed
663
664
665
666
667
668
669
670
671
672
673
  /** Map to associate a CallID to the good account */
  CallAccountMap _callAccountMap;
  /** Mutex to lock the call account map (main thread + voiplink thread) */
  ost::Mutex _callAccountMapMutex;

  /** Associate a new CallID to a AccountID
   * Protected by mutex
   * @param callID the new CallID not in the list yet
   * @param accountID the known accountID present in accountMap
   * @return true if the new association is create
   */
yanmorin's avatar
   
yanmorin committed
674
  bool associateCallToAccount(const CallID& callID, const AccountID& accountID);
yanmorin's avatar
   
yanmorin committed
675
676
677
678
679
680

  /** Return the AccountID from a CallID
   * Protected by mutex
   * @param callID the CallID in the list
   * @return the accountID associated or "" if the callID is not found
   */
yanmorin's avatar
   
yanmorin committed
681
  AccountID getAccountFromCall(const CallID& callID);
yanmorin's avatar
   
yanmorin committed
682
683
684
685
686
687

  /** Remove a CallID/AccountID association
   * Protected by mutex
   * @param callID the CallID to remove
   * @return true if association is removed
   */
yanmorin's avatar
   
yanmorin committed
688
  bool removeCallAccount(const CallID& callID);
yanmorin's avatar
   
yanmorin committed
689

yanmorin's avatar
   
yanmorin committed
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
  /** Contains a list of account (sip, aix, etc) and their respective voiplink/calls */
  AccountMap _accountMap;

  /**
   * Load the account from configuration
   * @return number of account
   */
  short loadAccountMap();

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

  /**
   * Tell if an account exists
   * @param accountID account ID check
   */
yanmorin's avatar
   
yanmorin committed
708
  bool accountExists(const AccountID& accountID);
yanmorin's avatar
   
yanmorin committed
709
710
711
712
713
714

  /**
   * Get an account pointer
   * @param accountID account ID to get
   * @param the account pointer or 0
   */
yanmorin's avatar
   
yanmorin committed
715
716
717
718
719
720
721
722
  Account* getAccount(const AccountID& accountID);

  /**
   * Get the voip link from the account pointer
   * @param accountID account ID to get
   * @param the voip link from the account pointer or 0
   */
  VoIPLink* getAccountLink(const AccountID& accountID);
yanmorin's avatar
   
yanmorin committed
723

yanmorin's avatar
   
yanmorin committed
724

Emmanuel Milou's avatar
Emmanuel Milou committed
725

yanmorin's avatar
   
yanmorin committed
726
727
  #ifdef TEST
  bool testCallAccountMap();
yanmorin's avatar
   
yanmorin committed
728
  bool testAccountMap();
yanmorin's avatar
   
yanmorin committed
729
  #endif
yanmorin's avatar
   
yanmorin committed
730

jpbl's avatar
jpbl committed
731
732
};

Emmanuel Milou's avatar
Emmanuel Milou committed
733
#endif // __MANAGER_H__