2 * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.Runtime.InteropServices;
19 using System.Collections.Generic;
21 namespace Tizen.Network.Mtp
24 /// A class for Mtp Object information. It allows applications to handle object information.
26 /// <since_tizen> 4 </since_tizen>
27 public class MtpObject : IDisposable
29 private int _deviceHandle = -1;
30 private int _objectHandle = -1;
31 private bool disposed = false;
34 /// Gets the filename of the object information.
36 /// <value>File name of object.</value>
37 /// <since_tizen> 4 </since_tizen>
38 public string FileName
43 int ret = Interop.Mtp.ObjectInformation.GetFileName(_deviceHandle, _objectHandle, out strPtr);
44 if (ret != (int)MtpError.None)
46 Log.Error(Globals.LogTag, "Failed to get file name, Error - " + (MtpError)ret);
49 return Marshal.PtrToStringAnsi(strPtr);
54 /// Gets the keywords of the object information.
56 /// <value>Keywords of object.</value>
57 /// <since_tizen> 4 </since_tizen>
58 public string Keywords
63 int ret = Interop.Mtp.ObjectInformation.GetKeywords(_deviceHandle, _objectHandle, out strPtr);
64 if (ret != (int)MtpError.None)
66 Log.Error(Globals.LogTag, "Failed to get keywords, Error - " + (MtpError)ret);
69 return Marshal.PtrToStringAnsi(strPtr);
74 /// Gets the association description of the object information.
76 /// <value>Association description of object.</value>
77 /// <since_tizen> 4 </since_tizen>
78 public int AssociationDescription
83 int ret = Interop.Mtp.ObjectInformation.GetAssociationDescription(_deviceHandle, _objectHandle, out value);
84 if (ret != (int)MtpError.None)
86 Log.Error(Globals.LogTag, "Failed to get association decription, Error - " + (MtpError)ret);
93 /// Gets the association type of the object information.
95 /// <value>Association type of object.</value>
96 /// <since_tizen> 4 </since_tizen>
97 public int AssociationType
102 int ret = Interop.Mtp.ObjectInformation.GetAssociationType(_deviceHandle, _objectHandle, out value);
103 if (ret != (int)MtpError.None)
105 Log.Error(Globals.LogTag, "Failed to get association type, Error - " + (MtpError)ret);
112 /// Gets the size of the object information.
114 /// <value>Size of object.</value>
115 /// <since_tizen> 4 </since_tizen>
121 int ret = Interop.Mtp.ObjectInformation.GetSize(_deviceHandle, _objectHandle, out value);
122 if (ret != (int)MtpError.None)
124 Log.Error(Globals.LogTag, "Failed to get size, Error - " + (MtpError)ret);
131 /// Gets the parent object handle of the object information.
133 /// <value>Handle of Parent object.</value>
134 /// <since_tizen> 4 </since_tizen>
135 public int ParentObjectHandle
140 int ret = Interop.Mtp.ObjectInformation.GetParentObjectHandle(_deviceHandle, _objectHandle, out value);
141 if (ret != (int)MtpError.None)
143 Log.Error(Globals.LogTag, "Failed to get parent object handle, Error - " + (MtpError)ret);
150 /// Gets the mtp storage of the object information.
152 /// <value>Storage of object.</value>
153 /// <since_tizen> 4 </since_tizen>
159 int ret = Interop.Mtp.ObjectInformation.GetStorage(_deviceHandle, _objectHandle, out value);
160 if (ret != (int)MtpError.None)
162 Log.Error(Globals.LogTag, "Failed to get storage, Error - " + (MtpError)ret);
169 /// Gets the object created time of the object information.
171 /// <value>Date created of object.</value>
172 /// <since_tizen> 4 </since_tizen>
173 public int DateCreated
178 int ret = Interop.Mtp.ObjectInformation.GetDateCreated(_deviceHandle, _objectHandle, out value);
179 if (ret != (int)MtpError.None)
181 Log.Error(Globals.LogTag, "Failed to get date created, Error - " + (MtpError)ret);
188 /// Gets the object modified time of the object information.
190 /// <value>Date modified of object.</value>
191 /// <since_tizen> 4 </since_tizen>
192 public int DateModified
197 int ret = Interop.Mtp.ObjectInformation.GetDateModified(_deviceHandle, _objectHandle, out value);
198 if (ret != (int)MtpError.None)
200 Log.Error(Globals.LogTag, "Failed to get date modified, Error - " + (MtpError)ret);
207 /// Gets the file type of the object information.
209 /// <value>File type of object.</value>
210 /// <since_tizen> 4 </since_tizen>
211 public MtpFileType FileType
216 int ret = Interop.Mtp.ObjectInformation.GetStorage(_deviceHandle, _objectHandle, out value);
217 if (ret != (int)MtpError.None)
219 Log.Error(Globals.LogTag, "Failed to get file type, Error - " + (MtpError)ret);
221 return (MtpFileType)value;
226 /// Gets the image bit depth of the object information.
228 /// <value>Bit depth of image.</value>
229 /// <since_tizen> 4 </since_tizen>
230 public int ImageBitDepth
235 int ret = Interop.Mtp.ObjectInformation.GetImageBitDepth(_deviceHandle, _objectHandle, out value);
236 if (ret != (int)MtpError.None)
238 Log.Error(Globals.LogTag, "Failed to get image bit depth, Error - " + (MtpError)ret);
245 /// Gets the image pixel width of the object information.
247 /// <value>Pixel width of image.</value>
248 /// <since_tizen> 4 </since_tizen>
249 public int ImagePixelWidth
254 int ret = Interop.Mtp.ObjectInformation.GetImagePixWidth(_deviceHandle, _objectHandle, out value);
255 if (ret != (int)MtpError.None)
257 Log.Error(Globals.LogTag, "Failed to get image pixel width, Error - " + (MtpError)ret);
264 /// Gets the image pixel height of the object information.
266 /// <value>Pixel height of image.</value>
267 /// <since_tizen> 4 </since_tizen>
268 public int ImagePixelHeight
273 int ret = Interop.Mtp.ObjectInformation.GetImagePixHeight(_deviceHandle, _objectHandle, out value);
274 if (ret != (int)MtpError.None)
276 Log.Error(Globals.LogTag, "Failed to get image pixel height, Error - " + (MtpError)ret);
283 /// Gets the thumbnail size of the object information.
285 /// <value>Size of thumbnail.</value>
286 /// <since_tizen> 4 </since_tizen>
287 public int ThumbnailSize
292 int ret = Interop.Mtp.ObjectInformation.GetThumbnailSize(_deviceHandle, _objectHandle, out value);
293 if (ret != (int)MtpError.None)
295 Log.Error(Globals.LogTag, "Failed to get thumbnail size, Error - " + (MtpError)ret);
302 /// Gets the thumbnail file type of the object information.
304 /// <value>File type of thumbnail.</value>
305 /// <since_tizen> 4 </since_tizen>
306 public int ThumbnailFileType
311 int ret = Interop.Mtp.ObjectInformation.GetThumbnailFileType(_deviceHandle, _objectHandle, out value);
312 if (ret != (int)MtpError.None)
314 Log.Error(Globals.LogTag, "Failed to get thumbnail file type, Error - " + (MtpError)ret);
321 /// Gets the thumbnail pixel width of the object information.
323 /// <value>Pixel width of thumbnail.</value>
324 /// <since_tizen> 4 </since_tizen>
325 public int ThumbnailPixelWidth
330 int ret = Interop.Mtp.ObjectInformation.GetThumbnailPixWidth(_deviceHandle, _objectHandle, out value);
331 if (ret != (int)MtpError.None)
333 Log.Error(Globals.LogTag, "Failed to get thumbnail pixel width, Error - " + (MtpError)ret);
340 /// Gets the thumbnail pixel height of the object information.
342 /// <value>Pixel height of thumbnail.</value>
343 /// <since_tizen> 4 </since_tizen>
344 public int ThumbnailPixelHeight
349 int ret = Interop.Mtp.ObjectInformation.GetThumbnailPixHeight(_deviceHandle, _objectHandle, out value);
350 if (ret != (int)MtpError.None)
352 Log.Error(Globals.LogTag, "Failed to get thumbnail pixel height, Error - " + (MtpError)ret);
358 internal MtpObject(int deviceHandle, int objectHandle)
360 _deviceHandle = deviceHandle;
361 _objectHandle = objectHandle;
365 /// MtpObject destructor.
375 /// <since_tizen> 4 </since_tizen>
376 public void Dispose()
379 GC.SuppressFinalize(this);
382 private void Dispose(bool disposing)
389 // Free managed objects.
391 //Free unmanaged objects
395 internal int GetHandle()
397 return _objectHandle;