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 : inline 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 : * Note: Even though this class is used as a singleton, the default constructor is public in
206 : * order to preserve the ability to instantiate this class in test code. This is meant to be
207 : * temporary until we find a better solution.
208 : */
209 : constexpr EventManagement() = default;
210 :
211 : /**
212 : * Initialize the EventManagement with an array of LogStorageResources and
213 : * an equal-length array of CircularEventBuffers that correspond to those
214 : * LogStorageResources. The array of LogStorageResources must provide a
215 : * resource for each valid priority level, the elements of the array must be
216 : * in increasing numerical value of priority (and in increasing priority);
217 : * the first element in the array corresponds to the resources allocated for
218 : * least important events, and the last element corresponds to the most
219 : * critical events.
220 : *
221 : * @param[in] apExchangeManager ExchangeManager to be used with this logging subsystem
222 : *
223 : * @param[in] aNumBuffers Number of elements in the apLogStorageResources
224 : * and apCircularEventBuffer arrays.
225 : *
226 : * @param[in] apCircularEventBuffer An array of CircularEventBuffer for each priority level.
227 : *
228 : * @param[in] apLogStorageResources An array of LogStorageResources for each priority level.
229 : *
230 : * @param[in] apEventNumberCounter A counter to use for event numbers.
231 : *
232 : * @param[in] aMonotonicStartupTime Time we should consider as "monotonic
233 : * time 0" for cases when we use
234 : * system-time event timestamps.
235 : *
236 : * @param[in] apEventReporter Event reporter to be notified when events are generated.
237 : *
238 : * @return CHIP_ERROR CHIP Error Code
239 : *
240 : */
241 : CHIP_ERROR Init(Messaging::ExchangeManager * apExchangeManager, uint32_t aNumBuffers,
242 : CircularEventBuffer * apCircularEventBuffer, const LogStorageResources * const apLogStorageResources,
243 : MonotonicallyIncreasingCounter<EventNumber> * apEventNumberCounter,
244 : System::Clock::Milliseconds64 aMonotonicStartupTime, EventReporter * apEventReporter);
245 :
246 : static EventManagement & GetInstance();
247 :
248 : /**
249 : * @brief Create EventManagement object and initialize the logging management
250 : * subsystem with provided resources.
251 : *
252 : * Initialize the EventManagement with an array of LogStorageResources. The
253 : * array must provide a resource for each valid priority level, the elements
254 : * of the array must be in increasing numerical value of priority (and in
255 : * decreasing priority); the first element in the array corresponds to the
256 : * resources allocated for the most critical events, and the last element
257 : * corresponds to the least important events.
258 : *
259 : * @param[in] apExchangeManager ExchangeManager to be used with this logging subsystem
260 : *
261 : * @param[in] aNumBuffers Number of elements in inLogStorageResources array
262 : *
263 : * @param[in] apCircularEventBuffer An array of CircularEventBuffer for each priority level.
264 : * @param[in] apLogStorageResources An array of LogStorageResources for each priority level.
265 : *
266 : * @param[in] apEventNumberCounter A counter to use for event numbers.
267 : *
268 : * @param[in] aMonotonicStartupTime Time we should consider as "monotonic
269 : * time 0" for cases when we use
270 : * system-time event timestamps.
271 : *
272 : * @note This function must be called prior to the logging being used.
273 : */
274 : static void
275 : CreateEventManagement(Messaging::ExchangeManager * apExchangeManager, uint32_t aNumBuffers,
276 : CircularEventBuffer * apCircularEventBuffer, const LogStorageResources * const apLogStorageResources,
277 : MonotonicallyIncreasingCounter<EventNumber> * apEventNumberCounter,
278 : System::Clock::Milliseconds64 aMonotonicStartupTime = System::SystemClock().GetMonotonicMilliseconds64());
279 :
280 : static void DestroyEventManagement();
281 :
282 : /**
283 : * @brief
284 : * Log an event via a EventLoggingDelegate, with options.
285 : *
286 : * The EventLoggingDelegate writes the event metadata and calls the `apDelegate`
287 : * with an TLV::TLVWriter reference so that the user code can emit
288 : * the event data directly into the event log. This form of event
289 : * logging minimizes memory consumption, as event data is serialized
290 : * directly into the target buffer. The event data MUST contain
291 : * context tags to be interpreted within the schema identified by
292 : * `ClusterID` and `EventId`. The tag of the first element will be
293 : * ignored; the event logging system will replace it with the
294 : * eventData tag.
295 : *
296 : * The event is logged if the schema priority exceeds the logging
297 : * threshold specified in the LoggingConfiguration. If the event's
298 : * priority does not meet the current threshold, it is dropped and
299 : * the function returns a `0` as the resulting event ID.
300 : *
301 : * @param[in] apDelegate The EventLoggingDelegate to serialize the event data
302 : *
303 : * @param[in] aEventOptions The options for the event metadata.
304 : *
305 : * @param[out] aEventNumber The event Number if the event was written to the
306 : * log, 0 otherwise.
307 : *
308 : * @return CHIP_ERROR CHIP Error Code
309 : */
310 : CHIP_ERROR LogEvent(EventLoggingDelegate * apDelegate, const EventOptions & aEventOptions, EventNumber & aEventNumber);
311 :
312 : /**
313 : * @brief
314 : * A helper method to get tlv reader along with buffer has data from particular priority
315 : *
316 : * @param[in,out] aReader A reference to the reader that will be
317 : * initialized with the backing storage from
318 : * the event log
319 : *
320 : * @param[in] aPriority The starting priority for the reader.
321 : * Note that in this case the starting
322 : * priority is somewhat counter intuitive:
323 : * more important events share the buffers
324 : * with less priority events, in addition to
325 : * their dedicated buffers. As a result, the
326 : * reader will traverse the least data when
327 : * the Debug priority is passed in.
328 : *
329 : * @param[in] apBufWrapper CircularEventBufferWrapper
330 : * @return #CHIP_NO_ERROR Unconditionally.
331 : */
332 : CHIP_ERROR GetEventReader(chip::TLV::TLVReader & aReader, PriorityLevel aPriority,
333 : app::CircularEventBufferWrapper * apBufWrapper);
334 :
335 : /**
336 : * @brief
337 : * A function to retrieve events of specified priority since a specified event ID.
338 : *
339 : * Given a TLV::TLVWriter, an priority type, and an event ID, the
340 : * function will fetch events since the
341 : * specified event number. The function will continue fetching events until
342 : * it runs out of space in the TLV::TLVWriter or in the log. The function
343 : * will terminate the event writing on event boundary. The function would filter out event based upon interested path
344 : * specified by read/subscribe request.
345 : *
346 : * @param[in] aWriter The writer to use for event storage
347 : * @param[in] apEventPathList the interested EventPathParams list
348 : *
349 : * @param[in,out] aEventMin On input, the Event number is the one we're fetching. On
350 : * completion, the event number of the next one we plan to fetch.
351 : *
352 : * @param[out] aEventCount The number of fetched event
353 : * @param[in] aSubjectDescriptor Subject descriptor for current read handler
354 : * @retval #CHIP_END_OF_TLV The function has reached the end of the
355 : * available log entries at the specified
356 : * priority level
357 : *
358 : * @retval #CHIP_ERROR_NO_MEMORY The function ran out of space in the
359 : * aWriter, more events in the log are
360 : * available.
361 : *
362 : * @retval #CHIP_ERROR_BUFFER_TOO_SMALL The function ran out of space in the
363 : * aWriter, more events in the log are
364 : * available.
365 : *
366 : */
367 : CHIP_ERROR FetchEventsSince(chip::TLV::TLVWriter & aWriter, const SingleLinkedListNode<EventPathParams> * apEventPathList,
368 : EventNumber & aEventMin, size_t & aEventCount,
369 : const Access::SubjectDescriptor & aSubjectDescriptor);
370 : /**
371 : * @brief brief Iterate all events and invalidate the fabric-sensitive events whose associated fabric has the given fabric
372 : * index.
373 : */
374 : CHIP_ERROR FabricRemoved(FabricIndex aFabricIndex);
375 :
376 : /**
377 : * @brief
378 : * Fetch the most recently vended Number for a particular priority level
379 : *
380 : * @return EventNumber most recently vended event Number for that event priority
381 : */
382 1024 : EventNumber GetLastEventNumber() const { return mLastEventNumber; }
383 :
384 : /**
385 : * @brief
386 : * IsValid returns whether the EventManagement instance is valid
387 : */
388 890 : bool IsValid(void) { return EventManagementStates::Shutdown != mState; };
389 :
390 : /**
391 : * Logger would save last logged event number and initial written event bytes number into schedule event number array
392 : */
393 : void SetScheduledEventInfo(EventNumber & aEventNumber, uint32_t & aInitialWrittenEventBytes) const;
394 :
395 : /* EventsGenerator implementation */
396 : CHIP_ERROR GenerateEvent(EventLoggingDelegate * eventPayloadWriter, const EventOptions & options,
397 : EventNumber & generatedEventNumber) override;
398 :
399 : private:
400 : static EventManagement sInstance;
401 :
402 : class InternalEventOptions : public EventOptions
403 : {
404 : public:
405 662 : InternalEventOptions() {}
406 662 : InternalEventOptions(Timestamp aTimestamp) : mTimestamp(aTimestamp) {}
407 : Timestamp mTimestamp;
408 : };
409 :
410 : /**
411 : * @brief
412 : * Internal structure for traversing events.
413 : */
414 : struct EventEnvelopeContext
415 : {
416 4348 : EventEnvelopeContext() {}
417 :
418 : int mFieldsToRead = 0;
419 : /* PriorityLevel and DeltaTime are there if that is not first event when putting events in report*/
420 : #if CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
421 : Timestamp mCurrentTime = Timestamp::Epoch(System::Clock::kZero);
422 : #else // CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
423 : Timestamp mCurrentTime = Timestamp::System(System::Clock::kZero);
424 : #endif // CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
425 : PriorityLevel mPriority = PriorityLevel::First;
426 : ClusterId mClusterId = 0;
427 : EndpointId mEndpointId = 0;
428 : EventId mEventId = 0;
429 : EventNumber mEventNumber = 0;
430 : Optional<FabricIndex> mFabricIndex;
431 : };
432 :
433 : void VendEventNumber();
434 : CHIP_ERROR CalculateEventSize(EventLoggingDelegate * apDelegate, const InternalEventOptions * apOptions,
435 : uint32_t & requiredSize);
436 : /**
437 : * @brief Helper function for writing event header and data according to event
438 : * logging protocol.
439 : *
440 : * @param[in,out] apContext EventLoadOutContext, initialized with stateful
441 : * information for the buffer. State is updated
442 : * and preserved by ConstructEvent using this context.
443 : *
444 : * @param[in] apDelegate The EventLoggingDelegate to serialize the event data
445 : *
446 : * @param[in] apOptions InternalEventOptions describing timestamp and other tags
447 : * relevant to this event.
448 : *
449 : */
450 : CHIP_ERROR ConstructEvent(EventLoadOutContext * apContext, EventLoggingDelegate * apDelegate,
451 : const InternalEventOptions * apOptions);
452 :
453 : // Internal function to log event
454 : CHIP_ERROR LogEventPrivate(EventLoggingDelegate * apDelegate, const EventOptions & aEventOptions, EventNumber & aEventNumber);
455 :
456 : /**
457 : * @brief copy the event outright to next buffer with higher priority
458 : *
459 : * @param[in] apEventBuffer CircularEventBuffer
460 : *
461 : */
462 : CHIP_ERROR CopyToNextBuffer(CircularEventBuffer * apEventBuffer);
463 :
464 : /**
465 : * @brief Ensure that:
466 : *
467 : * 1) There could be aRequiredSpace bytes available (if enough things were
468 : * evicted) in all buffers that can hold events with priority aPriority.
469 : *
470 : * 2) There are in fact aRequiredSpace bytes available in our
471 : * lowest-priority buffer. This might involve evicting some events to
472 : * higher-priority buffers or dropping them.
473 : *
474 : * @param[in] aRequiredSpace required space
475 : * @param[in] aPriority priority of the event we are making space for.
476 : *
477 : */
478 : CHIP_ERROR EnsureSpaceInCircularBuffer(size_t aRequiredSpace, PriorityLevel aPriority);
479 :
480 : /**
481 : * @brief Iterate the event elements inside event tlv and mark the fabric index as kUndefinedFabricIndex if
482 : * it matches the FabricIndex apFabricIndex points to.
483 : *
484 : * @param[in] aReader event tlv reader
485 : * @param[in] apFabricIndex A FabricIndex* pointing to the fabric index for which we want to effectively evict events.
486 : *
487 : */
488 : static CHIP_ERROR FabricRemovedCB(const TLV::TLVReader & aReader, size_t, void * apFabricIndex);
489 :
490 : /**
491 : * @brief
492 : * Internal API used to implement #FetchEventsSince
493 : *
494 : * Iterator function to used to copy an event from the log into a
495 : * TLVWriter. The included apContext contains the context of the copy
496 : * operation, including the TLVWriter that will hold the copy of an
497 : * event. If event cannot be written as a whole, the TLVWriter will
498 : * be rolled back to event boundary.
499 : *
500 : * @retval #CHIP_END_OF_TLV Function reached the end of the event
501 : * @retval #CHIP_ERROR_NO_MEMORY Function could not write a portion of
502 : * the event to the TLVWriter.
503 : * @retval #CHIP_ERROR_BUFFER_TOO_SMALL Function could not write a
504 : * portion of the event to the TLVWriter.
505 : */
506 : static CHIP_ERROR CopyEventsSince(const TLV::TLVReader & aReader, size_t aDepth, void * apContext);
507 :
508 : /**
509 : * @brief Internal iterator function used to scan and filter though event logs
510 : *
511 : * The function is used to scan through the event log to find events matching the spec in the supplied context.
512 : * Particularly, it would check against mStartingEventNumber, and skip fetched event.
513 : */
514 : static CHIP_ERROR EventIterator(const TLV::TLVReader & aReader, size_t aDepth, EventLoadOutContext * apEventLoadOutContext,
515 : EventEnvelopeContext * event);
516 :
517 : /**
518 : * @brief Internal iterator function used to fetch event into EventEnvelopeContext, then EventIterator would filter event
519 : * based upon EventEnvelopeContext
520 : *
521 : */
522 : static CHIP_ERROR FetchEventParameters(const TLV::TLVReader & aReader, size_t aDepth, void * apContext);
523 :
524 : /**
525 : * @brief Internal iterator function used to scan and filter though event logs
526 : * First event gets a timestamp, subsequent ones get a delta T
527 : * First event in the sequence gets a event number neatly packaged
528 : */
529 : static CHIP_ERROR CopyAndAdjustDeltaTime(const TLV::TLVReader & aReader, size_t aDepth, void * apContext);
530 :
531 : /**
532 : * @brief checking if the tail's event can be moved to higher priority, if not, dropped, if yes, note how much space it
533 : * requires, and return.
534 : */
535 : static CHIP_ERROR EvictEvent(chip::TLV::TLVCircularBuffer & aBuffer, void * apAppData, TLV::TLVReader & aReader);
536 0 : static CHIP_ERROR AlwaysFail(chip::TLV::TLVCircularBuffer & aBuffer, void * apAppData, TLV::TLVReader & aReader)
537 : {
538 0 : return CHIP_ERROR_NO_MEMORY;
539 : };
540 :
541 : /**
542 : * @brief Check whether the event instance represented by the EventEnvelopeContext should be included in the report.
543 : *
544 : * @retval CHIP_ERROR_UNEXPECTED_EVENT This path should be excluded in the generated event report.
545 : * @retval CHIP_EVENT_ID_FOUND This path should be included in the generated event report.
546 : * @retval CHIP_ERROR_ACCESS_DENIED This path should be included in the generated event report, but the client does not have
547 : * . enough privilege to access it.
548 : *
549 : * TODO: Consider using CHIP_NO_ERROR, CHIP_ERROR_SKIP_EVENT, CHIP_ERROR_ACCESS_DENINED or some enum to represent the checking
550 : * result.
551 : */
552 : static CHIP_ERROR CheckEventContext(EventLoadOutContext * eventLoadOutContext, const EventEnvelopeContext & event);
553 :
554 : /**
555 : * @brief copy event from circular buffer to target buffer for report
556 : */
557 : static CHIP_ERROR CopyEvent(const TLV::TLVReader & aReader, TLV::TLVWriter & aWriter, EventLoadOutContext * apContext);
558 :
559 : /**
560 : * @brief
561 : * A function to get the circular buffer for particular priority
562 : *
563 : * @param aPriority PriorityLevel
564 : *
565 : * @return A pointer for the CircularEventBuffer
566 : */
567 : CircularEventBuffer * GetPriorityBuffer(PriorityLevel aPriority) const;
568 :
569 : // EventBuffer for debug level,
570 : CircularEventBuffer * mpEventBuffer = nullptr;
571 : Messaging::ExchangeManager * mpExchangeMgr = nullptr;
572 : EventManagementStates mState = EventManagementStates::Shutdown;
573 : uint32_t mBytesWritten = 0;
574 :
575 : // The counter we're going to use for event numbers.
576 : MonotonicallyIncreasingCounter<EventNumber> * mpEventNumberCounter = nullptr;
577 :
578 : EventNumber mLastEventNumber = 0; ///< Last event Number vended
579 : Timestamp mLastEventTimestamp{}; ///< The timestamp of the last event in this buffer
580 :
581 : System::Clock::Milliseconds64 mMonotonicStartupTime{};
582 :
583 : EventReporter * mpEventReporter = nullptr;
584 : };
585 :
586 : } // namespace app
587 : } // namespace chip
|