Buffer traits: add `platform`
[platform/core/system/dlog.git] / src / shared / buffer_traits.c
1 /*  MIT License
2  *
3  * Copyright (c) 2023 Samsung Electronics Co., Ltd
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy
6  * of this software and associated documentation files (the "Software"), to deal
7  * in the Software without restriction, including without limitation the rights
8  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9  * copies of the Software, and to permit persons to whom the Software is furnished
10  * to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21  * THE SOFTWARE. */
22
23 #include <buffer_traits.h>
24
25 static const struct {
26         log_id_t id;
27         char * name;
28         bool core;
29         bool platform;
30 } buffer_traits[LOG_ID_MAX] = {
31         [LOG_ID_MAIN  ] = { .name = "main"  , .core =  true, .platform =  true, },
32         [LOG_ID_RADIO ] = { .name = "radio" , .core =  true, .platform =  true, },
33         [LOG_ID_SYSTEM] = { .name = "system", .core =  true, .platform =  true, },
34         [LOG_ID_APPS  ] = { .name = "apps"  , .core =  true, .platform = false, },
35         [LOG_ID_KMSG  ] = { .name = "kmsg"  , .core = false, .platform = false, },
36         [LOG_ID_SYSLOG] = { .name = "syslog", .core = false, .platform = false, },
37 };
38
39 bool is_buffer_valid(log_id_t id)
40 {
41         return id > LOG_ID_INVALID
42             && id < LOG_ID_MAX;
43 }
44
45 bool is_core_buffer(log_id_t id)
46 {
47         return is_buffer_valid(id) && buffer_traits[id].core;
48 }
49
50 bool is_platform_buffer(log_id_t id)
51 {
52         return is_buffer_valid(id) && buffer_traits[id].platform;
53 }
54
55 char *log_name_by_id(log_id_t id)
56 {
57         return is_buffer_valid(id) ? buffer_traits[id].name : "";
58 }
59
60 log_id_t log_id_by_name(const char *name)
61 {
62         for (log_id_t i = 0; i < LOG_ID_MAX; ++i)
63                 if (!strcmp(name, buffer_traits[i].name))
64                         return i;
65
66         return LOG_ID_INVALID;
67 }
68