Extract buffer trait functions from logcommon 44/288444/1
authorMichal Bloch <m.bloch@samsung.com>
Wed, 15 Feb 2023 15:45:19 +0000 (16:45 +0100)
committerMichal Bloch <m.bloch@samsung.com>
Thu, 16 Feb 2023 12:08:50 +0000 (13:08 +0100)
Change-Id: If920b77c08d79b3d704ff2aba5cbf48a40845485
Signed-off-by: Michal Bloch <m.bloch@samsung.com>
19 files changed:
Makefile.am
include/buffer_traits.h [new file with mode: 0644]
include/logcommon.h
src/libdlog/log.c
src/libdlog/log_pipe.c
src/libdlogutil/fdi_pipe.c
src/libdlogutil/lib.c
src/log-redirect-stdout/internal.c
src/log-redirect-stdout/main.c
src/logctl/logctl.c
src/logger/logger.c
src/logger/reader_logger.c
src/logsend/logsend.c
src/shared/backend_androidlogger.c
src/shared/buffer_traits.c [new file with mode: 0644]
src/shared/logcommon.c
src/shared/util_parser.c
src/tests/libdlog_pipe.c
src/tests/test_common_wrap.c

index c4dcf14..b934695 100644 (file)
@@ -28,6 +28,7 @@ lib_LTLIBRARIES = libdlog.la
 libdlog_la_SOURCES = \
        src/libdlog/log.c \
        src/shared/backend_androidlogger.c \
+       src/shared/buffer_traits.c \
        src/shared/connect_pipe.c \
        src/shared/logcommon.c \
        src/shared/logconfig.c \
@@ -72,6 +73,7 @@ libdlogutil_la_SOURCES = \
        src/libdlogutil/fdi_logger.c \
        src/libdlogutil/fdi_zero_copy.c \
        src/shared/backend_androidlogger.c \
+       src/shared/buffer_traits.c \
        src/shared/logcommon.c \
        src/shared/logprint.c \
        src/shared/parsers.c \
@@ -100,6 +102,7 @@ dlogutil_LDADD = \
 
 dlogutil_SOURCES = \
        src/logutil/logutil.c \
+       src/shared/buffer_traits.c \
        src/shared/logcommon.c \
        src/shared/logconfig.c \
        src/shared/logprint.c \
@@ -155,6 +158,7 @@ dlog_logger_SOURCES = \
        src/logger/socket.c \
        src/logger/writer.c \
        src/shared/backend_androidlogger.c \
+       src/shared/buffer_traits.c \
        src/shared/ptrs_list.c \
        src/shared/logcommon.c \
        src/shared/logconfig.c \
@@ -199,6 +203,7 @@ dlogsend_LDADD = \
        libdlog.la
 
 dlogsend_SOURCES = \
+       src/shared/buffer_traits.c \
        src/shared/logcommon.c \
        src/logsend/logsend.c
 
@@ -213,6 +218,7 @@ dlogctl_LDFLAGS = \
        -pie
 
 dlogctl_SOURCES = \
+       src/shared/buffer_traits.c \
        src/shared/logcommon.c \
        src/shared/logconfig.c \
        src/shared/parsers.c \
@@ -268,6 +274,7 @@ libdlog_redirect_stdout_la_SOURCES = \
        src/log-redirect-stdout/lib.c \
        src/log-redirect-stdout/internal.c \
        src/shared/backend_androidlogger.c \
+       src/shared/buffer_traits.c \
        src/shared/connect_pipe.c \
        src/shared/logcommon.c \
        src/shared/logconfig.c \
@@ -286,6 +293,7 @@ dlog_redirect_stdout_LDADD = \
        libdlog_redirect_stdout.la
 
 dlog_redirect_stdout_SOURCES = \
+       src/shared/buffer_traits.c \
        src/shared/logcommon.c \
        src/log-redirect-stdout/main.c
 
