Commit Graph

31 Commits

Author SHA1 Message Date
Ashok Sidipotu
03e6de9894 m-standard-source: handle create-* events 2023-08-15 07:14:59 +00:00
George Kiagiadakis
417b0dff4c m-std-event-source: don't push events during the core dispose sequence 2023-06-23 18:01:26 +03:00
George Kiagiadakis
5c3032c064 core: change the component arguments to be WpSpaJson instead of GVariant
This allows us to pass entire JSON objects from the config file
down to the modules / scripts without any conversion
2023-05-25 18:29:58 +03:00
George Kiagiadakis
4736d56557 log: implement a log topics system, like pipewire
The intention is to make checks for enabled log topics faster.

Every topic has its own structure that is statically defined in the file
where the logs are printed from. The structure is initialized transparently
when it is first used and it contains all the log level flags for the levels
that this topic should print messages. It is then checked on the wp_log()
macro before printing the message.

Topics from SPA/PipeWire are also handled natively, so messages are printed
directly without checking if the topic is enabled, since the PipeWire and SPA
macros do the checking themselves.

Messages coming from GLib are checked inside the handler.

An internal WpLogFields object is used to manage the state of each log
message, populating all the fields appropriately from the place they
are coming from (wp_log, spa_log, glib log), formatting the message and
then printing it. For printing to the journald, we still use the glib
message handler, converting all the needed fields to GLogField on demand.
That message handler does not do any checks for the topic or the level, so
we can just call it to send the message.
2023-05-16 20:42:28 +03:00
Julian Bouzas
c61d1e4245 component-loader: make wp_core_load_component() API asynchronous
This change completely refactors the way components are loaded in wireplumber:
- The module_init() function must return a GObject now. This object is either
a WpPlugin or a WpSiFactory in the current modules.
- When the component loader initializes a module, it automatically registers
the WpPlugin or WpSiFactory with their respective methods. There is no need
to register the WpPlugin or WpSiFactory in the module now.
- The wp_core_load_component() API has been refactored to be asynchronows. This
allows the component loader to automatically activate WpPlugin objects, and
therefore allows the application to directly get the WpPlugin without having
to find it. This simplifies a lot of things.
- The 'ifexists' and 'nofail' component flags now work even if the respective
WpPlugin could not be activated.
- The code that loads components in main.c has also been simplified a lot,
and the option to load dangling components has also been removed.
2023-04-17 07:48:18 -04:00
Julian Bouzas
9004362cda lib: remove WpEndpoint and WpSiEndpoint APIs 2023-04-17 07:48:18 -04:00
George Kiagiadakis
153c019343 m-std-event-source: separate rescan events for linking and default-nodes
Call the event "rescan-for-<context>", where <context> is either
"linking" or "default-nodes" and can be expanded in the future.

Add an additional hook in default-nodes to trigger the
rescan-for-default-nodes event when sources and sinks come and go.
2023-04-17 07:48:18 -04:00
George Kiagiadakis
dc196df239 m-std-event-source: fix state names in node-state-changed event
We need to use the enum nicknames ("idle"), not the enum names
("WP_NODE_STATE_IDLE"). This makes suspend-node work again.
2023-04-17 07:48:18 -04:00
George Kiagiadakis
dbca5783d0 m-std-event-source: don't crash in disable() if the core is not available
When the core is shutting down, the weak reference to it is cleared before
we have a change to use it, but it's ok because everything is getting destroyed
at this point, including the hook that we want to unregister.
2023-04-17 07:48:18 -04:00
George Kiagiadakis
08a9d39295 events: rename find-target-si-and-link to select-target
And make sure it does not get prefixed with the subject type
2023-04-17 07:48:18 -04:00
George Kiagiadakis
b5d8a7982f scripts: split/refactor the policy-device-routes script into smaller hooks 2023-04-17 07:48:18 -04:00
George Kiagiadakis
7ae4fca46b m-std-event-source: add a "create-event" action
This allows the calling script to also attach event data before
pushing the event on the dispatcher
2023-04-17 07:48:18 -04:00
George Kiagiadakis
f99c3005f2 scripts: rewrite policy-device-profile and m-default-profile into a set of hooks
... excluding the persistent profile functionality for now (I am not convinced)
2023-04-17 07:48:18 -04:00
George Kiagiadakis
ffa85840ac event: move cancelling of events on pw-proxy-destroyed to m-std-event-source
It is really out of place to do this inside WpEvent, as it is not
a generic action. It should only happen for some events.
2023-04-17 07:48:18 -04:00
George Kiagiadakis
3a23fb451a event-dispatcher: refactor to use before/after dependencies on hooks
* Remove entirely the hook priority numbers and use before/after dependencies
* Split the WpEvent code out of WpEventDispatcher
* Add methods on WpEvent to interface with it from the WpEventDispatcher.
  As a bonus, we can now also implement tooling to inspect which hooks would
  in theory run for an event and write tests around that
