Config.cpp 5.65 KB
Newer Older
1
/*
Erwan Croze's avatar
Erwan Croze committed
2
Config.cpp
3 4 5 6 7 8 9 10 11 12 13
Copyright (C) 2015  Belledonne Communications, Grenoble, France
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 the Free Software Foundation; either version 2
of the License, or (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
14
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
15 16 17
*/

#include "ApiLock.h"
Erwan Croze's avatar
Erwan Croze committed
18
#include "Config.h"
19

Erwan Croze's avatar
Erwan Croze committed
20
bool BelledonneCommunications::Linphone::Native::Config::GetBool(Platform::String^ section, Platform::String^ key, bool defaultValue)
21 22 23 24
{
	return (GetInt(section, key, defaultValue) == TRUE);
}

Erwan Croze's avatar
Erwan Croze committed
25
void BelledonneCommunications::Linphone::Native::Config::SetBool(Platform::String^ section, Platform::String^ key, bool value)
26 27 28 29
{
	SetInt(section, key, (int)value);
}

Erwan Croze's avatar
Erwan Croze committed
30
int BelledonneCommunications::Linphone::Native::Config::GetInt(Platform::String^ section, Platform::String^ key, int defaultValue)
31 32
{
	API_LOCK;
33 34
	const char *ccSection = Utils::pstoccs(section);
	const char *ccKey = Utils::pstoccs(key);
35 36 37 38 39 40
	int value = lp_config_get_int(this->config, ccSection, ccKey, defaultValue);
	delete(ccKey);
	delete(ccSection);
	return value;
}

Erwan Croze's avatar
Erwan Croze committed
41
void BelledonneCommunications::Linphone::Native::Config::SetInt(Platform::String^ section, Platform::String^ key, int value)
42 43
{
	API_LOCK;
44 45
	const char *ccSection = Utils::pstoccs(section);
	const char *ccKey = Utils::pstoccs(key);
46 47 48 49 50
	lp_config_set_int(this->config, ccSection, ccKey, value);
	delete(ccKey);
	delete(ccSection);
}

Erwan Croze's avatar
Erwan Croze committed
51
int64 BelledonneCommunications::Linphone::Native::Config::GetInt64(Platform::String^ section, Platform::String^ key, int64 defaultValue)
52 53
{
	API_LOCK;
54 55
	const char *ccSection = Utils::pstoccs(section);
	const char *ccKey = Utils::pstoccs(key);
56 57 58 59 60 61
	int64 value = lp_config_get_int64(this->config, ccSection, ccKey, defaultValue);
	delete(ccKey);
	delete(ccSection);
	return value;
}

Erwan Croze's avatar
Erwan Croze committed
62
void BelledonneCommunications::Linphone::Native::Config::SetInt64(Platform::String^ section, Platform::String^ key, int64 value)
63 64
{
	API_LOCK;
65 66
	const char *ccSection = Utils::pstoccs(section);
	const char *ccKey = Utils::pstoccs(key);
67 68 69 70 71
	lp_config_set_int64(this->config, ccSection, ccKey, value);
	delete(ccKey);
	delete(ccSection);
}

Erwan Croze's avatar
Erwan Croze committed
72
float BelledonneCommunications::Linphone::Native::Config::GetFloat(Platform::String^ section, Platform::String^ key, float defaultValue)
73 74
{
	API_LOCK;
75 76
	const char *ccSection = Utils::pstoccs(section);
	const char *ccKey = Utils::pstoccs(key);
77 78 79 80 81 82
	float value = lp_config_get_float(this->config, ccSection, ccKey, defaultValue);
	delete(ccKey);
	delete(ccSection);
	return value;
}

Erwan Croze's avatar
Erwan Croze committed
83
void BelledonneCommunications::Linphone::Native::Config::SetFloat(Platform::String^ section, Platform::String^ key, float value)
84 85
{
	API_LOCK;
86 87
	const char *ccSection = Utils::pstoccs(section);
	const char *ccKey = Utils::pstoccs(key);
88 89 90 91 92
	lp_config_set_float(this->config, ccSection, ccKey, value);
	delete(ccKey);
	delete(ccSection);
}