@@ -557,15 +565,15 @@ src_tests_test_ptrs_list_neg_SOURCES = src/tests/test_ptrs_list_neg.c src/shared
 src_tests_test_ptrs_list_neg_CFLAGS = $(check_CFLAGS)
 src_tests_test_ptrs_list_neg_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=free,--wrap=calloc
 
-src_tests_test_common_SOURCES = src/tests/test_common.c src/shared/logcommon.c src/shared/logconfig.c src/shared/parsers.c src/shared/backend_androidlogger.c
+src_tests_test_common_SOURCES = src/tests/test_common.c src/shared/logcommon.c src/shared/buffer_traits.c src/shared/logconfig.c src/shared/parsers.c src/shared/backend_androidlogger.c
 src_tests_test_common_CFLAGS = $(check_CFLAGS)
 src_tests_test_common_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=sendmsg,--wrap=recvmsg,--wrap=writev,--wrap=read,--wrap=poll,--wrap=fcntl,--wrap=fcntl64,--wrap=malloc,--wrap=calloc,--wrap=connect,--wrap=socket,--wrap=open,--wrap=open64,--wrap=ioctl
 
-src_tests_test_common_neg_SOURCES = src/tests/test_common_neg.c src/shared/logcommon.c
+src_tests_test_common_neg_SOURCES = src/tests/test_common_neg.c src/shared/logcommon.c src/shared/buffer_traits.c
 src_tests_test_common_neg_CFLAGS = $(check_CFLAGS)
 src_tests_test_common_neg_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=sendmsg,--wrap=recvmsg,--wrap=writev,--wrap=read,--wrap=poll,--wrap=fcntl,--wrap=fcntl64,--wrap=malloc,--wrap=calloc,--wrap=connect,--wrap=socket,--wrap=open,--wrap=open64,--wrap=ioctl
 
-src_tests_test_common_pos_SOURCES = src/tests/test_common_pos.c src/shared/logcommon.c
+src_tests_test_common_pos_SOURCES = src/tests/test_common_pos.c src/shared/logcommon.c src/shared/buffer_traits.c
 src_tests_test_common_pos_CFLAGS = $(check_CFLAGS)
 src_tests_test_common_pos_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=sendmsg,--wrap=recvmsg,--wrap=writev,--wrap=read,--wrap=poll,--wrap=fcntl,--wrap=fcntl64,--wrap=malloc,--wrap=calloc,--wrap=connect,--wrap=socket,--wrap=open,--wrap=open64,--wrap=ioctl
 
@@ -609,23 +617,23 @@ src_tests_fd_info_neg_SOURCES = src/tests/fd_info_neg.c \
 src_tests_fd_info_neg_CFLAGS = $(check_CFLAGS)
 src_tests_fd_info_neg_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=sort_vector_push,--wrap=malloc,--wrap=free,--wrap=close,--wrap=dlogutil_entry_get_timestamp,--wrap=log_should_print_line
 
-src_tests_fdi_logger_pos_SOURCES = src/tests/fdi_logger_pos.c src/libdlogutil/fdi_logger.c src/shared/ptrs_list.c src/shared/logcommon.c src/shared/backend_androidlogger.c src/shared/logconfig.c src/shared/parsers.c
+src_tests_fdi_logger_pos_SOURCES = src/tests/fdi_logger_pos.c src/libdlogutil/fdi_logger.c src/shared/ptrs_list.c src/shared/logcommon.c src/shared/buffer_traits.c src/shared/backend_androidlogger.c src/shared/logconfig.c src/shared/parsers.c
 src_tests_fdi_logger_pos_CFLAGS = $(check_CFLAGS)
 src_tests_fdi_logger_pos_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=logger_open_buffer_from_config_get_path,--wrap=log_filter_set_filterspec,--wrap=parse_androidlogger_message,--wrap=copy_recv_timestamp,--wrap=malloc,--wrap=read,--wrap=close,--wrap=ioctl,--wrap=calloc
 
