$darkmode
tcp_transceiver_config.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2020 Robert Bosch GmbH
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * SPDX-License-Identifier: Apache-2.0
17  */
23 #pragma once
24 #ifndef CLOE_UTILITY_TCP_TRANSCEIVER_CONFIG_HPP_
25 #define CLOE_UTILITY_TCP_TRANSCEIVER_CONFIG_HPP_
26 
27 #include <chrono> // for duration
28 #include <string> // for string
29 #include <utility> // for move
30 
31 #include <cloe/core.hpp> // for Confable, Schema, Json
32 
33 namespace cloe {
34 namespace utility {
35 
41  TcpTransceiverConfiguration() = default;
42  TcpTransceiverConfiguration(int32_t attempts, std::chrono::duration<float> delay)
43  : retry_attempts(attempts), retry_delay(delay) {}
44  virtual ~TcpTransceiverConfiguration() = default;
45 
53  int32_t retry_attempts{60};
54 
61  std::chrono::duration<float> retry_delay{1.0};
62 
63  CONFABLE_SCHEMA(TcpTransceiverConfiguration) {
64  return Schema{
65  {"retry_attempts", Schema(&retry_attempts, "connection retry attempts")},
66  {"retry_delay_s", Schema(&retry_delay, "time delay between connection attempts")},
67  };
68  }
69 
70  void to_json(Json& j) const override {
71  j = {
72  {"retry_attempts", retry_attempts},
73  {"retry_delay_s", retry_delay.count()},
74  };
75  }
76 };
77 
86  TcpTransceiverFullConfiguration(const std::string& host, uint16_t port)
87  : host(host), port(port) {}
88  TcpTransceiverFullConfiguration(std::string&& host, uint16_t port)
89  : host(std::move(host)), port(port) {}
90 
94  std::string host{"localhost"};
95 
99  uint16_t port{0};
100 
101  CONFABLE_SCHEMA(TcpTransceiverFullConfiguration) {
102  return Schema{
104  {
105  {"host", Schema(&host, "hostname of connection")},
106  {"port", Schema(&port, "port of connection")},
107  },
108  };
109  }
110 
111  void to_json(Json& j) const override {
113  j["host"] = host;
114  j["port"] = port;
115  }
116 };
117 
118 } // namespace utility
119 } // namespace cloe
120 
121 #endif // CLOE_UTILITY_TCP_TRANSCEIVER_CONFIG_HPP_
Definition: confable.hpp:46
int32_t retry_attempts
Definition: tcp_transceiver_config.hpp:53
Definition: coordinator.hpp:36
Definition: tcp_transceiver_config.hpp:84
Json to_json() const
Definition: confable.cpp:74
Definition: schema.hpp:178
Definition: tcp_transceiver_config.hpp:40
std::chrono::duration< float > retry_delay
Definition: tcp_transceiver_config.hpp:61
virtual Schema schema_impl()
Definition: confable.cpp:80