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.
19 using System.Collections.Generic;
21 namespace Tizen.System.Usb
24 /// Class to manage USB Configuration.
26 /// <since_tizen> 4 </since_tizen>
27 public class UsbConfiguration : IDisposable
29 internal readonly Interop.UsbConfigHandle _handle;
30 private readonly UsbDevice _parent;
31 private Dictionary<int, UsbInterface> _interfaces;
33 internal UsbConfiguration(UsbDevice parent, Interop.UsbConfigHandle handle)
40 /// Checks if device is self-powered in given configuration.
42 /// <since_tizen> 4 </since_tizen>
43 public bool IsSelfPowered
48 return Interop.NativeGet<bool>(_handle.IsSelfPowered);
53 /// Checks if device in given configuration supports remote wakeup.
55 /// <since_tizen> 4 </since_tizen>
56 public bool SupportRemoteWakeup
61 return Interop.NativeGet<bool>(_handle.SupportRemoteWakeup);
66 /// Gets maximum power required in given configuration, in mA.
68 /// <since_tizen> 4 </since_tizen>
69 public int MaximumPowerRequired
74 return Interop.NativeGet<int>(_handle.GetMaxPower);
79 /// Dictionary mapping interfaces Ids to interface instances for given configuration.
81 /// <since_tizen> 4 </since_tizen>
82 public IReadOnlyDictionary<int, UsbInterface> Interfaces
87 if (_interfaces == null)
89 _interfaces = new Dictionary<int, UsbInterface>();
90 int count = Interop.NativeGet<int>(_handle.GetNumInterfaces);
91 for (int i = 0; i < count; ++i)
94 _handle.GetInterface(i, out handle);
95 UsbInterface usbInterface = new UsbInterface(this, new Interop.UsbInterfaceHandle(handle));
96 _interfaces.Add(usbInterface.Id, usbInterface);
104 /// Configuration string.
106 /// <since_tizen> 4 </since_tizen>
107 public string ConfigurationString
112 return Interop.DescriptorString(_handle.GetConfigStr);
117 /// Set this configuration as active configuration for the device.
119 /// <exception cref="InvalidOperationException">
120 /// Throws exception if device is disconnected or not opened for operation or busy as its interfaces are currently claimed.
122 /// <since_tizen> 4 </since_tizen>
123 public void SetAsActive()
126 _handle.SetAsActive();
129 internal void ThrowIfDisposed()
131 if (disposedValue) throw new ObjectDisposedException("Configuration is already disposed");
132 _parent.ThrowIfDisposed();
135 #region IDisposable Support
136 private bool disposedValue = false;
139 /// Releases all resources used by the ConnectionProfile.
140 /// It should be called after finished using of the object.</summary>
141 /// <since_tizen> 4 </since_tizen>
142 protected virtual void Dispose(bool disposing)
147 disposedValue = true;
152 /// Finalizes an instance of the UsbConfiguration class.
160 /// Releases all resources used by the ConnectionProfile.
161 /// It should be called after finished using of the object.</summary>
162 /// <since_tizen> 4 </since_tizen>
163 public void Dispose()
166 GC.SuppressFinalize(this);