-src_tests_fdi_logger_neg_SOURCES = src/tests/fdi_logger_neg.c src/libdlogutil/fdi_logger.c src/shared/ptrs_list.c src/shared/logcommon.c src/shared/backend_androidlogger.c src/shared/logconfig.c src/shared/parsers.c
+src_tests_fdi_logger_neg_SOURCES = src/tests/fdi_logger_neg.c src/libdlogutil/fdi_logger.c src/shared/ptrs_list.c src/shared/logcommon.c src/shared/buffer_traits.c src/shared/backend_androidlogger.c src/shared/logconfig.c src/shared/parsers.c
 src_tests_fdi_logger_neg_CFLAGS = $(check_CFLAGS)
 src_tests_fdi_logger_neg_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=logger_open_buffer_from_config_get_path,--wrap=log_filter_set_filterspec,--wrap=parse_androidlogger_message,--wrap=copy_recv_timestamp,--wrap=malloc,--wrap=read,--wrap=close,--wrap=ioctl,--wrap=calloc
 
-src_tests_fdi_pipe_pos_SOURCES = src/tests/fdi_pipe_pos.c src/libdlogutil/fdi_pipe.c src/shared/logconfig.c src/shared/ptrs_list.c src/shared/logprint.c src/shared/parsers.c src/shared/logcommon.c src/shared/queued_entry_timestamp.c
+src_tests_fdi_pipe_pos_SOURCES = src/tests/fdi_pipe_pos.c src/libdlogutil/fdi_pipe.c src/shared/logconfig.c src/shared/ptrs_list.c src/shared/logprint.c src/shared/parsers.c src/shared/logcommon.c src/shared/buffer_traits.c src/shared/queued_entry_timestamp.c
 src_tests_fdi_pipe_pos_CFLAGS = $(check_CFLAGS)
 src_tests_fdi_pipe_pos_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=connect_sock,--wrap=close,--wrap=malloc,--wrap=free,--wrap=send_dlog_request,--wrap=recv_dlog_reply,--wrap=read,--wrap=recv_pipe
 
-src_tests_fdi_pipe_neg_SOURCES = src/tests/fdi_pipe_neg.c src/libdlogutil/fdi_pipe.c src/shared/logconfig.c src/shared/ptrs_list.c src/shared/logprint.c src/shared/parsers.c src/shared/logcommon.c src/shared/queued_entry_timestamp.c
+src_tests_fdi_pipe_neg_SOURCES = src/tests/fdi_pipe_neg.c src/libdlogutil/fdi_pipe.c src/shared/logconfig.c src/shared/ptrs_list.c src/shared/logprint.c src/shared/parsers.c src/shared/logcommon.c src/shared/buffer_traits.c src/shared/queued_entry_timestamp.c
 src_tests_fdi_pipe_neg_CFLAGS = $(check_CFLAGS)
 src_tests_fdi_pipe_neg_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=connect_sock,--wrap=close,--wrap=malloc,--wrap=free,--wrap=send_dlog_request,--wrap=recv_dlog_reply,--wrap=read,--wrap=recv_pipe
 
-src_tests_libdlog_pipe_SOURCES = src/tests/libdlog_pipe.c src/libdlog/log_pipe.c src/shared/connect_pipe.c src/shared/logcommon.c src/shared/logconfig.c src/shared/queued_entry.c src/shared/translate_syslog.c src/shared/parsers.c
+src_tests_libdlog_pipe_SOURCES = src/tests/libdlog_pipe.c src/libdlog/log_pipe.c src/shared/connect_pipe.c src/shared/logcommon.c src/shared/buffer_traits.c src/shared/logconfig.c src/shared/queued_entry.c src/shared/translate_syslog.c src/shared/parsers.c
 src_tests_libdlog_pipe_CFLAGS = $(check_CFLAGS) -pthread
 src_tests_libdlog_pipe_LDFLAGS = $(AM_LDFLAGS) -lpthread -Wl,--wrap=syslog_critical_failure,--wrap=connect,--wrap=write,--wrap=recv_pipe,--wrap=dup2,--wrap=socket,--wrap=close -lm
 
