merge with master
[platform/framework/native/content.git] / src / inc / FCnt_ContentTransferImpl.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 /**
18  * @file                FCnt_ContentTransferImpl.h
19  * @brief               This is the header file for the %_ContentTransferImpl class.
20  *
21  * This header file contains the declarations of the %_ContentTransferImpl class.
22  */
23
24 #ifndef _FCNT_INTERNAL_CONTENT_TRANSFER_IMPL_H_
25 #define _FCNT_INTERNAL_CONTENT_TRANSFER_IMPL_H_
26
27 #include <unique_ptr.h>
28 #include <FBaseRtITimerEventListener.h>
29 #include <FBaseColAllElementsDeleter.h>
30 #include <FCntContentTransferInfo.h>
31
32 namespace Tizen { namespace Base { namespace Runtime
33 {
34 class Timer;
35 }}}
36
37 namespace Tizen { namespace Content
38 {
39
40 class IContentTransferListener;
41 class ContentTransfer;
42 class _ContentTransferEvent;
43 class _ContentDownloadHandler;
44 class _ContentDownloadUserData;
45
46 class _ContentTransferImpl
47         : virtual public Tizen::Base::Runtime::ITimerEventListener
48 {
49 public:
50         /**
51          * This is the default constructor for this class.
52          *
53          * @since 2.1
54          */
55         _ContentTransferImpl(void);
56
57         /**
58          * This is the destructor for this class.
59          *
60          * @since 2.1
61          */
62         virtual ~_ContentTransferImpl(void);
63
64         /**
65          * @see @ref Tizen::Content::ContentTransfer::Construct()
66          */
67         result Construct(IContentTransferListener& listener);
68
69         /**
70          * @see @ref Tizen::Content::ContentTransfer::Download(const Tizen::Base::Utility::Uri&, int, const Tizen::Base::String&, bool, RequestId&, const IContentTransferListener*, int)
71          */
72         result Download(const Tizen::Base::Utility::Uri& uri, int fileSize, const Tizen::Base::String& destFilePath, bool replace, RequestId& requestID, IContentTransferListener* pListener = null, int sec = 0);
73
74         /**
75          * @see @ref Tizen::Content::ContentTransfer::Download(const Tizen::Base::Utility::Uri&, const Tizen::Base::String&, RequestId&, bool, int, int)
76          */
77         result Download(const Tizen::Base::Utility::Uri& uri, const Tizen::Base::String& filePath, RequestId& reqId, bool replace = false, int timeout = 0, int progressInterval = 0);
78
79         /**
80          * @see @ref Tizen::Content::ContentTransfer::DownloadToBuffer(const Tizen::Base::Utility::Uri&, int, RequestId&, const IContentTransferListener*, int)
81          */
82         result DownloadToBuffer(const Tizen::Base::Utility::Uri& uri, int fileSize, RequestId& reqId, IContentTransferListener* pListener = null, int sec = 0);
83
84         /**
85          * @see @ref Tizen::Content::ContentTransfer::DownloadToBuffer(const Tizen::Base::Utility::Uri&, RequestId&, int, int)
86          */
87         result DownloadToBuffer(const Tizen::Base::Utility::Uri& uri, RequestId& reqId, int timeout = 0, int progressInterval = 0);
88
89         /**
90          * @see @ref Tizen::Content::ContentTransfer::SetDefaultTimeout()
91          */
92         void SetDefaultTimeout(int sec);
93
94         /**
95          * @see @ref Tizen::Content::ContentTransfer::GetDefaultTimeout()
96          */
97         int GetDefaultTimeout(void) const;
98
99         /**
100          * @see @ref Tizen::Content::ContentTransfer::Remove()
101          */
102         result Remove(RequestId reqId);
103
104         /**
105          * @see @ref Tizen::Content::ContentTransfer::RemoveAll()
106          */
107         result RemoveAll(void);
108
109         /**
110          * @see @ref Tizen::Content::ContentTransfer::Cancel()
111          */
112         result Cancel(RequestId reqId);
113
114         /**
115          * @see @ref Tizen::Content::ContentTransfer::CancelAll()
116          */
117         result CancelAll(void);
118
119         /**
120          * @see @ref Tizen::Content::ContentTransfer::GetContentTransferInfoListN()
121          */
122         Tizen::Base::Collection::IList* GetContentTransferInfoListN(void) const;
123
124         /**
125          * @see @ref Tizen::Content::ContentTransfer::GetContentTransferInfoListInProgressN()
126          */
127         Tizen::Base::Collection::IList* GetContentTransferInfoListInProgressN(void) const;
128
129         /**
130          * @see @ref Tizen::Content::ContentTransfer::SetProgressIntervalByPercent()
131          */
132         void SetProgressIntervalByPercent(int percent);
133
134         /**
135          * Gets the Impl instance.
136          *
137          * @since 2.1
138          * @return              The pointer to _ContentTransferImpl
139          * @param[in]   contentTransfer         An instance of ContentTransfer
140          */
141         static _ContentTransferImpl* GetInstance(ContentTransfer& contentTransfer);
142
143         /**
144          * Gets the Impl instance.
145          *
146          * @since 2.1
147          * @return              The pointer to _ContentTransferImpl
148          * @param[in]   contentTransfer         An instance of ContentTransfer
149          */
150         static const _ContentTransferImpl* GetInstance(const ContentTransfer& contentTransfer);
151
152 private:
153         _ContentTransferImpl(const _ContentTransferImpl& rhs);
154         virtual void OnTimerExpired(Tizen::Base::Runtime::Timer& timer);
155
156         RequestId GetRequestId(void) const;
157         ContentTransferInfo* GetContentTransferInfoByRequestId(RequestId requestId) const;
158         void StartTimer(void);
159         result GetEmptySlot(int& slot) const;
160         void DeleteDownloadObj(void);
161         result CheckDestPath(const Tizen::Base::String& destPath, bool replace);
162         result CheckDownloadStatus(const Tizen::Base::Utility::Uri& uri, const Tizen::Base::String& destPath);
163         result AddTransferItem(const Tizen::Base::Utility::Uri& uri, const Tizen::Base::String& destPath,
164                         const Tizen::Base::String& sourcePath, int sourceFileSize, ContentTransferStatus status,
165                         IContentTransferListener* pListener, int sec, bool isBuffer, RequestId& requestId);
166         result AddTransferItem(const Tizen::Base::Utility::Uri& uri, const Tizen::Base::String& destPath,
167                                                                                   const Tizen::Base::String& sourcePath, ContentTransferStatus status,
168                                                                                   int timeout, int interval, bool isBuffer, RequestId& requestId);
169         result SetDownloadSlotInfo(ContentTransferInfo* pTransferInfo, int& slot);
170         result RequestErrorEvent(result requestErrorCode, ContentTransferInfo* pTransferInfo);
171         result RemoveCompletedTransferInfo(Tizen::Base::Collection::ArrayList* pTransferInfoList);
172         bool ContentTransferHandler(void);
173
174         void InitializeEmptySlotInternal(_ContentDownloadUserData* pUserData);
175         int GetEmptySlotInternal(void) const;
176         void SetUsedSlotInternal(int slot);
177         void SetEmptySlotInternal(void);
178         int GetMaxDownloadCount(void) const;
179
180         _ContentTransferImpl& operator =(const _ContentTransferImpl& rhs);
181
182 private:
183         RequestId __requestId;
184         RequestId __restRequestId;
185         int __maxDownloadCount;
186         int __timeout;
187         int __percent;
188         bool __timerStarted;
189         bool __isBuffer;
190         Tizen::Base::String __destFilePath;
191         std::unique_ptr<_ContentDownloadUserData> __pContentDownloadUserData;
192         std::unique_ptr<_ContentDownloadUserData[]> __pContentDownloadUserDataSequence;
193         std::unique_ptr<_ContentDownloadHandler> __pContentDownloadHandler;
194         std::unique_ptr<_ContentDownloadHandler[]> __pContentDownloadHandlerSequence;
195         std::unique_ptr<_ContentTransferEvent> __pTransferEvent;
196         std::unique_ptr<Tizen::Base::Collection::ArrayList, Tizen::Base::Collection::AllElementsDeleter> __pTransferInfoList;
197         std::unique_ptr<Tizen::Base::Runtime::Timer> __pTimer;
198 };  // class _ContentTransferImpl
199
200 }}  // Tizen::Content
201
202 #endif  // _FCNT_INTERNAL_CONTENT_TRANSFER_IMPL_H_
203