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 : #ifndef SOLIDSYSLOGPRIVATE_H
6 : #define SOLIDSYSLOGPRIVATE_H
7 :
8 : #include <stddef.h>
9 :
10 : #include "SolidSyslogConfig.h"
11 : #include "SolidSyslogDiscardPolicy.h"
12 : #include "SolidSyslogError.h"
13 : #include "SolidSyslogErrors.h"
14 : #include "SolidSyslogFormatter.h"
15 : #include "SolidSyslogMessageFormatter.h"
16 : #include "SolidSyslogPrival.h"
17 : #include "SolidSyslogTimestamp.h"
18 :
19 : struct SolidSyslogBuffer;
20 : struct SolidSyslogConfig;
21 : struct SolidSyslogHeaderField;
22 : struct SolidSyslogScratch;
23 : struct SolidSyslogSender;
24 : struct SolidSyslogStore;
25 :
26 : struct SolidSyslog
27 : {
28 : struct SolidSyslogBuffer* Buffer;
29 : struct SolidSyslogSender* Sender;
30 : struct SolidSyslogStore* Store;
31 : struct SolidSyslogScratch* Scratch;
32 : struct SolidSyslogMessageFormatterContext Format;
33 : /* The one record Service works on at a time: taken from the buffer, or read
34 : * from the store to send. It outlives a Service pass so that a record no
35 : * store will take can be kept for the next; HoldsRecord is true while one is
36 : * kept that way, and Service reads neither the buffer nor the store until it
37 : * has gone. Service alone puts a record in the slot, from the one task that
38 : * calls it.
39 : *
40 : * The storage is the pool entry's, not the instance's: Create points
41 : * RecordStorage at it, and Record at the formatter's bytes within it, so
42 : * Service can format its own report into the slot it sends from. Cleanup
43 : * takes it away, leaving both NULL and RecordCapacity 0. Destroy and the
44 : * fallback SolidSyslog_Create returns both go through Cleanup, so the
45 : * fallback carries no slot. Cleanup also installs the Null buffer and
46 : * store, which deliver no record, so a NULL Record never meets a Read that
47 : * could write into it. */
48 : SolidSyslogFormatterStorage* RecordStorage;
49 : char* Record;
50 : size_t RecordCapacity;
51 : size_t RecordLength;
52 : bool HoldsRecord;
53 : /* Whether the record held is a report Service made of one of the
54 : * library's own events, rather than a record from the buffer. */
55 : bool HeldRecordIsReport;
56 : /* A report stands for a run of held records dropped because the buffer
57 : * filled behind them; a record from the buffer dealt with ends the run. */
58 : bool HeldRecordLossReported;
59 : SolidSyslogDiscardPolicyFunction GetDiscardPolicy;
60 : void* DiscardPolicyContext;
61 : SolidSyslogHaltCallback OnHalt;
62 : void* HaltContext;
63 : SolidSyslogEventReportingFunction IsEventReportingOn;
64 : void* EventReportingContext;
65 : /* Whether the switch turned a report down this pass; each pass starts
66 : * without. */
67 : bool ReportTurnedDown;
68 : /* Set while the policy answers Halt, when a retaining store refuses a
69 : * record or the buffer has filled behind the record Service holds; Service
70 : * then moves nothing until the answer changes. */
71 : bool Halted;
72 : };
73 :
74 : void SolidSyslog_Initialise(
75 : struct SolidSyslog* self,
76 : const struct SolidSyslogConfig* config,
77 : SolidSyslogFormatterStorage* recordStorage,
78 : size_t recordCapacity
79 : );
80 : void SolidSyslog_Cleanup(struct SolidSyslog* self);
81 :
82 333 : static inline void SolidSyslog_Report(enum SolidSyslogSeverity severity, uint16_t category, enum SolidSyslogErrors code)
83 : {
84 333 : SolidSyslog_Error(severity, &SolidSyslogErrorSource, category, (int32_t) code);
85 333 : }
86 :
87 : #endif /* SOLIDSYSLOGPRIVATE_H */
|