pvData: added C api test
This commit is contained in:
@@ -4,5 +4,6 @@ DIRS += misc
|
||||
DIRS += pv
|
||||
DIRS += property
|
||||
DIRS += monitor
|
||||
DIRS += capi
|
||||
include $(TOP)/configure/RULES_DIRS
|
||||
|
||||
|
||||
9
testApp/capi/Makefile
Normal file
9
testApp/capi/Makefile
Normal file
@@ -0,0 +1,9 @@
|
||||
TOP=../..
|
||||
|
||||
include $(TOP)/configure/CONFIG
|
||||
|
||||
LIBRARY_HOST += testc
|
||||
testc_SRCS += testc.cpp
|
||||
testc_LIBS += pvData Com
|
||||
|
||||
include $(TOP)/configure/RULES
|
||||
81
testApp/capi/testc.cpp
Normal file
81
testApp/capi/testc.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
#include <pv/pvData.h>
|
||||
#include <pv/standardField.h>
|
||||
#include <pv/standardPVField.h>
|
||||
|
||||
using namespace epics::pvData;
|
||||
|
||||
struct StructureHandle
|
||||
{
|
||||
StructureConstPtr s;
|
||||
StructureHandle(StructureConstPtr s) : s(s) {}
|
||||
};
|
||||
|
||||
extern "C"
|
||||
{
|
||||
void * createTest()
|
||||
{
|
||||
FieldCreatePtr fieldCreate = getFieldCreate();
|
||||
PVDataCreatePtr pvDataCreate = getPVDataCreate();
|
||||
FieldConstPtrArray fields;
|
||||
StringArray fieldNames;
|
||||
fields.push_back(fieldCreate->createScalar(pvString));
|
||||
fields.push_back(fieldCreate->createScalarArray(pvDouble));
|
||||
fieldNames.push_back("name");
|
||||
fieldNames.push_back("value");
|
||||
StructureConstPtr s = fieldCreate->createStructure(fieldNames, fields);
|
||||
StructureHandle * sh = new StructureHandle(s);
|
||||
return (void *)sh;
|
||||
}
|
||||
|
||||
int getNumberFields(void * handle)
|
||||
{
|
||||
StructureHandle * sh = (StructureHandle *)handle;
|
||||
return sh->s->getNumberFields();
|
||||
}
|
||||
|
||||
const char * getFieldName(void * handle, int n)
|
||||
{
|
||||
StructureHandle * sh = (StructureHandle *)handle;
|
||||
return sh->s->getFieldNames()[n].c_str();
|
||||
}
|
||||
|
||||
int getFieldType(void * handle, const char * name)
|
||||
{
|
||||
StructureHandle * sh = (StructureHandle *)handle;
|
||||
/* api missing const for getField(size_t) so have to use name */
|
||||
return sh->s->getField(name)->getType();
|
||||
}
|
||||
|
||||
int getScalarType(void * handle, const char * name)
|
||||
{
|
||||
StructureHandle * sh = (StructureHandle *)handle;
|
||||
FieldConstPtr f = sh->s->getField(name);
|
||||
if(f->getType() == scalar)
|
||||
{
|
||||
ScalarConstPtr sp = std::tr1::static_pointer_cast<const Scalar>(f);
|
||||
return sp->getScalarType();
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int getElementType(void * handle, const char * name)
|
||||
{
|
||||
StructureHandle * sh = (StructureHandle *)handle;
|
||||
FieldConstPtr f = sh->s->getField(name);
|
||||
if(f->getType() == scalarArray)
|
||||
{
|
||||
ScalarArrayConstPtr sp = std::tr1::static_pointer_cast<const ScalarArray>(f);
|
||||
return sp->getElementType();
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
33
testApp/capi/testc.py
Executable file
33
testApp/capi/testc.py
Executable file
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
from ctypes import *
|
||||
|
||||
libname = "../../lib/%s/libtestc.so" % os.environ["EPICS_HOST_ARCH"]
|
||||
lib = CDLL(libname)
|
||||
lib.createTest.restype = c_void_p
|
||||
lib.createTest.argtypes = []
|
||||
lib.getNumberFields.restype = c_int
|
||||
lib.getNumberFields.argtypes = [c_void_p]
|
||||
lib.getFieldName.restype = c_char_p
|
||||
lib.getFieldName.argtypes = [c_void_p, c_int]
|
||||
lib.getFieldType.restype = c_int
|
||||
lib.getFieldType.argtypes = [c_void_p, c_char_p]
|
||||
lib.getScalarType.restype = c_int
|
||||
lib.getScalarType.argtypes = [c_void_p, c_char_p]
|
||||
lib.getElementType.restype = c_int
|
||||
lib.getElementType.argtypes = [c_void_p, c_char_p]
|
||||
|
||||
type_enum = ["scalar", "scalarArray", "structure", "structureArray"]
|
||||
struct = lib.createTest()
|
||||
|
||||
l = lib.getNumberFields(struct)
|
||||
print "pvData structure has %d fields" % l
|
||||
|
||||
for n in range(l):
|
||||
name = lib.getFieldName(struct, n)
|
||||
type_ = lib.getFieldType(struct, name)
|
||||
sc_type = lib.getScalarType(struct, name)
|
||||
el_type = lib.getElementType(struct, name)
|
||||
print name, type_enum[type_], sc_type, el_type
|
||||
|
||||
Reference in New Issue
Block a user