aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2021-02-01 19:57:52 +0100
committerDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2021-02-01 20:10:10 +0100
commit5d33536f489d94ddbfd895433ae0207d8a87f2cb (patch)
tree9934cd9742dae4199565d5aebca6f082398645b2
parent5a643dd89e2636cea19d9642c3a205d2d20250ec (diff)
downloadhardware_replicant_libsamsung-ipc-patches-todo/new-logging-api-for-1.0.tar.gz
hardware_replicant_libsamsung-ipc-patches-todo/new-logging-api-for-1.0.tar.bz2
hardware_replicant_libsamsung-ipc-patches-todo/new-logging-api-for-1.0.zip
With the current one we are missing the following features: - Log levels: everything or nothing from libsamsung-ipc is printed. Having the ability to only print errors (like modem bootstrap failures) is useful for applications. - There is no category of logging: being able to print only relevant parts (like only SIM related logs) from applications would also be useful. Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
-rw-r--r--include/log.h31
-rw-r--r--samsung-ipc/ipc.c95
2 files changed, 122 insertions, 4 deletions
diff --git a/include/log.h b/include/log.h
new file mode 100644
index 0000000..847ed93
--- /dev/null
+++ b/include/log.h
@@ -0,0 +1,31 @@
+/*
+ * This file is part of libsamsung-ipc.
+ *
+ * Copyright (C) 2021 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
+ *
+ * libsamsung-ipc 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * libsamsung-ipc 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 libsamsung-ipc. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __SAMSUNG_IPC_LOG_H__
+#define __SAMSUNG_IPC_LOG_H__
+
+enum debug_level {
+ ERR 0, /* Default */
+ WARN 1,
+ NOTICE 2,
+ INFO 3,
+ DBG 4,
+};
+
+#endif /* __SAMSUNG_IPC_LOG_H__ */
diff --git a/samsung-ipc/ipc.c b/samsung-ipc/ipc.c
index c116fbb..c95310f 100644
--- a/samsung-ipc/ipc.c
+++ b/samsung-ipc/ipc.c
@@ -333,7 +333,52 @@ int ipc_client_gprs_handlers_register(
return 0;
}
-void ipc_client_log(struct ipc_client *client, const char *message, ...)
+void ipc_client_log(struct ipc_client *client,
+ enum debug_level level, const char *category,
+ const char *message, ...)
+{
+ char buffer[4096];
+ va_list args;
+
+ if (client == NULL || message == NULL)
+ return;
+
+ if (client->simple_log_callback == NULL &&
+ client->advanced_log_callback == NULL)
+ return;
+
+ if (client->adv_log_callback) {
+ va_start(args, message);
+ vsnprintf((char *) &buffer, sizeof(buffer), message, args);
+ client->advanced_log_callback(level, category,
+ client->log_data, buffer);
+ va_end(args);
+ } else if (client->simple_log_callback) {
+ size_t new_message_len;
+ const char *new_message;
+
+ new_message_len = strlen(message) + strlen("%s: ") + 1;
+ new_message = malloc(new_message_len);
+ /* TODO: checks */
+
+ new_message = strlcpy(new_message, "%s: ", sizeof("%s: ");
+ /* TODO: checks */
+
+ new_message = strncat(new_message, message, new_message_len);
+ /* TODO: checks */
+
+ va_start(args, message);
+ vsnprintf((char *) &buffer, sizeof(buffer),
+ "%s: " + new_message,
+ category,
+ args);
+ client->simple_log_callback(client->log_data, buffer);
+ va_end(args);
+ }
+}
+
+/* TODO: add default level and category */
+void ipc_client_log_old(struct ipc_client *client, const char *message, ...)
{
char buffer[4096];
va_list args;
@@ -343,11 +388,38 @@ void ipc_client_log(struct ipc_client *client, const char *message, ...)
va_start(args, message);
vsnprintf((char *) &buffer, sizeof(buffer), message, args);
- client->log_callback(client->log_data, buffer);
+ client->advanced_log_callback(NULL, NULL, client->log_data, buffer);
+ va_end(args);
+}
+
+void ipc_client_dbg(struct ipc_client *client, const char *category,
+ const char *message, ...)
+{
+ va_list args;
+ va_start(message, args);
+ ipc_client_log(client, DBG, category, message, args);
+ va_end(args);
+}
+
+void ipc_client_info(struct ipc_client *client, const char *category,
+ const char *message, ...)
+{
+ va_list args;
+ va_start(message, args);
+ ipc_client_log(client, INFO, category, message, args);
va_end(args);
}
-int ipc_client_log_callback_register(
+/* ETC... */
+
+
+/* Compatibility with older applications
+ * To be added in applications (not in libsamsung-ipc):
+ * #define ipc_client_log_callback_register \
+ * ipc_client_log_simple_callback_register
+ */
+
+int ipc_client_log_simple_callback_register(
struct ipc_client *client,
void (*log_callback)(void *log_data, const char *message),
void *log_data)
@@ -355,7 +427,22 @@ int ipc_client_log_callback_register(
if (client == NULL)
return -1;
- client->log_callback = log_callback;
+ client->simple_log_callback = log_callback;
+ client->log_data = log_data;
+
+ return 0;
+}
+
+int ipc_client_advanced_callback_register(
+ struct ipc_client *client,
+ void (*log_callback)(enum debug_level level, const char *category,
+ void *log_data, const char *message),
+ void *log_data)
+{
+ if (client == NULL)
+ return -1;
+
+ client->advanced_log_callback = log_callback;
client->log_data = log_data;
return 0;