aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2019-06-14 17:00:24 +0200
committerHanspeter Portner <dev@open-music-kontrollers.ch>2019-06-14 17:00:24 +0200
commitef9caebc0068a5fc100dc6d33a9db1d827579ff9 (patch)
tree4e00808d4035a527f2a5a4e848098934238691f4
parent8eee956efee8fdaa88b07fcdb92dfc51c8a9cd55 (diff)
downloadosc.lv2-ef9caebc0068a5fc100dc6d33a9db1d827579ff9.tar.xz
redesign reader pattern matching infrastructure.
-rw-r--r--VERSION2
-rw-r--r--osc.lv2/reader.h22
-rw-r--r--test/osc_test.c68
3 files changed, 64 insertions, 28 deletions
diff --git a/VERSION b/VERSION
index 56ebc9e..39e1a8e 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.1.133
+0.1.135
diff --git a/osc.lv2/reader.h b/osc.lv2/reader.h
index b2dd827..7a8456b 100644
--- a/osc.lv2/reader.h
+++ b/osc.lv2/reader.h
@@ -35,14 +35,13 @@ typedef struct _LV2_OSC_Tree LV2_OSC_Tree;
typedef struct _LV2_OSC_Reader LV2_OSC_Reader;
typedef struct _LV2_OSC_Item LV2_OSC_Item;
typedef struct _LV2_OSC_Arg LV2_OSC_Arg;
-typedef void (*LV2_OSC_Branch)(const char *path, LV2_OSC_Reader *reader,
- LV2_OSC_Arg *arg, void *data);
+typedef void (*LV2_OSC_Branch)(LV2_OSC_Reader *reader, LV2_OSC_Arg *arg,
+ const LV2_OSC_Tree *tree, void *data);
struct _LV2_OSC_Tree {
const char *name;
const LV2_OSC_Tree *trees;
LV2_OSC_Branch branch;
- void *data;
};
struct _LV2_OSC_Reader {
@@ -578,7 +577,7 @@ lv2_osc_reader_is_message(LV2_OSC_Reader *reader)
static inline void
_lv2_osc_trees_internal(LV2_OSC_Reader *reader, const char *path, const char *from,
- LV2_OSC_Arg *arg, const LV2_OSC_Tree *trees)
+ LV2_OSC_Arg *arg, const LV2_OSC_Tree *trees, void *data)
{
const char *ptr = strchr(from, '/');
@@ -592,27 +591,32 @@ _lv2_osc_trees_internal(LV2_OSC_Reader *reader, const char *path, const char *fr
{
if(tree->trees && ptr)
{
- from = &ptr[1];
+ if(tree->branch)
+ {
+ LV2_OSC_Reader reader_clone = *reader;
+ tree->branch(&reader_clone, arg, tree, data);
+ }
- _lv2_osc_trees_internal(reader, path, from, arg, tree->trees);
+ _lv2_osc_trees_internal(reader, path, &ptr[1], arg, tree->trees, data);
}
else if(tree->branch && !ptr)
{
LV2_OSC_Reader reader_clone = *reader;
- tree->branch(path, &reader_clone, arg, tree->data);
+ tree->branch(&reader_clone, arg, tree, data);
}
}
}
}
static inline void
-lv2_osc_reader_match(LV2_OSC_Reader *reader, size_t len, const LV2_OSC_Tree *trees)
+lv2_osc_reader_match(LV2_OSC_Reader *reader, size_t len,
+ const LV2_OSC_Tree *trees, void *data)
{
LV2_OSC_Arg *arg = OSC_READER_MESSAGE_BEGIN(reader, len);
const char *path = arg->path;
const char *from = &path[1];
- _lv2_osc_trees_internal(reader, path, from, arg, trees);
+ _lv2_osc_trees_internal(reader, path, from, arg, trees, data);
}
#ifdef __cplusplus
diff --git a/test/osc_test.c b/test/osc_test.c
index 5d5bd74..2c6a710 100644
--- a/test/osc_test.c
+++ b/test/osc_test.c
@@ -942,6 +942,11 @@ _one(const char *path, unsigned *flag)
{
*flag += 1;
+ if(!path)
+ {
+ return;
+ }
+
assert(!strcmp(path, "/sub/one")
|| !strcmp(path, "/*/one")
|| !strcmp(path, "/s*/one")
@@ -964,6 +969,11 @@ _two(const char *path, unsigned *flag)
{
*flag += 1;
+ if(!path)
+ {
+ return;
+ }
+
assert(!strcmp(path, "/sub/two")
|| !strcmp(path, "/sub/*")
|| !strcmp(path, "/sub/{one,two}"));
@@ -974,6 +984,11 @@ _foo(const char *path, unsigned *flag)
{
*flag += 1;
+ if(!path)
+ {
+ return;
+ }
+
assert(!strcmp(path, "/foo")
|| !strcmp(path, "/{foo,bar}"));
}
@@ -983,6 +998,11 @@ _bar(const char *path, unsigned *flag)
{
*flag += 1;
+ if(!path)
+ {
+ return;
+ }
+
assert(!strcmp(path, "/bar")
|| !strcmp(path, "/{foo,bar}"));
}
@@ -1029,44 +1049,56 @@ static LV2_OSC_Hook hook_root [] = {
{ .name = NULL }
};
+static LV2_OSC_Tree tree_sub [4];
+
static void
-_branch_one( const char *path, LV2_OSC_Reader *reader __attribute__((unused)),
- LV2_OSC_Arg *arg __attribute__((unused)), void *data)
+_branch_one(LV2_OSC_Reader *reader __attribute__((unused)),
+ LV2_OSC_Arg *arg __attribute__((unused)),
+ const LV2_OSC_Tree *tree __attribute__((unused)),
+ void *data __attribute__((unused)))
{
- _one(path, data);
+ _one(NULL, &foo_sub_one);
}
static void
-_branch_two( const char *path, LV2_OSC_Reader *reader __attribute__((unused)),
- LV2_OSC_Arg *arg __attribute__((unused)), void *data)
+_branch_two(LV2_OSC_Reader *reader __attribute__((unused)),
+ LV2_OSC_Arg *arg __attribute__((unused)),
+ const LV2_OSC_Tree *tree __attribute__((unused)),
+ void *data __attribute__((unused)))
{
- _two(path, data);
+ const size_t idx = tree - &tree_sub[1];
+
+ _two(NULL, &foo_sub_two[idx]);
}
static void
-_branch_foo( const char *path, LV2_OSC_Reader *reader __attribute__((unused)),
- LV2_OSC_Arg *arg __attribute__((unused)), void *data)
+_branch_foo(LV2_OSC_Reader *reader __attribute__((unused)),
+ LV2_OSC_Arg *arg __attribute__((unused)),
+ const LV2_OSC_Tree *tree __attribute__((unused)),
+ void *data __attribute__((unused)))
{
- _foo(path, data);
+ _foo(NULL, &foo);
}
static void
-_branch_bar( const char *path, LV2_OSC_Reader *reader __attribute__((unused)),
- LV2_OSC_Arg *arg __attribute__((unused)), void *data)
+_branch_bar(LV2_OSC_Reader *reader __attribute__((unused)),
+ LV2_OSC_Arg *arg __attribute__((unused)),
+ const LV2_OSC_Tree *tree __attribute__((unused)),
+ void *data __attribute__((unused)))
{
- _bar(path, data);
+ _bar(NULL, &bar);
}
static LV2_OSC_Tree tree_sub [] = {
- { .name = "one", .branch = _branch_one, .data = &foo_sub_one },
- { .name = "two", .branch = _branch_two, .data = &foo_sub_two[0] },
- { .name = "two", .branch = _branch_two, .data = &foo_sub_two[1] },
+ { .name = "one", .branch = _branch_one },
+ { .name = "two", .branch = _branch_two },
+ { .name = "two", .branch = _branch_two },
{ .name = NULL }
};
static LV2_OSC_Tree tree_root [] = {
- { .name = "foo", .branch = _branch_foo, .data = &foo },
- { .name = "bar", .branch = _branch_bar, .data = &bar },
+ { .name = "foo", .branch = _branch_foo },
+ { .name = "bar", .branch = _branch_bar },
{ .name = "sub", .trees = tree_sub },
{ .name = NULL }
};
@@ -1103,7 +1135,7 @@ _run_test_hooks_internal(const char *path)
assert(len);
lv2_osc_reader_initialize(&reader, buf, len);
- lv2_osc_reader_match(&reader, len, tree_root);
+ lv2_osc_reader_match(&reader, len, tree_root, NULL);
}
return true;