mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-16 07:00:00 -05:00
improve interfaces
Make an interface structure to hold methods and events. Move interface setup to protocol
This commit is contained in:
parent
905743dac6
commit
7ad02f553a
13 changed files with 341 additions and 255 deletions
|
|
@ -979,7 +979,7 @@ client_node_destroy (void *object,
|
|||
pinos_client_node_destroy (node);
|
||||
}
|
||||
|
||||
static PinosClientNodeInterface client_node_interface = {
|
||||
static PinosClientNodeMethods client_node_methods = {
|
||||
&client_node_update,
|
||||
&client_node_port_update,
|
||||
&client_node_state_change,
|
||||
|
|
@ -1147,7 +1147,6 @@ client_node_resource_destroy (PinosResource *resource)
|
|||
if (proxy->data_source.fd != -1) {
|
||||
spa_loop_remove_source (proxy->data_loop, &proxy->data_source);
|
||||
close (proxy->data_source.fd);
|
||||
proxy->data_source.fd = -1;
|
||||
}
|
||||
|
||||
pinos_node_destroy (this->node);
|
||||
|
|
@ -1239,7 +1238,7 @@ pinos_client_node_new (PinosClient *client,
|
|||
&impl->global_added,
|
||||
on_global_added);
|
||||
|
||||
this->resource->interface = &client_node_interface;
|
||||
this->resource->implementation = &client_node_methods;
|
||||
|
||||
return this;
|
||||
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ no_id:
|
|||
"unknown object id %u", id);
|
||||
}
|
||||
|
||||
static PinosRegistryInterface registry_interface = {
|
||||
static PinosRegistryMethods registry_methods = {
|
||||
®istry_bind
|
||||
};
|
||||
|
||||
|
|
@ -114,7 +114,7 @@ core_get_registry (void *object,
|
|||
if (registry_resource == NULL)
|
||||
goto no_mem;
|
||||
|
||||
registry_resource->interface = ®istry_interface;
|
||||
registry_resource->implementation = ®istry_methods;
|
||||
|
||||
spa_list_insert (this->registry_resource_list.prev, ®istry_resource->link);
|
||||
|
||||
|
|
@ -202,7 +202,7 @@ no_mem:
|
|||
return;
|
||||
}
|
||||
|
||||
static PinosCoreInterface core_interface = {
|
||||
static PinosCoreMethods core_methods = {
|
||||
&core_client_update,
|
||||
&core_sync,
|
||||
&core_get_registry,
|
||||
|
|
@ -235,7 +235,7 @@ core_bind_func (PinosGlobal *global,
|
|||
if (resource == NULL)
|
||||
goto no_mem;
|
||||
|
||||
resource->interface = &core_interface;
|
||||
resource->implementation = &core_methods;
|
||||
|
||||
spa_list_insert (this->resource_list.prev, &resource->link);
|
||||
client->core_resource = resource;
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
#include "pinos/server/resource.h"
|
||||
#include "pinos/server/protocol-native.h"
|
||||
|
||||
typedef bool (*PinosDemarshalFunc) (void *object, void *data, size_t size);
|
||||
|
||||
typedef struct {
|
||||
SpaPODBuilder b;
|
||||
|
|
@ -164,7 +165,7 @@ core_demarshal_client_update (void *object,
|
|||
0))
|
||||
return false;
|
||||
}
|
||||
pinos_core_do_client_update (resource, &props);
|
||||
((PinosCoreMethods*)resource->implementation)->client_update (resource, &props);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -183,7 +184,7 @@ core_demarshal_sync (void *object,
|
|||
0))
|
||||
return false;
|
||||
|
||||
pinos_core_do_sync (resource, seq);
|
||||
((PinosCoreMethods*)resource->implementation)->sync (resource, seq);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -203,7 +204,7 @@ core_demarshal_get_registry (void *object,
|
|||
0))
|
||||
return false;
|
||||
|
||||
pinos_core_do_get_registry (resource, seq, new_id);
|
||||
((PinosCoreMethods*)resource->implementation)->get_registry (resource, seq, new_id);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -238,12 +239,12 @@ core_demarshal_create_node (void *object,
|
|||
if (!spa_pod_iter_get (&it, SPA_POD_TYPE_INT, &new_id, 0))
|
||||
return false;
|
||||
|
||||
pinos_core_do_create_node (resource,
|
||||
seq,
|
||||
factory_name,
|
||||
name,
|
||||
&props,
|
||||
new_id);
|
||||
((PinosCoreMethods*)resource->implementation)->create_node (resource,
|
||||
seq,
|
||||
factory_name,
|
||||
name,
|
||||
&props,
|
||||
new_id);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -277,11 +278,11 @@ core_demarshal_create_client_node (void *object,
|
|||
if (!spa_pod_iter_get (&it, SPA_POD_TYPE_INT, &new_id, 0))
|
||||
return false;
|
||||
|
||||
pinos_core_do_create_client_node (resource,
|
||||
seq,
|
||||
name,
|
||||
&props,
|
||||
new_id);
|
||||
((PinosCoreMethods*)resource->implementation)->create_client_node (resource,
|
||||
seq,
|
||||
name,
|
||||
&props,
|
||||
new_id);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -337,7 +338,7 @@ registry_demarshal_bind (void *object,
|
|||
0))
|
||||
return false;
|
||||
|
||||
pinos_registry_do_bind (resource, id, new_id);
|
||||
((PinosRegistryMethods*)resource->implementation)->bind (resource, id, new_id);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -757,7 +758,7 @@ client_node_demarshal_update (void *object,
|
|||
if (have_props && !spa_pod_iter_get (&it, SPA_POD_TYPE_OBJECT, &props, 0))
|
||||
return false;
|
||||
|
||||
pinos_client_node_do_update (resource, change_mask, max_input_ports, max_output_ports, props);
|
||||
((PinosClientNodeMethods*)resource->implementation)->update (resource, change_mask, max_input_ports, max_output_ports, props);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -829,7 +830,7 @@ client_node_demarshal_port_update (void *object,
|
|||
}
|
||||
}
|
||||
|
||||
pinos_client_node_do_port_update (resource,
|
||||
((PinosClientNodeMethods*)resource->implementation)->port_update (resource,
|
||||
direction,
|
||||
port_id,
|
||||
change_mask,
|
||||
|
|
@ -854,7 +855,7 @@ client_node_demarshal_state_change (void *object,
|
|||
!spa_pod_iter_get (&it, SPA_POD_TYPE_INT, &state, 0))
|
||||
return false;
|
||||
|
||||
pinos_client_node_do_state_change (resource, state);
|
||||
((PinosClientNodeMethods*)resource->implementation)->state_change (resource, state);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -872,7 +873,7 @@ client_node_demarshal_event (void *object,
|
|||
!spa_pod_iter_get (&it, SPA_POD_TYPE_BYTES, &event, &sz, 0))
|
||||
return false;
|
||||
|
||||
pinos_client_node_do_event (resource, event);
|
||||
((PinosClientNodeMethods*)resource->implementation)->event (resource, event);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -889,7 +890,7 @@ client_node_demarshal_destroy (void *object,
|
|||
!spa_pod_iter_get (&it, SPA_POD_TYPE_INT, &seq, 0))
|
||||
return false;
|
||||
|
||||
pinos_client_node_do_destroy (resource, seq);
|
||||
((PinosClientNodeMethods*)resource->implementation)->destroy (resource, seq);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -906,23 +907,16 @@ link_marshal_info (void *object,
|
|||
SPA_POD_TYPE_STRUCT, &f,
|
||||
SPA_POD_TYPE_INT, info->id,
|
||||
SPA_POD_TYPE_LONG, info->change_mask,
|
||||
SPA_POD_TYPE_LONG, info->output_node_id,
|
||||
SPA_POD_TYPE_LONG, info->output_port_id,
|
||||
SPA_POD_TYPE_LONG, info->input_node_id,
|
||||
SPA_POD_TYPE_LONG, info->input_port_id,
|
||||
SPA_POD_TYPE_INT, info->output_node_id,
|
||||
SPA_POD_TYPE_INT, info->output_port_id,
|
||||
SPA_POD_TYPE_INT, info->input_node_id,
|
||||
SPA_POD_TYPE_INT, info->input_port_id,
|
||||
-SPA_POD_TYPE_STRUCT, &f, 0);
|
||||
|
||||
pinos_connection_end_write (connection, resource->id, 0, b.b.offset);
|
||||
}
|
||||
|
||||
const PinosCoreEvent pinos_protocol_native_server_core_event = {
|
||||
&core_marshal_info,
|
||||
&core_marshal_done,
|
||||
&core_marshal_error,
|
||||
&core_marshal_remove_id
|
||||
};
|
||||
|
||||
const PinosDemarshalFunc pinos_protocol_native_server_core_demarshal[] = {
|
||||
static const PinosDemarshalFunc pinos_protocol_native_server_core_demarshal[] = {
|
||||
&core_demarshal_client_update,
|
||||
&core_demarshal_sync,
|
||||
&core_demarshal_get_registry,
|
||||
|
|
@ -930,29 +924,69 @@ const PinosDemarshalFunc pinos_protocol_native_server_core_demarshal[] = {
|
|||
&core_demarshal_create_client_node
|
||||
};
|
||||
|
||||
const PinosRegistryEvent pinos_protocol_native_server_registry_event = {
|
||||
static const PinosCoreEvents pinos_protocol_native_server_core_events = {
|
||||
&core_marshal_info,
|
||||
&core_marshal_done,
|
||||
&core_marshal_error,
|
||||
&core_marshal_remove_id
|
||||
};
|
||||
|
||||
const PinosInterface pinos_protocol_native_server_core_interface = {
|
||||
5, pinos_protocol_native_server_core_demarshal,
|
||||
4, &pinos_protocol_native_server_core_events,
|
||||
};
|
||||
|
||||
static const PinosDemarshalFunc pinos_protocol_native_server_registry_demarshal[] = {
|
||||
®istry_demarshal_bind,
|
||||
};
|
||||
|
||||
static const PinosRegistryEvents pinos_protocol_native_server_registry_events = {
|
||||
®istry_marshal_global,
|
||||
®istry_marshal_global_remove,
|
||||
};
|
||||
|
||||
const PinosDemarshalFunc pinos_protocol_native_server_registry_demarshal[] = {
|
||||
®istry_demarshal_bind,
|
||||
const PinosInterface pinos_protocol_native_server_registry_interface = {
|
||||
1, pinos_protocol_native_server_registry_demarshal,
|
||||
2, &pinos_protocol_native_server_registry_events,
|
||||
};
|
||||
|
||||
const PinosModuleEvent pinos_protocol_native_server_module_event = {
|
||||
static const PinosModuleEvents pinos_protocol_native_server_module_events = {
|
||||
&module_marshal_info,
|
||||
};
|
||||
|
||||
const PinosNodeEvent pinos_protocol_native_server_node_event = {
|
||||
const PinosInterface pinos_protocol_native_server_module_interface = {
|
||||
0, NULL,
|
||||
1, &pinos_protocol_native_server_module_events,
|
||||
};
|
||||
|
||||
static const PinosNodeEvents pinos_protocol_native_server_node_events = {
|
||||
&node_marshal_done,
|
||||
&node_marshal_info,
|
||||
};
|
||||
|
||||
const PinosClientEvent pinos_protocol_native_server_client_event = {
|
||||
const PinosInterface pinos_protocol_native_server_node_interface = {
|
||||
0, NULL,
|
||||
2, &pinos_protocol_native_server_node_events,
|
||||
};
|
||||
|
||||
static const PinosClientEvents pinos_protocol_native_server_client_events = {
|
||||
&client_marshal_info,
|
||||
};
|
||||
|
||||
const PinosClientNodeEvent pinos_protocol_native_server_client_node_events = {
|
||||
const PinosInterface pinos_protocol_native_server_client_interface = {
|
||||
0, NULL,
|
||||
2, &pinos_protocol_native_server_client_events,
|
||||
};
|
||||
|
||||
static const PinosDemarshalFunc pinos_protocol_native_server_client_node_demarshal[] = {
|
||||
&client_node_demarshal_update,
|
||||
&client_node_demarshal_port_update,
|
||||
&client_node_demarshal_state_change,
|
||||
&client_node_demarshal_event,
|
||||
&client_node_demarshal_destroy,
|
||||
};
|
||||
|
||||
static const PinosClientNodeEvents pinos_protocol_native_server_client_node_events = {
|
||||
&client_node_marshal_done,
|
||||
&client_node_marshal_event,
|
||||
&client_node_marshal_add_port,
|
||||
|
|
@ -966,14 +1000,46 @@ const PinosClientNodeEvent pinos_protocol_native_server_client_node_events = {
|
|||
&client_node_marshal_transport,
|
||||
};
|
||||
|
||||
const PinosDemarshalFunc pinos_protocol_native_server_client_node_demarshal[] = {
|
||||
&client_node_demarshal_update,
|
||||
&client_node_demarshal_port_update,
|
||||
&client_node_demarshal_state_change,
|
||||
&client_node_demarshal_event,
|
||||
&client_node_demarshal_destroy,
|
||||
const PinosInterface pinos_protocol_native_server_client_node_interface = {
|
||||
5, &pinos_protocol_native_server_client_node_demarshal,
|
||||
11, &pinos_protocol_native_server_client_node_events,
|
||||
};
|
||||
|
||||
const PinosLinkEvent pinos_protocol_native_server_link_event = {
|
||||
static const PinosLinkEvents pinos_protocol_native_server_link_events = {
|
||||
&link_marshal_info,
|
||||
};
|
||||
|
||||
const PinosInterface pinos_protocol_native_server_link_interface = {
|
||||
0, NULL,
|
||||
1, &pinos_protocol_native_server_link_events,
|
||||
};
|
||||
|
||||
bool
|
||||
pinos_protocol_native_server_setup (PinosResource *resource)
|
||||
{
|
||||
const PinosInterface *iface;
|
||||
if (resource->type == resource->core->uri.core) {
|
||||
iface = &pinos_protocol_native_server_core_interface;
|
||||
}
|
||||
else if (resource->type == resource->core->uri.registry) {
|
||||
iface = &pinos_protocol_native_server_registry_interface;
|
||||
}
|
||||
else if (resource->type == resource->core->uri.module) {
|
||||
iface = &pinos_protocol_native_server_module_interface;
|
||||
}
|
||||
else if (resource->type == resource->core->uri.node) {
|
||||
iface = &pinos_protocol_native_server_node_interface;
|
||||
}
|
||||
else if (resource->type == resource->core->uri.client) {
|
||||
iface = &pinos_protocol_native_server_client_interface;
|
||||
}
|
||||
else if (resource->type == resource->core->uri.client_node) {
|
||||
iface = &pinos_protocol_native_server_client_node_interface;
|
||||
}
|
||||
else if (resource->type == resource->core->uri.link) {
|
||||
iface = &pinos_protocol_native_server_link_interface;
|
||||
} else
|
||||
return false;
|
||||
resource->iface = iface;
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,16 +19,4 @@
|
|||
|
||||
#include "pinos/client/pinos.h"
|
||||
|
||||
typedef bool (*PinosDemarshalFunc) (void *object, void *data, size_t size);
|
||||
|
||||
extern const PinosCoreEvent pinos_protocol_native_server_core_event;
|
||||
extern const PinosRegistryEvent pinos_protocol_native_server_registry_event;
|
||||
extern const PinosModuleEvent pinos_protocol_native_server_module_event;
|
||||
extern const PinosNodeEvent pinos_protocol_native_server_node_event;
|
||||
extern const PinosClientEvent pinos_protocol_native_server_client_event;
|
||||
extern const PinosClientNodeEvent pinos_protocol_native_server_client_node_events;
|
||||
extern const PinosLinkEvent pinos_protocol_native_server_link_event;
|
||||
|
||||
extern const PinosDemarshalFunc pinos_protocol_native_server_core_demarshal[];
|
||||
extern const PinosDemarshalFunc pinos_protocol_native_server_registry_demarshal[];
|
||||
extern const PinosDemarshalFunc pinos_protocol_native_server_client_node_demarshal[];
|
||||
bool pinos_protocol_native_server_setup (PinosResource *resource);
|
||||
|
|
|
|||
|
|
@ -48,9 +48,8 @@ struct _PinosResource {
|
|||
void *object;
|
||||
PinosDestroy destroy;
|
||||
|
||||
const void *interface;
|
||||
const void *event;
|
||||
const void *demarshal;
|
||||
const PinosInterface *iface;
|
||||
const void *implementation;
|
||||
|
||||
PINOS_SIGNAL (destroy_signal, (PinosListener *listener,
|
||||
PinosResource *resource));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue