summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPawel Szewczyk <p.szewczyk@samsung.com>2015-05-19 12:42:01 +0200
committerKrzysztof Opasiak <k.opasiak@samsung.com>2015-05-21 15:40:01 +0200
commitf1613aab97513188478087e001defbfca6847eca (patch)
tree38dd6f4aade951d1981461223bdf861dfb8a51d7
parentb18c56c4526e910a961bbe110d0172ee5a1327dc (diff)
downloadlibusbg-f1613aab97513188478087e001defbfca6847eca.tar.gz
libusbg-f1613aab97513188478087e001defbfca6847eca.tar.bz2
libusbg-f1613aab97513188478087e001defbfca6847eca.zip
libusbg: schemes: Allow to import midi function
Add support for importing midi function from gadget scheme. Signed-off-by: Pawel Szewczyk <p.szewczyk@samsung.com> Reviewed-by: Krzysztof Opasiak <k.opasiak@samsung.com>
-rw-r--r--src/usbg_schemes_libconfig.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/usbg_schemes_libconfig.c b/src/usbg_schemes_libconfig.c
index bb856dc..0f6a99a 100644
--- a/src/usbg_schemes_libconfig.c
+++ b/src/usbg_schemes_libconfig.c
@@ -1136,6 +1136,61 @@ out:
}
+static int usbg_import_f_midi_attrs(config_setting_t *root, usbg_function *f)
+{
+ config_setting_t *node;
+ int ret = USBG_ERROR_NO_MEM;
+ int tmp;
+ usbg_function_attrs attrs;
+ usbg_f_midi_attrs *midi_attrs = &attrs.attrs.midi;
+
+ attrs.header.attrs_type = USBG_F_ATTRS_MIDI;
+
+#define ADD_F_MIDI_INT_ATTR(attr, defval, minval) \
+ do { \
+ node = config_setting_get_member(root, #attr); \
+ if (node) { \
+ if (!usbg_config_is_int(node)) { \
+ ret = USBG_ERROR_INVALID_TYPE; \
+ goto out; \
+ } \
+ tmp = config_setting_get_int(node); \
+ if (tmp < minval) { \
+ ret = USBG_ERROR_INVALID_VALUE; \
+ goto out; \
+ } \
+ midi_attrs->attr = tmp; \
+ } else { \
+ midi_attrs->attr = defval; \
+ } \
+ } while (0)
+
+ ADD_F_MIDI_INT_ATTR(index, -1, INT_MIN);
+ ADD_F_MIDI_INT_ATTR(in_ports, 1, 0);
+ ADD_F_MIDI_INT_ATTR(out_ports, 1, 0);
+ ADD_F_MIDI_INT_ATTR(buflen, 256, 0);
+ ADD_F_MIDI_INT_ATTR(qlen, 32, 0);
+
+#undef ADD_F_MIDI_INT_ATTR
+
+ node = config_setting_get_member(root, "id");
+ if (node) {
+ if (!usbg_config_is_string(node)) {
+ ret = USBG_ERROR_INVALID_TYPE;
+ goto out;
+ }
+
+ midi_attrs->id = config_setting_get_string(node);
+ } else {
+ midi_attrs->id = "";
+ }
+
+
+ ret = usbg_set_function_attrs(f, &attrs);
+out:
+ return ret;
+}
+
static int usbg_import_function_attrs(config_setting_t *root, usbg_function *f)
{
int ret = USBG_SUCCESS;
@@ -1169,6 +1224,10 @@ static int usbg_import_function_attrs(config_setting_t *root, usbg_function *f)
ret = usbg_import_f_ms_attrs(root, f);
break;
+ case USBG_F_ATTRS_MIDI:
+ ret = usbg_import_f_midi_attrs(root, f);
+ break;
+
default:
ERROR("Unsupported function type\n");
ret = USBG_ERROR_NOT_SUPPORTED;