diff --git a/pipewire/client/interfaces.h b/pipewire/client/interfaces.h index 14c6a119b..660ae4141 100644 --- a/pipewire/client/interfaces.h +++ b/pipewire/client/interfaces.h @@ -139,12 +139,12 @@ struct pw_core_methods { uint32_t new_id); }; -#define pw_core_do_update_types(r,...) ((struct pw_core_methods*)r->iface->methods)->update_types(r,__VA_ARGS__) -#define pw_core_do_sync(r,...) ((struct pw_core_methods*)r->iface->methods)->sync(r,__VA_ARGS__) -#define pw_core_do_get_registry(r,...) ((struct pw_core_methods*)r->iface->methods)->get_registry(r,__VA_ARGS__) -#define pw_core_do_client_update(r,...) ((struct pw_core_methods*)r->iface->methods)->client_update(r,__VA_ARGS__) -#define pw_core_do_create_node(r,...) ((struct pw_core_methods*)r->iface->methods)->create_node(r,__VA_ARGS__) -#define pw_core_do_create_link(r,...) ((struct pw_core_methods*)r->iface->methods)->create_link(r,__VA_ARGS__) +#define pw_core_do_update_types(p,...) pw_proxy_do(p,struct pw_core_methods,update_types,__VA_ARGS__) +#define pw_core_do_sync(p,...) pw_proxy_do(p,struct pw_core_methods,sync,__VA_ARGS__) +#define pw_core_do_get_registry(p,...) pw_proxy_do(p,struct pw_core_methods,get_registry,__VA_ARGS__) +#define pw_core_do_client_update(p,...) pw_proxy_do(p,struct pw_core_methods,client_update,__VA_ARGS__) +#define pw_core_do_create_node(p,...) pw_proxy_do(p,struct pw_core_methods,create_node,__VA_ARGS__) +#define pw_core_do_create_link(p,...) pw_proxy_do(p,struct pw_core_methods,create_link,__VA_ARGS__) #define PW_CORE_EVENT_UPDATE_TYPES 0 #define PW_CORE_EVENT_DONE 1 @@ -211,11 +211,11 @@ struct pw_core_events { void (*info) (void *object, struct pw_core_info *info); }; -#define pw_core_notify_update_types(r,...) ((struct pw_core_events*)r->iface->events)->update_types(r,__VA_ARGS__) -#define pw_core_notify_done(r,...) ((struct pw_core_events*)r->iface->events)->done(r,__VA_ARGS__) -#define pw_core_notify_error(r,...) ((struct pw_core_events*)r->iface->events)->error(r,__VA_ARGS__) -#define pw_core_notify_remove_id(r,...) ((struct pw_core_events*)r->iface->events)->remove_id(r,__VA_ARGS__) -#define pw_core_notify_info(r,...) ((struct pw_core_events*)r->iface->events)->info(r,__VA_ARGS__) +#define pw_core_notify_update_types(r,...) pw_resource_notify(r,struct pw_core_events,update_types,__VA_ARGS__) +#define pw_core_notify_done(r,...) pw_resource_notify(r,struct pw_core_events,done,__VA_ARGS__) +#define pw_core_notify_error(r,...) pw_resource_notify(r,struct pw_core_events,error,__VA_ARGS__) +#define pw_core_notify_remove_id(r,...) pw_resource_notify(r,struct pw_core_events,remove_id,__VA_ARGS__) +#define pw_core_notify_info(r,...) pw_resource_notify(r,struct pw_core_events,info,__VA_ARGS__) #define PW_VERSION_REGISTRY 0 @@ -238,7 +238,7 @@ struct pw_registry_methods { void (*bind) (void *object, uint32_t id, uint32_t version, uint32_t new_id); }; -#define pw_registry_do_bind(r,...) ((struct pw_registry_methods*)r->iface->methods)->bind(r,__VA_ARGS__) +#define pw_registry_do_bind(p,...) pw_proxy_do(p,struct pw_registry_methods,bind,__VA_ARGS__) #define PW_REGISTRY_EVENT_GLOBAL 0 #define PW_REGISTRY_EVENT_GLOBAL_REMOVE 1 @@ -269,8 +269,8 @@ struct pw_registry_events { void (*global_remove) (void *object, uint32_t id); }; -#define pw_registry_notify_global(r,...) ((struct pw_registry_events*)r->iface->events)->global(r,__VA_ARGS__) -#define pw_registry_notify_global_remove(r,...) ((struct pw_registry_events*)r->iface->events)->global_remove(r,__VA_ARGS__) +#define pw_registry_notify_global(r,...) pw_resource_notify(r,struct pw_registry_events,global,__VA_ARGS__) +#define pw_registry_notify_global_remove(r,...) pw_resource_notify(r,struct pw_registry_events,global_remove,__VA_ARGS__) #define PW_VERSION_MODULE 0 @@ -287,7 +287,7 @@ struct pw_module_events { void (*info) (void *object, struct pw_module_info *info); }; -#define pw_module_notify_info(r,...) ((struct pw_module_events*)r->iface->events)->info(r,__VA_ARGS__) +#define pw_module_notify_info(r,...) pw_resource_notify(r,struct pw_module_events,info,__VA_ARGS__) #define PW_VERSION_NODE 0 @@ -304,7 +304,7 @@ struct pw_node_events { void (*info) (void *object, struct pw_node_info *info); }; -#define pw_node_notify_info(r,...) ((struct pw_node_events*)r->iface->events)->info(r,__VA_ARGS__) +#define pw_node_notify_info(r,...) pw_resource_notify(r,struct pw_node_events,info,__VA_ARGS__) #define PW_VERSION_CLIENT 0 @@ -321,7 +321,7 @@ struct pw_client_events { void (*info) (void *object, struct pw_client_info *info); }; -#define pw_client_notify_info(r,...) ((struct pw_client_events*)r->iface->events)->info(r,__VA_ARGS__) +#define pw_client_notify_info(r,...) pw_resource_notify(r,struct pw_client_events,info,__VA_ARGS__) #define PW_VERSION_LINK 0 @@ -338,7 +338,7 @@ struct pw_link_events { void (*info) (void *object, struct pw_link_info *info); }; -#define pw_link_notify_info(r,...) ((struct pw_link_events*)r->iface->events)->info(r,__VA_ARGS__) +#define pw_link_notify_info(r,...) pw_resource_notify(r,struct pw_link_events,info,__VA_ARGS__) #ifdef __cplusplus } /* extern "C" */ diff --git a/pipewire/client/proxy.h b/pipewire/client/proxy.h index 09bfa7395..f91534faf 100644 --- a/pipewire/client/proxy.h +++ b/pipewire/client/proxy.h @@ -121,6 +121,11 @@ pw_proxy_set_implementation(struct pw_proxy *proxy, void pw_proxy_destroy(struct pw_proxy *proxy); +#define pw_proxy_notify(p,type,event,...) ((type*) (p)->implementation)->event(p, __VA_ARGS__) +#define pw_proxy_notify_na(p,type,event) ((type*) (p)->implementation)->event(p) +#define pw_proxy_do(p,type,method,...) ((type*) (p)->iface->methods)->method(p, __VA_ARGS__) +#define pw_proxy_do_na(p,type,method) ((type*) (p)->iface->methods)->method(p) + #ifdef __cplusplus } #endif diff --git a/pipewire/extensions/client-node.h b/pipewire/extensions/client-node.h index b014e3d28..445d9de32 100644 --- a/pipewire/extensions/client-node.h +++ b/pipewire/extensions/client-node.h @@ -113,11 +113,11 @@ struct pw_client_node_methods { void (*destroy) (void *object); }; -#define pw_client_node_do_done(r,...) ((struct pw_client_node_methods*)r->iface->methods)->done(r,__VA_ARGS__) -#define pw_client_node_do_update(r,...) ((struct pw_client_node_methods*)r->iface->methods)->update(r,__VA_ARGS__) -#define pw_client_node_do_port_update(r,...) ((struct pw_client_node_methods*)r->iface->methods)->port_update(r,__VA_ARGS__) -#define pw_client_node_do_event(r,...) ((struct pw_client_node_methods*)r->iface->methods)->event(r,__VA_ARGS__) -#define pw_client_node_do_destroy(r) ((struct pw_client_node_methods*)r->iface->methods)->destroy(r) +#define pw_client_node_do_done(p,...) pw_proxy_do(p,struct pw_client_node_methods,done,__VA_ARGS__) +#define pw_client_node_do_update(p,...) pw_proxy_do(p,struct pw_client_node_methods,update,__VA_ARGS__) +#define pw_client_node_do_port_update(p,...) pw_proxy_do(p,struct pw_client_node_methods,port_update,__VA_ARGS__) +#define pw_client_node_do_event(p,...) pw_proxy_do(p,struct pw_client_node_methods,event,__VA_ARGS__) +#define pw_client_node_do_destroy(p) pw_proxy_do_na(p,struct pw_client_node_methods,destroy) #define PW_CLIENT_NODE_EVENT_TRANSPORT 0 #define PW_CLIENT_NODE_EVENT_SET_PROPS 1 @@ -280,17 +280,17 @@ struct pw_client_node_events { }; -#define pw_client_node_notify_transport(r,...) ((struct pw_client_node_events*)r->iface->events)->transport(r,__VA_ARGS__) -#define pw_client_node_notify_set_props(r,...) ((struct pw_client_node_events*)r->iface->events)->props(r,__VA_ARGS__) -#define pw_client_node_notify_event(r,...) ((struct pw_client_node_events*)r->iface->events)->event(r,__VA_ARGS__) -#define pw_client_node_notify_add_port(r,...) ((struct pw_client_node_events*)r->iface->events)->add_port(r,__VA_ARGS__) -#define pw_client_node_notify_remove_port(r,...) ((struct pw_client_node_events*)r->iface->events)->remove_port(r,__VA_ARGS__) -#define pw_client_node_notify_set_format(r,...) ((struct pw_client_node_events*)r->iface->events)->set_format(r,__VA_ARGS__) -#define pw_client_node_notify_set_param(r,...) ((struct pw_client_node_events*)r->iface->events)->set_param(r,__VA_ARGS__) -#define pw_client_node_notify_add_mem(r,...) ((struct pw_client_node_events*)r->iface->events)->add_mem(r,__VA_ARGS__) -#define pw_client_node_notify_use_buffers(r,...) ((struct pw_client_node_events*)r->iface->events)->use_buffers(r,__VA_ARGS__) -#define pw_client_node_notify_node_command(r,...) ((struct pw_client_node_events*)r->iface->events)->node_command(r,__VA_ARGS__) -#define pw_client_node_notify_port_command(r,...) ((struct pw_client_node_events*)r->iface->events)->port_command(r,__VA_ARGS__) +#define pw_client_node_notify_transport(r,...) pw_resource_notify(r,struct pw_client_node_events,transport,__VA_ARGS__) +#define pw_client_node_notify_set_props(r,...) pw_resource_notify(r,struct pw_client_node_events,props,__VA_ARGS__) +#define pw_client_node_notify_event(r,...) pw_resource_notify(r,struct pw_client_node_events,event,__VA_ARGS__) +#define pw_client_node_notify_add_port(r,...) pw_resource_notify(r,struct pw_client_node_events,add_port,__VA_ARGS__) +#define pw_client_node_notify_remove_port(r,...) pw_resource_notify(r,struct pw_client_node_events,remove_port,__VA_ARGS__) +#define pw_client_node_notify_set_format(r,...) pw_resource_notify(r,struct pw_client_node_events,set_format,__VA_ARGS__) +#define pw_client_node_notify_set_param(r,...) pw_resource_notify(r,struct pw_client_node_events,set_param,__VA_ARGS__) +#define pw_client_node_notify_add_mem(r,...) pw_resource_notify(r,struct pw_client_node_events,add_mem,__VA_ARGS__) +#define pw_client_node_notify_use_buffers(r,...) pw_resource_notify(r,struct pw_client_node_events,use_buffers,__VA_ARGS__) +#define pw_client_node_notify_node_command(r,...) pw_resource_notify(r,struct pw_client_node_events,node_command,__VA_ARGS__) +#define pw_client_node_notify_port_command(r,...) pw_resource_notify(r,struct pw_client_node_events,port_command,__VA_ARGS__) #ifdef __cplusplus } /* extern "C" */ diff --git a/pipewire/modules/module-protocol-native/protocol-native.c b/pipewire/modules/module-protocol-native/protocol-native.c index d3c41cbd1..eaed5bd50 100644 --- a/pipewire/modules/module-protocol-native/protocol-native.c +++ b/pipewire/modules/module-protocol-native/protocol-native.c @@ -277,7 +277,7 @@ static bool core_demarshal_info(void *object, void *data, size_t size) SPA_POD_TYPE_STRING, &props.items[i].value, 0)) return false; } - ((struct pw_core_events *) proxy->implementation)->info(proxy, &info); + pw_proxy_notify(proxy, struct pw_core_events, info, &info); return true; } @@ -291,7 +291,7 @@ static bool core_demarshal_done(void *object, void *data, size_t size) !spa_pod_iter_get(&it, SPA_POD_TYPE_INT, &seq, 0)) return false; - ((struct pw_core_events *) proxy->implementation)->done(proxy, seq); + pw_proxy_notify(proxy, struct pw_core_events, done, seq); return true; } @@ -308,7 +308,7 @@ static bool core_demarshal_error(void *object, void *data, size_t size) SPA_POD_TYPE_INT, &res, SPA_POD_TYPE_STRING, &error, 0)) return false; - ((struct pw_core_events *) proxy->implementation)->error(proxy, id, res, error); + pw_proxy_notify(proxy, struct pw_core_events, error, id, res, error); return true; } @@ -322,7 +322,7 @@ static bool core_demarshal_remove_id(void *object, void *data, size_t size) !spa_pod_iter_get(&it, SPA_POD_TYPE_INT, &id, 0)) return false; - ((struct pw_core_events *) proxy->implementation)->remove_id(proxy, id); + pw_proxy_notify(proxy, struct pw_core_events, remove_id, id); return true; } @@ -343,8 +343,7 @@ static bool core_demarshal_update_types_client(void *object, void *data, size_t if (!spa_pod_iter_get(&it, SPA_POD_TYPE_STRING, &types[i], 0)) return false; } - ((struct pw_core_events *) proxy->implementation)->update_types(proxy, first_id, n_types, - types); + pw_proxy_notify(proxy, struct pw_core_events, update_types, first_id, n_types, types); return true; } @@ -469,7 +468,7 @@ static bool core_demarshal_client_update(void *object, void *data, size_t size) SPA_POD_TYPE_STRING, &props.items[i].value, 0)) return false; } - ((struct pw_core_methods *) resource->implementation)->client_update(resource, &props); + pw_resource_do(resource, struct pw_core_methods, client_update, &props); return true; } @@ -483,7 +482,7 @@ static bool core_demarshal_sync(void *object, void *data, size_t size) !spa_pod_iter_get(&it, SPA_POD_TYPE_INT, &seq, 0)) return false; - ((struct pw_core_methods *) resource->implementation)->sync(resource, seq); + pw_resource_do(resource, struct pw_core_methods, sync, seq); return true; } @@ -497,7 +496,7 @@ static bool core_demarshal_get_registry(void *object, void *data, size_t size) !spa_pod_iter_get(&it, SPA_POD_TYPE_INT, &new_id, 0)) return false; - ((struct pw_core_methods *) resource->implementation)->get_registry(resource, new_id); + pw_resource_do(resource, struct pw_core_methods, get_registry, new_id); return true; } @@ -525,9 +524,8 @@ static bool core_demarshal_create_node(void *object, void *data, size_t size) if (!spa_pod_iter_get(&it, SPA_POD_TYPE_INT, &new_id, 0)) return false; - ((struct pw_core_methods *) resource->implementation)->create_node(resource, - factory_name, - name, &props, new_id); + pw_resource_do(resource, struct pw_core_methods, create_node, factory_name, + name, &props, new_id); return true; } @@ -561,14 +559,13 @@ static bool core_demarshal_create_link(void *object, void *data, size_t size) if (!spa_pod_iter_get(&it, SPA_POD_TYPE_INT, &new_id, 0)) return false; - ((struct pw_core_methods *) resource->implementation)->create_link(resource, - output_node_id, - output_port_id, - input_node_id, - input_port_id, - filter, - &props, - new_id); + pw_resource_do(resource, struct pw_core_methods, create_link, output_node_id, + output_port_id, + input_node_id, + input_port_id, + filter, + &props, + new_id); return true; } @@ -589,8 +586,7 @@ static bool core_demarshal_update_types_server(void *object, void *data, size_t if (!spa_pod_iter_get(&it, SPA_POD_TYPE_STRING, &types[i], 0)) return false; } - ((struct pw_core_methods *) resource->implementation)->update_types(resource, first_id, - n_types, types); + pw_resource_do(resource, struct pw_core_methods, update_types, first_id, n_types, types); return true; } @@ -639,7 +635,7 @@ static bool registry_demarshal_bind(void *object, void *data, size_t size) SPA_POD_TYPE_INT, &new_id, 0)) return false; - ((struct pw_registry_methods *) resource->implementation)->bind(resource, id, version, new_id); + pw_resource_do(resource, struct pw_registry_methods, bind, id, version, new_id); return true; } @@ -698,7 +694,7 @@ static bool module_demarshal_info(void *object, void *data, size_t size) SPA_POD_TYPE_STRING, &props.items[i].value, 0)) return false; } - ((struct pw_module_events *) proxy->implementation)->info(proxy, &info); + pw_proxy_notify(proxy, struct pw_module_events, info, &info); return true; } @@ -797,7 +793,7 @@ static bool node_demarshal_info(void *object, void *data, size_t size) SPA_POD_TYPE_STRING, &props.items[i].value, 0)) return false; } - ((struct pw_node_events *) proxy->implementation)->info(proxy, &info); + pw_proxy_notify(proxy, struct pw_node_events, info, &info); return true; } @@ -851,7 +847,7 @@ static bool client_demarshal_info(void *object, void *data, size_t size) SPA_POD_TYPE_STRING, &props.items[i].value, 0)) return false; } - ((struct pw_client_events *) proxy->implementation)->info(proxy, &info); + pw_proxy_notify(proxy, struct pw_client_events, info, &info); return true; } @@ -894,7 +890,7 @@ static bool link_demarshal_info(void *object, void *data, size_t size) -SPA_POD_TYPE_OBJECT, &info.format, 0)) return false; - ((struct pw_link_events *) proxy->implementation)->info(proxy, &info); + pw_proxy_notify(proxy, struct pw_link_events, info, &info); return true; } @@ -912,7 +908,7 @@ static bool registry_demarshal_global(void *object, void *data, size_t size) SPA_POD_TYPE_INT, &version, 0)) return false; - ((struct pw_registry_events *) proxy->implementation)->global (proxy, id, type, version); + pw_proxy_notify(proxy, struct pw_registry_events, global, id, type, version); return true; } @@ -926,7 +922,7 @@ static bool registry_demarshal_global_remove(void *object, void *data, size_t si !spa_pod_iter_get(&it, SPA_POD_TYPE_INT, &id, 0)) return false; - ((struct pw_registry_events *) proxy->implementation)->global_remove(proxy, id); + pw_proxy_notify(proxy, struct pw_registry_events, global_remove, id); return true; } diff --git a/pipewire/server/resource.h b/pipewire/server/resource.h index 4159e227a..e15fbe8fc 100644 --- a/pipewire/server/resource.h +++ b/pipewire/server/resource.h @@ -94,6 +94,11 @@ pw_resource_set_implementation(struct pw_resource *resource, void pw_resource_destroy(struct pw_resource *resource); +#define pw_resource_do(r,type,method,...) ((type*) r->implementation)->method(r, __VA_ARGS__) +#define pw_resource_do_na(r,type,method) ((type*) r->implementation)->method(r) +#define pw_resource_notify(r,type,event,...) ((type*) r->iface->events)->event(r, __VA_ARGS__) +#define pw_resource_notify_na(r,type,event) ((type*) r->iface->events)->event(r) + #ifdef __cplusplus } #endif