Commit f64e0f6e authored by Hanspeter Portner's avatar Hanspeter Portner

Squashed 'osc.lv2/' changes from 8eee956..ef9caeb

ef9caeb redesign reader pattern matching infrastructure.

git-subtree-dir: osc.lv2
git-subtree-split: ef9caebc0068a5fc100dc6d33a9db1d827579ff9
parent 66e8ef31
......@@ -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
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment