Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
SocketClientParams.hxx
Go to the documentation of this file.
1
35#ifndef _UTILS_SOCKETCLIENTPARAMS_HXX_
36#define _UTILS_SOCKETCLIENTPARAMS_HXX_
37
47{
48public:
53 static std::unique_ptr<SocketClientParams> from_static(
54 string hostname, int port);
55
61 static std::unique_ptr<SocketClientParams> from_static_and_mdns(
62 string hostname, int port, string mdns_service);
63
64 virtual ~SocketClientParams()
65 {
66 }
67
80
82 virtual SearchMode search_mode() = 0;
83
86 virtual string mdns_service_name() = 0;
87
91 virtual string mdns_host_name() = 0;
92
96 virtual string manual_host_name() = 0;
97
99 virtual int manual_port() = 0;
100
103 virtual bool enable_last() = 0;
104
108 virtual string last_host_name() = 0;
109
111 virtual int last_port() = 0;
112
116 virtual bool one_shot() { return false; }
117
123 virtual void set_last(const char *hostname, int port)
124 {
125 }
126
129 {
130 CYCLE_START = 0,
147 CONNECTION_LOST
148 };
149
156 virtual void log_message(LogMessage id, const string &arg = string())
157 {
158 }
159
161 virtual int retry_seconds()
162 {
163 return 5;
164 }
165
167 virtual int timeout_seconds()
168 {
169 return 255;
170 }
171
174 virtual bool disallow_local()
175 {
176 return false;
177 }
178};
179
182{
183public:
186 {
187 return AUTO_MANUAL;
188 }
189
192 string mdns_service_name() override
193 {
194 return string();
195 }
196
200 string mdns_host_name() override
201 {
202 return string();
203 }
204
208 string manual_host_name() override
209 {
210 return string();
211 }
212
214 int manual_port() override
215 {
216 return -1;
217 }
218
221 bool enable_last() override
222 {
223 return false;
224 }
225
229 string last_host_name() override
230 {
231 return string();
232 }
233
235 int last_port() override
236 {
237 return -1;
238 }
239};
240
244{
245public:
248 string mdns_service_name() override
249 {
250 return mdnsService_;
251 }
252
256 string manual_host_name() override
257 {
258 return staticHost_;
259 }
260
262 int manual_port() override
263 {
264 return staticPort_;
265 }
266
267protected:
268 friend std::unique_ptr<SocketClientParams> SocketClientParams::from_static(
269 string hostname, int port);
270 friend std::unique_ptr<SocketClientParams>
272 string hostname, int port, string mdns_service);
273
277 int staticPort_ = -1;
280};
281
282#endif // _UTILS_SOCKETCLIENTPARAMS_HXX_
Default implementation that supplies parametrized values for static and mdns connection methods.
int staticPort_
what to return for manual_port
string staticHost_
what to return for manual_host_name
string mdnsService_
what to return for mdns_service_name
Default implementation that supplies no connection method.
string manual_host_name() override
string mdns_service_name() override
SearchMode search_mode() override
Abstract interface to represent parameters to the socket client.
virtual string last_host_name()=0
virtual void set_last(const char *hostname, int port)
This function is called on an unspecified thread when a connection is successfully established.
virtual string mdns_service_name()=0
virtual string mdns_host_name()=0
virtual bool enable_last()=0
SearchMode
Parameter that determines what order we will attempt to connect.
@ AUTO_MANUAL
Try mDNS first, then (if it failed) try manual address.
@ MANUAL_ONLY
Try only manual address, never try mDNS lookups.
@ MANUAL_AUTO
Try manual address first, then (if it failed) try mDNS.
@ AUTO_ONLY
Try only mDNS, ignore manual address.
virtual string manual_host_name()=0
virtual bool disallow_local()
static std::unique_ptr< SocketClientParams > from_static(string hostname, int port)
static std::unique_ptr< SocketClientParams > from_static_and_mdns(string hostname, int port, string mdns_service)
virtual int last_port()=0
virtual SearchMode search_mode()=0
virtual void log_message(LogMessage id, const string &arg=string())
Notifies the caller about the current phase of the connection.
virtual int manual_port()=0
LogMessage
Enum for sending connection status updates to the caller.
@ MDNS_NOT_FOUND
mDNS lookup failed.
@ CONNECT_FAILED_SELF
Connection dropped because target is localhost.
@ MDNS_FOUND
mDNS lookup suceeded.
@ CONNECT_MDNS
Connecting to mDNS target. Arg is host:port.
@ CONNECT_MANUAL
Connecting to manual target. Arg is hostname:port.
@ MDNS_SEARCH
Starting mDNS lookup. Argument: mdns [hostname.]service_name.
@ CONNECT_FAILED_ONESHOT
Attempt to search & connect failed, given up. No arg.
@ CONNECT_RE
Attempting to reconnect. Arg is host:port.