Add Tizen.Log and Tizen.LogTraceListener to support dlog system.
Change-Id: Ibe1fd321d3df3a6be1c5abe0997edc585acc5b58
--- /dev/null
+bin/
+obj/
+*.exe
+*.dll
--- /dev/null
+using System.Reflection;\r
+using System.Runtime.CompilerServices;\r
+using System.Runtime.InteropServices;\r
+\r
+[assembly: AssemblyTitle("Tizen")]\r
+[assembly: AssemblyDescription("")]\r
+[assembly: AssemblyConfiguration("")]\r
+[assembly: AssemblyCompany("Samsung Electronics")]\r
+[assembly: AssemblyProduct("Tizen")]\r
+[assembly: AssemblyCopyright("Copyright (c) 2015 Samsung Electronics Co., Ltd")]\r
+[assembly: AssemblyTrademark("")]\r
+[assembly: AssemblyCulture("")]\r
+\r
+[assembly: ComVisible(false)]\r
+\r
+[assembly: Guid("8aa94469-cdb5-4d8c-81d0-df4590eea612")]\r
+\r
+[assembly: AssemblyVersion("1.0.0.0")]\r
+[assembly: AssemblyFileVersion("1.0.0.0")]\r
--- /dev/null
+<manifest>
+ <request>
+ <domain name="_"/>
+ </request>
+</manifest>
--- /dev/null
+Name: csapi-tizen
+Description: Tizen API for C#
+Version: @version@
+Libs: -r:@dllpath@/@dllname@
+Requires:
\ No newline at end of file
--- /dev/null
+%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
--- /dev/null
+using System;\r
+using System.IO;\r
+using System.Runtime.CompilerServices;\r
+\r
+namespace Tizen\r
+{\r
+ /// <summary>\r
+ /// Provides methods to print log messages to Tizen logging system.\r
+ /// </summary>\r
+ public class Log\r
+ {\r
+ /// <summary>\r
+ /// Prints a log message with the DEBUG priority.\r
+ /// </summary>\r
+ /// <param name="tag">The tag name of the log message.</param>\r
+ /// <param name="msg">The log message to print.</param>\r
+ /// <param name="file">The source file path of the caller function. This argument will be set automatically by the compiler.</param>\r
+ /// <param name="func">The function name of caller function. This argument will be set automatically by the compiler.</param>\r
+ /// <param name="line">The line number of calling position. This argument will be set automatically by the compiler.</param>\r
+ public static void Debug(string tag, string msg, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)\r
+ {\r
+ if (String.IsNullOrEmpty(file))\r
+ {\r
+ NativeMethods.DlogPrint(NativeMethods.LogPriority.DLOG_DEBUG, tag, "%s", msg);\r
+ }\r
+ else\r
+ {\r
+ Uri f = new Uri(file);\r
+ NativeMethods.DlogPrint(NativeMethods.LogPriority.DLOG_DEBUG, tag, "%s: %s(%d) > %s", Path.GetFileName(f.AbsolutePath), func, line, msg);\r
+ }\r
+ }\r
+\r
+ /// <summary>\r
+ /// Prints a log message with the VERBOSE priority.\r
+ /// </summary>\r
+ /// <param name="tag">The tag name of the log message.</param>\r
+ /// <param name="msg">The log message to print.</param>\r
+ /// <param name="file">The source file path of the caller function. This argument will be set automatically by the compiler.</param>\r
+ /// <param name="func">The function name of caller function. This argument will be set automatically by the compiler.</param>\r
+ /// <param name="line">The line number of calling position. This argument will be set automatically by the compiler.</param>\r
+ public static void Verbose(string tag, string msg, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)\r
+ {\r
+ if (String.IsNullOrEmpty(file))\r
+ {\r
+ NativeMethods.DlogPrint(NativeMethods.LogPriority.DLOG_VERBOSE, tag, "%s", msg);\r
+ }\r
+ else\r
+ {\r
+ Uri f = new Uri(file);\r
+ NativeMethods.DlogPrint(NativeMethods.LogPriority.DLOG_VERBOSE, tag, "%s: %s(%d) > %s", Path.GetFileName(f.AbsolutePath), func, line, msg);\r
+ }\r
+ }\r
+\r
+ /// <summary>\r
+ /// Prints a log message with the INFO priority.\r
+ /// </summary>\r
+ /// <param name="tag">The tag name of the log message.</param>\r
+ /// <param name="msg">The log message to print.</param>\r
+ /// <param name="file">The source file path of the caller function. This argument will be set automatically by the compiler.</param>\r
+ /// <param name="func">The function name of caller function. This argument will be set automatically by the compiler.</param>\r
+ /// <param name="line">The line number of calling position. This argument will be set automatically by the compiler.</param>\r
+ public static void Info(string tag, string msg, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)\r
+ {\r
+ if (String.IsNullOrEmpty(file))\r
+ {\r
+ NativeMethods.DlogPrint(NativeMethods.LogPriority.DLOG_INFO, tag, "%s", msg);\r
+ }\r
+ else\r
+ {\r
+ Uri f = new Uri(file);\r
+ NativeMethods.DlogPrint(NativeMethods.LogPriority.DLOG_INFO, tag, "%s: %s(%d) > %s", Path.GetFileName(f.AbsolutePath), func, line, msg);\r
+ }\r
+ }\r
+\r
+ /// <summary>\r
+ /// Prints a log message with the WARNING priority.\r
+ /// </summary>\r
+ /// <param name="tag">The tag name of the log message.</param>\r
+ /// <param name="msg">The log message to print.</param>\r
+ /// <param name="file">The source file path of the caller function. This argument will be set automatically by the compiler.</param>\r
+ /// <param name="func">The function name of caller function. This argument will be set automatically by the compiler.</param>\r
+ /// <param name="line">The line number of calling position. This argument will be set automatically by the compiler.</param>\r
+ public static void Warn(string tag, string msg, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)\r
+ {\r
+ if (String.IsNullOrEmpty(file))\r
+ {\r
+ NativeMethods.DlogPrint(NativeMethods.LogPriority.DLOG_WARN, tag, "%s", msg);\r
+ }\r
+ else\r
+ {\r
+ Uri f = new Uri(file);\r
+ NativeMethods.DlogPrint(NativeMethods.LogPriority.DLOG_WARN, tag, "%s: %s(%d) > %s", Path.GetFileName(f.AbsolutePath), func, line, msg);\r
+ }\r
+ }\r
+\r
+ /// <summary>\r
+ /// Prints a log message with the ERROR priority.\r
+ /// </summary>\r
+ /// <param name="tag">The tag name of the log message.</param>\r
+ /// <param name="msg">The log message to print.</param>\r
+ /// <param name="file">The source file path of the caller function. This argument will be set automatically by the compiler.</param>\r
+ /// <param name="func">The function name of caller function. This argument will be set automatically by the compiler.</param>\r
+ /// <param name="line">The line number of calling position. This argument will be set automatically by the compiler.</param>\r
+ public static void Error(string tag, string msg, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)\r
+ {\r
+ if (String.IsNullOrEmpty(file))\r
+ {\r
+ NativeMethods.DlogPrint(NativeMethods.LogPriority.DLOG_ERROR, tag, "%s", msg);\r
+ }\r
+ else\r
+ {\r
+ Uri f = new Uri(file);\r
+ NativeMethods.DlogPrint(NativeMethods.LogPriority.DLOG_ERROR, tag, "%s: %s(%d) > %s", Path.GetFileName(f.AbsolutePath), func, line, msg);\r
+ }\r
+ }\r
+\r
+ /// <summary>\r
+ /// Prints a log message with the FATAL priority.\r
+ /// </summary>\r
+ /// <param name="tag">The tag name of the log message.</param>\r
+ /// <param name="msg">The log message to print.</param>\r
+ /// <param name="file">The source file path of the caller function. This argument will be set automatically by the compiler.</param>\r
+ /// <param name="func">The function name of caller function. This argument will be set automatically by the compiler.</param>\r
+ /// <param name="line">The line number of calling position. This argument will be set automatically by the compiler.</param>\r
+ public static void Fatal(string tag, string msg, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)\r
+ {\r
+ if (String.IsNullOrEmpty(file))\r
+ {\r
+ NativeMethods.DlogPrint(NativeMethods.LogPriority.DLOG_FATAL, tag, "%s", msg);\r
+ }\r
+ else\r
+ {\r
+ Uri f = new Uri(file);\r
+ NativeMethods.DlogPrint(NativeMethods.LogPriority.DLOG_FATAL, tag, "%s: %s(%d) > %s", Path.GetFileName(f.AbsolutePath), func, line, msg);\r
+ }\r
+ }\r
+ }\r
+}\r
--- /dev/null
+using System;\r
+using System.Text;\r
+using System.Diagnostics;\r
+\r
+namespace Tizen\r
+{\r
+ /// <summary>\r
+ /// Directs tracing or debugging output to Tizen logging system.\r
+ /// </summary>\r
+ public class LogTraceListener : TraceListener\r
+ {\r
+ private string tagName = null;\r
+ private StringBuilder buf = new StringBuilder();\r
+\r
+ /// <summary>\r
+ /// Initializes a new instance of the LogTraceListener class, using the specfied tag name of the logging system.\r
+ /// </summary>\r
+ /// <param name="tag">The tag name of the log message.</param>\r
+ public LogTraceListener(string tag) : base("DLOG")\r
+ {\r
+ this.tagName = tag;\r
+ }\r
+\r
+ /// <summary>\r
+ /// The tag name of the log message.\r
+ /// </summary>\r
+ public string Tag\r
+ {\r
+ get { return tagName; }\r
+ set { tagName = value; }\r
+ }\r
+\r
+ private void WriteImpl(string message)\r
+ {\r
+ if (NeedIndent)\r
+ {\r
+ WriteIndent();\r
+ }\r
+ buf.Append(message);\r
+ }\r
+\r
+ /// <summary>\r
+ /// Writes an error message to the logging system.\r
+ /// </summary>\r
+ /// <param name="message">The error message to print.</param>\r
+ public override void Fail(string message)\r
+ {\r
+ Fail(message, null);\r
+ }\r
+\r
+ /// <summary>\r
+ /// Writes an error message and a detailed error message to the logging system.\r
+ /// </summary>\r
+ /// <param name="message">The error message to print.</param>\r
+ /// <param name="detailMessage">The detailed error message to print.</param>\r
+ public override void Fail(string message, string detailMessage)\r
+ {\r
+ StringBuilder failBuf = new StringBuilder();\r
+ failBuf.Append("Fail: ");\r
+ failBuf.Append(message);\r
+ if (!String.IsNullOrEmpty(detailMessage))\r
+ {\r
+ failBuf.Append(" ");\r
+ failBuf.Append(detailMessage);\r
+ }\r
+ Log.Error(tagName, failBuf.ToString(), null);\r
+ }\r
+\r
+ /// <summary>\r
+ /// Writes a log message to the logging system.\r
+ /// </summary>\r
+ /// <param name="message">The log message to print.</param>\r
+ public override void Write(string message)\r
+ {\r
+ WriteImpl(message);\r
+ }\r
+\r
+ /// <summary>\r
+ /// Writes a log message followed by the current line terminator to the logging system.\r
+ /// </summary>\r
+ /// <param name="message">The log message to print.</param>\r
+ public override void WriteLine(string message)\r
+ {\r
+ WriteImpl(message + Environment.NewLine);\r
+ NeedIndent = true;\r
+ Flush();\r
+ }\r
+\r
+ /// <summary>\r
+ /// Causes buffered data to be written to the logging system.\r
+ /// </summary>\r
+ public override void Flush()\r
+ {\r
+ Log.Debug(tagName, buf.ToString(), null);\r
+ buf.Clear();\r
+ }\r
+ }\r
+}\r
--- /dev/null
+using System;\r
+using System.Collections.Generic;\r
+using System.Linq;\r
+using System.Text;\r
+using System.Threading.Tasks;\r
+using System.Runtime.InteropServices;\r
+\r
+namespace Tizen\r
+{\r
+ internal static class NativeMethods\r
+ {\r
+ internal enum LogPriority\r
+ {\r
+ DLOG_UNKNOWN = 0,\r
+ DLOG_DEFAULT,\r
+ DLOG_VERBOSE,\r
+ DLOG_DEBUG,\r
+ DLOG_INFO,\r
+ DLOG_WARN,\r
+ DLOG_ERROR,\r
+ DLOG_FATAL,\r
+ DLOG_SILENT,\r
+ DLOG_PRIO_MAX,\r
+ }\r
+ [DllImportAttribute("libdlog.so.0", EntryPoint = "dlog_print", CallingConvention = CallingConvention.Cdecl)]\r
+ internal static extern int DlogPrint(LogPriority prio, string tag, string fmt, string msg);\r
+\r
+ [DllImportAttribute("libdlog.so.0", EntryPoint = "dlog_print", CallingConvention = CallingConvention.Cdecl)]\r
+ internal static extern int DlogPrint(LogPriority prio, string tag, string fmt, string file, string func, int line, string msg);\r
+ }\r
+}\r
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>\r
+<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+ <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />\r
+ <PropertyGroup>\r
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>\r
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>\r
+ <ProjectGuid>{8AA94469-CDB5-4D8C-81D0-DF4590EEA612}</ProjectGuid>\r
+ <OutputType>Library</OutputType>\r
+ <AppDesignerFolder>Properties</AppDesignerFolder>\r
+ <RootNamespace>\r
+ </RootNamespace>\r
+ <AssemblyName>Tizen</AssemblyName>\r
+ <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>\r
+ <FileAlignment>512</FileAlignment>\r
+ <TargetFrameworkProfile />\r
+ </PropertyGroup>\r
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">\r
+ <DebugSymbols>true</DebugSymbols>\r
+ <DebugType>full</DebugType>\r
+ <Optimize>false</Optimize>\r
+ <OutputPath>bin\Debug\</OutputPath>\r
+ <DefineConstants>DEBUG;TRACE</DefineConstants>\r
+ <ErrorReport>prompt</ErrorReport>\r
+ <WarningLevel>4</WarningLevel>\r
+ <DocumentationFile>bin\Debug\Tizen.XML</DocumentationFile>\r
+ </PropertyGroup>\r
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">\r
+ <DebugType>pdbonly</DebugType>\r
+ <Optimize>true</Optimize>\r
+ <OutputPath>bin\Release\</OutputPath>\r
+ <DefineConstants>TRACE</DefineConstants>\r
+ <ErrorReport>prompt</ErrorReport>\r
+ <WarningLevel>4</WarningLevel>\r
+ </PropertyGroup>\r
+ <PropertyGroup>\r
+ <SignAssembly>true</SignAssembly>\r
+ </PropertyGroup>\r
+ <PropertyGroup>\r
+ <AssemblyOriginatorKeyFile>Tizen.snk</AssemblyOriginatorKeyFile>\r
+ </PropertyGroup>\r
+ <ItemGroup>\r
+ <Reference Include="System" />\r
+ <Reference Include="System.Core" />\r
+ <Reference Include="System.Xml.Linq" />\r
+ <Reference Include="System.Data.DataSetExtensions" />\r
+ <Reference Include="Microsoft.CSharp" />\r
+ <Reference Include="System.Data" />\r
+ <Reference Include="System.Net.Http" />\r
+ <Reference Include="System.Xml" />\r
+ </ItemGroup>\r
+ <ItemGroup>\r
+ <Compile Include="Tizen\NativeMethods.cs" />\r
+ <Compile Include="Tizen\LogTraceListener.cs" />\r
+ <Compile Include="Tizen\Log.cs" />\r
+ <Compile Include="Properties\AssemblyInfo.cs" />\r
+ </ItemGroup>\r
+ <ItemGroup>\r
+ <None Include="Tizen.snk" />\r
+ </ItemGroup>\r
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />\r
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it. \r
+ Other similar extension points exist, see Microsoft.Common.targets.\r
+ <Target Name="BeforeBuild">\r
+ </Target>\r
+ <Target Name="AfterBuild">\r
+ </Target>\r
+ -->\r
+</Project>
\ No newline at end of file