summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKrzysztof Opasiak <k.opasiak@samsung.com>2015-04-14 12:26:42 +0200
committerKrzysztof Opasiak <k.opasiak@samsung.com>2015-04-27 10:14:19 +0200
commitddb5964c07ecd9f14ca4896af47ed5c85a72558c (patch)
tree758d21e50fa64553d7463e3aee4e1cf812294674
parente2cc066bcd6302620d9806b6346523670f4e1ef7 (diff)
downloadlibusbg-ddb5964c07ecd9f14ca4896af47ed5c85a72558c.tar.gz
libusbg-ddb5964c07ecd9f14ca4896af47ed5c85a72558c.tar.bz2
libusbg-ddb5964c07ecd9f14ca4896af47ed5c85a72558c.zip
libusbg: Add rm callback to usbg_function
Some functions requires more complicated rm method which will remove its sub directories. To avoid complexity in usbg_rm_function() just add a callback which is called there. Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com> Reviewed-by: Pawel Szewczyk <p.szewczyk@samsung.com>
-rw-r--r--include/usbg/usbg_internal.h3
-rw-r--r--src/usbg.c14
2 files changed, 17 insertions, 0 deletions
diff --git a/include/usbg/usbg_internal.h b/include/usbg/usbg_internal.h
index 793319c..30098c9 100644
--- a/include/usbg/usbg_internal.h
+++ b/include/usbg/usbg_internal.h
@@ -74,6 +74,8 @@ struct usbg_config
int id;
};
+typedef int (*usbg_rm_function_callback)(usbg_function *, int);
+
struct usbg_function
{
TAILQ_ENTRY(usbg_function) fnode;
@@ -85,6 +87,7 @@ struct usbg_function
/* Only for internal library usage */
char *label;
usbg_function_type type;
+ usbg_rm_function_callback rm_callback;
};
struct usbg_binding
diff --git a/src/usbg.c b/src/usbg.c
index 0b96524..9182acb 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -725,6 +725,13 @@ static usbg_function *usbg_allocate_function(const char *path,
f->parent = parent;
f->type = type;
+ /* only composed funcitons (with subdirs) require this callback */
+ switch (usbg_lookup_function_attrs_type(type)) {
+ default:
+ f->rm_callback = NULL;
+ break;
+ }
+
if (!(f->path)) {
free(f->name);
free(f->path);
@@ -1642,12 +1649,19 @@ int usbg_rm_function(usbg_function *f, int opts)
} /* TAILQ_FOREACH */
}
+ if (f->rm_callback) {
+ ret = f->rm_callback(f, opts);
+ if (ret != USBG_SUCCESS)
+ goto out;
+ }
+
ret = usbg_rm_dir(f->path, f->name);
if (ret == USBG_SUCCESS) {
TAILQ_REMOVE(&(g->functions), f, fnode);
usbg_free_function(f);
}
+out:
return ret;
}