Commit a0f183ab authored by Ghislain MARY's avatar Ghislain MARY

Handle trace levels.

parent c3294deb
......@@ -17,7 +17,7 @@ Linphone::Core::BackgroundModeLogger::~BackgroundModeLogger()
{
}
void Linphone::Core::BackgroundModeLogger::OutputTrace(int level, Platform::String^ msg)
void Linphone::Core::BackgroundModeLogger::OutputTrace(OutputTraceLevel level, Platform::String^ msg)
{
if (!dataWriter) {
StorageFolder^ localFolder = ApplicationData::Current->LocalFolder;
......
......@@ -14,7 +14,7 @@ namespace Linphone
public ref class BackgroundModeLogger sealed : OutputTraceListener
{
public:
virtual void OutputTrace(int level, Platform::String^ msg);
virtual void OutputTrace(OutputTraceLevel level, Platform::String^ msg);
private:
friend ref class Linphone::Core::Globals;
......
......@@ -107,5 +107,17 @@ namespace Linphone
Missed = 2,
Declined = 3
};
/// <summary>
/// Levels for trace output
/// </summary>
public enum class OutputTraceLevel : int
{
Debug = 0,
Message = 1,
Warning = 2,
Error = 3,
Raw = 4
};
}
}
\ No newline at end of file
......@@ -13,7 +13,7 @@ using namespace Platform;
static bool sDebugEnabled = false;
static OutputTraceListener^ sTraceListener;
static void nativeOutputTraceHandler(int lev, const char *fmt, va_list args)
static void nativeOutputTraceHandler(OutputTraceLevel lev, const char *fmt, va_list args)
{
if (sDebugEnabled) {
wchar_t wstr[MAX_TRACE_SIZE];
......@@ -31,9 +31,16 @@ static void nativeOutputTraceHandler(int lev, const char *fmt, va_list args)
static void LinphoneNativeOutputTraceHandler(OrtpLogLevel lev, const char *fmt, va_list args)
{
OutputTraceLevel level = OutputTraceLevel::Message;
char fmt2[MAX_TRACE_SIZE];
snprintf(fmt2, MAX_TRACE_SIZE, "%s\n", fmt);
nativeOutputTraceHandler((int)lev, fmt2, args);
if (lev == ORTP_DEBUG) level = OutputTraceLevel::Debug;
else if (lev == ORTP_MESSAGE) level = OutputTraceLevel::Message;
else if (lev == ORTP_TRACE) level = OutputTraceLevel::Message;
else if (lev == ORTP_WARNING) level = OutputTraceLevel::Warning;
else if (lev == ORTP_ERROR) level = OutputTraceLevel::Error;
else if (lev == ORTP_FATAL) level = OutputTraceLevel::Error;
nativeOutputTraceHandler(level, fmt2, args);
}
void LinphoneCoreFactory::SetDebugMode(Platform::Boolean enable, OutputTraceListener^ traceListener)
......
......@@ -14,8 +14,8 @@ namespace Linphone
public interface class OutputTraceListener
{
public:
void OutputTrace(int level, Platform::String^ msg);
public:
void OutputTrace(OutputTraceLevel level, Platform::String^ msg);
};
public ref class LinphoneCoreFactory sealed
......
......@@ -156,7 +156,7 @@ namespace Linphone.Model
}
// Disconnect the listeners to prevent crash of the background process
server.LinphoneCoreFactory.SetDebugMode(SettingsManager.isDebugEnabled, server.BackgroundModeLogger);
BackgroundModeDebug();
server.LinphoneCore.CoreListener = null;
BackgroundProcessConnected = false;
......@@ -206,7 +206,7 @@ namespace Linphone.Model
/// </summary>
public void InitLinphoneCore()
{
server.LinphoneCoreFactory.SetDebugMode(SettingsManager.isDebugEnabled, Logger.Instance);
ForegroundModeDebug();
if (server.LinphoneCore != null)
{
......@@ -217,12 +217,26 @@ namespace Linphone.Model
server.LinphoneCoreFactory.CreateLinphoneCore(this);
InitProxyConfig();
Logger.WriteLine("[LinphoneManager] LinphoneCore created");
Logger.Msg("[LinphoneManager] LinphoneCore created");
AudioRoutingManager.GetDefault().AudioEndpointChanged += AudioEndpointChanged;
CallController.MuteRequested += MuteRequested;
CallController.UnmuteRequested += UnmuteRequested;
}
#region Debug handling
private void ForegroundModeDebug()
{
Logger.Instance.Enable = SettingsManager.isDebugEnabled;
server.LinphoneCoreFactory.SetDebugMode(SettingsManager.isDebugEnabled, Logger.Instance);
}
private void BackgroundModeDebug()
{
Logger.Instance.Enable = SettingsManager.isDebugEnabled;
server.LinphoneCoreFactory.SetDebugMode(SettingsManager.isDebugEnabled, server.BackgroundModeLogger);
}
#endregion
#region CallLogs
private List<CallLogs> _history;
......@@ -402,7 +416,7 @@ namespace Linphone.Model
#region Audio route handling
private void AudioEndpointChanged(AudioRoutingManager sender, object args)
{
Logger.WriteLine("[LinphoneManager] AudioEndpointChanged:" + sender.GetAudioEndpoint().ToString());
Logger.Msg("[LinphoneManager] AudioEndpointChanged:" + sender.GetAudioEndpoint().ToString());
}
public void EnableSpeaker(bool enable)
......@@ -424,7 +438,7 @@ namespace Linphone.Model
/// </summary>
public void AuthInfoRequested(string realm, string username)
{
Logger.WriteLine("[LinphoneManager] Auth info requested: realm=" + realm + ", username=" + username);
Logger.Msg("[LinphoneManager] Auth info requested: realm=" + realm + ", username=" + username);
}
/// <summary>
......@@ -432,7 +446,7 @@ namespace Linphone.Model
/// </summary>
public void GlobalState(GlobalState state, string message)
{
Logger.WriteLine("[LinphoneManager] Global state changed: " + state.ToString() + ", message=" + message);
Logger.Msg("[LinphoneManager] Global state changed: " + state.ToString() + ", message=" + message);
}
/// <summary>
......@@ -441,7 +455,7 @@ namespace Linphone.Model
public void CallState(LinphoneCall call, LinphoneCallState state)
{
string sipAddress = call.GetRemoteAddress().AsStringUriOnly();
Logger.WriteLine("[LinphoneManager] Call state changed: " + sipAddress + " => " + state.ToString());
Logger.Msg("[LinphoneManager] Call state changed: " + sipAddress + " => " + state.ToString());
if (state == LinphoneCallState.OutgoingProgress)
{
BaseModel.UIDispatcher.BeginInvoke(() =>
......@@ -461,7 +475,7 @@ namespace Linphone.Model
{
String contact = call.GetRemoteContact();
String number = call.GetRemoteAddress().AsStringUriOnly();
Logger.WriteLine("[LinphoneManager] Incoming received: " + contact + " (" + number + ")");
Logger.Msg("[LinphoneManager] Incoming received: " + contact + " (" + number + ")");
BaseModel.UIDispatcher.BeginInvoke(() =>
{
......@@ -473,7 +487,7 @@ namespace Linphone.Model
CallController.RequestNewIncomingCall("/Linphone;component/Views/InCall.xaml?sip=" + number, contact, number, contactUri, "Linphone", iconUri, "", ringtoneUri, VoipCallMedia.Audio, fifteenSecs, out vcall);
vcall.AnswerRequested += ((c, eventargs) =>
{
Logger.WriteLine("[LinphoneManager] Call accepted");
Logger.Msg("[LinphoneManager] Call accepted");
vcall.NotifyCallActive();
LinphoneCore.AcceptCall(call);
BaseModel.UIDispatcher.BeginInvoke(() =>
......@@ -484,7 +498,7 @@ namespace Linphone.Model
});
vcall.RejectRequested += ((c, eventargs) =>
{
Logger.WriteLine("[LinphoneManager] Call rejected");
Logger.Msg("[LinphoneManager] Call rejected");
LinphoneCore.TerminateCall(call);
});
vcall.HoldRequested += CallHoldRequested;
......@@ -494,7 +508,7 @@ namespace Linphone.Model
}
else if (state == LinphoneCallState.CallEnd || state == LinphoneCallState.Error)
{
Logger.WriteLine("[LinphoneManager] Call ended");
Logger.Msg("[LinphoneManager] Call ended");
BaseModel.UIDispatcher.BeginInvoke(() =>
{
((VoipPhoneCall)call.CallContext).NotifyCallEnded();
......@@ -531,7 +545,7 @@ namespace Linphone.Model
{
BaseModel.UIDispatcher.BeginInvoke(() =>
{
Logger.WriteLine("[LinphoneManager] Registration state changed: " + state.ToString() + ", message=" + message + " for identity " + config.GetIdentity());
Logger.Msg("[LinphoneManager] Registration state changed: " + state.ToString() + ", message=" + message + " for identity " + config.GetIdentity());
LastKnownState = state;
if (BasePage.StatusBar != null)
BasePage.StatusBar.RefreshStatusIcon(state);
......
......@@ -18,13 +18,30 @@ namespace Linphone.Model
/// </summary>
public sealed class Logger : OutputTraceListener
{
[Flags] public enum Output {
/// <summary>
/// Type of outputs to write the logs to
/// </summary>
[Flags] public enum Output
{
/// <summary>Write to a file synchronously</summary>
FILE_SYNCHRONOUS,
/// <summary>Write to the standard debug output (Visual Studio output)</summary>
DEBUG_WRITE
};
/// <summary>
/// The outputs to which to write the logs
/// </summary>
public Output Outputs { get; set; }
/// <summary>
/// The name of the file to write the logs to if using the FILE_SYNCHRONOUS output
/// </summary>
public String Filename { get; set; }
/// <summary>
/// Whether the logger is enabled or not
/// </summary>
public bool Enable { get; set; }
private Logger()
......@@ -74,7 +91,11 @@ namespace Linphone.Model
}
}
public void Write(String msg)
/// <summary>
/// Write a message to the configured outputs
/// </summary>
/// <param name="msg">The message to be written</param>
private void Write(OutputTraceLevel level, String msg)
{
if (Outputs.HasFlag(Output.FILE_SYNCHRONOUS))
{
......@@ -86,17 +107,48 @@ namespace Linphone.Model
}
}
public static void WriteLine(string 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 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 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 an error message
/// </summary>
/// <param name="msg">The message to be written</param>
public static void Err(String msg)
{
Logger.Instance.Write(msg);
Logger.Instance.Write(OutputTraceLevel.Error, msg);
}
/// <summary>
/// Handler to get and output native traces
/// </summary>
public void OutputTrace(int level, String msg)
public void OutputTrace(OutputTraceLevel level, String msg)
{
Write(msg);
Write(level, msg);
}
}
}
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