From 124d28d33e245f5156dc269e37f551cfbf6bd8cc Mon Sep 17 00:00:00 2001 From: Marty Kraimer Date: Fri, 12 Apr 2013 15:17:21 -0400 Subject: [PATCH] interim commit --- src/database/exampleCounter.h | 2 +- src/database/pvDatabase.h | 24 ++++-- src/database/pvRecord.cpp | 33 +++++++- test/pvCopy/Makefile | 4 + test/pvCopy/testPVCopy.cpp | 3 + test/pvCopy/testPVRecord.cpp | 117 +++++++++++++++++++++++++++++ test/server/exampleCounterMain.cpp | 51 +++++++++++++ 7 files changed, 223 insertions(+), 11 deletions(-) create mode 100644 test/pvCopy/testPVRecord.cpp create mode 100644 test/server/exampleCounterMain.cpp diff --git a/src/database/exampleCounter.h b/src/database/exampleCounter.h index df05f2f..74e9198 100644 --- a/src/database/exampleCounter.h +++ b/src/database/exampleCounter.h @@ -40,7 +40,7 @@ ExampleCounterPtr ExampleCounter::create( epics::pvData::String const & recordName) { epics::pvData::PVStructurePtr pvStructure = - epics::pvData::getStandardPVField()->scalar(epics::pvData::pvDouble,""); + epics::pvData::getStandardPVField()->scalar(epics::pvData::pvLong,"timeStamp"); ExampleCounterPtr pvRecord( new ExampleCounter(recordName,pvStructure)); if(!pvRecord->init()) pvRecord.reset(); diff --git a/src/database/pvDatabase.h b/src/database/pvDatabase.h index 3fe38e5..912af68 100644 --- a/src/database/pvDatabase.h +++ b/src/database/pvDatabase.h @@ -75,14 +75,6 @@ public: static PVRecordPtr create( epics::pvData::String const & recordName, epics::pvData::PVStructurePtr const & pvStructure); - /** - * The constructor. - * @param recordName The name of the record, which is also the channelName. - * @param pvStructure The top level structure. - */ - PVRecord( - epics::pvData::String const & recordName, - epics::pvData::PVStructurePtr const & pvStructure); /** * The Destructor. Must be virtual. */ @@ -227,6 +219,14 @@ public: */ void toString(epics::pvData::StringBuilder buf,int indentLevel); protected: + /** + * Constructor + * @param recordName The name of the record + * @param pvStructure The top level PVStructutre + */ + PVRecord( + epics::pvData::String const & recordName, + epics::pvData::PVStructurePtr const & pvStructure); /** * Initializes the base class. Must be called by derived classes. */ @@ -281,6 +281,10 @@ public: * Destructor. */ virtual ~PVRecordField(); + /** + * Release any resources used + */ + virtual void destroy(); /** * Get the parent. * @return The parent. @@ -377,6 +381,10 @@ public: * Destructor. */ virtual ~PVRecordStructure(); + /** + * Release any resources used + */ + virtual void destroy(); /** * Get the sub fields. * @return the array of PVRecordFieldPtr. diff --git a/src/database/pvRecord.cpp b/src/database/pvRecord.cpp index 9c31eed..92707c3 100644 --- a/src/database/pvRecord.cpp +++ b/src/database/pvRecord.cpp @@ -14,6 +14,7 @@ using std::tr1::static_pointer_cast; using namespace epics::pvData; using namespace epics::pvAccess; +using namespace std; namespace epics { namespace pvDatabase { @@ -85,6 +86,11 @@ void PVRecord::destroy() pvRecordClientList.clear(); pvListenerList.clear(); + pvRecordStructure->destroy(); + pvRecordStructure.reset(); + convert.reset(); + pvStructure.reset(); + unlock(); } @@ -362,7 +368,17 @@ void PVRecordField::init() pvField->setPostHandler(getPtrSelf()); } -PVRecordField::~PVRecordField() {} +PVRecordField::~PVRecordField() +{ +} + +void PVRecordField::destroy() +{ + pvRecord.reset(); + parent.reset(); + pvField.reset(); + pvListenerList.clear(); +} PVRecordStructurePtr PVRecordField::getParent() {return parent;} @@ -435,7 +451,20 @@ PVRecordStructure::PVRecordStructure( { } -PVRecordStructure::~PVRecordStructure() {} +PVRecordStructure::~PVRecordStructure() +{ +} + +void PVRecordStructure::destroy() +{ + PVRecordFieldPtrArray::iterator iter; + PVRecordField::destroy(); + for(iter = pvRecordFields->begin() ; iter !=pvRecordFields->end(); iter++) { + (*iter)->destroy(); + } + pvRecordFields.reset(); + pvStructure.reset(); +} void PVRecordStructure::init() { diff --git a/test/pvCopy/Makefile b/test/pvCopy/Makefile index de1fb0f..8acd9da 100644 --- a/test/pvCopy/Makefile +++ b/test/pvCopy/Makefile @@ -6,6 +6,10 @@ PROD_HOST += testPVCopy testPVCopy_SRCS += testPVCopy.cpp testPVCopy_LIBS += pvDatabase pvAccess pvData Com +PROD_HOST += testPVRecord +testPVRecord_SRCS += testPVRecord.cpp +testPVRecord_LIBS += pvDatabase pvAccess pvData Com + include $(TOP)/configure/RULES #---------------------------------------- # ADD RULES AFTER THIS LINE diff --git a/test/pvCopy/testPVCopy.cpp b/test/pvCopy/testPVCopy.cpp index 8d7f206..68a6ae0 100644 --- a/test/pvCopy/testPVCopy.cpp +++ b/test/pvCopy/testPVCopy.cpp @@ -309,6 +309,7 @@ static void scalarTest() pvCopy = PVCopy::create(pvRecord,pvRequest,""); valueNameCopy = "value"; testPVScalar(valueNameRecord,valueNameCopy,pvRecord,pvCopy); + pvRecord->destroy(); } static void arrayTest() @@ -349,6 +350,7 @@ static void arrayTest() pvCopy = PVCopy::create(pvRecord,pvRequest,""); valueNameCopy = "value"; testPVScalarArray(pvDouble,valueNameRecord,valueNameCopy,pvRecord,pvCopy); + pvRecord->destroy(); } static void powerSupplyTest() @@ -397,6 +399,7 @@ static void powerSupplyTest() pvCopy = PVCopy::create(pvRecord,pvRequest,""); valueNameCopy = "power.value"; testPVScalar(valueNameRecord,valueNameCopy,pvRecord,pvCopy); + pvRecord->destroy(); } int main(int argc,char *argv[]) diff --git a/test/pvCopy/testPVRecord.cpp b/test/pvCopy/testPVRecord.cpp new file mode 100644 index 0000000..5e1b029 --- /dev/null +++ b/test/pvCopy/testPVRecord.cpp @@ -0,0 +1,117 @@ +/*testPVRecordMain.cpp */ +/** + * Copyright - See the COPYRIGHT that is included with this distribution. + * EPICS pvData is distributed subject to a Software License Agreement found + * in file LICENSE that is included with this distribution. + */ +/** + * @author mrk + */ + +/* Author: Marty Kraimer */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + + +using namespace std; +using std::tr1::static_pointer_cast; +using namespace epics::pvData; +using namespace epics::pvAccess; +using namespace epics::pvDatabase; + +static PVRecordPtr createScalar( + String const & recordName, + ScalarType scalarType, + String const & properties) +{ + PVStructurePtr pvStructure = getStandardPVField()->scalar(scalarType,properties); + PVRecordPtr pvRecord = PVRecord::create(recordName,pvStructure); + pvStructure.reset(); + return pvRecord; +} + +static PVRecordPtr createScalarArray( + String const & recordName, + ScalarType scalarType, + String const & properties) +{ + PVStructurePtr pvStructure = getStandardPVField()->scalarArray(scalarType,properties); + return PVRecord::create(recordName,pvStructure); +} + +static PowerSupplyRecordTestPtr createPowerSupply(String const & recordName) +{ + FieldCreatePtr fieldCreate = getFieldCreate(); + StandardFieldPtr standardField = getStandardField(); + PVDataCreatePtr pvDataCreate = getPVDataCreate(); + size_t nfields = 5; + StringArray names; + names.reserve(nfields); + FieldConstPtrArray powerSupply; + powerSupply.reserve(nfields); + names.push_back("alarm"); + powerSupply.push_back(standardField->alarm()); + names.push_back("timeStamp"); + powerSupply.push_back(standardField->timeStamp()); + String properties("alarm,display"); + names.push_back("voltage"); + powerSupply.push_back(standardField->scalar(pvDouble,properties)); + names.push_back("power"); + powerSupply.push_back(standardField->scalar(pvDouble,properties)); + names.push_back("current"); + powerSupply.push_back(standardField->scalar(pvDouble,properties)); + return PowerSupplyRecordTest::create(recordName, + pvDataCreate->createPVStructure( + fieldCreate->createStructure(names,powerSupply))); +} + +static void scalarTest() +{ + cout << endl << endl << "****scalarTest****" << endl; + PVRecordPtr pvRecord; + pvRecord = createScalar("doubleRecord",pvDouble,"alarm,timeStamp.display"); + pvRecord->destroy(); +} + +static void arrayTest() +{ + cout << endl << endl << "****arrayTest****" << endl; + PVRecordPtr pvRecord; + pvRecord = createScalarArray("doubleArrayRecord",pvDouble,"alarm,timeStamp"); + pvRecord->destroy(); +} + +static void powerSupplyTest() +{ + cout << endl << endl << "****powerSupplyTest****" << endl; + PowerSupplyRecordTestPtr pvRecord; + pvRecord = createPowerSupply("powerSupply"); + pvRecord->destroy(); +} + +int main(int argc,char *argv[]) +{ + scalarTest(); + //arrayTest(); + //powerSupplyTest(); + return 0; +} + diff --git a/test/server/exampleCounterMain.cpp b/test/server/exampleCounterMain.cpp new file mode 100644 index 0000000..460f9a3 --- /dev/null +++ b/test/server/exampleCounterMain.cpp @@ -0,0 +1,51 @@ +/*ExampleCounterMain.cpp */ +/** + * Copyright - See the COPYRIGHT that is included with this distribution. + * EPICS pvData is distributed subject to a Software License Agreement found + * in file LICENSE that is included with this distribution. + */ +/** + * @author mrk + */ + +/* Author: Marty Kraimer */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +using namespace std; +using std::tr1::static_pointer_cast; +using namespace epics::pvData; +using namespace epics::pvAccess; +using namespace epics::pvDatabase; + +int main(int argc,char *argv[]) +{ + PVDatabasePtr master = PVDatabase::getMaster(); + ChannelProviderLocalPtr channelProvider = ChannelProviderLocal::create(); + String recordName("exampleCounter"); + PVRecordPtr pvRecord = ExampleCounter::create(recordName); + bool result = master->addRecord(pvRecord); + cout << "result of addRecord " << recordName << " " << result << endl; + pvRecord.reset(); + cout << "exampleServer\n"; + string str; + while(true) { + cout << "Type exit to stop: \n"; + getline(cin,str); + if(str.compare("exit")==0) break; + + } + return 0; +} +