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 SOLIDSYSLOGPOSIXMESSAGEQUEUEBUFFERPRIVATE_H
6 : #define SOLIDSYSLOGPOSIXMESSAGEQUEUEBUFFERPRIVATE_H
7 :
8 : #include <stdint.h>
9 :
10 : #include <mqueue.h>
11 : #include <stdbool.h>
12 : #include <stddef.h>
13 :
14 : #include "SolidSyslogBufferDefinition.h"
15 : #include "SolidSyslogDiscardPolicy.h"
16 : #include "SolidSyslogError.h"
17 : #include "SolidSyslogPosixMessageQueueBufferErrors.h"
18 : #include "SolidSyslogPrival.h"
19 :
20 : enum
21 : {
22 : POSIX_MESSAGE_QUEUE_BUFFER_MAX_NAME_SIZE = 64
23 : };
24 :
25 : struct SolidSyslogMutex;
26 :
27 : struct SolidSyslogPosixMessageQueueBuffer
28 : {
29 : struct SolidSyslogBuffer Base;
30 : struct SolidSyslogMutex* Mutex;
31 : mqd_t Mq;
32 : SolidSyslogDiscardPolicyFunction GetDiscardPolicy;
33 : void* DiscardPolicyContext;
34 : /* Each report stands for a run of records the queue would not take as it
35 : * stood - full, or failing - or of sends that had to evict; the next record
36 : * it takes ends the first two, the next send that evicts nothing the
37 : * third. */
38 : bool RefusalReported;
39 : bool FailureReported;
40 : bool EvictionReported;
41 : /* One report stands for a run of failed receives; the next record
42 : * received ends it. */
43 : bool ReceiveFailureReported;
44 : /* The last send found the queue full - it evicted, or was refused - and
45 : * nothing has been received since: Log has outrun Service. Shared between
46 : * the two sides, so kept under the mutex. */
47 : bool Full;
48 : };
49 :
50 : /* Answers 0 once the queue is open, else the errno mq_open left. */
51 : int SolidSyslogPosixMessageQueueBuffer_Initialise(
52 : struct SolidSyslogBuffer* base,
53 : struct SolidSyslogMutex* mutex,
54 : size_t maxMessages,
55 : size_t slotIndex,
56 : SolidSyslogDiscardPolicyFunction getDiscardPolicy,
57 : void* discardPolicyContext
58 : );
59 : void SolidSyslogPosixMessageQueueBuffer_Cleanup(struct SolidSyslogBuffer* base);
60 :
61 59 : static inline void PosixMessageQueueBuffer_Report(
62 : enum SolidSyslogSeverity severity,
63 : uint16_t category,
64 : enum SolidSyslogPosixMessageQueueBufferErrors code
65 : )
66 : {
67 59 : SolidSyslog_Error(severity, &SolidSyslogPosixMessageQueueBufferErrorSource, category, (int32_t) code);
68 59 : }
69 :
70 : #endif /* SOLIDSYSLOGPOSIXMESSAGEQUEUEBUFFERPRIVATE_H */
|