managerimpl.h 17.6 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>
jpbl's avatar
jpbl committed
6
7
8
 *
 *  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
9
 *  the Free Software Foundation; either version 3 of the License, or
jpbl's avatar
jpbl committed
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 *  (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
25
26
//#define TEST

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

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

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

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

46

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

jpbl's avatar
jpbl committed
53
54
55
56
#ifdef USE_ZEROCONF
class DNSService;
#endif

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

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

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

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

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

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

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

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

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

yanmorin's avatar
   
yanmorin committed
115
  /**
jpbl's avatar
jpbl committed
116
117
   * Functions which occur with a user's action
   */
yanmorin's avatar
   
yanmorin committed
118
119
120
121
122
123
124
  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
125
126
  void mute();
  void unmute();
yanmorin's avatar
   
yanmorin committed
127
  bool refuseCall(const CallID& id);
jpbl's avatar
jpbl committed
128

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

yanmorin's avatar
   
yanmorin committed
132
  /**
133
134
135
136
137
138
139
   * 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
140
  /**
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
   * 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
162

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

  // 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
197
198
  void displayConfigError(const std::string& message);

yanmorin's avatar
   
yanmorin committed
199
200
  void startVoiceMessageNotification(const AccountID& accountId, const std::string& nb_msg);
  void stopVoiceMessageNotification(const AccountID& accountId);
jpbl's avatar
jpbl committed
201

yanmorin's avatar
   
yanmorin committed
202
203
204
205
  /** Notify the user that registration succeeded  */
  void registrationSucceed(const AccountID& accountId);
  /** Notify the user that registration succeeded  */
  void registrationFailed(const AccountID& accountId);
jpbl's avatar
jpbl committed
206
207

  // configuration function requests
208
209
210
211
212
213
214
215

  /**
   * Start events thread. This function actually only calls the private
   * initRegisterVoIPLink().
   *
   * This function should definitively be renamed!
   *
   * @todo Receive account name (???)
216
217
   *
   * DEPRECATED
218
   */
219
  //bool getEvents();
yanmorin's avatar
   
yanmorin committed
220
221

  //
jpbl's avatar
jpbl committed
222
223
224
225
  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);
226

227
  /** 
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
228
229
   * Get account list 
   * @return A list of accoundIDs
230
   */
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
231
  std::vector< std::string >  getAccountList();
232
233
234
235

  /**
   * Retrieve details about a given account
   */
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
236
  std::map< std::string, std::string > getAccountDetails(const AccountID& accountID);
237
238
239

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

  /**
   * 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
256
  void removeAccount(const AccountID& accountID);
257
258
  
  /*
259
260
   * Get the default account
   * @return The default account
261
262
   */
  std::string getDefaultAccount();
263

264
265
266
267
  /**
   * Set the prefered order for codecs.
   * Called by D-Bus command: "setCodecPreferedOrder"
   *
268
   * @param codec_name The name of the prefered codec.
269
   */
270
  void setPreferedCodec(const ::DBus::String& codec_name);
271
  
272
273
/**
 * Get the prefered codec
274
 * @return The description of the prefered codec
275
276
277
 */
  std::string getPreferedCodec(  );

278
  /**
279
   * Get the list of codecs we supports, ordered by the user
280
   * @return The list of the codecs
281
282
283
   */  
  std::vector< ::DBus::String > getCodecList( void ); 

284
285
286
287
288
  /**
   * Get the default list of codecs we supports
   * @ return The list of the codecs
   */  
  std::vector< ::DBus::String > getDefaultCodecList( void ); 
289

290
291
292
293
294
295
296
297
298
299
300
301
/**
 * Get the sample rate of a codec
 * @param name: The description of the codec
 * @return The sample rate of the specified codec
 */	
  unsigned int clockRate(std::string& name); 

/**
 * Get the list of the standart sound sample rates
 * Values: { 44100 , 44000 , 96000 }
 * @return The list of the sample rates
 */     
302
  std::vector< ::DBus::String> getSampleRateList( void );
303
304
305

  /*
   * Set an account as default
306
   * @param The ID of the account we want to set as default
307
   */
308
309
  void setDefaultAccount(const AccountID& accountID);

310

jpbl's avatar
jpbl committed
311
312
313
314
315
316
  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);
317

yanmorin's avatar
   
yanmorin committed
318
319
320
321
322
323
324
  /** 
   * 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
325
326
327

  // configuration function for extern
  // throw an Conf::ConfigTreeItemException if not found
yanmorin's avatar
   
yanmorin committed
328
  /** Get a int from the config tree */
jpbl's avatar
jpbl committed
329
  int getConfigInt(const std::string& section, const std::string& name);
yanmorin's avatar
   
yanmorin committed
330
  /** Get a string from the config tree */
jpbl's avatar
jpbl committed
331
332
  std::string getConfigString(const std::string& section, const std::string& name);

yanmorin's avatar
   
yanmorin committed
333
	/**
jpbl's avatar
jpbl committed
334
335
336
337
338
	 * 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
339
	/**
jpbl's avatar
jpbl committed
340
341
342
343
	 * Handle played music when an incoming call occurs
	 */
  void ringtone ();
  void congestion ();
yanmorin's avatar
   
