Matter SDK Coverage Report
Current view: top level - app - EventManagement.h (source / functions) Coverage Total Hit
Test: SHA:b879ecb8e99e175eea0a293a888bda853da2b19c Lines: 84.6 % 13 11
Test Date: 2025-01-17 19:00:11 Functions: 84.6 % 13 11

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

Generated by: LCOV version 2.0-1