[USB] Add bulk, interrupt, isochronous Endpoint classes 49/133849/3
authorDinesh Dwivedi <dinesh.d@samsung.com>
Wed, 21 Jun 2017 10:53:23 +0000 (16:23 +0530)
committerDinesh Dwivedi <dinesh.d@samsung.com>
Wed, 21 Jun 2017 10:53:23 +0000 (16:23 +0530)
Change-Id: I72cba1373ee9c6f25868f04b6ee5e5f1065cf202
Signed-off-by: Dinesh Dwivedi <dinesh.d@samsung.com>
Tizen.System.Usb/Usb/SynchronizationType.cs [new file with mode: 0644]
Tizen.System.Usb/Usb/UsageType.cs [new file with mode: 0644]
Tizen.System.Usb/Usb/UsbBulkEndpoint.cs [new file with mode: 0644]
Tizen.System.Usb/Usb/UsbEndpoint.cs
Tizen.System.Usb/Usb/UsbInterruptEndpoint.cs [new file with mode: 0644]
Tizen.System.Usb/Usb/UsbIsochronousEndpoint.cs [new file with mode: 0644]

diff --git a/Tizen.System.Usb/Usb/SynchronizationType.cs b/Tizen.System.Usb/Usb/SynchronizationType.cs
new file mode 100644 (file)
index 0000000..4dcda11
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Tizen.System.Usb
+{
+    /// <summary>
+    /// Enumeration of isochronous endpoint's synchronization type
+    /// </summary>
+    public enum SynchronizationType
+    {
+        /// <summary>
+        /// Asynchronous
+        /// </summary>
+        Asynchronous = Interop.SynchronizationType.Async,
+        /// <summary>
+        /// Adaptive
+        /// </summary>
+        Adaptive = Interop.SynchronizationType.Adaptive,
+        /// <summary>
+        /// Synchronous
+        /// </summary>
+        Synchronous = Interop.SynchronizationType.Sync,
+    }
+}
\ No newline at end of file
diff --git a/Tizen.System.Usb/Usb/UsageType.cs b/Tizen.System.Usb/Usb/UsageType.cs
new file mode 100644 (file)
index 0000000..e45ff55
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Tizen.System.Usb
+{
+    /// <summary>
+    /// Enumeration of an endpoint's usage type
+    /// </summary>
+    public enum UsageType
+    {
+        /// <summary>
+        /// Data endpoint
+        /// </summary>
+        Data = Interop.UsageType.Data,
+        /// <summary>
+        /// Feedback endpoint
+        /// </summary>
+        Feedback = Interop.UsageType.Feedback,
+        /// <summary>
+        /// Implicit feedback Data endpoint
+        /// </summary>
+        Implicit = Interop.UsageType.Implicit,
+    }
+}
\ No newline at end of file
diff --git a/Tizen.System.Usb/Usb/UsbBulkEndpoint.cs b/Tizen.System.Usb/Usb/UsbBulkEndpoint.cs
new file mode 100644 (file)
index 0000000..f2b8a42
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+
+namespace Tizen.System.Usb
+{
+    /// <summary>
+    /// USB Bulk Endpoint class
+    /// </summary>
+    public class UsbBulkEndpoint : UsbEndpoint
+    {
+        internal UsbBulkEndpoint(Interop.UsbEndpointHandle handle) : base(handle)
+        {
+        }
+
+        /// <summary>
+        /// Performs a USB transfer on given endpoint. Direction of transfer is determined by the endpoint
+        /// </summary>
+        /// <param name="buffer">Suitably-sized data buffer for either input or output (depending on endpoint)</param>
+        /// <param name="length">
+        /// For writes, the number of bytes from data to be sent, for reads the maximum number of bytes to receive
+        /// into the data buffer
+        /// </param>
+        /// <param name="timeout">
+        /// Timeout (in milliseconds) that this function should wait before giving up due to no response being
+        /// received(for an unlimited timeout 0 value should be used)
+        /// </param>
+        /// <returns>transferred number of bytes actually transferred</returns>
+        /// <exception cref="InvalidOperationException">Throws excetion if device is disconnected or not opened for operation</exception>
+        /// <exception cref="TimeoutException">Throws excetion if transfer timed-out</exception>
+        public int Transfer(byte[] buffer, int length, uint timeout)
+        {
+            return TransferImpl(buffer, length, timeout);
+        }
+    }
+}
index ab366a6..914bf2d 100644 (file)
@@ -69,5 +69,18 @@ namespace Tizen.System.Usb
             _handle.Transfer(buffer, length, out transferred, timeout).ThrowIfFailed("Transfer failed");
             return transferred;
         }
