#include <stdio.h>
#if !defined(_WIN32)
#include <signal.h>
#define USE_SIGNAL
#endif
#include <epicsEvent.h>
#include <pv/pvData.h>
#include <pv/serverContext.h>
#include <pva/server.h>
#include <pva/sharedstate.h>
namespace {
epicsEvent done;
#ifdef USE_SIGNAL
void alldone(int num)
{
(void)num;
done.signal();
}
#endif
static pvd::StructureConstPtr string_type(pvd::getFieldCreate()->createFieldBuilder()
->
add(
"value", pvd::pvString)
->createStructure());
static pvd::StructureConstPtr int_type(pvd::getFieldCreate()->createFieldBuilder()
->
add(
"value", pvd::pvInt)
->createStructure());
static pvd::StructureConstPtr real_type(pvd::getFieldCreate()->createFieldBuilder()
->
add(
"value", pvd::pvDouble)
->createStructure());
}
int main(int argc, char *argv[])
{
try {
if(argc<=1) {
fprintf(stderr, "Usage: %s <pvname[=type]> ...\n type: string, int, real", argv[0]);
return 1;
}
for(int i=1; i<argc; i++) {
std::string
name(argv[i]), type(
"string");
size_t sep =
name.find(
'=');
if(sep==0 || sep==
name.size()) {
fprintf(stderr, "Invalid: '%s'\n", argv[i]);
return 1;
}
type =
name.substr(sep+1);
}
if(type=="string") {
pv->open(string_type);
} else if(type=="int") {
pv->open(int_type);
} else if(type=="real") {
pv->open(real_type);
} else {
fprintf(stderr, "Unknown type '%s'\n", type.c_str());
return 1;
}
provider.add(argv[1], pv);
}
pva::ServerContext::shared_pointer server(pva::ServerContext::create(
pva::ServerContext::Config()
.provider(provider.provider())
));
#ifdef USE_SIGNAL
signal(SIGINT, alldone);
signal(SIGTERM, alldone);
signal(SIGQUIT, alldone);
#endif
server->printInfo();
printf("Running with mailbox '%s'\n", argv[1]);
done.wait();
return 1;
}
return 0;
}
virtual const char * what() const noexcept
A Provider based on a list of SharedPV instance.
static shared_pointer buildMailbox(Config *conf=0)
A SharedPV which accepts all Put operations, and fails all RPC operations. In closed state.
const char * name(ScalarType scalarType)