Browse Source

add code to remove metadata for ports and clients when ports and clients are deleted/cleaned up

tags/0.124.0
Paul Davis 12 years ago
parent
commit
70a24bceff
7 changed files with 98 additions and 39 deletions
  1. +1
    -1
      jack
  2. +2
    -2
      jackd/Makefile.am
  3. +11
    -0
      jackd/clientengine.c
  4. +2
    -0
      jackd/clientengine.h
  5. +46
    -30
      jackd/engine.c
  6. +35
    -5
      libjack/metadata.c
  7. +1
    -1
      tools

+ 1
- 1
jack

@@ -1 +1 @@
Subproject commit bec4aa8b94f684c0dd38029e0c7ab91f41e6bfcf
Subproject commit 383c13c50ab517b79cf28bd3e594a9e6e21f5051

+ 2
- 2
jackd/Makefile.am View File

@@ -50,8 +50,8 @@ libjackserver_la_SOURCES = engine.c clientengine.c transengine.c controlapi.c \
../libjack/messagebuffer.c ../libjack/pool.c ../libjack/port.c \
../libjack/midiport.c ../libjack/ringbuffer.c ../libjack/shm.c \
../libjack/thread.c ../libjack/time.c ../libjack/transclient.c \
../libjack/unlock.c ../libjack/uuid.c
libjackserver_la_LIBADD = simd.lo @OS_LDFLAGS@
../libjack/unlock.c ../libjack/uuid.c ../libjack/metadata.c
libjackserver_la_LIBADD = simd.lo -ldb @OS_LDFLAGS@
libjackserver_la_LDFLAGS = -export-dynamic -version-info @JACK_SO_VERSION@

simd.lo: $(srcdir)/../libjack/simd.c


+ 11
- 0
jackd/clientengine.c View File

@@ -42,6 +42,7 @@
#include "transengine.h"

#include <jack/uuid.h>
#include <jack/metadata.h>

#include "libjack/local.h"

