Skip to content

Commit

Permalink
finx git merde
Browse files Browse the repository at this point in the history
  • Loading branch information
bha-evs committed Nov 22, 2023
1 parent 165b36c commit 2bb335a
Show file tree
Hide file tree
Showing 32 changed files with 1,583 additions and 2,520 deletions.
6 changes: 2 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,8 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${COMPILED_BINARIES_DIR}/lib)
# == PACKAGING ==
# ===============

if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
# make package only if BofStd is the main project (not a submodule)
include(packaging.cmake)
endif()
include(packaging.cmake)

# =======================
# == POPULATE PROJECTS ==
# =======================
Expand Down
46 changes: 41 additions & 5 deletions lib/include/bofstd/bofcircularbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class BofCircularBuffer
uint32_t GetNbElementLocked() const;
uint32_t GetCapacity() const;
uint32_t GetNbFreeElement();
BOFERR SetOverWriteMode(bool _Overwrite_B);
uint32_t GetMaxLevel() const;
bool IsBufferOverflow();
void Reset();
Expand All @@ -125,7 +126,8 @@ class BofCircularBuffer
BOFERR Peek(DataType *_pData, uint32_t _BlockingTimeouItInMs_U32, uint32_t *_pIndexOf_U32, DataType **_ppStorage); //_ppStorage is mainly used in mCircularBufferParam_X.PopLockMode_B to provide write access to the locked storage cell
BOFERR PeekFromPop(uint32_t _RelativeIndexFromPop_U32, DataType *_pData, bool *_pLocked_B, DataType **_ppStorage); //_ppStorage is mainly used in mCircularBufferParam_X.PopLockMode_B to provide write access to the locked storage cell
BOFERR PeekByIndex(uint32_t _AbsoluteIndex_U32, DataType *_pData, bool *_pLocked_B, DataType **_ppStorage); //_ppStorage is mainly used in mCircularBufferParam_X.PopLockMode_B to provide write access to the locked storage cell);
BOFERR Skip(bool *_pLocked_B);
//_SignalIfNeeded_B:: sometime you skip just to process OverWrite mode, in this case do not signal free space
BOFERR Skip(DataType *_pData, bool _SignalIfNeeded_B, uint32_t *_pIndexOf_U32, DataType **_ppStorage, bool *_pLocked_B);
BOFERR UnlockPop(uint32_t _AbsoluteIndex_U32);
bool IsLocked(uint32_t _AbsoluteIndex_U32);
bool IsEntryFree(uint32_t _AbsoluteIndex_U32, bool *_pIsLocked_B, DataType **_ppStorage); //_ppStorage is mainly used in mCircularBufferParam_X.PopLockMode_B to provide write access to the locked storage cell
Expand Down Expand Up @@ -298,6 +300,12 @@ uint32_t BofCircularBuffer<DataType>::GetNbFreeElement()
return Rts_U32;
}

