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