microui  4.1.0
microui
LLUI_INPUT_LOG_impl.c
Go to the documentation of this file.
1 /*
2  * C
3  *
4  * Copyright 2021-2024 MicroEJ Corp. All rights reserved.
5  * Use of this source code is governed by a BSD-style license that can be found with this software.
6  */
7 
24 // -----------------------------------------------------------------------------
25 // Includes
26 // -----------------------------------------------------------------------------
27 
28 #include <assert.h>
29 #include <string.h>
30 
31 // implements some LLUI_INPUT_impl functions
32 #include <LLUI_INPUT_impl.h>
33 
34 // deport event description to another file
35 #include "microui_event_decoder.h"
36 
37 #ifdef MICROUIEVENTDECODER_ENABLED
38 
39 // -----------------------------------------------------------------------------
40 // Macros and Defines
41 // -----------------------------------------------------------------------------
42 
43 /*
44  * @brief Logger's array size. The MicroUI FIFO cannot be higher than this size.
45  */
46 #define QUEUE_LOG_MAX_SIZE 100
47 
48 // -----------------------------------------------------------------------------
49 // Global Variables
50 // -----------------------------------------------------------------------------
51 
52 /*
53  * @brief Pointer on event's data decoder.
54  */
55 static MICROUI_EVENT_DECODER_decode_event_data fct_decode_data;
56 
57 /*
58  * @brief Logger array where store the MicroUI event metadata.
59  */
60 static uint8_t queue_log[QUEUE_LOG_MAX_SIZE];
61 
62 /*
63  * @brief true when a new event is logged, false when the event's data is logged.
64  */
65 static bool queue_is_first_element;
66 
67 /*
68  * @brief Current event to decode.
69  */
70 static uint32_t dump_current_event;
71 
72 // -----------------------------------------------------------------------------
73 // LLUI_INPUT_impl.h functions
74 // -----------------------------------------------------------------------------
75 
76 void LLUI_INPUT_IMPL_log_queue_init(uint32_t length) {
77  assert(length <= (uint32_t)QUEUE_LOG_MAX_SIZE);
78  (void)memset((void *)queue_log, 0, length);
79  queue_is_first_element = true;
80 }
81 
82 void LLUI_INPUT_IMPL_log_queue_full(uint32_t data) {
83  // queue is full, nothing to log
84  (void)data;
85 }
86 
87 void LLUI_INPUT_IMPL_log_queue_add(uint32_t data, uint32_t index, uint32_t remaining_elements, uint32_t queue_length) {
88  (void)data;
89  (void)queue_length;
90 
91  if (queue_is_first_element) {
92  // start new event: set the event size in array
93  queue_log[index] = (uint8_t)(remaining_elements + (uint32_t)1);
94  } else {
95  // continue previous event: drop data
96  queue_log[index] = 0;
97  }
98 
99  // prepare next log
100  queue_is_first_element = remaining_elements == (uint32_t)0;
101 }
102 
103 void LLUI_INPUT_IMPL_log_queue_replace(uint32_t old, uint32_t data, uint32_t index, uint32_t queue_length) {
104  // previous event has been replaced, nothing to log
105  (void)old;
106  (void)data;
107  (void)index;
108  (void)queue_length;
109 }
110 
111 void LLUI_INPUT_IMPL_log_queue_read(uint32_t data, uint32_t index) {
112  // event has been read, nothing to log
113  (void)data;
114  (void)index;
115 }
116 
117 void LLUI_INPUT_IMPL_log_dump(bool log_type, uint32_t log, uint32_t index) {
118  if (log_type) {
119  // log is an event or a data event
120 
121  if ((uint32_t)0 != queue_log[index]) {
122  // it is a new event to decode
123  dump_current_event = log;
124 
125  // reset data decoder
126  fct_decode_data = NULL;
127 
128  // decode event (decoder can give a data decoder)
129  MICROUI_EVENT_DECODER_decode_event(log, index, &fct_decode_data);
130  } else if (NULL != fct_decode_data) {
131  // decode data of previous event
132  fct_decode_data(dump_current_event, log, index);
133  } else {
134  // cannot decode this element: drop it
135  MICROUI_EVENT_DECODER_drop_data(log, index);
136  }
137  } else {
138  // log is a status: see function API comment.
139 
140  switch (log) {
141  case 0:
142  // start of dump (events already consumed)
143  MICROUI_EVENT_DECODER_describe_dump_start();
144  MICROUI_EVENT_DECODER_describe_dump_past();
145 
146  // drop first element if it is not an event
147  fct_decode_data = NULL;
148  break;
149 
150  case 1:
151  // continue dump (events not consumed yet)
152  MICROUI_EVENT_DECODER_describe_dump_future();
153  break;
154 
155  case 2:
156  // dump java objects
157  MICROUI_EVENT_DECODER_describe_dump_events_objects();
158  break;
159 
160  case 3:
161  default:
162  // end of dump
163  MICROUI_EVENT_DECODER_describe_dump_end();
164  break;
165  }
166  }
167 }
168 
169 #endif // MICROUIEVENTDECODER_ENABLED
170 
171 // -----------------------------------------------------------------------------
172 // EOF
173 // -----------------------------------------------------------------------------