Commit 4985d4fa authored by Hanspeter Portner's avatar Hanspeter Portner

improve failure handling in OSC initialization.

parent ccb9b77d
Pipeline #63124199 passed with stages
in 2 minutes and 18 seconds
......@@ -293,6 +293,50 @@ _ftdi_deinit(app_t *app)
ftdi_deinit(&app->ftdi);
}
static void
_osc_deinit(app_t *app)
{
lv2_osc_stream_deinit(&app->stream);
if(app->rb.rx)
{
varchunk_free(app->rb.rx);
}
if(app->rb.tx)
{
varchunk_free(app->rb.tx);
}
}
static int
_osc_init(app_t *app)
{
app->rb.rx = varchunk_new(8192, false);
if(!app->rb.rx)
{
goto failure;
}
app->rb.tx = varchunk_new(8192, false);
if(!app->rb.tx)
{
goto failure;
}
if(lv2_osc_stream_init(&app->stream, app->url, &driver, app) != 0)
{
fprintf(stderr, "[%s] '%s'\n", __func__, strerror(errno));
goto failure;
}
return 0;
failure:
_osc_deinit(app);
return -1;
}
static void
_version(void)
{
......@@ -424,34 +468,22 @@ main(int argc __attribute__((unused)), char **argv __attribute__((unused)))
if(sem_init(&sem, 0, 0) == -1)
{
goto failure;
}
app.rb.rx = varchunk_new(8192, false);
if(!app.rb.rx)
{
sem_destroy(&sem);
goto failure;
return -1;
}
app.rb.tx = varchunk_new(8192, false);
if(!app.rb.tx)
if(_osc_init(&app) == -1)
{
varchunk_free(app.rb.rx);
sem_destroy(&sem);
goto failure;
return -1;
}
if(_ftdi_init(&app) == -1)
{
varchunk_free(app.rb.tx);
varchunk_free(app.rb.rx);
_osc_deinit(&app);
sem_destroy(&sem);
goto failure;
return -1;
}
lv2_osc_stream_init(&app.stream, "osc.udp://:6666", &driver, &app);
struct timespec t0;
clock_gettime(CLOCK_REALTIME, &t0);
struct timespec t1 = t0;
......@@ -506,17 +538,9 @@ main(int argc __attribute__((unused)), char **argv __attribute__((unused)))
t0 = t1;
}
sem_destroy(&sem);
lv2_osc_stream_deinit(&app.stream);
_ftdi_deinit(&app);
varchunk_free(app.rb.rx);
varchunk_free(app.rb.tx);
_osc_deinit(&app);
sem_destroy(&sem);
return 0;
failure:
return -1;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment