aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVadim Yanitskiy <axilirator@gmail.com>2017-09-07 16:36:56 +0300
committerVadim Yanitskiy <axilirator@gmail.com>2017-12-31 12:20:59 +0100
commitc35ba8a725405f7712618871c56a3b7fb3933e2a (patch)
tree5150376f41c14f847cd0a09c31778cdf4af06ffc /src
parentf8d91a07b45a618fd25c9d6edcf28218642044c9 (diff)
libosmogapk: use Osmocom logging framework
Since this change, the libosmogapk uses the Osmocom logging framework. By default, logging is disabled and could be enabled by the external applications calling the osmo_gapk_log_init() with a desired log target as an argument.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am5
-rw-r--r--src/app_osmo_gapk.c28
-rw-r--r--src/libosmogapk.map2
-rw-r--r--src/logging.c27
-rw-r--r--src/pq_alsa.c9
-rw-r--r--src/pq_codec.c3
-rw-r--r--src/pq_file.c5
-rw-r--r--src/pq_format.c12
-rw-r--r--src/pq_rtp.c8
-rw-r--r--src/procqueue.c7
10 files changed, 89 insertions, 17 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 2c52ec1..060d435 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -76,6 +76,11 @@ libosmogapk_la_SOURCES += \
benchmark.c \
$(NULL)
+# Logging
+libosmogapk_la_SOURCES += \
+ logging.c \
+ $(NULL)
+
# libosmogapk representative application
bin_PROGRAMS = osmo-gapk
diff --git a/src/app_osmo_gapk.c b/src/app_osmo_gapk.c
index 90779af..926f3ba 100644
--- a/src/app_osmo_gapk.c
+++ b/src/app_osmo_gapk.c
@@ -31,8 +31,12 @@
#include <sys/socket.h>
#include <netinet/in.h>
+#include <osmocom/core/application.h>
+#include <osmocom/core/logging.h>
#include <osmocom/core/socket.h>
+#include <osmocom/core/utils.h>
+#include <osmocom/gapk/common.h>
#include <osmocom/gapk/codecs.h>
#include <osmocom/gapk/formats.h>
#include <osmocom/gapk/procqueue.h>
@@ -85,6 +89,25 @@ struct gapk_state
} out;
};
+/* Logging related routines */
+enum {
+ DAPP,
+};
+
+static struct log_info_cat gapk_log_info_cat[] = {
+ [DAPP] = {
+ .name = "DAPP",
+ .description = "Application",
+ .color = "\033[0;36m",
+ .enabled = 1, .loglevel = LOGL_DEBUG,
+ },
+};
+
+static const struct log_info gapk_log_info = {
+ .cat = gapk_log_info_cat,
+ .num_cat = ARRAY_SIZE(gapk_log_info_cat),
+};
+
static void
print_help(char *progname)
@@ -620,6 +643,11 @@ int main(int argc, char *argv[])
{
int rv;
+ /* Init Osmocom logging framework */
+ osmo_init_logging(&gapk_log_info);
+ /* and GAPK logging wrapper */
+ osmo_gapk_log_init(DAPP);
+
/* Clear state */
memset(gs, 0x00, sizeof(struct gapk_state));
gs->in.rtp.fd = -1;
diff --git a/src/libosmogapk.map b/src/libosmogapk.map
index 0ab0669..d8b8af3 100644
--- a/src/libosmogapk.map
+++ b/src/libosmogapk.map
@@ -1,6 +1,8 @@
LIBOSMOGAPK_1.0 {
global:
+osmo_gapk_log_init;
+
osmo_gapk_pq;
osmo_gapk_pq_item;
diff --git a/src/logging.c b/src/logging.c
new file mode 100644
index 0000000..96313ae
--- /dev/null
+++ b/src/logging.c
@@ -0,0 +1,27 @@
+/*
+ * This file is part of gapk (GSM Audio Pocket Knife).
+ *
+ * (C) 2017 by Vadim Yanitskiy <axilirator@gmail.com>
+ *
+ * gapk 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.
+ *
+ * gapk 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 gapk. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+int osmo_gapk_log_init_complete = 0;
+int osmo_gapk_log_subsys;
+
+void osmo_gapk_log_init(int subsys)
+{
+ osmo_gapk_log_subsys = subsys;
+ osmo_gapk_log_init_complete = 1;
+}
diff --git a/src/pq_alsa.c b/src/pq_alsa.c
index d280de6..b91457e 100644
--- a/src/pq_alsa.c
+++ b/src/pq_alsa.c
@@ -23,6 +23,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <osmocom/gapk/logging.h>
#include <osmocom/gapk/codecs.h>
#include <osmocom/gapk/formats.h>
#include <osmocom/gapk/procqueue.h>
@@ -147,7 +148,7 @@ out_close:
snd_pcm_close(state->pcm_handle);
free(state);
out_print:
- fprintf(stderr, "[!] Couldn't init ALSA device '%s': %s\n",
+ LOGPGAPK(LOGL_ERROR, "Couldn't init ALSA device '%s': %s\n",
alsa_dev, snd_strerror(rc));
return rc;
}
@@ -162,7 +163,8 @@ out_print:
int
osmo_gapk_pq_queue_alsa_input(struct osmo_gapk_pq *pq, const char *hwdev, unsigned int blk_len)
{
- fprintf(stderr, "[+] PQ: Adding ALSA input (dev='%s', blk_len=%u)\n", hwdev, blk_len);
+ LOGPGAPK(LOGL_DEBUG, "PQ: Adding ALSA input "
+ "(dev='%s', blk_len=%u)\n", hwdev, blk_len);
return pq_queue_alsa_op(pq, hwdev, blk_len, 1);
}
@@ -175,7 +177,8 @@ osmo_gapk_pq_queue_alsa_input(struct osmo_gapk_pq *pq, const char *hwdev, unsign
int
osmo_gapk_pq_queue_alsa_output(struct osmo_gapk_pq *pq, const char *hwdev, unsigned int blk_len)
{
- fprintf(stderr, "[+] PQ: Adding ALSA output (dev='%s', blk_len=%u)\n", hwdev, blk_len);
+ LOGPGAPK(LOGL_DEBUG, "PQ: Adding ALSA output "
+ "(dev='%s', blk_len=%u)\n", hwdev, blk_len);
return pq_queue_alsa_op(pq, hwdev, blk_len, 0);
}
diff --git a/src/pq_codec.c b/src/pq_codec.c
index 37fa1c9..f5da628 100644
--- a/src/pq_codec.c
+++ b/src/pq_codec.c
@@ -20,6 +20,7 @@
#include <errno.h>
#include <stdint.h>
+#include <osmocom/gapk/logging.h>
#include <osmocom/gapk/codecs.h>
#include <osmocom/gapk/formats.h>
#include <osmocom/gapk/procqueue.h>
@@ -71,7 +72,7 @@ osmo_gapk_pq_queue_codec(struct osmo_gapk_pq *pq, const struct osmo_gapk_codec_d
item->exit = codec->codec_exit;
- fprintf(stderr, "[+] PQ: Adding Codec %s, %s format %s\n", codec->name,
+ LOGPGAPK(LOGL_DEBUG, "PQ: Adding codec %s, %s format %s\n", codec->name,
enc_dec_n ? "encoding to" : "decoding from", fmt->name);
if (!item->proc)
diff --git a/src/pq_file.c b/src/pq_file.c
index 2d0a6b0..b31ef52 100644
--- a/src/pq_file.c
+++ b/src/pq_file.c
@@ -22,6 +22,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <osmocom/gapk/logging.h>
#include <osmocom/gapk/codecs.h>
#include <osmocom/gapk/formats.h>
#include <osmocom/gapk/procqueue.h>
@@ -97,7 +98,7 @@ pq_queue_file_op(struct osmo_gapk_pq *pq, FILE *fh, unsigned int blk_len, int in
int
osmo_gapk_pq_queue_file_input(struct osmo_gapk_pq *pq, FILE *src, unsigned int blk_len)
{
- fprintf(stderr, "[+] PQ: Adding file input (blk_len=%u)\n", blk_len);
+ LOGPGAPK(LOGL_DEBUG, "PQ: Adding file input (blk_len=%u)\n", blk_len);
return pq_queue_file_op(pq, src, blk_len, 1);
}
@@ -110,6 +111,6 @@ osmo_gapk_pq_queue_file_input(struct osmo_gapk_pq *pq, FILE *src, unsigned int b
int
osmo_gapk_pq_queue_file_output(struct osmo_gapk_pq *pq, FILE *dst, unsigned int blk_len)
{
- fprintf(stderr, "[+] PQ: Adding file output (blk_len=%u)\n", blk_len);
+ LOGPGAPK(LOGL_DEBUG, "PQ: Adding file output (blk_len=%u)\n", blk_len);
return pq_queue_file_op(pq, dst, blk_len, 0);
}
diff --git a/src/pq_format.c b/src/pq_format.c
index 08860a3..ae5386e 100644
--- a/src/pq_format.c
+++ b/src/pq_format.c
@@ -20,6 +20,7 @@
#include <errno.h>
#include <stdint.h>
+#include <osmocom/gapk/logging.h>
#include <osmocom/gapk/codecs.h>
#include <osmocom/gapk/formats.h>
#include <osmocom/gapk/procqueue.h>
@@ -44,7 +45,8 @@ osmo_gapk_pq_queue_fmt_convert(struct osmo_gapk_pq *pq, const struct osmo_gapk_f
codec = osmo_gapk_codec_get_from_type(fmt->codec_type);
if (!codec) {
- fprintf(stderr, "[!] Cannot determine codec from format %s\n", fmt->name);
+ LOGPGAPK(LOGL_ERROR, "Cannot determine codec from "
+ "format %s\n", fmt->name);
return -EINVAL;
}
@@ -54,14 +56,14 @@ osmo_gapk_pq_queue_fmt_convert(struct osmo_gapk_pq *pq, const struct osmo_gapk_f
return -ENOMEM;
if (to_from_n) {
- fprintf(stderr, "[+] PQ: Adding conversion from canon to %s (for codec %s)\n",
- fmt->name, codec->name);
+ LOGPGAPK(LOGL_DEBUG, "PQ: Adding conversion from canon "
+ "to %s (for codec %s)\n", fmt->name, codec->name);
item->len_in = codec->canon_frame_len;
item->len_out = fmt->frame_len;
item->state = fmt->conv_from_canon;
} else {
- fprintf(stderr, "[+] PQ: Adding conversion from %s to canon (for codec %s)\n",
- fmt->name, codec->name);
+ LOGPGAPK(LOGL_DEBUG, "PQ: Adding conversion from %s "
+ "to canon (for codec %s)\n", fmt->name, codec->name);
item->len_in = fmt->frame_len;
item->len_out = codec->canon_frame_len;
item->state = fmt->conv_to_canon;
diff --git a/src/pq_rtp.c b/src/pq_rtp.c
index b68e84a..6e7a87d 100644
--- a/src/pq_rtp.c
+++ b/src/pq_rtp.c
@@ -27,6 +27,7 @@
#include <arpa/inet.h>
+#include <osmocom/gapk/logging.h>
#include <osmocom/gapk/codecs.h>
#include <osmocom/gapk/formats.h>
#include <osmocom/gapk/procqueue.h>
@@ -86,7 +87,8 @@ struct pq_state_rtp {
uint32_t ssrc;
};
-#define rtp_err(x, args...) fprintf(stderr, "[!] %s():" x, __func__, ## args)
+#define rtp_err(err_msg, args...) \
+ LOGPGAPK(LOGL_ERROR, "%s():" err_msg, __func__, ## args)
static int
pq_cb_rtp_input(void *_state, uint8_t *out, const uint8_t *in, unsigned int in_len)
@@ -241,7 +243,7 @@ pq_queue_rtp_op(struct osmo_gapk_pq *pq, int udp_fd, unsigned int blk_len, int i
int
osmo_gapk_pq_queue_rtp_input(struct osmo_gapk_pq *pq, int udp_fd, unsigned int blk_len)
{
- fprintf(stderr, "[+] PQ: Adding RTP input (blk_len=%u)\n", blk_len);
+ LOGPGAPK(LOGL_DEBUG, "PQ: Adding RTP input (blk_len=%u)\n", blk_len);
return pq_queue_rtp_op(pq, udp_fd, blk_len, 1);
}
@@ -253,6 +255,6 @@ osmo_gapk_pq_queue_rtp_input(struct osmo_gapk_pq *pq, int udp_fd, unsigned int b
int
osmo_gapk_pq_queue_rtp_output(struct osmo_gapk_pq *pq, int udp_fd, unsigned int blk_len)
{
- fprintf(stderr, "[+] PQ: Adding RTP output (blk_len=%u)\n", blk_len);
+ LOGPGAPK(LOGL_DEBUG, "PQ: Adding RTP output (blk_len=%u)\n", blk_len);
return pq_queue_rtp_op(pq, udp_fd, blk_len, 0);
}
diff --git a/src/procqueue.c b/src/procqueue.c
index 00472d3..ffd3f6d 100644
--- a/src/procqueue.c
+++ b/src/procqueue.c
@@ -24,6 +24,7 @@
#include <osmocom/core/linuxlist.h>
#include <osmocom/gapk/procqueue.h>
+#include <osmocom/gapk/logging.h>
/* crate a new (empty) processing queue */
struct osmo_gapk_pq *
@@ -102,7 +103,7 @@ osmo_gapk_pq_prepare(struct osmo_gapk_pq *pq)
llist_for_each_entry(item, &pq->items, list) {
/* Make sure I/O data lengths are equal */
if (item->len_in && item->len_in != len_prev) {
- fprintf(stderr, "[!] PQ item requires input size %u, "
+ LOGPGAPK(LOGL_ERROR, "PQ item requires input size %u, "
"but previous output is %u\n", item->len_in, len_prev);
return -EINVAL;
}
@@ -151,8 +152,8 @@ osmo_gapk_pq_execute(struct osmo_gapk_pq *pq)
/* Call item's processing handler */
rv = item->proc(item->state, item->buf, buf_prev, len_prev);
if (rv < 0) {
- fprintf(stderr, "[!] osmo_gapk_pq_execute(): "
- "abort, item returned %d\n", rv);
+ LOGPGAPK(LOGL_ERROR, "Queue execution aborted: "
+ "item returned %d\n", rv);
return rv;
}