@@ -645,15 +653,15 @@ src_tests_libdlog_android_monotonic_neg_SOURCES = src/tests/libdlog_android_neg.
 src_tests_libdlog_android_monotonic_neg_CFLAGS = $(check_CFLAGS) -DUSE_ANDROID_MONOTONIC
 src_tests_libdlog_android_monotonic_neg_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=logger_open_buffer_from_config,--wrap=close,--wrap=writev,--wrap=clock_gettime
 
-src_tests_libdlog_base_pos_SOURCES = src/tests/libdlog_base_pos.c src/libdlog/log.c src/shared/hash.c src/libdlog/deduplicate.c src/shared/logcommon.c src/shared/logconfig.c src/shared/parsers.c
+src_tests_libdlog_base_pos_SOURCES = src/tests/libdlog_base_pos.c src/libdlog/log.c src/shared/hash.c src/libdlog/deduplicate.c src/shared/logcommon.c src/shared/buffer_traits.c src/shared/logconfig.c src/shared/parsers.c
 src_tests_libdlog_base_pos_CFLAGS = $(check_CFLAGS) -pthread
 src_tests_libdlog_base_pos_LDFLAGS = $(AM_LDFLAGS) -lpthread -Wl,--wrap=log_config_read,--wrap=snprintf
 
-src_tests_libdlog_base_neg_SOURCES = src/tests/libdlog_base_neg.c src/libdlog/log.c src/shared/hash.c src/libdlog/deduplicate.c src/shared/logcommon.c src/shared/logconfig.c src/shared/parsers.c
+src_tests_libdlog_base_neg_SOURCES = src/tests/libdlog_base_neg.c src/libdlog/log.c src/shared/hash.c src/libdlog/deduplicate.c src/shared/logcommon.c src/shared/buffer_traits.c src/shared/logconfig.c src/shared/parsers.c
 src_tests_libdlog_base_neg_CFLAGS = $(check_CFLAGS) -pthread
 src_tests_libdlog_base_neg_LDFLAGS = $(AM_LDFLAGS) -lpthread -Wl,--wrap=log_config_read,--wrap=snprintf
 
-src_tests_libdlog_prio_filter_pos_SOURCES = src/tests/libdlog_prio_filter_pos.c src/libdlog/log.c src/shared/hash.c src/libdlog/deduplicate.c src/shared/logcommon.c src/shared/logconfig.c src/shared/parsers.c
+src_tests_libdlog_prio_filter_pos_SOURCES = src/tests/libdlog_prio_filter_pos.c src/libdlog/log.c src/shared/hash.c src/libdlog/deduplicate.c src/shared/logcommon.c src/shared/buffer_traits.c src/shared/logconfig.c src/shared/parsers.c
 src_tests_libdlog_prio_filter_pos_CFLAGS = $(check_CFLAGS) -pthread
 src_tests_libdlog_prio_filter_pos_LDFLAGS = $(AM_LDFLAGS) -lpthread -Wl,--wrap=log_config_read
 
@@ -675,7 +683,7 @@ src_tests_queued_entry_monotonic_pos_SOURCES = src/tests/queued_entry_pos.c src/
 src_tests_queued_entry_monotonic_pos_CFLAGS = $(check_CFLAGS) -DUSE_ANDROID_MONOTONIC
 src_tests_queued_entry_monotonic_pos_LDFLAGS = $(AM_LDFLAGS)
 
-src_tests_logctl_SOURCES = src/tests/logctl.c src/logctl/logctl.c src/shared/logcommon.c src/shared/logconfig.c src/shared/parsers.c
+src_tests_logctl_SOURCES = src/tests/logctl.c src/logctl/logctl.c src/shared/logcommon.c src/shared/logconfig.c src/shared/parsers.c src/shared/buffer_traits.c
 src_tests_logctl_CFLAGS = $(check_CFLAGS)
 src_tests_logctl_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=calloc,--wrap=asprintf,--wrap=open,--wrap=open64,--wrap=fdopen,--wrap=fdopen64,--wrap=mkstemp,--wrap=mkstemp64,--wrap=fchmod,--wrap=rename
 
