Still working on initial version

This commit is contained in:
Marty Kraimer
2010-09-17 09:31:44 -04:00
parent ac194e1123
commit 10c2be9a3f
16 changed files with 748 additions and 52 deletions

View File

@@ -0,0 +1,89 @@
/*AbstractPVField.cpp*/
#include <cstddef>
#include <cstdlib>
#include <string>
#include <cstdio>
#include "pvData.h"
#include "factory.h"
namespace epics { namespace pvData {
class AbstractPVField : public PVField {
public:
AbstractPVField(PVStructure *parent,FieldConstPtr field);
virtual ~AbstractPVField();
// from Requester
virtual StringConstPtr getRequesterName() const;
virtual void message(StringConstPtr message,MessageType messageType) const;
// from PVField
virtual void setRequester(Requester *prequester);
virtual int getFieldOffset() const;
virtual int getNextFieldOffset() const;
virtual int getNumberFields() const;
virtual PVAuxInfo * getPVAuxInfo() const;
virtual epicsBoolean isImmutable() const;
virtual void setImmutable();
virtual FieldConstPtr getField() const;
virtual PVStructure * getParent() const;
virtual void replacePVField(PVField * newPVField);
virtual void renameField(StringConstPtr newName);
virtual void postPut() const;
virtual void setPostHandler(PostHandler *ppostHandler);
virtual void toString(StringPtr buf) const;
virtual void toString(StringPtr buf,int indentLevel) const;
protected:
void replaceStructure();
private:
AbstractPVField(AbstractPVField const & ); // not implemented
AbstractPVField & operator=(AbstractPVField const &); //not implemented
int fieldOffset;
int nextFieldOffset;
PVAuxInfo *pvAuxInfo;
epicsBoolean immutable;
PVStructure *parent;
FieldConstPtr field;
Requester *requester;
PostHandler *postHandler;
};
AbstractPVField::AbstractPVField(PVStructure *parent,FieldConstPtr field)
: fieldOffset(0),nextFieldOffset(0),pvAuxInfo(0),immutable(epicsFalse),
parent(parent),field(field),requester(0),postHandler(0)
{
field->incReferenceCount();
}
AbstractPVField::~AbstractPVField()
{
field->decReferenceCount();
}
StringConstPtr AbstractPVField::getRequesterName() const
{
static std::string none("none");
if(requester!=0) return requester->getRequesterName();
return &none;
}
void AbstractPVField::message(StringConstPtr message,MessageType messageType) const
{
if(requester) {
requester->message(message,messageType);
} else {
printf("%s %s %s\n",
messageTypeName[messageType].c_str(),
field->getFieldName()->c_str(),
message->c_str());
}
}
void AbstractPVField::setRequester(Requester *prequester)
{
static std::string requesterPresent = "Logic Error. requester is already present";
if(requester==0) {
requester = prequester;
return;
}
throw std::logic_error(requesterPresent);
}
}}

View File

