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.Collections.Generic;
19 using System.Runtime.InteropServices;
20 using System.Threading.Tasks;
22 namespace Tizen.Network.Mtp
24 static internal class Globals
26 internal const string LogTag = "Tizen.Network.Mtp";
29 internal partial class MtpManagerImpl : IDisposable
31 private static readonly MtpManagerImpl _instance = new MtpManagerImpl();
32 private List<MtpDevice> _deviceList = new List<MtpDevice>();
33 private bool disposed = false;
35 internal static MtpManagerImpl Instance
43 private MtpManagerImpl()
56 GC.SuppressFinalize(this);
59 private void Dispose(bool disposing)
66 // Free managed objects.
68 //Free unmanaged objects
73 private void Initialize()
75 int ret = Interop.Mtp.Initialize();
76 if (ret != (int)MtpError.None)
78 Log.Error(Globals.LogTag, "Failed to Initialize Mtp, Error - " + (MtpError)ret);
79 MtpErrorFactory.ThrowMtpException(ret);
83 private void Deinitialize()
85 int ret = Interop.Mtp.Deinitialize();
86 if (ret != (int)MtpError.None)
88 Log.Error(Globals.LogTag, "Failed to Deinitialize Mtp, Error - " + (MtpError)ret);
92 internal IEnumerable<MtpDevice> GetDevices()
97 int ret = Interop.Mtp.GetDevices(out devicePtr, out count);
98 if (ret != (int)MtpError.None)
100 Log.Error(Globals.LogTag, "Failed to get device list, Error - " + (MtpError)ret);
101 MtpErrorFactory.ThrowMtpException(ret);
104 for (int i = 0; i < count; i++)
106 int deviceID = Marshal.ReadInt32(devicePtr);
108 MtpDevice deviceItem = new MtpDevice(deviceID);
109 _deviceList.Add(deviceItem);
110 devicePtr += sizeof(int);