@@ -683,7 +691,7 @@ src_tests_config_SOURCES = src/tests/config.c src/shared/logconfig.c src/shared/
 src_tests_config_CFLAGS = $(check_CFLAGS)
 src_tests_config_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=openat64,--wrap=openat,--wrap=scandirat,--wrap=scandirat64,--wrap=fdopen,--wrap=fdopen64,--wrap=open,--wrap=open64,--wrap=calloc
 
-src_tests_logprint_SOURCES = src/tests/logprint.c src/shared/ptrs_list.c src/shared/logconfig.c src/shared/logprint.c src/shared/logcommon.c src/shared/queued_entry.c src/shared/parsers.c src/shared/translate_syslog.c src/shared/queued_entry_timestamp.c
+src_tests_logprint_SOURCES = src/tests/logprint.c src/shared/ptrs_list.c src/shared/logconfig.c src/shared/buffer_traits.c src/shared/logprint.c src/shared/logcommon.c src/shared/queued_entry.c src/shared/parsers.c src/shared/translate_syslog.c src/shared/queued_entry_timestamp.c
 src_tests_logprint_CFLAGS = $(check_CFLAGS)
 src_tests_logprint_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=write,--wrap=malloc,--wrap=calloc,--wrap=localtime_r,--wrap=strdup,--wrap=strndup,--wrap=list_add
 
@@ -703,6 +711,7 @@ src_tests_logutil_pos_SOURCES = src/tests/logutil_pos.c \
        src/libdlogutil/fdi_logger.c \
        src/libdlogutil/fdi_zero_copy.c \
        src/shared/backend_androidlogger.c \
+       src/shared/buffer_traits.c \
        src/shared/logcommon.c \
        src/shared/logprint.c \
        src/shared/parsers.c \
@@ -722,6 +731,7 @@ src_tests_logutil_neg_SOURCES = src/tests/logutil_neg.c \
        src/libdlogutil/fdi_logger.c \
        src/libdlogutil/fdi_zero_copy.c \
        src/shared/backend_androidlogger.c \
+       src/shared/buffer_traits.c \
        src/shared/logcommon.c \
        src/shared/logprint.c \
        src/shared/parsers.c \
@@ -786,6 +796,7 @@ src_tests_critical_log_SOURCES = src/tests/critical_log.c \
        src/shared/hash.c \
        src/libdlog/dynamic_config.c \
        src/shared/ptrs_list.c \
+       src/shared/buffer_traits.c \
        src/shared/logcommon.c \
        src/shared/logconfig.c \
        src/shared/parsers.c
@@ -795,6 +806,7 @@ src_tests_critical_log_LDFLAGS = $(AM_LDFLAGS) -lpthread -Wl,--wrap=execv,--wrap
 src_tests_pid_limiter_SOURCES = src/tests/pid_limiter.c \
        src/shared/hash.c \
        src/shared/loglimiter.c \
+       src/shared/buffer_traits.c \
        src/shared/logcommon.c \
        src/shared/logconfig.c \
        src/shared/parsers.c \
@@ -816,6 +828,7 @@ src_tests_libdlogutil_neg_SOURCES = src/tests/libdlogutil_neg.c  \
        src/shared/logprint.c \
        src/shared/ptrs_list.c \
        src/libdlogutil/logretrieve.c \
+       src/shared/buffer_traits.c \
        src/shared/logcommon.c \
        src/libdlogutil/fd_info.c \
        src/libdlogutil/sort_vector.c \
@@ -838,6 +851,7 @@ src_tests_libdlogutil_pos_SOURCES = src/tests/libdlogutil_pos.c  \
        src/shared/logprint.c \
        src/shared/ptrs_list.c \
        src/libdlogutil/logretrieve.c \
+       src/shared/buffer_traits.c \
        src/shared/logcommon.c \
        src/libdlogutil/fd_info.c \
        src/libdlogutil/sort_vector.c \
