UTILLib 2.0
Common C++ library with utilities.
Loading...
Searching...
No Matches
ilistenclient.h
Go to the documentation of this file.
1/*
2 * Copyright 2021 Ingemar Hedvall
3 * SPDX-License-Identifier: MIT
4 */
5
12#pragma once
13#include <atomic>
14#include <cstdint>
15#include <memory>
16#include <string>
17
19namespace util::log {
20
21namespace detail {
22class ListenMessage;
23}
24
31 public:
38 IListenClient(const std::string& host_name, uint16_t port);
39
40 virtual ~IListenClient() = default;
41
42 IListenClient() = delete;
43 IListenClient(const IListenClient&) = delete;
44 IListenClient& operator=(const IListenClient&) = delete;
45
51 [[nodiscard]] const std::string& HostName() const { return host_name_; }
52
58 [[nodiscard]] uint16_t Port() const { return port_; }
59
65 void Name(const std::string& name) { name_ = name; }
66
72 [[nodiscard]] std::string Name() const { return name_; }
73
79 void Description(const std::string& description) {
80 description_ = description;
81 }
82
88 [[nodiscard]] const std::string& Description() const { return description_; }
89
95 void Active(bool active) { active_ = active; }
96
103 [[nodiscard]] bool Active() const { return active_; }
104
110 [[nodiscard]] bool IsConnected() const { return connected_; }
111
118 [[nodiscard]] virtual bool GetMsg(
119 std::unique_ptr<detail::ListenMessage>& message) = 0;
120
126 virtual void SendLogLevel(uint64_t level) = 0;
127
128 protected:
129 std::atomic<bool> active_ =
130 true;
131 std::atomic<bool> connected_ = false;
132
133 private:
134 std::string host_name_ = "127.0.0.1";
135 uint16_t port_ = 0;
136 std::string name_;
137 std::string description_;
138};
139
140} // namespace util::log
bool Active() const
Returns if the interface is activated or deactivated.
Definition ilistenclient.h:103
uint16_t Port() const
Return the TCP/IP port.
Definition ilistenclient.h:58
const std::string & HostName() const
Returns the host name.
Definition ilistenclient.h:51
virtual ~IListenClient()=default
Default destructor.
bool IsConnected() const
Returns true if the client is connected to a server.
Definition ilistenclient.h:110
std::string Name() const
Name of the client.
Definition ilistenclient.h:72
void Name(const std::string &name)
Sets a name for the client.
Definition ilistenclient.h:65
void Description(const std::string &description)
Description of the client.
Definition ilistenclient.h:79
std::atomic< bool > connected_
True if connected.
Definition ilistenclient.h:131
std::atomic< bool > active_
Indicate if the message should be used or not.
Definition ilistenclient.h:129
IListenClient(const std::string &host_name, uint16_t port)
Constructor.
virtual void SendLogLevel(uint64_t level)=0
Send log level to the server.
const std::string & Description() const
Returns the cleint description.
Definition ilistenclient.h:88
void Active(bool active)
Active or deactivates the client.
Definition ilistenclient.h:95
virtual bool GetMsg(std::unique_ptr< detail::ListenMessage > &message)=0
Returns the next listen message.
The log namespace is used for log related classes and functions.
Definition idirectory.h:18
Implements a thread-safe queue.