Files
wireplumber/lib/wp/policy.h
George Kiagiadakis e7e5c66853 lib: introduce WpObjectManager
* rework how global objects are stored in the core
* rework how users get notified about global objects
  and proxies of remote global objects

The purpose of this change is to have a class that can manage
objects that are registered in the core or signalled through the
registry. This object can declare interest on certain types
of global objects and only keep & signal those objects that it is
interested in. Additionally, it can prepare proxy features and
asynchronously deliver an 'objects-changed' signal, which is
basically telling us that the list of objects has changed.

This is useful to simplify port proxies management in WpAudioStream.
Now the stream object can declare that it is interested in ports
that have "node.id" == X and the object manager will only maintain
a list of those. Additionally, it will emit the 'objects-changed'
signal when the list of ports is complete, so there is no reason to
do complex operations and core syncs in the WpAudioStream class
in order to figure out when the list of ports is ready.

As a side effect, this also reduces resource management. Now we
don't construct a WpProxy for every global that pipewire reports;
we only construct proxies when there is interest in them!

Another interesting side effect is that we can now register an
object manager at any point in time and get immediately notified
about remote globals that already exist. i.e. when you register
an object manager that is interested in nodes, it will be immediately
notified about all the existing nodes in the graph. This is useful
to avoid race conditions between connecting the signal and objects
beting created in pipewire
2019-11-13 15:49:39 +02:00

73 lines
2.2 KiB
C

/* WirePlumber
*
* Copyright © 2019 Collabora Ltd.
* @author George Kiagiadakis <george.kiagiadakis@collabora.com>
*
* SPDX-License-Identifier: MIT
*/
#ifndef __WIREPLUMBER_POLICY_H__
#define __WIREPLUMBER_POLICY_H__
#include "endpoint.h"
G_BEGIN_DECLS
/**
* WpPolicyRank:
* @WP_POLICY_RANK_UPSTREAM: should only be used inside WirePlumber
* @WP_POLICY_RANK_PLATFORM: policies provided by the platform
* @WP_POLICY_RANK_VENDOR: policies provided by hardware vendors
*
* The rank of a policy is an unsigned integer that can take an arbitrary
* value from 0 to G_MAXINT32 (0x7fffffff). On invocation, policies ranked
* with a higher number are tried first, which is how one can implement
* overrides. This enum provides default values for certain kinds of policies.
* Feel free to add/substract numbers to these constants in order to make a
* hierarchy, if you are implementing multiple different policies that need to
* be tried in a certain order.
*/
typedef enum {
WP_POLICY_RANK_UPSTREAM = 1,
WP_POLICY_RANK_PLATFORM = 128,
WP_POLICY_RANK_VENDOR = 256,
} WpPolicyRank;
#define WP_TYPE_POLICY_MANAGER (wp_policy_manager_get_type ())
G_DECLARE_FINAL_TYPE (WpPolicyManager, wp_policy_manager, WP, POLICY_MANAGER, GObject)
#define WP_TYPE_POLICY (wp_policy_get_type ())
G_DECLARE_DERIVABLE_TYPE (WpPolicy, wp_policy, WP, POLICY, GObject)
struct _WpPolicyClass
{
GObjectClass parent_class;
void (*endpoint_added) (WpPolicy *self, WpEndpoint *ep);
void (*endpoint_removed) (WpPolicy *self, WpEndpoint *ep);
gboolean (*handle_endpoint) (WpPolicy *self, WpEndpoint *ep);
WpEndpoint * (*find_endpoint) (WpPolicy *self, GVariant *props,
guint32 *stream_id);
};
WpPolicyManager * wp_policy_manager_get_instance (WpCore *core);
GPtrArray * wp_policy_manager_list_endpoints (WpPolicyManager * self,
const gchar * media_class);
guint32 wp_policy_get_rank (WpPolicy *self);
WpCore *wp_policy_get_core (WpPolicy *self);
void wp_policy_register (WpPolicy *self, WpCore *core);
void wp_policy_unregister (WpPolicy *self);
void wp_policy_notify_changed (WpPolicy *self);
WpEndpoint * wp_policy_find_endpoint (WpCore *core, GVariant *props,
guint32 *stream_id);
G_END_DECLS
#endif