Files
pcas/src/ca/oldChannelNotify.cpp
2002-05-09 15:00:14 +00:00

178 lines
5.0 KiB
C++

/*
* $Id$
*
*
* L O S A L A M O S
* Los Alamos National Laboratory
* Los Alamos, New Mexico 87545
*
* Copyright, 1986, The Regents of the University of California.
*
*
* Author Jeffrey O. Hill
* johill@lanl.gov
* 505 665 1831
*/
#ifdef _MSC_VER
# pragma warning(disable:4355)
#endif
#define epicsAssertAuthor "Jeff Hill johill@lanl.gov"
#define epicsExportSharedSymbols
#include "iocinf.h"
#include "oldAccess.h"
#include "cac.h"
epicsSingleton < tsFreeList < struct oldChannelNotify, 1024 > > oldChannelNotify::pFreeList;
extern "C" void cacNoopAccesRightsHandler ( struct access_rights_handler_args )
{
}
oldChannelNotify::oldChannelNotify ( oldCAC & cacIn, const char *pName,
caCh * pConnCallBackIn, void * pPrivateIn, capri priority ) :
cacCtx ( cacIn ),
io ( cacIn.createChannel ( pName, *this, priority ) ),
pConnCallBack ( pConnCallBackIn ),
pPrivate ( pPrivateIn ), pAccessRightsFunc ( cacNoopAccesRightsHandler ),
ioSeqNo ( cacIn.sequenceNumberOfOutstandingIO () ),
prevConnected ( false )
{
// no need to worry about a connect preempting here because
// the connect sequence will not start untill initiateConnect()
// is called
if ( pConnCallBackIn == 0 ) {
this->cacCtx.incrementOutstandingIO ( cacIn.sequenceNumberOfOutstandingIO () );
}
}
oldChannelNotify::~oldChannelNotify ()
{
delete & this->io;
// no need to worry about a connect preempting here because
// the nciu as been deleted
this->cacCtx.decrementOutstandingIO ( this->ioSeqNo );
}
void oldChannelNotify::setPrivatePointer ( void *pPrivateIn )
{
this->pPrivate = pPrivateIn;
}
void * oldChannelNotify::privatePointer () const
{
return this->pPrivate;
}
int oldChannelNotify::replaceAccessRightsEvent ( caArh *pfunc )
{
// The order of the following is significant to guarantee that the
// access rights handler is always gets called even if the channel connects
// while this is running. There is some very small chance that the
// handler could be called twice here with the same access rights state, but
// that will not upset the application.
this->pAccessRightsFunc = pfunc ? pfunc : cacNoopAccesRightsHandler;
if ( this->io.connected () ) {
struct access_rights_handler_args args;
args.chid = this;
caAccessRights tmp = this->io.accessRights ();
args.ar.read_access = tmp.readPermit ();
args.ar.write_access = tmp.writePermit ();
( *pfunc ) ( args );
}
return ECA_NORMAL;
}
int oldChannelNotify::changeConnCallBack ( caCh * pfunc )
{
epicsGuard < callbackMutex > callbackGuard =
this->cacCtx.callbackGuardFactory ();
if ( ! this->prevConnected ) {
if ( pfunc ) {
if ( ! this->pConnCallBack ) {
this->cacCtx.decrementOutstandingIO ( this->ioSeqNo );
}
}
else {
if ( this->pConnCallBack ) {
this->cacCtx.incrementOutstandingIO ( this->ioSeqNo );
}
}
}
this->pConnCallBack = pfunc;
return ECA_NORMAL;
}
void oldChannelNotify::connectNotify ()
{
this->prevConnected = true;
if ( this->pConnCallBack ) {
struct connection_handler_args args;
args.chid = this;
args.op = CA_OP_CONN_UP;
( *this->pConnCallBack ) ( args );
}
else {
this->cacCtx.decrementOutstandingIO ( this->ioSeqNo );
}
}
void oldChannelNotify::disconnectNotify ()
{
if ( this->pConnCallBack ) {
struct connection_handler_args args;
args.chid = this;
args.op = CA_OP_CONN_DOWN;
( *this->pConnCallBack ) ( args );
}
else {
this->cacCtx.incrementOutstandingIO ( this->ioSeqNo );
}
}
void oldChannelNotify::accessRightsNotify ( const caAccessRights &ar )
{
struct access_rights_handler_args args;
args.chid = this;
args.ar.read_access = ar.readPermit();
args.ar.write_access = ar.writePermit();
( *this->pAccessRightsFunc ) ( args );
}
void oldChannelNotify::exception ( int status, const char *pContext )
{
this->cacCtx.exception ( status, pContext, __FILE__, __LINE__ );
}
void oldChannelNotify::readException ( int status, const char *pContext,
unsigned type, arrayElementCount count, void * /* pValue */ )
{
this->cacCtx.exception ( status, pContext,
__FILE__, __LINE__, *this, type, count, CA_OP_GET );
}
void oldChannelNotify::writeException ( int status, const char *pContext,
unsigned type, arrayElementCount count )
{
this->cacCtx.exception ( status, pContext,
__FILE__, __LINE__, *this, type, count, CA_OP_PUT );
}
void * oldChannelNotify::operator new ( size_t size )
{
return oldChannelNotify::pFreeList->allocate ( size );
}
void oldChannelNotify::operator delete ( void *pCadaver, size_t size )
{
oldChannelNotify::pFreeList->release ( pCadaver, size );
}