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