SolidSyslog coverage report
Current view: top level - Platform/PlusTcp/Source - SolidSyslogPlusTcpTcpStreamStatic.c (source / functions) Coverage Total Hit
Test: SolidSyslog Lines: 100.0 % 26 26
Test Date: 2026-11-12 23:14:35 Functions: 100.0 % 4 4
Branches: 100.0 % 12 12

             Branch data     Line data    Source code
       1                 :             : /* SPDX-FileCopyrightText: Copyright 2026 Cozens Software Solutions Limited
       2                 :             :  * SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0 OR LicenseRef-PolyForm-Internal-Use-1.0.0 OR LicenseRef-COSOSO-Commercial
       3                 :             :  */
       4                 :             : 
       5                 :             : #include "FreeRTOS_IP.h"
       6                 :             : 
       7                 :             : /* This component requires FreeRTOS-Plus-TCP built with TCP. */
       8                 :             : #if (ipconfigUSE_TCP == 1)
       9                 :             : 
      10                 :             : #include "SolidSyslogPlusTcpTcpStream.h"
      11                 :             : 
      12                 :             : #include <stdbool.h>
      13                 :             : #include <stddef.h>
      14                 :             : #include <stdint.h>
      15                 :             : 
      16                 :             : #include "SolidSyslogError.h"
      17                 :             : #include "SolidSyslogErrorCategory.h"
      18                 :             : #include "SolidSyslogNullStream.h"
      19                 :             : #include "SolidSyslogPlusTcpTcpStreamErrors.h"
      20                 :             : #include "SolidSyslogPlusTcpTcpStreamPrivate.h"
      21                 :             : #include "SolidSyslogPoolAllocator.h"
      22                 :             : #include "SolidSyslogPrival.h"
      23                 :             : #include "SolidSyslogTunables.h"
      24                 :             : 
      25                 :             : struct SolidSyslogStream;
      26                 :             : 
      27                 :             : static inline size_t PlusTcpTcpStream_IndexFromHandle(const struct SolidSyslogStream* base);
      28                 :             : static inline void PlusTcpTcpStream_CleanupAtIndex(size_t index, void* context);
      29                 :             : 
      30                 :             : static bool PlusTcpTcpStream_InUse[SOLIDSYSLOG_TCP_STREAM_POOL_SIZE];
      31                 :             : static struct SolidSyslogPlusTcpTcpStream PlusTcpTcpStream_Pool[SOLIDSYSLOG_TCP_STREAM_POOL_SIZE];
      32                 :             : static struct SolidSyslogPoolAllocator PlusTcpTcpStream_Allocator = {
      33                 :             :     PlusTcpTcpStream_InUse,
      34                 :             :     SOLIDSYSLOG_TCP_STREAM_POOL_SIZE
      35                 :             : };
      36                 :             : 
      37                 :          72 : struct SolidSyslogStream* SolidSyslogPlusTcpTcpStream_Create(const struct SolidSyslogPlusTcpTcpStreamConfig* config)
      38                 :             : {
      39                 :          72 :     size_t index = SolidSyslogPoolAllocator_AcquireFirstFree(&PlusTcpTcpStream_Allocator);
      40                 :          72 :     struct SolidSyslogStream* handle = SolidSyslogNullStream_Get();
      41         [ +  + ]:          72 :     if (SolidSyslogPoolAllocator_IndexIsValid(&PlusTcpTcpStream_Allocator, index) == true)
      42                 :             :     {
      43                 :          68 :         SolidSyslogPlusTcpTcpStream_Initialise(&PlusTcpTcpStream_Pool[index].Base, config);
      44                 :          68 :         handle = &PlusTcpTcpStream_Pool[index].Base;
      45                 :             :     }
      46                 :             :     else
      47                 :             :     {
      48                 :           4 :         PlusTcpTcpStream_Report(
      49                 :             :             SOLIDSYSLOG_POOL_EXHAUSTED_SEVERITY,
      50                 :             :             SOLIDSYSLOG_CAT_POOL_EXHAUSTED,
      51                 :             :             SOLIDSYSLOG_TCP_STREAM_ERROR_POOL_EXHAUSTED
      52                 :             :         );
      53                 :             :     }
      54                 :          72 :     return handle;
      55                 :             : }
      56                 :             : 
      57                 :          75 : void SolidSyslogPlusTcpTcpStream_Destroy(struct SolidSyslogStream* base)
      58                 :             : {
      59                 :          75 :     size_t index = PlusTcpTcpStream_IndexFromHandle(base);
      60                 :          75 :     bool released =
      61   [ +  +  +  + ]:         144 :         SolidSyslogPoolAllocator_IndexIsValid(&PlusTcpTcpStream_Allocator, index) &&
      62                 :          69 :         SolidSyslogPoolAllocator_FreeIfInUse(&PlusTcpTcpStream_Allocator, index, PlusTcpTcpStream_CleanupAtIndex, NULL);
      63         [ +  + ]:          75 :     if (!released)
      64                 :             :     {
      65                 :           7 :         PlusTcpTcpStream_Report(
      66                 :             :             SOLIDSYSLOG_UNKNOWN_DESTROY_SEVERITY,
      67                 :             :             SOLIDSYSLOG_CAT_UNKNOWN_DESTROY,
      68                 :             :             SOLIDSYSLOG_TCP_STREAM_ERROR_UNKNOWN_DESTROY
      69                 :             :         );
      70                 :             :     }
      71                 :          75 : }
      72                 :             : 
      73                 :          75 : static inline size_t PlusTcpTcpStream_IndexFromHandle(const struct SolidSyslogStream* base)
      74                 :             : {
      75                 :          75 :     size_t result = SOLIDSYSLOG_TCP_STREAM_POOL_SIZE;
      76         [ +  + ]:          91 :     for (size_t poolIndex = 0U; poolIndex < SOLIDSYSLOG_TCP_STREAM_POOL_SIZE; poolIndex++)
      77                 :             :     {
      78         [ +  + ]:          85 :         if (base == &PlusTcpTcpStream_Pool[poolIndex].Base)
      79                 :             :         {
      80                 :          69 :             result = poolIndex;
      81                 :          69 :             break;
      82                 :             :         }
      83                 :             :     }
      84                 :          75 :     return result;
      85                 :             : }
      86                 :             : 
      87                 :          68 : static inline void PlusTcpTcpStream_CleanupAtIndex(size_t index, void* context)
      88                 :             : {
      89                 :             :     (void) context;
      90                 :          68 :     SolidSyslogPlusTcpTcpStream_Cleanup(&PlusTcpTcpStream_Pool[index].Base);
      91                 :          68 : }
      92                 :             : 
      93                 :             : #else
      94                 :             : 
      95                 :             : /* ISO C forbids an empty translation unit. */
      96                 :             : typedef int PlusTcpTcpStreamStatic_EmptyTranslationUnit;
      97                 :             : 
      98                 :             : #endif /* ipconfigUSE_TCP */
        

Generated by: LCOV version 2.0-1