Commit graph

106 commits

Author SHA1 Message Date
Wim Taymans
8a959ea7a1 core_proxy: prepare to rename pw_remote -> pw_core_proxy
The pw_remote object is really a wrapper around the pw_core_proxy.
The events it emits are also available in the core proxy and are
generally awkward to use.

With some clever new pw_core_proxy_* methods and a pw_core_connect
to create the core_proxy, we can convert all code away from pw_remote.

This is a first step in this conversion, using the pw_remote behind
the scenes. It leaks into some places because it really needs to become
its own struct in a next step.
2019-12-06 11:48:40 +01:00
Wim Taymans
0b2e4a18ff protocol-native: make the connection earlier
Make the connection as soon as we create the client. We create it
without file descriptor and then set it when we connect. This
makes it possible to use the connection to queue messages before
we connect.
2019-12-05 11:43:05 +01:00
Wim Taymans
8bb1ccf587 protocol-native: emit a core error on disconnect
Let the listeners on the core_proxy know about connection errors.
2019-12-05 11:32:51 +01:00
Wim Taymans
e40fbf8cc4 Add printf checks for proxy_error and resource_error
Add an error variant without checks.
2019-11-21 16:09:05 +01:00
Wim Taymans
e18a24493a client: don't register in client_new()
Don't register in client_new() to make it possible to do other things
on the client before registering. Register the client in protocol-native
after we set up the events etc.
2019-11-19 15:59:45 +01:00
George Kiagiadakis
5f65f1cbbe client: register the global early, in pw_client_new()
otherwise, if the access module blocks the client, the on_start
callback in the protocol is not called and there is no global,
which means the session manager cannot do anything to grant
permissions on this client and the client is blocked forever
2019-11-19 14:50:04 +00:00
Gleb Popov
6ea24a7db5 Don't call getsockopt with SO_PEERCRED and SO_PEERSEC parameters on FreeBSD. 2019-11-19 13:41:40 +01:00
Wim Taymans
4ad7ce3aa2 session-manager: split policy and monitor
Separate the session manager in a monitor and policy part.

The monitor manages the devices and endpoints.

The policy watches the nodes/ports/clients and applies the policy
of linking them.

Because both now have a separate connection, we can remove some
hacks in the protocol. When a remote was both the implementer and
user of an object we could get in a deadlock when the user was
blocked waiting and the implementator was blocked sending a reply.
We used to un-busy a client when it was expecting a reply from a
ping or sync for this reason.

Add and use some more keys for the endpoints and streams.
2019-11-07 16:03:00 +01:00
Wim Taymans
8ddf579cc0 protocol: add flags to protocol marshal
Allows us to to select marshallers for implementation and binding.
2019-11-03 10:21:57 +01:00
Wim Taymans
e18ca6e9c8 protocol-native: don't try to flush when the source is gone
When the connection is broken, we destroy the source avoid trying
to flush when the source is gone.
2019-10-08 23:47:02 +02:00
Wim Taymans
082463efd0 protocol: add v0 compatibility
For flatpaks we need to be able to support older v0 protocol clients.
To handle this we have:

- the connection detects an old client when it receives the first
  message. It can do this by checking the sequence number, on old
  versions it contains the message size and is never 0, on new
  clients the sequence number is 0.

- We add a new signal at the start of the connection with the detected
  version number. This installs the right version of the core proxy.
  We also move the binding of the client until the hello message is
  received. This way we can have a new client connect (portal),
  hand over the connection to an old client, which then removes the
  client binding again in the hello request with a v0 version.
  There are some changes to the passing of fds in v0 vs v3 which need
  to investigated some more.

- bump version of our interfaces to 3. This makes it possible to
  have v0 and v3 protocol marshal functions.

- Add version number in the proxy. This is mostly automatically done
  internally based on the version numbers the library is compiled
  with. Where the version number was in the API before, it is now
  actually used to look up the right protocol marshal functions. For
  Proxies there is usually just 1 version, the current one. It is the
  server that will support different versions.

- Add v0 compat marshal functions to convert from and to v0 format.
  This has some complications. v0 has a type map it keeps in sync
  with the server. For this we have a static type map with mappings
  to our own v3 types. Pods are mostly the same except for objects
  that used to have arbitrary pods in v0 vs spa_pod_prop in v3. Also
  convert between v0 spa_pod_prop and v3 spa_pod_choice.
  Formats and commands are also slightly different so handle those
  mappings as well.
  We only have marshal functions for the server side (resource)
  v0 functions.

- Add v0 compatible client-node again. It's a bit tricky to map, v0
  client-node basically lets the server to the mixing and teeing
  and just does the processing of the internal node.
