Line data Source code
1 : /*
2 : *
3 : * Copyright (c) 2021 Project CHIP Authors
4 : * Copyright (c) 2015-2017 Nest Labs, Inc.
5 : * All rights reserved.
6 : *
7 : * Licensed under the Apache License, Version 2.0 (the "License");
8 : * you may not use this file except in compliance with the License.
9 : * You may obtain a copy of the License at
10 : *
11 : * http://www.apache.org/licenses/LICENSE-2.0
12 : *
13 : * Unless required by applicable law or agreed to in writing, software
14 : * distributed under the License is distributed on an "AS IS" BASIS,
15 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 : * See the License for the specific language governing permissions and
17 : * limitations under the License.
18 : */
19 :
20 : /**
21 : * @file
22 : *
23 : * @brief
24 : * Management of the CHIP Event Logging.
25 : *
26 : */
27 : #pragma once
28 :
29 : #include "EventLoggingDelegate.h"
30 : #include <access/SubjectDescriptor.h>
31 : #include <app/EventLoggingTypes.h>
32 : #include <app/EventReporter.h>
33 : #include <app/MessageDef/EventDataIB.h>
34 : #include <app/MessageDef/StatusIB.h>
35 : #include <app/data-model-provider/EventsGenerator.h>
36 : #include <app/util/basic-types.h>
37 : #include <lib/core/TLVCircularBuffer.h>
38 : #include <lib/support/CHIPCounter.h>
39 : #include <lib/support/LinkedList.h>
40 : #include <messaging/ExchangeMgr.h>
41 : #include <platform/CHIPDeviceConfig.h>
42 : #include <system/SystemClock.h>
43 :
44 : /**
45 : * Events are stored in the LogStorageResources provided to
46 : * EventManagement::Init.
47 : *
48 : * A newly generated event will be placed in the lowest-priority (in practice
49 : * DEBUG) buffer, the one associated with the first LogStorageResource. If
50 : * there is no space in that buffer, space will be created by evicting the
51 : * oldest event currently in that buffer, until enough space is available.
52 : *
53 : * When an event is evicted from a buffer, there are two possibilities:
54 : *
55 : * 1) If the next LogStorageResource has a priority that is no higher than the
56 : * event's priority, the event will be moved to that LogStorageResource's
57 : * buffer. This may in turn require events to be evicted from that buffer.
58 : * 2) If the next LogStorageResource has a priority that is higher than the
59 : * event's priority, then the event is just dropped.
60 : *
61 : * This means that LogStorageResources at a given priority level are reserved
62 : * for events of that priority level or higher priority.
63 : *
64 : * As a simple example, assume there are only two priority levels, DEBUG and
65 : * CRITICAL, and two LogStorageResources with those priorities. In that case,
66 : * old CRITICAL events will not start getting dropped until both buffers are
67 : * full, while old DEBUG events will start getting dropped once the DEBUG
68 : * LogStorageResource buffer is full.
69 : */
70 :
71 : #define CHIP_CONFIG_EVENT_GLOBAL_PRIORITY PriorityLevel::Debug
72 :
73 : namespace chip {
74 : namespace app {
75 : inline constexpr const uint32_t kEventManagementProfile = 0x1;
76 : inline constexpr const uint32_t kFabricIndexTag = 0x1;
77 : inline constexpr size_t kMaxEventSizeReserve = 512;
78 : constexpr uint16_t kRequiredEventField =
79 : (1 << to_underlying(EventDataIB::Tag::kPriority)) | (1 << to_underlying(EventDataIB::Tag::kPath));
80 :
81 : /**
82 : * @brief
83 : * Internal event buffer, built around the TLV::TLVCircularBuffer
84 : */
85 :
86 : class CircularEventBuffer : public TLV::TLVCircularBuffer
87 : {
88 : public:
89 : /**
90 : * @brief
91 : * A constructor for the CircularEventBuffer (internal API).
92 : */
93 6 : CircularEventBuffer() : TLVCircularBuffer(nullptr, 0){};
94 :
95 : /**
96 : * @brief
97 : * A Init for the CircularEventBuffer (internal API).
98 : *
99 : * @param[in] apBuffer The actual storage to use for event storage.
100 : *
101 : * @param[in] aBufferLength The length of the \c apBuffer in bytes.
102 : *
103 : * @param[in] apPrev The pointer to CircularEventBuffer storing
104 : * events of lesser priority.
105 : *
106 : * @param[in] apNext The pointer to CircularEventBuffer storing
107 : * events of greater priority.
108 : *
109 : * @param[in] aPriorityLevel CircularEventBuffer priority level
110 : */
111 : void Init(uint8_t * apBuffer, uint32_t aBufferLength, CircularEventBuffer * apPrev, CircularEventBuffer * apNext,
112 : PriorityLevel aPriorityLevel);
113 :
114 : /**
115 : * @brief
116 : * A helper function that determines whether the event of
117 : * specified priority is final destination
118 : *
119 : * @param[in] aPriority Priority of the event.
120 : *
121 : * @retval true/false event's priority is same as current buffer's priority, otherwise, false
122 : */
123 : bool IsFinalDestinationForPriority(PriorityLevel aPriority) const;
124 :
125 787 : PriorityLevel GetPriority() { return mPriority; }
126 :
127 4934 : CircularEventBuffer * GetPreviousCircularEventBuffer() { return mpPrev; }
128 4723 : CircularEventBuffer * GetNextCircularEventBuffer() { return mpNext; }
129 :
130 313 : void SetRequiredSpaceforEvicted(size_t aRequiredSpace) { mRequiredSpaceForEvicted = aRequiredSpace; }
131 313 : size_t GetRequiredSpaceforEvicted() const { return mRequiredSpaceForEvicted; }
132 :
133 455 : ~CircularEventBuffer() override = default;
134 :
135 : private:
136 : CircularEventBuffer * mpPrev = nullptr; ///< A pointer CircularEventBuffer storing events less important events
137 : CircularEventBuffer * mpNext = nullptr; ///< A pointer CircularEventBuffer storing events more important events
138 :
139 : PriorityLevel mPriority = PriorityLevel::Invalid; ///< The buffer is the final bucket for events of this priority. Events of
140 : ///< lesser priority are dropped when they get bumped out of this buffer
141 :
142 : size_t mRequiredSpaceForEvicted = 0; ///< Required space for previous buffer to evict event to new buffer
143 :
144 : CHIP_ERROR OnInit(TLV::TLVWriter & writer, uint8_t *& bufStart, uint32_t & bufLen) override;
145 : };
146 :
147 : class CircularEventReader;
148 :
149 : /**
150 : * @brief
151 : * A CircularEventBufferWrapper which has a pointer to the "current CircularEventBuffer". When trying to locate next buffer,
152 : * if nothing left there update its CircularEventBuffer until the buffer with data has been found,
153 : * the tlv reader will have a pointer to this impl.
154 : */
155 : class CircularEventBufferWrapper : public TLV::TLVCircularBuffer
156 : {
157 : public:
158 870 : CircularEventBufferWrapper() : TLVCircularBuffer(nullptr, 0), mpCurrent(nullptr){};
159 : CircularEventBuffer * mpCurrent;
160 :
161 : private:
162 : CHIP_ERROR GetNextBuffer(chip::TLV::TLVReader & aReader, const uint8_t *& aBufStart, uint32_t & aBufLen) override;
163 : };
164 :
165 : enum class EventManagementStates
166 : {
167 : Idle = 1, // No log offload in progress, log offload can begin without any constraints
168 : InProgress = 2, // Log offload in progress
169 : Shutdown = 3 // Not capable of performing any logging operation
170 : };
171 :
172 : /**
173 : * @brief
174 : * A helper class used in initializing logging management.
175 : *
176 : * The class is used to encapsulate the resources allocated by the caller and denotes
177 : * resources to be used in logging events of a particular priority. Note that
178 : * while resources referring to the counters are used exclusively by the
179 : * particular priority level, the buffers are shared between `this` priority
180 : * level and events that are "more" important.
181 : */
182 :
183 : struct LogStorageResources
184 : {
185 : // TODO: Update TLVCircularBuffer with size_t for buffer size, then use ByteSpan
186 : uint8_t * mpBuffer =
187 : nullptr; // Buffer to be used as a storage at the particular priority level and shared with more important events.
188 : // Must not be nullptr. Must be large enough to accommodate the largest event emitted by the system.
189 : uint32_t mBufferSize = 0; ///< The size, in bytes, of the `mBuffer`.
190 : PriorityLevel mPriority =
191 : PriorityLevel::Invalid; // Log priority level associated with the resources provided in this structure.
192 : };
193 :
194 : /**
195 : * @brief
196 : * A class for managing the in memory event logs. See documentation at the
197 : * top of the file describing the eviction policy for events when there is no
198 : * more space for new events.
199 : */
200 :
201 : class EventManagement : public DataModel::EventsGenerator
202 : {
203 : public:
204 : /**
205 : * Initialize the EventManagement with an array of LogStorageResources and
206 : * an equal-length array of CircularEventBuffers that correspond to those
207 : * LogStorageResources. The array of LogStorageResources must provide a
208 : * resource for each valid priority level, the elements of the array must be
209 : * in increasing numerical value of priority (and in increasing priority);
210 : * the first element in the array corresponds to the resources allocated for
211 : * least important events, and the last element corresponds to the most
212 : * critical events.
213 : *
214 : * @param[in] apExchangeManager ExchangeManager to be used with this logging subsystem
215 : *
216 : * @param[in] aNumBuffers Number of elements in the apLogStorageResources
217 : * and apCircularEventBuffer arrays.
218 : *
219 : * @param[in] apCircularEventBuffer An array of CircularEventBuffer for each priority level.
220 : *
221 : * @param[in] apLogStorageResources An array of LogStorageResources for each priority level.
222 : *
223 : * @param[in] apEventNumberCounter A counter to use for event numbers.
224 : *
225 : * @param[in] aMonotonicStartupTime Time we should consider as "monotonic
226 : * time 0" for cases when we use
227 : * system-time event timestamps.
228 : *
229 : * @param[in] apEventReporter Event reporter to be notified when events are generated.
230 : *
231 : * @return CHIP_ERROR CHIP Error Code
232 : *
233 : */
234 : CHIP_ERROR Init(Messaging::ExchangeManager * apExchangeManager, uint32_t aNumBuffers,
235 : CircularEventBuffer * apCircularEventBuffer, const LogStorageResources * const apLogStorageResources,
236 : MonotonicallyIncreasingCounter<EventNumber> * apEventNumberCounter,
237 : System::Clock::Milliseconds64 aMonotonicStartupTime, EventReporter * apEventReporter);
238 :
239 : static EventManagement & GetInstance();
240 :
241 : /**
242 : * @brief Create EventManagement object and initialize the logging management
243 : * subsystem with provided resources.
244 : *
245 : * Initialize the EventManagement with an array of LogStorageResources. The
246 : * array must provide a resource for each valid priority level, the elements
247 : * of the array must be in increasing numerical value of priority (and in
248 : * decreasing priority); the first element in the array corresponds to the
249 : * resources allocated for the most critical events, and the last element
250 : * corresponds to the least important events.
251 : *
252 : * @param[in] apExchangeManager ExchangeManager to be used with this logging subsystem
253 : *
254 : * @param[in] aNumBuffers Number of elements in inLogStorageResources array
255 : *
256 : * @param[in] apCircularEventBuffer An array of CircularEventBuffer for each priority level.
257 : * @param[in] apLogStorageResources An array of LogStorageResources for each priority level.
258 : *
259 : * @param[in] apEventNumberCounter A counter to use for event numbers.
260 : *
261 : * @param[in] aMonotonicStartupTime Time we should consider as "monotonic
262 : * time 0" for cases when we use
263 : * system-time event timestamps.
264 : *
265 : * @note This function must be called prior to the logging being used.
266 : */
267 : static void
268 : CreateEventManagement(Messaging::ExchangeManager * apExchangeManager, uint32_t aNumBuffers,
269 : CircularEventBuffer * apCircularEventBuffer, const LogStorageResources * const apLogStorageResources,
270 : MonotonicallyIncreasingCounter<EventNumber> * apEventNumberCounter,
271 : System::Clock::Milliseconds64 aMonotonicStartupTime = System::SystemClock().GetMonotonicMilliseconds64());
272 :
273 : static void DestroyEventManagement();
274 :
275 : /**
276 : * @brief
277 : * Log an event via a EventLoggingDelegate, with options.
278 : *
279 : * The EventLoggingDelegate writes the event metadata and calls the `apDelegate`
280 : * with an TLV::TLVWriter reference so that the user code can emit
281 : * the event data directly into the event log. This form of event
282 : * logging minimizes memory consumption, as event data is serialized
283 : * directly into the target buffer. The event data MUST contain
284 : * context tags to be interpreted within the schema identified by
285 : * `ClusterID` and `EventId`. The tag of the first element will be
286 : * ignored; the event logging system will replace it with the
287 : * eventData tag.
288 : *
289 : * The event is logged if the schema priority exceeds the logging
290 : * threshold specified in the LoggingConfiguration. If the event's
291 : * priority does not meet the current threshold, it is dropped and
292 : * the function returns a `0` as the resulting event ID.
293 : *
294 : * @param[in] apDelegate The EventLoggingDelegate to serialize the event data
295 : *
296 : * @param[in] aEventOptions The options for the event metadata.
297 : *
298 : * @param[out] aEventNumber The event Number if the event was written to the
299 : * log, 0 otherwise.
300 : *
301 : * @return CHIP_ERROR CHIP Error Code
302 : */
303 : CHIP_ERROR LogEvent(EventLoggingDelegate * apDelegate, const EventOptions & aEventOptions, EventNumber & aEventNumber);
304 :
305 : /**
306 : * @brief
307 : * A helper method to get tlv reader along with buffer has data from particular priority
308 : *
309 : * @param[in,out] aReader A reference to the reader that will be
310 : * initialized with the backing storage from
311 : * the event log
312 : *
313 : * @param[in] aPriority The starting priority for the reader.
314 : * Note that in this case the starting
315 : * priority is somewhat counter intuitive:
316 : * more important events share the buffers
317 : * with less priority events, in addition to
318 : * their dedicated buffers. As a result, the
319 : * reader will traverse the least data when
320 : * the Debug priority is passed in.
321 : *
322 : * @param[in] apBufWrapper CircularEventBufferWrapper
323 : * @return #CHIP_NO_ERROR Unconditionally.
324 : */
325 : CHIP_ERROR GetEventReader(chip::TLV::TLVReader & aReader, PriorityLevel aPriority,
326 : app::CircularEventBufferWrapper * apBufWrapper);
327 :
328 : /**
329 : * @brief
330 : * A function to retrieve events of specified priority since a specified event ID.
331 : *
332 : * Given a TLV::TLVWriter, an priority type, and an event ID, the
333 : * function will fetch events since the
334 : * specified event number. The function will continue fetching events until
335 : * it runs out of space in the TLV::TLVWriter or in the log. The function
336 : * will terminate the event writing on event boundary. The function would filter out event based upon interested path
337 : * specified by read/subscribe request.
338 : *
339 : * @param[in] aWriter The writer to use for event storage
340 : * @param[in] apEventPathList the interested EventPathParams list
341 : *
342 : * @param[in,out] aEventMin On input, the Event number is the one we're fetching. On
343 : * completion, the event number of the next one we plan to fetch.
344 : *
345 : * @param[out] aEventCount The number of fetched event
346 : * @param[in] aSubjectDescriptor Subject descriptor for current read handler
347 : * @retval #CHIP_END_OF_TLV The function has reached the end of the
348 : * available log entries at the specified
349 : * priority level
350 : *
351 : * @retval #CHIP_ERROR_NO_MEMORY The function ran out of space in the
352 : * aWriter, more events in the log are
353 : * available.
354 : *
355 : * @retval #CHIP_ERROR_BUFFER_TOO_SMALL The function ran out of space in the
356 : * aWriter, more events in the log are
357 : * available.
358 : *
359 : */
360 : CHIP_ERROR FetchEventsSince(chip::TLV::TLVWriter & aWriter, const SingleLinkedListNode<EventPathParams> * apEventPathList,
361 : EventNumber & aEventMin, size_t & aEventCount,
362 : const Access::SubjectDescriptor & aSubjectDescriptor);
363 : /**
364 : * @brief brief Iterate all events and invalidate the fabric-sensitive events whose associated fabric has the given fabric
365 : * index.
366 : */
367 : CHIP_ERROR FabricRemoved(FabricIndex aFabricIndex);
368 :
369 : /**
370 : * @brief
371 : * Fetch the most recently vended Number for a particular priority level
372 : *
373 : * @return EventNumber most recently vended event Number for that event priority
374 : */
375 1024 : EventNumber GetLastEventNumber() const { return mLastEventNumber; }
376 :
377 : /**
378 : * @brief
379 : * IsValid returns whether the EventManagement instance is valid
380 : */
381 890 : bool IsValid(void) { return EventManagementStates::Shutdown != mState; };
382 :
383 : /**
384 : * Logger would save last logged event number and initial written event bytes number into schedule event number array
385 : */
386 : void SetScheduledEventInfo(EventNumber & aEventNumber, uint32_t & aInitialWrittenEventBytes) const;
387 :
388 : /* EventsGenerator implementation */
389 : CHIP_ERROR GenerateEvent(EventLoggingDelegate * eventPayloadWriter, const EventOptions & options,
390 : EventNumber & generatedEventNumber) override;
391 :
392 : private:
393 : class InternalEventOptions : public EventOptions
394 : {
395 : public:
396 662 : InternalEventOptions() {}
397 662 : InternalEventOptions(Timestamp aTimestamp) : mTimestamp(aTimestamp) {}
398 : Timestamp mTimestamp;
399 : };
400 :
401 : /**
402 : * @brief
403 : * Internal structure for traversing events.
404 : */
405 : struct EventEnvelopeContext
406 : {
407 4348 : EventEnvelopeContext() {}
408 :
409 : int mFieldsToRead = 0;
410 : /* PriorityLevel and DeltaTime are there if that is not first event when putting events in report*/
411 : #if CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
412 : Timestamp mCurrentTime = Timestamp::Epoch(System::Clock::kZero);
413 : #else // CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
414 : Timestamp mCurrentTime = Timestamp::System(System::Clock::kZero);
415 : #endif // CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
416 : PriorityLevel mPriority = PriorityLevel::First;
417 : ClusterId mClusterId = 0;
418 : EndpointId mEndpointId = 0;
419 : EventId mEventId = 0;
420 : EventNumber mEventNumber = 0;
421 : Optional<FabricIndex> mFabricIndex;
422 : };
423 :
424 : void VendEventNumber();
425 : CHIP_ERROR CalculateEventSize(EventLoggingDelegate * apDelegate, const InternalEventOptions * apOptions,
426 : uint32_t & requiredSize);
427 : /**
428 : * @brief Helper function for writing event header and data according to event
429 : * logging protocol.
430 : *
431 : * @param[in,out] apContext EventLoadOutContext, initialized with stateful
432 : * information for the buffer. State is updated
433 : * and preserved by ConstructEvent using this context.
434 : *
435 : * @param[in] apDelegate The EventLoggingDelegate to serialize the event data
436 : *
437 : * @param[in] apOptions InternalEventOptions describing timestamp and other tags
438 : * relevant to this event.
439 : *
440 : */
441 : CHIP_ERROR ConstructEvent(EventLoadOutContext * apContext, EventLoggingDelegate * apDelegate,
442 : const InternalEventOptions * apOptions);
443 :
444 : // Internal function to log event
445 : CHIP_ERROR LogEventPrivate(EventLoggingDelegate * apDelegate, const EventOptions & aEventOptions, EventNumber & aEventNumber);
446 :
447 : /**
448 : * @brief copy the event outright to next buffer with higher priority
449 : *
450 : * @param[in] apEventBuffer CircularEventBuffer
451 : *
452 : */
453 : CHIP_ERROR CopyToNextBuffer(CircularEventBuffer * apEventBuffer);
454 :
455 : /**
456 : * @brief Ensure that:
457 : *
458 : * 1) There could be aRequiredSpace bytes available (if enough things were
459 : * evicted) in all buffers that can hold events with priority aPriority.
460 : *
461 : * 2) There are in fact aRequiredSpace bytes available in our
462 : * lowest-priority buffer. This might involve evicting some events to
463 : * higher-priority buffers or dropping them.
464 : *
465 : * @param[in] aRequiredSpace required space
466 : * @param[in] aPriority priority of the event we are making space for.
467 : *
468 : */
469 : CHIP_ERROR EnsureSpaceInCircularBuffer(size_t aRequiredSpace, PriorityLevel aPriority);
470 :
471 : /**
472 : * @brief Iterate the event elements inside event tlv and mark the fabric index as kUndefinedFabricIndex if
473 : * it matches the FabricIndex apFabricIndex points to.
474 : *
475 : * @param[in] aReader event tlv reader
476 : * @param[in] apFabricIndex A FabricIndex* pointing to the fabric index for which we want to effectively evict events.
477 : *
478 : */
479 : static CHIP_ERROR FabricRemovedCB(const TLV::TLVReader & aReader, size_t, void * apFabricIndex);
480 :
481 : /**
482 : * @brief
483 : * Internal API used to implement #FetchEventsSince
484 : *
485 : * Iterator function to used to copy an event from the log into a
486 : * TLVWriter. The included apContext contains the context of the copy
487 : * operation, including the TLVWriter that will hold the copy of an
488 : * event. If event cannot be written as a whole, the TLVWriter will
489 : * be rolled back to event boundary.
490 : *
491 : * @retval #CHIP_END_OF_TLV Function reached the end of the event
492 : * @retval #CHIP_ERROR_NO_MEMORY Function could not write a portion of
493 : * the event to the TLVWriter.
494 : * @retval #CHIP_ERROR_BUFFER_TOO_SMALL Function could not write a
495 : * portion of the event to the TLVWriter.
496 : */
497 : static CHIP_ERROR CopyEventsSince(const TLV::TLVReader & aReader, size_t aDepth, void * apContext);
498 :
499 : /**
500 : * @brief Internal iterator function used to scan and filter though event logs
501 : *
502 : * The function is used to scan through the event log to find events matching the spec in the supplied context.
503 : * Particularly, it would check against mStartingEventNumber, and skip fetched event.
504 : */
505 : static CHIP_ERROR EventIterator(const TLV::TLVReader & aReader, size_t aDepth, EventLoadOutContext * apEventLoadOutContext,
506 : EventEnvelopeContext * event);
507 :
508 : /**
509 : * @brief Internal iterator function used to fetch event into EventEnvelopeContext, then EventIterator would filter event
510 : * based upon EventEnvelopeContext
511 : *
512 : */
513 : static CHIP_ERROR FetchEventParameters(const TLV::TLVReader & aReader, size_t aDepth, void * apContext);
514 :
515 : /**
516 : * @brief Internal iterator function used to scan and filter though event logs
517 : * First event gets a timestamp, subsequent ones get a delta T
518 : * First event in the sequence gets a event number neatly packaged
519 : */
520 : static CHIP_ERROR CopyAndAdjustDeltaTime(const TLV::TLVReader & aReader, size_t aDepth, void * apContext);
521 :
522 : /**
523 : * @brief checking if the tail's event can be moved to higher priority, if not, dropped, if yes, note how much space it
524 : * requires, and return.
525 : */
526 : static CHIP_ERROR EvictEvent(chip::TLV::TLVCircularBuffer & aBuffer, void * apAppData, TLV::TLVReader & aReader);
527 0 : static CHIP_ERROR AlwaysFail(chip::TLV::TLVCircularBuffer & aBuffer, void * apAppData, TLV::TLVReader & aReader)
528 : {
529 0 : return CHIP_ERROR_NO_MEMORY;
530 : };
531 :
532 : /**
533 : * @brief Check whether the event instance represented by the EventEnvelopeContext should be included in the report.
534 : *
535 : * @retval CHIP_ERROR_UNEXPECTED_EVENT This path should be excluded in the generated event report.
536 : * @retval CHIP_EVENT_ID_FOUND This path should be included in the generated event report.
537 : * @retval CHIP_ERROR_ACCESS_DENIED This path should be included in the generated event report, but the client does not have
538 : * . enough privilege to access it.
539 : *
540 : * TODO: Consider using CHIP_NO_ERROR, CHIP_ERROR_SKIP_EVENT, CHIP_ERROR_ACCESS_DENINED or some enum to represent the checking
541 : * result.
542 : */
543 : static CHIP_ERROR CheckEventContext(EventLoadOutContext * eventLoadOutContext, const EventEnvelopeContext & event);
544 :
545 : /**
546 : * @brief copy event from circular buffer to target buffer for report
547 : */
548 : static CHIP_ERROR CopyEvent(const TLV::TLVReader & aReader, TLV::TLVWriter & aWriter, EventLoadOutContext * apContext);
549 :
550 : /**
551 : * @brief
552 : * A function to get the circular buffer for particular priority
553 : *
554 : * @param aPriority PriorityLevel
555 : *
556 : * @return A pointer for the CircularEventBuffer
557 : */
558 : CircularEventBuffer * GetPriorityBuffer(PriorityLevel aPriority) const;
559 :
560 : // EventBuffer for debug level,
561 : CircularEventBuffer * mpEventBuffer = nullptr;
562 : Messaging::ExchangeManager * mpExchangeMgr = nullptr;
563 : EventManagementStates mState = EventManagementStates::Shutdown;
564 : uint32_t mBytesWritten = 0;
565 :
566 : // The counter we're going to use for event numbers.
567 : MonotonicallyIncreasingCounter<EventNumber> * mpEventNumberCounter = nullptr;
568 :
569 : EventNumber mLastEventNumber = 0; ///< Last event Number vended
570 : Timestamp mLastEventTimestamp; ///< The timestamp of the last event in this buffer
571 :
572 : System::Clock::Milliseconds64 mMonotonicStartupTime;
573 :
574 : EventReporter * mpEventReporter = nullptr;
575 : };
576 :
577 : } // namespace app
578 : } // namespace chip
|