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 "SolidSyslogError.h"
6 : :
7 : : #include <stdbool.h>
8 : : #include <stddef.h>
9 : :
10 : : #include "SolidSyslogPendingEvents.h"
11 : :
12 : 320 : static void Error_NoOpErrorHandler(void* context, const struct SolidSyslogErrorEvent* event)
13 : : {
14 : : (void) context;
15 : : (void) event;
16 : 320 : }
17 : :
18 : : static SolidSyslogErrorHandler currentHandler = Error_NoOpErrorHandler;
19 : : static void* currentContext = NULL;
20 : :
21 : 15176 : void SolidSyslog_SetErrorHandler(SolidSyslogErrorHandler handler, void* context)
22 : : {
23 [ + + ]: 15176 : if (handler == NULL)
24 : : {
25 : 6942 : currentHandler = Error_NoOpErrorHandler;
26 : : }
27 : : else
28 : : {
29 : 8234 : currentHandler = handler;
30 : : }
31 : 15176 : currentContext = context;
32 : 15176 : }
33 : :
34 : : static inline bool Error_EventHasNamedDetail(const struct SolidSyslogErrorEvent* event);
35 : :
36 : 894 : const char* SolidSyslogErrorEvent_DetailName(const struct SolidSyslogErrorEvent* event)
37 : : {
38 : 894 : const char* name = NULL;
39 [ + + ]: 894 : if (Error_EventHasNamedDetail(event))
40 : : {
41 : 832 : name = event->Source->DetailName(event->Detail);
42 : : }
43 : 894 : return name;
44 : : }
45 : :
46 : : /* An integrator's own SolidSyslog_Error call may carry no source at all. */
47 : 894 : static inline bool Error_EventHasNamedDetail(const struct SolidSyslogErrorEvent* event)
48 : : {
49 [ + + + + ]: 894 : return (event->Source != NULL) && (event->Source->DetailName != NULL);
50 : : }
51 : :
52 : 9053 : void SolidSyslog_Error(
53 : : enum SolidSyslogSeverity severity,
54 : : const struct SolidSyslogErrorSource* source,
55 : : uint16_t category,
56 : : int32_t detail
57 : : )
58 : : {
59 : 9053 : const struct SolidSyslogErrorEvent event = {severity, category, false, source, detail, 0};
60 : 9053 : currentHandler(currentContext, &event);
61 : 9053 : SolidSyslogPendingEvents_Record(&event);
62 : 9053 : }
63 : :
64 : : // NOLINTNEXTLINE(bugprone-easily-swappable-parameters) -- detail and nativeCode are both codes; every caller passes named values
65 : 239 : void SolidSyslog_ErrorWithNativeCode(
66 : : enum SolidSyslogSeverity severity,
67 : : const struct SolidSyslogErrorSource* source,
68 : : uint16_t category,
69 : : int32_t detail,
70 : : int32_t nativeCode
71 : : )
72 : : {
73 : 239 : const struct SolidSyslogErrorEvent event = {severity, category, true, source, detail, nativeCode};
74 : 239 : currentHandler(currentContext, &event);
75 : 239 : SolidSyslogPendingEvents_Record(&event);
76 : 239 : }
|