From: WonYoung Choi Date: Mon, 22 Feb 2016 02:43:36 +0000 (+0900) Subject: Add Logging classes to Tizen namespace X-Git-Tag: submit/trunk/20170823.075128~77^2~37 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c02c436890e14ef6e78acb4b898e8e6ff62205ed;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git Add Logging classes to Tizen namespace Add Tizen.Log and Tizen.LogTraceListener to support dlog system. Change-Id: Ibe1fd321d3df3a6be1c5abe0997edc585acc5b58 --- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7d84484 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +bin/ +obj/ +*.exe +*.dll diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs new file mode 100755 index 0000000..dc0c870 --- /dev/null +++ b/Properties/AssemblyInfo.cs @@ -0,0 +1,19 @@ +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")] diff --git a/Tizen.snk b/Tizen.snk new file mode 100755 index 0000000..f83d126 Binary files /dev/null and b/Tizen.snk differ diff --git a/packaging/csapi-tizen.manifest b/packaging/csapi-tizen.manifest new file mode 100644 index 0000000..75b0fa5 --- /dev/null +++ b/packaging/csapi-tizen.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/packaging/csapi-tizen.pc.in b/packaging/csapi-tizen.pc.in new file mode 100644 index 0000000..e0b220a --- /dev/null +++ b/packaging/csapi-tizen.pc.in @@ -0,0 +1,5 @@ +Name: csapi-tizen +Description: Tizen API for C# +Version: @version@ +Libs: -r:@dllpath@/@dllname@ +Requires: \ No newline at end of file diff --git a/packaging/csapi-tizen.spec b/packaging/csapi-tizen.spec new file mode 100644 index 0000000..8301e45 --- /dev/null +++ b/packaging/csapi-tizen.spec @@ -0,0 +1,81 @@ +%define dllpath %{_libdir}/mono/tizen +%define dllname Tizen.dll + +Name: csapi-tizen +Summary: Tizen API for C# +Version: 1.0.0 +Release: 1 +Group: Development/Libraries +License: Apache-2.0 +URL: https://www.tizen.org +Source0: %{name}-%{version}.tar.gz +Source1: %{name}.manifest +Source2: %{name}.pc.in + +# TODO: replace mono-compiler, mono-devel to mcs, mono-shlib-cop +BuildRequires: mono-compiler +BuildRequires: mono-devel +# TODO: replace mono-core to gacutil. +# mono-core should provide the symbol 'gacutil' +Requires(post): mono-core +Requires(postun): mono-core + +# P/Invoke Dependencies +BuildRequires: pkgconfig(dlog) + +# P/Invoke Runtime Dependencies +# TODO: It should be removed after fix tizen-rpm-config +Requires: dlog +# DLL Dependencies +#BuildRequires: ... + +%description +Tizen API for C# + +%package devel +Summary: Development package for %{name} +Group: Development/Libraries +Requires: %{name} = %{version}-%{release} + +%description devel +Development package for %{name} + +%prep +%setup -q + +cp %{SOURCE1} . + +%build +# build dll +mcs -target:library -out:%{dllname} -keyfile:Tizen.snk \ + Properties/AssemblyInfo.cs \ + Tizen/Log.cs \ + Tizen/LogTraceListener.cs + +# check p/invoke +if [ -x %{dllname} ]; then + RET=`mono-shlib-cop %{dllname}`; \ + CNT=`echo $RET | grep -E "^error:" | wc -l`; \ + if [ $CNT -gt 0 ]; then exit 1; fi +fi + +%install +# copy dll +mkdir -p %{buildroot}%{dllpath} +install -p -m 644 %{dllname} %{buildroot}%{dllpath} + +# generate pkgconfig +mkdir -p %{buildroot}%{_libdir}/pkgconfig +sed -e "s#@version@#%{version}#g" \ + -e "s#@dllpath@#%{dllpath}#g" \ + -e "s#@dllname@#%{dllname}#g" \ + %{SOURCE2} > %{buildroot}%{_libdir}/pkgconfig/%{name}.pc + +%post +gacutil -i %{dllpath}/%{dllname} + +%files +%{dllpath}/%{dllname} + +%files devel +%{_libdir}/pkgconfig/%{name}.pc diff --git a/src/Tizen/Log.cs b/src/Tizen/Log.cs new file mode 100755 index 0000000..c0f8170 --- /dev/null +++ b/src/Tizen/Log.cs @@ -0,0 +1,138 @@ +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); + } + } + } +} diff --git a/src/Tizen/LogTraceListener.cs b/src/Tizen/LogTraceListener.cs new file mode 100755 index 0000000..43fe0c7 --- /dev/null +++ b/src/Tizen/LogTraceListener.cs @@ -0,0 +1,98 @@ +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(); + } + } +} diff --git a/src/Tizen/NativeMethods.cs b/src/Tizen/NativeMethods.cs new file mode 100755 index 0000000..b3d3b65 --- /dev/null +++ b/src/Tizen/NativeMethods.cs @@ -0,0 +1,31 @@ +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/tizen.csproj b/tizen.csproj new file mode 100755 index 0000000..7b1b546 --- /dev/null +++ b/tizen.csproj @@ -0,0 +1,68 @@ + + + + + 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 + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file