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