+
+        internal static UsbEndpoint EndpointFactory(Interop.UsbEndpointHandle handle)
+        {
+            Interop.TransferType transferType;
+            handle.GetTransferType(out transferType).ThrowIfFailed("Failed to get transfer type from endpoint");
+            switch(transferType)
+            {
+                case Interop.TransferType.Bulk: return new UsbBulkEndpoint(handle);
+                case Interop.TransferType.Interrupt: return new UsbInterruptEndpoint(handle);
+                case Interop.TransferType.Isochronous: return new UsbIsochronousEndpoint(handle);
+                default: return new UsbEndpoint(handle);
+            }
+        }
     }
 }
\ No newline at end of file
diff --git a/Tizen.System.Usb/Usb/UsbInterruptEndpoint.cs b/Tizen.System.Usb/Usb/UsbInterruptEndpoint.cs
new file mode 100644 (file)
index 0000000..eb4e5c6
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Tizen.System.Usb
+{
+    /// <summary>
+    /// USB Interrupt Endpoint class
+    /// </summary>
+    public class UsbInterruptEndpoint : UsbEndpoint
+    {
+        internal UsbInterruptEndpoint(Interop.UsbEndpointHandle handle) : base(handle)
+        {
+        }
+
+        /// <summary>
+        /// Gets interval for polling endpoint for data transfers, in frame counts (refer to USB protocol specification)
+        /// </summary>
+        public int PollingInterval
+        {
+            get
+            {
+                return Interop.NativeGet<int>(_handle.GetInterval);
+            }
+        }
+
+        /// <summary>
+        /// Performs a USB transfer on given endpoint. Direction of transfer is determined by the endpoint.
+        /// </summary>
+        /// <param name="buffer">Suitably-sized data buffer for either input or output (depending on endpoint)</param>
+        /// <param name="length">
+        /// For writes, the number of bytes from data to be sent, for reads the maximum number of bytes to receive
+        /// into the data buffer
+        /// </param>
+        /// <param name="timeout">
+        /// Timeout (in milliseconds) that this function should wait before giving up due to no response being
+        /// received(for an unlimited timeout 0 value should be used)
+        /// </param>
+        /// <returns>transferred number of bytes actually transferred</returns>
+        /// <exception cref="InvalidOperationException">Throws excetion if device is disconnected or not opened for operation</exception>
+        /// <exception cref="TimeoutException">Throws excetion if transfer timed-out</exception>
+        public int Transfer(byte[] buffer, int length, uint timeout)
+        {
+            return TransferImpl(buffer, length, timeout);
+        }
+    }
+}
diff --git a/Tizen.System.Usb/Usb/UsbIsochronousEndpoint.cs b/Tizen.System.Usb/Usb/UsbIsochronousEndpoint.cs
new file mode 100644 (file)
index 0000000..680e184
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Tizen.System.Usb
+{
+    /// <summary>
+    /// USB Isochronous Endpoint class
+    /// </summary>
+    public class UsbIsochronousEndpoint : UsbEndpoint
+    {
+        internal UsbIsochronousEndpoint(Interop.UsbEndpointHandle handle) : base(handle)
+        {
+        }
+
+        /// <summary>
+        /// Gets synchronization type of this endpoint
+        /// </summary>
+        public SynchronizationType SynchronizationType
+        {
+            get
+            {
+                return (SynchronizationType)Interop.NativeGet<Interop.SynchronizationType>(_handle.GetSynchType);
+            }
+        }
+
+        /// <summary>
+        /// Gets usage type of this endpoint
+        /// </summary>
+        public UsageType UsageType
+        {
+            get
+            {
+                return (UsageType)Interop.NativeGet<Interop.UsageType>(_handle.GetUsageType);
+            }
+        }
+    }
+}