2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file FCntContentManager.h
19 * @brief This is the header file for the %ContentManager class.
21 * This header file contains the declarations of the %ContentManager class.
24 #ifndef _FCNT_CONTENT_MANAGER_H_
25 #define _FCNT_CONTENT_MANAGER_H_
27 #include <FBaseObject.h>
28 #include <FCntTypes.h>
30 namespace Tizen { namespace Base
35 namespace Tizen { namespace Content
39 class _ContentManagerImpl;
40 class IContentScanListener;
41 class IContentUpdateEventListener;
44 * @class ContentManager
45 * @brief This class provides methods for local content management.
49 * The %ContentManager class manages the information stored locally on the device's content database. @n
50 * It also allows you to create, read, update, and delete specific content information in the database.
52 * For more information on managing content on the device, see <a href="../org.tizen.native.appprogramming/html/guide/content/device_content_mgmt.htm">Device Content Management</a>.
54 * The following example demonstrates how to use the %ContentManager class.
58 * MyClass::TestContentManager(void)
60 * result r = E_SUCCESS;
61 * ContentId contentId;
62 * ContentManager contentManager;
63 * r = contentManager.Construct();
64 * TryReturn(!IsFailed(r), r, "Construct failed.");
67 * ImageContentInfo imageContentInfo;
68 * r = imageContentInfo.Construct(null);
69 * TryReturn(!IsFailed(r), r, "Construct failed.");
71 * r = imageContentInfo.SetKeyword(L"platform, tizen");
77 * r = imageContentInfo.SetLocationTag(L"seoul");
83 * Tizen::Base::String sourcePath = Tizen::App::App::GetInstance()->GetAppRootPath() + L"data/flower.jpg";
84 * Tizen::Base::String destPath = Tizen::System::Environment::GetMediaPath() + L"Images/flower.jpg";
86 * contentId = contentManager.CreateContent(sourcePath, destPath, false, &imageContentInfo);
87 * TryReturn(Tizen::Base::UuId::GetInvalidUuId() != contentId, GetLastResult(), "CreateContent failed.");
90 * ImageContentInfo* pImageContentInfo = null;
91 * pImageContentInfo = dynamic_cast<ImageContentInfo*>(contentManager.GetContentInfoN(contentId));
92 * TryReturn(pImageContentInfo != null, GetLastResult(), "GetContentInfoN failed.");
94 * pImageContentInfo->GetContentPath();
97 * r = pImageContentInfo->SetKeyword(L"apple, fruit");
100 * delete pImageContentInfo;
103 * r = pImageContentInfo->SetProvider(L"kw1128");
106 * delete pImageContentInfo;
109 * r = contentManager.UpdateContent(*pImageContentInfo);
112 * delete pImageContentInfo;
117 * r = contentManager.DeleteContent(contentId);
120 * delete pImageContentInfo;
124 * delete pImageContentInfo;
129 class _OSP_EXPORT_ ContentManager
130 : virtual public Tizen::Base::Object
135 * The object is not fully constructed after this constructor is called. For full construction, the Construct() method must be called right after calling this constructor.
139 * @remarks After creating an instance of this class, the Construct() method must be called explicitly to initialize this instance.
141 ContentManager(void);
144 * This destructor overrides Tizen::Base::Object::~Object().
148 virtual ~ContentManager(void);
151 * Initializes this instance of %ContentManager.
155 * @return An error code
156 * @exception E_SUCCESS The method is successful.
157 * @exception E_OUT_OF_MEMORY The memory is insufficient.
158 * @exception E_SYSTEM A system error has occurred.
160 result Construct(void);
163 * Creates the content information.
167 * @privilege %http://tizen.org/privilege/content.write
169 * @return The content ID
170 * @param[in] contentInfo An instance of ContentInfo
171 * @exception E_SUCCESS The method is successful.
172 * @exception E_INVALID_ARG The specified input parameter is invalid, or
173 * the specified format is invalid or not supported on the device.
174 * @exception E_FILE_NOT_FOUND The specified file cannot be found or accessed.
175 * @exception E_IO An I/O error has occurred.
176 * @exception E_OUT_OF_MEMORY The memory is insufficient.
177 * @exception E_SYSTEM A system error has occurred.
178 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
179 * @exception E_SERVICE_BUSY The database is busy.
181 * - If the E_UNSUPPORTED_FORMAT exception is received from ContentManagerUtil::CheckContentType(),
182 * the file can be created as a content only using the OtherContentInfo class.
183 * - The specific error code can be accessed using the GetLastResult() method.
185 ContentId CreateContent(const ContentInfo& contentInfo);
188 * Writes the content in the byte buffer to the destination path and creates the content information.
191 * @brief <i> [Compatibility] </i>
195 * @compatibility This method has compatibility issues with OSP compatible applications. @n
196 * For more information, see @ref CompContentManagerCreateContentPage "here".
199 * @privilege %http://tizen.org/privilege/content.write
201 * @return The content ID
202 * @param[in] byteBuffer The @c byteBuffer of the content to create
203 * @param[in] destinationPath The destination file path formed by the @c byteBuffer
204 * @param[in] pContentInfo A pointer to the ContentInfo instance @n
205 * If the content path exists in %ContentInfo, it gets ignored.
206 * @exception E_SUCCESS The method is successful.
207 * @exception E_INVALID_ARG Either of the following conditions has occurred: @n
208 * - A specified input parameter is invalid. @n
209 * - There is a mismatch between the type specified in ContentInfo and the type specified in the actual content.
210 * @exception E_STORAGE_FULL The storage is full.
211 * @exception E_FILE_ALREADY_EXIST The specified file already exists.
212 * @exception E_ILLEGAL_ACCESS Access is denied due to insufficient permission.
213 * @exception E_MAX_EXCEEDED The number of opened files has exceeded the maximum limit.
214 * @exception E_IO An I/O error has occurred.
215 * @exception E_OUT_OF_MEMORY The memory is insufficient.
216 * @exception E_SYSTEM A system error has occurred.
217 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
218 * @exception E_SERVICE_BUSY The database is busy.
220 * - The destination path should start with the directory path returned by either Tizen::System::Environment::GetMediaPath() or Tizen::System::Environment::GetExternalStoragePath().
221 * - The specific error code can be accessed using the GetLastResult() method.
223 ContentId CreateContent(const Tizen::Base::ByteBuffer& byteBuffer, const Tizen::Base::String& destinationPath, const ContentInfo* pContentInfo = null);
226 * Copies or moves the actual content to the destination path and creates the content information.
229 * @brief <i> [Compatibility] </i>
233 * @compatibility This method has compatibility issues with OSP compatible applications. @n
234 * For more information, see @ref CompContentManagerCreateContentPage "here".
237 * @privilege %http://tizen.org/privilege/content.write
239 * @return The content ID
240 * @param[in] sourcePath The source file path
241 * @param[in] destinationPath The destination file path
242 * @param[in] deleteSource Set to @c true in order to delete the source file, @n
244 * @param[in] pContentInfo A pointer to the ContentInfo instance @n
245 * If the content path exists in %ContentInfo, it gets ignored.
246 * @exception E_SUCCESS The method is successful.
247 * @exception E_INVALID_ARG Either of the following conditions has occurred: @n
248 * - A specified input parameter is invalid. @n
249 * - There is a mismatch between the type of the source path and destination path. @n
250 * - There is a mismatch between the type specified in ContentInfo and the type specified in the actual content.
251 * @exception E_FILE_NOT_FOUND The specified file cannot be found or accessed.
252 * @exception E_STORAGE_FULL The storage is full.
253 * @exception E_FILE_ALREADY_EXIST The specified file already exists.
254 * @exception E_ILLEGAL_ACCESS Access is denied due to insufficient permission.
255 * @exception E_MAX_EXCEEDED The number of opened files has exceeded the maximum limit.
256 * @exception E_IO An I/O error has occurred.
257 * @exception E_OUT_OF_MEMORY The memory is insufficient.
258 * @exception E_SYSTEM A system error has occurred.
259 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
260 * @exception E_SERVICE_BUSY The database is busy.
262 * - The source path should start with the directory path returned by either Tizen::App::App::GetAppRootPath() or Tizen::System::Environment::GetExternalStoragePath(). @n
263 * The destination path should start with the directory path returned by either Tizen::System::Environment::GetMediaPath() or Tizen::System::Environment::GetExternalStoragePath().
264 * - The specific error code can be accessed using the GetLastResult() method.
266 ContentId CreateContent(const Tizen::Base::String& sourcePath, const Tizen::Base::String& destinationPath, bool deleteSource, const ContentInfo* pContentInfo = null);
270 * @page CompContentManagerCreateContentPage Compatibility for the file path.
271 * @section CompContentManagerCreateContentPageIssueSection Issues
272 * The content path argument of this method in OSP compatible applications has the following issues: @n
273 * -# The content path should be a path that begins with an allowed path prefix. @n
274 * For example, L"/Media/Images/flower.jpg", L"/Storagecard/Media/Images/flower.jpg".
276 * @section CompContentManagerCreateContentPageSolutionSection Resolutions
277 * This issue has been resolved in Tizen. @n
278 * -# The content path can be a path without a specific allowed path prefix. @n
279 * Application do not need to know the specific allowed path prefixes. @n
280 * To get the directory path, use the following methods: @n
281 * - For accessing the home directory, use Tizen::App::App::GetInstance()->GetAppRootPath().
282 * - For accessing the media directory, use Tizen::System::Environment::GetMediaPath().
283 * - For accessing the external storage, use Tizen::System::Environment::GetExternalStoragePath().
289 * Gets the content information.
293 * @privilege %http://tizen.org/privilege/content.read
295 * @return A pointer to ContentInfo
296 * @param[in] contentId The content ID
297 * @exception E_SUCCESS The method is successful.
298 * @exception E_INVALID_ARG The specified input parameter is invalid, or
299 * the content information corresponding to @c contentId cannot be found.
300 * @exception E_FILE_NOT_FOUND The specified file cannot be found or accessed.
301 * @exception E_OUT_OF_MEMORY The memory is insufficient.
302 * @exception E_SYSTEM A system error has occurred.
303 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
304 * @exception E_SERVICE_BUSY The database is busy.
305 * @remarks The specific error code can be accessed using the GetLastResult() method.
307 ContentInfo* GetContentInfoN(const ContentId& contentId) const;
310 * Updates the content information with the specified instance of ContentInfo.
314 * @privilege %http://tizen.org/privilege/content.write
316 * @return An error code
317 * @param[in] contentInfo An instance of ContentInfo
318 * @exception E_SUCCESS The method is successful.
319 * @exception E_INVALID_ARG The specified input parameter is invalid.
320 * @exception E_FILE_NOT_FOUND The specified file cannot be found or accessed.
321 * @exception E_OUT_OF_MEMORY The memory is insufficient.
322 * @exception E_SYSTEM A system error has occurred.
323 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
324 * @exception E_SERVICE_BUSY The database is busy.
326 result UpdateContent(const ContentInfo& contentInfo);
329 * Deletes the content information with the specified content ID.
333 * @privilege %http://tizen.org/privilege/content.write
335 * @return An error code
336 * @param[in] contentId The content ID
337 * @exception E_SUCCESS The method is successful.
338 * @exception E_INVALID_ARG The specified input parameter is invalid, or
339 * the content information corresponding to @c contentId cannot be found.
340 * @exception E_FILE_NOT_FOUND The specified file cannot be found or accessed.
341 * @exception E_ILLEGAL_ACCESS Access is denied due to insufficient permission.
342 * @exception E_OUT_OF_MEMORY The memory is insufficient.
343 * @exception E_SYSTEM A system error has occurred.
344 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
345 * @exception E_SERVICE_BUSY The database is busy.
346 * @remarks The physical file corresponding to @c contentId is deleted.
348 result DeleteContent(const ContentId& contentId);
351 * Adds a listener to receive the database change notification.
355 * @return An error code
356 * @param[in] listener The event listener
357 * @exception E_SUCCESS The method is successful.
358 * @exception E_OBJ_ALREADY_EXIST The listener has already been added.
359 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
360 * @remarks Only a listener of an instance can be added.
361 * If you add more than two listeners, the listener added first will receive notification for the DB change.
363 result AddContentUpdateEventListener(IContentUpdateEventListener& listener);
366 * Removes a listener.
370 * @return An error code
371 * @param[in] listener The event listener
372 * @exception E_SUCCESS The method is successful.
373 * @exception E_OBJ_NOT_FOUND The listener is not found.
374 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
376 result RemoveContentUpdateEventListener(IContentUpdateEventListener& listener);
380 * Requests to scan a file.
384 * @privilege %http://tizen.org/privilege/content.write
386 * @return An error code
387 * @param[in] contentPath The content path
388 * @exception E_SUCCESS The method is successful.
389 * @exception E_INVALID_ARG The specified input parameter is invalid.
390 * @exception E_SERVICE_BUSY The database is busy.
391 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
392 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
394 static result ScanFile(const Tizen::Base::String& contentPath);
397 * Requests to scan a directory.
401 * @privilege %http://tizen.org/privilege/content.write
403 * @return An error code
404 * @param[in] directoryPath The directory path
405 * @param[in] recursive Set to @c true in order to recursively scan sub directories, @n
407 * @param[in] pListener The scan event listener
408 * @param[out] reqId The request ID
409 * @exception E_SUCCESS The method is successful.
410 * @exception E_INVALID_ARG The specified input parameter is invalid.
411 * @exception E_SERVICE_BUSY The database is busy.
412 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
413 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
414 * @remark Platform does not have the ownership of the listener.
416 static result ScanDirectory(const Tizen::Base::String& directoryPath, bool recursive, IContentScanListener* pListener, RequestId& reqId);
420 * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
422 ContentManager(const ContentManager& rhs);
425 * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
427 ContentManager& operator =(const ContentManager& rhs);
430 friend class _ContentManagerImpl;
431 _ContentManagerImpl* __pImpl;
433 }; // Class ContentManager
437 #endif // _FCNT_CONTENT_MANAGER_H_