Skip to content

Commit

Permalink
[tlv] Rename CHIPCircularTLVBuffer to TLVCircularBuffer. (#24405)
Browse files Browse the repository at this point in the history
  • Loading branch information
turon authored and pull[bot] committed Jul 19, 2023
1 parent 60db5d3 commit 4877393
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 58 deletions.
6 changes: 3 additions & 3 deletions src/app/EventManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ CHIP_ERROR EventManagement::FabricRemovedCB(const TLV::TLVReader & aReader, size
VerifyOrReturnError(event.Get(fabricIndex) == CHIP_NO_ERROR, CHIP_NO_ERROR);
if (fabricIndex == *invalidFabricIndex)
{
CHIPCircularTLVBuffer * readBuffer = static_cast<CHIPCircularTLVBuffer *>(event.GetBackingStore());
TLVCircularBuffer * readBuffer = static_cast<TLVCircularBuffer *>(event.GetBackingStore());
// fabricIndex is encoded as an integer; the dataPtr will point to a location immediately after its encoding
// shift the dataPtr to point to the encoding of the fabric index, accounting for wraparound in backing storage
// we cannot get the actual encoding size from current container beginning to the fabric index because of several
Expand Down Expand Up @@ -796,7 +796,7 @@ CHIP_ERROR EventManagement::FetchEventParameters(const TLVReader & aReader, size
return CHIP_NO_ERROR;
}

CHIP_ERROR EventManagement::EvictEvent(CHIPCircularTLVBuffer & apBuffer, void * apAppData, TLVReader & aReader)
CHIP_ERROR EventManagement::EvictEvent(TLVCircularBuffer & apBuffer, void * apAppData, TLVReader & aReader)
{
// pull out the delta time, pull out the priority
ReturnErrorOnFailure(aReader.Next());
Expand Down Expand Up @@ -847,7 +847,7 @@ void EventManagement::SetScheduledEventInfo(EventNumber & aEventNumber, uint32_t
void CircularEventBuffer::Init(uint8_t * apBuffer, uint32_t aBufferLength, CircularEventBuffer * apPrev,
CircularEventBuffer * apNext, PriorityLevel aPriorityLevel)
{
CHIPCircularTLVBuffer::Init(apBuffer, aBufferLength);
TLVCircularBuffer::Init(apBuffer, aBufferLength);
mpPrev = apPrev;
mpNext = apNext;
mPriority = aPriorityLevel;
Expand Down
18 changes: 9 additions & 9 deletions src/app/EventManagement.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include <app/MessageDef/StatusIB.h>
#include <app/ObjectList.h>
#include <app/util/basic-types.h>
#include <lib/core/CHIPCircularTLVBuffer.h>
#include <lib/core/TLVCircularBuffer.h>
#include <lib/support/CHIPCounter.h>
#include <messaging/ExchangeMgr.h>

Expand All @@ -49,17 +49,17 @@ constexpr uint16_t kRequiredEventField =

/**
* @brief
* Internal event buffer, built around the TLV::CHIPCircularTLVBuffer
* Internal event buffer, built around the TLV::TLVCircularBuffer
*/

class CircularEventBuffer : public TLV::CHIPCircularTLVBuffer
class CircularEventBuffer : public TLV::TLVCircularBuffer
{
public:
/**
* @brief
* A constructor for the CircularEventBuffer (internal API).
*/
CircularEventBuffer() : CHIPCircularTLVBuffer(nullptr, 0){};
CircularEventBuffer() : TLVCircularBuffer(nullptr, 0){};

/**
* @brief
Expand Down Expand Up @@ -119,10 +119,10 @@ class CircularEventReader;
* if nothing left there update its CircularEventBuffer until the buffer with data has been found,
* the tlv reader will have a pointer to this impl.
*/
class CircularEventBufferWrapper : public TLV::CHIPCircularTLVBuffer
class CircularEventBufferWrapper : public TLV::TLVCircularBuffer
{
public:
CircularEventBufferWrapper() : CHIPCircularTLVBuffer(nullptr, 0), mpCurrent(nullptr){};
CircularEventBufferWrapper() : TLVCircularBuffer(nullptr, 0), mpCurrent(nullptr){};
CircularEventBuffer * mpCurrent;

private:
Expand All @@ -149,7 +149,7 @@ enum class EventManagementStates

struct LogStorageResources
{
// TODO: Update CHIPCircularTLVBuffer with size_t for buffer size, then use ByteSpan
// TODO: Update TLVCircularBuffer with size_t for buffer size, then use ByteSpan
uint8_t * mpBuffer =
nullptr; // Buffer to be used as a storage at the particular priority level and shared with more important events.
// Must not be nullptr. Must be large enough to accommodate the largest event emitted by the system.
Expand Down Expand Up @@ -466,8 +466,8 @@ class EventManagement
* @brief checking if the tail's event can be moved to higher priority, if not, dropped, if yes, note how much space it
* requires, and return.
*/
static CHIP_ERROR EvictEvent(chip::TLV::CHIPCircularTLVBuffer & aBuffer, void * apAppData, TLV::TLVReader & aReader);
static CHIP_ERROR AlwaysFail(chip::TLV::CHIPCircularTLVBuffer & aBuffer, void * apAppData, TLV::TLVReader & aReader)
static CHIP_ERROR EvictEvent(chip::TLV::TLVCircularBuffer & aBuffer, void * apAppData, TLV::TLVReader & aReader);
static CHIP_ERROR AlwaysFail(chip::TLV::TLVCircularBuffer & aBuffer, void * apAppData, TLV::TLVReader & aReader)
{
return CHIP_ERROR_NO_MEMORY;
};
Expand Down
4 changes: 2 additions & 2 deletions src/lib/core/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ static_library("core") {
# instead.
"${chip_root}/zzz_generated/app-common/app-common/zap-generated/cluster-enums.h",
"CHIPCallback.h",
"CHIPCircularTLVBuffer.cpp",
"CHIPCircularTLVBuffer.h",
"CHIPCore.h",
"CHIPEncoding.h",
"CHIPError.cpp",
Expand All @@ -110,6 +108,8 @@ static_library("core") {
"PasscodeId.h",
"PeerId.h",
"TLV.h",
"TLVCircularBuffer.cpp",
"TLVCircularBuffer.h",
"TLVDebug.cpp",
"TLVReader.cpp",
"TLVTags.h",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#ifndef __STDC_LIMIT_MACROS
#define __STDC_LIMIT_MACROS
#endif
#include <lib/core/CHIPCircularTLVBuffer.h>
#include <lib/core/TLVCircularBuffer.h>

#include <lib/core/CHIPCore.h>
#include <lib/core/CHIPEncoding.h>
Expand All @@ -47,7 +47,7 @@ using namespace chip::Encoding;

/**
* @brief
* CHIPCircularTLVBuffer constructor
* TLVCircularBuffer constructor
*
* @param[in] inBuffer A pointer to the backing store for the queue
*
Expand All @@ -56,7 +56,7 @@ using namespace chip::Encoding;
* @param[in] inHead Initial point for the head. The @a inHead pointer is must fall within the backing store for the
* circular buffer, i.e. within @a inBuffer and &(@a inBuffer[@a inBufferLength])
*/
CHIPCircularTLVBuffer::CHIPCircularTLVBuffer(uint8_t * inBuffer, uint32_t inBufferLength, uint8_t * inHead)
TLVCircularBuffer::TLVCircularBuffer(uint8_t * inBuffer, uint32_t inBufferLength, uint8_t * inHead)
{
mQueue = inBuffer;
mQueueSize = inBufferLength;
Expand All @@ -74,26 +74,26 @@ CHIPCircularTLVBuffer::CHIPCircularTLVBuffer(uint8_t * inBuffer, uint32_t inBuff

/**
* @brief
* CHIPCircularTLVBuffer constructor
* TLVCircularBuffer constructor
*
* @param[in] inBuffer A pointer to the backing store for the queue
*
* @param[in] inBufferLength Length, in bytes, of the backing store
*/
CHIPCircularTLVBuffer::CHIPCircularTLVBuffer(uint8_t * inBuffer, uint32_t inBufferLength)
TLVCircularBuffer::TLVCircularBuffer(uint8_t * inBuffer, uint32_t inBufferLength)
{
Init(inBuffer, inBufferLength);
}

/**
* @brief
* CHIPCircularTLVBuffer Init function
* TLVCircularBuffer Init function
*
* @param[in] inBuffer A pointer to the backing store for the queue
*
* @param[in] inBufferLength Length, in bytes, of the backing store
*/
void CHIPCircularTLVBuffer::Init(uint8_t * inBuffer, uint32_t inBufferLength)
void TLVCircularBuffer::Init(uint8_t * inBuffer, uint32_t inBufferLength)
{
mQueue = inBuffer;
mQueueSize = inBufferLength;
Expand All @@ -111,23 +111,23 @@ void CHIPCircularTLVBuffer::Init(uint8_t * inBuffer, uint32_t inBufferLength)

/**
* @brief
* Evicts the oldest top-level TLV element in the CHIPCircularTLVBuffer
* Evicts the oldest top-level TLV element in the TLVCircularBuffer
*
* This function removes the oldest top level TLV element in the
* buffer. The function will call the callback registered at
* #mProcessEvictedElement to process the element prior to removal.
* If the callback returns anything but #CHIP_NO_ERROR, the element
* is not removed. Similarly, if any other error occurs -- no
* elements within the buffer, etc -- the underlying
* #CHIPCircularTLVBuffer remains unchanged.
* #TLVCircularBuffer remains unchanged.
*
* @retval #CHIP_NO_ERROR On success.
*
* @retval other On any other error returned either by the callback
* or by the TLVReader.
*
*/
CHIP_ERROR CHIPCircularTLVBuffer::EvictHead()
CHIP_ERROR TLVCircularBuffer::EvictHead()
{
CircularTLVReader reader;
uint8_t * newHead;
Expand Down Expand Up @@ -169,7 +169,7 @@ CHIP_ERROR CHIPCircularTLVBuffer::EvictHead()
* @brief
* Implements TLVBackingStore::OnInit(TLVWriter) for circular buffers.
*/
CHIP_ERROR CHIPCircularTLVBuffer::OnInit(TLVWriter & writer, uint8_t *& bufStart, uint32_t & bufLen)
CHIP_ERROR TLVCircularBuffer::OnInit(TLVWriter & writer, uint8_t *& bufStart, uint32_t & bufLen)
{
return GetNewBuffer(writer, bufStart, bufLen);
}
Expand All @@ -192,7 +192,7 @@ CHIP_ERROR CHIPCircularTLVBuffer::OnInit(TLVWriter & writer, uint8_t *& bufStart
* top-level TLV element.
*/

CHIP_ERROR CHIPCircularTLVBuffer::GetNewBuffer(TLVWriter & ioWriter, uint8_t *& outBufStart, uint32_t & outBufLen)
CHIP_ERROR TLVCircularBuffer::GetNewBuffer(TLVWriter & ioWriter, uint8_t *& outBufStart, uint32_t & outBufLen)
{
uint8_t * tail = QueueTail();

Expand All @@ -219,7 +219,7 @@ CHIP_ERROR CHIPCircularTLVBuffer::GetNewBuffer(TLVWriter & ioWriter, uint8_t *&

/**
* @brief
* FinalizeBuffer adjust the `CHIPCircularTLVBuffer` state on
* FinalizeBuffer adjust the `TLVCircularBuffer` state on
* completion of output from the TLVWriter. This function affects
* the position of the queue tail.
*
Expand All @@ -234,7 +234,7 @@ CHIP_ERROR CHIPCircularTLVBuffer::GetNewBuffer(TLVWriter & ioWriter, uint8_t *&
* @retval #CHIP_NO_ERROR Unconditionally.
*/

CHIP_ERROR CHIPCircularTLVBuffer::FinalizeBuffer(TLVWriter & ioWriter, uint8_t * inBufStart, uint32_t inBufLen)
CHIP_ERROR TLVCircularBuffer::FinalizeBuffer(TLVWriter & ioWriter, uint8_t * inBufStart, uint32_t inBufLen)
{
CHIP_ERROR err = CHIP_NO_ERROR;
uint8_t * tail = inBufStart + inBufLen;
Expand All @@ -256,7 +256,7 @@ CHIP_ERROR CHIPCircularTLVBuffer::FinalizeBuffer(TLVWriter & ioWriter, uint8_t *
* @brief
* Implements TLVBackingStore::OnInit(TVLReader) for circular buffers.
*/
CHIP_ERROR CHIPCircularTLVBuffer::OnInit(TLVReader & reader, const uint8_t *& bufStart, uint32_t & bufLen)
CHIP_ERROR TLVCircularBuffer::OnInit(TLVReader & reader, const uint8_t *& bufStart, uint32_t & bufLen)
{
return GetNextBuffer(reader, bufStart, bufLen);
}
Expand All @@ -265,7 +265,7 @@ CHIP_ERROR CHIPCircularTLVBuffer::OnInit(TLVReader & reader, const uint8_t *& bu
* @brief
* Get additional space for the TLVReader.
*
* The storage provided by the CHIPCircularTLVBuffer may be
* The storage provided by the TLVCircularBuffer may be
* wraparound within the buffer. This function provides us with an
* ability to match the buffering of the circular buffer to the
* TLVReader constraints. The reader will read at most `mQueueSize`
Expand All @@ -282,7 +282,7 @@ CHIP_ERROR CHIPCircularTLVBuffer::OnInit(TLVReader & reader, const uint8_t *& bu
*
* @retval #CHIP_NO_ERROR Succeeds unconditionally.
*/
CHIP_ERROR CHIPCircularTLVBuffer::GetNextBuffer(TLVReader & ioReader, const uint8_t *& outBufStart, uint32_t & outBufLen)
CHIP_ERROR TLVCircularBuffer::GetNextBuffer(TLVReader & ioReader, const uint8_t *& outBufStart, uint32_t & outBufLen)
{
CHIP_ERROR err = CHIP_NO_ERROR;
uint8_t * tail = QueueTail();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,23 @@ namespace chip {
namespace TLV {

/**
* @class CHIPCircularTLVBuffer
* @class TLVCircularBuffer
*
* @brief
* CHIPCircularTLVBuffer provides circular storage for the
* TLVCircularBuffer provides circular storage for the
* chip::TLV::TLVWriter and chip::TLVTLVReader. chip::TLV::TLVWriter is able to write an
* unbounded number of TLV entries to the CHIPCircularTLVBuffer
* unbounded number of TLV entries to the TLVCircularBuffer
* as long as each individual TLV entry fits entirely within the
* provided storage. The chip::TLV::TLVReader will read at most the size of
* the buffer, but will accommodate the wraparound within the
* buffer.
*
*/
class DLL_EXPORT CHIPCircularTLVBuffer : public chip::TLV::TLVBackingStore
class DLL_EXPORT TLVCircularBuffer : public chip::TLV::TLVBackingStore
{
public:
CHIPCircularTLVBuffer(uint8_t * inBuffer, uint32_t inBufferLength);
CHIPCircularTLVBuffer(uint8_t * inBuffer, uint32_t inBufferLength, uint8_t * inHead);
TLVCircularBuffer(uint8_t * inBuffer, uint32_t inBufferLength);
TLVCircularBuffer(uint8_t * inBuffer, uint32_t inBufferLength, uint8_t * inHead);

void Init(uint8_t * inBuffer, uint32_t inBufferLength);
inline uint8_t * QueueHead() const { return mQueueHead; }
Expand All @@ -78,25 +78,25 @@ class DLL_EXPORT CHIPCircularTLVBuffer : public chip::TLV::TLVBackingStore
CHIP_ERROR FinalizeBuffer(TLVWriter & ioWriter, uint8_t * inBufStart, uint32_t inBufLen) override;

/**
* @typedef CHIP_ERROR (*ProcessEvictedElementFunct)(CHIPCircularTLVBuffer &inBuffer, void * inAppData, TLVReader &inReader)
* @typedef CHIP_ERROR (*ProcessEvictedElementFunct)(TLVCircularBuffer &inBuffer, void * inAppData, TLVReader &inReader)
*
* A function that is called to process a TLV element prior to it
* being evicted from the chip::TLV::CHIPCircularTLVBuffer
* being evicted from the chip::TLV::TLVCircularBuffer
*
* Functions of this type are used to process a TLV element about
* to be evicted from the buffer. The function will be given a
* chip::TLV::TLVReader positioned on the element about to be deleted, as
* well as void * context where the user may have provided
* additional environment for the callback. If the function
* processed the element successfully, it must return
* #CHIP_NO_ERROR ; this signifies to the CHIPCircularTLVBuffer
* #CHIP_NO_ERROR ; this signifies to the TLVCircularBuffer
* that the element may be safely evicted. Any other return
* value is treated as an error and will prevent the
* #CHIPCircularTLVBuffer from evicting the element under
* #TLVCircularBuffer from evicting the element under
* consideration.
*
* Note: This callback may be used to force
* CHIPCircularTLVBuffer to not evict the element. This may be
* TLVCircularBuffer to not evict the element. This may be
* useful in a number of circumstances, when it is desired to
* have an underlying circular buffer, but not to override any
* elements within it.
Expand All @@ -119,7 +119,7 @@ class DLL_EXPORT CHIPCircularTLVBuffer : public chip::TLV::TLVBackingStore
* triggered this element eviction will
* fail.
*/
typedef CHIP_ERROR (*ProcessEvictedElementFunct)(CHIPCircularTLVBuffer & inBuffer, void * inAppData, TLVReader & inReader);
typedef CHIP_ERROR (*ProcessEvictedElementFunct)(TLVCircularBuffer & inBuffer, void * inAppData, TLVReader & inReader);

uint32_t mImplicitProfileId;
void * mAppData; /**< An optional, user supplied context to be used with the callback processing the evicted element. */
Expand All @@ -140,25 +140,25 @@ class DLL_EXPORT CircularTLVReader : public TLVReader
public:
/**
* @brief
* Initializes a TLVReader object to read from a single CHIPCircularTLVBuffer
* Initializes a TLVReader object to read from a single TLVCircularBuffer
*
* Parsing begins at the start of the buffer (obtained by the
* buffer->Start() position) and continues until the end of the buffer
* Parsing may wraparound within the buffer (on any element). At most
* buffer->GetQueueSize() bytes are read out.
*
* @param[in] buf A pointer to a fully initialized CHIPCircularTLVBuffer
* @param[in] buf A pointer to a fully initialized TLVCircularBuffer
*
*/
void Init(CHIPCircularTLVBuffer & buf) { TLVReader::Init(buf, buf.DataLength()); }
void Init(TLVCircularBuffer & buf) { TLVReader::Init(buf, buf.DataLength()); }
};

class DLL_EXPORT CircularTLVWriter : public TLVWriter
{
public:
/**
* @brief
* Initializes a TLVWriter object to write from a single CHIPCircularTLVBuffer
* Initializes a TLVWriter object to write from a single TLVCircularBuffer
*
* Writing begins at the last byte of the buffer. The number of bytes
* to be written is not constrained by the underlying circular buffer:
Expand All @@ -168,10 +168,10 @@ class DLL_EXPORT CircularTLVWriter : public TLVWriter
* 7 byte buffer will work indefinitely, but writing an 8-byte TLV
* structure will result in an error.
*
* @param[in] buf A pointer to a fully initialized CHIPCircularTLVBuffer
* @param[in] buf A pointer to a fully initialized TLVCircularBuffer
*
*/
void Init(CHIPCircularTLVBuffer & buf) { TLVWriter::Init(buf, UINT32_MAX); }
void Init(TLVCircularBuffer & buf) { TLVWriter::Init(buf, UINT32_MAX); }
};

} // namespace TLV
Expand Down
Loading

0 comments on commit 4877393

Please sign in to comment.