From: manish.r Date: Thu, 7 Apr 2016 05:33:50 +0000 (+0530) Subject: Code with Doxygen Comments and TCT X-Git-Tag: submit/trunk/20170823.075128~96^2~14 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=94816bf97f620f65f20ec3d135ceba7c53ce8b85;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git Code with Doxygen Comments and TCT Change-Id: Id89cef41e305c3c516b4d997dbaa6f7bd3038661 Signed-off-by: manish.r --- diff --git a/Tizen.Content.MimeType.sln b/Tizen.Content.MimeType.sln new file mode 100755 index 0000000..06aacf0 --- /dev/null +++ b/Tizen.Content.MimeType.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Express 2013 for Windows Desktop +VisualStudioVersion = 12.0.21005.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tizen.Content", "Tizen.Content\Tizen.Content.csproj", "{3EE5842E-7004-43BC-825B-29FFDEC18D4E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {3EE5842E-7004-43BC-825B-29FFDEC18D4E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3EE5842E-7004-43BC-825B-29FFDEC18D4E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3EE5842E-7004-43BC-825B-29FFDEC18D4E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3EE5842E-7004-43BC-825B-29FFDEC18D4E}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Tizen.Content.MimeType.v12.suo b/Tizen.Content.MimeType.v12.suo new file mode 100755 index 0000000..84c10c6 Binary files /dev/null and b/Tizen.Content.MimeType.v12.suo differ diff --git a/packaging/csapi-mime-type.manifest b/packaging/csapi-mime-type.manifest new file mode 100644 index 0000000..75b0fa5 --- /dev/null +++ b/packaging/csapi-mime-type.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/packaging/csapi-mime-type.pc.in b/packaging/csapi-mime-type.pc.in new file mode 100644 index 0000000..8a7a193 --- /dev/null +++ b/packaging/csapi-mime-type.pc.in @@ -0,0 +1,5 @@ +Name: csapi-mime-type +Description: Tizen MimeType API for C# +Version: @version@ +Libs: -r:@dllpath@/@dllname@ +Requires: diff --git a/packaging/csapi-mime-type.spec b/packaging/csapi-mime-type.spec new file mode 100755 index 0000000..fb2b218 --- /dev/null +++ b/packaging/csapi-mime-type.spec @@ -0,0 +1,77 @@ +%define dllpath %{_libdir}/mono/tizen +%define dllname Tizen.Content.MimeType.dll + +Name: csapi-mime-type +Summary: Tizen MimeType 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(glib-2.0) +BuildRequires: pkgconfig(capi-content-mime-type) +BuildRequires: pkgconfig(csapi-tizen) + +%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.Content.MimeType/Tizen.Content.MimeType.snk -pkg:'csapi-tizen'\ + Tizen.Content.MimeType/Properties/AssemblyInfo.cs \ + Tizen.Content.MimeType/Interop/*.cs \ + Tizen.Content.MimeType/Tizen.Content.MimeType/*.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.Content.MimeType/Interop/Interop.Glib.cs b/src/Tizen.Content.MimeType/Interop/Interop.Glib.cs new file mode 100755 index 0000000..b2e3f5c --- /dev/null +++ b/src/Tizen.Content.MimeType/Interop/Interop.Glib.cs @@ -0,0 +1,23 @@ +/// 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.Runtime.InteropServices; + +internal static partial class Interop +{ + internal static partial class Glib + { + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate bool GSourceFunc(IntPtr userData); + + [DllImport(Libraries.Glib, EntryPoint = "g_idle_add", CallingConvention = CallingConvention.Cdecl)] + internal static extern uint IdleAdd(GSourceFunc d, IntPtr data); + } +} diff --git a/src/Tizen.Content.MimeType/Interop/Interop.Libc.cs b/src/Tizen.Content.MimeType/Interop/Interop.Libc.cs new file mode 100755 index 0000000..c968cb2 --- /dev/null +++ b/src/Tizen.Content.MimeType/Interop/Interop.Libc.cs @@ -0,0 +1,20 @@ +/// 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.Runtime.InteropServices; + +internal static partial class Interop +{ + internal static partial class Libc + { + [DllImport(Libraries.Libc, EntryPoint = "free", CallingConvention = CallingConvention.Cdecl)] + internal static extern int Free(IntPtr ptr); + } +} diff --git a/src/Tizen.Content.MimeType/Interop/Interop.Libraries.cs b/src/Tizen.Content.MimeType/Interop/Interop.Libraries.cs new file mode 100755 index 0000000..8fbff9b --- /dev/null +++ b/src/Tizen.Content.MimeType/Interop/Interop.Libraries.cs @@ -0,0 +1,17 @@ +/// 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. + +internal static partial class Interop +{ + internal static partial class Libraries + { + public const string Mime = "libcapi-content-mime-type.so.0"; + public const string Glib = "libglib-2.0.so.0"; + public const string Libc = "libc.so.6"; + } +} diff --git a/src/Tizen.Content.MimeType/Interop/Interop.Mime.cs b/src/Tizen.Content.MimeType/Interop/Interop.Mime.cs new file mode 100755 index 0000000..640719f --- /dev/null +++ b/src/Tizen.Content.MimeType/Interop/Interop.Mime.cs @@ -0,0 +1,20 @@ +using System; +using System.Runtime.InteropServices; + +internal static partial class Interop +{ + internal static partial class Mime + { + [DllImport(Libraries.Mime, EntryPoint = "mime_type_get_mime_type", CallingConvention = CallingConvention.Cdecl)] + internal static extern int GetMime( + [System.Runtime.InteropServices.InAttribute()] + [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPStr)] string file_extension + , out string mime_type); + + [DllImport(Libraries.Mime, EntryPoint = "mime_type_get_file_extension", CallingConvention = CallingConvention.Cdecl)] + internal static extern int GetFile( + [System.Runtime.InteropServices.InAttribute()] + [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPStr)] string mime_type + , out System.IntPtr file_extension, out int length); + } +} \ No newline at end of file diff --git a/src/Tizen.Content.MimeType/Properties/AssemblyInfo.cs b/src/Tizen.Content.MimeType/Properties/AssemblyInfo.cs new file mode 100755 index 0000000..35f4acf --- /dev/null +++ b/src/Tizen.Content.MimeType/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Tizen.Content.MimeType")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Tizen.Content.MimeType")] +[assembly: AssemblyCopyright("Copyright \u00A9 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("99a90243-7db1-4704-a078-3529c2da4e81")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/Tizen.Content.MimeType/Tizen.Content.MimeType.csproj b/src/Tizen.Content.MimeType/Tizen.Content.MimeType.csproj new file mode 100755 index 0000000..eb7ac76 --- /dev/null +++ b/src/Tizen.Content.MimeType/Tizen.Content.MimeType.csproj @@ -0,0 +1,75 @@ + + + + + Debug + AnyCPU + {3EE5842E-7004-43BC-825B-29FFDEC18D4E} + Library + Properties + Tizen.Content.MimeType + Tizen.Content.MimeType + v4.0 + 512 + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + + + Tizen.Content.MimeType.snk + + + + + + + + + + + ..\..\..\..\..\..\..\dll\usr\lib\mono\tizen\Tizen.dll + + + ..\..\..\..\..\..\..\dll\usr\lib\mono\tizen\Tizen.Internals.dll + + + + + + + + + + + + + + + + + + diff --git a/src/Tizen.Content.MimeType/Tizen.Content.MimeType.snk b/src/Tizen.Content.MimeType/Tizen.Content.MimeType.snk new file mode 100755 index 0000000..f3d151d Binary files /dev/null and b/src/Tizen.Content.MimeType/Tizen.Content.MimeType.snk differ diff --git a/src/Tizen.Content.MimeType/Tizen.Content.MimeType/MimeExceptionFactory.cs b/src/Tizen.Content.MimeType/Tizen.Content.MimeType/MimeExceptionFactory.cs new file mode 100755 index 0000000..b543ad6 --- /dev/null +++ b/src/Tizen.Content.MimeType/Tizen.Content.MimeType/MimeExceptionFactory.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Tizen.Content.MimeType +{ + internal class MimeExceptionFactory + { + internal static Exception CreateException(MimeUtil.MimeError err) + { + Exception exp; + switch (err) + { + case MimeUtil.MimeError.InvalidParameter: + { + exp = new ArgumentException("Invalid Parameters Provided"); + break; + } + + case MimeUtil.MimeError.IoError: + { + exp = new SystemException("I/O Error Occured"); + break; + } + case MimeUtil.MimeError.OutOfMemory: + { + exp = new SystemException("Out Of Memory"); + break; + } + default: + { + exp = new InvalidOperationException(""); + break; + } + } + return exp; + } + } +} diff --git a/src/Tizen.Content.MimeType/Tizen.Content.MimeType/MimeUtil.cs b/src/Tizen.Content.MimeType/Tizen.Content.MimeType/MimeUtil.cs new file mode 100755 index 0000000..45ce6f8 --- /dev/null +++ b/src/Tizen.Content.MimeType/Tizen.Content.MimeType/MimeUtil.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Collections.Specialized; +using System.Runtime.InteropServices; + +namespace Tizen.Content.MimeType +{ + /// + /// The MimeUtil API provides functions to map MIME types to file extensions and vice versa. + /// + /// Conversions are provided from file extensions to MIME types and from MIME types to file extensions. + public static class MimeUtil + { + /// + /// Gets the MIME type for the given file extension. + /// The MIME type is 'application/octet-stream' if the given file extension is not associated with specific file formats + /// + /// The file Extension + /// + /// + /// string mimeType = MimeUtil.GetMimeType("png"); + /// + /// + public static string GetMimeType(string fileExtension) + { + string mime; + int res = Interop.Mime.GetMime(fileExtension, out mime); + if (res != (int)MimeError.None) + { + throw MimeExceptionFactory.CreateException((MimeError)res); + } + return mime; + } + + /// + /// Gets file extensions for the given MIME type. + /// + /// If Successfull, return's the list of file extension strings for the given MIME type. + /// The array of file extension are without the leading dot ('.') + /// The mime type + /// + /// + /// IEnumerable extColl = MimeUtil.GetFileExtension("video/mpeg"); + /// foreach ( string obj in extColl ) + /// { + /// Console.WriteLine(obj); + /// } + /// + /// + public static IEnumerable GetFileExtension(string mime) + { + IntPtr extensionArray = IntPtr.Zero; + int length = -1; + int res = Interop.Mime.GetFile(mime, out extensionArray, out length); + if (res != (int)MimeError.None) + { + throw MimeExceptionFactory.CreateException((MimeError)res); + } + IntPtr[] extensionList = new IntPtr[length]; + Marshal.Copy(extensionArray, extensionList, 0, length); + Collection coll = new Collection(); + foreach (IntPtr extension in extensionList) + { + coll.Add(Marshal.PtrToStringAnsi(extension)); + Interop.Libc.Free(extension); + } + Interop.Libc.Free(extensionArray); + return coll; + } + + internal enum MimeError : int + { + None = Tizen.Internals.Errors.ErrorCode.None, /**< Successful */ + InvalidParameter = Tizen.Internals.Errors.ErrorCode.InvalidParameter, /**< Invalid parameter */ + OutOfMemory = Tizen.Internals.Errors.ErrorCode.OutOfMemory, /**< Out of memory */ + IoError = Tizen.Internals.Errors.ErrorCode.IoError, /**< Internal I/O error */ + } + } +}