* Removed some internal debugging facilities and log calls, will redo it later.
* Using spa_list now for the list of hooks, to reduce the number of allocations
  happening in the "hook collection" algorithm
* Switched some internal data to use g_new0 instead of g_slice_new0
* Added g_free to free WpEvent structures... surprisingly, we were leaking them
  before
2023-04-17 07:48:18 -04:00
George Kiagiadakis
b100bdda4a event-hook: remove the exec type property & enumeration
With the latest changes, we can implement the "after-events" type
with external code that pushes a very low priority event that is
the "rescan" event.
2023-04-17 07:48:18 -04:00
George Kiagiadakis
bcb4e80723 m-std-event-source: use type-specific event names and multiple object managers
It is better to have type-specific event names to minimize the amount
of constraint string matches we do on hooks, as most hooks (if not all)
are interested on specific types of objects only.

Similarly, use a different object manager for each object type to
minimize the performance impact of iterations and lookups, as all
such actions are interested in only 1 object type every time.

Port all existing hooks to the new event names and the get-object-manager API.
2023-04-17 07:48:18 -04:00
George Kiagiadakis
374e4ecaff m-standard-event-source: simplify push_event, removing the subject_type
This avoids having to determine the subject type prior to pushing
an event from lua code and makes the call more convenient

Also add a debug statement to trace calls to push_event
2023-04-17 07:48:18 -04:00
George Kiagiadakis
55122b84b4 m-standard-event-source: add "schedule-rescan" action signal
This can be used anywhere else in the codebase to push a "rescan-session"
event, making sure that there is only one such event pushed on the stack,
no matter how many times this is called.
2023-04-17 07:48:18 -04:00
George Kiagiadakis
e2b9cb0b5e m-standard-event-source: export the push_event function as an action signal 2023-04-17 07:48:18 -04:00
George Kiagiadakis
252c5b4935 m-standard-event-source: refactor around a central "push_event" function
Also redo some priorities and rename the object-changed event
to metadata-changed
2023-04-17 07:48:18 -04:00
George Kiagiadakis
79d8c9f5d9 m-standard-event-source: pass self as the event's source object 2023-04-17 07:48:18 -04:00
George Kiagiadakis
ab1668af15 m-standard-event-source: add object-manager property 2023-04-17 07:48:18 -04:00
George Kiagiadakis
b2f2e3f745 m-standard-event-source: add SiLink to the object type & priority list
Just to avoid warnings for now
2023-04-17 07:48:18 -04:00
George Kiagiadakis
48635cb780 m-standard-event-source: manage all kinds of session items in the om
So that we can also work with SiLink objects with this object manager
2023-04-17 07:48:18 -04:00
George Kiagiadakis
c0322cb34f m-standard-event-source: remove the devices object manager
That makes no sense to have. The only script that uses this can easily
be rewriten so that it uses object-added/removed instead.
2023-04-17 07:48:18 -04:00
Ashok Sidipotu
a5a6300662 policy-node.lua: fix the session items unhandling 2023-04-17 07:47:09 -04:00
Ashok Sidipotu
bc2d403396 policy-device-routes.lua: Port to event-stack 2023-04-17 07:47:09 -04:00
Ashok Sidipotu
a6b3f1c1fb m-standard-event-source: fix params of on-params-changed event 2023-04-17 07:47:09 -04:00
Ashok Sidipotu
f5f4acf95d m-standard-event-source: fix metadata changed evnt
Assign type and priority for metadata events
2023-04-17 07:47:09 -04:00
George Kiagiadakis
b62fdd8fef modules: add m-standard-event-source
An event source for standard pipewire events
2023-04-17 07:47:09 -04:00