microui  4.0.1
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  }
95  else {
96  // continue previous event: drop data
97  queue_log[index] = 0;
98  }
99 
100  // prepare next log
101  queue_is_first_element = remaining_elements == (uint32_t)0;
102 }
103 
104 void LLUI_INPUT_IMPL_log_queue_replace(uint32_t old, uint32_t data, uint32_t index, uint32_t queue_length) {
105  // previous event has been replaced, nothing to log
106  (void)old;
107  (void)data;
108  (void)index;
109  (void)queue_length;
110 }
111 
112 void LLUI_INPUT_IMPL_log_queue_read(uint32_t data, uint32_t index) {
113  // event has been read, nothing to log
114  (void)data;
115  (void)index;
116 }
117 
118 void LLUI_INPUT_IMPL_log_dump(bool log_type, uint32_t log, uint32_t index) {
119  if (log_type) {
120  // log is an event or a data event
121 
122  if ((uint32_t)0 != queue_log[index]) {
123  // it is a new event to decode
124  dump_current_event = log;
125 
126  // reset data decoder
127  fct_decode_data = NULL;
128 
129  // decode event (decoder can give a data decoder)
130  MICROUI_EVENT_DECODER_decode_event(log, index, &fct_decode_data);
131  }
132  else if (NULL != fct_decode_data) {
133  // decode data of previous event
134  fct_decode_data(dump_current_event, log, index);
135  }
136  else {
137  // cannot decode this element: drop it
138  MICROUI_EVENT_DECODER_drop_data(log, index);
139  }
140  }
141  else {
142  // log is a status: see function API comment.
143 
144  switch(log) {
145 
146  case 0:
147  // start of dump (events already consumed)
148  MICROUI_EVENT_DECODER_describe_dump_start();
149  MICROUI_EVENT_DECODER_describe_dump_past();
150 
151  // drop first element if it is not an event
152  fct_decode_data = NULL;
153  break;
154 
155  case 1:
156  // continue dump (events not consumed yet)
157  MICROUI_EVENT_DECODER_describe_dump_future();
158  break;
159 
160  case 2:
161  // dump java objects
162  MICROUI_EVENT_DECODER_describe_dump_events_objects();
163  break;
164 
165  case 3:
166  default:
167  // end of dump
168  MICROUI_EVENT_DECODER_describe_dump_end();
169  break;
170  }
171  }
172 }
173 
174 #endif // MICROUIEVENTDECODER_ENABLED
175 
176 // -----------------------------------------------------------------------------
177 // EOF
178 // -----------------------------------------------------------------------------
179