Commit graph

41 commits

Author SHA1 Message Date
Wim Taymans
c48c444566 pw-link: avoid memleak when proxy create fails 2024-06-11 15:57:21 +02:00
Diego Viola
7410755c03 Fix typos
found them with codespell.

Signed-off-by: Diego Viola <diego.viola@gmail.com>
2024-05-22 09:19:34 +02:00
Wim Taymans
d4581755e6 spa: Improve JSON error reporting
Add struct spa_error_location that holds information about some parsing
context such as the line and column number, error and line fragment
with the error.

Make spa_json_get_error() fill in the spa_error_location instead. Add
some error codes to the error state and use this to add a parsing reason
to the location.

Add a debug function to log the error location in a nice way. Also
add a FILE based debug context to log to any FILE.

Replace pw_properties_check_string() with
pw_properties_update_string_checked() and add
pw_properties_new_string_checked(). The check string behaviour can still
be done by setting props to NULL but the main purpose is to be able to
avoid parsing the json file twice in the future.

When using the old pw_properties_update_string(), log a warning to the
log when we fail to parse the complete string.

Use the new checked functions and the debug functions to report about
parsing errors in the tools and conf parsing.

This gives errors like:

```
> pw-loopback --playback-props '{ foo =  [ f : g ] }'
error: syntax error in --playback-props: Invalid array separator
line:      1 | { foo =  [ f : g ] }
col:      14 |              ^
```
2024-03-27 15:42:29 +01:00
Pauli Virtanen
026d55df62 tools: check properties given by user for syntax errors
Check JSON passed in by user for syntax errors before processing it.
2024-03-25 21:42:26 +02:00
Barnabás Pőcze
8cf5bbf658 pw-link: do argument check before sync 2024-02-27 08:32:56 +00:00
Barnabás Pőcze
e362a66880 pw-link: do not leak memory 2024-02-27 08:32:56 +00:00
Barnabás Pőcze
ca5a342e92 pw-link: use the regex_t objects in struct data 2024-02-27 08:32:56 +00:00
Barnabás Pőcze
431a201d6c pw-link: make mode a proper enum 2024-02-27 08:32:56 +00:00
Barnabás Pőcze
8947ba504e pw-link: use a simple boolean flag to control monitor mode
Monitoring does not interact with the normal modes of pw-link,
so separate it from them.
2024-02-27 08:32:56 +00:00
Barnabás Pőcze
241346d887 pw-link: use union for type specific data
This is safer than using a bare array of `uint32_t` with hard-coded indices.
2024-02-27 08:32:56 +00:00
Barnabás Pőcze
6160615726 pw-link: use proper enum for object types
Using an enum provides better debugging experience and
indicates the purpose better than a bare `uint32_t`.
2024-02-27 08:32:56 +00:00
Barnabás Pőcze
5218afc7e8 pw-link: pass false instead of NULL for bool parameter 2024-02-27 08:32:56 +00:00
Barnabás Pőcze
d84101d97f pw-link: free target_link objects at the end 2024-02-27 08:32:56 +00:00
Wim Taymans
efd22efff8 pw-link: improve port and node names
don't leave the port and node names blank but fill in some defaults that
include the node/port id.
2024-02-12 17:14:33 +01:00
Wim Taymans
27dbbd40c9 tools: improve indentation 2024-02-09 10:24:34 +01:00
Théo Lebrun
28df14859a pw-link: handle link proxy removal 2024-02-01 13:35:30 +01:00
Théo Lebrun
ecffe3cbd6 pw-link: handle link proxy destruction
If for some reason the proxy gets destroyed, we make sure to remove
listeners and forget the proxy pointer. We do not however delete the
target_link; we consider the proxy destruction as an error.

If another definitive state occured on the link (got to paused state,
got an error), then that event will be ignored. Else we consider it an
error.
2024-02-01 12:08:15 +01:00
Théo Lebrun
7ebc1b05d2 pw-link: --wait: allow linking with nodes
Previously, on new node event, we registered a core sync. Linking was
attempted at core sync done  but the node did not yet have time to
register its ports.

Only listen to new ports. This delays the linking attempt to when nodes
have had time to create their ports.
2024-02-01 10:47:49 +00:00
Théo Lebrun
6a7d83f051 pw-link: listen to link info events to detect link creation
Stop using sync for link creation detection. Instead, listen to link
events.

We still listen to errors, link info events are not enough. For example,
if a link already exists, we only get a proxy error and no link info
event.
2024-02-01 10:47:49 +00:00
Théo Lebrun
5169941908 pw-link: add --wait option
Now that we have a create_link_proxies() that looks for our matching
nodes/ports and creates proxies if they exist, implementing --wait is
easy.

