Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Server.h
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Frameworks_Modbus_Server_h_
5#define _Stroika_Frameworks_Modbus_Server_h_ 1
6
7#include "Stroika/Frameworks/StroikaPreComp.h"
8
9#include <optional>
10
15
16#include "IModbusService.h"
17
18/**
19 *
20 * \note Code-Status: <a href="Code-Status.md#Beta">Beta</a>
21 *
22 * \note Testing Note
23 * This code was tested and used by a client as of around Stroika v2.0a204, but may not have been used since, and
24 * probably has not undergone testing since. It could have small breaks, but I don't have stuff with which to test, so
25 * as-is - sorry
26 *
27 */
29
30 using namespace Stroika::Foundation;
31
32 /**
33 */
34 struct ServerOptions {
35 /**
36 * By spec, defaults to 502
37 */
38 optional<uint16_t> fListenPort;
39
40 /**
41 * Logger to write interesting messages to.
42 */
43 optional<Execution::Logger*> fLogger;
44
45 /**
46 * Often helpful to specify reUseAddr = true, to avoid trouble restarting service
47 */
48 optional<IO::Network::Socket::BindFlags> fBindFlags;
49
50 /**
51 * To specify size, provide your own threadpool
52 */
53 shared_ptr<Execution::ThreadPool> fThreadPool;
54
55 /**
56 * defaults to true iff argument fThreadPool null.
57 *
58 * \note Either let this class or caller must shutdown threadpool before exiting app.
59 */
60 optional<bool> fShutdownThreadPool;
61 };
62
63 /**
64 * Construct a Modbus TCP Listener which will listen for Modbus connections, run them using
65 * the optionally provided thread pool (and other configuration options) and send actual handler
66 * requests to the argument IModbusService handler.
67 *
68 * Supported Function Codes:
69 * o kReadCoils (#1)
70 * o ReadDiscreteInputs (#2)
71 * o ReadHoldingResisters (#3)
72 * o ReadInputRegister (#4)
73 * o WriteSingleCoil (#5)
74 *
75 * \pre serviceHandler != nullptr
76 */
77 Execution::Thread::Ptr MakeModbusTCPServerThread (const shared_ptr<IModbusService>& serviceHandler, const ServerOptions& options = ServerOptions{});
78
79 template <typename MODBUS_REGISTER_DESCRIPTOR, typename SRC_TYPE>
80 void SplitSrcAcrossOutputs (const SRC_TYPE& s, typename MODBUS_REGISTER_DESCRIPTOR::NameType baseRegister,
82
83}
84
85/*
86 ********************************************************************************
87 ***************************** Implementation Details ***************************
88 ********************************************************************************
89 */
90#include "Server.inl"
91
92#endif /*_Stroika_Frameworks_Modbus_Server_h_*/
Thread::Ptr is a (unsynchronized) smart pointer referencing an internally synchronized std::thread ob...
Definition Thread.h:334
Execution::Thread::Ptr MakeModbusTCPServerThread(const shared_ptr< IModbusService > &serviceHandler, const ServerOptions &options=ServerOptions{})
Definition Server.cpp:435