25 #define epicsAssertAuthor "Jeff Hill johill@lanl.gov" 49 typeCode ( USHRT_MAX ),
52 size_t nameLengthTmp = strlen ( pNameIn ) + 1;
55 if ( nameLengthTmp >
MAX_UDP_SEND -
sizeof (
caHdr ) || nameLengthTmp > USHRT_MAX ) {
63 this->nameLength = static_cast <
unsigned short> ( nameLengthTmp );
65 this->pNameStr =
new char [ this->nameLength ];
66 strcpy ( this->pNameStr, pNameIn );
71 delete [] this->pNameStr;
81 bool success = this->cacCtx.
destroyIO ( callbackGuard, mutualExcusionGuard,
82 pNetIO->getId (), *this );
91 mutualExcusionGuard, this->sid, this->
id );
97 void nciu::operator
delete (
void * )
104 errlogPrintf (
"%s:%d this compiler is confused about placement delete - memory was probably leaked",
105 __FILE__, __LINE__ );
108 void nciu::initiateConnect (
115 unsigned nativeCount,
unsigned sidIn,
121 throw std::logic_error (
"Ignored conn resp with bad native data type" );
124 this->typeCode = static_cast <
unsigned short > ( nativeType );
125 this->count = nativeCount;
132 bool v41Ok = this->piiu->
ca_v41_ok ( guard );
146 guard, this->accessRightState );
165 cac & caRefTmp = this->cacCtx;
168 *
this, this->eventq );
187 this->piiu = & newiiu;
189 this->typeCode = USHRT_MAX;
191 this->sid = UINT_MAX;
201 this->accessRightState = arIn;
217 guard, this->
getId (), this->pNameStr, this->nameLength );
219 if ( this->retry < UINT_MAX ) {
230 return this->pNameStr;
235 char * pBuf,
unsigned bufLen )
const throw ()
237 if ( bufLen == 0u ) {
240 if ( this->nameLength < bufLen ) {
241 strcpy ( pBuf, this->pNameStr );
242 return this->nameLength;
245 unsigned reducedSize = bufLen - 1u;
246 strncpy ( pBuf, this->pNameStr, bufLen );
247 pBuf[reducedSize] =
'\0';
256 return this->nameLength;
259 unsigned nciu::requestMessageBytesPending (
268 piiu->
flush ( guard );
281 if ( ! this->accessRightState.
readPermit () ) {
284 if ( countIn > this->count ) {
296 guard, *
this, *
this, type, countIn, notify );
300 this->eventq.
add ( io );
304 void nciu::stringVerify (
const char *pStr,
const unsigned count )
306 for (
unsigned i = 0;
i < count;
i++ ) {
307 unsigned int strsize = 0;
308 while ( pStr[strsize++] !=
'\0' ) {
331 if ( countIn > this->count || countIn == 0 ) {
335 nciu::stringVerify ( (
char *) pValue, countIn );
337 this->piiu->
writeRequest ( guard, *
this, type, countIn, pValue );
352 if ( countIn > this->count || countIn == 0 ) {
356 nciu::stringVerify ( (
char *) pValue, countIn );
360 guard, *
this, *
this, type, countIn, pValue, notify );
364 this->eventq.
add ( io );
368 void nciu::subscribe (
374 guard, *
this, *
this, type, nElem, mask, notify,
376 this->eventq.
add ( io );
382 void nciu::ioCancel (
388 mutualExclusionGuard, idIn, *
this );
393 const ioid &idIn,
unsigned level )
const 395 this->cacCtx.
ioShow ( guard, idIn, level );
400 char *pBuf,
unsigned bufLength )
const throw ()
403 guard, pBuf, bufLength );
406 const char * nciu::pHostName (
412 bool nciu::ca_v42_ok (
418 short nciu::nativeType (
423 if ( this->typeCode < SHRT_MAX ) {
424 type = static_cast <
short> ( this->typeCode );
435 countOut = this->count;
444 return this->accessRightState;
447 unsigned nciu::searchAttempts (
454 double nciu::beaconPeriod (
460 double nciu::receiveWatchdogDelay (
475 this->
show ( guard, level );
482 char hostNameTmp [256];
483 this->
getHostName ( guard, hostNameTmp,
sizeof ( hostNameTmp ) );
484 ::printf (
"Channel \"%s\", connected to server %s",
485 this->pNameStr, hostNameTmp );
487 int tmpTypeCode = static_cast <
int > ( this->typeCode );
488 ::printf (
", native type %s, native element count %u",
490 ::printf (
", %sread access, %swrite access",
491 this->accessRightState.
readPermit() ?
"" :
"no ",
492 this->accessRightState.
writePermit() ?
"" :
"no ");
497 ::printf (
"Channel \"%s\" is disconnected\n", this->pNameStr );
501 ::printf (
"\tnetwork IO pointer = %p\n",
502 static_cast <void *> ( this->piiu ) );
503 ::printf (
"\tserver identifier %u\n", this->sid );
504 ::printf (
"\tsearch retry number=%u\n", this->retry );
505 ::printf (
"\tname length=%u\n", this->nameLength );
509 void nciu::ioCompletionNotify (
512 this->eventq.
remove ( io );
519 while ( pNetIO.
valid () ) {
531 errlogPrintf (
"CAC: failed to send subscription request " 532 "during channel connect\n" );
543 while ( pNetIO.
valid () ) {
551 "CAC: failed to send subscription update request " 552 "during channel connect\n" );
563 *
this, this->eventq );
574 void channelNode::setRespPendingState (
578 static_cast < channelNode::channelState >
579 ( channelNode::cs_searchRespPending0 + index );
580 if ( this->listMember > cs_searchRespPending17 ) {
581 throw std::runtime_error (
582 "resp search timer index out of bounds" );
586 void channelNode::setReqPendingState (
590 static_cast < channelNode::channelState >
591 ( channelNode::cs_searchReqPending0 + index );
592 if ( this->listMember > cs_searchReqPending17 ) {
593 throw std::runtime_error (
594 "req search timer index out of bounds" );
601 cs_searchReqPending17 - cs_searchReqPending0,
602 cs_searchRespPending17 - cs_searchRespPending0 ) + 1u;
605 unsigned channelNode::getSearchTimerIndex (
608 channelNode::channelState chanState = this->listMember;
610 if ( chanState >= cs_searchReqPending0 &&
611 chanState <= cs_searchReqPending17 ) {
612 index = chanState - cs_searchReqPending0;
614 else if ( chanState >= cs_searchRespPending0 &&
615 chanState <= cs_searchRespPending17 ) {
616 index = chanState - cs_searchRespPending0;
619 throw std::runtime_error (
620 "channel was expected to be in a search timer, but wasnt" );;
virtual void connectNotify(epicsGuard< epicsMutex > &)=0
virtual bool ca_v42_ok(epicsGuard< epicsMutex > &) const =0
void sendSubscriptionUpdateRequests(epicsGuard< epicsMutex > &)
bool searchMsg(epicsGuard< epicsMutex > &)
#define assert(exp)
Declare that a condition should be true.
unsigned nameLen(epicsGuard< epicsMutex > &) const
#define dbf_type_to_text(type)
void setServerAddressUnknown(netiiu &newiiu, epicsGuard< epicsMutex > &guard)
bool connected(epicsGuard< epicsMutex > &) const
void subscribeIfRequired(epicsGuard< epicsMutex > &guard, nciu &chan)
virtual void disconnectNotify(epicsGuard< epicsMutex > &)=0
unsigned getHostName(epicsGuard< epicsMutex > &, char *pBuf, unsigned bufLen) const
void connect(unsigned nativeType, unsigned nativeCount, unsigned sid, epicsGuard< epicsMutex > &cbGuard, epicsGuard< epicsMutex > &guard)
tsDLIterConst< T > firstIter() const
virtual void accessRightsNotify(epicsGuard< epicsMutex > &, const caAccessRights &)=0
void unresponsiveCircuitNotify(epicsGuard< epicsMutex > &cbGuard, epicsGuard< epicsMutex > &guard)
const char * pName(epicsGuard< epicsMutex > &) const
void ioShow(epicsGuard< epicsMutex > &guard, const cacChannel::ioid &id, unsigned level) const
pvd::StructureConstPtr type
#define INVALID_DB_REQ(x)
void serviceShutdownNotify(epicsGuard< epicsMutex > &callbackControlGuard, epicsGuard< epicsMutex > &mutualExclusionGuard)
void assertIdenticalMutex(const T &) const
const unsigned getId() const
nciu(cac &, netiiu &, cacChannelNotify &, const char *pNameIn, cacChannel::priLev)
virtual void flush(epicsGuard< epicsMutex > &mutualExclusionGuard)=0
virtual unsigned getHostName(epicsGuard< epicsMutex > &, char *pBuf, unsigned bufLength) const =0
virtual bool ca_v41_ok(epicsGuard< epicsMutex > &) const =0
virtual void forceSubscriptionUpdate(epicsGuard< epicsMutex > &guard, nciu &chan)=0
static unsigned getMaxSearchTimerCount()
nciu * lookupChannel(epicsGuard< epicsMutex > &, const cacChannel::ioid &)
netiiu * getPIIU(epicsGuard< epicsMutex > &)
unsigned getName(epicsGuard< epicsMutex > &, char *pBuf, unsigned bufLen) const
const T & epicsMin(const T &a, const T &b)
void initiateConnect(epicsGuard< epicsMutex > &, nciu &, netiiu *&)
virtual void uninstallChan(epicsGuard< epicsMutex > &, nciu &)=0
bool destroyIO(CallbackGuard &callbackGuard, epicsGuard< epicsMutex > &mutualExclusionGuard, const cacChannel::ioid &idIn, nciu &chan)
void destroyChannel(epicsGuard< epicsMutex > &, nciu &)
int errlogPrintf(const char *pFormat,...)
virtual const char * pHostName(epicsGuard< epicsMutex > &) const =0
double beaconPeriod(epicsGuard< epicsMutex > &, const nciu &chan) const
virtual class netSubscription * isSubscription()=0
unsigned long arrayElementCount
virtual void serviceShutdownNotify(epicsGuard< epicsMutex > &mutualExclusionGuard)=0
virtual bool searchMsg(epicsGuard< epicsMutex > &, ca_uint32_t id, const char *pName, unsigned nameLength)=0
void disconnectAllIO(epicsGuard< epicsMutex > &, epicsGuard< epicsMutex > &)
netSubscription & subscriptionRequest(epicsGuard< epicsMutex > &, nciu &, privateInterfaceForIO &, unsigned type, arrayElementCount nElem, unsigned mask, cacStateNotify &, bool channelIsInstalled)
Contains a few templates out of the C++ standard header algorithm.
virtual void writeRequest(epicsGuard< epicsMutex > &, nciu &, unsigned type, arrayElementCount nElem, const void *pValue)=0
void show(unsigned level) const
virtual unsigned requestMessageBytesPending(epicsGuard< epicsMutex > &mutualExclusionGuard)=0
#define dbf_type_is_valid(type)
bool isInstalledInServer(epicsGuard< epicsMutex > &) const
bool isConnected(epicsGuard< epicsMutex > &) const
void disconnectAllIO(epicsGuard< epicsMutex > &cbGuard, epicsGuard< epicsMutex > &guard, nciu &, tsDLList< baseNMIU > &ioList)
virtual void clearChannelRequest(epicsGuard< epicsMutex > &, ca_uint32_t sid, ca_uint32_t cid)=0
virtual double receiveWatchdogDelay(epicsGuard< epicsMutex > &) const =0
netReadNotifyIO & readNotifyRequest(epicsGuard< epicsMutex > &, nciu &, privateInterfaceForIO &, unsigned type, arrayElementCount nElem, cacReadNotify &)
void accessRightsStateChange(const caAccessRights &, epicsGuard< epicsMutex > &cbGuard, epicsGuard< epicsMutex > &guard)
netWriteNotifyIO & writeNotifyRequest(epicsGuard< epicsMutex > &, nciu &, privateInterfaceForIO &, unsigned type, arrayElementCount nElem, const void *pValue, cacWriteNotify &)
cacChannelNotify & notify() const