From 5815d595c4d9a05eeaddf183e63b285092d42ad9 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Wed, 5 Feb 2020 18:35:08 -0800 Subject: [PATCH] move server Config out server::Server::Config doesn't add anything vs. server::Config --- documentation/server.rst | 5 +++- src/pvxs/server.h | 60 +++++++++++++++++++++------------------- src/server.cpp | 8 +++--- test/countdown.cpp | 2 +- test/dummyserv.cpp | 2 +- test/mailbox.cpp | 2 +- test/mcat.cpp | 2 +- 7 files changed, 44 insertions(+), 37 deletions(-) diff --git a/documentation/server.rst b/documentation/server.rst index 0f5d3b4..a412f66 100644 --- a/documentation/server.rst +++ b/documentation/server.rst @@ -17,7 +17,7 @@ The basic recipe to run a server using configuration from the process environmen .. code-block:: c++ - auto serv = Server::Config::from_env() + auto serv = server::Config::from_env() .build() // call serv.addSource() at least once serv.run(); // run intil SIGINT or serv.interrupt() @@ -30,5 +30,8 @@ If more than one Source is added, then an order of precedence is established thr the "order" argument of addSource(). In the event that more than one Source could provide/claim a given PV name, the Source with the lowest "order" will win. +.. doxygenstruct:: pvxs::server::Config + :members: + .. doxygenclass:: pvxs::server::Server :members: diff --git a/src/pvxs/server.h b/src/pvxs/server.h index 301efa3..6e48389 100644 --- a/src/pvxs/server.h +++ b/src/pvxs/server.h @@ -24,10 +24,41 @@ namespace pvxs { namespace server { struct Source; +class Server; + +//! Configuration for a Server +struct Config { + //! List of network interface addresses to which this server will bind. + //! interfaces.empty() treated as an alias for "0.0.0.0", which may also be given explicitly. + //! Port numbers are optional and unused (parsed and ignored) + std::vector interfaces; + //! Addresses to which (UDP) beacons message will be sent. + //! May include broadcast and/or unicast addresses. + //! Supplimented iif auto_beacon==true + std::vector beaconDestinations; + //! TCP port to bind. Default is 5075. May be zero. + unsigned short tcp_port; + //! UDP port to bind. Default is 5076. May not be zero, cf. Server::config() to find allocated port. + unsigned short udp_port; + //! Whether to populate the beacon address list automatically. (recommended) + bool auto_beacon; + + //! Server unique ID. Only meaningful in readback via Server::config() + std::array guid; + + //! Default configuration using process environment + PVXS_API + static Config from_env(); + Config() :tcp_port(5075), udp_port(5076), auto_beacon(true), guid{} {} + + //! Short-hand for @code Server(std::move(*this)) @endcode. + PVXS_API + Server build(); +}; /** PV Access protocol server instance * - * Use a Server::Config to determine how this server will bind, listen, + * Use a Config to determine how this server will bind, listen, * and announce itself. * * In order to be useful, a Server will have one or more Source instances added @@ -36,33 +67,6 @@ struct Source; class PVXS_API Server { public: - //! Configuration for a Server - struct Config { - //! List of network interface addresses to which this server will bind. - //! interfaces.empty() treated as an alias for "0.0.0.0", which may also be given explicitly. - //! Port numbers are optional and unused (parsed and ignored) - std::vector interfaces; - //! Addresses to which (UDP) beacons message will be sent. - //! May include broadcast and/or unicast addresses. - //! Supplimented iif auto_beacon==true - std::vector beaconDestinations; - //! TCP port to bind. Default is 5075. May be zero. - unsigned short tcp_port; - //! UDP port to bind. Default is 5076. May not be zero, cf. Server::config() to find allocated port. - unsigned short udp_port; - //! Whether to populate the beacon address list automatically. (recommended) - bool auto_beacon; - - //! Server unique ID. Only meaningful in readback via Server::config() - std::array guid; - - //! Default configuration using process environment - PVXS_API static Config from_env(); - Config() :tcp_port(5075), udp_port(5076), auto_beacon(true), guid{} {} - - //! Short-hand for @code Server(std::move(*this)) @endcode. - PVXS_API Server build(); - }; //! An empty/dummy Server Server(); diff --git a/src/server.cpp b/src/server.cpp index 63ce3f9..31ac641 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -54,9 +54,9 @@ void split_into(std::vector& out, const char *inp) } } -Server::Config Server::Config::from_env() +Config Config::from_env() { - Server::Config ret; + Config ret; ret.udp_port = 5076; if(const char *env = getenv("EPICS_PVAS_INTF_ADDR_LIST")) { @@ -89,7 +89,7 @@ Server::Config Server::Config::from_env() } -Server Server::Config::build() +Server Config::build() { Server ret(std::move(*this)); return ret; @@ -192,7 +192,7 @@ void Server::listSource(std::vector > &names) } } -const Server::Config& Server::config() const +const Config& Server::config() const { if(!pvt) throw std::logic_error("NULL Server"); diff --git a/test/countdown.cpp b/test/countdown.cpp index 8ceb182..e0f6ed8 100644 --- a/test/countdown.cpp +++ b/test/countdown.cpp @@ -117,7 +117,7 @@ int main(int argc, char *argv[]) auto src = std::make_shared("countdown"); - auto serv = Server::Config::from_env() + auto serv = Config::from_env() .build() .addSource("countdown", src); diff --git a/test/dummyserv.cpp b/test/dummyserv.cpp index 472217f..71d12c1 100644 --- a/test/dummyserv.cpp +++ b/test/dummyserv.cpp @@ -139,7 +139,7 @@ int main(int argc, char *argv[]) auto src = std::make_shared("blah"); - auto serv = Server::Config::from_env() + auto serv = Config::from_env() .build() .addSource("dummy", src); diff --git a/test/mailbox.cpp b/test/mailbox.cpp index 9a05e07..60a9163 100644 --- a/test/mailbox.cpp +++ b/test/mailbox.cpp @@ -44,7 +44,7 @@ int main(int argc, char* argv[]) src.add(argv[1], pv); - auto serv = Server::Config::from_env() + auto serv = Config::from_env() .build() .addSource("box", src.source()); diff --git a/test/mcat.cpp b/test/mcat.cpp index f788967..6915b10 100644 --- a/test/mcat.cpp +++ b/test/mcat.cpp @@ -152,7 +152,7 @@ int main(int argc, char* argv[]) src->name = argv[optind]; src->fname = argv[optind+1]; - auto serv = server::Server::Config::from_env() + auto serv = server::Config::from_env() .build() .addSource("mcat", src);