yanmorin committed
344
345
  void callBusy(const CallID& id);
  void callFailure(const CallID& id);
jpbl's avatar
jpbl committed
346

yanmorin's avatar
   
yanmorin committed
347
  /** @return 0 if no tone (init before calling this function) */
jpbl's avatar
jpbl committed
348
  AudioLoop* getTelephoneTone();
yanmorin's avatar
   
yanmorin committed
349
  /** @return 0 if the wav is stopped */
jpbl's avatar
jpbl committed
350
351
352
353
354
355
356
  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
357
	/**
jpbl's avatar
jpbl committed
358
359
	 * Notification of incoming call when you are already busy
	 */
yanmorin's avatar
   
yanmorin committed
360
361
  void notificationIncomingCall(void);

jpbl's avatar
jpbl committed
362
363
364
365
366
367
368
369
370
371
372

  /*
   * 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
373
  // Manage information about firewall
jpbl's avatar
jpbl committed
374
  /*
yanmorin's avatar
   
yanmorin committed
375
376
377
378
   * 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
379
   */
yanmorin's avatar
   
yanmorin committed
380
381
  bool getStunInfo(StunAddress4& stunSvrAddr, int port);

yanmorin's avatar
   
yanmorin committed
382
383
  inline int getFirewallPort(void) 		{ return _firewallPort; }
  inline void setFirewallPort(int port) 	{ _firewallPort = port; }
jpbl's avatar
jpbl committed
384
385
  inline std::string getFirewallAddress (void) 	{ return _firewallAddr; }

yanmorin's avatar
   
yanmorin committed
386
387
388
389
390
  /**
   * 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
391
392
   * @param svr  : serveur on which to send request
   * @param port : on which port we want to listen to
yanmorin's avatar
   
yanmorin committed
393
394
395
   * 
   * Return true if we are behind a NAT (without error)
   */
yanmorin's avatar
   
yanmorin committed
396
  bool behindNat(const std::string& svr, int port);
yanmorin's avatar
   
yanmorin committed
397

398
399
400
401
402
403
  /**
   * 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
404
  void initConfigFile (void);
yanmorin's avatar
   
yanmorin committed
405
406
407
408

  /**
   * Tell if the setup was already loaded
   */
jpbl's avatar
jpbl committed
409
410
  bool hasLoadedSetup() { return _setupLoaded; }
	
yanmorin's avatar
   
yanmorin committed
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
  /** 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);

jpbl's avatar
jpbl committed
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
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);
444

jpbl's avatar
jpbl committed
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
  /*
   * 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);
473
   
474

jpbl's avatar
jpbl committed
475

yanmorin's avatar
   
yanmorin committed
476
477
478
479
480
481
482
483
484
  /**
   * 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
485
   */
yanmorin's avatar
   
yanmorin committed
486
487
488
489
490
491
492
493
  void switchCall(const CallID& id);

  /** Current Call ID */
  CallID _currentCallId2;

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

jpbl's avatar
jpbl committed
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509

  /*
   * 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
  //
510
  AudioLayer* _audiodriver;
jpbl's avatar
jpbl committed
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529

  // Main thread
  DTMF* _dtmfKey;

  // map of codec (for configlist request)
  CodecDescriptorMap _codecDescriptorMap;

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

jpbl's avatar
jpbl committed
531
532
533
534
535
536
537
538
539

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

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

yanmorin's avatar
   
yanmorin committed
542
543
544
545
546
547
  /** 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
548
  /**
yanmorin's avatar
   
yanmorin committed
549
550
   * Add incoming callid to the waiting list
   * @param id CallID to add
jpbl's avatar
jpbl committed
551
   */
yanmorin's avatar
   
yanmorin committed
552
553
554
555
556
557
558
559
560
561
562
563
  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
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584

	/**
   * 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
585
586
587
588
589
590
591
592
593
594
595
  /** 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
596
  bool associateCallToAccount(const CallID& callID, const AccountID& accountID);
yanmorin's avatar
   
yanmorin committed
597
598
599
600
601
602

  /** 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
603
  AccountID getAccountFromCall(const CallID& callID);
yanmorin's avatar
   
yanmorin committed
604
605
606
607
608
609

  /** 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
610
  bool removeCallAccount(const CallID& callID);
yanmorin's avatar
   
yanmorin committed
611

yanmorin's avatar
   
yanmorin committed
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
  /** 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
630
  bool accountExists(const AccountID& accountID);
yanmorin's avatar
   
yanmorin committed
631
632
633
634
635
636

  /**
   * Get an account pointer
   * @param accountID account ID to get
   * @param the account pointer or 0
   */
yanmorin's avatar
   
yanmorin committed
637
638
639
640
641
642
643
644
  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
645

yanmorin's avatar
   
yanmorin committed
646

yanmorin's avatar
   
yanmorin committed
647
648
  #ifdef TEST
  bool testCallAccountMap();
yanmorin's avatar
   
yanmorin committed
649
  bool testAccountMap();
yanmorin's avatar
   
yanmorin committed
650
  #endif
yanmorin's avatar
   
yanmorin committed
651

jpbl's avatar
jpbl committed
652
653
};

654
t#endif // __MANAGER_H__