Commit 01b95fa3 authored by Ghislain MARY's avatar Ghislain MARY

Refactor linphone core creation.

parent 80420754
using Linphone.Core;
using Linphone.Core.OutOfProcess;
using Mediastreamer2.WP8Video;
using System;
using System.IO;
using Windows.Storage;
namespace Linphone.Agents
{
public static class AgentHost
{
static VideoRenderer videoRenderer = new VideoRenderer();
static AgentHost()
{
AgentHost.videoRenderer = new VideoRenderer();
Globals.Instance.VideoRenderer = AgentHost.videoRenderer;
}
......@@ -16,7 +20,5 @@ namespace Linphone.Agents
{
Globals.Instance.StartServer(RegistrationHelper.OutOfProcServerClassNames);
}
static VideoRenderer videoRenderer;
}
}
......@@ -65,9 +65,11 @@
<Compile Include="AgentHost.cs" />
<Compile Include="BackgroundManager.cs" />
<Compile Include="Customs.cs" />
<Compile Include="InitManager.cs" />
<Compile Include="LinphoneCallInProgressAgent.cs" />
<Compile Include="LinphoneForegroundLifeTimeAgent.cs" />
<Compile Include="LinphoneScheduledAgent.cs" />
<Compile Include="Logger.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RegistrationHelper.cs" />
<Compile Include="TileManager.cs" />
......
......@@ -61,13 +61,7 @@ namespace Linphone.Agents
public void InitLinphoneCore()
{
// Initiate incoming call processing by creating the Linphone Core
LpConfig config = OopServer.LinphoneCoreFactory.CreateLpConfig(ApplicationData.Current.LocalFolder.Path + "\\linphonerc", "Assets/linphonerc-factory");
OutputTraceLevel level = (OutputTraceLevel)config.GetInt("app", "LogLevel", 1); //1 is Message
OopServer.LinphoneCoreFactory.SetLogLevel(level);
OopServer.LinphoneCoreFactory.CreateLinphoneCore(null, config);
OopServer.LinphoneCore.SetRootCA("Assets/rootca.pem");
OopServer.LinphoneCore.SetChatDatabasePath(ApplicationData.Current.LocalFolder.Path + "\\chat.db");
OopServer.LinphoneCore.SetUserAgent("LinphoneWP8PushNotification", Linphone.Version.Number);
InitManager.CreateLinphoneCore(OopServer, null, OutputTraceLevel.Message);
OopServer.LinphoneCore.SetNetworkReachable(true);
OopServer.LinphoneCore.IterateEnabled = true;
}
......
using Linphone.Core;
using System;
using System.IO;
using Windows.Storage;
namespace Linphone.Agents
{
/// <summary>
/// Class to handle the initialization process of the application
/// </summary>
public static class InitManager
{
/// <summary>
/// Get the path of the default config file stored in the package
/// </summary>
/// <returns>The path of the default config file</returns>
public static String GetDefaultConfigPath()
{
return Path.Combine(Windows.ApplicationModel.Package.Current.InstalledLocation.Path, "Assets", "linphonerc");
}
/// <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()
{
return Path.Combine(ApplicationData.Current.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 path of the database file used to store chat messages stored in the Isolated Storage
/// </summary>
/// <returns>The path of the config file</returns>
public static String GetChatDatabasePath()
{
return Path.Combine(ApplicationData.Current.LocalFolder.Path, "chat.db");
}
/// <summary>
/// Configure the Logger
/// </summary>
/// <param name="server">The out-of-process server</param>
/// <param name="level">The log level to use for the Logger</param>
public static void ConfigureLogger(Linphone.Core.OutOfProcess.Server server, OutputTraceLevel level)
{
server.LinphoneCoreFactory.SetLogLevel(level);
Logger.Instance.TraceListener = server.BackgroundModeLogger;
}
/// <summary>
/// Create the linphone core and set some basic configuration values
/// </summary>
/// <param name="server">The out-of-process server</param>
/// <param name="listener">The LinphoneCoreListener</param>
/// <param name="level">The log level to use for the Logger</param>
public static void CreateLinphoneCore(Linphone.Core.OutOfProcess.Server server, LinphoneCoreListener listener, OutputTraceLevel level)
{
LpConfig config = server.LinphoneCoreFactory.CreateLpConfig(GetConfigPath(), GetFactoryConfigPath());
ConfigureLogger(server, level);
server.LinphoneCoreFactory.CreateLinphoneCore(listener, config);
server.LinphoneCore.SetRootCA("Assets/rootca.pem");
server.LinphoneCore.SetChatDatabasePath(GetChatDatabasePath());
server.LinphoneCore.SetUserAgent(Customs.UserAgent, Linphone.Version.Number);
}
}
}
......@@ -43,14 +43,8 @@ namespace Linphone.Agents
if (DeviceNetworkInformation.IsNetworkAvailable)
{
var server = BackgroundManager.Instance.OopServer;
LpConfig config = server.LinphoneCoreFactory.CreateLpConfig(ApplicationData.Current.LocalFolder.Path + "\\linphonerc", "Assets/linphonerc-factory");
OutputTraceLevel level = (OutputTraceLevel)config.GetInt("app", "LogLevel", 1); //1 is Message
server.LinphoneCoreFactory.SetLogLevel(level);
server.LinphoneCoreFactory.CreateLinphoneCore(this, config);
server.LinphoneCore.SetRootCA("Assets/rootca.pem");
server.LinphoneCore.SetChatDatabasePath(ApplicationData.Current.LocalFolder.Path + "\\chat.db");
InitManager.CreateLinphoneCore(server, this, OutputTraceLevel.Message);
server.LinphoneCore.SetNetworkReachable(true);
server.LinphoneCore.SetUserAgent("LinphoneWP8KeepAlive", Linphone.Version.Number);
server.LinphoneCore.IterateEnabled = true;
Debug.WriteLine("[KeepAliveAgent] Linphone Core created");
}
......
using Linphone.Core;
using Linphone.Core;
using System;
namespace Linphone.Model
{
/// <summary>
/// Class to handle the logging of the application
/// </summary>
public sealed class Logger
{
/// <summary>
/// The trace listener to which to send the messages to be logged
/// </summary>
public OutputTraceListener TraceListener { get; set; }
private Logger()
{
}
private static Logger singleton;
/// <summary>
/// Static instance of the class.
/// </summary>
public static Logger Instance
{
get
{
if (Logger.singleton == null)
Logger.singleton = new Logger();
return Logger.singleton;
}
}
/// <summary>
/// Write a message to the logs
/// </summary>
/// <param name="level">The trace level of the message to be written</param>
/// <param name="msg">The message to be written</param>
private void Write(OutputTraceLevel level, String msg)
{
if (TraceListener != null)
{
TraceListener.OutputTrace(level, msg);
}
}
/// <summary>
/// Write a debug message
/// </summary>
/// <param name="msg">The message to be written</param>
public static void Dbg(String msg)
{
Logger.Instance.Write(OutputTraceLevel.Debug, msg);
}
/// <summary>
/// Write a debug message with a format and some arguments
/// </summary>
/// <param name="fmt">The format of the message to be written</param>
/// <param name="args">The arguments to fill the format with</param>
public static void Dbg(String fmt, params object[] args)
{
Logger.Instance.Write(OutputTraceLevel.Debug, String.Format(fmt, args));
}
/// <summary>
/// Write a standard message
/// </summary>
/// <param name="msg">The message to be written</param>
public static void Msg(String msg)
{
Logger.Instance.Write(OutputTraceLevel.Message, msg);
}
/// <summary>
/// Write a standard message with a format and some arguments
/// </summary>
/// <param name="fmt">The format of the message to be written</param>
/// <param name="args">The arguments to fill the format with</param>
public static void Msg(String fmt, params object[] args)
{
Logger.Instance.Write(OutputTraceLevel.Message, String.Format(fmt, args));
}
/// <summary>
/// Write a warning message
/// </summary>
/// <param name="msg">The message to be written</param>
public static void Warn(String msg)
{
Logger.Instance.Write(OutputTraceLevel.Warning, msg);
}
/// <summary>
/// Write a warning message with a format and some arguments
/// </summary>
/// <param name="fmt">The format of the message to be written</param>
/// <param name="args">The arguments to fill the format with</param>
public static void Warn(String fmt, params object[] args)
{
Logger.Instance.Write(OutputTraceLevel.Warning, String.Format(fmt, args));
}
/// <summary>
/// Write an error message
/// </summary>
/// <param name="msg">The message to be written</param>
public static void Err(String msg)
{
Logger.Instance.Write(OutputTraceLevel.Error, msg);
}
/// <summary>
/// Write an error message with a format and some arguments
/// </summary>
/// <param name="fmt">The format of the message to be written</param>
/// <param name="args">The arguments to fill the format with</param>
public static void Err(String fmt, params object[] args)
{
Logger.Instance.Write(OutputTraceLevel.Error, String.Format(fmt, args));
}
}
}
namespace Linphone.Agents
{
/// <summary>
/// Class to handle the logging of the application
/// </summary>
public sealed class Logger
{
/// <summary>
/// The trace listener to which to send the messages to be logged
/// </summary>
public OutputTraceListener TraceListener { get; set; }
private Logger()
{
}
private static Logger singleton;
/// <summary>
/// Static instance of the class.
/// </summary>
public static Logger Instance
{
get
{
if (Logger.singleton == null)
Logger.singleton = new Logger();
return Logger.singleton;
}
}
/// <summary>
/// Write a message to the logs
/// </summary>
/// <param name="level">The trace level of the message to be written</param>
/// <param name="msg">The message to be written</param>
private void Write(OutputTraceLevel level, String msg)
{
if (TraceListener != null)
{
TraceListener.OutputTrace(level, msg);
}
}
/// <summary>
/// Write a debug message
/// </summary>
/// <param name="msg">The message to be written</param>
public static void Dbg(String msg)
{
Logger.Instance.Write(OutputTraceLevel.Debug, msg);
}
/// <summary>
/// Write a debug message with a format and some arguments
/// </summary>
/// <param name="fmt">The format of the message to be written</param>
/// <param name="args">The arguments to fill the format with</param>
public static void Dbg(String fmt, params object[] args)
{
Logger.Instance.Write(OutputTraceLevel.Debug, String.Format(fmt, args));
}
/// <summary>
/// Write a standard message
/// </summary>
/// <param name="msg">The message to be written</param>
public static void Msg(String msg)
{
Logger.Instance.Write(OutputTraceLevel.Message, msg);
}
/// <summary>
/// Write a standard message with a format and some arguments
/// </summary>
/// <param name="fmt">The format of the message to be written</param>
/// <param name="args">The arguments to fill the format with</param>
public static void Msg(String fmt, params object[] args)
{
Logger.Instance.Write(OutputTraceLevel.Message, String.Format(fmt, args));
}
/// <summary>
/// Write a warning message
/// </summary>
/// <param name="msg">The message to be written</param>
public static void Warn(String msg)
{
Logger.Instance.Write(OutputTraceLevel.Warning, msg);
}
/// <summary>
/// Write a warning message with a format and some arguments
/// </summary>
/// <param name="fmt">The format of the message to be written</param>
/// <param name="args">The arguments to fill the format with</param>
public static void Warn(String fmt, params object[] args)
{
Logger.Instance.Write(OutputTraceLevel.Warning, String.Format(fmt, args));
}
/// <summary>
/// Write an error message
/// </summary>
/// <param name="msg">The message to be written</param>
public static void Err(String msg)
{
Logger.Instance.Write(OutputTraceLevel.Error, msg);
}
/// <summary>
/// Write an error message with a format and some arguments
/// </summary>
/// <param name="fmt">The format of the message to be written</param>
/// <param name="args">The arguments to fill the format with</param>
public static void Err(String fmt, params object[] args)
{
Logger.Instance.Write(OutputTraceLevel.Error, String.Format(fmt, args));
}
}
}
......@@ -117,7 +117,6 @@
<Compile Include="Model\Conversation.cs" />
<Compile Include="Model\HubTileConverterFix.cs" />
<Compile Include="Model\LinphoneManager.cs" />
<Compile Include="Model\Logger.cs" />
<Compile Include="Model\SipUriToUsernameConverter.cs" />
<Compile Include="Model\BoolToAccentBrushConverter.cs" />
<Compile Include="Model\SettingsManager.cs" />
......
using Linphone.Core;
using Linphone.Agents;
using Linphone.Core;
using Linphone.Model;
using System;
using System.Collections.Generic;
......
......@@ -295,11 +295,7 @@ namespace Linphone.Model
}
Debug.WriteLine("[LinphoneManager] Creating LinphoneCore");
LpConfig config = server.LinphoneCoreFactory.CreateLpConfig(SettingsManager.GetConfigPath(), SettingsManager.GetFactoryConfigPath());
ConfigureLogger();
server.LinphoneCoreFactory.CreateLinphoneCore(this, config);
server.LinphoneCore.SetRootCA("Assets/rootca.pem");
server.LinphoneCore.SetChatDatabasePath(SettingsManager.GetChatDatabasePath());
InitManager.CreateLinphoneCore(server, this, LogLevel);
Logger.Dbg("[LinphoneManager] LinphoneCore created");
AudioRoutingManager.GetDefault().AudioEndpointChanged += AudioEndpointChanged;
......@@ -357,15 +353,22 @@ namespace Linphone.Model
}
}
public OutputTraceLevel LogLevel
{
get
{
ApplicationSettingsManager appSettings = new ApplicationSettingsManager();
appSettings.Load();
return appSettings.LogLevel;
}
}
/// <summary>
/// Configures the Logger
/// </summary>
public void ConfigureLogger()
{
ApplicationSettingsManager appSettings = new ApplicationSettingsManager();
appSettings.Load();
server.LinphoneCoreFactory.SetLogLevel(appSettings.LogLevel);
Logger.Instance.TraceListener = server.BackgroundModeLogger;
InitManager.ConfigureLogger(server, LogLevel);
}
/// <summary>
......
......@@ -47,49 +47,17 @@ namespace Linphone.Model
changesDict = new Dictionary<String, String>();
}
private static String GetDefaultConfigPath()
{
return Path.Combine(Windows.ApplicationModel.Package.Current.InstalledLocation.Path, "Assets", "linphonerc");
}
/// <summary>
/// Install the default config file from the package to the Isolated Storage
/// </summary>
public static void InstallConfigFile()
{
if (!File.Exists(GetConfigPath()))
if (!File.Exists(InitManager.GetConfigPath()))
{
File.Copy(GetDefaultConfigPath(), GetConfigPath());
File.Copy(InitManager.GetDefaultConfigPath(), InitManager.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()
{
return Path.Combine(ApplicationData.Current.LocalFolder.Path, "linphonerc");
}
/// <summary>
/// Get the path of the database file used to store chat messages stored in the Isolated Storage
/// </summary>
/// <returns>The path of the config file</returns>
public static String GetChatDatabasePath()
{
return Path.Combine(ApplicationData.Current.LocalFolder.Path, "chat.db");
}
/// <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>
......@@ -174,7 +142,7 @@ namespace Linphone.Model
{
if (LinphoneManager.Instance.LinphoneCore == null)
{
Config = LinphoneManager.Instance.LinphoneCoreFactory.CreateLpConfig(GetConfigPath(), GetFactoryConfigPath());
Config = LinphoneManager.Instance.LinphoneCoreFactory.CreateLpConfig(InitManager.GetConfigPath(), InitManager.GetFactoryConfigPath());
}
else
{
......@@ -1060,7 +1028,7 @@ namespace Linphone.Model
{
if (LinphoneManager.Instance.LinphoneCore == null)
{
Config = LinphoneManager.Instance.LinphoneCoreFactory.CreateLpConfig(GetConfigPath(), GetFactoryConfigPath());
Config = LinphoneManager.Instance.LinphoneCoreFactory.CreateLpConfig(InitManager.GetConfigPath(), InitManager.GetFactoryConfigPath());
}
else
{
......
using Microsoft.Xna.Framework.Media;
using Linphone.Agents;
using Microsoft.Xna.Framework.Media;
using System;
using System.Collections.Generic;
using System.IO;
......
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