This is Unofficial EPICS BASE Doxygen Site
getCopy.cpp
Go to the documentation of this file.
1 /*************************************************************************\
2 * Copyright (c) 2002 The University of Chicago, as Operator of Argonne
3 * National Laboratory.
4 * Copyright (c) 2002 The Regents of the University of California, as
5 * Operator of Los Alamos National Laboratory.
6 * EPICS BASE is distributed subject to a Software License Agreement found
7 * in file LICENSE that is included with this distribution.
8 \*************************************************************************/
9 
10 /*
11  *
12  *
13  * L O S A L A M O S
14  * Los Alamos National Laboratory
15  * Los Alamos, New Mexico 87545
16  *
17  * Copyright, 1986, The Regents of the University of California.
18  *
19  *
20  * Author Jeffrey O. Hill
21  * johill@lanl.gov
22  * 505 665 1831
23  */
24 
25 #include <string>
26 #include <stdexcept>
27 
28 #include "errlog.h"
29 
30 #define epicsAssertAuthor "Jeff Hill johill@lanl.gov"
31 
32 #include "iocinf.h"
33 #include "oldAccess.h"
34 #include "cac.h"
35 
37  epicsGuard < epicsMutex > & guard, ca_client_context & cacCtxIn,
38  oldChannelNotify & chanIn, unsigned typeIn,
39  arrayElementCount countIn, void * pValueIn ) :
40  count ( countIn ), cacCtx ( cacCtxIn ), chan ( chanIn ), pValue ( pValueIn ),
41  ioSeqNo ( 0 ), type ( typeIn )
42 {
43  this->ioSeqNo = cacCtxIn.sequenceNumberOfOutstandingIO ( guard );
44  cacCtxIn.incrementOutstandingIO ( guard, this->ioSeqNo );
45 }
46 
48 {
49 }
50 
52 {
53  epicsGuard < epicsMutex > guard ( this->cacCtx.mutexRef () );
54  this->cacCtx.decrementOutstandingIO ( guard, this->ioSeqNo );
55 }
56 
58  epicsGuard < epicsMutex > & guard, unsigned typeIn,
59  arrayElementCount countIn, const void *pDataIn )
60 {
61  if ( this->type == typeIn ) {
62  unsigned size = dbr_size_n ( typeIn, countIn );
63  memcpy ( this->pValue, pDataIn, size );
64  this->cacCtx.decrementOutstandingIO ( guard, this->ioSeqNo );
65  this->cacCtx.destroyGetCopy ( guard, *this );
66  // this object destroyed by preceding function call
67  }
68  else {
69  this->exception ( guard, ECA_INTERNAL,
70  "bad data type match in get copy back response",
71  typeIn, countIn);
72  // this object destroyed by preceding function call
73  }
74 }
75 
76 void getCopy::exception (
78  int status, const char *pContext,
79  unsigned /* typeIn */, arrayElementCount /* countIn */ )
80 {
81  oldChannelNotify & chanTmp ( this->chan );
82  unsigned typeTmp ( this->type );
83  arrayElementCount countTmp ( this->count );
84  ca_client_context & caClientCtx ( this->cacCtx );
85  // fetch client context and destroy prior to releasing
86  // the lock and calling cb in case they destroy channel there
87  this->cacCtx.destroyGetCopy ( guard, *this );
88  if ( status != ECA_CHANDESTROY ) {
89  caClientCtx.exception ( guard, status, pContext,
90  __FILE__, __LINE__, chanTmp, typeTmp,
91  countTmp, CA_OP_GET );
92  }
93 }
94 
95 void getCopy::show ( unsigned level ) const
96 {
97  int tmpType = static_cast <int> ( this->type );
98  ::printf ( "read copy IO at %p, type %s, element count %lu\n",
99  static_cast <const void *> ( this ), dbf_type_to_text ( tmpType ), this->count );
100  if ( level > 0u ) {
101  ::printf ( "\tIO sequence number %u, user's storage %p\n",
102  this->ioSeqNo, static_cast <const void *> ( this->pValue ) );
103  }
104 }
105 
106 void getCopy::operator delete ( void * )
107 {
108  // Visual C++ .net appears to require operator delete if
109  // placement operator delete is defined? I smell a ms rat
110  // because if I declare placement new and delete, but
111  // comment out the placement delete definition there are
112  // no undefined symbols.
113  errlogPrintf ( "%s:%d this compiler is confused about placement delete - memory was probably leaked",
114  __FILE__, __LINE__ );
115 }
116 
#define CA_OP_GET
Definition: cadef.h:118
#define dbf_type_to_text(type)
Definition: db_access.h:677
#define ECA_INTERNAL
Definition: caerr.h:94
void * pValue
Definition: oldAccess.h:179
void incrementOutstandingIO(epicsGuard< epicsMutex > &, unsigned ioSeqNo)
#define printf
Definition: epicsStdio.h:41
pvd::StructureConstPtr type
unsigned ioSeqNo
Definition: oldAccess.h:180
~getCopy()
Definition: getCopy.cpp:47
void exception epicsGuard< epicsMutex > int status
Definition: oldAccess.h:185
getCopy(epicsGuard< epicsMutex > &guard, ca_client_context &cacCtx, oldChannelNotify &, unsigned type, arrayElementCount count, void *pValue)
Definition: getCopy.cpp:36
unsigned type
Definition: oldAccess.h:181
int errlogPrintf(const char *pFormat,...)
Definition: errlog.c:105
void exception epicsGuard< epicsMutex > int const char * pContext
Definition: oldAccess.h:185
unsigned sequenceNumberOfOutstandingIO(epicsGuard< epicsMutex > &) const
Definition: oldAccess.h:566
void cancel()
Definition: getCopy.cpp:51
unsigned long arrayElementCount
Definition: cacIO.h:57
void completion(epicsGuard< epicsMutex > &, unsigned type, arrayElementCount count, const void *pData)
Definition: getCopy.cpp:57
oldChannelNotify & chan
Definition: oldAccess.h:178
#define dbr_size_n(TYPE, COUNT)
Definition: db_access.h:518
#define ECA_CHANDESTROY
Definition: caerr.h:132
epicsPlacementDeleteOperator((void *, tsFreeList< class getCopy, 1024, epicsMutexNOOP > &)) private ca_client_context cacCtx)
Definition: oldAccess.h:173
void show(unsigned level) const
Definition: getCopy.cpp:95
void exception epicsGuard< epicsMutex > int const char unsigned arrayElementCount count
Definition: oldAccess.h:185