Implementation of Download module
authoryuvaraj.s <yuvaraj.s@samsung.com>
Mon, 18 Apr 2016 11:47:55 +0000 (17:17 +0530)
committeryuvaraj.s <yuvaraj.s@samsung.com>
Tue, 24 May 2016 11:10:57 +0000 (16:40 +0530)
Change-Id: I1e9d28238a221e6013cdefc8e4c88409701bbd0c
Signed-off-by: yuvaraj.s <yuvaraj.s@samsung.com>
14 files changed:
packaging/csapi-download.pc.in [moved from packaging/csapi-download.in with 100% similarity]
packaging/csapi-download.spec
src/Tizen.Content.Download/Interop/Interop.Download.cs [new file with mode: 0644]
src/Tizen.Content.Download/Interop/Interop.Libc.cs [new file with mode: 0644]
src/Tizen.Content.Download/Interop/Interop.Libraries.cs [new file with mode: 0644]
src/Tizen.Content.Download/Tizen.Content.Download.csproj
src/Tizen.Content.Download/Tizen.Content.Download/DownloadEnumerator.cs [moved from src/Tizen.Content.Download/download/DownloadEnumerator.cs with 87% similarity]
src/Tizen.Content.Download/Tizen.Content.Download/DownloadErrorFactory.cs [new file with mode: 0644]
src/Tizen.Content.Download/Tizen.Content.Download/Notification.cs [new file with mode: 0644]
src/Tizen.Content.Download/Tizen.Content.Download/ProgressChangedEventArgs.cs [new file with mode: 0644]
src/Tizen.Content.Download/Tizen.Content.Download/Request.cs [new file with mode: 0644]
src/Tizen.Content.Download/Tizen.Content.Download/StateChangedEventArgs.cs [new file with mode: 0644]
src/Tizen.Content.Download/download/Notification.cs [deleted file]
src/Tizen.Content.Download/download/Request.cs [deleted file]

index 809637e..645632f 100644 (file)
@@ -24,6 +24,8 @@ Requires(postun): mono-core
 BuildRequires: pkgconfig(glib-2.0)
 BuildRequires: pkgconfig(capi-appfw-application)
 BuildRequires: pkgconfig(capi-web-url-download)
+BuildRequires: pkgconfig(csapi-tizen)
+BuildRequires: pkgconfig(csapi-application)
 
 %description
 Tizen API for C#
@@ -43,9 +45,10 @@ cp %{SOURCE1} .
 
 %build
 # build dll
-mcs -target:library -out:%{dllname} -keyfile:Tizen.Content.Download/Tizen.Content.Download.snk \
+mcs -target:library -out:%{dllname} -keyfile:Tizen.Content.Download/Tizen.Content.Download.snk -pkg:'csapi-tizen' -pkg:'csapi-application'\
   Tizen.Content.Download/Properties/AssemblyInfo.cs \
