$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 
25 #include <chrono> // for duration
26 #include <string> // for string
27 #include <utility> // for move
28 
29 #include <cloe/core.hpp> // for Confable, Schema, Json
30 
31 namespace cloe {
32 namespace utility {
33 
39  TcpTransceiverConfiguration() = default;
40  TcpTransceiverConfiguration(int32_t attempts, std::chrono::duration<float> delay)
41  : retry_attempts(attempts), retry_delay(delay) {}
42  virtual ~TcpTransceiverConfiguration() = default;
43 
51  int32_t retry_attempts{60};
52 
59  std::chrono::duration<float> retry_delay{1.0};
60 
61  CONFABLE_SCHEMA(TcpTransceiverConfiguration) {
62  return Schema{
63  {"retry_attempts", Schema(&retry_attempts, "connection retry attempts")},
64  {"retry_delay_s", Schema(&retry_delay, "time delay between connection attempts")},
65  };
66  }
67 
68  void to_json(Json& j) const override {
69  j = {
70  {"retry_attempts", retry_attempts},
71  {"retry_delay_s", retry_delay.count()},
72  };
73  }
74 };
75 
84  TcpTransceiverFullConfiguration(std::string host, uint16_t port)
85  : host(std::move(host)), port(port) {}
86 
90  std::string host{"localhost"};
91 
95  uint16_t port{0};
96 
97  CONFABLE_SCHEMA(TcpTransceiverFullConfiguration) {
98  return Schema{
100  {
101  {"host", Schema(&host, "hostname of connection")},
102  {"port", Schema(&port, "port of connection")},
103  },
104  };
105  }
106 
107  void to_json(Json& j) const override {
109  j["host"] = host;
110  j["port"] = port;
111  }
112 };
113 
114 } // namespace utility
115 } // namespace cloe
Definition: confable.hpp:43
virtual Schema schema_impl()
Definition: confable.cpp:84
Json to_json() const
Definition: confable.cpp:78
Definition: schema.hpp:175
Definition: tcp_transceiver_config.hpp:38
int32_t retry_attempts
Definition: tcp_transceiver_config.hpp:51
std::chrono::duration< float > retry_delay
Definition: tcp_transceiver_config.hpp:59
Definition: tcp_transceiver_config.hpp:82
std::string host
Definition: tcp_transceiver_config.hpp:90
uint16_t port
Definition: tcp_transceiver_config.hpp:95