Open some APIs
authorMinje Ahn <minje.ahn@samsung.com>
Wed, 5 Apr 2017 01:26:15 +0000 (10:26 +0900)
committerMinje ahn <minje.ahn@samsung.com>
Wed, 5 Apr 2017 03:47:23 +0000 (20:47 -0700)
Open Connect/Disconnect API.

Change-Id: I8d7f6569e8bd0030d1be9a4af5d5cb077776b961
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
packaging/csapi-media-content.spec
src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/ContentDatabase.cs
src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/ContentManager.cs

index ef2815d..0902377 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       csapi-media-content
 Summary:    Tizen Media Content API for C#
-Version:    1.0.15
+Version:    1.0.16
 Release:    1
 Group:      Development/Libraries
 License:    Apache-2.0
index 02b077a..7e9d548 100755 (executable)
@@ -43,29 +43,23 @@ namespace Tizen.Content.MediaContent
     /// </summary>
     public class ContentDatabase
     {
-        private bool _isConnected = false;
-        internal ContentDatabase()
-        {
-        }
-
-        internal void ConnectToDB()
+        /// <summary>
+        /// Connect to the media database to search, insert, remove or modify media information.
+        /// </summary>
+        /// <remarks>
+        /// For information security, disconnect() after use media database.
+        /// </remarks>
+        public static void Connect()
         {
-            if (!_isConnected)
-            {
-                MediaContentValidator.ThrowIfError(Interop.Content.Connect(), "Connect failed");
-
-                _isConnected = true;
-            }
+            MediaContentValidator.ThrowIfError(Interop.Content.Connect(), "Connect failed");
         }
 
-        private void DisconnectFromDB()
+        /// <summary>
+        /// Disconnect from the media database.
+        /// </summary>
+        public static void Disconnect()
         {
-            if (_isConnected)
-            {
-                MediaContentValidator.ThrowIfError(Interop.Content.Disconnect(), "Disconnect failed");
-
-                _isConnected = false;
-            }
+            MediaContentValidator.ThrowIfError(Interop.Content.Disconnect(), "Disconnect failed");
         }
 
         private static readonly Interop.Content.MediaContentDBUpdatedCallback s_contentUpdatedCallback = (
@@ -128,8 +122,6 @@ namespace Tizen.Content.MediaContent
                 groupType = filter.GroupType;
             }
 
-            ConnectToDB();
-
             if (typeof(T) == typeof(MediaInformation))
             {
                 MediaContentValidator.ThrowIfError(
@@ -185,7 +177,6 @@ namespace Tizen.Content.MediaContent
         /// <returns>MediaInformation instance for the associated id.It throws Exception for invalid Id.</returns>
         public MediaInformation Select(string id)
         {
-            ConnectToDB();
             Interop.MediaInformation.SafeMediaInformationHandle mediaHandle;
             MediaContentValidator.ThrowIfError(
                 Interop.MediaInformation.GetMediaFromDB(id, out mediaHandle), "Failed to get information");
@@ -233,7 +224,6 @@ namespace Tizen.Content.MediaContent
         /// <returns>ContentCollection instance for the associated id.It throws Exception for invalid Id.</returns>
         public T Select<T>(string id) where T : ContentCollection
         {
-            ConnectToDB();
             ContentCollection result = null;
             IntPtr handle = IntPtr.Zero;
 
@@ -273,7 +263,6 @@ namespace Tizen.Content.MediaContent
         /// <returns>ContentCollection instance for the associated id.It throws Exception for invalid Id.</returns>
         public T Select<T>(int id) where T : ContentCollection
         {
-            ConnectToDB();
             ContentCollection result = null;
             IntPtr handle = IntPtr.Zero;
 
@@ -448,7 +437,6 @@ namespace Tizen.Content.MediaContent
         /// </returns>
         public IEnumerable<T> SelectAll<T>(ContentFilter filter)
         {
-            ConnectToDB();
             if (typeof(T) == typeof(MediaInformation))
             {
                 IEnumerable<MediaInformation> mediaList = GetMediaInformations(filter);
@@ -496,7 +484,6 @@ namespace Tizen.Content.MediaContent
         /// <returns>List of media</returns>
         private IEnumerable<MediaInformation> GetMediaInformations(ContentFilter filter)
         {
-            ConnectToDB();
             IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero;
             List<MediaInformation> mediaInformationList = new List<MediaInformation>();
             Interop.MediaInformation.MediaInformationCallback callback = (IntPtr mediaHandle, IntPtr userData) =>
@@ -550,7 +537,6 @@ namespace Tizen.Content.MediaContent
         /// <param name="mediaInfo">The MediaInformation to be deleted</param>
         public void Delete(MediaInformation mediaInfo)
         {
-            ConnectToDB();
             MediaContentValidator.ThrowIfError(
                 Interop.MediaInformation.Delete(mediaInfo.MediaId), "Failed to remove information");
         }
@@ -564,7 +550,6 @@ namespace Tizen.Content.MediaContent
         /// <param name="contentcollection">The ContentCollection instance to be deleted</param>
         public void Delete(ContentCollection contentcollection)
         {
-            ConnectToDB();
             Type type = contentcollection.GetType();
 
             if (type == typeof(Tag))
@@ -585,14 +570,12 @@ namespace Tizen.Content.MediaContent
 
         internal void Delete(MediaBookmark bookmark)
         {
-            ConnectToDB();
             MediaContentValidator.ThrowIfError(
                 Interop.MediaBookmark.DeleteFromDb(bookmark.Id), "Failed to remove information");
         }
 
         internal void Delete(MediaFace face)
         {
-            ConnectToDB();
             MediaContentValidator.ThrowIfError(
                 Interop.Face.DeleteFromDb(face.Id), "Failed to remove face information");
         }
@@ -604,7 +587,6 @@ namespace Tizen.Content.MediaContent
         /// <param name="contentCollection">The content collection to be updated</param>
         public void Update(ContentCollection contentCollection)
         {
-            ConnectToDB();
             Type type = contentCollection.GetType();
             if (type == typeof(Tag))
             {
@@ -633,7 +615,6 @@ namespace Tizen.Content.MediaContent
         /// <param name="mediaInfo">The MediaInformation object to be updated</param>
         public void Update(MediaInformation mediaInfo)
         {
-            ConnectToDB();
             Type type = mediaInfo.GetType();
             if (type == typeof(ImageInformation))
             {
@@ -672,7 +653,6 @@ namespace Tizen.Content.MediaContent
 
         internal void Update(MediaFace face)
         {
-            ConnectToDB();
             MediaContentValidator.ThrowIfError(Interop.Face.UpdateToDb(face.Handle), "Failed to update DB");
         }
 
@@ -683,7 +663,6 @@ namespace Tizen.Content.MediaContent
         /// <param name="contentCollection">The content collection to be inserted</param>
         public void Insert(ContentCollection contentCollection)
         {
-            ConnectToDB();
             Type type = contentCollection.GetType();
             IntPtr handle = IntPtr.Zero;
             if (type == typeof(Tag))
@@ -706,14 +685,12 @@ namespace Tizen.Content.MediaContent
 
         internal void Insert(string mediaId, uint offset, string thumbnailPath)
         {
-            ConnectToDB();
             MediaContentValidator.ThrowIfError(
                 Interop.MediaBookmark.InsertToDb(mediaId, offset, thumbnailPath), "Failed to insert information");
         }
 
         internal void Insert(MediaFace face)
         {
-            ConnectToDB();
             MediaContentValidator.ThrowIfError(
                 Interop.Face.InsertToDb(((MediaFace)face).Handle), "Failed to insert information");
         }
index 44a8a22..acb313b 100755 (executable)
@@ -71,7 +71,6 @@ namespace Tizen.Content.MediaContent
         /// </remarks>
         public static void Scan(string filePath)
         {
-            Database.ConnectToDB();
             MediaContentValidator.ThrowIfError(Interop.Content.ScanFile(filePath), "Failed scan");
         }
 
@@ -82,7 +81,6 @@ namespace Tizen.Content.MediaContent
         /// <returns>the MediaInformation instance about added media path</returns>
         public static MediaInformation AddMediaInformation(string filePath)
         {
-            Database.ConnectToDB();
             Interop.MediaInformation.SafeMediaInformationHandle mediaInformationHandle;
             MediaContentValidator.ThrowIfError(
                 Interop.MediaInformation.Insert(filePath, out mediaInformationHandle), "Failed to Insert MediaInformation to DB");
@@ -211,7 +209,6 @@ namespace Tizen.Content.MediaContent
         /// </returns>
         public static Task AddMediaInformationBatchAsync(IEnumerable<string> filePaths)
         {
-            Database.ConnectToDB();
             var task = new TaskCompletionSource<int>();
             string[] paths = ((List<string>)filePaths).ToArray();
             Interop.MediaInformation.MediaInsertCompletedCallback callback = (MediaContentError error, IntPtr userData) =>
@@ -234,7 +231,6 @@ namespace Tizen.Content.MediaContent
         /// </returns>
         public static Task AddBurstShotImagesAsync(IEnumerable<string> filePaths)
         {
-            Database.ConnectToDB();
             var task = new TaskCompletionSource<int>();
             string[] paths = ((List<string>)filePaths).ToArray();
             Interop.MediaInformation.MediaInsertBurstShotCompletedCallback callback = (MediaContentError error, IntPtr userData) =>
@@ -256,7 +252,6 @@ namespace Tizen.Content.MediaContent
         /// <param name="filter">The content filter to which media will be matched</param>
         public static void RemoveMediaInformationBatch(ContentFilter filter)
         {
-            Database.ConnectToDB();
             IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero;
             MediaContentValidator.ThrowIfError(
                 Interop.MediaInformation.BatchDelete(handle), "Failed to remove items");