1
0
Fork 0
mirror of https://github.com/linux-usb-gadgets/libusbgx.git synced 2025-07-25 23:25:05 +03:00

libusbgx: Add internal API for defining function types

Adding support for a new function type was quite complicated.
Moreover the main library source fail was growing realy fast.

As a solution introduce internal OO API for defining function.
Thanks to this support for each function may be placed in
a separate file.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
This commit is contained in:
Krzysztof Opasiak 2015-12-23 00:17:25 +01:00
parent 639a329af5
commit 013b9cc990
11 changed files with 1674 additions and 1284 deletions

80
src/function/ffs.c Normal file
View file

@ -0,0 +1,80 @@
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*/
#include "usbg/usbg.h"
#include "usbg/usbg_internal.h"
#ifdef HAS_LIBCONFIG
#include <libconfig.h>
#endif
static int ffs_set_attrs(struct usbg_function *f,
const usbg_function_attrs *f_attrs)
{
const usbg_f_ffs_attrs *ffs_attrs = &(f_attrs->attrs.ffs);
int ret = USBG_ERROR_INVALID_PARAM;
if (f_attrs->header.attrs_type &&
f_attrs->header.attrs_type != USBG_F_ATTRS_FFS)
goto out;
ret = ffs_attrs->dev_name && ffs_attrs->dev_name[0] ?
USBG_ERROR_INVALID_PARAM : USBG_SUCCESS;
out:
return ret;
}
static int ffs_get_attrs(struct usbg_function *f,
usbg_function_attrs *f_attrs)
{
usbg_f_ffs_attrs *ffs_attrs = &(f_attrs->attrs.ffs);
int ret = USBG_SUCCESS;
ffs_attrs->dev_name = strdup(f->instance);
if (!ffs_attrs->dev_name) {
ret = USBG_ERROR_NO_MEM;
goto out;
}
f_attrs->header.attrs_type = USBG_F_ATTRS_FFS;
out:
return ret;
}
static void ffs_cleanup_attrs(struct usbg_function *f,
usbg_function_attrs *f_attrs)
{
free((char*)f_attrs->attrs.ffs.dev_name);
f_attrs->attrs.ffs.dev_name = NULL;
}
static int ffs_libconfig_import(struct usbg_function *f,
config_setting_t *root)
{
return USBG_SUCCESS;
}
static int ffs_libconfig_export(struct usbg_function *f,
config_setting_t *root)
{
return USBG_SUCCESS;
}
struct usbg_function_type usbg_f_type_ffs = {
.name = "ffs",
.set_attrs = ffs_set_attrs,
.get_attrs = ffs_get_attrs,
.cleanup_attrs = ffs_cleanup_attrs,
.import = ffs_libconfig_import,
.export = ffs_libconfig_export,
};