Browse Source

Unify jack_client_open(), add error_handler

- Use jack_set_error_function() (currently no-op)

In the case of clients that use jack_options_t JackNoStartServer,
running it with no server started produces verbose output in the form:

```
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JACK server not running?
```

Setting a no-op error handler before trying jack_client_open()
will hide these messages.

Checking the status allows to output a user-friendly error message.

The first string is generic for any fail of jack_client_open()

`Error: cannot connect to JACK, `
Most importantly it informs the user that there is an error.

Depending on status the string is extended with either
`server is not running.`
or
`jack_client_open() failed, status =...`
if the status indicates anything else than JackServerFailed.

Running jack_lsp or jack_connect with no server running outputs (new)
`
Error: cannot connect to JACK, server is not running.
`

More aspects of example_clients/* can be reviewed for unification.
Some do ask:
`JACK server not running?`
Others tell
`JACK server not running.`

If this commit won't show deficits: jack_client_open() sections can be
changed in all example_clients accordingly.

Note: obviously the --version option is currently a NO-OP in many client programs. This needs a closer look.
tags/v1.9.13
Thomas Brand 6 years ago
parent
commit
bccbc38b84
2 changed files with 24 additions and 6 deletions
  1. +13
    -1
      example-clients/connect.c
  2. +11
    -5
      example-clients/lsp.c

+ 13
- 1
example-clients/connect.c View File

@@ -40,6 +40,11 @@ void port_connect_callback(jack_port_id_t a, jack_port_id_t b, int connect, void
done = 1;
}

void error_callback (const char *err)
{
//fprintf (stderr, "%s\n", err);
}

void
show_version (char *my_name)
{
@@ -133,10 +138,17 @@ main (int argc, char *argv[])
return 1;
}

jack_set_error_function(error_callback);

/* try to become a client of the JACK server */

if ((client = jack_client_open (my_name, options, &status, server_name)) == 0) {
fprintf (stderr, "JACK server not running?\n");
fprintf (stderr, "Error: cannot connect to JACK, ");
if (status & JackServerFailed) {
fprintf (stderr, "server is not running.\n");
} else {
fprintf (stderr, "jack_client_open() failed, status = 0x%2.0x\n", status);
}
return 1;
}



+ 11
- 5
example-clients/lsp.c View File

@@ -26,6 +26,11 @@

char * my_name;

void error_callback (const char *err)
{
//fprintf (stderr, "%s\n", err);
}

static void
show_version (void)
{
@@ -136,18 +141,19 @@ main (int argc, char *argv[])
}
}

jack_set_error_function(error_callback);

/* Open a client connection to the JACK server. Starting a
* new server only to list its ports seems pointless, so we
* specify JackNoStartServer. */
//JOQ: need a new server name option

client = jack_client_open ("lsp", options, &status, server_name);
if (client == NULL) {
if ((client = jack_client_open ("lsp", options, &status, server_name)) == 0) {
fprintf (stderr, "Error: cannot connect to JACK, ");
if (status & JackServerFailed) {
fprintf (stderr, "JACK server not running\n");
fprintf (stderr, "server is not running.\n");
} else {
fprintf (stderr, "jack_client_open() failed, "
"status = 0x%2.0x\n", status);
fprintf (stderr, "jack_client_open() failed, status = 0x%2.0x\n", status);
}
return 1;
}


Loading…
Cancel
Save