libusbgx: Add support for MIDI function
authorDominic Sacré <dominic.sacre@gmx.de>
Mon, 11 May 2015 12:45:10 +0000 (14:45 +0200)
committerKrzysztof Opasiak <k.opasiak@samsung.com>
Tue, 22 Dec 2015 20:45:36 +0000 (21:45 +0100)
Signed-off-by: Dominic Sacré <dominic.sacre@gmx.de>
Reviewed-by: Pawel Szewczyk <p.szewczyk@samsung.com>
Fix usbg_parse_function_midi_attrs() to store qlen value
in qlen member of attrs struct instead of in buflen

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
include/usbg/usbg.h
src/usbg.c

index 3f920f7..dc16c41 100644 (file)
@@ -182,6 +182,7 @@ typedef enum
        F_PHONET,
        F_FFS,
        F_MASS_STORAGE,
+       F_MIDI,
        USBG_FUNCTION_TYPE_MAX,
 } usbg_function_type;
 
@@ -246,6 +247,19 @@ typedef struct {
 } usbg_f_ms_attrs;
 
 /**
+ * @typedef usbg_f_midi_attrs
+ * @brief Attributes for the MIDI function
+ */
+typedef struct {
+       int index;
+       const char *id;
+       unsigned int in_ports;
+       unsigned int out_ports;
+       unsigned int buflen;
+       unsigned int qlen;
+} usbg_f_midi_attrs;
+
+/**
  * @typedef attrs
  * @brief Attributes for a given function type
  */
@@ -255,6 +269,7 @@ typedef union {
        usbg_f_phonet_attrs phonet;
        usbg_f_ffs_attrs ffs;
        usbg_f_ms_attrs ms;
+       usbg_f_midi_attrs midi;
 } usbg_f_attrs;
 
 typedef enum {
@@ -263,6 +278,7 @@ typedef enum {
        USBG_F_ATTRS_PHONET,
        USBG_F_ATTRS_FFS,
        USBG_F_ATTRS_MS,
+       USBG_F_ATTRS_MIDI,
 } usbg_f_attrs_type;
 
 typedef struct {
index 3a2700e..61027e3 100644 (file)
@@ -51,6 +51,7 @@ const char *function_names[] =
        "phonet",
        "ffs",
        "mass_storage",
+       "midi",
 };
 
 ARRAY_SIZE_SENTINEL(function_names, USBG_FUNCTION_TYPE_MAX);
@@ -252,6 +253,9 @@ int usbg_lookup_function_attrs_type(int f_type)
        case F_MASS_STORAGE:
                ret = USBG_F_ATTRS_MS;
                break;
+       case F_MIDI:
+               ret = USBG_F_ATTRS_MIDI;
+               break;
        default:
                ret = USBG_ERROR_NOT_SUPPORTED;
        }
@@ -1051,6 +1055,39 @@ out:
        return ret;
 }
 
+static int usbg_parse_function_midi_attrs(usbg_function *f,
+               usbg_f_midi_attrs *attrs)
+{
+       int ret;
+
+       ret = usbg_read_dec(f->path, f->name, "index", &(attrs->index));
+       if (ret != USBG_SUCCESS)
+               goto out;
+
+       ret = usbg_read_string_alloc(f->path, f->name, "id", &(attrs->id));
+       if (ret != USBG_SUCCESS)
+               goto out;
+
+       ret = usbg_read_dec(f->path, f->name, "in_ports", (int*)&(attrs->in_ports));
+       if (ret != USBG_SUCCESS)
+               goto out;
+
+       ret = usbg_read_dec(f->path, f->name, "out_ports", (int*)&(attrs->out_ports));
+       if (ret != USBG_SUCCESS)
+               goto out;
+
+       ret = usbg_read_dec(f->path, f->name, "buflen", (int*)&(attrs->buflen));
+       if (ret != USBG_SUCCESS)
+               goto out;
+
+       ret = usbg_read_dec(f->path, f->name, "qlen", (int*)&(attrs->qlen));
+       if (ret != USBG_SUCCESS)
+               goto out;
+
+out:
+       return ret;
+}
+
 static int usbg_parse_function_attrs(usbg_function *f,
                usbg_function_attrs *f_attrs)
 {
@@ -1099,6 +1136,11 @@ static int usbg_parse_function_attrs(usbg_function *f,
                ret = usbg_parse_function_ms_attrs(f, &(f_attrs->attrs.ms));
                break;
 
+       case USBG_F_ATTRS_MIDI:
+               f_attrs->header.attrs_type = USBG_F_ATTRS_MIDI;
+               ret = usbg_parse_function_midi_attrs(f, &(f_attrs->attrs.midi));
+               break;
+
        default:
                ERROR("Unsupported function type\n");
                ret = USBG_ERROR_NOT_SUPPORTED;
@@ -2922,6 +2964,11 @@ void usbg_cleanup_function_attrs(usbg_function_attrs *f_attrs)
                break;
        }
 
+       case USBG_F_ATTRS_MIDI:
+               free((char*)attrs->midi.id);
+               attrs->midi.id = NULL;
+               break;
+
        default:
                ERROR("Unsupported attrs type\n");
                break;
@@ -3123,6 +3170,37 @@ out:
        return ret;
 }
 
+int usbg_set_function_midi_attrs(usbg_function *f,
+                                const usbg_f_midi_attrs *attrs)
+{
+       int ret;
+
+       ret = usbg_write_dec(f->path, f->name, "index", attrs->index);
+       if (ret != USBG_SUCCESS)
+               goto out;
+
+       ret = usbg_write_string(f->path, f->name, "id", attrs->id);
+       if (ret != USBG_SUCCESS)
+               goto out;
+
+       ret = usbg_write_dec(f->path, f->name, "in_ports", attrs->in_ports);
+       if (ret != USBG_SUCCESS)
+               goto out;
+
+       ret = usbg_write_dec(f->path, f->name, "out_ports", attrs->out_ports);
+       if (ret != USBG_SUCCESS)
+               goto out;
+
+       ret = usbg_write_dec(f->path, f->name, "buflen", attrs->buflen);
+       if (ret != USBG_SUCCESS)
+               goto out;
+
+       ret = usbg_write_dec(f->path, f->name, "qlen", attrs->qlen);
+
+out:
+       return ret;
+}
+
 int usbg_set_function_attrs(usbg_function *f,
                            const usbg_function_attrs *f_attrs)
 {
@@ -3170,6 +3248,10 @@ int usbg_set_function_attrs(usbg_function *f,
                ret = usbg_set_function_ms_attrs(f, &f_attrs->attrs.ms);
                break;
 
+       case USBG_F_ATTRS_MIDI:
+               ret = usbg_set_function_midi_attrs(f, &f_attrs->attrs.midi);
+               break;
+
        default:
                ERROR("Unsupported function type\n");
                ret = USBG_ERROR_NOT_SUPPORTED;