utils.h
Go to the documentation of this file.
/* Simple Plugin API
*
* Copyright © 2019 Wim Taymans
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef SPA_DEVICE_UTILS_H
#define SPA_DEVICE_UTILS_H
#ifdef __cplusplus
extern "C" {
#endif
#include <spa/pod/builder.h>
#include <spa/monitor/device.h>
struct spa_result_device_params_data {
struct spa_pod_builder *builder;
struct spa_result_device_params data;
};
static inline void spa_result_func_device_params(void *data, int seq, int res,
uint32_t type, const void *result)
{
struct spa_result_device_params_data *d =
(struct spa_result_device_params_data *)data;
const struct spa_result_device_params *r =
(const struct spa_result_device_params *)result;
uint32_t offset = d->builder->state.offset;
if (spa_pod_builder_raw_padded(d->builder, r->param, SPA_POD_SIZE(r->param)) < 0)
return;
d->data.next = r->next;
d->data.param = spa_pod_builder_deref(d->builder, offset);
}
static inline int spa_device_enum_params_sync(struct spa_device *device,
uint32_t id, uint32_t *index,
const struct spa_pod *filter,
struct spa_pod **param,
struct spa_pod_builder *builder)
{
struct spa_result_device_params_data data = { builder, };
struct spa_hook listener = {{0}};
static const struct spa_device_events device_events = {
.version = SPA_VERSION_DEVICE_EVENTS,
.info = NULL,
.result = spa_result_func_device_params,
};
int res;
spa_device_add_listener(device, &listener, &device_events, &data);
res = spa_device_enum_params(device, 0, id, *index, 1, filter);
spa_hook_remove(&listener);
if (data.data.param == NULL) {
if (res > 0)
res = 0;
} else {
*index = data.data.next;
*param = data.data.param;
res = 1;
}
return res;
}
#define spa_device_emit(hooks,method,version,...) \
spa_hook_list_call_simple(hooks, struct spa_device_events, \
method, version, ##__VA_ARGS__)
#define spa_device_emit_info(hooks,i) spa_device_emit(hooks,info, 0, i)
#define spa_device_emit_result(hooks,s,r,t,res) spa_device_emit(hooks,result, 0, s, r, t, res)
#define spa_device_emit_event(hooks,e) spa_device_emit(hooks,event, 0, e)
#define spa_device_emit_object_info(hooks,id,i) spa_device_emit(hooks,object_info, 0, id, i)
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* SPA_DEVICE_UTILS_H */
builder.h
spa/pod/builder.h
spa_device_enum_params
#define spa_device_enum_params(d,...)
Enumerate the parameters of a device.
Definition: device.h:288
spa_device_enum_params_sync
static int spa_device_enum_params_sync(struct spa_device *device, uint32_t id, uint32_t *index, const struct spa_pod *filter, struct spa_pod **param, struct spa_pod_builder *builder)
Definition: utils.h:64
SPA_VERSION_DEVICE_EVENTS
#define SPA_VERSION_DEVICE_EVENTS
version of the structure
Definition: device.h:142
spa_device_add_listener
#define spa_device_add_listener(d,...)
Set events to receive asynchronous notifications from the device.
Definition: device.h:282
spa_result_func_device_params
static void spa_result_func_device_params(void *data, int seq, int res, uint32_t type, const void *result)
Definition: utils.h:50
spa_hook_remove
static void spa_hook_remove(struct spa_hook *hook)
Remove a hook.
Definition: hook.h:383
spa_pod_builder_raw_padded
static int spa_pod_builder_raw_padded(struct spa_pod_builder *builder, const void *data, uint32_t size)
Definition: builder.h:178
SPA_POD_SIZE
#define SPA_POD_SIZE(pod)
Definition: pod.h:50
spa_pod_builder_deref
static struct spa_pod * spa_pod_builder_deref(struct spa_pod_builder *builder, uint32_t offset)
Definition: builder.h:113
device.h
spa/monitor/device.h
spa_device_events
spa_device_events:
Definition: device.h:139
spa_device_events::version
uint32_t version
Definition: device.h:143
spa_device
Definition: device.h:60
spa_hook
A hook, contains the structure with functions and the data passed to the functions.
Definition: hook.h:342
spa_pod_builder_state::offset
uint32_t offset
Definition: builder.h:53
spa_pod_builder
Definition: builder.h:73
spa_pod_builder::state
struct spa_pod_builder_state state
Definition: builder.h:77
spa_pod
Definition: pod.h:63
spa_result_device_params_data
Definition: utils.h:45
spa_result_device_params_data::data
struct spa_result_device_params data
Definition: utils.h:47
spa_result_device_params_data::builder
struct spa_pod_builder * builder
Definition: utils.h:46
spa_result_device_params
Definition: device.h:116
spa_result_device_params::index
uint32_t index
Definition: device.h:118
spa_result_device_params::next
uint32_t next
Definition: device.h:119
spa_result_device_params::param
struct spa_pod * param
Definition: device.h:120