We move the call to create_link_proxies() the core done event. If it
finds no potential nodes/ports, we keep running our loop, monitoring
new objects.
2024-02-01 10:47:49 +00:00
Théo Lebrun
54662ad209 pw-link: refactor do_link_ports() to not run the event-loop
Make do_link_ports() only create proxies. Previously it ran the event
loop once per attempted link to detect link creation errors. Rename it
to create_link_proxies() to make things clear.

Created proxies are stored into a list (data->link_targets).
create_link_proxies() returns the number of link proxies created. This
can be zero when the two matching nodes have zero ports.

Refactor main() to use create_link_proxies(), ask for a sync then run
the event loop. It will stop on sync done, and we will have received
all potential link proxy errors.

Cleanup all proxies and listeners at the end of main().
2024-02-01 10:47:49 +00:00
Théo Lebrun
e8d104f7bc pw-link: move output/input option checking before main event loop run 2024-02-01 10:47:49 +00:00
Barnabás Pőcze
436787d6ba treewide: try to use const char * for string literals 2023-09-16 17:47:35 +02:00
Barnabás Pőcze
934ab3036e treewide: use SPDX tags to specify copyright information
SPDX tags make the licensing information easy to understand and clear,
and they are machine parseable.

See https://spdx.dev for more information.
2023-02-16 10:54:48 +00:00
Sanchayan Maity
05a133f5b5 pw-link: Improve error message if ports are not found
In a scenario where pw-link is called without a session manager running,
the output port on a node will not exist. In such a case, we broke out
of the for loop with all_links_exist set to true and returning EEXIST.

The return of EEXIST gives a confusing error message. Fix this.
2022-10-05 18:08:32 +05:30
Wim Taymans
978c50e86c pw-link: make port_id char array larger
The id might not fit.
2022-04-22 21:06:40 +02:00
Antonio Larrosa
6dd3ee4e15 pw-link: Support destroying all links between ports of two nodes
With this commit, something like
`pw-link -d my-device alsa_output.headset` can be used to destroy
all links from output ports of `my-device` to input ports of
`alsa_output.headset`.
2022-04-22 17:29:52 +00:00
Antonio Larrosa
3a18da7cc3 pw-link: Support creating links for all ports from a node to another
This allows to call pw-link with output and input nodes instead of
ports and pw-link will connect all output ports from the first node
to all input ports in the second node by port-id.

Note that the number of ports in each node isn't checked before
starting, so the ports will be connected until there's no matching
port to connect (i.e. if the output node has 2 output ports and
the input node has 5 ports, then only the first two ports will be
connected).
2022-04-22 17:29:52 +00:00
Quentin Wenger
22fc9eec35 Cleanup argument names in methods and events interfaces
First method argument is object, first event argument is data.

Closes !963
2022-04-15 10:11:49 +02:00
Pauli Virtanen
c66bb65c7a pipewire: don't setlocale from pw_init, let parent app set it
Library code generally shouldn't modify global state, so pw_init()
should not result to changing the C locale.

Instead, set the C locale in main() for tools and daemons.

We'll still setlocale for LC_MESSAGES, to get translated UI elements in
wireplumber. This workaround should be removed eventually...
2022-03-22 21:32:35 +02:00
Wim Taymans
e82f775fb3 tools: remove listeners 2022-02-09 16:30:13 +01:00
Wim Taymans
afc88a12e5 tools: cleanup up printf
Make all tools output to stdout (pw-mon mostly) so that we can pipe the
output around.
Send errors to stderr.
fprintf(stdout, ...)  -> printf(...)
setlinebuf for stdout so that pipe works better.

See #2110
2022-02-07 17:03:46 +01:00
Wim Taymans
7ac809618e pw-link: improve help and error messages
See #2089
2022-02-03 16:39:52 +01:00
Wim Taymans
a947faeaa0 pw-link: clarify -L option
-L is enabled by default, unless -m is specified.
2022-02-03 16:30:06 +01:00
Wim Taymans
b5cd6d02fd pw-link: fix -L comment 2022-02-03 16:22:21 +01:00
Peter Hutterer
7697ed0757 treewide: replace strcmp() == 0 with spa_streq()
This change is only done in source files for now, header files will be done
separately.
2021-05-18 22:10:27 +10:00
Wim Taymans
9019edec31 pw-link: improve unlink
When we only have one argument, just check the link id and if that
fails don't try to check the second argument because we would crash.
2021-04-08 15:32:06 +02:00
Wim Taymans
1b29531336 pw-link: make it possible to use ids
Make it possible to link/unlink using port ids
Make it possible to unlink using the link id
2021-04-08 13:09:51 +02:00
Wim Taymans
40194833ce pw-link: add option to print ids
Add an option to print the object ids
Improve monitor output
2021-04-08 12:54:53 +02:00
Wim Taymans
a296007ed9 pw-link: implement monitor 2021-04-08 12:08:04 +02:00
Wim Taymans
67a3f28bdf tools: add new pw-link tool
pw-link can be used to list, link and unlink ports.
2021-04-07 18:56:44 +02:00