[content] Change version in spec file
[platform/framework/native/content.git] / inc / FCntContentTransfer.h
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 /**
17  * @file                FCntContentTransfer.h
18  * @brief               This is the header file for the %ContentTransfer class.
19  *
20  * This header file contains the declarations of the %ContentTransfer class.
21  */
22
23 #ifndef _FCNT_CONTENT_TRANSFER_H_
24 #define _FCNT_CONTENT_TRANSFER_H_
25
26 #include <FBaseObject.h>
27
28 namespace Tizen { namespace Base { namespace Collection
29 {
30 class IList;
31 }}}
32
33 namespace Tizen { namespace Base { namespace Utility
34 {
35 class Uri;
36 }}}
37
38 namespace Tizen { namespace Content
39 {
40
41 class _ContentTransferImpl;
42 class IContentTransferListener;
43
44 /**
45  * @if OSPDEPREC
46  * @class       ContentTransfer
47  * @brief       <i> [Deprecated] </i> This class provides methods to download the content.
48  *
49  * @deprecated  This class is deprecated. Instead of using this class, use DownloadManager class.
50  * @since       2.0
51  *
52  * The %ContentTransfer class provides the following features:
53  * - Downloading the content from the servers that support HTTP access.
54  * - Cancelling a download operation.
55  *
56  * HTTP download (ContentTransfer::Download()) is a standard HTTP transaction using the HTTP GET request and response methods.
57  *
58  * The following example demonstrates how to use the %ContentTransfer class.
59  *
60  *      @code
61  *      class  MyClass
62  *              :public Tizen::Content::IContentTransferListener
63  *      {
64  *      public:
65  *              MyClass(void);
66  *              virtual ~MyClass(void);
67  *
68  *      public:
69  *              void OnContentTransferInProgress(RequestId requestID, int totalReceivedSize);
70  *              void OnContentDownloadCompleted(RequestId requestID, ContentId contentID, result res, const Tizen::Base::String& errorCode, const Tizen::Base::String& errorMessage);
71  *              void OnContentDownloadToBufferCompleted(RequestId reqId, Tizen::Base::ByteBuffer* pBuffer, result r, const Tizen::Base::String& errorCode, const Tizen::Base::String& errorMessage);
72  *              void OnContentTransferCanceled(RequestId reqId, result res, const Tizen::Base::String& errorCode, const Tizen::Base::String& errorMessage);
73  *      };
74  *
75  *      // Implementation for the listener function and Implementation of other listener function is
76  *      void MyClass::OnContentDownloadCompleted(RequestId requestID, ContentId contentID, result res, const Tizen::Base::String& errorCode, const Tizen::Base::String& errorMessage)
77  *      {
78  *              result r = E_SUCCESS;
79  *              ContentManager contentManager;
80  *              ContentInfo* pContentInfo = null;
81  *
82  *              // Error check
83  *              TryCatch(!IsFailed(res), r, "Download Error [%s]", GetErrorMessage(res));
84  *
85  *              // Do something
86  *              r = contentManager.Construct();
87  *              TryCatch(!IsFailed(r), r, "Construct failed.");
88  *
89  *              // Get ContentInfo
90  *              pContentInfo = contentManager.GetContentInfoN(contentID);
91  *      CATCH:
92  *              if (pContentInfo)
93  *                      delete pContentInfo;
94  *      }
95  *
96  *      result
97  *      MyClass::RequestDownload(void)
98  *      {
99  *              ContentTransfer contentTransfer;
100  *              RequestId requestId;
101  *              Tizen::Base::Utility::Uri contentUri;
102  *              int contentSize;
103  *              Tizen::Base::String downloadPath;
104  *
105  *              result r = contentTransfer.Construct(*this);
106  *              TryReturn(!IsFailed(r), r, ("Construct is failed.\n"));
107  *
108  *              // TODO: set uri and download path
109  *
110  *              r = contentTransfer.Download(contentUri, downloadPath, requestId, false);
111  *              TryReturn(!IsFailed(r), r, ("Download Request is failed.\n"));
112  *      }
113  *      @endcode
114  *      @endif
115  */
116 class _OSP_EXPORT_ ContentTransfer
117         : virtual public Tizen::Base::Object
118 {
119 public:
120         /**
121          * The object is not fully constructed after this constructor is called. @n
122          * For full construction, the Construct(IContentTransferListener&) method must be called right after calling this constructor.
123          *
124          * @brief       <i> [Deprecated] </i>
125          * @deprecated  This class is deprecated. Instead of using this class, use DownloadManager class.
126          * @since               2.0
127          *
128          * @remarks             After creating an instance of this class, the Construct() method must be called explicitly to initialize this instance.
129          */
130         ContentTransfer(void);
131
132         /**
133          * This destructor overrides Tizen::Base::Object::~Object().
134          *
135          * @brief       <i> [Deprecated] </i>
136          * @deprecated  This class is deprecated. Instead of using this class, use DownloadManager class.
137          *
138          * @since               2.0
139          */
140         virtual ~ContentTransfer(void);
141
142         /**
143          * Initializes this instance of %ContentTransfer with the specified parameter. @n
144          * The %Construct() method should be called after every instance of %ContentTransfer is constructed.
145          *
146          * @brief       <i> [Deprecated] </i>
147          * @deprecated  This class is deprecated. Instead of using this class, use DownloadManager class.
148          * @since               2.0
149          *
150          * @return              An error code
151          * @param[in]   listener                A reference to IContentTransferListener
152          * @exception   E_SUCCESS               The method is successful.
153          * @exception   E_OUT_OF_MEMORY The memory is insufficient.
154          * @exception   E_SYSTEM                A system error has occurred.
155          */
156         result Construct(IContentTransferListener& listener);
157
158         /**
159         * Downloads a content file from the content provider's server. @n
160         * The @c filesize parameter is used to check the limitation of the local volume. If this parameter is set to @c 0, the %Download() method will not check the volume. @n
161         * An application should set the full destination path for the downloaded contents. When the content is downloaded to one of the following paths, this method internally registers the content using ContentManager.
162         * - /Media/
163         * - /Storagecard/Media/ @n
164         *
165         * When the download is completed, the application is notified using the IContentTransferListener::OnContentDownloadCompleted() method. @n
166         * When the data is being downloaded, the application is notified of the progress using the IContentTransferListener::OnContentTransferInProgress() method.
167         *
168         * @brief        <i> [Deprecated] </i>
169         * @deprecated This method is deprecated due to the operation policy of the Tizen Server.
170         * When downloading the contents from a third party server, it is recommended to use the Download(const Tizen::Base::Utility::Uri&, const Tizen::Base::String&, RequestId&, bool, int, int) method.
171         * @since                                 2.0
172         * @privlevel    public
173         * @privilege    %http://tizen.org/privilege/download
174         *
175         * @return       An error code
176         * @param[in]    uri                                     The content URL
177         * @param[in]    fileSize                        The content file size in bytes @n
178         *                                                                       If set to @c 0, the method does not check the storage limitation.
179         * @param[in]    destFilePath            The full destination path
180         * @param[in]    replace                         The replace option of the destination file @n
181         *                                                                       Set to @c true to replace the file, @n
182         *                                                                       else @c false.
183         * @param[out]   reqId                           The request ID
184         * @param[in]    pListener                       A pointer to the IContentTransferListener instance
185         * @param[in]    sec                                     The timeout period in seconds
186         * @exception    E_SUCCESS                               The method is successful.
187         * @exception    E_INVALID_ARG                   A specified input parameter is invalid.
188         * @exception    E_INVALID_STATE         This method is invalid for the current state of this instance.
189         * @exception    E_ILLEGAL_ACCESS                Access is denied due to insufficient permission.
190         * @exception    E_FILE_ALREADY_EXIST    The specified file already exists.
191         * @exception    E_PRIVILEGE_DENIED      The application does not have the privilege to call this method.
192         * @exception    E_IN_PROGRESS                   A previous request is in progress.
193         * @exception    E_OUT_OF_MEMORY The memory is insufficient.
194         * @exception    E_USER_NOT_CONSENTED    The user blocks an application from calling this method. @b Since: @b 2.1
195         * @see  IContentTransferListener::OnContentDownloadCompleted()
196         * @see  IContentTransferListener::OnContentTransferInProgress()
197         */
198         result Download(const Tizen::Base::Utility::Uri& uri, int fileSize, const Tizen::Base::String& destFilePath, bool replace, RequestId& reqId, IContentTransferListener* pListener = null, int sec = 0);
199
200         /**
201          * Downloads a content file from the content provider's server. @n
202          * An application should set the destination path for the downloaded contents.
203          * The path of the downloaded file should use Tizen::System::Environment::GetMediaPath() or Tizen::System::Environment::GetExternalStoragePath().
204          *
205          * When the content is downloaded to the path using Tizen::System::Environment::GetMediaPath() or Tizen::System::Environment::GetExternalStoragePath(), the %Download() method internally registers the content in the content database. @n
206          * When the download is completed, the application is notified using the IContentTransferListener::OnContentDownloadCompleted() method. @n
207          * When the data is being downloaded, the application is notified of the progress using the IContentTransferListener::OnContentTransferInProgress() method.
208          *
209          * @brief       <i> [Deprecated] </i>
210          * @deprecated  This class is deprecated. Instead of using this class, use DownloadManager class.
211          * @if OSPCOMPAT
212          * @brief <i> [Compatibility] </i>
213          * @endif
214          * @since                       2.0
215          * @if OSPCOMPAT
216          * @compatibility This method has compatibility issues with OSP compatible applications. @n
217          *                       For more information, see @ref CompContentTransferDownloadPage3 "here".
218          * @endif
219          * @privlevel           public
220          * @privilege           %http://tizen.org/privilege/download
221          *
222          * @return                      An error code
223          * @param[in]   uri                                             The content URL
224          * @param[in]   filePath                                The destination file path @n
225          *                                                      Use Tizen::System::Environment::GetMediaPath(), Tizen::System::Environment::GetExternalStoragePath() and Tizen::App::App::GetInstance()->GetAppRootPath().
226          * @param[out]  reqId                   The request ID
227          * @param[in]   replace                 The replace option of the destination file @n
228          *                                       Set to @c true to replace the file, @n
229          *                                                                              else @c false.
230          * @param[in]   timeout                 The timeout period in seconds
231          * @param[in]   progressInterval        The progress period interval as a percentage value
232          * @exception   E_SUCCESS                               The method is successful.
233          * @exception   E_PRIVILEGE_DENIED      The application does not have the privilege to call this method.
234          * @exception   E_INVALID_ARG                   A specified input parameter is invalid.
235          * @exception   E_INVALID_STATE         This method is invalid for the current state of this instance.
236          * @exception   E_ILLEGAL_ACCESS                Access is denied due to insufficient permission.
237          * @exception   E_FILE_ALREADY_EXIST    The specified file already exists.
238          * @exception   E_IN_PROGRESS                   A previous request is in progress.
239          * @exception   E_OUT_OF_MEMORY         The memory is insufficient.
240          * @exception   E_SYSTEM                                A system error has occurred.
241          * @exception   E_USER_NOT_CONSENTED    The user blocks an application from calling this method. @b Since: @b 2.1
242          * @remarks
243          *                              - The @c progressInterval is the interval of the progress for each download request. If the value of the @c progressInterval is @c 0, the @c progressInterval uses the value set by the ContentTransfer::SetProgressIntervalByPercent(int). The @c progressInterval is a percentage value between @c 0 and @c 100.
244          *                              - The @c timeout is the value of the response timeout for each download request. If the value of the @c timeout is @c 0, the value for the @c timeout uses the value set by the ContentTransfer::SetDefaultTimeout(int).
245          * @see  IContentTransferListener::OnContentDownloadCompleted()
246          * @see  IContentTransferListener::OnContentTransferInProgress()
247          */
248         result Download(const Tizen::Base::Utility::Uri& uri, const Tizen::Base::String& filePath, RequestId& reqId, bool replace = false, int timeout = 0, int progressInterval = 0);
249
250         /**
251          * @if OSPCOMPAT
252          * @page                CompContentTransferDownloadPage3 Compatibility for the file path.
253          * @section     CompContentTransferDownloadPageIssueSection Issues
254          *                 The content path argument of this method in OSP compatible applications has the following issues: @n
255          *                 -# The content path should be a path that begins with an allowed path prefix. @n
256          *                    For example, L"/Media/Images/flower.jpg", "/Storagecard/Media/Images/flower.jpg".
257          *
258          * @section     CompImageContentInfoConstructPageSolutionSection Resolutions
259          *                 This issue has been resolved in Tizen. @n
260          *                 -# The content path can be a path without a specific allowed path prefix. @n
261          *                 Application do not need to know the specific allowed path prefixes. @n
262          *                 To get the directory path, use the following methods: @n
263          *                 - For accessing the media directory, use Tizen::System::Environment::GetMediaPath().
264          *                 - For accessing the external storage, use Tizen::System::Environment::GetExternalStoragePath().
265          *
266          * @endif
267          */
268
269         /**
270         * Downloads a content file to a buffer from the content provider's servers. @n
271         * The %DownloadToBuffer() method does not register the content. @n
272         * When the download is completed, the application is notified using the IContentTransferListener::OnContentDownloadToBufferCompleted() method. @n
273         * When the data is being downloaded, the application is notified of the progress using the IContentTransferListener::OnContentTransferInProgress() method.
274         *
275         * @brief        <i> [Deprecated] </i>
276         * @deprecated This method is deprecated due to the operation policy of the Tizen Server.
277         * When downloading the contents to a buffer from a third party server, it is recommended to use the DownloadToBuffer(const Tizen::Base::Utility::Uri&, RequestId&, int, int) method.
278         * @since                                 2.0
279         * @privlevel    public
280         * @privilege    %http://tizen.org/privilege/download
281         *
282         * @return       An error code
283         * @param[in]    uri                                     The content URL
284         * @param[in]    fileSize                        The content file size in bytes @n
285         *                                                                       If set to @c 0, the method does not check the storage limitation.
286         * @param[out]   reqId                           The request ID
287         * @param[in]    pListener                       A pointer to the IContentTransferListener instance
288         * @param[in]    sec                                     The timeout period in seconds
289         * @exception    E_SUCCESS                               The method is successful.
290         * @exception    E_INVALID_ARG                   A specified input parameter is invalid.
291         * @exception    E_INVALID_STATE         This method is invalid for the current state of this instance.
292         * @exception    E_OUT_OF_MEMORY         The memory is insufficient.
293         * @exception    E_PRIVILEGE_DENIED      The application does not have the privilege to call this method.
294         * @exception    E_USER_NOT_CONSENTED    The user blocks an application from calling this method. @b Since: @b 2.1
295         * @see  IContentTransferListener::OnContentDownloadToBufferCompleted()
296         * @see  IContentTransferListener::OnContentTransferInProgress()
297         */
298         result DownloadToBuffer(const Tizen::Base::Utility::Uri& uri, int fileSize, RequestId& reqId, IContentTransferListener* pListener = null, int sec = 0);
299
300         /**
301          * Downloads a content file to a buffer from the content provider's servers. @n
302          * The %DownloadToBuffer() method does not register the content. @n
303          * When the download is completed, the application is notified using the IContentTransferListener::OnContentDownloadToBufferCompleted() method. @n
304          * When the data is being downloaded, the application is notified of the progress using the IContentTransferListener::OnContentTransferInProgress() method.
305          *
306          * @brief       <i> [Deprecated] </i>
307          * @deprecated  This class is deprecated. Instead of using this class, use DownloadManager class.
308          * @since                       2.0
309          * @privlevel           public
310          * @privilege           %http://tizen.org/privilege/download
311          *
312          * @return                      An error code
313          * @param[in]   uri                                             The content URL
314          * @param[out]  reqId                                   The request ID
315          * @param[in]   timeout                                 The timeout period in seconds
316          * @param[in]   progressInterval        The progress period interval as a percentage value
317          * @exception   E_SUCCESS                               The method is successful.
318          * @exception   E_PRIVILEGE_DENIED      The application does not have the privilege to call this method.
319          * @exception   E_INVALID_ARG                   A specified input parameter is invalid.
320          * @exception   E_INVALID_STATE         This method is invalid for the current state of this instance.
321          * @exception   E_ILLEGAL_ACCESS                Access is denied due to insufficient permission.
322          * @exception   E_IN_PROGRESS                   A previous request is in progress.
323          * @exception   E_OUT_OF_MEMORY         The memory is insufficient.
324          * @exception   E_USER_NOT_CONSENTED    The user blocks an application from calling this method. @b Since: @b 2.1
325          * @remarks
326          *                              - The @c progressInterval is the interval of the progress for each download request. If the value of the @c progressInterval is @c 0, the @c progressInterval uses the value set by the ContentTransfer::SetProgressIntervalByPercent(int). The @c progressInterval is a percentage value between @c 0 and @c 100.
327          *                              - The @c timeout is the value of the response timeout for each download request. If the value of the @c timeout is @c 0, the value for the @c timeout uses the value set by the ContentTransfer::SetDefaultTimeout(int).
328          * @see  IContentTransferListener::OnContentDownloadToBufferCompleted()
329          * @see  IContentTransferListener::OnContentTransferInProgress()
330          */
331         result DownloadToBuffer(const Tizen::Base::Utility::Uri& uri, RequestId& reqId, int timeout = 0, int progressInterval = 0);
332
333         /**
334          * Sets the default timeout period. @n
335          * If the server does not respond during the timeout period, the network connection is closed.
336          * @c 0 or minus second means unlimited period.
337          *
338          * @brief       <i> [Deprecated] </i>
339          * @deprecated  This class is deprecated. Instead of using this class, use DownloadManager class.
340          * @since               2.0
341          *
342          * @param[in]   sec                     The default timeout period in seconds @n
343          *                          The default value is @c 0.
344          */
345         void SetDefaultTimeout(int sec);
346
347         /**
348          * Gets the default timeout period.
349          *
350          * @brief       <i> [Deprecated] </i>
351          * @deprecated  This class is deprecated. Instead of using this class, use DownloadManager class.
352          * @since               2.0
353          *
354          * @return              The default timeout period
355          */
356         int GetDefaultTimeout(void) const;
357
358         /**
359          * Removes a transfer operation. @n
360          * This operation removes a request for multiple downloads.
361          * A download operation in progress is not removed by this operation.
362          *
363          * @brief       <i> [Deprecated] </i>
364          * @deprecated  This class is deprecated. Instead of using this class, use DownloadManager class.
365          * @since               2.0
366          *
367          * @return              An error code
368          * @param[in]   reqId The request ID
369          * @exception   E_SUCCESS                       The method is successful.
370          * @exception   E_OUT_OF_MEMORY The memory is insufficient.
371          * @exception   E_OBJ_NOT_FOUND The specified @c reqId is not found.
372          * @exception   E_INVALID_STATE This method is invalid for the current state of this instance.
373          * @remarks     To stop an on-going transfer, use the Cancel() method.
374          */
375         result Remove(RequestId reqId);
376
377         /**
378          * Removes all the transfer operations. @n
379          * This operation removes all the requests for multiple downloads.
380          * The download operations in progress are not removed by this operation.
381          *
382          * @brief       <i> [Deprecated] </i>
383          * @deprecated  This class is deprecated. Instead of using this class, use DownloadManager class.
384          * @since               2.0
385          *
386          * @return              An error code
387          * @exception   E_SUCCESS                       The method is successful.
388          * @exception   E_OUT_OF_MEMORY The memory is insufficient.
389          * @exception   E_INVALID_STATE This method is invalid for the current state of this instance.
390          * @remarks     To stop an on-going transfer, use the Cancel() method.
391          */
392         result RemoveAll(void);
393
394         /**
395          * Cancels a transfer operation. @n
396          * The downloaded file is deleted from the file system. @n
397          * When a transfer download operation is canceled, the application is notified via the IContentTransferListener::OnContentTransferCanceled() method.
398          *
399          * @brief       <i> [Deprecated] </i>
400          * @deprecated  This class is deprecated. Instead of using this class, use DownloadManager class.
401          * @since               2.0
402          *
403          * @return              An error code
404          * @param[in]   reqId                   The request ID
405          * @exception   E_SUCCESS                       The method is successful.
406          * @exception   E_OBJ_NOT_FOUND         The specified @c reqId is not found.
407          * @exception   E_INVALID_ARG           The specified input parameter is invalid.
408          * @exception   E_INVALID_STATE This method is invalid for the current state of this instance.
409          * @see IContentTransferListener::OnContentTransferCanceled()
410          */
411         result Cancel(RequestId reqId);
412
413         /**
414          * Cancels all the operations in progress.
415          *
416          * @brief       <i> [Deprecated] </i>
417          * @deprecated  This class is deprecated. Instead of using this class, use DownloadManager class.
418          * @since               2.0
419          *
420          * @return              An error code
421          * @exception   E_SUCCESS                       The method is successful.
422          * @exception   E_OUT_OF_MEMORY The memory is insufficient.
423          * @exception   E_INVALID_STATE This method is invalid for the current state of this instance.
424          */
425         result CancelAll(void);
426
427         /**
428          * Gets the content transfer information list.
429          *
430          * @brief       <i> [Deprecated] </i>
431          * @deprecated  This class is deprecated. Instead of using this class, use DownloadManager class.
432          * @since               2.0
433          *
434          * @return              A pointer to a list containing the ContentTransferInfo instances, @n
435          *                              else an empty list if there is no result and no error
436          */
437         Tizen::Base::Collection::IList* GetContentTransferInfoListN(void) const;
438
439         /**
440          * Gets the list of transfers that are in progress.
441          *
442          * @brief       <i> [Deprecated] </i>
443          * @deprecated  This class is deprecated. Instead of using this class, use DownloadManager class.
444          * @since               2.0
445          *
446          * @return              A pointer to a list containing the ContentTransferInfo instances, @n
447          *                              else an empty list if there is no result and no error
448          */
449         Tizen::Base::Collection::IList* GetContentTransferInfoListInProgressN(void) const;
450
451         /**
452          * Sets the interval of the progress. @n
453          * The input is a percentage value between @c 0 and @c 100. The default value is @c 0.
454          * @c 0 means the application would not receive progress events.
455          *
456          * @brief       <i> [Deprecated] </i>
457          * @deprecated  This class is deprecated. Instead of using this class, use DownloadManager class.
458          * @since               2.0
459          *
460          * @param[in]   percent         The progress period interval as a percentage value
461          * @remarks     If a server does not provide the information about the content size, then the content module cannot verify the information. @n
462          *              In that case, progress event will occur randomly.
463          */
464         void SetProgressIntervalByPercent(int percent);
465
466 private:
467         /**
468          * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
469          */
470         ContentTransfer(const ContentTransfer& rhs);
471
472         /**
473          * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
474          */
475         ContentTransfer& operator =(const ContentTransfer& rhs);
476
477 private:
478         friend class _ContentTransferImpl;
479         _ContentTransferImpl* __pImpl;
480
481 };  // class ContentTransfer
482
483 }}  // Tizen::Content
484
485 #endif  // _FCNT_CONTENT_TRANSFER_H_