@@ -861,7 +875,7 @@ src_tests_metrics_LDADD = libdlogutil.la
 src_tests_metrics_CFLAGS = $(check_CFLAGS)
 src_tests_metrics_LDFLAGS = $(AM_LDFLAGS) -lpthread -Wl,--wrap=dlogutil_entry_get_tag,--wrap=dlogutil_entry_get_pid,--wrap=dlogutil_entry_get_priority,--wrap=free,--wrap=calloc,--wrap=strdup
 
-src_tests_deduplicate_test_SOURCES = src/tests/deduplicate_test.c src/libdlog/log.c src/libdlog/deduplicate.c src/shared/hash.c src/shared/logcommon.c src/shared/loglimiter.c src/libdlog/dynamic_config.c src/shared/logconfig.c src/shared/parsers.c src/shared/ptrs_list.c
+src_tests_deduplicate_test_SOURCES = src/tests/deduplicate_test.c src/libdlog/log.c src/libdlog/deduplicate.c src/shared/hash.c src/shared/buffer_traits.c src/shared/logcommon.c src/shared/loglimiter.c src/libdlog/dynamic_config.c src/shared/logconfig.c src/shared/parsers.c src/shared/ptrs_list.c
 src_tests_deduplicate_test_CFLAGS = $(check_CFLAGS) -pthread
 src_tests_deduplicate_test_LDFLAGS = $(AM_LDFLAGS) -lpthread -Wl,--wrap=clock_gettime,--wrap=log_config_read,--wrap=deduplicate_warn
 
diff --git a/include/buffer_traits.h b/include/buffer_traits.h
new file mode 100644 (file)
index 0000000..c7fe8f7
--- /dev/null
@@ -0,0 +1,63 @@
+/*  MIT License
+ *
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is furnished
+ * to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE. */
+
+#pragma once
+
+#include <dlog-internal.h>
+#include <stdbool.h>
+
+/**
+ * @brief Get buffer ID by name
+ * @details Returns the ID of the buffer with the given name
+ * @param[in] name The name of the buffer whose ID we seek
+ * @return If such buffer exists, its ID.
+ *         Else, LOG_ID_INVALID.
+ * @see log_name_by_id
+ */
+log_id_t log_id_by_name(const char *name);
+
+/**
+ * @brief Get buffer name by ID
+ * @details Returns the name of the buffer with the given ID
+ * @param[in] id The ID of the buffer whose name we seek
+ * @return If such buffer exists, its name.
+ *         Else, empty string.
+ * @see log_id_by_name
+ */
+char * log_name_by_id(log_id_t id);
+
+/**
+ * @brief Is core buffer
+ * @details Returns whether given buffer is one of the original four buffers
+ * @param[in] id The ID of the buffer
+ * @return boolean
+ */
+bool is_core_buffer(log_id_t id);
+
+/**
+ * @brief Is buffer valid
+ * @details Returns whether given buffer ID represents an actual buffer
+ * @param[in] id The ID of the buffer
+ * @return boolean
+ */
+bool is_buffer_valid(log_id_t id);
+
index 2105222..e1067ef 100644 (file)
@@ -107,23 +107,6 @@ static inline void close_fd(const int *fd)
                close(*fd);
 }
 
-static inline bool is_core_buffer(log_id_t buf_id)
-{
-       static bool const is_core [LOG_ID_MAX] = {
-               [LOG_ID_MAIN  ] = true,
-               [LOG_ID_RADIO ] = true,
-               [LOG_ID_SYSTEM] = true,
-               [LOG_ID_APPS  ] = true,
-       };
-
-       if (buf_id < 0 || buf_id >= (log_id_t) NELEMS(is_core))
-               return false;
-       return is_core [buf_id];
-}
-
-char * log_name_by_id(log_id_t id);
-log_id_t log_id_by_name(const char *name);
-
 log_priority filter_char_to_pri(int c);
 char filter_pri_to_char(log_priority pri);
 
index dbb7ecc..3d88744 100644 (file)
 #include <tizen.h>
 
 // DLog
+#include <buffer_traits.h>
 #include "deduplicate.h"
 #include <dynamic_config.h>
 #include <libdlog.h>
-#include <logcommon.h>
 #include "logconfig.h"
 #include "loglimiter.h"
 
