URI: ev4 to epics, and URI version major check
This commit is contained in:
2
DEMO
2
DEMO
@ -34,7 +34,7 @@ New : testArray10_1 3 11 22 33
|
||||
--------------------------------------------------------------------------------
|
||||
> pvget -r 'field()' testValue
|
||||
testValue
|
||||
uri:ev4:nt/2012/pwd:NTScalar
|
||||
epics:nt/NTScalar:1.0
|
||||
double value 1.23
|
||||
alarm_t alarm
|
||||
int severity 0
|
||||
|
@ -823,15 +823,15 @@ NTFormatterLUTMap ntFormatterLUT;
|
||||
|
||||
void initializeNTFormatterLUT()
|
||||
{
|
||||
ntFormatterLUT["ev4:nt/NTScalar:1.0"] = formatNTScalar;
|
||||
ntFormatterLUT["ev4:nt/NTScalarArray:1.0"] = formatNTScalarArray;
|
||||
ntFormatterLUT["ev4:nt/NTEnum:1.0"] = formatNTEnum;
|
||||
ntFormatterLUT["ev4:nt/NTTable:1.0"] = formatNTTable;
|
||||
ntFormatterLUT["ev4:nt/NTMatrix:1.0"] = formatNTMatrix;
|
||||
ntFormatterLUT["ev4:nt/NTAny:1.0"] = formatNTAny;
|
||||
ntFormatterLUT["ev4:nt/NTNameValue:1.0"] = formatNTNameValue;
|
||||
ntFormatterLUT["ev4:nt/NTURI:1.0"] = formatNTURI;
|
||||
ntFormatterLUT["ev4:nt/NTNDArray:1.0"] = formatNTNDArray;
|
||||
ntFormatterLUT["epics:nt/NTScalar:1"] = formatNTScalar;
|
||||
ntFormatterLUT["epics:nt/NTScalarArray:1"] = formatNTScalarArray;
|
||||
ntFormatterLUT["epics:nt/NTEnum:1"] = formatNTEnum;
|
||||
ntFormatterLUT["epics:nt/NTTable:1"] = formatNTTable;
|
||||
ntFormatterLUT["epics:nt/NTMatrix:1"] = formatNTMatrix;
|
||||
ntFormatterLUT["epics:nt/NTAny:1"] = formatNTAny;
|
||||
ntFormatterLUT["epics:nt/NTNameValue:1"] = formatNTNameValue;
|
||||
ntFormatterLUT["epics:nt/NTURI:1"] = formatNTURI;
|
||||
ntFormatterLUT["epics:nt/NTNDArray:1"] = formatNTNDArray;
|
||||
}
|
||||
|
||||
void formatNT(std::ostream& o, PVFieldPtr const & pv)
|
||||
@ -856,6 +856,11 @@ void formatNT(std::ostream& o, PVFieldPtr const & pv)
|
||||
{
|
||||
string id = pvStruct->getField()->getID();
|
||||
|
||||
// remove minor
|
||||
size_t pos = id.find_last_of('.');
|
||||
if (pos != string::npos)
|
||||
id = id.substr(0, pos);
|
||||
|
||||
NTFormatterLUTMap::const_iterator formatter = ntFormatterLUT.find(id);
|
||||
if (formatter != ntFormatterLUT.end())
|
||||
{
|
||||
@ -2040,7 +2045,7 @@ int main (int argc, char *argv[])
|
||||
|
||||
Structure::const_shared_pointer uriStructure(
|
||||
getFieldCreate()->createStructure(
|
||||
"ev4:nt/NTURI:1.0",
|
||||
"epics:nt/NTURI:1.0",
|
||||
uriFieldNames,
|
||||
uriFields
|
||||
)
|
||||
|
@ -593,3 +593,6 @@ bool URI::parse(const string& uri, URI& result)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool starts_with(const string& s1, const string& s2) {
|
||||
return s2.size() <= s1.size() && s1.compare(0, s2.size(), s2) == 0;
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ std::ostream& printEnumT(std::ostream& o, epics::pvData::PVStructure const & pvE
|
||||
std::ostream& printEnumT(std::ostream& o, epics::pvData::PVStructure::shared_pointer const & pvEnumT);
|
||||
std::ostream& printTimeT(std::ostream& o, epics::pvData::PVStructure::shared_pointer const & pvTimeT);
|
||||
|
||||
bool starts_with(const std::string& str, const std::string& part);
|
||||
|
||||
/* Converts a hex character to its integer value */
|
||||
char from_hex(char ch);
|
||||
|
@ -476,6 +476,11 @@ private:
|
||||
|
||||
ServerContextImpl::shared_pointer m_serverContext;
|
||||
|
||||
// s1 starts with s2 check
|
||||
static bool starts_with(const string& s1, const string& s2) {
|
||||
return s2.size() <= s1.size() && s1.compare(0, s2.size(), s2) == 0;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
ServerRPCService(ServerContextImpl::shared_pointer const & context) :
|
||||
@ -489,7 +494,7 @@ public:
|
||||
{
|
||||
// NTURI support
|
||||
PVStructure::shared_pointer args(
|
||||
(arguments->getStructure()->getID() == "ev4:nt/NTURI:1.0") ?
|
||||
(starts_with(arguments->getStructure()->getID(), "epics:nt/NTURI:1.")) ?
|
||||
arguments->getStructureField("query") :
|
||||
arguments
|
||||
);
|
||||
@ -598,13 +603,13 @@ public:
|
||||
int32 ServerRPCService::TIMEOUT_SEC = 3;
|
||||
Structure::const_shared_pointer ServerRPCService::helpStructure =
|
||||
getFieldCreate()->createFieldBuilder()->
|
||||
setId("ev4:nt/NTScalar:1.0")->
|
||||
setId("epics:nt/NTScalar:1.0")->
|
||||
add("value", pvString)->
|
||||
createStructure();
|
||||
|
||||
Structure::const_shared_pointer ServerRPCService::channelListStructure =
|
||||
getFieldCreate()->createFieldBuilder()->
|
||||
setId("ev4:nt/NTScalarArray:1.0")->
|
||||
setId("epics:nt/NTScalarArray:1.0")->
|
||||
addArray("value", pvString)->
|
||||
createStructure();
|
||||
|
||||
|
@ -15,6 +15,11 @@ static Structure::const_shared_pointer resultStructure =
|
||||
add("c", pvDouble)->
|
||||
createStructure();
|
||||
|
||||
// s1 starts with s2 check
|
||||
static bool starts_with(const std::string& s1, const std::string& s2) {
|
||||
return s2.size() <= s1.size() && s1.compare(0, s2.size(), s2) == 0;
|
||||
}
|
||||
|
||||
class SumServiceImpl :
|
||||
public RPCService
|
||||
{
|
||||
@ -23,7 +28,7 @@ class SumServiceImpl :
|
||||
{
|
||||
// NTURI support
|
||||
PVStructure::shared_pointer args(
|
||||
(pvArguments->getStructure()->getID() == "ev4:nt/NTURI:1.0") ?
|
||||
(starts_with(pvArguments->getStructure()->getID(), "epics:nt/NTURI:1.")) ?
|
||||
pvArguments->getStructureField("query") :
|
||||
pvArguments
|
||||
);
|
||||
|
@ -22,7 +22,7 @@ class WildServiceImpl :
|
||||
throw (RPCRequestException)
|
||||
{
|
||||
// requires NTURI as argument
|
||||
if (pvArguments->getStructure()->getID() != "ev4:nt/NTURI:1.0")
|
||||
if (pvArguments->getStructure()->getID() != "epics:nt/NTURI:1.0")
|
||||
throw RPCRequestException(Status::STATUSTYPE_ERROR, "RPC argument must be a NTURI normative type");
|
||||
|
||||
std::string channelName = pvArguments->getSubField<PVString>("path")->get();
|
||||
|
@ -29,7 +29,7 @@ epics::pvData::StructureConstPtr createNTNDArrayStructure()
|
||||
add("reverse", pvBoolean)->
|
||||
createStructure();
|
||||
|
||||
StructureConstPtr attributeStruc = fb->setId("ev4:nt/NTAttribute:1.0")->
|
||||
StructureConstPtr attributeStruc = fb->setId("epics:nt/NTAttribute:1.0")->
|
||||
add("name", pvString)->
|
||||
add("value", getFieldCreate()->createVariantUnion())->
|
||||
add("descriptor", pvString)->
|
||||
@ -38,7 +38,7 @@ epics::pvData::StructureConstPtr createNTNDArrayStructure()
|
||||
createStructure();
|
||||
|
||||
|
||||
ntndArrayStructure = fb->setId("ev4:nt/NTNDArray:1.0")->
|
||||
ntndArrayStructure = fb->setId("epics:nt/NTNDArray:1.0")->
|
||||
add("value", valueType)->
|
||||
add("codec", codecStruc)->
|
||||
add("compressedSize", pvLong)->
|
||||
|
@ -38,6 +38,12 @@ void testServerShutdown();
|
||||
// TODO temp
|
||||
#include "testNTImage.cpp"
|
||||
|
||||
// s1 starts with s2 check
|
||||
bool starts_with(const string& s1, const string& s2) {
|
||||
return s2.size() <= s1.size() && s1.compare(0, s2.size(), s2) == 0;
|
||||
}
|
||||
|
||||
|
||||
Mutex structureStoreMutex;
|
||||
map<string, PVStructure::shared_pointer> structureStore;
|
||||
|
||||
@ -291,7 +297,7 @@ static epics::pvData::PVStructure::shared_pointer createNTTable(int columnsCount
|
||||
PVStructure::shared_pointer result(
|
||||
getPVDataCreate()->createPVStructure(
|
||||
getFieldCreate()->createStructure(
|
||||
"ev4:nt/NTTable:1.0", tableFieldNames, tableFields)
|
||||
"epics:nt/NTTable:1.0", tableFieldNames, tableFields)
|
||||
)
|
||||
);
|
||||
result->getSubField<PVStringArray>("labels")->replace(freeze(labels));
|
||||
@ -329,7 +335,7 @@ static epics::pvData::PVStructure::shared_pointer createNTNameValue(int columnsC
|
||||
PVStructure::shared_pointer result(
|
||||
getPVDataCreate()->createPVStructure(
|
||||
getFieldCreate()->createStructure(
|
||||
"ev4:nt/NTNameValue:1.0", tableFieldNames, tableFields)
|
||||
"epics:nt/NTNameValue:1.0", tableFieldNames, tableFields)
|
||||
)
|
||||
);
|
||||
result->getSubField<PVStringArray>("name")->replace(freeze(labels));
|
||||
@ -341,7 +347,7 @@ static epics::pvData::PVStructure::shared_pointer createNTAggregate()
|
||||
{
|
||||
epics::pvData::StructureConstPtr s =
|
||||
getFieldCreate()->createFieldBuilder()->
|
||||
setId("ev4:nt/NTAggregate:1.0")->
|
||||
setId("epics:nt/NTAggregate:1.0")->
|
||||
add("value", pvDouble)->
|
||||
add("N", pvLong)->
|
||||
add("dispersion", pvDouble)->
|
||||
@ -360,7 +366,7 @@ static epics::pvData::PVStructure::shared_pointer createNTHistogram()
|
||||
{
|
||||
epics::pvData::StructureConstPtr s =
|
||||
getFieldCreate()->createFieldBuilder()->
|
||||
setId("ev4:nt/NTHistogram:1.0")->
|
||||
setId("epics:nt/NTHistogram:1.0")->
|
||||
addArray("ranges", pvDouble)->
|
||||
addArray("value", pvInt)->
|
||||
add("timeStamp", getStandardField()->timeStamp())->
|
||||
@ -623,23 +629,23 @@ public:
|
||||
{
|
||||
ScopedLock lock(shared_from_this());
|
||||
|
||||
if (m_pvStructure->getStructure()->getID() == "ev4:nt/NTTable:1.0")
|
||||
if (starts_with(m_pvStructure->getStructure()->getID(), "epics:nt/NTTable:1."))
|
||||
{
|
||||
generateNTTableDoubleValues(m_pvStructure);
|
||||
}
|
||||
else if (m_pvStructure->getStructure()->getID() == "ev4:nt/NTNameValue:1.0")
|
||||
else if (starts_with(m_pvStructure->getStructure()->getID(), "epics:nt/NTNameValue:1."))
|
||||
{
|
||||
generateNTNameValueDoubleValues(m_pvStructure);
|
||||
}
|
||||
else if (m_pvStructure->getStructure()->getID() == "ev4:nt/NTAggregate:1.0")
|
||||
else if (starts_with(m_pvStructure->getStructure()->getID(), "epics:nt/NTAggregate:1."))
|
||||
{
|
||||
generateNTAggregateValues(m_pvStructure);
|
||||
}
|
||||
else if (m_pvStructure->getStructure()->getID() == "ev4:nt/NTHistogram:1.0")
|
||||
else if (starts_with(m_pvStructure->getStructure()->getID(), "epics:nt/NTHistogram:1."))
|
||||
{
|
||||
generateNTHistogramValues(m_pvStructure);
|
||||
}
|
||||
else if (m_pvStructure->getStructure()->getID() == "ev4:test/binaryCounter:1.0")
|
||||
else if (starts_with(m_pvStructure->getStructure()->getID(), "epics:test/binaryCounter:1."))
|
||||
{
|
||||
PVBytePtr pvByte = static_pointer_cast<PVByte>(m_valueField);
|
||||
int8 val = pvByte->get() + 1;
|
||||
@ -1199,7 +1205,7 @@ static bool handleHelp(
|
||||
PVStructure::shared_pointer result(
|
||||
getPVDataCreate()->createPVStructure(
|
||||
getFieldCreate()->createStructure(
|
||||
"ev4:nt/NTScalar:1.0", fieldNames, fields)
|
||||
"epics:nt/NTScalar:1.0", fieldNames, fields)
|
||||
)
|
||||
);
|
||||
|
||||
@ -1254,14 +1260,37 @@ public:
|
||||
virtual void request(epics::pvData::PVStructure::shared_pointer const & pvArgument)
|
||||
{
|
||||
string channelName = m_channel->getChannelName();
|
||||
|
||||
if (channelName == "testNTURI")
|
||||
{
|
||||
const string helpText =
|
||||
"Returns the NTURI structure response identical the NTURI request.\n"
|
||||
"Arguments: (none)\n";
|
||||
if (handleHelp(pvArgument, shared_from_this(), m_channelRPCRequester, helpText))
|
||||
return;
|
||||
|
||||
if (!starts_with(pvArgument->getStructure()->getID(), "epics:nt/NTURI:1."))
|
||||
{
|
||||
PVStructure::shared_pointer nullPtr;
|
||||
Status errorStatus(Status::STATUSTYPE_ERROR, "argument is not a NTURI structure");
|
||||
m_channelRPCRequester->requestDone(errorStatus, shared_from_this(), nullPtr);
|
||||
}
|
||||
else
|
||||
{
|
||||
// return argument as result
|
||||
m_channelRPCRequester->requestDone(Status::Ok, shared_from_this(), pvArgument);
|
||||
}
|
||||
}
|
||||
|
||||
// handle NTURI request
|
||||
PVStructure::shared_pointer args(
|
||||
(starts_with(pvArgument->getStructure()->getID(), "epics:nt/NTURI:1.")) ?
|
||||
pvArgument->getStructureField("query") :
|
||||
pvArgument
|
||||
);
|
||||
|
||||
if (channelName == "testNTTable")
|
||||
{
|
||||
PVStructure::shared_pointer args(
|
||||
(pvArgument->getStructure()->getID() == "ev4:nt/NTURI:1.0") ?
|
||||
pvArgument->getStructureField("query") :
|
||||
pvArgument
|
||||
);
|
||||
|
||||
const string helpText =
|
||||
"Generates a NTTable structure response with 10 rows and a specified number of columns.\n"
|
||||
"Columns are labeled 'column<num>' and values are '<num> + random [0..1)'.\n"
|
||||
@ -1286,12 +1315,6 @@ public:
|
||||
}
|
||||
else if (channelName == "testNTNameValue")
|
||||
{
|
||||
PVStructure::shared_pointer args(
|
||||
(pvArgument->getStructure()->getID() == "ev4:nt/NTURI:1.0") ?
|
||||
pvArgument->getStructureField("query") :
|
||||
pvArgument
|
||||
);
|
||||
|
||||
const string helpText =
|
||||
"Generates a NTNameValue structure response with a specified number of columns.\n"
|
||||
"Columns are labeled 'name<num>' and values are '<num> + random [0..1)'.\n"
|
||||
@ -1329,7 +1352,7 @@ public:
|
||||
PVStructure::shared_pointer result(
|
||||
getPVDataCreate()->createPVStructure(
|
||||
getFieldCreate()->createStructure(
|
||||
"ev4:nt/NTNameValue:1.0", tableFieldNames, tableFields)
|
||||
"epics:nt/NTNameValue:1.0", tableFieldNames, tableFields)
|
||||
)
|
||||
);
|
||||
result->getSubField<PVStringArray>("name")->replace(freeze(labels));
|
||||
@ -1345,12 +1368,6 @@ public:
|
||||
}
|
||||
else if (channelName == "testNTMatrix")
|
||||
{
|
||||
PVStructure::shared_pointer args(
|
||||
(pvArgument->getStructure()->getID() == "ev4:nt/NTURI:1.0") ?
|
||||
pvArgument->getStructureField("query") :
|
||||
pvArgument
|
||||
);
|
||||
|
||||
const string helpText =
|
||||
"Generates a NTMatrix structure response with a specified number of rows and columns.\n"
|
||||
"Matrix values are '<row> + random [0..1)'.\n"
|
||||
@ -1382,7 +1399,7 @@ public:
|
||||
|
||||
PVStructure::shared_pointer result(
|
||||
getPVDataCreate()->createPVStructure(
|
||||
getFieldCreate()->createStructure("ev4:nt/NTMatrix:1.0", fieldNames, fields)
|
||||
getFieldCreate()->createStructure("epics:nt/NTMatrix:1.0", fieldNames, fields)
|
||||
)
|
||||
);
|
||||
|
||||
@ -1410,12 +1427,6 @@ public:
|
||||
}
|
||||
else if (channelName.find("testImage") == 0)
|
||||
{
|
||||
PVStructure::shared_pointer args(
|
||||
(pvArgument->getStructure()->getID() == "ev4:nt/NTURI:1.0") ?
|
||||
pvArgument->getStructureField("query") :
|
||||
pvArgument
|
||||
);
|
||||
|
||||
const string helpText =
|
||||
"Generates a NTNDArray structure response that has encoded a specified image.\n"
|
||||
"Arguments:\n"
|
||||
@ -1502,34 +1513,8 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (channelName == "testNTURI")
|
||||
{
|
||||
const string helpText =
|
||||
"Returns the NTURI structure response identical the NTURI request.\n"
|
||||
"Arguments: (none)\n";
|
||||
if (handleHelp(pvArgument, shared_from_this(), m_channelRPCRequester, helpText))
|
||||
return;
|
||||
|
||||
if (pvArgument->getStructure()->getID() != "ev4:nt/NTURI:1.0")
|
||||
{
|
||||
PVStructure::shared_pointer nullPtr;
|
||||
Status errorStatus(Status::STATUSTYPE_ERROR, "argument is not a NTURI structure");
|
||||
m_channelRPCRequester->requestDone(errorStatus, shared_from_this(), nullPtr);
|
||||
}
|
||||
else
|
||||
{
|
||||
// return argument as result
|
||||
m_channelRPCRequester->requestDone(Status::Ok, shared_from_this(), pvArgument);
|
||||
}
|
||||
}
|
||||
else if (channelName == "testSum") {
|
||||
|
||||
PVStructure::shared_pointer args(
|
||||
(pvArgument->getStructure()->getID() == "ev4:nt/NTURI:1.0") ?
|
||||
pvArgument->getStructureField("query") :
|
||||
pvArgument
|
||||
);
|
||||
|
||||
const string helpText =
|
||||
"Calculates a sum of two integer values.\n"
|
||||
"Arguments:\n"
|
||||
@ -2206,7 +2191,7 @@ protected:
|
||||
|
||||
m_pvStructure =
|
||||
getPVDataCreate()->createPVStructure(
|
||||
getFieldCreate()->createStructure("ev4:nt/NTMatrix:1.0", fieldNames, fields)
|
||||
getFieldCreate()->createStructure("epics:nt/NTMatrix:1.0", fieldNames, fields)
|
||||
);
|
||||
|
||||
// fill with default values
|
||||
@ -2242,7 +2227,7 @@ protected:
|
||||
{
|
||||
epics::pvData::StructureConstPtr s =
|
||||
getFieldCreate()->createFieldBuilder()->
|
||||
setId("ev4:test/binaryCounter:1.0")->
|
||||
setId("epics:test/binaryCounter:1.0")->
|
||||
add("value", pvByte)->
|
||||
add("bit0", pvBoolean)->
|
||||
add("bit1", pvBoolean)->
|
||||
|
Reference in New Issue
Block a user