diff options
author | Hanspeter Portner <dev@open-music-kontrollers.ch> | 2017-03-19 18:58:34 +0100 |
---|---|---|
committer | Hanspeter Portner <dev@open-music-kontrollers.ch> | 2017-03-19 18:58:34 +0100 |
commit | de2d8fe72d62a8192a9c05d715924f308189e5e1 (patch) | |
tree | dae1cc2e85bd50031162bf6dfa650a72a90034fb | |
parent | a9ee41bb3eb9d7a9021c4213c50cd1bed09c32c7 (diff) | |
parent | d52738538423c10c1c5c4056d94daa89cf327625 (diff) | |
download | sherlock.lv2-de2d8fe72d62a8192a9c05d715924f308189e5e1.tar.xz |
Merge commit 'd52738538423c10c1c5c4056d94daa89cf327625'
-rw-r--r-- | props.lv2/props.h | 31 | ||||
-rw-r--r-- | props.lv2/test/props.c | 46 | ||||
-rw-r--r-- | props.lv2/test/props.ttl | 5 |
3 files changed, 43 insertions, 39 deletions
diff --git a/props.lv2/props.h b/props.lv2/props.h index 312e98d..35081eb 100644 --- a/props.lv2/props.h +++ b/props.lv2/props.h @@ -46,6 +46,7 @@ typedef struct _props_def_t props_def_t; typedef struct _props_impl_t props_impl_t; typedef struct _props_work_t props_work_t; typedef struct _props_t props_t; +typedef union _props_magic_t props_magic_t; // function callbacks typedef void (*props_event_cb_t)( @@ -101,7 +102,13 @@ struct _props_impl_t { bool stashing; }; +union _props_magic_t { + uint8_t u64; + uint8_t u8 [8]; +}; + struct _props_work_t { + props_magic_t magic; LV2_URID property; LV2_URID size; LV2_URID type; @@ -212,6 +219,10 @@ props_work_response(props_t *props, uint32_t size, const void *body); * API END *****************************************************************************/ +static const props_magic_t props_magic = { + .u8 = {'p', 'r', 'o', 'p', 's', 'l', 'v', '2'} +}; + static inline void _impl_spin_lock(props_impl_t *impl) { @@ -889,6 +900,7 @@ _props_schedule(const LV2_Worker_Schedule *work_sched, LV2_URID property, props_work_t *job = malloc(sz); if(job) { + job->magic = props_magic; job->property = property; job->type = type; job->size = size; @@ -980,14 +992,25 @@ static inline LV2_Worker_Status props_work(props_t *props, LV2_Worker_Respond_Function respond, LV2_Worker_Respond_Handle worker, uint32_t size, const void *body) { - return respond(worker, size, body); + const props_work_t *job = body; + + if(job && (job->magic.u64 == props_magic.u64) ) + { + const LV2_Worker_Status stat = respond(worker, size, body); + (void)stat; + + return LV2_WORKER_SUCCESS; + } + + return LV2_WORKER_ERR_UNKNOWN; } static inline LV2_Worker_Status props_work_response(props_t *props, uint32_t size, const void *body) { const props_work_t *job = body; - if(job) + + if(job && (job->magic.u64 == props_magic.u64) ) { props_impl_t *impl = _props_impl_search(props, job->property); if(impl) @@ -998,9 +1021,11 @@ props_work_response(props_t *props, uint32_t size, const void *body) if(def->event_cb && (def->event_mask & PROP_EVENT_RESTORE) ) def->event_cb(props->data, NULL, 0, PROP_EVENT_RESTORE, impl); } + + return LV2_WORKER_SUCCESS; } - return LV2_WORKER_SUCCESS; + return LV2_WORKER_ERR_UNKNOWN; } #ifdef __cplusplus diff --git a/props.lv2/test/props.c b/props.lv2/test/props.c index e4b27d8..1883230 100644 --- a/props.lv2/test/props.c +++ b/props.lv2/test/props.c @@ -20,6 +20,7 @@ #include <props.h> #include <lv2/lv2plug.in/ns/ext/log/log.h> +#include <lv2/lv2plug.in/ns/ext/log/logger.h> #define PROPS_PREFIX "http://open-music-kontrollers.ch/lv2/props#" #define PROPS_TEST_URI PROPS_PREFIX"test" @@ -43,12 +44,10 @@ struct _plugstate_t { struct _plughandle_t { LV2_URID_Map *map; LV2_Log_Log *log; + LV2_Log_Logger logger; LV2_Atom_Forge forge; LV2_Atom_Forge_Ref ref; - LV2_URID log_trace; - LV2_URID log_note; - PROPS_T(props, MAX_NPROPS); plugstate_t state; plugstate_t stash; @@ -62,26 +61,6 @@ struct _plughandle_t { LV2_Atom_Sequence *event_out; }; -static int -_log_vprintf(plughandle_t *handle, LV2_URID type, const char *fmt, va_list args) -{ - return handle->log->vprintf(handle->log->handle, type, fmt, args); -} - -// non-rt || rt with LV2_LOG__Trace -static int -_log_printf(plughandle_t *handle, LV2_URID type, const char *fmt, ...) -{ - va_list args; - int ret; - - va_start (args, fmt); - ret = _log_vprintf(handle, type, fmt, args); - va_end(args); - - return ret; -} - static void _intercept(void *data, LV2_Atom_Forge *forge, int64_t frames, props_event_t event, props_impl_t *impl) @@ -92,27 +71,27 @@ _intercept(void *data, LV2_Atom_Forge *forge, int64_t frames, { case PROP_EVENT_GET: { - _log_printf(handle, handle->log_trace, "GET : %s", impl->def->property); + lv2_log_trace(&handle->logger, "GET : %s\n", impl->def->property); break; } case PROP_EVENT_SET: { - _log_printf(handle, handle->log_trace, "SET : %s", impl->def->property); + lv2_log_trace(&handle->logger, "SET : %s\n", impl->def->property); break; } case PROP_EVENT_REGISTER: { - _log_printf(handle, handle->log_trace, "REGISTER: %s", impl->def->property); + lv2_log_note(&handle->logger, "REGISTER: %s\n", impl->def->property); break; } case PROP_EVENT_SAVE: { - _log_printf(handle, handle->log_note, "SAVE : %s", impl->def->property); + lv2_log_note(&handle->logger, "SAVE : %s\n", impl->def->property); break; } case PROP_EVENT_RESTORE: { - _log_printf(handle, handle->log_note, "RESTORE : %s", impl->def->property); + lv2_log_note(&handle->logger, "RESTORE : %s\n", impl->def->property); break; } } @@ -259,20 +238,19 @@ instantiate(const LV2_Descriptor* descriptor, double rate, return NULL; } - handle->log_trace = handle->map->map(handle->map->handle, LV2_LOG__Trace); - handle->log_note = handle->map->map(handle->map->handle, LV2_LOG__Note); - + lv2_log_logger_init(&handle->logger, handle->map, handle->log); lv2_atom_forge_init(&handle->forge, handle->map); + if(!props_init(&handle->props, MAX_NPROPS, descriptor->URI, handle->map, handle)) { - fprintf(stderr, "failed to initialize property structure\n"); + lv2_log_error(&handle->logger, "failed to initialize property structure\n"); free(handle); return NULL; } if(!props_register(&handle->props, defs, MAX_NPROPS, &handle->state, &handle->stash)) { - _log_printf(handle, handle->log_trace, "ERR : registering"); + lv2_log_error(&handle->logger, "ERR : registering\n"); free(handle); return NULL; } @@ -374,7 +352,7 @@ _work_response(LV2_Handle instance, uint32_t size, const void *body) return props_work_response(&handle->props, size, body); } -LV2_Worker_Interface work_iface = { +static const LV2_Worker_Interface work_iface = { .work = _work, .work_response = _work_response, .end_run = NULL diff --git a/props.lv2/test/props.ttl b/props.lv2/test/props.ttl index 3f6b188..68d6b43 100644 --- a/props.lv2/test/props.ttl +++ b/props.lv2/test/props.ttl @@ -24,6 +24,7 @@ @prefix state: <http://lv2plug.in/ns/ext/state#> . @prefix patch: <http://lv2plug.in/ns/ext/patch#> . @prefix log: <http://lv2plug.in/ns/ext/log#> . +@prefix work: <http://lv2plug.in/ns/ext/worker#> . @prefix units: <http://lv2plug.in/ns/extensions/units#> . @prefix xsd: <http://www.w3.org/2001/XMLSchema#> . @@ -106,9 +107,9 @@ props:test doap:name "Props Test" ; doap:license lic:Artistic-2.0 ; lv2:project proj:props ; - lv2:extensionData state:interface ; - lv2:requiredFeature urid:map, log:log, state:loadDefaultState ; + lv2:requiredFeature urid:map, log:log, state:loadDefaultState, work:schedule ; lv2:optionalFeature lv2:isLive, lv2:hardRTCapable, state:threadSafeRestore ; + lv2:extensionData state:interface, work:interface ; lv2:port [ # sink event port |