#include <assert.h>
#include <limits.h>
-static const struct fd_ops *const backend_ops[] = {
- [BACKEND_PIPE] = &ops_pipe,
- [BACKEND_ANDROID_LOGGER] = &ops_logger,
- [BACKEND_ZERO_COPY] = &ops_zero_copy,
-};
+static const struct fd_ops *get_ops_by_buffer(size_t buf_id, int enabled_buffers, backend_t backend, bool is_compressed_memory)
+{
+ if (!bit_test(enabled_buffers, buf_id))
+ return NULL;
+
+ /* These are implemented by the pipe daemon,
+ * regardless of the nominal backend. */
+ if (is_compressed_memory
+ || buf_id == LOG_ID_KMSG
+ || buf_id == LOG_ID_SYSLOG)
+ return &ops_pipe;
+
+ switch (backend) {
+ case BACKEND_PIPE : return &ops_pipe;
+ case BACKEND_ANDROID_LOGGER: return &ops_logger;
+ case BACKEND_ZERO_COPY : return &ops_zero_copy;
+ default : return NULL;
+ }
+}
int create_initial_fdis(struct fd_info ***fdis, int enabled_buffers, backend_t backend, bool is_compressed_memory, const struct log_config *conf, log_id_t aliased[LOG_ID_MAX])
{
int fdi_cnt = 0;
int r;
+ const struct fd_ops *ops_by_buffer[LOG_ID_MAX];
+ for (size_t i = 0; i < NELEMS(ops_by_buffer); ++i)
+ ops_by_buffer[i] = get_ops_by_buffer(i, enabled_buffers, backend, is_compressed_memory);
+
fdi_ptrs = calloc(bit_count(enabled_buffers) + 1 /* NULL terminator */, sizeof *fdi_ptrs);
if (!fdi_ptrs)
return TIZEN_ERROR_OUT_OF_MEMORY;
fdi_cnt = 0;
for (int i = 0; i < LOG_ID_MAX; ++i) {
- if (!bit_test(enabled_buffers, i))
+ const struct fd_ops *const ops = ops_by_buffer[i];
+ if (!ops)
continue;
- struct fd_info *fdi;
- if (is_compressed_memory) {
- /* Ignore `is_pipe`. This feature is done
- * via pipes always, even on other backends. */
- fdi = fdi_create(&ops_pipe, i);
- } else {
- switch (i) {
- case LOG_ID_KMSG:
- case LOG_ID_SYSLOG:
- fdi = fdi_create(&ops_pipe, i);
- break;
- default:
- fdi = fdi_create(backend_ops[backend], i);
- break;
- }
- }
+ struct fd_info *const fdi = fdi_create(ops, i);
if (!fdi)
return -ENOMEM;