summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKrzysztof Opasiak <k.opasiak@samsung.com>2015-12-22 22:42:12 +0100
committerKrzysztof Opasiak <k.opasiak@samsung.com>2015-12-23 00:49:03 +0100
commit38fe104315a6f28ff957cc842ee4a912527ecf6f (patch)
treee0737fcfef708225635de95d5f31f150daf9c5b8 /src
parente722c6395f72c1f33ceeafdbc3cae7b769ca98e5 (diff)
downloadlibusbg-38fe104315a6f28ff957cc842ee4a912527ecf6f.tar.gz
libusbg-38fe104315a6f28ff957cc842ee4a912527ecf6f.tar.bz2
libusbg-38fe104315a6f28ff957cc842ee4a912527ecf6f.zip
libusbgx: phonet: Add implementation of function specific API
Implement all function-specific functions from header file Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Diffstat (limited to 'src')
-rw-r--r--src/function/phonet.c50
1 files changed, 48 insertions, 2 deletions
diff --git a/src/function/phonet.c b/src/function/phonet.c
index 3858343..6e9cdb4 100644
--- a/src/function/phonet.c
+++ b/src/function/phonet.c
@@ -12,6 +12,7 @@
#include "usbg/usbg.h"
#include "usbg/usbg_internal.h"
+#include "usbg/function/phonet.h"
#include <malloc.h>
#ifdef HAS_LIBCONFIG
@@ -48,8 +49,8 @@ static int phonet_get_attrs(struct usbg_function *f,
{
int ret;
- ret = usbg_read_string_alloc(f->path, f->name, "ifname",
- &(f_attrs->attrs.phonet.ifname));
+ ret = usbg_f_phonet_get_ifname(usbg_to_phonet_function(f),
+ (char **)&(f_attrs->attrs.phonet.ifname));
if (ret != USBG_SUCCESS)
goto out;
@@ -87,3 +88,48 @@ struct usbg_function_type usbg_f_type_phonet = {
.import = phonet_libconfig_import,
.export = phonet_libconfig_export,
};
+
+/* API implementation */
+
+usbg_f_phonet *usbg_to_phonet_function(usbg_function *f)
+{
+ return f->ops == &usbg_f_type_phonet ?
+ container_of(f, struct usbg_f_phonet, func) : NULL;
+}
+
+usbg_function *usbg_from_phonet_function(usbg_f_phonet *pf)
+{
+ return &pf->func;
+}
+
+int usbg_f_phonet_get_ifname(usbg_f_phonet *pf, char **ifname)
+{
+ struct usbg_function *f = &pf->func;
+
+ if (!pf || !ifname)
+ return USBG_ERROR_INVALID_PARAM;
+
+ return usbg_read_string_alloc(f->path, f->name, "ifname", ifname);
+}
+
+int usbg_f_phonet_get_ifname_s(usbg_f_phonet *pf, char *buf, int len)
+{
+ struct usbg_function *f = &pf->func;
+ int ret;
+
+ if (!pf || !buf)
+ return USBG_ERROR_INVALID_PARAM;
+
+ /*
+ * TODO:
+ * Rework usbg_common to make this function consistent with doc.
+ * This below is only an ugly hack
+ */
+ ret = usbg_read_string_limited(f->path, f->name, "ifname", buf, len);
+ if (ret)
+ goto out;
+
+ ret = strlen(buf);
+out:
+ return ret;
+}