Commit d02f29d6 authored by Bob Ham's avatar Bob Ham
Browse files

src: Don't call g_error

Instead call a new function, haeg_error, which calls g_log_v with a
level of critical, and then calls exit().
parent c7b836cc
......@@ -23,6 +23,7 @@
*/
#include "haeg-sample-buffer.h"
#include "util.h"
#include <glib/gi18n.h>
#include <gmodule.h>
......@@ -182,8 +183,8 @@ haeg_sample_buffer_read (HaegSampleBuffer *self,
bytes_read = read (self->fd, buf + total, buf_len - total);
if (bytes_read == -1)
{
g_error ("Error reading from TTY port: %s",
g_strerror (errno));
haeg_error ("Error reading from TTY port: %s",
g_strerror (errno));
}
g_debug ("Read %i bytes from TTY port", bytes_read);
......
......@@ -22,6 +22,7 @@
*
*/
#include "util.h"
#include "haeg-sample-buffer.h"
#include <glib.h>
......@@ -80,7 +81,7 @@ set_up_tty (int fd)
err = call ; \
if (err != 0) \
{ \
g_error ("Error " text ": %s", g_strerror (errno)); \
haeg_error ("Error " text ": %s", g_strerror (errno)); \
}
try (tcgetattr (fd, &tty), "getting terminal attributes");
......@@ -112,8 +113,8 @@ set_up_port (struct haegtesse_data *data)
data->port = open (data->port_name, O_RDWR | O_NONBLOCK);
if (data->port == -1)
{
g_error ("Error opening port `%s': %s",
data->port_name, g_strerror (errno));
haeg_error ("Error opening port `%s': %s",
data->port_name, g_strerror (errno));
}
set_up_tty (data->port);
......@@ -121,15 +122,15 @@ set_up_port (struct haegtesse_data *data)
data->port_channel = g_io_channel_unix_new (data->port);
if (!data->port_channel)
{
g_error ("Error opening port `%s': %s",
data->port_name, error->message);
haeg_error ("Error opening port `%s': %s",
data->port_name, error->message);
}
status = g_io_channel_set_encoding (data->port_channel, NULL, &error);
if (status != G_IO_STATUS_NORMAL)
{
g_error ("Error setting port channel to raw encoding: %s",
error->message);
haeg_error ("Error setting port channel to raw encoding: %s",
error->message);
}
g_debug ("TTY port set up");
......@@ -147,8 +148,8 @@ tear_down_port (struct haegtesse_data *data)
err = close (data->port);
if (err == -1)
{
g_error ("Error closing TTY port: %s",
g_strerror (errno));
haeg_error ("Error closing TTY port: %s",
g_strerror (errno));
}
data->port = -1;
......@@ -167,8 +168,8 @@ mic_read_cb (pa_stream *stream, size_t nbytes, struct haegtesse_data *data)
err = pa_stream_peek (data->from_mic, &buf, &nbytes);
if (err < 0)
{
g_error ("Error peeking PulseAudio microphone stream: %s",
pa_strerror (err));
haeg_error ("Error peeking PulseAudio microphone stream: %s",
pa_strerror (err));
}
if (!buf && !nbytes)
......@@ -193,8 +194,8 @@ mic_read_cb (pa_stream *stream, size_t nbytes, struct haegtesse_data *data)
err = pa_stream_drop (data->from_mic);
if (err < 0)
{
g_error ("Error dropping fragment on PulseAudio microphone stream: %s",
pa_strerror (err));
haeg_error ("Error dropping fragment on PulseAudio microphone stream: %s",
pa_strerror (err));
}
}
......@@ -205,8 +206,8 @@ stream_is_corked (pa_stream *stream)
int corked = pa_stream_is_corked (stream);
if (corked < 0)
{
g_error ("Error checking PulseAudio stream for corked state: %s",
pa_strerror (corked));
haeg_error ("Error checking PulseAudio stream for corked state: %s",
pa_strerror (corked));
}
return (gboolean)corked;
......@@ -218,12 +219,12 @@ cork_success_cb (pa_stream *stream, int success, gboolean *successp)
{
if (success < 0)
{
g_error ("Error setting cork of PulseAudio stream: %s",
pa_strerror (pa_context_errno (pa_stream_get_context (stream))));
haeg_error ("Error setting cork of PulseAudio stream: %s",
pa_strerror (pa_context_errno (pa_stream_get_context (stream))));
}
else if (!success)
{
g_error ("No success setting cork of PulseAudio stream");
haeg_error ("No success setting cork of PulseAudio stream");
}
*successp = TRUE;
......@@ -271,12 +272,12 @@ flush_success_cb (pa_stream *stream, int success, struct haegtesse_data *data)
{
if (success < 0)
{
g_error ("Error flushing PulseAudio stream: %s",
pa_strerror (pa_context_errno (data->audio)));
haeg_error ("Error flushing PulseAudio stream: %s",
pa_strerror (pa_context_errno (data->audio)));
}
else if (!success)
{
g_error ("No success flushing PulseAudio stream");
haeg_error ("No success flushing PulseAudio stream");
}
}
......@@ -379,8 +380,8 @@ transfer_spk (struct haegtesse_data *data)
&buf, &buf_size);
if (err < 0)
{
g_error ("Error getting write buffer for PulseAudio speaker stream: %s",
pa_strerror (err));
haeg_error ("Error getting write buffer for PulseAudio speaker stream: %s",
pa_strerror (err));
}
/* Read audio data from the TTY */
......@@ -392,8 +393,8 @@ transfer_spk (struct haegtesse_data *data)
NULL, 0, 0);
if (err < 0)
{
g_error ("Error writing to PulseAudio speaker stream: %s",
pa_strerror (err));
haeg_error ("Error writing to PulseAudio speaker stream: %s",
pa_strerror (err));
}
g_debug ("Wrote %zi bytes to PA speaker stream", (size_t)bytes_read);
......@@ -435,8 +436,8 @@ transfer_mic (struct haegtesse_data *data)
}
else
{
g_error ("Error writing to TTY port: %s",
g_strerror (errno));
haeg_error ("Error writing to TTY port: %s",
g_strerror (errno));
}
}
g_debug ("Wrote %i bytes (of %u) to TTY port from mic buffer of %u bytes",
......@@ -465,7 +466,7 @@ port_read_watch_cb (GIOChannel *source,
case G_IO_ERR:
case G_IO_HUP:
case G_IO_NVAL:
g_error ("Error on TTY port");
haeg_error ("Error on TTY port");
case G_IO_OUT:
return TRUE;
case G_IO_IN:
......@@ -522,8 +523,8 @@ context_notify_cb (pa_context *audio, gboolean *ready)
break;
case PA_CONTEXT_FAILED:
case PA_CONTEXT_TERMINATED:
g_error ("Error in PulseAudio context: %s",
pa_strerror (pa_context_errno (audio)));
haeg_error ("Error in PulseAudio context: %s",
pa_strerror (pa_context_errno (audio)));
case PA_CONTEXT_READY:
*ready = TRUE;
break;
......@@ -542,15 +543,15 @@ set_up_audio_context (struct haegtesse_data *data)
props = pa_proplist_new ();
if (!props)
{
g_error ("Error creating PA property list");
haeg_error ("Error creating PA property list");
}
#define set(key,value) \
err = pa_proplist_sets (props, key, value); \
if (err != 0) \
{ \
g_error ("Error setting PA property list property: %s", \
pa_strerror (err)); \
#define set(key,value) \
err = pa_proplist_sets (props, key, value); \
if (err != 0) \
{ \
haeg_error ("Error setting PA property list property: %s", \
pa_strerror (err)); \
}
set (PA_PROP_APPLICATION_NAME, APPLICATION_NAME);
......@@ -563,14 +564,14 @@ set_up_audio_context (struct haegtesse_data *data)
data->audio_loop = pa_glib_mainloop_new (NULL);
if (!data->audio_loop)
{
g_error ("Error creating PulseAudio main loop");
haeg_error ("Error creating PulseAudio main loop");
}
data->audio = pa_context_new (pa_glib_mainloop_get_api (data->audio_loop),
APPLICATION_NAME);
if (!data->audio)
{
g_error ("Error creating PulseAudio context");
haeg_error ("Error creating PulseAudio context");
}
pa_context_set_state_callback (data->audio,
......@@ -579,8 +580,8 @@ set_up_audio_context (struct haegtesse_data *data)
err = pa_context_connect(data->audio, NULL, PA_CONTEXT_NOFAIL, 0);
if (err < 0)
{
g_error ("Error connecting PulseAudio context: %s",
pa_strerror (err));
haeg_error ("Error connecting PulseAudio context: %s",
pa_strerror (err));
}
while (!ready)
......@@ -605,7 +606,7 @@ stream_notify_cb (pa_stream *stream, gboolean *ready)
break;
case PA_STREAM_FAILED:
case PA_STREAM_TERMINATED:
g_error
haeg_error
("Error in PulseAudio stream: %s",
pa_strerror (pa_context_errno (pa_stream_get_context (stream))));
case PA_STREAM_READY:
......@@ -648,15 +649,15 @@ set_up_audio_streams (struct haegtesse_data *data)
props = pa_proplist_new ();
if (!props)
{
g_error ("Error creating PA property list");
haeg_error ("Error creating PA property list");
}
#define set(key,value) \
err = pa_proplist_sets (props, key, value); \
if (err != 0) \
{ \
g_error ("Error setting PA property list property: %s", \
pa_strerror (err)); \
#define set(key,value) \
err = pa_proplist_sets (props, key, value); \
if (err != 0) \
{ \
haeg_error ("Error setting PA property list property: %s", \
pa_strerror (err)); \
}
set (PA_PROP_MEDIA_ROLE, "phone");
......@@ -674,16 +675,16 @@ set_up_audio_streams (struct haegtesse_data *data)
(data->audio, "To speaker", &sample_spec, NULL, props);
if (!data->to_spk)
{
g_error ("Error creating PulseAudio speaker stream: %s",
pa_strerror (pa_context_errno (data->audio)));
haeg_error ("Error creating PulseAudio speaker stream: %s",
pa_strerror (pa_context_errno (data->audio)));
}
data->from_mic = pa_stream_new_with_proplist
(data->audio, "From microphone", &sample_spec, NULL, props);
if (!data->from_mic)
{
g_error ("Error creating PulseAudio microphone stream: %s",
pa_strerror (pa_context_errno (data->audio)));
haeg_error ("Error creating PulseAudio microphone stream: %s",
pa_strerror (pa_context_errno (data->audio)));
}
pa_proplist_free (props);
......@@ -707,8 +708,8 @@ set_up_audio_streams (struct haegtesse_data *data)
NULL, NULL);
if (err < 0)
{
g_error ("Error connecting PulseAudio speaker stream: %s",
pa_strerror (err));
haeg_error ("Error connecting PulseAudio speaker stream: %s",
pa_strerror (err));
}
memset (&mic_attrs, 0, sizeof (pa_buffer_attr));
......@@ -719,8 +720,8 @@ set_up_audio_streams (struct haegtesse_data *data)
PA_STREAM_START_CORKED);
if (err < 0)
{
g_error ("Error connecting PulseAudio microphone stream: %s",
pa_strerror (err));
haeg_error ("Error connecting PulseAudio microphone stream: %s",
pa_strerror (err));
}
/* Wait for streams to be connected */
......@@ -813,7 +814,7 @@ main (int argc, char **argv)
if (!port_name)
{
g_error ("No port specified");
haeg_error ("No port specified");
}
run (port_name);
......
......@@ -25,7 +25,10 @@ haegtesse_deps = [ dependency('gobject-2.0'),
]
executable('haegtesse',
['main.c', 'haeg-sample-buffer.h', 'haeg-sample-buffer.c'],
['main.c',
'util.h', 'util.c',
'haeg-sample-buffer.h', 'haeg-sample-buffer.c'
],
dependencies : haegtesse_deps,
include_directories : include_directories('..'),
install : true)
/*
* Copyright (C) 2018 Purism SPC
*
* This file is part of Hægtesse.
*
* Hægtesse is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* Hægtesse is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hægtesse. If not, see <http://www.gnu.org/licenses/>.
*
* Author: Bob Ham <bob.ham@puri.sm>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/
#include <glib.h>
#include <stdarg.h>
#include <stdlib.h>
void
haeg_error (const gchar *format, ...)
{
va_list ap;
va_start (ap, format);
g_logv (NULL, G_LOG_LEVEL_CRITICAL, format, ap);
va_end (ap);
exit (EXIT_FAILURE);
}
/*
* Copyright (C) 2018 Purism SPC
*
* This file is part of Hægtesse.
*
* Hægtesse is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* Hægtesse is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hægtesse. If not, see <http://www.gnu.org/licenses/>.
*
* Author: Bob Ham <bob.ham@puri.sm>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/
#ifndef HAEG_UTIL_H__
#define HAEG_UTIL_H__
#include <glib.h>
G_BEGIN_DECLS
void haeg_error (const gchar *format, ...);
G_END_DECLS
#endif /* HAEG_UTIL_H__ */
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