2019-10-08 23:20:18 +02:00
Wim Taymans
6e0ffb0c47 flags: change flag macros
SPA_FLAG_CHECK -> SPA_FLAG_IS_SET
SPA_FLAG_UNSET -> SPA_FLAG_CLEAR
Add SPA_FLAG_UPDATE
2019-10-02 18:00:42 +02:00
Wim Taymans
cc8e992cd1 protocol: improve flushing
Use the IO_OUT flag to schedule flushing instead of a flush_event.

Handle EGAIN and wait for IO_OUT to try again.

Fixes #111
2019-10-01 12:53:56 +02:00
Wim Taymans
ca34a75173 protocol-native: attempt to remove socket
After we grab the lockfile we should remove the socket when it
exists so that we can bind again. This should solve startup
problems after a crash, which left the socket around and caused
bind failures.
2019-08-30 18:08:00 +02:00
George Kiagiadakis
f1d60d6009 protocol-native: downgrade getsockopt SO_PEERSEC error to warning
Getting SO_PEERSEC on distributions that do not use a LSM by default,
results always in a "protocol error", which is just annoying and not
a real problem for pipewire's operation.
2019-08-19 16:34:18 +02:00
Wim Taymans
8db4a797aa core: remove parent_id from the global event
Remove the parent_id from the global event. Remove the parent
and owner from the global object.

Use properties instead to mark parents and owners of objects.

Properties are easier to control for client exported objects and
usually a simple parent/child is not enough. For example, a client
exported node has the client as a parent but also the factory that
created the node.
2019-08-16 22:11:42 +02:00
Wim Taymans
84ec90da2d proxy: add refcount to keep the proxy alive in demarshal
We need to keep the proxy alive during demarshal because the callbacks
might decide to destroy the proxy.
2019-08-16 15:19:19 +02:00
Wim Taymans
8da7222c7e protocol-native: avoid NULL pointer access 2019-08-16 15:09:16 +02:00
Wim Taymans
35f617157f proxy: improve proxy cleanup
When we destroy a proxy, mark it as zombie until the server removes
the id. This way we can still keep the id locked with a valid entry
and remove it later.
2019-08-14 11:52:59 +02:00
Wim Taymans
6a8fe43a0c improve debug 2019-08-14 11:44:16 +02:00
Wim Taymans
53d3d5cb0c improve debug 2019-07-17 15:29:18 +02:00
Wim Taymans
30e5ad2b6a protocol: improve debug 2019-07-16 18:51:14 +02:00
Wim Taymans
5b7e95c71c system: make system functions return error on error
Return -errno from system functions instead of -1 in errors. This
makes it easier to pass along the result without having to go to
errno etc..
2019-06-20 17:31:29 +02:00
Wim Taymans
a212d2f9ed improve error handling some more 2019-06-20 11:04:34 +02:00
Wim Taymans
00ea15dc1f improve error handling 2019-06-19 16:22:22 +02:00
Wim Taymans
c4f35825fe protocol: improve error handling 2019-06-19 11:06:10 +02:00
Wim Taymans
216b641ebb connection: add do_close flag to connect_fd
Make pw_remote_connect_fd() not automatically close the provided
fd but let the caller take care of that. This allows us to reuse
the fd in pipewiresrc.

Fixes #155
2019-06-19 11:05:58 +02:00
Wim Taymans
db88e9f954 System: More work on making system functions pluggable
Move the epoll functions to the system functions and make the loop
use those. Use simple mask for events instead of enum.
Add the used system api in pw_loop.
Add System API to spa_support and use it where possible.
Pass the system API used in the realtime loops in spa_support as
well and use this in the realtime paths.
Improve bootstrapping, load only the log and cpu interfaces because
those can/need to be shared between instances. Let the core load
the other interfaces.
Add keys to configure the System and Loop implementations used in
pw_loop.
2019-06-06 15:31:53 +02:00
Wim Taymans
3ad73f0532 keys: add keys.h with defines and docs
Add a keys.h file that lists and documents all keys available to
be used in properties.
2019-05-24 15:47:48 +02:00
Wim Taymans
ff946e3d4b interface: add an interface struct
The interface struct has the type,version and methods of the
interface.
Make spa interfaces extend from spa_interface and make a
separate structure for the methods.
Pass a generic void* as the first argument of methods, like
we don in PipeWire.
Bundle the methods + implementation in a versioned inteface
and use that to invoke methods. This way we can do version
checks on the methods.
Make resource and proxy interfaces that we can can call. We
can then make the core interfaces independent on proxy/resource and
hide them in the lower layers.
Add add_listener method to methods of core interfaces, just
like SPA.
2019-05-23 12:59:24 +02:00
Wim Taymans
795b14f48b protocol-native: also handle 0 recvmsg as EOF
When recvmsg returns 0, also handle it like an EOF and close to
connection otherwise we keep spinning forever.
2019-05-13 10:10:41 +02:00
Wim Taymans
a2bf4ce96e protocol: add security label to a client
Don't pass the ucred to the client construct, just set the properties
in the protocol.
Use the client properties to get ucred.
Add the security label to the client properties (from SO_PEERSEC)
2019-05-10 13:28:18 +02:00
Wim Taymans
c2cb74a146 protocol-native: fix indentation 2019-03-20 15:57:34 +01:00
Wim Taymans
70e62aacd7 protocol-native: pass a message around
Pass a message around to make things more extensible later.
Keep fds per message if we ever want to write individual
messages.
Pass number of fds in the message header. We might need this to
close the fds when the proxy is gone.
2019-03-19 16:15:20 +01:00
Wim Taymans
09c4683ef1 interfaces: make events return void
Events are dispatched with hooks and have no return value.