index a7692e4..9b3e893 100644 (file)
@@ -31,6 +31,7 @@
 #include <sys/un.h>
 
 // DLog
+#include <buffer_traits.h>
 #include <logcommon.h>
 #include <libdlog.h>
 #include <logconfig.h>
index b753c19..e4eee7b 100644 (file)
@@ -24,8 +24,8 @@
 #include <stdio.h>
 #include <string.h>
 
+#include <buffer_traits.h>
 #include <logconfig.h>
-#include <logcommon.h>
 #include <logpipe.h>
 
 #include "fd_info.h"
index 8c263c2..04492ed 100644 (file)
@@ -22,7 +22,7 @@
 
 #include <dlogutil-internal.h>
 #include <tizen.h>
-#include <logcommon.h>
+#include <buffer_traits.h>
 
 #include "logretrieve.h"
 
index f064bac..04fbe73 100644 (file)
@@ -23,6 +23,7 @@
 #include "internal.h"
 
 #include <backend_androidlogger.h>
+#include <buffer_traits.h>
 #include <sys/ioctl.h>
 #include <linux/logger.h>
 #include <logconfig.h>
index 197ac3d..d791e51 100644 (file)
@@ -23,8 +23,9 @@
 #include <getopt.h>
 #include <stdio.h>
 
-#include <logcommon.h>
+#include <buffer_traits.h>
 #include <dlog-redirect-stdout.h>
+#include <logcommon.h>
 
 /* Tag length is limited by maximum request size. */
 #define MAX_TAG_LENGTH (MAX_LOGGER_REQUEST_LEN - sizeof(struct dlog_control_msg) - sizeof(struct dlog_control_msg_stdout))
index c07ec6f..903d4e6 100644 (file)
@@ -13,8 +13,8 @@
 #include <sys/stat.h>
 
 // DLog
+#include <buffer_traits.h>
 #include <dynamic_config.h>
-#include <logcommon.h>
 #include <logconfig.h>
 #include <loglimiter.h>
 
index c7d12e5..d82e2bb 100644 (file)
@@ -24,6 +24,7 @@
 #include "subreader_metrics.h"
 #include "subreader_memory.h"
 
+#include <buffer_traits.h>
 #include <metrics.h>
 #include <getopt.h>
 #include <dynamic_config.h>
index a4ea684..a090b33 100644 (file)
@@ -2,6 +2,8 @@
 #include "reader_common.h"
 #include "logger_internal.h"
 
