Commit 59bb8066 authored by Ghislain MARY's avatar Ghislain MARY

Handle configuration of logging in the config file.

parent e4099ad4
......@@ -125,9 +125,10 @@ namespace Linphone
/// </summary>
public enum class OutputTraceDest : int
{
Debugger = 0,
File = 1,
TCPRemote = 2
None = 0,
Debugger = 1,
File = 2,
TCPRemote = 3
};
}
}
\ No newline at end of file
......@@ -74,6 +74,12 @@ Linphone::Core::LinphoneAddress^ LinphoneCoreFactory::CreateLinphoneAddress(Plat
return (Linphone::Core::LinphoneAddress^)Utils::CreateLinphoneAddressFromUri(Utils::pstoccs(uri));
}
void LinphoneCoreFactory::SetLogLevel(OutputTraceLevel logLevel)
{
std::lock_guard<std::recursive_mutex> lock(g_apiLock);
Linphone::Core::LinphoneCore::SetLogLevel(logLevel);
}
Linphone::Core::LinphoneCore^ LinphoneCoreFactory::LinphoneCore::get()
{
return this->linphoneCore;
......
......@@ -48,6 +48,8 @@ namespace Linphone
/// <param name="uri">address, should be like "sip:joe@sip.linphone.org"</param>
LinphoneAddress^ CreateLinphoneAddress(Platform::String^ uri);
void SetLogLevel(OutputTraceLevel logLevel);
private:
friend ref class Linphone::Core::Globals;
......
......@@ -81,11 +81,12 @@ Platform::String^ Linphone::Core::LpConfig::GetString(Platform::String^ section,
const char *ccSection = Linphone::Core::Utils::pstoccs(section);
const char *ccKey = Linphone::Core::Utils::pstoccs(key);
const char *ccDefaultValue = Linphone::Core::Utils::pstoccs(defaultValue);
const char *value = lp_config_get_string(this->config, ccSection, ccKey, ccDefaultValue);
const char *ccvalue = lp_config_get_string(this->config, ccSection, ccKey, ccDefaultValue);
Platform::String^ value = Linphone::Core::Utils::cctops(ccvalue);
delete(ccDefaultValue);
delete(ccKey);
delete(ccSection);
return Linphone::Core::Utils::cctops(value);
return value;
}
void Linphone::Core::LpConfig::SetString(Platform::String^ section, Platform::String^ key, Platform::String^ value)
......
......@@ -65,11 +65,6 @@ namespace Linphone
return Windows::ApplicationModel::Package::Current->InstalledLocation->Path;
};
}
void SetLogLevel(OutputTraceLevel logLevel)
{
Linphone::Core::LinphoneCore::SetLogLevel(logLevel);
}
};
}
}
......
......@@ -228,20 +228,6 @@ namespace Linphone.Model
}
#endregion
private void InstallConfig()
{
if (!File.Exists(GetConfigPath()))
{
File.Copy("Assets/linphonerc", GetConfigPath());
}
}
private String GetConfigPath()
{
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
return localFolder.Path + "\\linphonerc";
}
/// <summary>
/// Creates a new LinphoneCore (if not created yet) using a LinphoneCoreFactory.
/// </summary>
......@@ -258,10 +244,10 @@ namespace Linphone.Model
}
Logger.Msg("[LinphoneManager] Creating LinphoneCore");
InstallConfig();
LpConfig config = server.LinphoneCoreFactory.CreateLpConfig(GetConfigPath(), "Assets/linphonerc-factory");
server.LinphoneCoreFactory.CreateLinphoneCore(this, config);
SettingsManager.InstallConfigFile();
LpConfig config = server.LinphoneCoreFactory.CreateLpConfig(SettingsManager.GetConfigPath(), SettingsManager.GetFactoryConfigPath());
ConfigureLogger();
server.LinphoneCoreFactory.CreateLinphoneCore(this, config);
server.LinphoneCore.SetRootCA("Assets/rootca.pem");
Logger.Msg("[LinphoneManager] LinphoneCore created");
......@@ -292,16 +278,14 @@ namespace Linphone.Model
// To have the debug output in the debugger use the following commented configure and set your debugger to native mode
//server.BackgroundModeLogger.Configure(SettingsManager.isDebugEnabled, OutputTraceDest.Debugger, "");
// Else output the debug traces to a file
server.BackgroundModeLogger.Configure(SettingsManager.isDebugEnabled, OutputTraceDest.File, "Linphone.log");
ApplicationSettingsManager appSettings = new ApplicationSettingsManager();
appSettings.Load();
server.BackgroundModeLogger.Configure(appSettings.DebugEnabled, appSettings.LogDestination, appSettings.LogOption);
server.LinphoneCoreFactory.OutputTraceListener = server.BackgroundModeLogger;
server.LinphoneCoreFactory.SetLogLevel(appSettings.LogLevel);
Logger.Instance.TraceListener = server.BackgroundModeLogger;
}
public void SetLogLevel(OutputTraceLevel logLevel)
{
server.SetLogLevel(logLevel);
}
#region CallLogs
private List<CallLogs> _history;
......
......@@ -2,11 +2,13 @@
using Linphone.Resources;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.IsolatedStorage;
using System.Linq;
using System.Resources;
using System.Text;
using System.Threading.Tasks;
using Windows.Storage;
namespace Linphone.Model
{
......@@ -44,18 +46,40 @@ namespace Linphone.Model
}
/// <summary>
/// Static access to the debug enabled setting.
/// Install the default config file from the package to the Isolated Storage
/// </summary>
public static bool isDebugEnabled
public static void InstallConfigFile()
{
get
if (!File.Exists(GetConfigPath()))
{
ApplicationSettingsManager asm = new ApplicationSettingsManager();
asm.Load();
return asm.DebugEnabled;
File.Copy("Assets/linphonerc", GetConfigPath());
}
}
/// <summary>
/// Get the path of the config file stored in the Isolated Storage
/// </summary>
/// <returns>The path of the config file</returns>
public static String GetConfigPath()
{
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
return localFolder.Path + "\\linphonerc";
}
/// <summary>
/// Get the path of the factory config file stored in the package
/// </summary>
/// <returns>The path of the factory config file</returns>
public static String GetFactoryConfigPath()
{
return "Assets/linphonerc-factory";
}
/// <summary>
/// Get the value of a settings parameter from its name
/// </summary>
/// <param name="Key">The name of the settings parameter for which we want the value</param>
/// <returns>The value of the settings parameter</returns>
protected String Get(String Key)
{
if (dict.ContainsKey(Key))
......@@ -68,6 +92,11 @@ namespace Linphone.Model
}
}
/// <summary>
/// Get the changed value of a settings parameter from its name
/// </summary>
/// <param name="Key">The name of the settings parameter for which we want the changed value</param>
/// <returns>The changed value of the settings parameter</returns>
protected String GetNew(String Key)
{
if (changesDict.ContainsKey(Key))
......@@ -81,6 +110,11 @@ namespace Linphone.Model
return null;
}
/// <summary>
/// Set a new value for a settings parameter given its name
/// </summary>
/// <param name="Key">The name of the settings parameter to change</param>
/// <param name="Value">The new value to be set for the settings parameter</param>
protected void Set(String Key, String Value)
{
if (dict.ContainsKey(Key))
......@@ -96,6 +130,11 @@ namespace Linphone.Model
}
}
/// <summary>
/// Tell whether a settings parameter has been changed given its name
/// </summary>
/// <param name="Key">The name of the settings parameter</param>
/// <returns>A boolean telling whether the settings parameter has been changed or not</returns>
protected bool ValueChanged(String Key)
{
return changesDict.ContainsKey(Key);
......@@ -108,18 +147,38 @@ namespace Linphone.Model
public class ApplicationSettingsManager : SettingsManager, ISettingsManager
{
private const string ApplicationSection = "app";
private LpConfig Config;
#region Constants settings names
private const string DebugSettingKeyName = "Debug";
private const string LogLevelKeyName = "LogLevel";
private const string LogDestinationKeyName = "LogDestination";
private const string LogOptionKeyName = "LogOption";
#endregion
/// <summary>
/// Public constructor.
/// </summary>
public ApplicationSettingsManager()
{
if (LinphoneManager.Instance.LinphoneCore == null)
{
Config = LinphoneManager.Instance.LinphoneCoreFactory.CreateLpConfig(GetConfigPath(), GetFactoryConfigPath());
}
else
{
Config = LinphoneManager.Instance.LinphoneCore.GetConfig();
}
}
#region Implementation of the ISettingsManager interface
/// <summary>
/// Load the application settings.
/// </summary>
public void Load()
{
dict[DebugSettingKeyName] = LinphoneManager.Instance.LinphoneCore.GetConfig().GetBool(ApplicationSection, DebugSettingKeyName, false).ToString();
dict[LogLevelKeyName] = Config.GetInt(ApplicationSection, LogLevelKeyName, (int)OutputTraceLevel.None).ToString();
dict[LogDestinationKeyName] = Config.GetString(ApplicationSection, LogDestinationKeyName, OutputTraceDest.File.ToString());
dict[LogOptionKeyName] = Config.GetString(ApplicationSection, LogOptionKeyName, "Linphone.log");
}
/// <summary>
......@@ -127,15 +186,10 @@ namespace Linphone.Model
/// </summary>
public void Save()
{
LinphoneCore lc = LinphoneManager.Instance.LinphoneCore;
bool debugEnabled = Convert.ToBoolean(GetNew(DebugSettingKeyName));
OutputTraceLevel logLevel = OutputTraceLevel.None;
if (debugEnabled)
if (ValueChanged(LogLevelKeyName))
{
logLevel = OutputTraceLevel.Message;
Config.SetInt(ApplicationSection, LogLevelKeyName, Convert.ToInt32(GetNew(LogLevelKeyName)));
}
LinphoneManager.Instance.SetLogLevel(logLevel);
lc.GetConfig().SetBool(ApplicationSection, DebugSettingKeyName, debugEnabled);
LinphoneManager.Instance.ConfigureLogger();
}
#endregion
......@@ -148,11 +202,67 @@ namespace Linphone.Model
{
get
{
return Convert.ToBoolean(Get(DebugSettingKeyName));
return Convert.ToInt32(Get(LogLevelKeyName)) != (int)OutputTraceLevel.None;
}
set
{
if (value)
{
Set(LogLevelKeyName, ((int)OutputTraceLevel.Message).ToString());
}
else
{
Set(LogLevelKeyName, ((int)OutputTraceLevel.None).ToString());
}
}
}
/// <summary>
/// Log level (OutputTraceLevel).
/// </summary>
public OutputTraceLevel LogLevel
{
get
{
return (OutputTraceLevel) Convert.ToInt32(Get(LogLevelKeyName));
}
set
{
Set(LogLevelKeyName, ((int)value).ToString());
}
}
/// <summary>
/// Log destination.
/// </summary>
public OutputTraceDest LogDestination
{
get
{
String dest = Get(LogDestinationKeyName);
if (dest == OutputTraceDest.Debugger.ToString()) return OutputTraceDest.Debugger;
else if (dest == OutputTraceDest.File.ToString()) return OutputTraceDest.File;
else if (dest == OutputTraceDest.TCPRemote.ToString()) return OutputTraceDest.TCPRemote;
return OutputTraceDest.None;
}
set
{
Set(LogDestinationKeyName, value.ToString());
}
}
/// <summary>
/// Log option (filename if LogDestination is OutputTraceDest.File, host:port if LogDestination is OutputTraceDest.TCPRemote).
/// </summary>
public String LogOption
{
get
{
return Get(LogOptionKeyName);
}
set
{
Set(DebugSettingKeyName, value.ToString());
Set(LogOptionKeyName, value);
}
}
#endregion
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment