Server add builtin Source
This commit is contained in:
+12
-1
@@ -23,6 +23,7 @@
|
||||
namespace pvxs {
|
||||
namespace server {
|
||||
|
||||
struct SharedPV;
|
||||
struct Source;
|
||||
class Server;
|
||||
|
||||
@@ -63,13 +64,18 @@ struct Config {
|
||||
*
|
||||
* In order to be useful, a Server will have one or more Source instances added
|
||||
* to it with addSource().
|
||||
*
|
||||
* As a convienence, each Server instance automatically contains a "builtin" StaticSource
|
||||
* to which SharedPV instances can be directly added.
|
||||
* The "builtin" has priority zero, and can be accessed or even removed like any Source
|
||||
* explicitly added with addSource().
|
||||
*/
|
||||
class PVXS_API Server
|
||||
{
|
||||
public:
|
||||
|
||||
//! An empty/dummy Server
|
||||
Server();
|
||||
constexpr Server() = default;
|
||||
//! Create/allocate, but do not start, a new server with the provided config.
|
||||
explicit Server(Config&&);
|
||||
~Server();
|
||||
@@ -91,6 +97,11 @@ public:
|
||||
//! effective config
|
||||
const Config& config() const;
|
||||
|
||||
//! Add a SharedPV to the builtin StaticSource
|
||||
Server& addPV(const std::string& name, const SharedPV& pv);
|
||||
//! Remove a SharedPV from the builtin StaticSource
|
||||
Server& removePV(const std::string& name);
|
||||
|
||||
//! Add a Source to this server with an arbitrary source name.
|
||||
//!
|
||||
//! @param name Source name
|
||||
|
||||
+18
-2
@@ -126,8 +126,6 @@ Server Config::build()
|
||||
return ret;
|
||||
}
|
||||
|
||||
Server::Server() {}
|
||||
|
||||
Server::Server(Config&& conf)
|
||||
{
|
||||
/* Here be dragons.
|
||||
@@ -231,6 +229,22 @@ const Config& Server::config() const
|
||||
return pvt->effective;
|
||||
}
|
||||
|
||||
Server& Server::addPV(const std::string& name, const SharedPV& pv)
|
||||
{
|
||||
if(!pvt)
|
||||
throw std::logic_error("NULL Server");
|
||||
pvt->builtinsrc.add(name, pv);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Server& Server::removePV(const std::string& name)
|
||||
{
|
||||
if(!pvt)
|
||||
throw std::logic_error("NULL Server");
|
||||
pvt->builtinsrc.remove(name);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Server& Server::start()
|
||||
{
|
||||
if(!pvt)
|
||||
@@ -312,6 +326,7 @@ Server::Pvt::Pvt(Config&& conf)
|
||||
,beaconSender(AF_INET, SOCK_DGRAM, 0)
|
||||
,beaconTimer(event_new(acceptor_loop.base, -1, EV_TIMEOUT, doBeaconsS, this))
|
||||
,searchReply(0x10000)
|
||||
,builtinsrc(StaticSource::build())
|
||||
,state(Stopped)
|
||||
{
|
||||
// empty interface address list implies the wildcard
|
||||
@@ -453,6 +468,7 @@ Server::Pvt::Pvt(Config&& conf)
|
||||
{
|
||||
auto L = sourcesLock.lockWriter();
|
||||
sources[std::make_pair(-1, "server")] = std::make_shared<ServerSource>(this);
|
||||
sources[std::make_pair(-1, "builtin")] = builtinsrc.source();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
#include <pvxs/server.h>
|
||||
#include <pvxs/source.h>
|
||||
#include <pvxs/sharedpv.h>
|
||||
#include "evhelper.h"
|
||||
#include "utilpvt.h"
|
||||
#include "dataimpl.h"
|
||||
@@ -222,6 +223,8 @@ struct Server::Pvt
|
||||
|
||||
Source::Search searchOp;
|
||||
|
||||
StaticSource builtinsrc;
|
||||
|
||||
RWLock sourcesLock;
|
||||
std::map<std::pair<int, std::string>, std::shared_ptr<Source> > sources;
|
||||
|
||||
|
||||
+4
-5
@@ -36,17 +36,16 @@ int main(int argc, char* argv[])
|
||||
|
||||
auto initial = nt::NTScalar{TypeCode::Float64}.create();
|
||||
initial["value"] = 42.0;
|
||||
|
||||
auto src(StaticSource::build());
|
||||
initial["alarm.severity"] = 0;
|
||||
initial["alarm.status"] = 0;
|
||||
initial["alarm.message"] = "";
|
||||
|
||||
auto pv(SharedPV::buildMailbox());
|
||||
pv.open(initial);
|
||||
|
||||
src.add(argv[1], pv);
|
||||
|
||||
auto serv = Config::from_env()
|
||||
.build()
|
||||
.addSource("box", src.source());
|
||||
.addPV(argv[1], pv);
|
||||
|
||||
auto& conf = serv.config();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user