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 "SolidSyslogLwipRawResolver.h"
6 : :
7 : : #include <stdbool.h>
8 : : #include <stddef.h>
9 : : #include <stdint.h>
10 : :
11 : : #include "SolidSyslogError.h"
12 : : #include "SolidSyslogErrorCategory.h"
13 : : #include "SolidSyslogLwipRawResolverErrors.h"
14 : : #include "SolidSyslogLwipRawResolverPrivate.h"
15 : : #include "SolidSyslogNullResolver.h"
16 : : #include "SolidSyslogPoolAllocator.h"
17 : : #include "SolidSyslogPrival.h"
18 : : #include "SolidSyslogTunables.h"
19 : :
20 : : struct SolidSyslogResolver;
21 : :
22 : : static inline size_t LwipRawResolver_IndexFromHandle(const struct SolidSyslogResolver* base);
23 : : static inline void LwipRawResolver_CleanupAtIndex(size_t index, void* context);
24 : :
25 : : static bool LwipRawResolver_InUse[SOLIDSYSLOG_RESOLVER_POOL_SIZE];
26 : : static struct SolidSyslogLwipRawResolver LwipRawResolver_Pool[SOLIDSYSLOG_RESOLVER_POOL_SIZE];
27 : : static struct SolidSyslogPoolAllocator LwipRawResolver_Allocator = {
28 : : LwipRawResolver_InUse,
29 : : SOLIDSYSLOG_RESOLVER_POOL_SIZE
30 : : };
31 : :
32 : 22 : struct SolidSyslogResolver* SolidSyslogLwipRawResolver_Create(void)
33 : : {
34 : 22 : size_t index = SolidSyslogPoolAllocator_AcquireFirstFree(&LwipRawResolver_Allocator);
35 : 22 : struct SolidSyslogResolver* handle = SolidSyslogNullResolver_Get();
36 [ + + ]: 22 : if (SolidSyslogPoolAllocator_IndexIsValid(&LwipRawResolver_Allocator, index) == true)
37 : : {
38 : 18 : SolidSyslogLwipRawResolver_Initialise(&LwipRawResolver_Pool[index].Base);
39 : 18 : handle = &LwipRawResolver_Pool[index].Base;
40 : : }
41 : : else
42 : : {
43 : 4 : LwipRawResolver_Report(
44 : : SOLIDSYSLOG_POOL_EXHAUSTED_SEVERITY,
45 : : SOLIDSYSLOG_CAT_POOL_EXHAUSTED,
46 : : SOLIDSYSLOG_RESOLVER_ERROR_POOL_EXHAUSTED
47 : : );
48 : : }
49 : 22 : return handle;
50 : : }
51 : :
52 : 25 : void SolidSyslogLwipRawResolver_Destroy(struct SolidSyslogResolver* base)
53 : : {
54 : 25 : size_t index = LwipRawResolver_IndexFromHandle(base);
55 : 25 : bool released =
56 [ + + + + ]: 44 : SolidSyslogPoolAllocator_IndexIsValid(&LwipRawResolver_Allocator, index) &&
57 : 19 : SolidSyslogPoolAllocator_FreeIfInUse(&LwipRawResolver_Allocator, index, LwipRawResolver_CleanupAtIndex, NULL);
58 [ + + ]: 25 : if (!released)
59 : : {
60 : 7 : LwipRawResolver_Report(
61 : : SOLIDSYSLOG_UNKNOWN_DESTROY_SEVERITY,
62 : : SOLIDSYSLOG_CAT_UNKNOWN_DESTROY,
63 : : SOLIDSYSLOG_RESOLVER_ERROR_UNKNOWN_DESTROY
64 : : );
65 : : }
66 : 25 : }
67 : :
68 : 25 : static inline size_t LwipRawResolver_IndexFromHandle(const struct SolidSyslogResolver* base)
69 : : {
70 : 25 : size_t result = SOLIDSYSLOG_RESOLVER_POOL_SIZE;
71 [ + + ]: 31 : for (size_t poolIndex = 0U; poolIndex < SOLIDSYSLOG_RESOLVER_POOL_SIZE; poolIndex++)
72 : : {
73 [ + + ]: 25 : if (base == &LwipRawResolver_Pool[poolIndex].Base)
74 : : {
75 : 19 : result = poolIndex;
76 : 19 : break;
77 : : }
78 : : }
79 : 25 : return result;
80 : : }
81 : :
82 : 18 : static inline void LwipRawResolver_CleanupAtIndex(size_t index, void* context)
83 : : {
84 : : (void) context;
85 : 18 : SolidSyslogLwipRawResolver_Cleanup(&LwipRawResolver_Pool[index].Base);
86 : 18 : }
|