Erwan Croze's avatar
Erwan Croze committed
93
Platform::String^ BelledonneCommunications::Linphone::Native::Config::GetString(Platform::String^ section, Platform::String^ key, Platform::String^ defaultValue)
94 95
{
	API_LOCK;
96 97 98
	const char *ccSection = Utils::pstoccs(section);
	const char *ccKey = Utils::pstoccs(key);
	const char *ccDefaultValue = Utils::pstoccs(defaultValue);
99
	const char *ccvalue = lp_config_get_string(this->config, ccSection, ccKey, ccDefaultValue);
100
	Platform::String^ value = Utils::cctops(ccvalue);
101 102 103 104 105 106
	delete(ccDefaultValue);
	delete(ccKey);
	delete(ccSection);
	return value;
}

Erwan Croze's avatar
Erwan Croze committed
107
void BelledonneCommunications::Linphone::Native::Config::SetString(Platform::String^ section, Platform::String^ key, Platform::String^ value)
108 109
{
	API_LOCK;
110 111 112
	const char *ccSection = Utils::pstoccs(section);
	const char *ccKey = Utils::pstoccs(key);
	const char *ccValue = Utils::pstoccs(value);
113 114 115 116 117 118
	lp_config_set_string(this->config, ccSection, ccKey, ccValue);
	delete(ccValue);
	delete(ccKey);
	delete(ccSection);
}

Erwan Croze's avatar
Erwan Croze committed
119
Platform::Array<int>^ BelledonneCommunications::Linphone::Native::Config::GetRange(Platform::String^ section, Platform::String^ key, const Platform::Array<int>^ defaultValue)
120 121 122
{
	API_LOCK;
	Platform::Array<int>^ range = ref new Platform::Array<int>(2);
123 124
	const char *ccSection = Utils::pstoccs(section);
	const char *ccKey = Utils::pstoccs(key);
125 126 127 128 129 130
	lp_config_get_range(this->config, ccSection, ccKey, &range[0], &range[1], defaultValue[0], defaultValue[1]);
	delete(ccKey);
	delete(ccSection);
	return range;
}

Erwan Croze's avatar
Erwan Croze committed
131
void BelledonneCommunications::Linphone::Native::Config::SetRange(Platform::String^ section, Platform::String^ key, const Platform::Array<int>^ value)
132 133
{
	API_LOCK;
134 135
	const char *ccSection = Utils::pstoccs(section);
	const char *ccKey = Utils::pstoccs(key);
136 137 138 139 140
	lp_config_set_range(this->config, ccSection, ccKey, value[0], value[1]);
	delete(ccKey);
	delete(ccSection);
}

Erwan Croze's avatar
Erwan Croze committed
141
BelledonneCommunications::Linphone::Native::Config::Config(::LinphoneConfig *config) :
142 143
	config(config)
{
144
	lp_config_ref(config);
145 146
}

Erwan Croze's avatar
Erwan Croze committed
147
BelledonneCommunications::Linphone::Native::Config::Config(Platform::String^ configPath, Platform::String^ factoryConfigPath)
148 149
{
	API_LOCK;
150 151
	const char *ccConfigPath = Utils::pstoccs(configPath);
	const char *ccFactoryConfigPath = Utils::pstoccs(factoryConfigPath);
152 153 154 155 156
	this->config = lp_config_new_with_factory(ccConfigPath, ccFactoryConfigPath);
	delete(ccFactoryConfigPath);
	delete(ccConfigPath);
}

Erwan Croze's avatar
Erwan Croze committed
157
BelledonneCommunications::Linphone::Native::Config::~Config()
158
{
159 160 161
	if (this->config != nullptr) {
		lp_config_unref(this->config);
	}
162
}