Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Network.Mtp / Tizen.Network.Mtp / MtpObject.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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 using System;
18 using System.Runtime.InteropServices;
19 using System.Collections.Generic;
20
21 namespace Tizen.Network.Mtp
22 {
23     /// <summary>
24     /// A class for Mtp Object information. It allows applications to handle object information.
25     /// </summary>
26     /// <since_tizen> 5 </since_tizen>
27     public class MtpObject : IDisposable
28     {
29         private int _deviceHandle = -1;
30         private int _objectHandle = -1;
31         private bool disposed = false;
32
33         /// <summary>
34         /// Gets the filename of the object information.
35         /// </summary>
36         /// <value>File name of object.</value>
37         /// <since_tizen> 5 </since_tizen>
38         public string FileName
39         {
40             get
41             {
42                 IntPtr strPtr;
43                 int ret = Interop.Mtp.ObjectInformation.GetFileName(_deviceHandle, _objectHandle, out strPtr);
44                 if (ret != (int)MtpError.None)
45                 {
46                     Log.Error(Globals.LogTag, "Failed to get file name, Error - " + (MtpError)ret);
47                     return "";
48                 }
49                 return Marshal.PtrToStringAnsi(strPtr);
50             }
51         }
52
53         /// <summary>
54         /// Gets the keywords of the object information.
55         /// </summary>
56         /// <value>Keywords of object.</value>
57         /// <since_tizen> 5 </since_tizen>
58         public string Keywords
59         {
60             get
61             {
62                 IntPtr strPtr;
63                 int ret = Interop.Mtp.ObjectInformation.GetKeywords(_deviceHandle, _objectHandle, out strPtr);
64                 if (ret != (int)MtpError.None)
65                 {
66                     Log.Error(Globals.LogTag, "Failed to get keywords, Error - " + (MtpError)ret);
67                     return "";
68                 }
69                 return Marshal.PtrToStringAnsi(strPtr);
70             }
71         }
72
73         /// <summary>
74         /// Gets the association description of the object information.
75         /// </summary>
76         /// <value>Association description of object.</value>
77         /// <since_tizen> 5 </since_tizen>
78         public int AssociationDescription
79         {
80             get
81             {
82                 int value;
83                 int ret = Interop.Mtp.ObjectInformation.GetAssociationDescription(_deviceHandle, _objectHandle, out value);
84                 if (ret != (int)MtpError.None)
85                 {
86                     Log.Error(Globals.LogTag, "Failed to get association decription, Error - " + (MtpError)ret);
87                 }
88                 return value;
89             }
90         }
91
92         /// <summary>
93         /// Gets the association type of the object information.
94         /// </summary>
95         /// <value>Association type of object.</value>
96         /// <since_tizen> 5 </since_tizen>
97         public int AssociationType
98         {
99             get
100             {
101                 int value;
102                 int ret = Interop.Mtp.ObjectInformation.GetAssociationType(_deviceHandle, _objectHandle, out value);
103                 if (ret != (int)MtpError.None)
104                 {
105                     Log.Error(Globals.LogTag, "Failed to get association type, Error - " + (MtpError)ret);
106                 }
107                 return value;
108             }
109         }
110
111         /// <summary>
112         /// Gets the size of the object information.
113         /// </summary>
114         /// <value>Size of object.</value>
115         /// <since_tizen> 5 </since_tizen>
116         public int Size
117         {
118             get
119             {
120                 int value;
121                 int ret = Interop.Mtp.ObjectInformation.GetSize(_deviceHandle, _objectHandle, out value);
122                 if (ret != (int)MtpError.None)
123                 {
124                     Log.Error(Globals.LogTag, "Failed to get size, Error - " + (MtpError)ret);
125                 }
126                 return value;
127             }
128         }
129
130         /// <summary>
131         /// Gets the parent object handle of the object information.
132         /// </summary>
133         /// <value>Handle of Parent object.</value>
134         /// <since_tizen> 5 </since_tizen>
135         public int ParentObjectHandle
136         {
137             get
138             {
139                 int value;
140                 int ret = Interop.Mtp.ObjectInformation.GetParentObjectHandle(_deviceHandle, _objectHandle, out value);
141                 if (ret != (int)MtpError.None)
142                 {
143                     Log.Error(Globals.LogTag, "Failed to get parent object handle, Error - " + (MtpError)ret);
144                 }
145                 return value;
146             }
147         }
148
149         /// <summary>
150         ///  Gets the mtp storage of the object information.
151         /// </summary>
152         /// <value>Storage of object.</value>
153         /// <since_tizen> 5 </since_tizen>
154         public int Storage
155         {
156             get
157             {
158                 int value;
159                 int ret = Interop.Mtp.ObjectInformation.GetStorage(_deviceHandle, _objectHandle, out value);
160                 if (ret != (int)MtpError.None)
161                 {
162                     Log.Error(Globals.LogTag, "Failed to get storage, Error - " + (MtpError)ret);
163                 }
164                 return value;
165             }
166         }
167
168         /// <summary>
169         /// Gets the object created time of the object information.
170         /// </summary>
171         /// <value>Date created of object.</value>
172         /// <since_tizen> 5 </since_tizen>
173         public int DateCreated
174         {
175             get
176             {
177                 int value;
178                 int ret = Interop.Mtp.ObjectInformation.GetDateCreated(_deviceHandle, _objectHandle, out value);
179                 if (ret != (int)MtpError.None)
180                 {
181                     Log.Error(Globals.LogTag, "Failed to get date created, Error - " + (MtpError)ret);
182                 }
183                 return value;
184             }
185         }
186
187         /// <summary>
188         /// Gets the object modified time of the object information.
189         /// </summary>
190         /// <value>Date modified of object.</value>
191         /// <since_tizen> 5 </since_tizen>
192         public int DateModified
193         {
194             get
195             {
196                 int value;
197                 int ret = Interop.Mtp.ObjectInformation.GetDateModified(_deviceHandle, _objectHandle, out value);
198                 if (ret != (int)MtpError.None)
199                 {
200                     Log.Error(Globals.LogTag, "Failed to get date modified, Error - " + (MtpError)ret);
201                 }
202                 return value;
203             }
204         }
205
206         /// <summary>
207         /// Gets the file type of the object information.
208         /// </summary>
209         /// <value>File type of object.</value>
210         /// <since_tizen> 5 </since_tizen>
211         public MtpFileType FileType
212         {
213             get
214             {
215                 int value;
216                 int ret = Interop.Mtp.ObjectInformation.GetStorage(_deviceHandle, _objectHandle, out value);
217                 if (ret != (int)MtpError.None)
218                 {
219                     Log.Error(Globals.LogTag, "Failed to get file type, Error - " + (MtpError)ret);
220                 }
221                 return (MtpFileType)value;
222             }
223         }
224
225         /// <summary>
226         /// Gets the image bit depth of the object information.
227         /// </summary>
228         /// <value>Bit depth of image.</value>
229         /// <since_tizen> 5 </since_tizen>
230         public int ImageBitDepth
231         {
232             get
233             {
234                 int value;
235                 int ret = Interop.Mtp.ObjectInformation.GetImageBitDepth(_deviceHandle, _objectHandle, out value);
236                 if (ret != (int)MtpError.None)
237                 {
238                     Log.Error(Globals.LogTag, "Failed to get image bit depth, Error - " + (MtpError)ret);
239                 }
240                 return value;
241             }
242         }
243
244         /// <summary>
245         /// Gets the image pixel width of the object information.
246         /// </summary>
247         /// <value>Pixel width of image.</value>
248         /// <since_tizen> 5 </since_tizen>
249         public int ImagePixelWidth
250         {
251             get
252             {
253                 int value;
254                 int ret = Interop.Mtp.ObjectInformation.GetImagePixWidth(_deviceHandle, _objectHandle, out value);
255                 if (ret != (int)MtpError.None)
256                 {
257                     Log.Error(Globals.LogTag, "Failed to get image pixel width, Error - " + (MtpError)ret);
258                 }
259                 return value;
260             }
261         }
262
263         /// <summary>
264         /// Gets the image pixel height of the object information.
265         /// </summary>
266         /// <value>Pixel height of image.</value>
267         /// <since_tizen> 5 </since_tizen>
268         public int ImagePixelHeight
269         {
270             get
271             {
272                 int value;
273                 int ret = Interop.Mtp.ObjectInformation.GetImagePixHeight(_deviceHandle, _objectHandle, out value);
274                 if (ret != (int)MtpError.None)
275                 {
276                     Log.Error(Globals.LogTag, "Failed to get image pixel height, Error - " + (MtpError)ret);
277                 }
278                 return value;
279             }
280         }
281
282         /// <summary>
283         /// Gets the thumbnail size of the object information.
284         /// </summary>
285         /// <value>Size of thumbnail.</value>
286         /// <since_tizen> 5 </since_tizen>
287         public int ThumbnailSize
288         {
289             get
290             {
291                 int value;
292                 int ret = Interop.Mtp.ObjectInformation.GetThumbnailSize(_deviceHandle, _objectHandle, out value);
293                 if (ret != (int)MtpError.None)
294                 {
295                     Log.Error(Globals.LogTag, "Failed to get thumbnail size, Error - " + (MtpError)ret);
296                 }
297                 return value;
298             }
299         }
300
301         /// <summary>
302         /// Gets the thumbnail file type of the object information.
303         /// </summary>
304         /// <value>File type of thumbnail.</value>
305         /// <since_tizen> 5 </since_tizen>
306         public int ThumbnailFileType
307         {
308             get
309             {
310                 int value;
311                 int ret = Interop.Mtp.ObjectInformation.GetThumbnailFileType(_deviceHandle, _objectHandle, out value);
312                 if (ret != (int)MtpError.None)
313                 {
314                     Log.Error(Globals.LogTag, "Failed to get thumbnail file type, Error - " + (MtpError)ret);
315                 }
316                 return value;
317             }
318         }
319
320         /// <summary>
321         /// Gets the thumbnail pixel width of the object information.
322         /// </summary>
323         /// <value>Pixel width of thumbnail.</value>
324         /// <since_tizen> 5 </since_tizen>
325         public int ThumbnailPixelWidth
326         {
327             get
328             {
329                 int value;
330                 int ret = Interop.Mtp.ObjectInformation.GetThumbnailPixWidth(_deviceHandle, _objectHandle, out value);
331                 if (ret != (int)MtpError.None)
332                 {
333                     Log.Error(Globals.LogTag, "Failed to get thumbnail pixel width, Error - " + (MtpError)ret);
334                 }
335                 return value;
336             }
337         }
338
339         /// <summary>
340         /// Gets the thumbnail pixel height of the object information.
341         /// </summary>
342         /// <value>Pixel height of thumbnail.</value>
343         /// <since_tizen> 5 </since_tizen>
344         public int ThumbnailPixelHeight
345         {
346             get
347             {
348                 int value;
349                 int ret = Interop.Mtp.ObjectInformation.GetThumbnailPixHeight(_deviceHandle, _objectHandle, out value);
350                 if (ret != (int)MtpError.None)
351                 {
352                     Log.Error(Globals.LogTag, "Failed to get thumbnail pixel height, Error - " + (MtpError)ret);
353                 }
354                 return value;
355             }
356         }
357
358         internal MtpObject(int deviceHandle, int objectHandle)
359         {
360             _deviceHandle = deviceHandle;
361             _objectHandle = objectHandle;
362         }
363
364         ~MtpObject()
365         {
366             Dispose(false);
367         }
368
369         public void Dispose()
370         {
371             Dispose(true);
372             GC.SuppressFinalize(this);
373         }
374
375         private void Dispose(bool disposing)
376         {
377             if (disposed)
378                 return;
379
380             if (disposing)
381             {
382                 // Free managed objects.
383             }
384             //Free unmanaged objects
385             disposed = true;
386         }
387
388         internal int GetHandle()
389         {
390             return _objectHandle;
391         }
392     }
393 }