Make it possible to get the last resource and proxy sender value
for where we need it.
2019-03-01 14:04:05 +01:00
Wim Taymans
f2ff6f393b more async improvements
Make the sequence number an int.

Keep track of the last received seq number and pass it in error
replies.

Pass seq in for_each methods.
2019-02-25 16:25:27 +01:00
Wim Taymans
d2c18c7b1a Improve async handling
Don't use special callback in node to receive the results. Instead,
use a generic result callback to receive the result. This makes things
a bit more symetric and generic again because then you can choose how
to match the result to the request and you have a generic way to handle
both the sync and async case. We can then also remove the wait method.
This also makes the remote interface and spa interface to objects very
similar.

Make a helper object to receive and dispatch results. Use this in the
helper for enum_params.

Make device use the same result callbacks.
2019-02-25 12:29:57 +01:00
Wim Taymans
7b12212eeb node: improve async handling
Remove the done and error callbacks. The error callback is in an
error message. The done callback is replace with spa_pending.

Make enum_params take a callback and data for the results. This allows
us to push the results one after another to the app and avoids ownership
issues of the passed data. We can then extend this to handle the async
case by doing a _wait call with a spa_pending+callback+data that will
be called when the _enum_params returns and async result.
Add a sync method.

All methods can now return SPA_RESULT_IS_ASYNC return values and you
can use spa_node_wait() to register a callback when they complete
with optional extra parameters. This makes it easier to sync and
handle the reply.

Make helper methods to simulate the sync enum_params behaviour for
sync nodes.

Let the transport generate the sequence number for pw_resource_sync()
and pw_proxy_sync(). That way we don't need to keep track of numbers
ourselves and we can match the reply to the request easily.
2019-02-21 09:40:12 +01:00
Wim Taymans
eea062ee53 interfaces: improve remote API
Add return values to events and method callbacks. This makes it
possible to pass any error or async return value.
Add sync/done/error in both directions so that both proxy and resource
and perform/reply sync and produce errors.
Return a SPA_ASYNC from remote method calls (and events), keep the
sequence number in the connection.
With the core sync/done we can remove the client-node done method and
it's internal sequence number along with the seq number in method calls.
We can also use the method/event async return value to perform a sync
with as the unique sequence number for this method.
Add sync method and done/error event to proxy and resource.
2019-02-18 12:31:36 +01:00
Wim Taymans
8ae5424359 resource: improve error handling
Make some more varargs error functions
Make pw_resource_error always just send the error to the resource id.
Make sure we send errors to the right destination.
Add proxy error event and emit it when the core finds an error for
the given proxy id.
The client error is supposed to be sent to all resources of a client
for the given global.
2019-02-14 16:53:42 +01:00
Wim Taymans
569cbb48a9 use SPA_EXPORT to export symbols 2019-02-06 13:24:41 +01:00
Wim Taymans
3dc6820e9e Don't use __ in defines or declarations, it's reserved
SPA_TYPE -> SPA_TYPE_INFO for type info strings
improve includes

Fixes #115
2019-01-14 13:00:00 +01:00
Wim Taymans
505eb7a423 protocol: automatically bind to the client as well
Bind to the client as well as the remote core. This way we will be
able to update our properties and permissions directly on the client.
2019-01-10 11:01:30 +01:00
Wim Taymans
e918f9f77c fix sign confusion 2019-01-07 15:52:42 +01:00
Wim Taymans
85f2e93c54 Relicense as MIT/X11
Remove some obsolete files
2018-11-05 17:48:52 +01:00
Wim Taymans
e107d75248 protocol-native: improve permission checks 2018-11-05 15:27:13 +01:00
Wim Taymans
f994b7eb70 protocol-native: only add fd if client active 2018-11-05 14:58:13 +01:00
Wim Taymans
8089d856c8 protocol: add more debug and check right permissions 2018-10-31 16:31:15 +00:00
Wim Taymans
dfde479b20 protocol-native: put client properties in global 2018-10-29 08:43:53 +00:00
Wim Taymans
537598726b protocol-native: first bind, then register
First let the client bind to the core, then register the client.
This way, the client is ready to receive methods on the core.
2018-10-27 17:10:01 +01:00