From: WonYoung Choi Date: Wed, 9 Mar 2016 14:19:42 +0000 (+0900) Subject: Refactor code X-Git-Tag: submit/trunk/20170823.075128~77^2~35 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6b8c1541022b30f1c234de35d6755561b03cfb0c;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git Refactor code Change-Id: I7a3f7eaee9d13359add0b5416cf1f23675f4c78c --- diff --git a/.gitattributes b/.gitattributes new file mode 100755 index 0000000..1ff0c42 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore index 7d84484..8fd3218 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ bin/ obj/ *.exe *.dll +.vs/ diff --git a/Tizen.sln b/Tizen.sln new file mode 100755 index 0000000..3ef5a12 --- /dev/null +++ b/Tizen.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.24720.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tizen", "Tizen\Tizen.csproj", "{7659CA59-410D-41A1-9841-586E88BC78C9}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7659CA59-410D-41A1-9841-586E88BC78C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7659CA59-410D-41A1-9841-586E88BC78C9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7659CA59-410D-41A1-9841-586E88BC78C9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7659CA59-410D-41A1-9841-586E88BC78C9}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/packaging/csapi-tizen.spec b/packaging/csapi-tizen.spec index 39ae4a3..19ebe13 100644 --- a/packaging/csapi-tizen.spec +++ b/packaging/csapi-tizen.spec @@ -47,11 +47,10 @@ cp %{SOURCE1} . %build # build dll -mcs -target:library -out:%{dllname} -keyfile:Tizen.snk \ - Properties/AssemblyInfo.cs \ - Tizen/Log.cs \ - Tizen/LogTraceListener.cs \ - Tizen/NativeMethods.cs +mcs -target:library -out:%{dllname} -keyfile:Tizen/Tizen.snk \ + Tizen/Properties/AssemblyInfo.cs \ + Tizen/Tizen/*.cs \ + Tizen/Interop/*.cs # check p/invoke if [ -x %{dllname} ]; then diff --git a/src/Tizen/Interop/Interop.Dlog.cs b/src/Tizen/Interop/Interop.Dlog.cs new file mode 100755 index 0000000..71bdef4 --- /dev/null +++ b/src/Tizen/Interop/Interop.Dlog.cs @@ -0,0 +1,41 @@ +/// Copyright 2016 by Samsung Electronics, Inc., +/// +/// This software is the confidential and proprietary information +/// of Samsung Electronics, Inc. ("Confidential Information"). You +/// shall not disclose such Confidential Information and shall use +/// it only in accordance with the terms of the license agreement +/// you entered into with Samsung. + + +using System.Runtime.InteropServices; + +internal static partial class Interop +{ + internal static partial class Libraries + { + public const string Dlog = "libdlog.so.0"; + } + + internal static partial class Dlog + { + internal enum LogPriority + { + DLOG_UNKNOWN = 0, + DLOG_DEFAULT, + DLOG_VERBOSE, + DLOG_DEBUG, + DLOG_INFO, + DLOG_WARN, + DLOG_ERROR, + DLOG_FATAL, + DLOG_SILENT, + DLOG_PRIO_MAX, + } + [DllImportAttribute(Libraries.Dlog, EntryPoint = "dlog_print", CallingConvention = CallingConvention.Cdecl)] + internal static extern int Print(LogPriority prio, string tag, string fmt, string msg); + + [DllImportAttribute(Libraries.Dlog, EntryPoint = "dlog_print", CallingConvention = CallingConvention.Cdecl)] + internal static extern int Print(LogPriority prio, string tag, string fmt, string file, string func, int line, string msg); + } +} + diff --git a/src/Tizen/NativeMethods.cs b/src/Tizen/NativeMethods.cs deleted file mode 100755 index b3d3b65..0000000 --- a/src/Tizen/NativeMethods.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Runtime.InteropServices; - -namespace Tizen -{ - internal static class NativeMethods - { - internal enum LogPriority - { - DLOG_UNKNOWN = 0, - DLOG_DEFAULT, - DLOG_VERBOSE, - DLOG_DEBUG, - DLOG_INFO, - DLOG_WARN, - DLOG_ERROR, - DLOG_FATAL, - DLOG_SILENT, - DLOG_PRIO_MAX, - } - [DllImportAttribute("libdlog.so.0", EntryPoint = "dlog_print", CallingConvention = CallingConvention.Cdecl)] - internal static extern int DlogPrint(LogPriority prio, string tag, string fmt, string msg); - - [DllImportAttribute("libdlog.so.0", EntryPoint = "dlog_print", CallingConvention = CallingConvention.Cdecl)] - internal static extern int DlogPrint(LogPriority prio, string tag, string fmt, string file, string func, int line, string msg); - } -} diff --git a/Properties/AssemblyInfo.cs b/src/Tizen/Properties/AssemblyInfo.cs similarity index 86% rename from Properties/AssemblyInfo.cs rename to src/Tizen/Properties/AssemblyInfo.cs index dc0c870..44daf40 100755 --- a/Properties/AssemblyInfo.cs +++ b/src/Tizen/Properties/AssemblyInfo.cs @@ -1,19 +1,18 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("Tizen")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Samsung Electronics")] -[assembly: AssemblyProduct("Tizen")] -[assembly: AssemblyCopyright("Copyright (c) 2015 Samsung Electronics Co., Ltd")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -[assembly: ComVisible(false)] - -[assembly: Guid("8aa94469-cdb5-4d8c-81d0-df4590eea612")] - -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +using System.Reflection; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("Tizen")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Samsung Electronics")] +[assembly: AssemblyProduct("Tizen")] +[assembly: AssemblyCopyright("Copyright (c) 2015 Samsung Electronics Co., Ltd")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: ComVisible(false)] + +[assembly: Guid("8aa94469-cdb5-4d8c-81d0-df4590eea612")] + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/tizen.csproj b/src/Tizen/Tizen.csproj similarity index 86% rename from tizen.csproj rename to src/Tizen/Tizen.csproj index 7b1b546..cc3e3ff 100755 --- a/tizen.csproj +++ b/src/Tizen/Tizen.csproj @@ -1,68 +1,65 @@ - - - - - Debug - AnyCPU - {8AA94469-CDB5-4D8C-81D0-DF4590EEA612} - Library - Properties - - - Tizen - v4.5 - 512 - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - bin\Debug\Tizen.XML - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - true - - - Tizen.snk - - - - - - - - - - - - - - - - - - - - - - + + + + + Debug + AnyCPU + {7659CA59-410D-41A1-9841-586E88BC78C9} + Library + Properties + Tizen + Tizen + v4.5.2 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + + + Tizen.snk + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Tizen/Tizen.csproj.user b/src/Tizen/Tizen.csproj.user new file mode 100755 index 0000000..ca1d04b --- /dev/null +++ b/src/Tizen/Tizen.csproj.user @@ -0,0 +1,6 @@ + + + + ProjectFiles + + \ No newline at end of file diff --git a/Tizen.snk b/src/Tizen/Tizen.snk similarity index 100% rename from Tizen.snk rename to src/Tizen/Tizen.snk diff --git a/src/Tizen/Log.cs b/src/Tizen/Tizen/Log.cs similarity index 77% rename from src/Tizen/Log.cs rename to src/Tizen/Tizen/Log.cs index c0f8170..1ade4e4 100755 --- a/src/Tizen/Log.cs +++ b/src/Tizen/Tizen/Log.cs @@ -1,138 +1,147 @@ -using System; -using System.IO; -using System.Runtime.CompilerServices; - -namespace Tizen -{ - /// - /// Provides methods to print log messages to Tizen logging system. - /// - public class Log - { - /// - /// Prints a log message with the DEBUG priority. - /// - /// The tag name of the log message. - /// The log message to print. - /// The source file path of the caller function. This argument will be set automatically by the compiler. - /// The function name of caller function. This argument will be set automatically by the compiler. - /// The line number of calling position. This argument will be set automatically by the compiler. - public static void Debug(string tag, string msg, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0) - { - if (String.IsNullOrEmpty(file)) - { - NativeMethods.DlogPrint(NativeMethods.LogPriority.DLOG_DEBUG, tag, "%s", msg); - } - else - { - Uri f = new Uri(file); - NativeMethods.DlogPrint(NativeMethods.LogPriority.DLOG_DEBUG, tag, "%s: %s(%d) > %s", Path.GetFileName(f.AbsolutePath), func, line, msg); - } - } - - /// - /// Prints a log message with the VERBOSE priority. - /// - /// The tag name of the log message. - /// The log message to print. - /// The source file path of the caller function. This argument will be set automatically by the compiler. - /// The function name of caller function. This argument will be set automatically by the compiler. - /// The line number of calling position. This argument will be set automatically by the compiler. - public static void Verbose(string tag, string msg, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0) - { - if (String.IsNullOrEmpty(file)) - { - NativeMethods.DlogPrint(NativeMethods.LogPriority.DLOG_VERBOSE, tag, "%s", msg); - } - else - { - Uri f = new Uri(file); - NativeMethods.DlogPrint(NativeMethods.LogPriority.DLOG_VERBOSE, tag, "%s: %s(%d) > %s", Path.GetFileName(f.AbsolutePath), func, line, msg); - } - } - - /// - /// Prints a log message with the INFO priority. - /// - /// The tag name of the log message. - /// The log message to print. - /// The source file path of the caller function. This argument will be set automatically by the compiler. - /// The function name of caller function. This argument will be set automatically by the compiler. - /// The line number of calling position. This argument will be set automatically by the compiler. - public static void Info(string tag, string msg, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0) - { - if (String.IsNullOrEmpty(file)) - { - NativeMethods.DlogPrint(NativeMethods.LogPriority.DLOG_INFO, tag, "%s", msg); - } - else - { - Uri f = new Uri(file); - NativeMethods.DlogPrint(NativeMethods.LogPriority.DLOG_INFO, tag, "%s: %s(%d) > %s", Path.GetFileName(f.AbsolutePath), func, line, msg); - } - } - - /// - /// Prints a log message with the WARNING priority. - /// - /// The tag name of the log message. - /// The log message to print. - /// The source file path of the caller function. This argument will be set automatically by the compiler. - /// The function name of caller function. This argument will be set automatically by the compiler. - /// The line number of calling position. This argument will be set automatically by the compiler. - public static void Warn(string tag, string msg, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0) - { - if (String.IsNullOrEmpty(file)) - { - NativeMethods.DlogPrint(NativeMethods.LogPriority.DLOG_WARN, tag, "%s", msg); - } - else - { - Uri f = new Uri(file); - NativeMethods.DlogPrint(NativeMethods.LogPriority.DLOG_WARN, tag, "%s: %s(%d) > %s", Path.GetFileName(f.AbsolutePath), func, line, msg); - } - } - - /// - /// Prints a log message with the ERROR priority. - /// - /// The tag name of the log message. - /// The log message to print. - /// The source file path of the caller function. This argument will be set automatically by the compiler. - /// The function name of caller function. This argument will be set automatically by the compiler. - /// The line number of calling position. This argument will be set automatically by the compiler. - public static void Error(string tag, string msg, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0) - { - if (String.IsNullOrEmpty(file)) - { - NativeMethods.DlogPrint(NativeMethods.LogPriority.DLOG_ERROR, tag, "%s", msg); - } - else - { - Uri f = new Uri(file); - NativeMethods.DlogPrint(NativeMethods.LogPriority.DLOG_ERROR, tag, "%s: %s(%d) > %s", Path.GetFileName(f.AbsolutePath), func, line, msg); - } - } - - /// - /// Prints a log message with the FATAL priority. - /// - /// The tag name of the log message. - /// The log message to print. - /// The source file path of the caller function. This argument will be set automatically by the compiler. - /// The function name of caller function. This argument will be set automatically by the compiler. - /// The line number of calling position. This argument will be set automatically by the compiler. - public static void Fatal(string tag, string msg, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0) - { - if (String.IsNullOrEmpty(file)) - { - NativeMethods.DlogPrint(NativeMethods.LogPriority.DLOG_FATAL, tag, "%s", msg); - } - else - { - Uri f = new Uri(file); - NativeMethods.DlogPrint(NativeMethods.LogPriority.DLOG_FATAL, tag, "%s: %s(%d) > %s", Path.GetFileName(f.AbsolutePath), func, line, msg); - } - } - } -} +/// Copyright 2016 by Samsung Electronics, Inc., +/// +/// This software is the confidential and proprietary information +/// of Samsung Electronics, Inc. ("Confidential Information"). You +/// shall not disclose such Confidential Information and shall use +/// it only in accordance with the terms of the license agreement +/// you entered into with Samsung. + + +using System; +using System.IO; +using System.Runtime.CompilerServices; + +namespace Tizen +{ + /// + /// Provides methods to print log messages to Tizen logging system. + /// + public class Log + { + /// + /// Prints a log message with the DEBUG priority. + /// + /// The tag name of the log message. + /// The log message to print. + /// The source file path of the caller function. This argument will be set automatically by the compiler. + /// The function name of caller function. This argument will be set automatically by the compiler. + /// The line number of calling position. This argument will be set automatically by the compiler. + public static void Debug(string tag, string msg, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0) + { + if (String.IsNullOrEmpty(file)) + { + Interop.Dlog.Print(Interop.Dlog.LogPriority.DLOG_DEBUG, tag, "%s", msg); + } + else + { + Uri f = new Uri(file); + Interop.Dlog.Print(Interop.Dlog.LogPriority.DLOG_DEBUG, tag, "%s: %s(%d) > %s", Path.GetFileName(f.AbsolutePath), func, line, msg); + } + } + + /// + /// Prints a log message with the VERBOSE priority. + /// + /// The tag name of the log message. + /// The log message to print. + /// The source file path of the caller function. This argument will be set automatically by the compiler. + /// The function name of caller function. This argument will be set automatically by the compiler. + /// The line number of calling position. This argument will be set automatically by the compiler. + public static void Verbose(string tag, string msg, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0) + { + if (String.IsNullOrEmpty(file)) + { + Interop.Dlog.Print(Interop.Dlog.LogPriority.DLOG_VERBOSE, tag, "%s", msg); + } + else + { + Uri f = new Uri(file); + Interop.Dlog.Print(Interop.Dlog.LogPriority.DLOG_VERBOSE, tag, "%s: %s(%d) > %s", Path.GetFileName(f.AbsolutePath), func, line, msg); + } + } + + /// + /// Prints a log message with the INFO priority. + /// + /// The tag name of the log message. + /// The log message to print. + /// The source file path of the caller function. This argument will be set automatically by the compiler. + /// The function name of caller function. This argument will be set automatically by the compiler. + /// The line number of calling position. This argument will be set automatically by the compiler. + public static void Info(string tag, string msg, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0) + { + if (String.IsNullOrEmpty(file)) + { + Interop.Dlog.Print(Interop.Dlog.LogPriority.DLOG_INFO, tag, "%s", msg); + } + else + { + Uri f = new Uri(file); + Interop.Dlog.Print(Interop.Dlog.LogPriority.DLOG_INFO, tag, "%s: %s(%d) > %s", Path.GetFileName(f.AbsolutePath), func, line, msg); + } + } + + /// + /// Prints a log message with the WARNING priority. + /// + /// The tag name of the log message. + /// The log message to print. + /// The source file path of the caller function. This argument will be set automatically by the compiler. + /// The function name of caller function. This argument will be set automatically by the compiler. + /// The line number of calling position. This argument will be set automatically by the compiler. + public static void Warn(string tag, string msg, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0) + { + if (String.IsNullOrEmpty(file)) + { + Interop.Dlog.Print(Interop.Dlog.LogPriority.DLOG_WARN, tag, "%s", msg); + } + else + { + Uri f = new Uri(file); + Interop.Dlog.Print(Interop.Dlog.LogPriority.DLOG_WARN, tag, "%s: %s(%d) > %s", Path.GetFileName(f.AbsolutePath), func, line, msg); + } + } + + /// + /// Prints a log message with the ERROR priority. + /// + /// The tag name of the log message. + /// The log message to print. + /// The source file path of the caller function. This argument will be set automatically by the compiler. + /// The function name of caller function. This argument will be set automatically by the compiler. + /// The line number of calling position. This argument will be set automatically by the compiler. + public static void Error(string tag, string msg, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0) + { + if (String.IsNullOrEmpty(file)) + { + Interop.Dlog.Print(Interop.Dlog.LogPriority.DLOG_ERROR, tag, "%s", msg); + } + else + { + Uri f = new Uri(file); + Interop.Dlog.Print(Interop.Dlog.LogPriority.DLOG_ERROR, tag, "%s: %s(%d) > %s", Path.GetFileName(f.AbsolutePath), func, line, msg); + } + } + + /// + /// Prints a log message with the FATAL priority. + /// + /// The tag name of the log message. + /// The log message to print. + /// The source file path of the caller function. This argument will be set automatically by the compiler. + /// The function name of caller function. This argument will be set automatically by the compiler. + /// The line number of calling position. This argument will be set automatically by the compiler. + public static void Fatal(string tag, string msg, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0) + { + if (String.IsNullOrEmpty(file)) + { + Interop.Dlog.Print(Interop.Dlog.LogPriority.DLOG_FATAL, tag, "%s", msg); + } + else + { + Uri f = new Uri(file); + Interop.Dlog.Print(Interop.Dlog.LogPriority.DLOG_FATAL, tag, "%s: %s(%d) > %s", Path.GetFileName(f.AbsolutePath), func, line, msg); + } + } + } +} diff --git a/src/Tizen/LogTraceListener.cs b/src/Tizen/Tizen/LogTraceListener.cs similarity index 77% rename from src/Tizen/LogTraceListener.cs rename to src/Tizen/Tizen/LogTraceListener.cs index 43fe0c7..5b288cc 100755 --- a/src/Tizen/LogTraceListener.cs +++ b/src/Tizen/Tizen/LogTraceListener.cs @@ -1,98 +1,107 @@ -using System; -using System.Text; -using System.Diagnostics; - -namespace Tizen -{ - /// - /// Directs tracing or debugging output to Tizen logging system. - /// - public class LogTraceListener : TraceListener - { - private string tagName = null; - private StringBuilder buf = new StringBuilder(); - - /// - /// Initializes a new instance of the LogTraceListener class, using the specfied tag name of the logging system. - /// - /// The tag name of the log message. - public LogTraceListener(string tag) : base("DLOG") - { - this.tagName = tag; - } - - /// - /// The tag name of the log message. - /// - public string Tag - { - get { return tagName; } - set { tagName = value; } - } - - private void WriteImpl(string message) - { - if (NeedIndent) - { - WriteIndent(); - } - buf.Append(message); - } - - /// - /// Writes an error message to the logging system. - /// - /// The error message to print. - public override void Fail(string message) - { - Fail(message, null); - } - - /// - /// Writes an error message and a detailed error message to the logging system. - /// - /// The error message to print. - /// The detailed error message to print. - public override void Fail(string message, string detailMessage) - { - StringBuilder failBuf = new StringBuilder(); - failBuf.Append("Fail: "); - failBuf.Append(message); - if (!String.IsNullOrEmpty(detailMessage)) - { - failBuf.Append(" "); - failBuf.Append(detailMessage); - } - Log.Error(tagName, failBuf.ToString(), null); - } - - /// - /// Writes a log message to the logging system. - /// - /// The log message to print. - public override void Write(string message) - { - WriteImpl(message); - } - - /// - /// Writes a log message followed by the current line terminator to the logging system. - /// - /// The log message to print. - public override void WriteLine(string message) - { - WriteImpl(message + Environment.NewLine); - NeedIndent = true; - Flush(); - } - - /// - /// Causes buffered data to be written to the logging system. - /// - public override void Flush() - { - Log.Debug(tagName, buf.ToString(), null); - buf.Clear(); - } - } -} +/// Copyright 2016 by Samsung Electronics, Inc., +/// +/// This software is the confidential and proprietary information +/// of Samsung Electronics, Inc. ("Confidential Information"). You +/// shall not disclose such Confidential Information and shall use +/// it only in accordance with the terms of the license agreement +/// you entered into with Samsung. + + +using System; +using System.Text; +using System.Diagnostics; + +namespace Tizen +{ + /// + /// Directs tracing or debugging output to Tizen logging system. + /// + public class LogTraceListener : TraceListener + { + private string _tagName = null; + private readonly StringBuilder _buf = new StringBuilder(); + + /// + /// Initializes a new instance of the LogTraceListener class, using the specfied tag name of the logging system. + /// + /// The tag name of the log message. + public LogTraceListener(string tag) : base("DLOG") + { + _tagName = tag; + } + + /// + /// The tag name of the log message. + /// + public string Tag + { + get { return _tagName; } + set { _tagName = value; } + } + + private void WriteImpl(string message) + { + if (NeedIndent) + { + WriteIndent(); + } + _buf.Append(message); + } + + /// + /// Writes an error message to the logging system. + /// + /// The error message to print. + public override void Fail(string message) + { + Fail(message, null); + } + + /// + /// Writes an error message and a detailed error message to the logging system. + /// + /// The error message to print. + /// The detailed error message to print. + public override void Fail(string message, string detailMessage) + { + StringBuilder failBuf = new StringBuilder(); + failBuf.Append("Fail: "); + failBuf.Append(message); + if (!String.IsNullOrEmpty(detailMessage)) + { + failBuf.Append(" "); + failBuf.Append(detailMessage); + } + Log.Error(_tagName, failBuf.ToString(), null); + } + + /// + /// Writes a log message to the logging system. + /// + /// The log message to print. + public override void Write(string message) + { + WriteImpl(message); + } + + /// + /// Writes a log message followed by the current line terminator to the logging system. + /// + /// The log message to print. + public override void WriteLine(string message) + { + WriteImpl(message + Environment.NewLine); + NeedIndent = true; + Flush(); + } + + /// + /// Causes buffered data to be written to the logging system. + /// + public override void Flush() + { + Log.Debug(_tagName, _buf.ToString(), null); + _buf.Clear(); + } + } +}