Files
pcas/src/makeBaseApp/top/caServerApp/exAsyncPV.cc
T
Andrew Johnson 081cb42dc8 Moved CA client examples into their own caClientApp
Added caServerApp - copied from src/cas/example/simple
Made simpleApp significantly more useful
Made exampleApp use the _APPNAME_ macro instead of example in various places
2003-02-05 23:46:23 +00:00

141 lines
3.1 KiB
C++

/*************************************************************************\
* Copyright (c) 2002 The University of Chicago, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE Versions 3.13.7
* and higher are distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
//
// Example EPICS CA server
// (asynchrronous process variable)
//
#include "exServer.h"
//
// exAsyncPV::read()
// (virtual replacement for the default)
//
caStatus exAsyncPV::read (const casCtx &ctx, gdd &valueIn)
{
exAsyncReadIO *pIO;
if (this->simultAsychIOCount>=maxSimultAsyncIO) {
return S_casApp_postponeAsyncIO;
}
this->simultAsychIOCount++;
pIO = new exAsyncReadIO ( ctx, *this, valueIn );
if (!pIO) {
return S_casApp_noMemory;
}
return S_casApp_asyncCompletion;
}
//
// exAsyncPV::write()
// (virtual replacement for the default)
//
caStatus exAsyncPV::write ( const casCtx &ctx, const gdd &valueIn )
{
exAsyncWriteIO *pIO;
if ( this->simultAsychIOCount >= maxSimultAsyncIO ) {
return S_casApp_postponeAsyncIO;
}
this->simultAsychIOCount++;
pIO = new exAsyncWriteIO ( ctx, *this, valueIn );
if ( ! pIO ) {
return S_casApp_noMemory;
}
return S_casApp_asyncCompletion;
}
//
// exAsyncWriteIO::exAsyncWriteIO()
//
exAsyncWriteIO::exAsyncWriteIO ( const casCtx &ctxIn, exAsyncPV &pvIn,
const gdd &valueIn ) :
casAsyncWriteIO ( ctxIn ), pv ( pvIn ),
timer ( pvIn.getCAS()->createTimer () ), pValue(valueIn)
{
this->timer.start ( *this, 0.1 );
}
//
// exAsyncWriteIO::~exAsyncWriteIO()
//
exAsyncWriteIO::~exAsyncWriteIO()
{
this->pv.removeIO();
if ( this->pv.getCAS() ) {
this->timer.destroy ();
}
}
//
// exAsyncWriteIO::expire()
// (a virtual function that runs when the base timer expires)
//
epicsTimerNotify::expireStatus exAsyncWriteIO::expire ( const epicsTime & /* currentTime */ )
{
caStatus status;
status = this->pv.update ( this->pValue );
this->postIOCompletion ( status );
return noRestart;
}
//
// exAsyncReadIO::exAsyncReadIO()
//
exAsyncReadIO::exAsyncReadIO ( const casCtx &ctxIn, exAsyncPV &pvIn,
gdd &protoIn ) :
casAsyncReadIO ( ctxIn ), pv ( pvIn ),
timer ( pvIn.getCAS()->createTimer() ), pProto ( protoIn )
{
this->timer.start ( *this, 0.1 );
}
//
// exAsyncReadIO::~exAsyncReadIO()
//
exAsyncReadIO::~exAsyncReadIO()
{
this->pv.removeIO ();
if ( this->pv.getCAS() ) {
this->timer.destroy ();
}
}
//
// exAsyncReadIO::expire()
// (a virtual function that runs when the base timer expires)
//
epicsTimerNotify::expireStatus exAsyncReadIO::expire ( const epicsTime & /* currentTime */ )
{
caStatus status;
//
// map between the prototype in and the
// current value
//
status = this->pv.exPV::readNoCtx ( this->pProto );
//
// post IO completion
//
this->postIOCompletion ( status, *this->pProto );
return noRestart;
}