block context_connect for session.services

This commit is contained in:
Anthony Ilersich 2022-10-11 18:37:34 -04:00
parent 6e8d8b67ec
commit ead3a99fd9
2 changed files with 37 additions and 0 deletions

View file

@ -28,6 +28,7 @@
#include <sys/un.h>
#include <errno.h>
#include <sys/mman.h>
#include <pthread.h>
#include <spa/pod/parser.h>
#include <spa/debug/types.h>
@ -36,10 +37,14 @@
#include "pipewire/private.h"
#include "pipewire/extensions/protocol-native.h"
#include "pipewire/extensions/session-manager/keys.h"
PW_LOG_TOPIC_EXTERN(log_core);
#define PW_LOG_TOPIC_DEFAULT log_core
static pthread_mutex_t service_added_lock = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t service_added_cv = PTHREAD_COND_INITIALIZER;
static void core_event_ping(void *data, uint32_t id, int seq)
{
struct pw_core *this = data;
@ -397,18 +402,46 @@ exit_cleanup:
return NULL;
}
SPA_EXPORT
void
pw_context_add_service(struct pw_context *context, const char *service)
{
struct pw_properties *props = pw_context_get_properties (context);
const char* old_services = pw_properties_get(props, PW_KEY_SESSION_SERVICES);
// TODO: avoid adding duplicates
pw_properties_setf(props, PW_KEY_SESSION_SERVICES, "%s test", old_services);
pw_log_error("ADDED SERVICE!");
pw_log_error("session.services: %s", pw_properties_get(props, PW_KEY_SESSION_SERVICES));
pthread_mutex_lock(&service_added_lock);
pthread_cond_signal(&service_added_cv);
pthread_mutex_unlock(&service_added_lock);
}
SPA_EXPORT
struct pw_core *
pw_context_connect(struct pw_context *context, struct pw_properties *properties,
size_t user_data_size)
{
struct pw_core *core;
const struct spa_dict_item *session_services;
int res;
core = core_new(context, properties, user_data_size);
if (core == NULL)
return NULL;
session_services = spa_dict_lookup_item(&core->properties->dict, PW_KEY_SESSION_SERVICES);
// if the property is present and empty, context creation blocks until services are added
if (session_services != NULL && !strcmp(session_services->value, ""))
{
pw_log_error("pw_context_connect is waiting for session.services to be populated");
pthread_mutex_lock(&service_added_lock);
pthread_cond_wait(&service_added_cv, &service_added_lock);
pthread_mutex_unlock(&service_added_lock);
pw_log_error("pw_context_connect is resuming");
pw_log_error("session.services: %s", session_services->value);
}
pw_log_debug("%p: connect", core);
if ((res = pw_protocol_client_connect(core->conn,

View file

@ -531,6 +531,10 @@ pw_registry_bind(struct pw_registry *registry,
* \{
*/
void
pw_context_add_service(struct pw_context *context,
const char *service);
/** Connect to a PipeWire instance
*
* \param context a \ref pw_context