template <typename DataType>
BOFERR BofCircularBuffer<DataType>::SetOverWriteMode(bool _Overwrite_B)
{
mCircularBufferParam_X.Overwrite_B = _Overwrite_B;
return BOF_ERR_NO_ERROR;
}
template <typename DataType>
uint32_t BofCircularBuffer<DataType>::GetMaxLevel() const
{
Expand Down Expand Up @@ -380,6 +388,12 @@ BOFERR BofCircularBuffer<DataType>::Push(const DataType *_pData, uint32_t _Block
if (mNbElementInBuffer_U32 > mCircularBufferParam_X.NbMaxElement_U32)
{
mNbElementInBuffer_U32 = mCircularBufferParam_X.NbMaxElement_U32; // mCircularBufferParam_X.Overwrite_B
BOF_ASSERT(mPushIndex_U32 == mPopIndex_U32)
mPopIndex_U32++;
if (mPopIndex_U32 >= mCircularBufferParam_X.NbMaxElement_U32)
{
mPopIndex_U32 = 0;
}
mOverflow_B = true;
}
}
Expand Down Expand Up @@ -487,6 +501,12 @@ BOFERR BofCircularBuffer<DataType>::PushForNextPop(const DataType *_pData, bool
if (mNbElementInBuffer_U32 > mCircularBufferParam_X.NbMaxElement_U32)
{
mNbElementInBuffer_U32 = mCircularBufferParam_X.NbMaxElement_U32; // mCircularBufferParam_X.Overwrite_B
BOF_ASSERT(mPushIndex_U32 == mPopIndex_U32)
mPopIndex_U32++;
if (mPopIndex_U32 >= mCircularBufferParam_X.NbMaxElement_U32)
{
mPopIndex_U32 = 0;
}
mOverflow_B = true;
}
}
Expand Down Expand Up @@ -822,8 +842,9 @@ BOFERR BofCircularBuffer<DataType>::PeekByIndex(uint32_t _AbsoluteIndex_U32, Dat
return Rts_E;
}

//_SignalIfNeeded_B:: sometime you skip just to process OverWrite mode, in this case do not signal free space
template <typename DataType>
BOFERR BofCircularBuffer<DataType>::Skip(bool *_pIsLocked_B)
BOFERR BofCircularBuffer<DataType>::Skip(DataType *_pData, bool _SignalIfNeeded_B, uint32_t *_pIndexOf_U32, DataType **_ppStorage, bool *_pLocked_B)
{
BOFERR Rts_E;

Expand All @@ -835,9 +856,9 @@ BOFERR BofCircularBuffer<DataType>::Skip(bool *_pIsLocked_B)
BOF_ASSERT(mNbElementLockedInBuffer_U32 <= mNbElementInBuffer_U32);
if (mNbElementInBuffer_U32 - mNbElementLockedInBuffer_U32)
{
if (_pIsLocked_B)
if (_pLocked_B)
{
*_pIsLocked_B = mpLock_U8[mPopIndex_U32] ? true : false;
*_pLocked_B = mpLock_U8[mPopIndex_U32] ? true : false;
}
if (mpLock_U8[mPopIndex_U32] == 0)
{
Expand All @@ -846,14 +867,29 @@ BOFERR BofCircularBuffer<DataType>::Skip(bool *_pIsLocked_B)
mNbElementInBuffer_U32--;

BOF_ASSERT(mPopIndex_U32 < mCircularBufferParam_X.NbMaxElement_U32);
if (_pIndexOf_U32)
{
*_pIndexOf_U32 = mPopIndex_U32;
}
if (_pData)
{
*_pData = mpData_T[mPopIndex_U32];
}
if (_ppStorage)
{
*_ppStorage = &mpData_T[mPopIndex_U32];
}
mPopIndex_U32++;
if (mPopIndex_U32 >= mCircularBufferParam_X.NbMaxElement_U32)
{
mPopIndex_U32 = 0;
}
if (mCircularBufferParam_X.Blocking_B) //&& (_BlockingTimeouItInMs_U32))
{
Rts_E = SignalReadWrite();
if (_SignalIfNeeded_B)
{
Rts_E = SignalReadWrite();
}
}
}
else
Expand Down
5 changes: 5 additions & 0 deletions lib/include/bofstd/bofhttprequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ enum BOF_HTTP_REQUEST_TYPE
BOF_HTTP_REQUEST_OPTIONS,
BOF_HTTP_REQUEST_CONNECT,
BOF_HTTP_REQUEST_TRACE,
BOF_HTTP_REQUEST_DBG_ECHO, //For user Debug Echo function
BOF_HTTP_REQUEST_MAX,

};
/// @brief This class implements an http request parser.
/// Cf BofHttpRequest
Expand Down Expand Up @@ -155,6 +158,8 @@ class BOFSTD_EXPORT BofHttpRequest
/// @remarks Different operator.
bool operator!=(const BofHttpRequest &_rOther_O) const;

static BOF_HTTP_REQUEST_TYPE S_RequestType(const char *_pRequest_c);
static std::string S_RequestString(BOF_HTTP_REQUEST_TYPE _Method_E);
/// @brief Check if the http request instance is well formed.
/// @return true if the http request is valid.
/// @remarks None
Expand Down
23 changes: 23 additions & 0 deletions lib/include/bofstd/bofpot.h
Original file line number Diff line number Diff line change
Expand Up @@ -1022,11 +1022,34 @@ template <typename DataType>
void BofPot<DataType>::Reset()
{
BOFERR Sts_E;
uint32_t i_U32;
DataType *pData_X;

BOF_POT_LOCK(Sts_E);
if (Sts_E == BOF_ERR_NO_ERROR)
{
mLevelMax_U32 = 0;
mpFirstPotElementToTryForGet_X = mpPotDataStorage_X;
mNumberOfElementOutOfThePot_U32=0;
pData_X = mpPotDataStorage_X;

if (mPotParam_X.MagicNumber_U32)
{
for (i_U32 = 0; i_U32 < mPotParam_X.PotCapacity_U32; i_U32++, pData_X++)
{
*(uint32_t *)pData_X = 0;
}
}
else
{
if (mpInUseElementList_U8)
{
for (i_U32 = 0; i_U32 < mPotParam_X.PotCapacity_U32; i_U32++)
{
mpInUseElementList_U8[i_U32] = 0x00;
}
}
}
BOF_POT_UNLOCK()
}
}
Expand Down
129 changes: 78 additions & 51 deletions lib/include/bofstd/bofrawcircularbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,20 @@
#pragma once

#include <bofstd/bofsystem.h>
#include <bofstd/bofcircularbuffer.h>

BEGIN_BOF_NAMESPACE()

struct BOF_RAW_CIRCULAR_BUFFER_PARAM
{
bool MultiThreadAware_B; /*! true if the object is used in a multi threaded application (use mCs)*/
uint32_t BufferSizeInByte_U32; /*! Specifies the maximum number of byte inside inside the queue*/
uint32_t NbMaxSlot_U32; /*! Specifies the maximum number of buffer inside the queue (if 0 the whole BufferSizeInByte_U32 can be used)*/
bool SlotMode_B; /* If true, the mpData_U8 buffer of BufferSizeInByte_U32 will be divided by NbMaxBufferEntry_U32 and each slot will be BufferSizeInByte_U32/NbMaxBufferEntry_U32 */
uint32_t NbMaxBufferEntry_U32; /*! Specifies the maximum number of buffer which will be tracked inside the mpData_U8 buffer of BufferSizeInByte_U32*/
uint8_t *pData_U8; /*! Pointer to queue storage buffer used to record queue element*/
bool Overwrite_B; /*! true if new data overwritte the oldest one when the queue is full. */
bool Blocking_B;

BOF_RAW_CIRCULAR_BUFFER_PARAM()
{
Reset();
Expand All @@ -40,8 +45,11 @@ struct BOF_RAW_CIRCULAR_BUFFER_PARAM
{
MultiThreadAware_B = false;
BufferSizeInByte_U32 = 0;
NbMaxSlot_U32 = 0;
SlotMode_B = false;
NbMaxBufferEntry_U32 = 0;
pData_U8 = nullptr;
Overwrite_B = false;
Blocking_B = false;
}
};

Expand All @@ -50,54 +58,70 @@ struct BOF_RAW_CIRCULAR_BUFFER_PARAM
* Raw Circular buffer class
*
* Description
* This class manages a circular byte buffer instance. Each entry in the circular buffer is
* preceded by a 32 bits value containing the length of the payload:
*
* L1: <L1 databyte> | L2: <L2 databyte> | ... | Ln: <Ln databyte>
* This class manages a circular byte buffer instance. For each entry in the circular buffer, there is an entry in
* in std::unique_ptr<BofCircularBuffer<BOF_RAW_BUFFER>> mpuSlotCollection.
* BOF_RAW_BUFFER describes a buffer portion inside the global mpData_U8 buffer
*
* The effective range of this value is [1,0x7FFFFFFF]. When bit 31 is set, this location has been
* reserved (locked) by LockBuffer and it will be filled by UnlockLockBuffer which will clear the bit 31
* When this bit is set PopBuffer will fail even if the state of the buffer seems to be ready for pop
* operation. PushBuffer can continue to work
* mpData_U8: <L1 databyte> | <L2 databyte> | ... | <Ln databyte>
*
* The filling of the buffer is controlled by BufferCapacity_U32 and NbMaxBuffer_U32
* The filling of the buffer is controlled by SlotMode_B, NbMaxBufferEntry_U32 and BufferSizeInByte_U32
*
* BufferCapacity_U32 gives the number of byte allocated to store the list of buffers
* BufferSizeInByte_U32 gives the number of byte allocated to store the list of buffers
*
* Each pushed buffer is stored one after each other if NbMaxBuffer_U32 is 0. In this case
* the buffer capacity is optimized used in term of memory
* L1:<L1 databyte>L2:<L2 databyte>...Ln:<Ln databyte>
* Each pushed buffer is stored one after each other if SlotMode_B is false up to a maximum of NbMaxBufferEntry_U32
* pending entries which must be Poped out to be able to use the rest of the buffer.
*
* If NbMaxBuffer_U32 is different from 0, each buffer will be stored in a slot of
* BufferCapacity_U32/NbMaxBuffer_U32 bytes. This will gives slot of equal size inside the
* If SlotMode_B is true, each buffer will be stored in a slot of
* BufferSizeInByte_U32/NbMaxBufferEntry_U32 bytes. This will gives slot of equal size inside the
* circular buffer which contains variable size buffer array from 1 to
* (BufferCapacity_U32/NbMaxBuffer_U32) bytes length. In this cas the BufferCapacity_U32 is
* increased by (NbMaxBuffer_U32*sizeof(uint32_t)) to be able to store the extra buffer 32 bits value
* containing the length of the payload
* L1:<L1 databyte> L2:<L2 databyte> ...Ln:<Ln databyte>
* (BufferSizeInByte_U32/NbMaxBufferEntry_U32) bytes length.
*
* <L1 databyte> <L2 databyte> ...Ln:<Ln databyte>
* <--------SlotSize--------><--------SlotSize-------->...<--------SlotSize-------->
*
* See Also
* None
*
* Each entry in the buffer list can be read partially byte per byte up to the size of the length of this entry.
* Data can also be appended part by part if you call SetAppendMode(true), do not forget to call SetAppendMode(false)
* when the data is considered as completly full
*/

struct BOF_RAW_BUFFER
{
uint32_t IndexInBuffer_U32; //Index of the first data byte (pData_U8[0]) inside the global mpData_U8 buffer.
uint32_t SlotEmpySpace_U32; //Number of not used byte in slot when pushed
uint32_t Size1_U32; //Number of byte from pData1_U8 to the end op the buffer (no Size2_U32 for slotmode)
uint8_t *pData1_U8; //Pointer to data corresponding to Size1_U32 (no pData2_U8 for SlotMode_B)
uint32_t Size2_U32; //In non slot mode, data may be spreaded accross the end of the buffer, this one contains the number of byte from mpData_U8[0] to the end of the buffer
uint8_t *pData2_U8; //Pointer to data corresponding to Size1_U32 (no Size2_U32 for SlotMode_B)
BOF_RAW_BUFFER()
{
Reset();
}
void Reset()
{
IndexInBuffer_U32 = 0;
SlotEmpySpace_U32 = 0;
Size1_U32 = 0;
pData1_U8 = nullptr;
Size2_U32 = 0;
pData2_U8 = nullptr;
}
};
class BOFSTD_EXPORT BofRawCircularBuffer
{
private:
BOF_RAW_CIRCULAR_BUFFER_PARAM mRawCircularBufferParam_X;
uint32_t mNbSlot_U32; /*! Current number of buffer stored inside the raw queue */
// uint32_t mNbMaxSlot_U32; /*! Maximum number of buffer which can be stored inside the queue. If it is 0, the whole buffer size is used to store a maximum number of buffer otherwise of constant slot size
// is used to store variable buffer length (see class comment) */
uint32_t mSlotSize_U32; /*! if mNbMaxSlot_U32 != 0 this is the slot size which is used to store variable buffer length (adjusted mNbElementInBuffer_U32/mNbMaxBuffer_U32 (see class comment) otherwize 0 */
bool mDataPreAllocated_B; /*! true if mpData_U8 is provided by the caller (!! if mNbMaxBuffer_U32 is different from zero, extra storage is needed to record lenth of each slot (see class comment) */
uint8_t *mpData_U8; /*! Pointer to queue storage buffer used to record queue element*/
uint32_t mPushIndex_U32; /*! Current position of the write index inside the queue*/
uint32_t mPopIndex_U32; /*! Current position of the read index inside the queue*/
// uint32_t mBufferCapacity_U32; /*! The maximum number of element inside the queue*/
uint32_t mNbElementInBuffer_U32; /*! Current number of element inside the queue*/
uint32_t mLevelMax_U32; /*! Contains the maximum buffer fill level. This one is reset by the GetMaxLevel method*/
BOF_MUTEX mRawCircularBufferMtx_X; /*! Provide a serialized access to shared resources in a multi threaded environment*/
BOFERR mErrorCode_E;
uint32_t mSlotSize_U32 = 0; /*! if SlotMode_B this is the slot size which is used to store variable buffer length (adjusted BufferSizeInByte_U32/mNbElementInBuffer_U32 */
bool mDataPreAllocated_B=false; /*! true if mpData_U8 is provided by the caller */
uint8_t *mpData_U8=nullptr; /*! Pointer to queue storage buffer used to record queue element*/
uint32_t mLevelMax_U32=0; /*! Contains the maximum buffer fill level. This one is reset by the GetMaxLevel method*/
BOF_MUTEX mRawCircularBufferMtx_X; /*! Provide a serialized access to shared resources in a multi threaded environment*/
BOFERR mErrorCode_E=BOF_ERR_NO_ERROR;
bool mOverflow_B=false; /*! true if data overflow has occured. Reset to false by IsBufferOverflow*/
bool mAppendMode_B=false; /*! true if we are in append mode */
std::unique_ptr<BofCircularBuffer<BOF_RAW_BUFFER>> mpuBufferCollection = nullptr;
BOF_RAW_BUFFER mRawBufferToPush_X;
uint32_t mCrtBufferRemain_U32 = 0;
uint8_t *mpCrtBufferHead_U8 = nullptr;
uint8_t *mpCrtBufferEnd_U8 = nullptr;

public:
BofRawCircularBuffer(const BOF_RAW_CIRCULAR_BUFFER_PARAM &_rRawCircularBufferParam_X);
Expand All @@ -112,23 +136,26 @@ class BOFSTD_EXPORT BofRawCircularBuffer
bool IsEmpty();
bool IsFull();
uint32_t GetSlotSize();
uint32_t GetNbElement();
uint32_t GetCapacity();
uint32_t GetNbElement(uint32_t *_pSizeOfFirst_U32);
uint32_t GetCapacity(uint32_t *_pTotalSize_U32);
uint32_t GetMaxLevel();
void Reset();
uint32_t GetNbFreeElement();
BOFERR PushBuffer(uint32_t _Nb_U32, const uint8_t *_pData_U8);
BOFERR PopBuffer(uint32_t *_pNbMax_U32, uint8_t *_pData_U8);
BOFERR Peek(uint32_t _Index_U32, uint32_t *_pNbMax_U32, uint8_t *_pData_U8);
BOFERR Skip();
BOFERR LockBuffer(uint32_t _Nb_U32, uint32_t *_pNb1_U32, uint8_t **_ppData1_U8, uint32_t *_pNb2_U32, uint8_t **_ppData2_U8);
BOFERR UnlockBuffer(const uint8_t *_pLockedBuffer_U8, uint32_t _Nb_U32);
uint32_t GetNbFreeElement(uint32_t *_pRemainingSize_U32);
BOFERR SetOverWriteMode(bool _Overwrite_B);
BOFERR SetAppendMode(uint32_t _BlockingTimeouItInMs_U32, bool _Append_B);
bool IsBufferOverflow();
BOFERR PushBuffer(uint32_t _BlockingTimeouItInMs_U32, uint32_t _Nb_U32, const uint8_t *_pData_U8);
BOFERR PopBuffer(uint32_t _BlockingTimeouItInMs_U32, uint32_t *_pNbMax_U32, uint8_t *_pData_U8);
BOFERR Peek(uint32_t _BlockingTimeouItInMs_U32, uint32_t *_pNbMax_U32, uint8_t *_pData_U8);
//Need to call Skip after GetBufferPtr
BOFERR GetBufferPtr(uint32_t _BlockingTimeouItInMs_U32, uint32_t *_pNb1_U32, uint8_t **_ppData1_U8, uint32_t *_pNb2_U32, uint8_t **_ppData2_U8);
//_SignalIfNeeded_B:: sometime you skip just to process OverWrite mode, in this case do not signal free space
BOFERR Skip(bool _SignalIfNeeded_B, bool *_pLocked_B);

private:
uint32_t ReadNbHeader(uint32_t *_pPopIndex_U32); //Lock is not taken to avoid recursive mutex
BOFERR WriteNbHeader(uint32_t *_pPushIndex_U32, uint32_t _Nb_U32); //Lock is not taken to avoid recursive mutex
BOFERR ReadPayload(uint32_t *_pPopIndex_U32, uint32_t _Nb_U32, uint8_t *_pData_U8); //Lock is not taken to avoid recursive mutex
BOFERR WritePayload(uint32_t *_pPushIndex_U32, uint32_t _Nb_U32, const uint8_t *_pData_U8); //Lock is not taken to avoid recursive mutex
BOFERR PushRawBuffer(uint32_t _BlockingTimeouItInMs_U32);
BOFERR UpdatePushRawBuffer(uint32_t _Size_U32, const uint8_t *_pData_U8);
BOFERR PopOrPeekBuffer(bool _Pop_B, uint32_t _BlockingTimeouItInMs_U32, uint32_t *_pNbMax_U32, uint8_t *_pData_U8);
};

END_BOF_NAMESPACE()
8 changes: 8 additions & 0 deletions lib/include/bofstd/bofsocketos.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,14 @@ struct BOF_SOCKET_ADDRESS
*pIp_U8++ = static_cast<uint8_t>(_Ip4_U32);
}
SocketType_E = _SocketType_E;
if (SocketType_E == BOF_SOCK_TYPE::BOF_SOCK_TCP)
{
Protocol_S = "tcp";
}
if (SocketType_E == BOF_SOCK_TYPE::BOF_SOCK_UDP)
{
Protocol_S = "udp";
}
}

void Inc(int32_t _Inc_S32)
Expand Down
2 changes: 1 addition & 1 deletion lib/include/bofstd/bofsocketthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ class BOFSTD_EXPORT BofSocketThread : public BofThread
BOFERR CancelSocketOperation(uint32_t _TimeOut_U32);
BOFERR ClearSocketOperation();
BOFERR ResetSocketOperation();

uint32_t GetIoDefaultTimeout() const;
BofSocket *GetListeningSocket();
BofSocket *GetSocket();
const BOF_SOCKET_OPERATION_PARAM &GetCurrentOpParam();
Expand Down
4 changes: 4 additions & 0 deletions lib/include/bofstd/bofstd.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ struct BOF_SIZE
};

#define BOF_PI 3.14159265358979323846
#define BOF_SQAURE_2 1.41421356237309504880
#define BOF_EULER_NUMBER 2.71828182845904523536
#define BOF_EULER_CONSTANT 0.57721566490153286060

#define BOF_HANDLE uintptr_t
// typedef void *BOF_HANDLE;
// #define BOF_INVALID_HANDLE_VALUE ((BOF_HANDLE)-1)
Expand Down
Loading

0 comments on commit 2bb335a

Please sign in to comment.