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