@@ -1,43 +1,52 @@
/*FieldCreateFactory.cpp*/
#include <cstddef>
#include <cstdlib>
#include <string>
#include <cstdio>
#include <boost/smart_ptr.hpp>
#include "pvData.h"
#include "factory.h"
namespace epics { namespace pvData {
static void newLine(StringPtr buffer,int indentLevel) {
*buffer += "\n";
for(int i=0; i<indentLevel; i++) *buffer += " ";
}
Field::~Field(){}
class BaseField : public Field {
public:
BaseField(StringConstPtr fieldName,Type type);
virtual ~BaseField();
virtual StringConstPtr getFieldName() const;
virtual Type getType() const;
virtual void toString(StringPtr buf) const;
virtual void decReferenceCount() const;
virtual void incReferenceCount() const {referenceCount++;}
virtual int getReferenceCount() const {return referenceCount;}
virtual StringConstPtr getFieldName() const {return &fieldName;}
virtual Type getType() const {return type;}
virtual void toString(StringPtr buf) const {return toString(buf,0);}
virtual void toString(StringPtr buf,int indentLevel) const;
private:
BaseField(BaseField const & ); // not implemented
BaseField & operator=(BaseField const &); //not implemented
std::string const fieldName;
Type type;
mutable volatile int referenceCount;
};
BaseField::BaseField(StringConstPtr fieldName,Type type)
:fieldName(*fieldName),type(type), referenceCount(0){}
BaseField::~BaseField() {
delete &fieldName;
// note that c++ automatically calls destructor for fieldName
if(debugLevel==highDebug) printf("~BaseField %s\n",fieldName.c_str());
}
BaseField::BaseField(StringConstPtr fieldName,Type type)
:fieldName(*fieldName),type(type){}
void BaseField::decReferenceCount() const {
if(referenceCount<=0) {
std::string message("logicError field ");
message += fieldName;
throw std::logic_error(message);
}
referenceCount--;
if(referenceCount==0) delete this;
}
StringConstPtr BaseField::getFieldName() const {return &fieldName;}
Type BaseField::getType() const {return type;}
void BaseField::toString(StringPtr buf) const{toString(buf,0);}
void BaseField::toString(StringPtr buffer,int indentLevel) const{
newLine(buffer,indentLevel);
*buffer += "field ";
@@ -52,9 +61,10 @@ namespace epics { namespace pvData {
public:
BaseScalar(StringConstPtr fieldName,ScalarType scalarType);
virtual ~BaseScalar();
virtual StringConstPtr getFieldName() const{
return BaseField::getFieldName();
}
virtual void incReferenceCount() const {BaseField::incReferenceCount();}
virtual void decReferenceCount() const {BaseField::decReferenceCount();}
virtual int getReferenceCount() const {return BaseField::getReferenceCount();}
virtual StringConstPtr getFieldName() const{ return BaseField::getFieldName(); }
virtual Type getType() const{return BaseField::getType();}
virtual ScalarType getScalarType() const { return scalarType;}
virtual void toString(StringPtr buf) const {toString(buf,0);}
@@ -80,9 +90,10 @@ namespace epics { namespace pvData {
public:
BaseScalarArray(StringConstPtr fieldName,ScalarType elementType);
virtual ~BaseScalarArray();
virtual StringConstPtr getFieldName() const{
return BaseField::getFieldName();
}
virtual void incReferenceCount() const {BaseField::incReferenceCount();}
virtual void decReferenceCount() const {BaseField::decReferenceCount();}
virtual int getReferenceCount() const {return BaseField::getReferenceCount();}
virtual StringConstPtr getFieldName() const{ return BaseField::getFieldName(); }
virtual Type getType() const{return BaseField::getType();}
virtual ScalarType getElementType() const { return elementType;}
virtual void toString(StringPtr buf) const {toString(buf,0);}
@@ -107,15 +118,14 @@ namespace epics { namespace pvData {
class BaseStructure: private BaseField,public Structure {
public:
BaseStructure(StringConstPtr fieldName,
int numberFields,FieldConstPtrArray fields);
BaseStructure(StringConstPtr fieldName, int numberFields,FieldConstPtrArray fields);
virtual ~BaseStructure();
virtual StringConstPtr getFieldName() const{
return BaseField::getFieldName();
}
virtual void incReferenceCount() const {BaseField::incReferenceCount();}
virtual void decReferenceCount() const {BaseField::decReferenceCount();}
virtual int getReferenceCount() const {return BaseField::getReferenceCount();}
virtual StringConstPtr getFieldName() const{ return BaseField::getFieldName(); }
virtual Type getType() const{return BaseField::getType();}
virtual int const getNumberFields() const {return numberFields;}
virtual StringConstPtrArray getFieldNames() const { return fieldNames;}
virtual FieldConstPtr getField(StringConstPtr fieldName) const;
virtual int getFieldIndex(StringConstPtr fieldName) const;
virtual FieldConstPtrArray getFields() const { return fields;}
@@ -124,26 +134,36 @@ namespace epics { namespace pvData {
private:
int numberFields;
FieldConstPtrArray fields;
StringConstPtr* fieldNames;
};
BaseStructure::BaseStructure (StringConstPtr fieldName,
int numberFields, FieldConstPtrArray fields)
: BaseField(fieldName,structure),
: BaseField(fieldName,structure),
numberFields(numberFields),
fields(fields),
fieldNames(new StringConstPtr[numberFields])
fields(fields)
{
for(int i=0; i<numberFields; i++) {
fieldNames[i] = fields[i]->getFieldName();
StringConstPtr name = fields[i]->getFieldName();
// look for duplicates
for(int j=i+1; j<numberFields; j++) {
StringConstPtr otherName = fields[j]->getFieldName();
int result = name->compare(*otherName);
if(result==0) {
std::string message("duplicate fieldName ");
message += *name;
throw std::invalid_argument(message);
}
}
// inc reference counter
fields[i]->incReferenceCount();
}
}
BaseStructure::~BaseStructure() {
if(debugLevel==highDebug) printf("~BaseStructure %s\n",BaseField::getFieldName()->c_str());
for(int i=0; i<numberFields; i++) {
delete fieldNames[i];
FieldConstPtr pfield = fields[i];
pfield->decReferenceCount();
}
delete[] fieldNames;
delete[] fields;
}
FieldConstPtr BaseStructure::getField(StringConstPtr fieldName) const {
@@ -181,6 +201,9 @@ namespace epics { namespace pvData {
public:
BaseStructureArray(StringConstPtr fieldName,StructureConstPtr structure);
virtual ~BaseStructureArray();
virtual void incReferenceCount() const {BaseField::incReferenceCount();}
virtual void decReferenceCount() const {BaseField::decReferenceCount();}
virtual int getReferenceCount() const {return BaseField::getReferenceCount();}
virtual StringConstPtr getFieldName() const{
return BaseField::getFieldName();
}
@@ -193,9 +216,15 @@ namespace epics { namespace pvData {
};
BaseStructureArray::BaseStructureArray(StringConstPtr fieldName,StructureConstPtr structure)
: BaseField(fieldName,structureArray),pstructure(structure) {}
: BaseField(fieldName,structureArray),pstructure(structure)
{
pstructure->incReferenceCount();
}
BaseStructureArray::~BaseStructureArray() {}
BaseStructureArray::~BaseStructureArray() {
if(debugLevel==highDebug) printf("~BaseStructureArray\n");
pstructure->decReferenceCount();
}
void BaseStructureArray::toString(StringPtr buffer,int indentLevel) const {
@@ -204,9 +233,6 @@ namespace epics { namespace pvData {
pstructure->toString(buffer,indentLevel + 1);
}
static std::string notImplemented = "not implemented";
static std::string logicError = "Logic Error. Should never get here";
FieldCreate::FieldCreate(){};
ScalarConstPtr FieldCreate::createScalar(StringConstPtr fieldName,
@@ -233,7 +259,8 @@ static std::string logicError = "Logic Error. Should never get here";
StructureArrayConstPtr FieldCreate::createStructureArray(
StringConstPtr fieldName,StructureConstPtr structure) const
{
throw std::invalid_argument(notImplemented);
BaseStructureArray *baseStructureArray = new BaseStructureArray(fieldName,structure);
return baseStructureArray;
}
FieldConstPtr FieldCreate::create(StringConstPtr fieldName,
@@ -258,7 +285,9 @@ static std::string logicError = "Logic Error. Should never get here";
return createStructureArray(fieldName,pstructureArray->getStructure());
}
}
throw std::logic_error(logicError);
std::string message("field ");
message += *fieldName;
throw std::logic_error(message);
}
static FieldCreate* instance = 0;

View File

@@ -2,8 +2,11 @@ TOP=../..
include $(TOP)/configure/CONFIG
INC += factory.h
INC += AbstractPVField.h
LIBSRCS += TypeFunc.cpp
LIBSRCS += FieldCreateFactory.cpp
LIBSRCS += PVDataCreateFactory.cpp
LIBRARY=pvFactory

View File

@@ -0,0 +1,99 @@
/*PVDataCreateFactory.cpp*/
#include <cstddef>
#include <cstdlib>
#include <string>
#include <cstdio>
#include "pvData.h"
#include "factory.h"
#include "AbstractPVField.h"
namespace epics { namespace pvData {
static std::string notImplemented("not implemented");
PVDataCreate::PVDataCreate(){};
PVField *PVDataCreate::createPVField(PVStructure *parent,
FieldConstPtr field) const
{
throw std::logic_error(notImplemented);
};
PVField *PVDataCreate::createPVField(PVStructure *parent,
StringConstPtr fieldName,FieldConstPtr fieldToClone) const
{
throw std::logic_error(notImplemented);
};
PVScalar *PVDataCreate::createPVScalar(PVStructure *parent,ScalarConstPtr scalar) const
{
throw std::logic_error(notImplemented);
};
PVScalar *PVDataCreate::createPVScalar(PVStructure *parent,
StringConstPtr fieldName,ScalarType scalarType)
{
throw std::logic_error(notImplemented);
};
PVScalar *PVDataCreate::createPVScalar(PVStructure *parent,
StringConstPtr fieldName,ScalarConstPtr scalarToClone) const
{
throw std::logic_error(notImplemented);
};
PVScalarArray *PVDataCreate::createPVScalarArray(PVStructure *parent,
ScalarArrayConstPtr scalarArray) const
{
throw std::logic_error(notImplemented);
};
PVScalarArray *PVDataCreate::createPVScalarArray(PVStructure *parent,
StringConstPtr fieldName,ScalarType elementType)
{
throw std::logic_error(notImplemented);
};
PVScalarArray *PVDataCreate::createPVScalarArray(PVStructure *parent,
StringConstPtr fieldName,ScalarArrayConstPtr scalarArrayToClone) const
{
throw std::logic_error(notImplemented);
};
PVStructureArray *PVDataCreate::createPVStructureArray(PVStructure *parent,
StructureArrayConstPtr structureArray) const
{
throw std::logic_error(notImplemented);
};
PVStructure *PVDataCreate::createPVStructure(PVStructure *parent,
StructureConstPtr structure)
{
throw std::logic_error(notImplemented);
};
PVStructure *PVDataCreate::createPVStructure(PVStructure *parent,
StringConstPtr fieldName,FieldConstPtrArray fields)
{
throw std::logic_error(notImplemented);
};
PVStructure *PVDataCreate::createPVStructure(PVStructure *parent,
StringConstPtr fieldName,PVStructure *structToClone)
{
throw std::logic_error(notImplemented);
};
static PVDataCreate* instance = 0;
class PVDataCreateExt : public PVDataCreate {
public:
PVDataCreateExt(): PVDataCreate(){};
};
PVDataCreate * getPVDataCreate() {
if(instance==0) instance = new PVDataCreateExt();
return instance;
}
}}

View File

@@ -4,8 +4,6 @@
#include <string>
#include <cstdio>
#include <boost/smart_ptr.hpp>
#include "pvData.h"
namespace epics { namespace pvData {

View File

@@ -0,0 +1,17 @@
/*factory.h*/
#ifndef FACTORY_H
#define FACTORY_H
namespace epics { namespace pvData {
enum DebugLevel{noDebug,lowDebug,highDebug};
static DebugLevel debugLevel = highDebug;
static void newLine(StringPtr buffer,int indentLevel) {
*buffer += "\n";
for(int i=0; i<indentLevel; i++) *buffer += " ";
}
}}
#endif /*FACTORY_H */

View File

@@ -3,6 +3,10 @@ TOP=../..
include $(TOP)/configure/CONFIG
INC += pvIntrospect.h
INC += bitSet.h
INC += requester.h
INC += byteBuffer.h
INC += serialize.h
INC += pvData.h
include $(TOP)/configure/RULES

11
pvDataApp/pv/bitSet.h Normal file
View File

@@ -0,0 +1,11 @@
/* bitSet.h */
#ifndef BITSET_H
#define BITSET_H
#include "pvIntrospect.h"
namespace epics { namespace pvData {
class BitSet;
// must be defined and implemented
}}
#endif /* BITSET_H */

37
pvDataApp/pv/byteBuffer.h Normal file
View File

@@ -0,0 +1,37 @@
/* byteBuffer.h */
#include <string>
#ifndef BYTEBUFFER_H
#define BYTEBUFFER_H
#include "epicsTypes.h"
#include "pvIntrospect.h"
namespace epics { namespace pvData {
// not sure why I have to define epicsInt64
typedef long long epicsInt64;
class ByteBuffer {
public:
virtual ~ByteBuffer();
virtual int getSize() const = 0;
virtual int getArrayOffset() const = 0;
virtual epicsBoolean getBoolean() const = 0;
virtual epicsInt8 getByte() const = 0;
virtual epicsInt16 geShort() const = 0;
virtual epicsInt32 getInt() const = 0;
virtual epicsInt64 getLong() const = 0;
virtual float getFloat() const = 0;
virtual double getDouble() const = 0;
virtual StringConstPtr getString() const = 0;
virtual ByteBuffer * putBoolean(epicsBoolean value) const = 0;
virtual ByteBuffer * putByte(epicsInt8 value) const = 0;
virtual ByteBuffer * geShort(epicsInt16 value) const = 0;
virtual ByteBuffer * putInt(epicsInt32 value) const = 0;
virtual ByteBuffer * putLong(epicsInt64 value) const = 0;
virtual ByteBuffer * putFloat(float value) const = 0;
virtual ByteBuffer * putDouble(double value) const = 0;
virtual ByteBuffer * putString(StringConstPtr value) const = 0;
// Must define arrays
};
}}
#endif /* BYTEBUFFER_H */

View File

@@ -1,10 +1,169 @@
/* pvData.h */
#include <string>
#include <stdexcept>
#include <map>
#ifndef PVDATA_H
#define PVDATA_H
#include "pvIntrospect.h"
#include "requester.h"
#include "byteBuffer.h"
#include "serialize.h"
namespace epics { namespace pvData {
class PVField;
class PVScalar;
class PVBoolean;
class PVByte;
class PVShort;
class PVInt;
class PVLong;
class PVFloat;
class PVDouble;
class PVString;
class PVScalarArray;
class PVBooleanArray;
class PVByteArray;
class PVShortArray;
class PVIntArray;
class PVLongArray;
class PVFloatArray;
class PVDoubleArray;
class PVStringArray;
class PVStructure;
class PVStructureArray;
class PVAuxInfo {
public:
virtual ~PVAuxInfo();
virtual PVField * getPVField() const = 0;
virtual PVScalar * createInfo(StringConstPtr key,ScalarType scalarType) = 0;
/* following caused compiler error
virtual map<std::string, ScalarType> getInfos() = 0;
*/
virtual PVScalar * getInto(StringConstPtr key) = 0;
virtual void toString(StringPtr buf) const = 0;
virtual void toString(StringPtr buf,int indentLevel) const = 0;
};
class PostHandler {
virtual void postPut() = 0;
};
class PVField : public Requester, public Serializable {
public:
virtual ~PVField();
virtual void setRequester(Requester *prequester) = 0;
virtual int getFieldOffset() const = 0;
virtual int getNextFieldOffset() const = 0;
virtual int getNumberFields() const = 0;
virtual PVAuxInfo * getPVAuxInfo() const = 0;
virtual epicsBoolean isImmutable() const = 0;
virtual void setImmutable() = 0;
virtual FieldConstPtr getField() const = 0;
virtual PVStructure * getParent() const = 0;
virtual void replacePVField(PVField * newPVField) = 0;
virtual void renameField(StringConstPtr newName) = 0;
virtual void postPut() const = 0;
virtual void setPostHandler(PostHandler *ppostHandler) = 0;
virtual void toString(StringPtr buf) const = 0;
virtual void toString(StringPtr buf,int indentLevel) const = 0;
};
class PVScalar : public PVField {
public:
virtual ~PVScalar();
virtual ScalarConstPtr getScalar() const = 0;
};
class PVBoolean : public PVScalar {
public:
virtual ~PVBoolean();
virtual epicsBoolean get() const = 0;
virtual void put(epicsBoolean value) = 0;
};
class PVByte : public PVScalar {
public:
virtual ~PVByte();
virtual epicsInt8 get() const = 0;
virtual void put(epicsInt8 value) = 0;
};
class PVShort : public PVScalar {
public:
virtual ~PVShort();
virtual epicsInt16 get() const = 0;
virtual void put(epicsInt16 value) = 0;
};
class PVInt : public PVScalar {
public:
virtual ~PVInt();
virtual epicsInt32 get() const = 0;
virtual void put(epicsInt32 value) = 0;
};
class PVLong : public PVScalar {
public:
virtual ~PVLong();
virtual epicsInt64 get() const = 0;
virtual void put(epicsInt64 value) = 0;
};
class PVFloat : public PVScalar {
public:
virtual ~PVFloat();
virtual float get() const = 0;
virtual void put(float value) = 0;
};
class PVDouble : public PVScalar {
public:
virtual ~PVDouble();
virtual double get() const = 0;
virtual void put(double value) = 0;
};
class PVString : public PVScalar {
public:
virtual ~PVString();
virtual StringConstPtr get() const = 0;
virtual void put(StringConstPtr value) = 0;
};
class PVDataCreate {
public:
PVField *createPVField(PVStructure *parent,
FieldConstPtr field) const;
PVField *createPVField(PVStructure *parent,
StringConstPtr fieldName,FieldConstPtr fieldToClone) const;
PVScalar *createPVScalar(PVStructure *parent,ScalarConstPtr scalar) const;
PVScalar *createPVScalar(PVStructure *parent,
StringConstPtr fieldName,ScalarType scalarType);
PVScalar *createPVScalar(PVStructure *parent,
StringConstPtr fieldName,ScalarConstPtr scalarToClone) const;
PVScalarArray *createPVScalarArray(PVStructure *parent,
ScalarArrayConstPtr scalarArray) const;
PVScalarArray *createPVScalarArray(PVStructure *parent,
StringConstPtr fieldName,ScalarType elementType);
PVScalarArray *createPVScalarArray(PVStructure *parent,
StringConstPtr fieldName,ScalarArrayConstPtr scalarArrayToClone) const;
PVStructureArray *createPVStructureArray(PVStructure *parent,
StructureArrayConstPtr structureArray) const;
PVStructure *createPVStructure(PVStructure *parent,
StructureConstPtr structure);
PVStructure *createPVStructure(PVStructure *parent,
StringConstPtr fieldName,FieldConstPtrArray fields);
PVStructure *createPVStructure(PVStructure *parent,
StringConstPtr fieldName,PVStructure *structToClone);
protected:
PVDataCreate();
};
extern PVDataCreate * getPVDataCreate();
}}
#endif /* PVDATA_H */

View File

@@ -1,4 +1,4 @@
/* pvData.h */
/* pvIntrospect.h */
#include <string>
#include <stdexcept>
#ifndef PVINTROSPECT_H
@@ -9,12 +9,16 @@ namespace epics { namespace pvData {
class ScalarArray;
class Structure;
class StructureArray;
typedef std::string * StringPtr;
typedef std::string const * StringConstPtr; //pointer to constant string
typedef StringConstPtr * StringConstPtrArray;//array of pointers to constant string
typedef Field const * FieldConstPtr; //pointer to constant field
typedef FieldConstPtr * FieldConstPtrArray; //array of pointers to const field
typedef Scalar const * ScalarConstPtr; //pointer to constant field
// pointer to constant string
typedef std::string const * StringConstPtr;
//array of pointers to constant string
typedef StringConstPtr * StringConstPtrArray;
typedef Field const * FieldConstPtr;
typedef FieldConstPtr * FieldConstPtrArray;
typedef Scalar const * ScalarConstPtr;
typedef ScalarArray const * ScalarArrayConstPtr;
typedef Structure const * StructureConstPtr;
typedef StructureArray const * StructureArrayConstPtr;
@@ -54,6 +58,9 @@ namespace epics { namespace pvData {
class Field {
public:
virtual ~Field();
virtual void incReferenceCount() const = 0;
virtual void decReferenceCount() const = 0;
virtual int getReferenceCount() const = 0;
virtual StringConstPtr getFieldName() const = 0;
virtual Type getType() const = 0;
virtual void toString(StringPtr buf) const = 0;
@@ -78,7 +85,6 @@ namespace epics { namespace pvData {
public:
virtual ~Structure();
virtual int const getNumberFields() const = 0;
virtual StringConstPtrArray getFieldNames() const = 0;
virtual FieldConstPtr getField(StringConstPtr fieldName) const = 0;
virtual int getFieldIndex(StringConstPtr fieldName) const = 0;
virtual FieldConstPtrArray getFields() const = 0;

18
pvDataApp/pv/requester.h Normal file
View File

@@ -0,0 +1,18 @@
/* requester.h */
#include <string>
#ifndef REQUESTER_H
#define REQUESTER_H
#include "pvIntrospect.h"
namespace epics { namespace pvData {
enum MessageType {info,warning,error,fatalError};
static std::string messageTypeName[] = {"info","warning","error","fatalError"};
class Requester {
public:
virtual StringConstPtr getRequesterName() const = 0;
virtual void message(StringConstPtr message,MessageType messageType) const = 0;
};
}}
#endif /* REQUESTER_H */

40
pvDataApp/pv/serialize.h Normal file
View File

@@ -0,0 +1,40 @@
/* serialize.h */
#ifndef SERIALIZE_H
#define SERIALIZE_H
#include "bitSet.h"
#include "byteBuffer.h"
namespace epics { namespace pvData {
class SerializableControl {
virtual void flushSerializeBuffer() const =0;
virtual void ensureBuffer(int size) const =0;
};
class DeserializableControl {
virtual void ensureData(int size) =0;
};
class Serializable {
public:
virtual void serialize(ByteBuffer *pbuffer,SerializableControl *pflusher) const = 0;
virtual void deserialize(ByteBuffer *pbuffer,DeserializableControl *pflusher) = 0;
};
class BitSetSerializable {
public:
virtual void serialize(ByteBuffer *pbuffer,
SerializableControl *pflusher,BitSet *pbitSet) const = 0;
virtual void deserialize(ByteBuffer *pbuffer,
DeserializableControl*pflusher,BitSet *pbitSet) = 0;
};
class SerializableArray : public Serializable {
public:
virtual void serialize(ByteBuffer *pbuffer,
SerializableControl *pflusher, int offset, int count) const = 0;
};
}}
#endif /* SERIALIZE_H */

View File

@@ -6,7 +6,13 @@ PROD_HOST = test
test_SRCS += test.cpp
test_LIBS += pvFactory
PROD_HOST += testDumpStdString
testDumpStdString_SRCS += testDumpStdString.cpp
testDumpStdString_LIBS += pvFactory
PROD_HOST = testPVScalar
testPVScalar_SRCS += testPVScalar.cpp
testPVScalar_LIBS += pvFactory
include $(TOP)/configure/RULES
#----------------------------------------

View File

@@ -0,0 +1,116 @@
/* pvDataMain.cpp */
/* Author: Marty Kraimer Date: 17MAR2000 */
#include <stddef.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include "pvData.h"
using namespace epics::pvData;
using namespace std;
static void dumpString(char const prefix[],string const* value) {
printf("%s\n value %p",prefix,value);
// Just convert value to a pointer
int *pvalue = (int *)value;
// Now get what pvalue points to. It is the cstr.
char * cstr = (char *)*pvalue;
if(cstr==0) { printf("\n"); return; }
printf(" *value %p",cstr);
int * stuff = (int *)*pvalue;
//At least on my implementation the following is true
stuff -= 3;
printf(" length %d capacity %d refcount %d str %s\n",
stuff[0],stuff[1],stuff[2],cstr);
}
int main(int argc,char *argv[])
{
FieldCreate * pfieldCreate = getFieldCreate();
std::string valueName("value");
std::string* myString= new std::string("type ");
int numberFields = 2;
FieldConstPtr fields[numberFields];
std::string name0("high");
std::string name1("low");
dumpString("high",&name0);
dumpString("low",&name1);
printf("\ncreate field0 and field1\n");
fields[0] = pfieldCreate->createScalar(&name0,pvDouble);
fields[1] = pfieldCreate->createScalar(&name1,pvDouble);
printf("referenceCounts field0 %d field1 %d\n",
fields[0]->getReferenceCount(),
fields[1]->getReferenceCount());
dumpString("high",&name0);
dumpString("low",&name1);
printf("\ncreate scalarArray");
std::string scalarArrayName("scalarArray");
ScalarArrayConstPtr pscalarArray = pfieldCreate->createScalarArray(
&scalarArrayName,pvDouble);
myString->clear();
pscalarArray->toString(myString);
printf("%s\n",myString->c_str());
printf("referenceCount pscalarArray %d\n", pscalarArray->getReferenceCount());
dumpString("scalarArray",&scalarArrayName);
pscalarArray->incReferenceCount();
printf("after incReferenceCounnt referenceCount pscalarArray %d\n",
pscalarArray->getReferenceCount());
dumpString("high",&name0);
pscalarArray->decReferenceCount();
dumpString("after decReferenceCount scalarArray",&scalarArrayName);
printf("\ncreate structure\n");
StructureConstPtr pstructure = pfieldCreate->createStructure(
&valueName,numberFields,fields);
myString->clear();
pstructure->toString(myString);
printf("%s\n",myString->c_str());
FieldConstPtr pfield = pstructure;
myString->clear();
pfield->toString(myString);
printf("as Field\n%s\n",myString->c_str());
printf("referenceCounts pfield %d field0 %d field1 %d\n",
pfield->getReferenceCount(),
fields[0]->getReferenceCount(),
fields[1]->getReferenceCount());
dumpString("high",&name0);
dumpString("low",&name1);
pfield->incReferenceCount();
pfield->incReferenceCount();
printf("after incReferenceCounter twice referenceCounts pfield %d field0 %d field1 %d\n",
pfield->getReferenceCount(),
fields[0]->getReferenceCount(),
fields[1]->getReferenceCount());
dumpString("high",&name0);
dumpString("low",&name1);
pfield->decReferenceCount();
printf("after decReferenceCount referenceCounts pfield %d field0 %d field1 %d\n",
pfield->getReferenceCount(),
fields[0]->getReferenceCount(),
fields[1]->getReferenceCount());
dumpString("high",&name0);
dumpString("low",&name1);
StructureArrayConstPtr pstructureArray = pfieldCreate->createStructureArray(
&valueName,pstructure);
pstructureArray->incReferenceCount();
printf("after createStructureArray referenceCounts pstructureArray %d pfield %d field0 %d field1 %d\n",
pstructureArray->getReferenceCount(),
pfield->getReferenceCount(),
fields[0]->getReferenceCount(),
fields[1]->getReferenceCount());
pstructureArray->decReferenceCount();
printf("after structureArray decReferenceCount referenceCounts pfield %d field0 %d field1 %d\n",
pfield->getReferenceCount(),
fields[0]->getReferenceCount(),
fields[1]->getReferenceCount());
dumpString("high",&name0);
dumpString("low",&name1);
printf("field recReferenceCount\n");
pfield->decReferenceCount();
dumpString("high",&name0);
dumpString("low",&name1);
return(0);
}

View File

@@ -0,0 +1,64 @@
/* pvDataMain.cpp */
/* Author: Marty Kraimer Date: 17MAR2000 */
#include <stddef.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include "pvData.h"
using namespace epics::pvData;
static FieldCreate * pfieldCreate = 0;
static PVDataCreate *pvDataCreate = 0;
static std::string theBuffer("");
static std::string *buffer = &theBuffer;
void testDouble() {
printf("\ntestDouble\n");
std::string valueName("value");
ScalarConstPtr pscalar = pfieldCreate->createScalar(&valueName,pvDouble);
PVScalar *pvScalar = pvDataCreate->createPVScalar(0,pscalar);
PVDouble *pvValue = (PVDouble *)pvScalar;
double value = 2;
pvValue->put(value);
double getValue = pvValue->get();
if(value!=getValue) {
fprintf(stderr,"ERROR getValue put %f get %f\n",value,getValue);
}
buffer->clear();
*buffer += "value ";
pvValue->toString(buffer);
printf("%s\n",buffer->c_str());
int offset = pvValue->getFieldOffset();
int nextOffset = pvValue->getNextFieldOffset();
int numberFields = pvValue->getNumberFields();
PVAuxInfo *auxInfo = pvValue->getPVAuxInfo();
epicsBoolean isImmutable = pvValue->isImmutable();
PVStructure *pvParent = pvValue->getParent();
printf("offset %d nextOffset %d numberFields %d auxInfo %p immutable %s parent %p\n",
offset,nextOffset,numberFields,auxInfo,
((isImmutable==epicsFalse) ? "false" : "true"),
pvParent);
FieldConstPtr field = pvValue->getField();
buffer->clear();
*buffer += "field ";
field->toString(buffer);
printf("%s\n",buffer->c_str());
ScalarConstPtr scalar = dynamic_cast<ScalarConstPtr>(field);
if(scalar!=field) {
fprintf(stderr,"ERROR field!=scalar field %p scalar %p\n",field,scalar);
}
delete pvValue;
}
int main(int argc,char *argv[])
{
pfieldCreate = getFieldCreate();
pvDataCreate = getPVDataCreate();
testDouble();
return(0);
}