UTILLib 2.0
Common C++ library with utilities.
Loading...
Searching...
No Matches
isyslogserver.h
Go to the documentation of this file.
1/*
2 * Copyright 2022 Ingemar Hedvall
3 * SPDX-License-Identifier: MIT
4 */
5
13
14#pragma once
15#include <atomic>
16#include <cstdint>
17#include <memory>
18#include <optional>
19
20#include "util/syslogmessage.h"
22
23namespace util::syslog {
24
31enum class SyslogServerType : uint8_t {
37};
38
45class ISyslogServer {
46 public:
47 ISyslogServer(const ISyslogServer&) = delete;
48 virtual ~ISyslogServer() = default;
49
55 [[nodiscard]] SyslogServerType Type() const { return type_; }
56
64 void Address(const std::string& address);
65
66 [[nodiscard]] const std::string& Address()
67 const {
68 return address_;
69 }
70
71 void Name(
72 const std::string& name) {
73 name_ = name;
74 }
75
76 const std::string& Name() const {
77 return name_;
78 }
79
80 void Port(uint16_t port) {
81 port_ = port;
82 }
83
84 [[nodiscard]] uint16_t Port() const {
85 return port_;
86 }
87
88 virtual void AddMsg(
89 const SyslogMessage& msg);
91
100 std::optional<SyslogMessage> GetMsg(bool block);
101
102 virtual void Start();
103 virtual void Stop();
104
105 [[nodiscard]] size_t NofMessages()
106 const {
107 return msg_queue_ ? msg_queue_->Size() : 0;
108 }
109
116 [[nodiscard]] bool IsOperable() const { return operable_; }
117
124 [[nodiscard]] virtual size_t NofConnections() const;
125
126 protected:
127 ISyslogServer() = default;
128 std::atomic<bool> operable_ = true;
130
131 private:
132 std::string address_ = "0.0.0.0";
133 std::string name_;
134 uint16_t port_ = 0;
135 std::unique_ptr<log::ThreadSafeQueue<SyslogMessage>>
136 msg_queue_;
137};
138
139} // namespace util::syslog
virtual void Start()
Starts the worker thread in the server.
std::atomic< bool > operable_
Operable flag.
Definition isyslogserver.h:128
SyslogServerType Type() const
Return s the type of server.
Definition isyslogserver.h:55
SyslogServerType type_
Type of server.
Definition isyslogserver.h:129
const std::string & Name() const
Definition isyslogserver.h:76
ISyslogServer()=default
Default constructor.
const std::string & Address() const
Definition isyslogserver.h:66
void Port(uint16_t port)
Definition isyslogserver.h:80
void Name(const std::string &name)
Definition isyslogserver.h:71
void Address(const std::string &address)
Bind address of the server.
uint16_t Port() const
Definition isyslogserver.h:84
virtual void Stop()
Stops the worker thread in the server.
virtual size_t NofConnections() const
Returns number of connections to the server.
std::optional< SyslogMessage > GetMsg(bool block)
Returns the next message in the queue.
size_t NofMessages() const
Definition isyslogserver.h:105
virtual void AddMsg(const SyslogMessage &msg)
bool IsOperable() const
Returns true if the receiver works as normal.
Definition isyslogserver.h:116
Simple wrapper around the parsing and generating os syslog messages.
Definition syslogmessage.h:72
The syslog namespace is used for the syslog interface.
Definition isyslogserver.h:23
SyslogServerType
Defines the type of syslog server.
Definition isyslogserver.h:31
@ TlsServer
Uses TLS on top of TCP (RFC5425).
Definition isyslogserver.h:33
@ TcpServer
Uses plain TCP protocol (RFC6587).
Definition isyslogserver.h:34
@ TcpSubscriber
Client that subscribe on syslog messages.
Definition isyslogserver.h:36
@ TcpPublisher
Server that sends syslog messages.
Definition isyslogserver.h:35
@ UdpServer
Uses UDP protocol (RFC5426).
Definition isyslogserver.h:32
Implements an interface against a syslog message.
Implements a thread-safe queue.