account.cpp 3.23 KB
Newer Older
yanmorin's avatar
   
yanmorin committed
1
/*
2
3
4
 *  Copyright (C) 2006-2009 Savoir-Faire Linux inc.
 *
 *  Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
5
 *  Author: Alexandre Bourget <alexandre.bourget@savoirfairelinux.com>
yanmorin's avatar
   
yanmorin 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
yanmorin's avatar
   
yanmorin committed
10
11
12
13
14
15
16
17
18
19
20
 *  (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.
 */
21

yanmorin's avatar
   
yanmorin committed
22
#include "account.h"
23
#include "manager.h"
yanmorin's avatar
   
yanmorin committed
24

25
Account::Account (const AccountID& accountID, std::string type) :
26
27
28
29
30
	_accountID (accountID)
	, _link (NULL)
	, _enabled (false)
	, _type (type)
	, _codecOrder ()
yanmorin's avatar
   
yanmorin committed
31
{
32
	setRegistrationState (Unregistered);
yanmorin's avatar
   
yanmorin committed
33
34
35
36
37
}

Account::~Account()
{
}
38

Emmanuel Milou's avatar
Emmanuel Milou committed
39
40
void Account::loadConfig() {

41
	std::string p;
42

43
	p =  Manager::instance().getConfigString (_accountID , CONFIG_ACCOUNT_TYPE);
44
#ifdef USE_IAX
45
	_enabled = (Manager::instance().getConfigString (_accountID, CONFIG_ACCOUNT_ENABLE) == "true") ? true : false;
46
#else
47

48
49
50
51
	if (p == "IAX")
		_enabled = false;
	else
		_enabled = (Manager::instance().getConfigString (_accountID, CONFIG_ACCOUNT_ENABLE) == "true") ? true : false;
52

53
#endif
Emmanuel Milou's avatar
Emmanuel Milou committed
54
55

	loadAudioCodecs ();
56
}
57

Emmanuel Milou's avatar
Emmanuel Milou committed
58
void Account::setRegistrationState (RegistrationState state) {
59

60
	if (state != _registrationState) {
Alexandre Savard's avatar
Alexandre Savard committed
61
		_debug ("Account: set registration state");
62
		_registrationState = state;
Emmanuel Milou's avatar
Emmanuel Milou committed
63

64
65
66
		// Notify the client
		Manager::instance().connectionStatusNotification();
	}
Emmanuel Milou's avatar
Emmanuel Milou committed
67
}
Emmanuel Milou's avatar
Emmanuel Milou committed
68
69
70
71

void Account::loadAudioCodecs (void) {

	// if the user never set the codec list, use the default configuration for this account
72
	if (Manager::instance ().getConfigString (_accountID, "ActiveCodecs") == "") {
Alexandre Savard's avatar
Alexandre Savard committed
73
		_info ("Account: use the default order");
Emmanuel Milou's avatar
Emmanuel Milou committed
74
		Manager::instance ().getCodecDescriptorMap ().setDefaultOrder();
75
76
77
78
79
80
81
82
83
	}

	// else retrieve the one set in the user config file
	else {
		std::vector<std::string> active_list = Manager::instance ().retrieveActiveCodecs();
		// This property is now set per account basis
		std::string s = Manager::instance ().getConfigString (_accountID, "ActiveCodecs");
		setActiveCodecs (Manager::instance ().unserialize (s));
	}
Emmanuel Milou's avatar
Emmanuel Milou committed
84
85
86
87
}

void Account::setActiveCodecs (const std::vector <std::string> &list) {

88
89
90
91
92
93
	_codecOrder.clear();
	// list contains the ordered payload of active codecs picked by the user for this account
	// we used the CodecOrder vector to save the order.
	int i=0;
	int payload;
	size_t size = list.size();
Emmanuel Milou's avatar
Emmanuel Milou committed
94

95
96
	while ( (unsigned int) i < size) {
		payload = std::atoi (list[i].data());
Alexandre Savard's avatar
Alexandre Savard committed
97
		_info ("Account: Adding codec with RTP payload=%i", payload);
98
99
100
101
102
103
		//if (Manager::instance ().getCodecDescriptorMap ().isCodecLoaded (payload)) {
		_codecOrder.push_back ( (AudioCodecType) payload);
		//}
		i++;
	}

104
105
106
	// setConfig
	std::string s = Manager::instance ().serialize (list);

107
108
109
110
	// Set the config per account
	Manager::instance().setConfig (_accountID, "ActiveCodecs", s);


Emmanuel Milou's avatar
Emmanuel Milou committed
111
}