mirror of
https://github.com/linux-usb-gadgets/libusbgx.git
synced 2025-07-23 10:15:06 +03:00
We have two configure options related to libconfig: 1) --disable-gadget-schemes 2) --without-libconfig Option #1 means that libusbgx itself should be compiled without gadget schemes support. Option #2 means that everything what requires libconfig should be turned off. So option #2 is wider than #1 as libconfig us used also in our testing program. To fix this meaning let's use HAS_GADGET_SCHEMES inside library source code to determine if we should use libconfig or not and HAS_LIBCONFIG inside our tests source code. Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
103 lines
2.4 KiB
C
103 lines
2.4 KiB
C
/*
|
|
* 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"
|
|
#include "usbg/function/ffs.h"
|
|
|
|
#include <malloc.h>
|
|
#ifdef HAS_GADGET_SCHEMES
|
|
#include <libconfig.h>
|
|
#endif
|
|
|
|
struct usbg_f_fs {
|
|
struct usbg_function func;
|
|
};
|
|
|
|
GENERIC_ALLOC_INST(ffs, struct usbg_f_fs, func);
|
|
|
|
GENERIC_FREE_INST(ffs, struct usbg_f_fs, func);
|
|
|
|
static int ffs_set_attrs(struct usbg_function *f, void *f_attrs)
|
|
{
|
|
const char *dev_name = *(const char **)f_attrs;
|
|
|
|
return dev_name && dev_name[0] ? USBG_ERROR_INVALID_PARAM
|
|
: USBG_SUCCESS;
|
|
}
|
|
|
|
static int ffs_get_attrs(struct usbg_function *f, void *f_attrs)
|
|
{
|
|
return usbg_f_fs_get_dev_name(usbg_to_fs_function(f), f_attrs);
|
|
}
|
|
|
|
static void ffs_cleanup_attrs(struct usbg_function *f, void *f_attrs)
|
|
{
|
|
free(*(char **)f_attrs);
|
|
}
|
|
|
|
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",
|
|
.alloc_inst = ffs_alloc_inst,
|
|
.free_inst = ffs_free_inst,
|
|
.set_attrs = ffs_set_attrs,
|
|
.get_attrs = ffs_get_attrs,
|
|
.cleanup_attrs = ffs_cleanup_attrs,
|
|
.import = ffs_libconfig_import,
|
|
.export = ffs_libconfig_export,
|
|
};
|
|
|
|
/* API implementation */
|
|
|
|
usbg_f_fs *usbg_to_fs_function(usbg_function *f)
|
|
{
|
|
return f->ops == &usbg_f_type_ffs ?
|
|
container_of(f, struct usbg_f_fs, func) : NULL;
|
|
}
|
|
|
|
usbg_function *usbg_from_fs_function(usbg_f_fs *ff)
|
|
{
|
|
return &ff->func;
|
|
}
|
|
|
|
int usbg_f_fs_get_dev_name(usbg_f_fs *ff, char **dev_name)
|
|
{
|
|
if (!ff || !dev_name)
|
|
return USBG_ERROR_INVALID_PARAM;
|
|
|
|
*dev_name = strdup(ff->func.instance);
|
|
if (!*dev_name)
|
|
return USBG_ERROR_NO_MEM;
|
|
|
|
return 0;
|
|
}
|
|
|
|
int usbg_f_fs_get_dev_name_s(usbg_f_fs *ff, char *buf, int len)
|
|
{
|
|
if (!ff || !buf)
|
|
return USBG_ERROR_INVALID_PARAM;
|
|
|
|
return snprintf(buf, len, "%s", ff->func.instance);
|
|
}
|
|
|