@@ -51,6 +52,7 @@ jack_client_disconnect_ports (jack_engine_t *engine,
{
JSList *node;
jack_port_internal_t *port;
char buf[JACK_UUID_STRING_SIZE];

/* call tree **** MUST HOLD *** engine->client_lock */

@@ -1061,8 +1063,17 @@ jack_mark_client_socket_error (jack_engine_t *engine, int fd)
void
jack_client_delete (jack_engine_t *engine, jack_client_internal_t *client)
{
jack_uuid_t uuid;
jack_uuid_copy (uuid, client->control->uuid);

jack_client_registration_notify (engine, (const char*) client->control->name, 0);

jack_remove_properties (NULL, uuid);
/* have to do the notification ourselves, since the client argument
to jack_remove_properties() was NULL
*/
jack_property_change_notify (engine, PropertyDeleted, uuid, NULL);

if (jack_client_is_internal (client)) {

free (client->private_client);


+ 2
- 0
jackd/clientengine.h View File

@@ -62,4 +62,6 @@ int jack_check_clients (jack_engine_t* engine, int with_timeout_check);
void jack_remove_clients (jack_engine_t* engine, int* exit_freewheeling);
void jack_client_registration_notify (jack_engine_t *engine,
const char* name, int yn);
void jack_property_change_notify (jack_engine_t *engine, jack_property_change_t change, jack_uuid_t uuid, const char* key);

void jack_remove_client (jack_engine_t *engine, jack_client_internal_t *client);

+ 46
- 30
jackd/engine.c View File

@@ -41,6 +41,7 @@

#include <jack/thread.h>
#include <jack/uuid.h>
#include <jack/metadata.h>

#include "internal.h"
#include "engine.h"
@@ -141,7 +142,6 @@ static void jack_do_reserve_name (jack_engine_t *engine, jack_request_t *req);
static void jack_do_session_reply (jack_engine_t *engine, jack_request_t *req );
static void jack_compute_new_latency (jack_engine_t *engine);
static int jack_do_has_session_cb (jack_engine_t *engine, jack_request_t *req);
static void jack_property_change_notify (jack_engine_t *engine, jack_property_change_t change, jack_uuid_t uuid, const char* key);

static inline int
jack_rolling_interval (jack_time_t period_usecs)
@@ -4275,6 +4275,16 @@ jack_get_free_port (jack_engine_t *engine)
void
jack_port_release (jack_engine_t *engine, jack_port_internal_t *port)
{
char buf[JACK_UUID_STRING_SIZE];
jack_uuid_unparse (port->shared->uuid, buf);
if (jack_remove_properties (NULL, port->shared->uuid) > 0) {
/* have to do the notification ourselves, since the client argument
to jack_remove_properties() was NULL
*/
jack_property_change_notify (engine, PropertyDeleted, port->shared->uuid, NULL);
}


pthread_mutex_lock (&engine->port_lock);
port->shared->in_use = 0;
port->shared->alias1[0] = '\0';
@@ -4452,6 +4462,7 @@ jack_port_do_unregister (jack_engine_t *engine, jack_request_t *req)
jack_client_internal_t *client;
jack_port_shared_t *shared;
jack_port_internal_t *port;
jack_uuid_t uuid;

if (req->x.port_info.port_id < 0 ||
req->x.port_info.port_id > engine->port_max) {
@@ -4471,6 +4482,8 @@ jack_port_do_unregister (jack_engine_t *engine, jack_request_t *req)
return -1;
}

jack_uuid_copy (uuid, shared->uuid);

jack_lock_graph (engine);
if ((client = jack_client_internal_by_id (engine, shared->client_id))
== NULL) {
@@ -4482,8 +4495,7 @@ jack_port_do_unregister (jack_engine_t *engine, jack_request_t *req)
port = &engine->internal_ports[req->x.port_info.port_id];

jack_port_clear_connections (engine, port);
jack_port_release (engine,
&engine->internal_ports[req->x.port_info.port_id]);
jack_port_release (engine, &engine->internal_ports[req->x.port_info.port_id]);
client->ports = jack_slist_remove (client->ports, port);
jack_port_registration_notify (engine, req->x.port_info.port_id,
@@ -4621,20 +4633,16 @@ jack_port_registration_notify (jack_engine_t *engine,
}

void
jack_property_change_notify (jack_engine_t *engine,
jack_property_change_t change,
jack_uuid_t uuid,
const char* key)
jack_client_registration_notify (jack_engine_t *engine,
const char* name, int yn)
{
jack_event_t event;
jack_client_internal_t *client;
JSList *node;

event.type = PropertyChange;
event.z.property_change = change;
jack_uuid_copy (event.x.uuid, uuid);
event.y.key_size = strlen (key) + 1;

event.type = (yn ? ClientRegistered : ClientUnregistered);
snprintf (event.x.name, sizeof (event.x.name), "%s", name);
for (node = engine->clients; node; node = jack_slist_next (node)) {
client = (jack_client_internal_t *) node->data;
@@ -4643,9 +4651,14 @@ jack_property_change_notify (jack_engine_t *engine,
continue;
}

if (client->control->port_register_cbset) {
if (jack_deliver_event (engine, client, &event, key)) {
jack_error ("cannot send port registration"
if (strcmp ((char*) client->control->name, (char*) name) == 0) {
/* do not notify client of its own registration */
continue;
}

if (client->control->client_register_cbset) {
if (jack_deliver_event (engine, client, &event)) {
jack_error ("cannot send client registration"
" notification to %s (%s)",
client->control->name,
strerror (errno));
@@ -4655,16 +4668,25 @@ jack_property_change_notify (jack_engine_t *engine,
}

void
jack_client_registration_notify (jack_engine_t *engine,
const char* name, int yn)
jack_property_change_notify (jack_engine_t *engine,
jack_property_change_t change,
jack_uuid_t uuid,
const char* key)
{
jack_event_t event;
jack_client_internal_t *client;
JSList *node;

event.type = (yn ? ClientRegistered : ClientUnregistered);
snprintf (event.x.name, sizeof (event.x.name), "%s", name);
event.type = PropertyChange;
event.z.property_change = change;
jack_uuid_copy (event.x.uuid, uuid);

if (key) {
event.y.key_size = strlen (key) + 1;
} else {
event.y.key_size = 0;
}

for (node = engine->clients; node; node = jack_slist_next (node)) {
client = (jack_client_internal_t *) node->data;
@@ -4673,16 +4695,10 @@ jack_client_registration_notify (jack_engine_t *engine,
continue;
}

if (strcmp ((char*) client->control->name, (char*) name) == 0) {
/* do not notify client of its own registration */
continue;
}

if (client->control->client_register_cbset) {
if (jack_deliver_event (engine, client, &event)) {
jack_error ("cannot send client registration"
" notification to %s (%s)",
client->control->name,
if (client->control->property_cbset) {
if (jack_deliver_event (engine, client, &event, key)) {
jack_error ("cannot send property change notification to %s (%s)",
client->control->name,
strerror (errno));
}
}


+ 35
- 5
libjack/metadata.c View File

@@ -27,6 +27,7 @@
#include "local.h"

static DB* db = NULL;
static DB_ENV* db_env = NULL;

static int
jack_property_init (const char* server_name)
@@ -37,11 +38,21 @@ jack_property_init (const char* server_name)

/* idempotent */

if (db) {
if (db_env) {
return 0;
}

if ((ret = db_create (&db, NULL, 0)) != 0) {
if ((ret = db_env_create(&db_env, 0)) != 0) {
jack_error ("cannot initialize DB environment: %s\n", db_strerror(ret));
return -1;
}
if ((ret = db_env->open(db_env, jack_server_dir (server_name, server_dir), DB_CREATE | DB_INIT_LOCK | DB_INIT_MPOOL | DB_THREAD, 0)) != 0) {
jack_error ("cannot open DB environment: %s", db_strerror (ret));
return -1;
}

if ((ret = db_create (&db, db_env, 0)) != 0) {
jack_error ("Cannot initialize metadata DB (%s)", db_strerror (ret));
return -1;
}
@@ -67,6 +78,10 @@ jack_properties_uninit ()
db->close (db, 0);
db = NULL;
}
if (db_env) {
db_env->close (db_env, 0);
db_env = 0;
}
}

void
@@ -93,6 +108,14 @@ static int
jack_property_change_notify (jack_client_t* client, jack_uuid_t uuid, const char* key, jack_property_change_t change)
{
jack_request_t req;

/* the engine passes in a NULL client when it removes metadata during port or client removal
*/

if (client == NULL) {
return 0;
}

req.type = PropertyChangeNotify;
req.x.property.change = change;
jack_uuid_copy (req.x.property.uuid, uuid);
@@ -562,6 +585,7 @@ jack_remove_properties (jack_client_t* client, jack_uuid_t subject)
int ret;
char ustr[JACK_UUID_STRING_SIZE];
int retval = 0;
uint32_t cnt = 0;

jack_uuid_unparse (subject, ustr);

@@ -569,7 +593,6 @@ jack_remove_properties (jack_client_t* client, jack_uuid_t subject)
return -1;
}


if ((ret = db->cursor (db, NULL, &cursor, 0)) != 0) {
jack_error ("Cannot create cursor for metadata search (%s)", db_strerror (ret));
return -1;
@@ -607,13 +630,20 @@ jack_remove_properties (jack_client_t* client, jack_uuid_t subject)
*/
retval = -1;
}
cnt++;
}

cursor->close (cursor);

jack_property_change_notify (client, subject, NULL, PropertyDeleted);
if (cnt) {
jack_property_change_notify (client, subject, NULL, PropertyDeleted);
}

if (retval) {
return -1;
}

return retval;
return cnt;
}

int


+ 1
- 1
tools

@@ -1 +1 @@
Subproject commit 6ac302ba8664e20c6c03d6da7fa8adeb7949925f
Subproject commit 0c64f246bdeef806e2938e3435a641bd4b716fe8

Loading…
Cancel
Save