server GET_FIELD reply

This commit is contained in:
Michael Davidsaver
2019-12-10 16:18:59 -08:00
parent a6ff69eb42
commit d20ac8ee6d
3 changed files with 30 additions and 2 deletions
+2
View File
@@ -19,6 +19,7 @@
#include <pvxs/util.h>
namespace pvxs {
class Value;
namespace impl {
struct ServerConn;
}
@@ -257,6 +258,7 @@ struct PVXS_API Source {
//! Token for an in-progress request for Channel data type information.
struct PVXS_API Introspect : public OpBase
{
virtual void reply(const Value& prototype) =0;
//! Negative reply w/ error message
virtual void error(const std::string& msg) =0;
// void success(Data);
+19 -1
View File
@@ -7,6 +7,8 @@
#include <cassert>
#include <pvxs/log.h>
#include "dataimpl.h"
#include "dataencode.h"
#include "serverconn.h"
namespace pvxs { namespace impl {
@@ -35,14 +37,28 @@ struct ServerIntrospectControl : public server::Introspect
error("Implict Cancel");
}
virtual void reply(const Value& prototype) override final
{
auto desc = prototype._desc();
if(!desc)
throw std::logic_error("Can't reply to GET_FIELD with Null prototype");
Status sts{Status::Ok};
doReply(desc, sts);
}
virtual void error(const std::string &msg) override final
{
Status sts{Status::Error, msg};
doReply(nullptr, sts);
}
void doReply(const FieldDesc* type, const Status& sts)
{
auto serv = server.lock();
if(!serv)
return; // soft fail if already completed, cancelled, disconnected, ....
serv->acceptor_loop.call([this, &sts](){
serv->acceptor_loop.call([this, type, &sts](){
auto oper = op.lock();
if(!oper || oper->state != ServerOp::Executing)
return;
@@ -60,6 +76,8 @@ struct ServerIntrospectControl : public server::Introspect
EvOutBuf R(be, conn->txBody.get());
to_wire(R, uint32_t(oper->ioid));
to_wire(R, sts);
if(type)
to_wire(R, type);
// would be FieldDesc payload if Ok or Warn
}
+9 -1
View File
@@ -12,21 +12,29 @@
#include <epicsEvent.h>
#include <pvxs/server.h>
#include <pvxs/data.h>
#include <pvxs/log.h>
namespace {
using namespace pvxs;
using namespace pvxs::server;
DEFINE_LOGGER(dummy,"dummyserv");
const Value mytype = TypeDef(TypeCode::Struct)
.begin()
.insert("value", TypeCode::Float64)
.create();
struct DummyHandler : public Handler
{
virtual ~DummyHandler() {}
virtual void onIntrospect(std::unique_ptr<Introspect> &&op) override final
{
op->error("Got nothing");
op->reply(mytype);
//op->error("Got nothing");
}
};