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 namespace Tizen.System.Usb
22 /// USB Endpoint class.
24 /// <since_tizen> 4 </since_tizen>
25 public class UsbEndpoint
27 internal readonly Interop.UsbEndpointHandle _handle;
28 internal readonly UsbInterface _parent;
30 internal UsbEndpoint(UsbInterface parent, Interop.UsbEndpointHandle handle)
37 /// Gets number of this endpoint.
39 /// <since_tizen> 4 </since_tizen>
45 return Interop.NativeGet<int>(_handle.GetNumber);
50 /// Gets direction of this endpoint.
52 /// <since_tizen> 4 </since_tizen>
53 public EndpointDirection Direction
58 return (EndpointDirection)Interop.NativeGet<Interop.EndpointDirection>(_handle.GetDirection);
63 /// Gets max packet size of given endpoint.
65 /// <since_tizen> 4 </since_tizen>
66 public int MaxPacketSize
71 return Interop.NativeGet<int>(_handle.GetMaxPacketSize);
75 internal void ThrowIfDisposed()
77 if (_handle == null) throw new InvalidOperationException("Incompatible endpoint handle");
78 _parent?.ThrowIfDisposed();
81 internal int TransferImpl(byte[] buffer, int length, uint timeout)
85 _handle.Transfer(buffer, length, out transferred, timeout).ThrowIfFailed("Transfer failed");
89 internal static UsbEndpoint EndpointFactory(UsbInterface parent, Interop.UsbEndpointHandle handle)
91 Interop.TransferType transferType;
92 handle.GetTransferType(out transferType).ThrowIfFailed("Failed to get transfer type from endpoint");
95 case Interop.TransferType.Bulk: return new UsbBulkEndpoint(parent, handle);
96 case Interop.TransferType.Interrupt: return new UsbInterruptEndpoint(parent, handle);
97 case Interop.TransferType.Isochronous: return new UsbIsochronousEndpoint(parent, handle);
98 default: return new UsbEndpoint(parent, handle);