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 3 : 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 452 : ~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 : * This variant of the invocation permits the caller to set any
295 : * combination of `EventOptions`:
296 : * - timestamp, when 0 defaults to the current time at the point of
297 : * the call,
298 : * - "root" section of the event source (event source and cluster ID);
299 : * if NULL, it defaults to the current device. the event is marked as
300 : * relating to the device that is making the call,
301 : *
302 : * @param[in] apDelegate The EventLoggingDelegate to serialize the event data
303 : *
304 : * @param[in] aEventOptions The options for the event metadata.
305 : *
306 : * @param[out] aEventNumber The event Number if the event was written to the
307 : * log, 0 otherwise.
308 : *
309 : * @return CHIP_ERROR CHIP Error Code
310 : */
311 : CHIP_ERROR LogEvent(EventLoggingDelegate * apDelegate, const EventOptions & aEventOptions, EventNumber & aEventNumber);
312 :
313 : /**
314 : * @brief
315 : * A helper method to get tlv reader along with buffer has data from particular priority
316 : *
317 : * @param[in,out] aReader A reference to the reader that will be
318 : * initialized with the backing storage from
319 : * the event log
320 : *
321 : * @param[in] aPriority The starting priority for the reader.
322 : * Note that in this case the starting
323 : * priority is somewhat counter intuitive:
324 : * more important events share the buffers
325 : * with less priority events, in addition to
326 : * their dedicated buffers. As a result, the
327 : * reader will traverse the least data when
328 : * the Debug priority is passed in.
329 : *
330 : * @param[in] apBufWrapper CircularEventBufferWrapper
331 : * @return #CHIP_NO_ERROR Unconditionally.
332 : */
333 : CHIP_ERROR GetEventReader(chip::TLV::TLVReader & aReader, PriorityLevel aPriority,
334 : app::CircularEventBufferWrapper * apBufWrapper);
335 :
336 : /**
337 : * @brief
338 : * A function to retrieve events of specified priority since a specified event ID.
339 : *
340 : * Given a TLV::TLVWriter, an priority type, and an event ID, the
341 : * function will fetch events since the
342 : * specified event number. The function will continue fetching events until
343 : * it runs out of space in the TLV::TLVWriter or in the log. The function
344 : * will terminate the event writing on event boundary. The function would filter out event based upon interested path
345 : * specified by read/subscribe request.
346 : *
347 : * @param[in] aWriter The writer to use for event storage
348 : * @param[in] apEventPathList the interested EventPathParams list
349 : *
350 : * @param[in,out] aEventMin On input, the Event number is the one we're fetching. On
351 : * completion, the event number of the next one we plan to fetch.
352 : *
353 : * @param[out] aEventCount The number of fetched event
354 : * @param[in] aSubjectDescriptor Subject descriptor for current read handler
355 : * @retval #CHIP_END_OF_TLV The function has reached the end of the
356 : * available log entries at the specified
357 : * priority level
358 : *
359 : * @retval #CHIP_ERROR_NO_MEMORY The function ran out of space in the
360 : * aWriter, more events in the log are
361 : * available.
362 : *
363 : * @retval #CHIP_ERROR_BUFFER_TOO_SMALL The function ran out of space in the
364 : * aWriter, more events in the log are
365 : * available.
366 : *
367 : */
368 : CHIP_ERROR FetchEventsSince(chip::TLV::TLVWriter & aWriter, const SingleLinkedListNode<EventPathParams> * apEventPathList,
369 : EventNumber & aEventMin, size_t & aEventCount,
370 : const Access::SubjectDescriptor & aSubjectDescriptor);
371 : /**
372 : * @brief brief Iterate all events and invalidate the fabric-sensitive events whose associated fabric has the given fabric
373 : * index.
374 : */
375 : CHIP_ERROR FabricRemoved(FabricIndex aFabricIndex);
376 :
377 : /**
378 : * @brief
379 : * Fetch the most recently vended Number for a particular priority level
380 : *
381 : * @return EventNumber most recently vended event Number for that event priority
382 : */
383 1024 : EventNumber GetLastEventNumber() const { return mLastEventNumber; }
384 :
385 : /**
386 : * @brief
387 : * IsValid returns whether the EventManagement instance is valid
388 : */
389 890 : bool IsValid(void) { return EventManagementStates::Shutdown != mState; };
390 :
391 : /**
392 : * Logger would save last logged event number and initial written event bytes number into schedule event number array
393 : */
394 : void SetScheduledEventInfo(EventNumber & aEventNumber, uint32_t & aInitialWrittenEventBytes) const;
395 :
396 : /* EventsGenerator implementation */
397 : CHIP_ERROR GenerateEvent(EventLoggingDelegate * eventPayloadWriter, const EventOptions & options,
398 : EventNumber & generatedEventNumber) override;
399 :
400 : private:
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 EventOptions * apOptions, uint32_t & requiredSize);
426 : /**
427 : * @brief Helper function for writing event header and data according to event
428 : * logging protocol.
429 : *
430 : * @param[in,out] apContext EventLoadOutContext, initialized with stateful
431 : * information for the buffer. State is updated
432 : * and preserved by ConstructEvent using this context.
433 : *
434 : * @param[in] apDelegate The EventLoggingDelegate to serialize the event data
435 : *
436 : * @param[in] apOptions EventOptions describing timestamp and other tags
437 : * relevant to this event.
438 : *
439 : */
440 : CHIP_ERROR ConstructEvent(EventLoadOutContext * apContext, EventLoggingDelegate * apDelegate, const EventOptions * apOptions);
441 :
442 : // Internal function to log event
443 : CHIP_ERROR LogEventPrivate(EventLoggingDelegate * apDelegate, const EventOptions & aEventOptions, EventNumber & aEventNumber);
444 :
445 : /**
446 : * @brief copy the event outright to next buffer with higher priority
447 : *
448 : * @param[in] apEventBuffer CircularEventBuffer
449 : *
450 : */
451 : CHIP_ERROR CopyToNextBuffer(CircularEventBuffer * apEventBuffer);
452 :
453 : /**
454 : * @brief Ensure that:
455 : *
456 : * 1) There could be aRequiredSpace bytes available (if enough things were
457 : * evicted) in all buffers that can hold events with priority aPriority.
458 : *
459 : * 2) There are in fact aRequiredSpace bytes available in our
460 : * lowest-priority buffer. This might involve evicting some events to
461 : * higher-priority buffers or dropping them.
462 : *
463 : * @param[in] aRequiredSpace required space
464 : * @param[in] aPriority priority of the event we are making space for.
465 : *
466 : */
467 : CHIP_ERROR EnsureSpaceInCircularBuffer(size_t aRequiredSpace, PriorityLevel aPriority);
468 :
469 : /**
470 : * @brief Iterate the event elements inside event tlv and mark the fabric index as kUndefinedFabricIndex if
471 : * it matches the FabricIndex apFabricIndex points to.
472 : *
473 : * @param[in] aReader event tlv reader
474 : * @param[in] apFabricIndex A FabricIndex* pointing to the fabric index for which we want to effectively evict events.
475 : *
476 : */
477 : static CHIP_ERROR FabricRemovedCB(const TLV::TLVReader & aReader, size_t, void * apFabricIndex);
478 :
479 : /**
480 : * @brief
481 : * Internal API used to implement #FetchEventsSince
482 : *
483 : * Iterator function to used to copy an event from the log into a
484 : * TLVWriter. The included apContext contains the context of the copy
485 : * operation, including the TLVWriter that will hold the copy of an
486 : * event. If event cannot be written as a whole, the TLVWriter will
487 : * be rolled back to event boundary.
488 : *
489 : * @retval #CHIP_END_OF_TLV Function reached the end of the event
490 : * @retval #CHIP_ERROR_NO_MEMORY Function could not write a portion of
491 : * the event to the TLVWriter.
492 : * @retval #CHIP_ERROR_BUFFER_TOO_SMALL Function could not write a
493 : * portion of the event to the TLVWriter.
494 : */
495 : static CHIP_ERROR CopyEventsSince(const TLV::TLVReader & aReader, size_t aDepth, void * apContext);
496 :
497 : /**
498 : * @brief Internal iterator function used to scan and filter though event logs
499 : *
500 : * The function is used to scan through the event log to find events matching the spec in the supplied context.
501 : * Particularly, it would check against mStartingEventNumber, and skip fetched event.
502 : */
503 : static CHIP_ERROR EventIterator(const TLV::TLVReader & aReader, size_t aDepth, EventLoadOutContext * apEventLoadOutContext,
504 : EventEnvelopeContext * event);
505 :
506 : /**
507 : * @brief Internal iterator function used to fetch event into EventEnvelopeContext, then EventIterator would filter event
508 : * based upon EventEnvelopeContext
509 : *
510 : */
511 : static CHIP_ERROR FetchEventParameters(const TLV::TLVReader & aReader, size_t aDepth, void * apContext);
512 :
513 : /**
514 : * @brief Internal iterator function used to scan and filter though event logs
515 : * First event gets a timestamp, subsequent ones get a delta T
516 : * First event in the sequence gets a event number neatly packaged
517 : */
518 : static CHIP_ERROR CopyAndAdjustDeltaTime(const TLV::TLVReader & aReader, size_t aDepth, void * apContext);
519 :
520 : /**
521 : * @brief checking if the tail's event can be moved to higher priority, if not, dropped, if yes, note how much space it
522 : * requires, and return.
523 : */
524 : static CHIP_ERROR EvictEvent(chip::TLV::TLVCircularBuffer & aBuffer, void * apAppData, TLV::TLVReader & aReader);
525 0 : static CHIP_ERROR AlwaysFail(chip::TLV::TLVCircularBuffer & aBuffer, void * apAppData, TLV::TLVReader & aReader)
526 : {
527 0 : return CHIP_ERROR_NO_MEMORY;
528 : };
529 :
530 : /**
531 : * @brief Check whether the event instance represented by the EventEnvelopeContext should be included in the report.
532 : *
533 : * @retval CHIP_ERROR_UNEXPECTED_EVENT This path should be excluded in the generated event report.
534 : * @retval CHIP_EVENT_ID_FOUND This path should be included in the generated event report.
535 : * @retval CHIP_ERROR_ACCESS_DENIED This path should be included in the generated event report, but the client does not have
536 : * . enough privilege to access it.
537 : *
538 : * TODO: Consider using CHIP_NO_ERROR, CHIP_ERROR_SKIP_EVENT, CHIP_ERROR_ACCESS_DENINED or some enum to represent the checking
539 : * result.
540 : */
541 : static CHIP_ERROR CheckEventContext(EventLoadOutContext * eventLoadOutContext, const EventEnvelopeContext & event);
542 :
543 : /**
544 : * @brief copy event from circular buffer to target buffer for report
545 : */
546 : static CHIP_ERROR CopyEvent(const TLV::TLVReader & aReader, TLV::TLVWriter & aWriter, EventLoadOutContext * apContext);
547 :
548 : /**
549 : * @brief
550 : * A function to get the circular buffer for particular priority
551 : *
552 : * @param aPriority PriorityLevel
553 : *
554 : * @return A pointer for the CircularEventBuffer
555 : */
556 : CircularEventBuffer * GetPriorityBuffer(PriorityLevel aPriority) const;
557 :
558 : // EventBuffer for debug level,
559 : CircularEventBuffer * mpEventBuffer = nullptr;
560 : Messaging::ExchangeManager * mpExchangeMgr = nullptr;
561 : EventManagementStates mState = EventManagementStates::Shutdown;
562 : uint32_t mBytesWritten = 0;
563 :
564 : // The counter we're going to use for event numbers.
565 : MonotonicallyIncreasingCounter<EventNumber> * mpEventNumberCounter = nullptr;
566 :
567 : EventNumber mLastEventNumber = 0; ///< Last event Number vended
568 : Timestamp mLastEventTimestamp; ///< The timestamp of the last event in this buffer
569 :
570 : System::Clock::Milliseconds64 mMonotonicStartupTime;
571 :
572 : EventReporter * mpEventReporter = nullptr;
573 : };
574 :
575 : } // namespace app
576 : } // namespace chip
|