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 public class UsbEndpoint
26 internal readonly Interop.UsbEndpointHandle _handle;
27 protected readonly UsbInterface _parent;
29 internal UsbEndpoint(UsbInterface parent, Interop.UsbEndpointHandle handle)
36 /// Gets number of this endpoint.
43 return Interop.NativeGet<int>(_handle.GetNumber);
48 /// Gets direction of this endpoint.
50 public EndpointDirection Direction
55 return (EndpointDirection)Interop.NativeGet<Interop.EndpointDirection>(_handle.GetDirection);
60 /// Gets max packet size of given endpoint.
62 public int MaxPacketSize
67 return Interop.NativeGet<int>(_handle.GetMaxPacketSize);
71 internal void ThrowIfDisposed()
73 if (_handle == null) throw new InvalidOperationException("Incompatible endpoint handle");
74 _parent?.ThrowIfDisposed();
77 protected int TransferImpl(byte[] buffer, int length, uint timeout)
81 _handle.Transfer(buffer, length, out transferred, timeout).ThrowIfFailed("Transfer failed");
85 internal static UsbEndpoint EndpointFactory(UsbInterface parent, Interop.UsbEndpointHandle handle)
87 Interop.TransferType transferType;
88 handle.GetTransferType(out transferType).ThrowIfFailed("Failed to get transfer type from endpoint");
91 case Interop.TransferType.Bulk: return new UsbBulkEndpoint(parent, handle);
92 case Interop.TransferType.Interrupt: return new UsbInterruptEndpoint(parent, handle);
93 case Interop.TransferType.Isochronous: return new UsbIsochronousEndpoint(parent, handle);
94 default: return new UsbEndpoint(parent, handle);