2 * Copyright (c) 2016 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 Storage informations. It allows applications to handle storage informations.
26 public class MtpStorage : IDisposable
28 private int _deviceHandle = -1;
29 private int _storageHandle = -1;
30 private bool disposed = false;
31 private List<int> _objectHandleList = new List<int>();
32 private List<MtpObject> _objectList = new List<MtpObject>();
33 //private int _objectHandle = 0;
38 public string Description
43 int ret = Interop.Mtp.StorageInformation.GetDescription(_deviceHandle, _storageHandle, out strPtr);
44 if (ret != (int)MtpError.None)
46 Log.Error(Globals.LogTag, "Failed to get description, Error - " + (MtpError)ret);
49 return Marshal.PtrToStringAnsi(strPtr);
56 public UInt64 FreeSpace
61 int ret = Interop.Mtp.StorageInformation.GetFreeSpace(_deviceHandle, _storageHandle, out freeSpace);
62 if (ret != (int)MtpError.None)
64 Log.Error(Globals.LogTag, "Failed to get free space, Error - " + (MtpError)ret);
73 public UInt64 MaxCapacity
78 int ret = Interop.Mtp.StorageInformation.GetMaxCapacity(_deviceHandle, _storageHandle, out maxCapacity);
79 if (ret != (int)MtpError.None)
81 Log.Error(Globals.LogTag, "Failed to get free space, Error - " + (MtpError)ret);
90 public MtpStorageType StorageType
95 int ret = Interop.Mtp.StorageInformation.GetStorageType(_deviceHandle, _storageHandle, out storageType);
96 if (ret != (int)MtpError.None)
98 Log.Error(Globals.LogTag, "Failed to get free space, Error - " + (MtpError)ret);
100 return (MtpStorageType)storageType;
105 /// The volume identifier.
107 public string VolumeIdentifier
112 int ret = Interop.Mtp.StorageInformation.GetVolumeIdentifier(_deviceHandle, _storageHandle, out strPtr);
113 if (ret != (int)MtpError.None)
115 Log.Error(Globals.LogTag, "Failed to get volume identifier, Error - " + (MtpError)ret);
118 return Marshal.PtrToStringAnsi(strPtr);
122 internal MtpStorage(int deviceHandle, int storageHandle)
124 _deviceHandle = deviceHandle;
125 _storageHandle = storageHandle;
133 public void Dispose()
136 GC.SuppressFinalize(this);
139 private void Dispose(bool disposing)
146 // Free managed objects.
147 /* foreach (SmartcardChannel channel in _basicChannelList)
150 _basicChannelList.Remove(channel);
153 foreach (SmartcardChannel channel in _logicalChannelList)
156 _logicalChannelList.Remove(channel);
159 //Free unmanaged objects
163 internal int GetHandle()
165 return _storageHandle;
169 /// Gets the list of storages.
171 /// <returns>List of storage objects.</returns>
172 public IEnumerable<MtpObject> GetObjectHandles(int parentHandle, MtpFileType fileType)
177 int ret = Interop.Mtp.GetObjectHandles(_deviceHandle, _storageHandle, parentHandle, (int)fileType, out objectPtr, out count);
178 if (ret != (int)MtpError.None)
180 Log.Error(Globals.LogTag, "Failed to get object handle lists, Error - " + (MtpError)ret);
181 MtpErrorFactory.ThrowMtpException(ret);
184 for (int i = 0; i < count; i++)
186 int objectID = Marshal.ReadInt32(objectPtr);
188 MtpObject objectItem = new MtpObject(_deviceHandle, objectID);
189 _objectList.Add(objectItem);
190 objectPtr += sizeof(int);