Inline struct log_filter in the struct dlogutil_config 49/243749/1
authorMateusz Majewski <m.majewski2@samsung.com>
Wed, 9 Sep 2020 13:40:42 +0000 (15:40 +0200)
committerMateusz Majewski <m.majewski2@samsung.com>
Wed, 9 Sep 2020 13:51:20 +0000 (15:51 +0200)
Change-Id: Ibfc41bf3f40564a409b2fd459633308c1ad469d1

include/dlogutil-internal.h
include/logprint.h
src/libdlogutil/lib.c
src/libdlogutil/logretrieve.c
src/shared/logprint.c

index 641f584..453dc12 100644 (file)
@@ -15,6 +15,7 @@
  * limitations under the License. */
 
 #include <dlogutil.h>
+#include <logprint.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -38,8 +39,7 @@ typedef enum {
 
 
 struct dlogutil_config {
-       // TODO: Consider making this not a pointer
-       struct log_filter *filter;
+       struct log_filter filter;
        unsigned int logs_size;
        dlogutil_sorting_order_e sort_by;
        unsigned int buffers;
index 670bf72..c119c2e 100644 (file)
@@ -60,6 +60,14 @@ struct log_write_buffer {
 struct log_filter *log_filter_new();
 
 void log_filter_free(struct log_filter *p_filter);
+struct log_filter {
+       list_head filters;
+       log_priority global_pri;
+       bool exact_global_pri;
+       bool need_apply_default;
+};
+
+void log_filter_init(struct log_filter *p_filter);
 
 struct log_write_buffer log_write_buffer_new();
 
index aeba710..1004dfc 100644 (file)
 #include <tizen.h>
 #include <logcommon.h>
 
-static void filter_options_destroy(struct log_filter **filter)
-{
-       log_filter_free(*filter);
-}
-
 EXPORT_API dlogutil_config_s *dlogutil_config_create(void)
 {
-       __attribute__((cleanup(filter_options_destroy))) struct log_filter *filter = log_filter_new();
-
-       if (!filter)
-               return NULL;
-
        dlogutil_config_s *ret = calloc(1, sizeof(*ret));
        if (!ret)
                return NULL;
@@ -39,8 +29,7 @@ EXPORT_API dlogutil_config_s *dlogutil_config_create(void)
        ret->mode = DLOGUTIL_MODE_NONPRINTING;
        ret->logs_size = DEFAULT_SORT_BUFFER_SIZE;
        ret->sort_by = DLOGUTIL_SORT_DEFAULT;
-       ret->filter = filter;
-       filter = NULL;
+       log_filter_init(&ret->filter);
 
        return ret;
 }
@@ -50,26 +39,26 @@ EXPORT_API void dlogutil_config_destroy(dlogutil_config_s *config)
        if (!config)
                return;
 
-       log_filter_free(config->filter);
+       log_filter_clear(&config->filter);
        free(config);
 }
 
 EXPORT_API int dlogutil_config_filter_tid(dlogutil_config_s *config, pid_t tid)
 {
        CHECK_PARAM(config);
-       return log_filter_set_tid(config->filter, tid);
+       return log_filter_set_tid(&config->filter, tid);
 }
 
 EXPORT_API int dlogutil_config_filter_pid(dlogutil_config_s *config, pid_t pid)
 {
        CHECK_PARAM(config);
-       return log_filter_set_pid(config->filter, pid);
+       return log_filter_set_pid(&config->filter, pid);
 }
 
 EXPORT_API int dlogutil_config_filter_filterspec(dlogutil_config_s *config, const char *query)
 {
        CHECK_PARAM(config);
-       return log_filter_set_filterspec(config->filter, query);
+       return log_filter_set_filterspec(&config->filter, query);
 }
 
 EXPORT_API int dlogutil_config_sorting_disable(dlogutil_config_s *config)
index eb467b9..052b36d 100644 (file)
@@ -175,7 +175,7 @@ int dlogutil_state_init(dlogutil_state_s *state, struct fd_info ***data_fds_ptr,
                state->aliased[i] = aliased[i];
 
        sort_vector_init(&state->logs);
-       state->filter_object = config->filter ? log_filter_from_filter(config->filter) : log_filter_new();
+       state->filter_object = log_filter_from_filter(&config->filter);
 
        state->epollfd = epoll_create1(0);
        if (state->epollfd < 0)
index 3302d2e..0e19899 100644 (file)
 #define FILTERINFO_PID_NONE -1
 #define FILTERINFO_TID_NONE -1
 
-struct log_filter {
-       list_head filters;
-       log_priority global_pri;
-       bool exact_global_pri;
-       bool need_apply_default;
-};
-
 /**
  * @brief Allocate filter info
  * @details Allocates filter info with given parameters
@@ -199,6 +192,13 @@ bool log_filter_need_apply_default(struct log_filter *p_filter)
        return p_filter->need_apply_default;
 }
 
+void log_filter_init(struct log_filter *p_filter)
+{
+       p_filter->global_pri = DLOG_SILENT;
+       p_filter->exact_global_pri = false;
+       p_filter->need_apply_default = true;
+}
+
 /**
  * @brief Allocate log format
  * @details Allocates a log format structure
@@ -213,9 +213,7 @@ struct log_filter *log_filter_new(void)
 
        if (!p_ret)
                return NULL;
-       p_ret->global_pri = DLOG_SILENT;
-       p_ret->exact_global_pri = false;
-       p_ret->need_apply_default = true;
+       log_filter_init(p_ret);
 
        return p_ret;
 }