-  Tizen.Content.Download/download/*.cs
+  Tizen.Content.Download/Tizen.Content.Download/*.cs \
+  Tizen.Content.Download/Interop/*.cs
 
 # check p/invoke
 if [ -x %{dllname} ]; then
diff --git a/src/Tizen.Content.Download/Interop/Interop.Download.cs b/src/Tizen.Content.Download/Interop/Interop.Download.cs
new file mode 100644 (file)
index 0000000..713e6c7
--- /dev/null
@@ -0,0 +1,97 @@
+using System;
+using System.Runtime.InteropServices;
+using Tizen.Applications;
+
+internal static partial class Interop
+{
+    internal static partial class Download
+    {
+        //capi-web-url-download
+        // Request class
+        //Callback delegate for event
+        internal delegate void StateChangedCallback(int requestId, int state, IntPtr userData);
+
+        internal delegate void ProgressChangedCallback(int requestId, ulong receivedSize, IntPtr userData);
+
+        [DllImport(Libraries.Download, EntryPoint = "download_create")]
+        internal static extern int CreateRequest(out int requestId);
+        [DllImport(Libraries.Download, EntryPoint = "download_destroy")]
+        internal static extern int DestroyRequest(int requestId);
+        [DllImport(Libraries.Download, EntryPoint = "download_set_url")]
+        internal static extern int SetUrl(int requestId, string url);
+        [DllImport(Libraries.Download, EntryPoint = "download_get_url")]
+        internal static extern int GetUrl(int requestId, out string url);
+        [DllImport(Libraries.Download, EntryPoint = "download_set_network_type")]
+        internal static extern int SetNetworkType(int requestId, int networkType);
+        [DllImport(Libraries.Download, EntryPoint = "download_get_network_type")]
+        internal static extern int GetNetworkType(int requestId, out int networkType);
+        [DllImport(Libraries.Download, EntryPoint = "download_set_destination")]
+        internal static extern int SetDestination(int requestId, string path);
+        [DllImport(Libraries.Download, EntryPoint = "download_get_destination")]
+        internal static extern int GetDestination(int requestId, out string path);
+        [DllImport(Libraries.Download, EntryPoint = "download_set_file_name")]
+        internal static extern int SetFileName(int requestId, string fileName);
+        [DllImport(Libraries.Download, EntryPoint = "download_get_file_name")]
+        internal static extern int GetFileName(int requestId, out string path);
+        [DllImport(Libraries.Download, EntryPoint = "download_set_auto_download")]
+        internal static extern int SetAutoDownload(int requestId, bool value);
+        [DllImport(Libraries.Download, EntryPoint = "download_get_auto_download")]
+        internal static extern int GetAutoDownload(int requestId, out bool value);
+        [DllImport(Libraries.Download, EntryPoint = "download_set_temp_file_path")]
+        internal static extern int SetTempFilePath(int requestId, string tempPath);
+        [DllImport(Libraries.Download, EntryPoint = "download_get_temp_path")]
+        internal static extern int GetTempFilePath(int requestId, out string tempPath);
+        [DllImport(Libraries.Download, EntryPoint = "download_add_http_header_field")]
+        internal static extern int AddHttpHeaderField(int requestId, string field, string value);
+        [DllImport(Libraries.Download, EntryPoint = "download_get_http_header_field")]
+        internal static extern int GetHttpHeaderField(int requestId, string field, out string value);
+        [DllImport(Libraries.Download, EntryPoint = "download_get_http_header_field_list")]
+        internal static extern int GetHttpHeaderFieldList(int requestId, out IntPtr field, out int length);
+        [DllImport(Libraries.Download, EntryPoint = "download_get_downloaded_file_path")]
+        internal static extern int GetDownloadedPath(int requestId, out string downloadedPath);
+        [DllImport(Libraries.Download, EntryPoint = "download_get_mime_type")]
+        internal static extern int GetMimeType(int requestId, out string mimeType);
+        [DllImport(Libraries.Download, EntryPoint = "download_get_state")]
+        internal static extern int GetState(int requestId, out int downloadState);
+        [DllImport(Libraries.Download, EntryPoint = "download_get_content_name")]
+        internal static extern int GetContentName(int requestId, out string contentName);
+        [DllImport(Libraries.Download, EntryPoint = "download_get_content_size")]
+        internal static extern int GetContentSize(int requestId, out ulong size);
+        [DllImport(Libraries.Download, EntryPoint = "download_get_http_status")]
+        internal static extern int GetHttpStatus(int requestId, out int httpStatus);
+        [DllImport(Libraries.Download, EntryPoint = "download_get_etag")]
+        internal static extern int GetETag(int requestId, out string etag);
+        [DllImport(Libraries.Download, EntryPoint = "download_start")]
+        internal static extern int StartDownload(int requestId);
+        [DllImport(Libraries.Download, EntryPoint = "download_pause")]
+        internal static extern int PauseDownload(int requestId);
+        [DllImport(Libraries.Download, EntryPoint = "download_cancel")]
+        internal static extern int CancelDownload(int requestId);
+        [DllImport(Libraries.Download, EntryPoint = "download_set_state_changed_cb")]
+        internal static extern int SetStateChangedCallback(int requestId, StateChangedCallback callback, IntPtr userData);
+        [DllImport(Libraries.Download, EntryPoint = "download_unset_state_changed_cb")]
+        internal static extern int UnsetStateChangedCallback(int requestId);
+        [DllImport(Libraries.Download, EntryPoint = "download_set_progress_cb")]
+        internal static extern int SetProgressCallback(int requestId, ProgressChangedCallback callback, IntPtr userData);
+        [DllImport(Libraries.Download, EntryPoint = "download_unset_progress_cb")]
+        internal static extern int UnsetProgressCallback(int requestId);
+
+        // Notification class
+        [DllImport(Libraries.Download, EntryPoint = "download_set_notification_title")]
+        internal static extern int SetNotificationTitle(int requestId, string title);
+        [DllImport(Libraries.Download, EntryPoint = "download_get_notification_title")]
+        internal static extern int GetNotificationTitle(int requestId, out string title);
+        [DllImport(Libraries.Download, EntryPoint = "download_set_notification_description")]
+        internal static extern int SetNotificationDescription(int requestId, string description);
+        [DllImport(Libraries.Download, EntryPoint = "download_get_notification_description")]
+        internal static extern int GetNotificationDescription(int requestId, out string description);
+        [DllImport(Libraries.Download, EntryPoint = "download_set_notification_type")]
+        internal static extern int SetNotificationType(int requestId, int type);
+        [DllImport(Libraries.Download, EntryPoint = "download_get_notification_type")]
+        internal static extern int GetNotificationType(int requestId, out int type);
+        [DllImport(Libraries.Download, EntryPoint = "download_set_notification_app_control")]
+        internal static extern int SetNotificationAppControl(int requestId, int appControlType, SafeAppControlHandle handle);
+        [DllImport(Libraries.Download, EntryPoint = "download_get_notification_app_control")]
+        internal static extern int GetNotificationAppControl(int requestId, int appControlType, out SafeAppControlHandle handle);
+    }
+}
diff --git a/src/Tizen.Content.Download/Interop/Interop.Libc.cs b/src/Tizen.Content.Download/Interop/Interop.Libc.cs
new file mode 100644 (file)
index 0000000..674ca1d
--- /dev/null
@@ -0,0 +1,19 @@
+// 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.Download/Interop/Interop.Libraries.cs b/src/Tizen.Content.Download/Interop/Interop.Libraries.cs
new file mode 100644 (file)
index 0000000..8b8311e
--- /dev/null
@@ -0,0 +1,16 @@
+/// 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 Download = "libcapi-web-url-download.so.0";
+        public const string Libc = "libc.so.6";
+    }
+}
index c534785..8aa14be 100644 (file)
@@ -9,7 +9,7 @@
     <AppDesignerFolder>Properties</AppDesignerFolder>\r
     <RootNamespace>Tizen.Content.Download</RootNamespace>\r
     <AssemblyName>Tizen.Content.Download</AssemblyName>\r
-    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>\r
+    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>\r
     <FileAlignment>512</FileAlignment>\r
     <TargetFrameworkProfile />\r
   </PropertyGroup>\r
@@ -21,6 +21,7 @@
     <DefineConstants>DEBUG;TRACE</DefineConstants>\r
     <ErrorReport>prompt</ErrorReport>\r
     <WarningLevel>4</WarningLevel>\r
+    <Prefer32Bit>false</Prefer32Bit>\r
   </PropertyGroup>\r
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">\r
     <DebugType>pdbonly</DebugType>\r
@@ -29,6 +30,7 @@
     <DefineConstants>TRACE</DefineConstants>\r
     <ErrorReport>prompt</ErrorReport>\r
     <WarningLevel>4</WarningLevel>\r
+    <Prefer32Bit>false</Prefer32Bit>\r
   </PropertyGroup>\r
   <PropertyGroup>\r
     <SignAssembly>true</SignAssembly>\r
     <Reference Include="Microsoft.CSharp" />\r
     <Reference Include="System.Data" />\r
     <Reference Include="System.Xml" />\r
+    <Reference Include="Tizen">\r
+      <HintPath>..\..\..\..\..\Desktop\dll\usr\lib\mono\tizen\Tizen.dll</HintPath>\r
+    </Reference>\r
+    <Reference Include="Tizen.Applications">\r
+      <HintPath>..\..\..\..\..\Desktop\dll\applicationdll\usr\lib\mono\tizen\Tizen.Applications.dll</HintPath>\r
+    </Reference>\r
+    <Reference Include="Tizen.Internals">\r
+      <HintPath>..\..\..\..\..\Desktop\dll\usr\lib\mono\tizen\Tizen.Internals.dll</HintPath>\r
+    </Reference>\r
   </ItemGroup>\r
   <ItemGroup>\r
-    <Compile Include="Class1.cs" />\r
+    <Compile Include="Tizen.Content.Download\DownloadEnumerator.cs" />\r
+    <Compile Include="Tizen.Content.Download\Notification.cs" />\r
+    <Compile Include="Tizen.Content.Download\Request.cs" />\r
+    <Compile Include="Tizen.Content.Download\StateChangedEventArgs.cs" />\r
+    <Compile Include="Tizen.Content.Download\ProgressChangedEventArgs.cs" />\r
+    <Compile Include="Tizen.Content.Download\DownloadErrorFactory.cs" />\r
+    <Compile Include="Interop\Interop.Download.cs" />\r
+    <Compile Include="Interop\Interop.Libc.cs" />\r
+    <Compile Include="Interop\Interop.Libraries.cs" />\r
     <Compile Include="Properties\AssemblyInfo.cs" />\r
   </ItemGroup>\r
   <ItemGroup>\r
@@ -60,4 +79,4 @@
   <Target Name="AfterBuild">\r
   </Target>\r
   -->\r
-</Project>
\ No newline at end of file
+</Project>\r
@@ -1,7 +1,4 @@
 using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
 
 namespace Tizen.Content.Download
 {
@@ -13,7 +10,7 @@ namespace Tizen.Content.Download
         /// <summary>
         /// Unhandled exception
         /// <summary>
-        None,
+        None = 0,
         /// <summary>
         /// Ready to download
         /// <summary>
@@ -52,7 +49,7 @@ namespace Tizen.Content.Download
         /// <summary>
         /// Download is available through data network
         /// <summary>
-        DataNetwork,
+        DataNetwork = 0,
         /// <summary>
         /// Download is available through WiFi
         /// <summary>
@@ -75,7 +72,7 @@ namespace Tizen.Content.Download
         /// <summary>
         /// Do not register notification
         /// <summary>
-        None,
+        None = 0,
         /// <summary>
         /// Completion notification for success state and failed state
         /// <summary>
@@ -85,5 +82,15 @@ namespace Tizen.Content.Download
         /// <summary>
         All
     }
-}
 
+    internal enum NotificationAppControlType
+    {
+        Downloading = 0,
+        Completed,
+        Failed
+    }
+    static internal class Downloads
+    {
+        internal const string LogTag = "Tizen.Content.Download";
+    }
+}
diff --git a/src/Tizen.Content.Download/Tizen.Content.Download/DownloadErrorFactory.cs b/src/Tizen.Content.Download/Tizen.Content.Download/DownloadErrorFactory.cs
new file mode 100644 (file)
index 0000000..ea1fec0
--- /dev/null
@@ -0,0 +1,78 @@
+using System;
+using Tizen.Internals.Errors;
+
+namespace Tizen.Content.Download
+{
+    internal enum DownloadError
+    {
+        DownloadErrorCommonCode = -0x02A00000,
+        None = ErrorCode.None,
+        InvalidParameter = ErrorCode.InvalidParameter,
+        OutOfMemory = ErrorCode.OutOfMemory,
+        NetworkUnreachable = ErrorCode.NetworkUnreachable,
+        ConnectionTimedOut = ErrorCode.ConnectionTimeout,
+        NoSpace = ErrorCode.FileNoSpaceOnDevice,
+        PermissionDenied = ErrorCode.PermissionDenied,
+        NotSupported = ErrorCode.NotSupported,
+        InvalidState = DownloadErrorCommonCode | 0x21,
+        ConnectionFailed = DownloadErrorCommonCode | 0x22,
+        InvalidUrl = DownloadErrorCommonCode | 0x24,
+        InvalidDestination = DownloadErrorCommonCode | 0x25,
+        TooManyDownloads = DownloadErrorCommonCode | 0x26,
+        QueueFull = DownloadErrorCommonCode | 0x27,
+        AlreadyCompleted = DownloadErrorCommonCode | 0x28,
+        FileAlreadyExists = DownloadErrorCommonCode | 0x29,
+        CannotResume = DownloadErrorCommonCode | 0x2a,
+        FieldNotFound = DownloadErrorCommonCode | 0x2b,
+        TooManyRedirects = DownloadErrorCommonCode | 0x30,
+        UnhandledHttpCode = DownloadErrorCommonCode | 0x31,
+        RequestTimeout = DownloadErrorCommonCode | 0x32,
+        ResponseTimeout = DownloadErrorCommonCode | 0x33,
+        SystemDown = DownloadErrorCommonCode | 0x34,
+        IdNotFound = DownloadErrorCommonCode | 0x35,
+        InvalidNetworkType = DownloadErrorCommonCode | 0x36,
+        NoData = ErrorCode.NoData,
+        IoError = ErrorCode.IoError
+    }
+
+    internal static class DownloadErrorFactory
+    {
+        internal static void ThrowException(int errorCode, string errorMessage = null, string paramName = null)
+        {
+            DownloadError err = (DownloadError)errorCode;
+            if (String.IsNullOrEmpty(errorMessage))
+            {
+                errorMessage = err.ToString();
+            }
+            switch ((DownloadError)errorCode)
+            {
+                case DownloadError.InvalidParameter:
+                case DownloadError.InvalidUrl:
+                case DownloadError.InvalidDestination:
+                case DownloadError.InvalidNetworkType: throw new ArgumentException(errorMessage, paramName);
+                case DownloadError.OutOfMemory:
+                case DownloadError.NetworkUnreachable:
+                case DownloadError.ConnectionTimedOut:
+                case DownloadError.NoSpace:
+                case DownloadError.PermissionDenied:
+                case DownloadError.NotSupported:
+                case DownloadError.InvalidState:
+                case DownloadError.ConnectionFailed:
+                case DownloadError.TooManyDownloads:
+                case DownloadError.QueueFull:
+                case DownloadError.AlreadyCompleted:
+                case DownloadError.FileAlreadyExists:
+                case DownloadError.CannotResume:
+                case DownloadError.FieldNotFound:
+                case DownloadError.TooManyRedirects:
+                case DownloadError.UnhandledHttpCode:
+                case DownloadError.RequestTimeout:
+                case DownloadError.ResponseTimeout:
+                case DownloadError.SystemDown:
+                case DownloadError.IdNotFound:
+                case DownloadError.NoData:
+                case DownloadError.IoError: throw new InvalidOperationException(errorMessage);
+            }
+        }
+    }
+}
diff --git a/src/Tizen.Content.Download/Tizen.Content.Download/Notification.cs b/src/Tizen.Content.Download/Tizen.Content.Download/Notification.cs
new file mode 100644 (file)
index 0000000..b66d892
--- /dev/null
@@ -0,0 +1,189 @@
+using System;
+using Tizen.Applications;
+
+namespace Tizen.Content.Download
+{
+    /// <summary>
+    /// The Notification class consists of all the properties required to set notifications for download operation.
+    /// </summary>
+    public class Notification
+    {
+        private int _downloadId;
+
+        public Notification(int requestId)
+        {
+            _downloadId = requestId;
+        }
+        /// <summary>
+        /// Title of the notification.
+        /// If user tries to get before setting, empty string is returned.
+        /// </summary>
+        public string Title
+        {
+            get
+            {
+                string title;
+                int ret = Interop.Download.GetNotificationTitle(_downloadId, out title);
+                if (ret != (int)DownloadError.None)
+                {
+                    Log.Error(Downloads.LogTag, "Failed to get Notification Title, " + (DownloadError)ret);
+                    return String.Empty;
+                }
+                return title;
+            }
+            set
+            {
+                int ret = Interop.Download.SetNotificationTitle(_downloadId, value.ToString());
+                if (ret != (int)DownloadError.None)
+                {
+                    DownloadErrorFactory.ThrowException(ret, "Failed to set Notification Title");
+                }
+            }
+        }
+
+        /// <summary>
+        /// Description of the notification.
+        /// If user tries to get before setting, empty string is returned.
+        /// </summary>
+        public string Description
+        {
+            get
+            {
+                string description;
+                int ret = Interop.Download.GetNotificationDescription(_downloadId, out description);
+                if (ret != (int)DownloadError.None)
+                {
+                    Log.Error(Downloads.LogTag, "Failed to get Notification Description, " + (DownloadError)ret);
+                    return String.Empty;
+                }
+                return description;
+            }
+            set
+            {
+                int ret = Interop.Download.SetNotificationDescription(_downloadId, value.ToString());
+                if (ret != (int)DownloadError.None)
+                {
+                    DownloadErrorFactory.ThrowException(ret, "Failed to set Notification Description");
+                }
+            }
+        }
+
+        /// <summary>
+        /// Type of Notification.
+        /// If user tries to get before setting, default NotificationType None is returned.
+        /// </summary>
+        public NotificationType Type
+        {
+            get
+            {
+                int type;
+                int ret = Interop.Download.GetNotificationType(_downloadId, out type);
+                if (ret != (int)DownloadError.None)
+                {
+                    Log.Error(Downloads.LogTag, "Failed to get NotificationType, " + (DownloadError)ret);
+                    return 0;
+                }
+                return (NotificationType)type;
+            }
+            set
+            {
+                int ret = Interop.Download.SetNotificationType(_downloadId, (int)value);
+                if (ret != (int)DownloadError.None)
+                {
+                    DownloadErrorFactory.ThrowException(ret, "Failed to set NotificationType");
+                }
+            }
+        }
+
+        /// <summary>
+        /// AppControl for an ongoing download notification.
+        /// If user tries to get before setting, null is returned.
+        /// </summary>
+        /// <remarks>
+        /// When the notification message is clicked, the action is decided by the app control.
+        /// </remarks>
+        public AppControl AppControlOngoing
+        {
+            get
+            {
+                SafeAppControlHandle handle;
+                int ret = Interop.Download.GetNotificationAppControl(_downloadId, (int)NotificationAppControlType.Downloading, out handle);
+                if (ret != (int)DownloadError.None)
+                {
+                    Log.Error(Downloads.LogTag, "Failed to get Ongoing type NotificationAppControl, " + (DownloadError)ret);
+                    return null;
+                }
+                return new AppControl(handle);
+            }
+            set
+            {
+                int ret = Interop.Download.SetNotificationAppControl(_downloadId, (int)NotificationAppControlType.Downloading, value.SafeAppControlHandle);
+                if (ret != (int)DownloadError.None)
+                {
+                    DownloadErrorFactory.ThrowException(ret, "Failed to set Ongoing type NotificationAppControl");
+                }
+            }
+        }
+
+        /// <summary>
+        /// AppControl for a completed download notification.
+        /// If user tries to get before setting, null is returned.
+        /// </summary>
+        /// <remarks>
+        /// When the notification message is clicked, the action is decided by the app control
+        /// </remarks>
+        public AppControl AppControlCompleted
+        {
+            get
+            {
+                SafeAppControlHandle handle;
+                int ret = Interop.Download.GetNotificationAppControl(_downloadId, (int)NotificationAppControlType.Completed, out handle);
+                if (ret != (int)DownloadError.None)
+                {
+                    Log.Error(Downloads.LogTag, "Failed to get Complete type NotificationAppControl, " + (DownloadError)ret);
+                    return null;
+                }
+                return new AppControl(handle);
+            }
+            set
+            {
+                int ret = Interop.Download.SetNotificationAppControl(_downloadId, (int)NotificationAppControlType.Completed, value.SafeAppControlHandle);
+                if (ret != (int)DownloadError.None)
+                {
+                    DownloadErrorFactory.ThrowException(ret, "Failed to set Complete type NotificationAppControl");
+                }
+            }
+        }
+
+        /// <summary>
+        /// AppControl for a failed download notification.
+        /// If user tries to get before setting, null is returned.
+        /// </summary>
+        /// <remarks>
+        /// When the notification message is clicked, the action is decided by the app control
+        /// </remarks>
+        public AppControl AppControlFailed
+        {
+            get
+            {
+                SafeAppControlHandle handle;
+                int ret = Interop.Download.GetNotificationAppControl(_downloadId, (int)NotificationAppControlType.Failed, out handle);
+                if (ret != (int)DownloadError.None)
+                {
+                    Log.Error(Downloads.LogTag, "Failed to get Fail type NotificationAppControl, " + (DownloadError)ret);
+                    return null;
+                }
+                return new AppControl(handle);
+            }
+            set
+            {
+                int ret = Interop.Download.SetNotificationAppControl(_downloadId, (int)NotificationAppControlType.Failed, value.SafeAppControlHandle);
+                if (ret != (int)DownloadError.None)
+                {
+                    DownloadErrorFactory.ThrowException(ret, "Failed to set Fail type NotificationAppControl");
+                }
+            }
+        }
+    }
+}
+
diff --git a/src/Tizen.Content.Download/Tizen.Content.Download/ProgressChangedEventArgs.cs b/src/Tizen.Content.Download/Tizen.Content.Download/ProgressChangedEventArgs.cs
new file mode 100644 (file)
index 0000000..655337e
--- /dev/null
@@ -0,0 +1,27 @@
+using System;
+
+namespace Tizen.Content.Download
+{
+    /// <summary>
+    /// An extended EventArgs class which contains the size of received data in bytes.
+    /// </summary>
+    public class ProgressChangedEventArgs : EventArgs
+    {
+        private ulong _size = 0;
+
+        internal ProgressChangedEventArgs(ulong size)
+        {
+            _size = size;
+        }
+        /// <summary>
+        /// Received data size in bytes.
+        /// </summary>
+        public ulong ReceivedDataSize
+        {
+            get
+            {
+                return _size;
+            }
+        }
+    }
+}
diff --git a/src/Tizen.Content.Download/Tizen.Content.Download/Request.cs b/src/Tizen.Content.Download/Tizen.Content.Download/Request.cs
new file mode 100644 (file)
index 0000000..a772bc8
--- /dev/null
@@ -0,0 +1,723 @@
+using System;
+using System.Collections.Generic;
+using System.Runtime.InteropServices;
+
+namespace Tizen.Content.Download
+{
+    /// <summary>
+    /// The Request class provides functions to create and manage a single download request.
+    /// </summary>
+    public class Request : IDisposable
+    {
+        private int _downloadId;
+        private Notification _notificationProperties;
+        private EventHandler<StateChangedEventArgs> _downloadStateChanged;
+        private Interop.Download.StateChangedCallback _downloadStateChangedCallback;
+        private EventHandler<ProgressChangedEventArgs> _downloadProgressChanged;
+        private Interop.Download.ProgressChangedCallback _downloadProgressChangedCallback;
+        private bool _disposed = false;
+        /// <summary>
+        /// Creates a Request object.
+        /// </summary>
+        /// <param name="url"> URL to download</param>
+        public Request(string url)
+        {
+            if (String.IsNullOrEmpty(url))
+            {
+                DownloadErrorFactory.ThrowException((int)DownloadError.InvalidParameter, "url cannot be null or empty");
+            }
+            int ret = Interop.Download.CreateRequest(out _downloadId);
+            if (ret != (int)DownloadError.None)
+            {
+                DownloadErrorFactory.ThrowException(ret, "Request creation failed");
+            }
+            ret = Interop.Download.SetUrl(_downloadId, url);
+            if (ret != (int)DownloadError.None)
+            {
+                DownloadErrorFactory.ThrowException(ret, "Setting Url failed");
+            }
+            _notificationProperties = new Notification(_downloadId);
+        }
+
+        /// <summary>
+        /// Creates a Request object.
+        /// </summary>
+        /// <param name="url"> URL to download</param>
+        /// <param name="destinationPath"> Directory path where downloaded file is stored </param>
+        /// <param name="fileName"> Name of the downloaded file </param>
+        /// <param name="type"> Network type which the download request must adhere to </param>
+        public Request(string url, string destinationPath, string fileName, NetworkType type)
+        {
+            if (String.IsNullOrEmpty(url))
+            {
+                DownloadErrorFactory.ThrowException((int)DownloadError.InvalidParameter, "url cannot be null or empty");
+            }
+            int ret = Interop.Download.CreateRequest(out _downloadId);
+            if (ret != (int)DownloadError.None)
+            {
+                DownloadErrorFactory.ThrowException(ret, "Request creation failed");
+            }
+
+            ret = Interop.Download.SetUrl(_downloadId, url);
+            if (ret != (int)DownloadError.None)
+            {
+                DownloadErrorFactory.ThrowException(ret, "Setting Url failed");
+            }
+
+            ret = Interop.Download.SetDestination(_downloadId, destinationPath);
+            if (ret != (int)DownloadError.None)
+            {
+                DownloadErrorFactory.ThrowException(ret, "Setting DestinationPath failed");
+            }
+
+            ret = Interop.Download.SetFileName(_downloadId, fileName);
+            if (ret != (int)DownloadError.None)
+            {
+                DownloadErrorFactory.ThrowException(ret, "Setting FileName failed");
+            }
+
+            ret = Interop.Download.SetNetworkType(_downloadId, (int)type);
+            if (ret != (int)DownloadError.None)
+            {
+                DownloadErrorFactory.ThrowException(ret, "Setting NetworkType failed");
+            }
+
+            _notificationProperties = new Notification(_downloadId);
+        }
+
+        /// <summary>
+        /// Creates a Request object.
+        /// </summary>
+        /// <param name="url"> URL to download</param>
+        /// <param name="destinationPath"> Directory path where downloaded file is stored </param>
+        /// <param name="fileName"> Name of the downloaded file </param>
+        /// <param name="type"> Network type which the download request must adhere to </param>
+        /// <param name="httpHeaders"> HTTP header fields for download request </param>
+        public Request(string url, string destinationPath, string fileName, NetworkType type, IDictionary<string, string> httpHeaders)
+        {
+            if (String.IsNullOrEmpty(url))
+            {
+                DownloadErrorFactory.ThrowException((int)DownloadError.InvalidParameter, "url cannot be null or empty");
+            }
+            int ret = Interop.Download.CreateRequest(out _downloadId);
+            if (ret != (int)DownloadError.None)
+            {
+                DownloadErrorFactory.ThrowException(ret, "Request creation failed");
+            }
+
+            ret = Interop.Download.SetUrl(_downloadId, url);
+            if (ret != (int)DownloadError.None)
+            {
+                DownloadErrorFactory.ThrowException(ret, "Setting Url failed");
+            }
+
+            ret = Interop.Download.SetDestination(_downloadId, destinationPath);
+            if (ret != (int)DownloadError.None)
+            {
+                DownloadErrorFactory.ThrowException(ret, "Setting DestinationPath failed");
+            }
+
+            ret = Interop.Download.SetFileName(_downloadId, fileName);
+            if (ret != (int)DownloadError.None)
+            {
+                DownloadErrorFactory.ThrowException(ret, "Setting FileName failed");
+            }
+
+            ret = Interop.Download.SetNetworkType(_downloadId, (int)type);
+            if (ret != (int)DownloadError.None)
+            {
+                DownloadErrorFactory.ThrowException(ret, "Setting NetworkType failed");
+            }
+
+            foreach (KeyValuePair<string, string> entry in httpHeaders)
+            {
+                ret = Interop.Download.AddHttpHeaderField(_downloadId, entry.Key, entry.Value);
+                if (ret != (int)DownloadError.None)
+                {
+                    DownloadErrorFactory.ThrowException(ret, "Adding HttpHeaderField failed");
+                }
+            }
+
+            _notificationProperties = new Notification(_downloadId);
+        }
+
+        ~Request()
+        {
+            Dispose(false);
+        }
+
+        /// <summary>
+        /// Releases all resources used by the Request class.
+        /// </summary>
+        public void Dispose()
+        {
+            Dispose(true);
+            GC.SuppressFinalize(this);
+        }
+
+        /// <summary>
+        /// Deletes the corresponding download request.
+        /// </summary>
+        protected virtual void Dispose(bool disposing)
+        {
+            if (_disposed)
+                return;
+
+            if (disposing)
+            {
+                // Free managed objects.
+            }
+            Interop.Download.DestroyRequest(_downloadId);
+            _disposed = true;
+        }
+
+        /// <summary>
+        /// Event that occurs when the download state changes.
+        /// </summary>
+        public event EventHandler<StateChangedEventArgs> StateChanged
+        {
+            add
+            {
+                if (_downloadStateChanged == null)
+                {
+                    RegisterStateChangedEvent();
+                }
+                _downloadStateChanged += value;
+            }
+            remove
+            {
+                _downloadStateChanged -= value;
+                if (_downloadStateChanged == null)
+                {
+                    UnregisterStateChangedEvent();
+                }
+            }
+        }
+
+        private void RegisterStateChangedEvent()
+        {
+            _downloadStateChangedCallback = (int downloadId, int downloadState, IntPtr userData) =>
+            {
+                StateChangedEventArgs eventArgs = new StateChangedEventArgs((DownloadState)downloadState);
+                _downloadStateChanged.Invoke(this, eventArgs);
+            };
+            int ret = Interop.Download.SetStateChangedCallback(_downloadId, _downloadStateChangedCallback, IntPtr.Zero);
+            if (ret != (int)DownloadError.None)
+            {
+                DownloadErrorFactory.ThrowException(ret, "Setting StateChanged callback failed");
+            }
+        }
+
+        private void UnregisterStateChangedEvent()
+        {
+            int ret = Interop.Download.UnsetStateChangedCallback(_downloadId);
+            if (ret != (int)DownloadError.None)
+            {
+                DownloadErrorFactory.ThrowException(ret, "Unsetting StateChanged callback failed");
+            }
+        }
+        /// <summary>
+        /// Event that occurs when the download progress changes.
+        /// </summary>
+        public event EventHandler<ProgressChangedEventArgs> ProgressChanged
+        {
+            add
+            {
+                if (_downloadProgressChanged == null)
+                {
+                    RegisterProgressChangedEvent();
+                }
+                _downloadProgressChanged += value;
+            }
+            remove
+            {
+                _downloadProgressChanged -= value;
+                if (_downloadProgressChanged == null)
+                {
+                    UnregisterProgressChangedEvent();
+                }
+            }
+        }
+
+        private void RegisterProgressChangedEvent()
+        {
+            _downloadProgressChangedCallback = (int downloadId, ulong size, IntPtr userData) =>
+            {
+                ProgressChangedEventArgs eventArgs = new ProgressChangedEventArgs(size);
+                _downloadProgressChanged.Invoke(this, eventArgs);
+            };
+            int ret = Interop.Download.SetProgressCallback(_downloadId, _downloadProgressChangedCallback, IntPtr.Zero);
+            if (ret != (int)DownloadError.None)
+            {
+                DownloadErrorFactory.ThrowException(ret, "Setting ProgressChanged callback failed");
+            }
+        }
+
+        private void UnregisterProgressChangedEvent()
+        {
+            int ret = Interop.Download.UnsetProgressCallback(_downloadId);
+            if (ret != (int)DownloadError.None)
+            {
+                DownloadErrorFactory.ThrowException(ret, "Unsetting ProgressChanged callback failed");
+            }
+        }
+
+        /// <summary>
+        /// Absolute path where the file will be downloaded.
+        /// If you try to get this property value before calling Start(), an empty string is returned.
+        /// </summary>
+        /// <remarks>
+        /// Returns empty string if download is not completed or if state has not yet changed to Completed or if any other error occurs.
+        /// </remarks>
+        public string DownloadedPath
+        {
+            get
+            {
+                string path;
+                int ret = Interop.Download.GetDownloadedPath(_downloadId, out path);
+                if (ret != (int)DownloadError.None)
+                {
+                    Log.Error(Downloads.LogTag, "Failed to get DownloadedPath, " + (DownloadError)ret);
+                    return String.Empty;
+                }
+                return path;
+            }
+        }
+
+        /// <summary>
+        /// MIME type of the downloaded content.
+        /// If you try to get this property value before calling Start(), an empty string is returned.
+        /// </summary>
+        public string MimeType
+        {
+            get
+            {
+                string mime;
+                int ret = Interop.Download.GetMimeType(_downloadId, out mime);
+                if (ret != (int)DownloadError.None)
+                {
+                    Log.Error(Downloads.LogTag, "Failed to get MimeType, " + (DownloadError)ret);
+                    return String.Empty;
+                }
+                return mime;
+            }
+        }
+
+        /// <summary>
+        /// Current state of the download.
+        /// </summary>
+        public DownloadState State
+        {
+            get
+            {
+                int state;
+                int ret = Interop.Download.GetState(_downloadId, out state);
+                if (ret != (int)DownloadError.None)
+                {
+                    Log.Error(Downloads.LogTag, "Failed to get DownloadState, " + (DownloadError)ret);
+                    return DownloadState.None;
+                }
+                return (DownloadState)state;
+            }
+        }
+
+        /// <summary>
+        /// Content name of the downloaded file.
+        /// This can be defined with reference of HTTP response header data. The content name can be received when HTTP response header is received.
+        /// If you try to get this property value before calling Start(), an empty string is returned.
+        /// </summary>
+        public string ContentName
+        {
+            get
+            {
+                string name;
+                int ret = Interop.Download.GetContentName(_downloadId, out name);
+                if (ret != (int)DownloadError.None)
+                {
+                    Log.Error(Downloads.LogTag, "Failed to get ContentName, " + (DownloadError)ret);
+                    return String.Empty;
+                }
+                return name;
+            }
+        }
+
+        /// <summary>
+        /// Total size of downloaded content.
+        /// This information is received from the server. If the server does not send the total size of the content, content_size is set to zero.
+        /// If you try to get this property value before calling Start(), 0 is returned.
+        /// </summary>
+        public ulong ContentSize
+        {
+            get
+            {
+                ulong size;
+                int ret = Interop.Download.GetContentSize(_downloadId, out size);
+                if (ret != (int)DownloadError.None)
+                {
+                    Log.Error(Downloads.LogTag, "Failed to get ContentSize, " + (DownloadError)ret);
+                    return 0;
+                }
+                return size;
+            }
+        }
+
+        /// <summary>
+        /// HTTP status code when a download exception occurs.
+        /// If you try to get this property value before calling Start(), 0 is returned.
+        /// </summary>
+        /// <remarks>
+        /// State of download request must be DownlodState.Failed.
+        /// </remarks>
+        public int HttpStatus
+        {
+            get
+            {
+                int status;
+                int ret = Interop.Download.GetHttpStatus(_downloadId, out status);
+                if (ret != (int)DownloadError.None)
+                {
+                    Log.Error(Downloads.LogTag, "Failed to get HttpStatus, " + (DownloadError)ret);
+                    return 0;
+                }
+                return status;
+            }
+        }
+
+        /// <summary>
+        /// ETag value from the HTTP response header when making a HTTP request for resume.
+        /// If you try to get this property value before calling Start() or if any other error occurs, an empty string is returned.
+        /// </summary>
+        /// <remarks>
+        /// The etag value is available or not depending on the web server. If not available, then on get of the property null is returned.
+        /// After download is started, it can get the etag value.
+        /// </remarks>
+        public string ETagValue
+        {
+            get
+            {
+                string etag;
+                int ret = Interop.Download.GetETag(_downloadId, out etag);
+                if (ret != (int)DownloadError.None)
+                {
+                    Log.Error(Downloads.LogTag, "Failed to get ETagValue, " + (DownloadError)ret);
+                    return String.Empty;
+                }
+                return etag;
+            }
+        }
+
+        /// <summary>
+        /// Contains properties required for creating download notifications.
+        /// </summary>
+        /// <remarks>
+        /// When the notification message is clicked, the action taken by the system is decided by the app control properties of the NotificationProperties instance.
+        /// If the app control is not set, the following default operation is executed when the notification message is clicked:
+        ///  1) download completed state - the viewer application is executed according to extension name of downloaded content,
+        ///  2) download failed state and ongoing state - the client application is executed.
+        /// This property should be set before calling Start().
+        /// </remarks>
+        public Notification NotificationProperties
+        {
+            get
+            {
+                return _notificationProperties;
+            }
+        }
+
+        /// <summary>
+        /// URL to download.
+        /// </summary>
+        /// <remarks>
+        /// Should be set before calling Start().
+        /// If you try to get this property value before setting or if any other error occurs, an empty string is returned.
+        /// </remarks>
+        public string Url
+        {
+            get
+            {
+                string url;
+                int ret = Interop.Download.GetUrl(_downloadId, out url);
+                if (ret != (int)DownloadError.None)
+                {
+                    Log.Error(Downloads.LogTag, "Failed to get Url, " + (DownloadError)ret);
+                    return String.Empty;
+                }
+                return url;
+            }
+            set
+            {
+                int ret = Interop.Download.SetUrl(_downloadId, value);
+                if (ret != (int)DownloadError.None)
+                {
+                    DownloadErrorFactory.ThrowException(ret, "Failed to set Url");
+                }
+            }
+        }
+
+        /// <summary>
+        /// Allowed network type for downloading the file.
+        /// The file will be downloaded only under the allowed network.
+        /// If you try to get this property value before setting or if any other error occurs, default value NetworkType All is returned.
+        /// </summary>
+        /// <remarks>
+        /// Should be set before calling Start().
+        /// </remarks>
+        public NetworkType AllowedNetworkType
+        {
+            get
+            {
+                int type;
+                int ret = Interop.Download.GetNetworkType(_downloadId, out type);
+                if (ret != (int)DownloadError.None)
+                {
+                    Log.Error(Downloads.LogTag, "Failed to get AllowedNetworkType, " + (DownloadError)ret);
+                    return NetworkType.All;
+                }
+                return (NetworkType)type;
+            }
+            set
+            {
+                int ret = Interop.Download.SetNetworkType(_downloadId, (int)value);
+                if (ret != (int)DownloadError.None)
+                {
+                    DownloadErrorFactory.ThrowException(ret, "Failed to set AllowedNetworkType");
+                }
+            }
+        }
+
+        /// <summary>
+        /// The file will be downloaded to the set destination file path. The downloaded file is saved to an auto-generated file name in the destination. If the destination is not specified, the file will be downloaded to default storage.
+        /// If you try to get this property value before setting or if any other error occurs, an empty string is returned.
+        /// </summary>
+        /// <remarks>
+        /// Should be set before calling Start().
+        /// </remarks>
+        public string DestinationPath
+        {
+            get
+            {
+                string path;
+                int ret = Interop.Download.GetDestination(_downloadId, out path);
+                if (ret != (int)DownloadError.None)
+                {
+                    Log.Error(Downloads.LogTag, "Failed to get DestinationPath, " + (DownloadError)ret);
+                    return String.Empty;
+                }
+                return path;
+            }
+            set
+            {
+                int ret = Interop.Download.SetDestination(_downloadId, value.ToString());
+                if (ret != (int)DownloadError.None)
+                {
+                    DownloadErrorFactory.ThrowException(ret, "Failed to set DestinationPath");
+                }
+            }
+        }
+
+        /// <summary>
+        /// The file will be saved in the specified destination or default storage with the set file name. If the file name is not specified, the downloaded file will be saved with an auto-generated file name in the destination.
+        /// If you try to get this property value before setting or if any other error occurs, an empty string is returned.
+        /// </summary>
+        /// <remarks>
+        /// Should be set before calling Start().
+        /// </remarks>
+        public string FileName
+        {
+            get
+            {
+                string name;
+                int ret = Interop.Download.GetFileName(_downloadId, out name);
+                if (ret != (int)DownloadError.None)
+                {
+                    Log.Error(Downloads.LogTag, "Failed to get FileName, " + (DownloadError)ret);
+                    return String.Empty;
+                }
+                return name;
+            }
+            set
+            {
+                int ret = Interop.Download.SetFileName(_downloadId, value.ToString());
+                if (ret != (int)DownloadError.None)
+                {
+                    DownloadErrorFactory.ThrowException(ret, "Failed to set FileName");
+                }
+            }
+        }
+
+        /// <summary>
+        /// Enables or disables auto download.
+        /// If this option is enabled, the previous downloading item is restarted automatically as soon as the download daemon is restarted. The download progress continues after the client process is terminated.
+        /// If you try to get this property value before setting, default value false is returned.
+        /// </summary>
+        /// <remarks>
+        /// The default value is false.
+        /// </remarks>
+        public bool AutoDownload
+        {
+            get
+            {
+                bool value;
+                int ret = Interop.Download.GetAutoDownload(_downloadId, out value);
+                if (ret != (int)DownloadError.None)
+                {
+                    Log.Error(Downloads.LogTag, "Failed to get AutoDownload, " + (DownloadError)ret);
+                    return false;
+                }
+                return value;
+            }
+            set
+            {
+                int ret = Interop.Download.SetAutoDownload(_downloadId, value);
+                if (ret != (int)DownloadError.None)
+                {
+                    DownloadErrorFactory.ThrowException(ret, "Failed to set AutoDownload");
+                }
+            }
+        }
+
+        /// <summary>
+        /// Directory path of the temporary file used in the previous download request.
+        /// This is only useful when resuming download to make HTTP request header at the client side. Otherwise, the path is ignored.
+        /// If you try to get this property value before setting or if any other error occurs, an empty string is returned.
+        /// </summary>
+        /// <remarks>
+        /// If the etag value is not present in the download database, it is not useful to set the temporary file path.
+        /// When resuming download request, the data is attached at the end of this temporary file.
+        /// </remarks>
+        public string TempFilePath
+        {
+            get
+            {
+                string path;
+                int ret = Interop.Download.GetTempFilePath(_downloadId, out path);
+                if (ret != (int)DownloadError.None)
+                {
+                    Log.Error(Downloads.LogTag, "Failed to get TempFilePath, " + (DownloadError)ret);
+                    return String.Empty;
+                }
+                return path;
+            }
+            set
+            {
+                int ret = Interop.Download.SetTempFilePath(_downloadId, value.ToString());
+                if (ret != (int)DownloadError.None)
+                {
+                    DownloadErrorFactory.ThrowException(ret, "Failed to set TempFilePath");
+                }
+            }
+        }
+
+        /// <summary>
+        /// HTTP header field and value pairs to the download request.
+        /// HTTP header <field,value> pair is the <key,value> pair in the Dictionary HttpHeaders
+        /// The given HTTP header field will be included with the HTTP request of the download request.
+        /// If you try to get this property value before setting, an empty dictionary is returned.
+        /// </summary>
+        /// <remarks>
+        /// HTTP header fields should be set before calling Start().
+        /// HTTP header fields can be removed before calling Start().
+        /// </remarks>
+        public IDictionary<string, string> HttpHeaders
+        {
+            get
+            {
+                Dictionary<string, string> httpHeaders = new Dictionary<string, string>();\r
+                IntPtr fieldsPointer;
+                int length;
+                int ret = Interop.Download.GetHttpHeaderFieldList(_downloadId, out fieldsPointer, out length);
+                if (ret != (int)DownloadError.None)
+                {
+                    Log.Error(Downloads.LogTag, "Failed to get HttpHeaders, " + (DownloadError)ret);
+                    return new Dictionary<string, string>();
+                }
+                string[] fields;
+                IntPtrToStringArray(fieldsPointer, length, out fields);
+                Interop.Libc.Free(fieldsPointer);
+                foreach (string field in fields)
+                {
+                    string value;
+                    ret = Interop.Download.GetHttpHeaderField(_downloadId, field, out value);
+                    if (ret != (int)DownloadError.None)
+                    {
+                        Log.Error(Downloads.LogTag, "Failed to get HttpHeader Field, " + (DownloadError)ret);
+                        return new Dictionary<string, string>();
+                    }
+                    httpHeaders.Add(field, value);
+                }
+                return httpHeaders;
+            }
+            set
+            {
+                foreach (KeyValuePair<string, string> entry in value)
+                {
+                    int ret = Interop.Download.AddHttpHeaderField(_downloadId, entry.Key, entry.Value);
+                    if (ret != (int)DownloadError.None)
+                    {
+                        DownloadErrorFactory.ThrowException(ret, "Failed to set HttpHeaders");
+                    }
+                }
+            }
+        }
+
+        /// <summary>
+        /// Starts or resumes download.
+        /// Starts to download the current URL, or resumes the download if paused.
+        /// </summary>
+        /// <remarks>
+        /// The URL is the mandatory information to start the download.
+        /// </remarks>
+        public void Start()
+        {
+            int ret = Interop.Download.StartDownload(_downloadId);
+            if (ret != (int)DownloadError.None)
+            {
+                DownloadErrorFactory.ThrowException(ret, "Failed to start download request");
+            }
+        }
+
+        /// <summary>
+        /// Pauses download request.
+        /// </summary>
+        /// <remarks>
+        /// The paused download request can be restarted with Start() or canceled with Cancel().
+        /// </remarks>
+        public void Pause()
+        {
+            int ret = Interop.Download.PauseDownload(_downloadId);
+            if (ret != (int)DownloadError.None)
+            {
+                DownloadErrorFactory.ThrowException(ret, "Failed to pause download request");
+            }
+        }
+
+        /// <summary>
+        /// Cancels download request.
+        /// </summary>
+        /// <remarks>
+        /// The canceled download can be restarted with Start().
+        /// </remarks>
+        public void Cancel()
+        {
+            int ret = Interop.Download.CancelDownload(_downloadId);
+            if (ret != (int)DownloadError.None)
+            {
+                DownloadErrorFactory.ThrowException(ret, "Failed to cancel download request");
+            }
+        }
+
+        static private void IntPtrToStringArray(IntPtr unmanagedArray, int size, out string[] managedArray)
+        {
+            managedArray = new string[size];
+            IntPtr[] IntPtrArray = new IntPtr[size];
+
+            Marshal.Copy(unmanagedArray, IntPtrArray, 0, size);
+
+            for (int iterator = 0; iterator < size; iterator++)
+            {
+                managedArray[iterator] = Marshal.PtrToStringAuto(IntPtrArray[iterator]);
+            }
+        }
+    }
+}
+
diff --git a/src/Tizen.Content.Download/Tizen.Content.Download/StateChangedEventArgs.cs b/src/Tizen.Content.Download/Tizen.Content.Download/StateChangedEventArgs.cs
new file mode 100644 (file)
index 0000000..6c162c6
--- /dev/null
@@ -0,0 +1,27 @@
+using System;
+
+namespace Tizen.Content.Download
+{
+    /// <summary>
+    /// An extended EventArgs class which contains the changed download state.
+    /// </summary>
+    public class StateChangedEventArgs : EventArgs
+    {
+        private DownloadState _state;
+
+        internal StateChangedEventArgs(DownloadState downloadState)
+        {
+            _state = downloadState;
+        }
+        /// <summary>
+        /// Present download state.
+        /// </summary>
+        public DownloadState State
+        {
+            get
+            {
+                return _state;
+            }
+        }
+    }
+}
diff --git a/src/Tizen.Content.Download/download/Notification.cs b/src/Tizen.Content.Download/download/Notification.cs
deleted file mode 100644 (file)
index d8a813c..0000000
+++ /dev/null
@@ -1,108 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using Tizen.Applications;
-
-namespace Tizen.Content.Download
-{
-    /// <summary>
-    /// The Notification class consists of all the properties required to set notification for download operation.
-    /// </summary>
-    public class Notification
-    {
-        /// <summary>
-        /// Title of the notification.
-        /// If user tries to get before setting, null is returned.
-        /// </summary>
-        public string Title
-        {
-            get
-            {
-            }
-            set
-            {
-            }
-        }
-
-        /// <summary>
-        /// Description of the notification.
-        /// If user tries to get before setting, null is returned.
-        /// </summary>
-        public string Description
-        {
-            get
-            {
-            }
-            set
-            {
-            }
-        }
-
-        /// <summary>
-        /// Type of Notification.
-        /// If user tries to get before setting, defaule NotificationType None is returned.
-        /// </summary>
-        public NotificationType Type
-        {
-            get
-            {
-            }
-            set
-            {
-            }
-        }
-
-        /// <summary>
-        /// AppControl for an ongoing download notification.
-        /// If user tries to get before setting, null is returned.
-        /// </summary>
-        /// <remarks>
-        /// When the notification message is clicked, the action is decided by the app control.
-        /// </remarks>
-        public AppControl AppControlOngoing
-        {
-            get
-            {
-            }
-            set
-            {
-            }
-        }
-
-        /// <summary>
-        /// AppControl for a completed download notification.
-        /// If user tries to get before setting, null is returned.
-        /// </summary>
-        /// <remarks>
-        /// When the notification message is clicked, the action is decided by the app control
-        /// </remarks>
-        public AppControl AppControlComplete
-        {
-            get
-            {
-            }
-            set
-            {
-            }
-        }
-
-        /// <summary>
-        /// AppControl for a failed download notification.
-        /// If user tries to get before setting, null is returned.
-        /// </summary>
-        /// <remarks>
-        /// When the notification message is clicked, the action is decided by the app control
-        /// </remarks>
-        public AppControl AppControlFail
-        {
-            get
-            {
-            }
-            set
-            {
-            }
-        }
-    }
-}
-
diff --git a/src/Tizen.Content.Download/download/Request.cs b/src/Tizen.Content.Download/download/Request.cs
deleted file mode 100644 (file)
index 0ee5eb6..0000000
+++ /dev/null
@@ -1,348 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using Tizen.Applications;
-
-namespace Tizen.Content.Download
-{
-    /// <summary>
-    /// The Request class provides functions to create and manage one or more download requests.
-    /// </summary>
-    public class Request : IDisposable
-    {
-        /// <summary>
-        /// Creates a Request object.
-        /// </summary>
-        /// <param name="url"> URL to download</param>
-        public Request(string url)
-        {
-        }
-
-        /// <summary>
-        /// Creates a Request object.
-        /// </summary>
-        /// <param name="url"> URL to download</param>
-        /// <param name="destinationPath"> Directory path where downloaded file is stored </param>
-        /// <param name="fileName"> Name of the downloaded file </param>
-        /// <param name="type"> Network type which the download request must adhere to </param>
-        public Request(string url, string destinationPath, string fileName, NetworkType type)
-        {
-        }
-
-        /// <summary>
-        /// Creates a Request object.
-        /// </summary>
-        /// <param name="url"> URL to download</param>
-        /// <param name="destinationPath"> Directory path where downloaded file is stored </param>
-        /// <param name="fileName"> Name of the downloaded file </param>
-        /// <param name="type"> Network type which the download request must adhere to </param>
-        /// <param name-"httpHeaders"> HTTP header fields for download request </param>
-        public Request(string url, string destinationPath, string fileName, NetworkType type, Dictionary<string, string> httpHeaders)
-        {
-        }
-
-        /// <summary>
-        /// Event that occurs when the download state changes.
-        /// </summary>
-        public event EventHandler<StateChangedEventArgs> StateChanged
-        {
-        }
-
-        /// <summary>
-        /// Event that occurs when the download progress changes.
-        /// </summary>
-        public event EventHandler<ProgressChangedEventArgs> ProgressChanged
-        {
-        }
-
-        /// <summary>
-        /// Absolute path to save the downloaded file.
-        /// If you try to get this property value before calling Start(), an empty string is returned.
-        /// </summary>
-        public string DownloadedPath
-        {
-            get
-            {
-            }
-        }
-
-        /// <summary>
-        /// MIME type of the downloaded content.
-        /// If you try to get this property value before calling Start(), an empty string is returned.
-        /// </summary>
-        public string MimeType
-        {
-            get
-            {
-            }
-        }
-
-        /// <summary>
-        /// Current state of the download.
-        /// </summary>
-        public DownloadState State
-        {
-            get
-            {
-            }
-        }
-
-        /// <summary>
-        /// Content name of the downloaded file.
-        /// This can be defined with reference of HTTP response header data. The content name can be received when HTTP response header is received.
-        /// If you try to get this property value before calling Start(), an empty string is returned.
-        /// </summary>
-        public string ContentName
-        {
-            get
-            {
-            }
-        }
-
-        /// <summary>
-        /// Total size of downloaded content.
-        /// This information is received from the server. If the server does not send the total size of the content, content_size is set to zero.
-        /// If you try to get this property value before calling Start(), 0 is returned.
-        /// </summary>
-        public ulong ContentSize
-        {
-            get
-            {
-            }
-        }
-
-        /// <summary>
-        /// HTTP status code when a download exception occurs.
-        /// If you try to get this property value before calling Start(), -1 is returned.
-        /// </summary>
-        public int HttpStatus
-        {
-            get
-            {
-            }
-        }
-
-        /// <summary>
-        /// ETag value from the HTTP response header when making a HTTP request for resume.
-        /// If you try to get this property value before calling Start(), an empty string is returned.
-        /// </summary>
-        /// <remarks>
-        /// The etag value is available or not depending on the web server. If not available, then on get of the property null is returned.
-        /// After download is started, it can get the etag value.
-        /// </remarks>
-        public string ETagValue
-        {
-            get
-            {
-            }
-        }
-
-        /// <summary>
-        /// Contains properties required for creating download notifications.
-        /// </summary>
-        /// <remarks>
-        /// When the notification message is clicked, the action to take is decided by the app control.
-        /// If the app control is not set, the following default operation is executed when the notification message is clicked:
-        ///  1) download completed state - the viewer application is executed according to extension name of downloaded content,
-        ///  2) download failed state and ongoing state - the client application is executed.
-        /// Should be set before calling Start().
-        /// </remarks>
-        public Notification NotificationProperties
-        {
-            get
-            {
-            }
-        }
-
-        /// <summary>
-        /// URL to download.
-        /// </summary>
-        /// <remarks>
-        /// Should be set before calling Start().
-        /// If you try to get this property value before setting, an empty string is returned.
-        /// </remarks>
-        public string Url
-        {
-            get
-            {
-            }
-            set
-            {
-            }
-        }
-
-        /// <summary>
-        /// Allowed network type for downloading the file.
-        /// The file will be downloaded only under the allowed network.
-        /// If you try to get this property value before setting, default value NetworkType All is returned.
-        /// </summary>
-        /// <remarks>
-        /// Should be set before calling Start().
-        /// </remarks>
-        public NetworkType AllowedNetworkType
-        {
-            get
-            {
-            }
-            set
-            {
-            }
-        }
-
-        /// <summary>
-        /// The file will be downloaded to the set destination file path. The downloaded file is saved to an auto-generated file name in the destination. If the destination is not specified, the file will be downloaded to default storage.
-        /// If you try to get this property value before setting, an empty string is returned.
-        /// </summary>
-        /// <remarks>
-        /// Should be set before calling Start().
-        /// </remarks>
-        public string DestinationPath
-        {
-            get
-            {
-            }
-            set
-            {
-            }
-        }
-
-        /// <summary>
-        /// The file will be saved in the specified destination or default storage with the set file name. If the file name is not specified, the downloaded file will be saved with an auto-generated file name in the destination.
-        /// If you try to get this property value before setting, an empty string is returned.
-        /// </summary>
-        /// <remarks>
-        /// Should be set before calling Start().
-        /// </remarks>
-        public string FileName
-        {
-            get
-            {
-            }
-            set
-            {
-            }
-        }
-
-        /// <summary>
-        /// Enables or disables auto download.
-        /// If this option is enabled, the previous downloading item is restarted automatically as soon as the download daemon is restarted. The download progress continues after the client process is terminated.
-        /// If you try to get this property value before setting, default value false is returned.
-        /// </summary>
-        /// <remarks>
-        /// The default value is false.
-        /// </remarks>
-        public bool AutoDownload
-        {
-            get
-            {
-            }
-            set
-            {
-            }
-        }
-
-        /// <summary>
-        /// Directory path of the temporary file used in the previous download request.
-        /// This is only useful when resuming download to make HTTP request header at the client side. Otherwise, the path is ignored.
-        /// If you try to get this property value before setting, an empty string is returned.
-        /// </summary>
-        /// <remarks>
-        /// If the etag value is not present in the download database, it is not useful to set the temporary file path.
-        /// When resuming download request, the data is attached at the end of this temporary file.
-        /// </remarks>
-        public string TempFilePath
-        {
-            get
-            {
-            }
-            set
-            {
-            }
-        }
-
-        /// <summary>
-        /// HTTP header field and value pairs to the download request.
-        /// HTTP header <field,value> pair is the <key,value> pair in the Dictionary HttpHeaders
-        /// The given HTTP header field will be included with the HTTP request of the download request.
-        /// If you try to get this property value before setting, an empty dictionary is returned.
-        /// </summary>
-        /// <remarks>
-        /// HTTP header fields should be set before calling Start().
-        /// HTTP header fields can be removed before calling Start().
-        /// </remarks>
-        public Dictionary<string, string> HttpHeaders
-        {
-            get
-            {
-            }
-            set
-            {
-            }
-        }
-
-        /// <summary>
-        /// Starts or resumes download.
-        /// Starts to download the current URL, or resumes the download if paused.
-        /// </summary>
-        /// <remarks>
-        /// The URL is the mandatory information to start the download.
-        /// </remarks>
-        public void Start()
-        {
-        }
-
-        /// <summary>
-        /// Pauses download request.
-        /// </summary>
-        /// <remarks>
-        /// The paused download request can be restarted with Start() or canceled with Cancel().
-        /// </remarks>
-        public void Pause()
-        {
-        }
-
-        /// <summary>
-        /// Cancels download request.
-        /// </summary>
-        /// <remarks>
-        /// The canceled download can be restarted with Start().
-        /// </remarks>
-        public void Cancel()
-        {
-        }
-    }
-
-    /// <summary>
-    /// An extended EventArgs class which contains changed download state type.
-    /// </summary>
-    public class StateChangedEventArgs : EventArgs
-    {
-        /// <summary>
-        /// Present download state.
-        /// </summary>
-        public DownloadState state
-        {
-            get
-            {
-            }
-        }
-    }
-
-    /// <summary>
-    /// An extended EventArgs class which contains size of received data in bytes.
-    /// </summary>
-    public class ProgressChangedEventArgs : EventArgs
-    {
-        /// <summary>
-        /// Received data size in bytes.
-        /// </summary>
-        public ulong receivedDataSize
-        {
-            get
-            {
-            }
-        }
-    }
-}
-