diff --git a/src/cas/example/simple/exAsyncPV.cc b/src/cas/example/simple/exAsyncPV.cc index f8fb9228c..97af45975 100644 --- a/src/cas/example/simple/exAsyncPV.cc +++ b/src/cas/example/simple/exAsyncPV.cc @@ -32,7 +32,7 @@ caStatus exAsyncPV::read (const casCtx &ctx, gdd &valueIn) // exAsyncPV::write() // (virtual replacement for the default) // -caStatus exAsyncPV::write (const casCtx &ctx, gdd &valueIn) +caStatus exAsyncPV::write (const casCtx &ctx, const gdd &valueIn) { exAsyncWriteIO *pIO; @@ -57,7 +57,7 @@ caStatus exAsyncPV::write (const casCtx &ctx, gdd &valueIn) void exAsyncWriteIO::expire() { caStatus status; - status = this->pv.update(this->value); + status = this->pv.update(this->pValue); this->postIOCompletion (status); } @@ -81,12 +81,12 @@ void exAsyncReadIO::expire () // map between the prototype in and the // current value // - status = this->pv.exPV::readNoCtx (this->proto); + status = this->pv.exPV::readNoCtx (this->pProto); // // post IO completion // - this->postIOCompletion (status, this->proto); + this->postIOCompletion (status, *this->pProto ); } // diff --git a/src/cas/example/simple/exPV.cc b/src/cas/example/simple/exPV.cc index 56d82e44a..0b48b7723 100644 --- a/src/cas/example/simple/exPV.cc +++ b/src/cas/example/simple/exPV.cc @@ -71,7 +71,7 @@ void exPV::destroy() // // exPV::update() // -caStatus exPV::update(gdd &valueIn) +caStatus exPV::update(smartConstGDDPointer pValueIn) { caServer *pCAS = this->getCAS(); caStatus cas; @@ -81,7 +81,7 @@ caStatus exPV::update(gdd &valueIn) valueIn.dump(); # endif - cas = this->updateValue (valueIn); + cas = this->updateValue (pValueIn); if ( cas || ( ! this->pValue.valid() ) ) { return cas; } @@ -343,7 +343,7 @@ caStatus exPV::getValue(gdd &value) // exPV::write() // (synchronous default) // -caStatus exPV::write (const casCtx &, gdd &valueIn) +caStatus exPV::write (const casCtx &, const gdd &valueIn) { return this->update (valueIn); } diff --git a/src/cas/example/simple/exScalarPV.cc b/src/cas/example/simple/exScalarPV.cc index 8daab0f6c..7a521eedf 100644 --- a/src/cas/example/simple/exScalarPV.cc +++ b/src/cas/example/simple/exScalarPV.cc @@ -66,7 +66,7 @@ void exScalarPV::scan() limit = (float) this->info.getLopr(); newValue = tsMax (newValue, limit); *pDD = newValue; - status = this->update (*pDD); + status = this->update (pDD); if (status!=S_casApp_success) { errMessage (status, "scalar scan update failed\n"); } @@ -84,17 +84,21 @@ void exScalarPV::scan() // result in each value change events retaining an // independent value on the event queue. // -caStatus exScalarPV::updateValue (gdd &valueIn) +caStatus exScalarPV::updateValue (smartConstGDDPointer pValueIn) { + if ( ! pValueIn.valid () ) { + return S_casApp_undefined; + } + // // Really no need to perform this check since the // server lib verifies that all requests are in range // - if (!valueIn.isScalar()) { + if (!pValueIn->isScalar()) { return S_casApp_outOfBounds; } - this->pValue = &valueIn; + this->pValue = pValueIn; return S_casApp_success; } diff --git a/src/cas/example/simple/exServer.h b/src/cas/example/simple/exServer.h index d91d7f7ee..97c8e9588 100644 --- a/src/cas/example/simple/exServer.h +++ b/src/cas/example/simple/exServer.h @@ -189,7 +189,7 @@ public: // // This gets called when the pv gets a new value // - caStatus update (gdd &value); + caStatus update (smartConstGDDPointer pValue); // // Gets called when we add noise to the current value @@ -213,12 +213,12 @@ public: caStatus read (const casCtx &, gdd &protoIn); - caStatus readNoCtx (gdd &protoIn) + caStatus readNoCtx (smartGDDPointer pProtoIn) { - return this->ft.read (*this, protoIn); + return this->ft.read (*this, *pProtoIn); } - caStatus write (const casCtx &, gdd &value); + caStatus write (const casCtx &, const gdd &value); void destroy(); @@ -241,15 +241,15 @@ public: const char * const pUserName, const char * const pHostName); protected: - smartGDDPointer pValue; - exScanTimer *pScanTimer; - pvInfo & info; - bool interest; - bool preCreate; - bool scanOn; - static osiTime currentTime; + smartConstGDDPointer pValue; + exScanTimer *pScanTimer; + pvInfo & info; + bool interest; + bool preCreate; + bool scanOn; + static osiTime currentTime; - virtual caStatus updateValue (gdd &value) = 0; + virtual caStatus updateValue (smartConstGDDPointer pValue) = 0; private: // @@ -270,7 +270,7 @@ private: }; // -// exScalerPV +// exScalarPV // class exScalarPV : public exPV { public: @@ -278,7 +278,7 @@ public: exPV (setup, preCreateFlag, scanOnIn) {} void scan(); private: - caStatus updateValue (gdd &value); + caStatus updateValue (smartConstGDDPointer pValue); }; // @@ -294,7 +294,7 @@ public: aitIndex maxBound (unsigned dimension) const; private: - caStatus updateValue (gdd &value); + caStatus updateValue (smartConstGDDPointer pValue); }; // @@ -364,7 +364,7 @@ public: // // write // - caStatus write (const casCtx &ctxIn, gdd &value); + caStatus write (const casCtx &ctxIn, const gdd &value); // // removeIO @@ -427,21 +427,15 @@ public: // // exAsyncWriteIO() // - exAsyncWriteIO (const casCtx &ctxIn, exAsyncPV &pvIn, gdd &valueIn) : - casAsyncWriteIO(ctxIn), exOSITimer(0.1), pv(pvIn), value(valueIn) + exAsyncWriteIO (const casCtx &ctxIn, exAsyncPV &pvIn, const gdd &valueIn) : + casAsyncWriteIO(ctxIn), exOSITimer(0.1), pv(pvIn), pValue(valueIn) { - int gddStatus; - gddStatus = this->value.reference(); - assert (!gddStatus); } ~exAsyncWriteIO() { - int gddStatus; this->pv.removeIO(); - gddStatus = this->value.unreference(); - assert (!gddStatus); - } + } // // expire() @@ -453,8 +447,8 @@ public: const char *name() const; private: - exAsyncPV &pv; - gdd &value; + exAsyncPV &pv; + smartConstGDDPointer pValue; }; // @@ -466,19 +460,13 @@ public: // exAsyncReadIO() // exAsyncReadIO(const casCtx &ctxIn, exAsyncPV &pvIn, gdd &protoIn) : - casAsyncReadIO(ctxIn), exOSITimer(0.1), pv(pvIn), proto(protoIn) + casAsyncReadIO(ctxIn), exOSITimer(0.1), pv(pvIn), pProto(protoIn) { - int gddStatus; - gddStatus = this->proto.reference(); - assert (!gddStatus); } ~exAsyncReadIO() { - int gddStatus; this->pv.removeIO(); - gddStatus = this->proto.unreference(); - assert (!gddStatus); } // @@ -491,8 +479,8 @@ public: const char *name() const; private: - exAsyncPV &pv; - gdd &proto; + exAsyncPV &pv; + smartGDDPointer pProto; }; // @@ -523,7 +511,7 @@ public: const char *name() const; private: const pvInfo &pvi; - exServer &cas; + exServer &cas; }; @@ -555,9 +543,9 @@ public: const char *name() const; private: - pvInfo &pvi; + pvInfo &pvi; exServer &cas; - bool scanOn; + bool scanOn; }; // diff --git a/src/cas/example/simple/exVectorPV.cc b/src/cas/example/simple/exVectorPV.cc index b7d19f342..901f9d01f 100644 --- a/src/cas/example/simple/exVectorPV.cc +++ b/src/cas/example/simple/exVectorPV.cc @@ -51,14 +51,15 @@ aitIndex exVectorPV::maxBound (unsigned dimension) const // void exVectorPV::scan() { - caStatus status; - double radians; - smartGDDPointer pDD; - aitFloat32 *pF, *pFE, *pCF; - float newValue; - float limit; - exVecDestructor *pDest; - int gddStatus; + caStatus status; + double radians; + smartGDDPointer pDD; + aitFloat32 *pF, *pFE; + const aitFloat32 *pCF; + float newValue; + float limit; + exVecDestructor *pDest; + int gddStatus; // // update current time (so we are not required to do @@ -131,7 +132,7 @@ void exVectorPV::scan() *(pF++) = newValue; } - status = this->update (*pDD); + status = this->update (pDD); if (status!=S_casApp_success) { errMessage (status, "vector scan update failed\n"); } @@ -151,16 +152,17 @@ void exVectorPV::scan() // this may result in too much memory consumtion on // the event queue. // -caStatus exVectorPV::updateValue(gdd &valueIn) +caStatus exVectorPV::updateValue(smartConstGDDPointer pValueIn) { - // - // replace means here throwing away the old gdd - // and "replacing" it with the one passed in - // - enum {replace, dontReplace} replFlag = dontReplace; gddStatus gdds; smartGDDPointer pNewValue; - + exVecDestructor *pDest; + unsigned i; + + if ( ! pValueIn.valid () ) { + return S_casApp_undefined; + } + // // Check bounds of incoming request // (and see if we are replacing all elements - @@ -169,99 +171,81 @@ caStatus exVectorPV::updateValue(gdd &valueIn) // Perhaps much of this is unnecessary since the // server lib checks the bounds of all requests // - if (valueIn.isAtomic()) { - if (valueIn.dimension()!=1u) { + if (pValueIn->isAtomic()) { + if (pValueIn->dimension()!=1u) { return S_casApp_badDimension; } - const gddBounds* pb = valueIn.getBounds(); + const gddBounds* pb = pValueIn->getBounds(); if (pb[0u].first()!=0u) { return S_casApp_outOfBounds; } - if (pb[0u].size()==this->info.getElementCount()) { - replFlag = replace; - } else if (pb[0u].size()>this->info.getElementCount()) { return S_casApp_outOfBounds; } } - else if (!valueIn.isScalar()) { + else if (!pValueIn->isScalar()) { // // no containers // return S_casApp_outOfBounds; } - if (replFlag==replace) { - // - // replacing all elements is efficient - // - pNewValue = &valueIn; + aitFloat32 *pF; + int gddStatus; + + // + // Create a new array data descriptor + // (so that old values that may be referenced on the + // event queue are not replaced) + // + pNewValue = new gddAtomic (gddAppType_value, aitEnumFloat32, + 1u, this->info.getElementCount()); + if ( ! pNewValue.valid () ) { + return S_casApp_noMemory; } - else { - aitFloat32 *pF, *pFE; - int gddStatus; - - // - // Create a new array data descriptor - // (so that old values that may be referenced on the - // event queue are not replaced) - // - pNewValue = new gddAtomic (gddAppType_value, aitEnumFloat32, - 1u, this->info.getElementCount()); - if ( ! pNewValue.valid () ) { - return S_casApp_noMemory; - } - - // - // smart pointer class takes care of the reference count - // from here down - // - gddStatus = pNewValue->unreference(); - assert (!gddStatus); + + // + // smart pointer class takes care of the reference count + // from here down + // + gddStatus = pNewValue->unreference(); + assert (!gddStatus); - // - // copy over the old values if they exist - // (or initialize all elements to zero) - // - if ( this->pValue.valid () ) { - gdds = pNewValue->copy( &(*this->pValue) ); - if ( gdds ) { - return S_cas_noConvert; - } - } - else { - // - // allocate array buffer - // - pF = new aitFloat32 [this->info.getElementCount()]; - if (!pF) { - return S_casApp_noMemory; - } - - // - // Install (and initialize) array buffer - // if no old values exist - // - pFE = &pF[this->info.getElementCount()]; - while (pFput(&valueIn); - if (gdds) { - return S_cas_noConvert; - } + // + // allocate array buffer + // + pF = new aitFloat32 [this->info.getElementCount()]; + if (!pF) { + return S_casApp_noMemory; + } + + // + // Install (and initialize) array buffer + // if no old values exist + // + unsigned count = this->info.getElementCount(); + for ( i = 0u; i < count; i++ ) { + pF[i] = 0.0f; + } - aitTimeStamp ts; - valueIn.getTimeStamp (&ts); - pNewValue->setTimeStamp (&ts); - pNewValue->setStat (valueIn.getStat()); - pNewValue->setSevr (valueIn.getSevr()); + pDest = new exVecDestructor; + if (!pDest) { + delete [] pF; + return S_casApp_noMemory; + } + + // + // install the buffer into the DD + // (do this before we increment pF) + // + pNewValue->putRef(pF, pDest); + + // + // copy in the values that they are writing + // + gdds = pNewValue->put( & (*pValueIn) ); + if (gdds) { + return S_cas_noConvert; } this->pValue = pNewValue;