fixed to register multiple same device & remove device from list when unplugging usb 47/11347/2
authoryoonki.park <yoonki.park@samsung.com>
Thu, 24 Oct 2013 18:41:43 +0000 (03:41 +0900)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Thu, 24 Oct 2013 19:01:26 +0000 (12:01 -0700)
Change-Id: Ic57837abcfca627d40621e74660c19e385df5bd5
Signed-off-by: yoonki.park <yoonki.park@samsung.com>
src/sdb_usb.h
src/usb_darwin.c
src/usb_linux.c
src/usb_windows.c

index 9d55a093425cf9feae08893fd024da4dbe579846..533bcecfd8d05c0815ab4e9d990d1e63cb9a7589 100755 (executable)
@@ -37,4 +37,5 @@ void    kick_disconnected_devices();
  */
 #define MAX_READ_WRITE  (16 * 1024)
 
+#define MAX_SERIAL_NAME  128
 #endif  // __USB_H
index 7e9024d9f8835a0be40e54486961b4bcd15d9476..03c16e0c92480640f622e9e0c8a04b13ac5efe5f 100755 (executable)
@@ -40,7 +40,6 @@
 #include "linkedlist.h"
 #include "transport.h"
 
-#define MAX_C_STRLEN            128
 #define kUSBLanguageEnglish     0x409
 
 static IONotificationPortRef gNotifyPort;
@@ -125,7 +124,7 @@ kern_return_t getUSBSerial(IOUSBDeviceInterface182 **dev, UInt8 string_id, char
                         ((result_length - 2) >> 1));
 
                 /* Copy the character contents to a local C string */
-                CFStringGetCString(result, spotSerial, MAX_C_STRLEN, kCFStringEncodingASCII);
+                CFStringGetCString(result, spotSerial, MAX_SERIAL_NAME, kCFStringEncodingASCII);
             }
         }
     }
index 4f72d8a15978a04787f9dc0de78fb8a08befa990..545a53599803ba0c19291ca490ad99e464aa890f 100644 (file)
@@ -33,7 +33,7 @@
 #include "transport.h"
 
 #define   TRACE_TAG  TRACE_USB
-
+#define   URB_TRANSFER_TIMEOUT   3000
 SDB_MUTEX_DEFINE( usb_lock);
 
 LIST_NODE* usb_list = NULL;
@@ -168,7 +168,7 @@ int register_device(const char* node, const char* serial) {
                     usb->end_point[0] = endpoint_in;
                     usb->end_point[1] = endpoint_out;
 
-                    char usb_serial[256] = { 0, };
+                    char usb_serial[MAX_SERIAL_NAME] = { 0, };
 
                     if (serial != NULL) {
                         s_strncpy(usb_serial, serial, sizeof(usb_serial));
@@ -387,9 +387,14 @@ static int usb_urb_transfer(usb_handle *h, int ep, char *bytes, int size,
 
         restart: waiting = 1;
         context = NULL;
-        while (!urb.usercontext
-                && ((ret = ioctl(h->node_fd, USBDEVFS_REAPURBNDELAY, &context))
-                        == -1) && waiting) {
+        for (;;) {
+            ret = ioctl(h->node_fd, USBDEVFS_REAPURBNDELAY, &context);
+            if (!urb.usercontext && (ret == -1) && waiting) {
+                continue;
+            } else {
+                break;
+            }
+
             tv.tv_sec = 0;
             tv.tv_usec = 1000; // 1 msec
 
@@ -401,8 +406,9 @@ static int usb_urb_transfer(usb_handle *h, int ep, char *bytes, int size,
 
                 if ((tv_now.tv_sec > tv_cur.tv_sec)
                         || ((tv_now.tv_sec == tv_cur.tv_sec)
-                                && (tv_now.tv_usec >= tv_ref.tv_usec)))
+                                && (tv_now.tv_usec >= tv_ref.tv_usec))) {
                     waiting = 0;
+                }
             }
         }
 
@@ -458,7 +464,7 @@ int sdb_usb_write(usb_handle *h, const void *_data, int len) {
     while (len > 0) {
         int xfer = (len > MAX_READ_WRITE) ? MAX_READ_WRITE : len;
 
-        n = usb_urb_transfer(h, h->end_point[1], data, xfer, 0);
+        n = usb_urb_transfer(h, h->end_point[1], data, xfer, URB_TRANSFER_TIMEOUT);
         if (n != xfer) {
             D("fail to usb write: n = %d, errno = %d (%s)\n", n, errno, strerror(errno));
             return -1;
@@ -482,7 +488,7 @@ int sdb_usb_read(usb_handle *h, void *_data, int len) {
     while (len > 0) {
         int xfer = (len > MAX_READ_WRITE) ? MAX_READ_WRITE : len;
 
-        n = usb_urb_transfer(h, h->end_point[0], data, xfer, 0);
+        n = usb_urb_transfer(h, h->end_point[0], data, xfer, URB_TRANSFER_TIMEOUT);
         if (n != xfer) {
             if ((errno == ETIMEDOUT)) {
                 D("usb bulk read timeout\n");
index aed769eaa40517a9583804f6438d1614c0ac6f40..87f09133929016872ca2dbf456485d8eeab4d014 100644 (file)
@@ -375,7 +375,7 @@ int usb_find_devices(GUID deviceClassID) {
         if (!is_device_registered(devicePath)) {
             struct usb_handle *hnd = usb_open(devicePath);
             if (hnd != NULL) {
-                char serial[256];
+                char serial[MAX_SERIAL_NAME]={0,};
                 if (get_serial_number(hnd, serial, sizeof(serial)) > 0) {
                     LOG_DEBUG("register usb for: %s\n", serial);
                     if (register_device(hnd)) {