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 public class UsbConfiguration : IDisposable
28 internal readonly Interop.UsbConfigHandle _handle;
29 private readonly UsbDevice _parent;
30 private Dictionary<int, UsbInterface> _interfaces;
32 internal UsbConfiguration(UsbDevice parent, Interop.UsbConfigHandle handle)
39 /// Checks if device is self-powered in given configuration.
41 public bool IsSelfPowered
46 return Interop.NativeGet<bool>(_handle.IsSelfPowered);
51 /// Checks if device in given configuration supports remote wakeup.
53 public bool SupportRemoteWakeup
58 return Interop.NativeGet<bool>(_handle.SupportRemoteWakeup);
63 /// Gets maximum power required in given configuration, in mA.
65 public int MaximumPowerRequired
70 return Interop.NativeGet<int>(_handle.GetMaxPower);
75 /// Dictionary mapping interfaces Ids to interface instances for given configuration.
77 public IReadOnlyDictionary<int, UsbInterface> Interfaces
82 if (_interfaces == null)
84 _interfaces = new Dictionary<int, UsbInterface>();
85 int count = Interop.NativeGet<int>(_handle.GetNumInterfaces);
86 for (int i = 0; i < count; ++i)
88 Interop.UsbInterfaceHandle handle;
89 _handle.GetInterface(i, out handle);
90 UsbInterface usbInterface = new UsbInterface(this, handle);
91 _interfaces.Add(usbInterface.Id, usbInterface);
99 /// Configuration string.
101 public string ConfigurationString
106 return Interop.DescriptorString(_handle.GetConfigStr);
111 /// Set this configuration as active configuration for the device.
113 /// <exception cref="InvalidOperationException">
114 /// Throws exception if device is disconnected or not opened for operation or busy as its interfaces are currently claimed.
116 public void SetAsActive()
119 _handle.SetAsActive();
122 internal void ThrowIfDisposed()
124 if (disposedValue) throw new ObjectDisposedException("Configuration is already disposed");
125 _parent.ThrowIfDisposed();
128 #region IDisposable Support
129 private bool disposedValue = false;
132 /// Releases all resources used by the ConnectionProfile.
133 /// It should be called after finished using of the object.</summary>
134 protected virtual void Dispose(bool disposing)
139 disposedValue = true;
144 /// Finalizes an instance of the UsbConfiguration class.
152 /// Releases all resources used by the ConnectionProfile.
153 /// It should be called after finished using of the object.</summary>
154 public void Dispose()
157 GC.SuppressFinalize(this);