1 /*
2 * Copyright (c) 2021 Nordic Semiconductor
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6 #include "mock_log_link.h"
7 #include <string.h>
8
initiate(const struct log_link * link,struct log_link_config * configa)9 static int initiate(const struct log_link *link, struct log_link_config *configa)
10 {
11 struct mock_log_link *mock = (struct mock_log_link *)link->ctx;
12
13 link->ctrl_blk->domain_cnt = mock->domain_cnt;
14
15 for (int i = 0; i < mock->domain_cnt; i++) {
16 link->ctrl_blk->source_cnt[i] = mock->domains[i]->source_cnt;
17 }
18
19 return 0;
20 }
21
activate(const struct log_link * link)22 static int activate(const struct log_link *link)
23 {
24 return 0;
25 }
26
get_domain_name(const struct log_link * link,uint32_t domain_id,char * buf,size_t * length)27 static int get_domain_name(const struct log_link *link, uint32_t domain_id,
28 char *buf, size_t *length)
29 {
30 struct mock_log_link *mock = (struct mock_log_link *)link->ctx;
31
32 *length = strlen(mock->domains[domain_id]->name);
33
34 if (buf) {
35 strncpy(buf, mock->domains[domain_id]->name, *length);
36 }
37
38 return 0;
39 }
40
get_source_name(const struct log_link * link,uint32_t domain_id,uint16_t source_id,char * buf,size_t * length)41 static int get_source_name(const struct log_link *link, uint32_t domain_id,
42 uint16_t source_id, char *buf, size_t *length)
43 {
44 struct mock_log_link *mock = (struct mock_log_link *)link->ctx;
45
46 strncpy(buf, mock->domains[domain_id]->sources[source_id].source,
47 *length);
48 *length = strlen(mock->domains[domain_id]->sources[source_id].source);
49
50 return 0;
51 }
52
get_levels(const struct log_link * link,uint32_t domain_id,uint16_t source_id,uint8_t * level,uint8_t * runtime_level)53 static int get_levels(const struct log_link *link, uint32_t domain_id,
54 uint16_t source_id, uint8_t *level, uint8_t *runtime_level)
55 {
56 struct mock_log_link *mock = (struct mock_log_link *)link->ctx;
57
58 *level = mock->domains[domain_id]->sources[source_id].clevel;
59
60 if (runtime_level) {
61 *runtime_level = mock->domains[domain_id]->sources[source_id].rlevel;
62 }
63
64 return 0;
65 }
66
set_runtime_level(const struct log_link * link,uint32_t domain_id,uint16_t source_id,uint8_t level)67 static int set_runtime_level(const struct log_link *link, uint32_t domain_id,
68 uint16_t source_id, uint8_t level)
69 {
70 struct mock_log_link *mock = (struct mock_log_link *)link->ctx;
71
72 mock->domains[domain_id]->sources[source_id].rlevel = level;
73
74 return 0;
75 }
76
77 struct log_link_api mock_log_link_api = {
78 .initiate = initiate,
79 .activate = activate,
80 .get_domain_name = get_domain_name,
81 .get_source_name = get_source_name,
82 .get_levels = get_levels,
83 .set_runtime_level = set_runtime_level,
84 };
85