+#include <buffer_traits.h>
+
 static void free_reader_logger(struct reader_common *_reader)
 {
        struct reader_logger *const reader = (struct reader_logger *) _reader;
index cc47a8b..f97b289 100644 (file)
@@ -3,8 +3,8 @@
 #include <stdlib.h>
 #include <stdbool.h>
 
+#include <buffer_traits.h>
 #include <dlog.h>
-#include <logcommon.h>
 #include <logprint.h>
 
 struct parsed_params {
index 7b5b871..1eba03d 100644 (file)
@@ -32,6 +32,7 @@
 
 // DLog
 #include <backend_androidlogger.h>
+#include <buffer_traits.h>
 #include <dlog.h>
 #include <linux/logger.h>
 #include <logcommon.h>
diff --git a/src/shared/buffer_traits.c b/src/shared/buffer_traits.c
new file mode 100644 (file)
index 0000000..a9dfebc
--- /dev/null
@@ -0,0 +1,62 @@
+/*  MIT License
+ *
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is furnished
+ * to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE. */
+
+#include <buffer_traits.h>
+
+static const struct {
+       log_id_t id;
+       char * name;
+       bool core;
+} buffer_traits[LOG_ID_MAX] = {
+       [LOG_ID_MAIN  ] = { .name = "main"  , .core =  true, },
+       [LOG_ID_RADIO ] = { .name = "radio" , .core =  true, },
+       [LOG_ID_SYSTEM] = { .name = "system", .core =  true, },
+       [LOG_ID_APPS  ] = { .name = "apps"  , .core =  true, },
+       [LOG_ID_KMSG  ] = { .name = "kmsg"  , .core = false, },
+       [LOG_ID_SYSLOG] = { .name = "syslog", .core = false, },
+};
+
+bool is_buffer_valid(log_id_t id)
+{
+       return id > LOG_ID_INVALID
+           && id < LOG_ID_MAX;
+}
+
+bool is_core_buffer(log_id_t id)
+{
+       return is_buffer_valid(id) && buffer_traits[id].core;
+}
+
+char *log_name_by_id(log_id_t id)
+{
+       return is_buffer_valid(id) ? buffer_traits[id].name : "";
+}
+
+log_id_t log_id_by_name(const char *name)
+{
+       for (log_id_t i = 0; i < LOG_ID_MAX; ++i)
+               if (!strcmp(name, buffer_traits[i].name))
+                       return i;
+
+       return LOG_ID_INVALID;
+}
+
index df5a277..a5c720e 100644 (file)
 
 #define MAX_PREFIX_SIZE 32
 
-static struct {
-       log_id_t id;
-       char * name;
-} logid_map[LOG_ID_MAX] = {
-       { .id = LOG_ID_MAIN,   .name = "main" },
-       { .id = LOG_ID_RADIO,  .name = "radio" },
-       { .id = LOG_ID_SYSTEM, .name = "system" },
-       { .id = LOG_ID_APPS,   .name = "apps" },
-       { .id = LOG_ID_KMSG,   .name = "kmsg" },
-       { .id = LOG_ID_SYSLOG, .name = "syslog" },
-};
-
 // message header structure to send and receive pipe file descriptor
 // contains header data required for building message
 // to send it using sendmsg(2) and receive using recvmsg(2)
@@ -168,44 +156,6 @@ static int parse_pipe_msg_control(struct msghdr *msg_hdr)
 }
 
 /**
- * @brief Get buffer ID by name
- * @details Returns the ID of the buffer with the given name
- * @param[in] name The name of the buffer whose ID we seek
- * @return If such buffer exists, its ID.
- *         Else, LOG_ID_INVALID.
- * @see log_name_by_id
- */
-log_id_t log_id_by_name(const char *name)
-{
-       log_id_t i;
-
-       for (i = 0; i < LOG_ID_MAX; ++i)
-               if (!strcmp(name, logid_map[i].name))
-                       return logid_map[i].id;
-
-       return LOG_ID_INVALID;
-}
-
-/**
- * @brief Get buffer name by ID
- * @details Returns the name of the buffer with the given ID
- * @param[in] id The ID of the buffer whose name we seek
- * @return If such buffer exists, its name.
- *         Else, empty string.
- * @see log_id_by_name
- */
-char * log_name_by_id(log_id_t id)
-{
-       log_id_t i;
-
-       for (i = 0; i < LOG_ID_MAX; ++i)
-               if (id == logid_map[i].id)
-                       return logid_map[i].name;
-
-       return "";
-}
-
-/**
  * @brief Log crtical failure
  * @details Writes the given message to syslog with a critical failure note
  * @param[in] message The message to write to syslog
index 78ba0e0..1c13560 100644 (file)
@@ -1,4 +1,6 @@
 #include <getopt.h>
+
+#include <buffer_traits.h>
 #include <util_parser.h>
 #include <sort_vector.h>
 
index 974d361..dd5623c 100644 (file)
@@ -6,8 +6,8 @@
 #include <sys/socket.h>
 #include <sys/un.h>
 
+#include <buffer_traits.h>
 #include <dlog.h>
-#include <logcommon.h>
 #include <logconfig.h>
 
 int (*write_to_log)(log_id_t, log_priority, const char *tag, const char *msg, struct timespec *tp_mono, int32_t pid, int32_t tid) = NULL;
index d877c5b..9631513 100644 (file)
@@ -28,6 +28,7 @@
 
 // DLog
 #include <backend_androidlogger.h>
+#include <buffer_traits.h>
 #include <logcommon.h>
 #include <logconfig.h>
 #include <logpipe.h>