From 23225348d6e673406ea52a219a2c45fd8f85876a Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Wed, 21 Aug 2002 16:33:50 +0000 Subject: [PATCH] installed --- src/cas/generic/caNetAddr.cc | 201 ++++++++++++++++++++++++++++++ src/cas/generic/pvAttachReturn.cc | 94 ++++++++++++++ src/cas/generic/pvExistReturn.cc | 59 +++++++++ 3 files changed, 354 insertions(+) create mode 100644 src/cas/generic/caNetAddr.cc create mode 100644 src/cas/generic/pvAttachReturn.cc create mode 100644 src/cas/generic/pvExistReturn.cc diff --git a/src/cas/generic/caNetAddr.cc b/src/cas/generic/caNetAddr.cc new file mode 100644 index 000000000..2a4d0965a --- /dev/null +++ b/src/cas/generic/caNetAddr.cc @@ -0,0 +1,201 @@ + +/*************************************************************************\ +* 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. +\*************************************************************************/ + +// +// $Id$ +// +// Author: Jeffrey O. Hill +// johill@lanl.gov +// + +#include + +#define epicsExportSharedSymbols +#define caNetAddrSock +#include "caNetAddr.h" + +static class caNetAddrSelfTest { +public: + caNetAddrSelfTest (); +} caNetAddrSelfTestDuringLoad; + +// +// caNetAddr::stringConvert () +// +void caNetAddr::stringConvert ( char *pString, unsigned stringLength ) const +{ +# ifdef caNetAddrSock + if ( this->type == casnaInet ) { + ipAddrToA (&this->addr.ip, pString, stringLength); + return; + } +# endif + if ( stringLength ) { + strncpy ( pString, "", stringLength ); + pString[stringLength-1] = '\n'; + } +} + +// +// caNetAddr::clear() +// +void caNetAddr::clear () +{ + this->type = casnaUDF; +} + +// +// caNetAddr::caNetAddr() +// +caNetAddr::caNetAddr () +{ + this->clear(); +} + +bool caNetAddr::isInet () const +{ + return this->type == casnaInet; +} + +bool caNetAddr::isValid () const +{ + return this->type != casnaUDF; +} + +bool caNetAddr::operator == (const caNetAddr &rhs) const // X aCC 361 +{ + if ( this->type != rhs.type ) { + return false; + } +# ifdef caNetAddrSock + if ( this->type == casnaInet ) { + return ( this->addr.ip.sin_addr.s_addr == rhs.addr.ip.sin_addr.s_addr ) && + ( this->addr.ip.sin_port == rhs.addr.ip.sin_port ); + } +# endif + else { + return false; + } +} + +bool caNetAddr::operator != ( const caNetAddr & rhs ) const +{ + return ! this->operator == (rhs); +} + +// +// This is specified so that compilers will not use one of +// the following assignment operators after converting to a +// sockaddr_in or a sockaddr first. +// +// caNetAddr caNetAddr::operator =(const struct sockaddr_in&) +// caNetAddr caNetAddr::operator =(const struct sockaddr&) +// +caNetAddr caNetAddr::operator = ( const caNetAddr &naIn ) +{ + this->addr = naIn.addr; + this->type = naIn.type; + return *this; +} + +void caNetAddr::setSockIP ( unsigned long inaIn, unsigned short portIn ) +{ + this->type = casnaInet; + this->addr.ip.sin_family = AF_INET; + this->addr.ip.sin_addr.s_addr = inaIn; + this->addr.ip.sin_port = portIn; +} + +void caNetAddr::setSockIP ( const struct sockaddr_in & sockIPIn ) +{ + if ( sockIPIn.sin_family != AF_INET ) { + throw std::logic_error ( "caNetAddr::setSockIP (): address wasnt IP" ); + } + this->type = casnaInet; + this->addr.ip = sockIPIn; +} + +void caNetAddr::setSock ( const struct sockaddr & sock ) +{ + if ( sock.sa_family != AF_INET ) { + throw std::logic_error ( "caNetAddr::setSock (): address wasnt IP" ); + } + this->type = casnaInet; + const struct sockaddr_in *psip = + reinterpret_cast ( & sock ); + this->addr.ip = *psip; +} + +caNetAddr::caNetAddr ( const struct sockaddr_in & sockIPIn ) +{ + this->setSockIP ( sockIPIn ); +} + +caNetAddr caNetAddr::operator = ( const struct sockaddr_in & sockIPIn ) +{ + this->setSockIP ( sockIPIn ); + return *this; +} + +caNetAddr caNetAddr::operator = ( const struct sockaddr & sockIn ) +{ + this->setSock (sockIn); + return *this; +} + +struct sockaddr_in caNetAddr::getSockIP() const +{ + if ( this->type != casnaInet ) { + throw std::logic_error ( "caNetAddr::getSockIP (): address wasnt IP" ); + } + return this->addr.ip; +} + +struct sockaddr caNetAddr::getSock() const +{ + if ( this->type != casnaInet ) { + throw std::logic_error ( "caNetAddr::getSock (): address wasnt IP" ); + } + + struct sockaddr sa; + struct sockaddr_in *psain = reinterpret_cast ( & sa ); + *psain = this->addr.ip; + return sa; +} + +caNetAddr::operator sockaddr_in () const +{ + return this->getSockIP(); +} + +caNetAddr::operator sockaddr () const +{ + return this->getSock(); +} + +void caNetAddr::selfTest () +{ + // the dummy field must be greater than or equal to the size of + // each of the other entries in the union + if ( sizeof ( this->addr ) != sizeof ( this->addr.pad ) ) { + fprintf ( stderr, "caNetAddr::selfTest ():self test failed in %s at line %d\n", + __FILE__, __LINE__ ); + throw std::logic_error ( "caNetAddr::selfTest (): failed self test" ); + } +} + +caNetAddrSelfTest::caNetAddrSelfTest () +{ + caNetAddr tmp; + tmp.selfTest (); +} + + diff --git a/src/cas/generic/pvAttachReturn.cc b/src/cas/generic/pvAttachReturn.cc new file mode 100644 index 000000000..3cc8460a9 --- /dev/null +++ b/src/cas/generic/pvAttachReturn.cc @@ -0,0 +1,94 @@ + +/*************************************************************************\ +* 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. +\*************************************************************************/ + +// +// $Id$ +// +// Author: Jeffrey O. Hill +// johill@lanl.gov +// + +#define epicsExportSharedSymbols +#include "casdef.h" + +pvAttachReturn::pvAttachReturn () +{ + this->pPV = 0; + // + // A pv name is required for success + // + this->stat = S_cas_badParameter; +} + +pvAttachReturn::pvAttachReturn ( caStatus statIn ) +{ + this->pPV = NULL; + if ( statIn == S_casApp_success ) { + // + // A pv name is required for success + // + this->stat = S_cas_badParameter; + } + else { + this->stat = statIn; + } +} + +pvAttachReturn::pvAttachReturn ( casPV & pv ) +{ + this->pPV = & pv; + this->stat = S_casApp_success; +} + +const pvAttachReturn & pvAttachReturn::operator = ( caStatus rhs ) +{ + this->pPV = NULL; + if ( rhs == S_casApp_success ) { + this->stat = S_cas_badParameter; + } + else { + this->stat = rhs; + } + return *this; +} + +// +// const pvAttachReturn &operator = (casPV &pvIn) +// +// The above assignment operator is not included +// because it does not match the strict definition of an +// assignment operator unless "const casPV &" +// is passed in, and we cant use a const PV +// pointer here because the server library _will_ make +// controlled modification of the PV in the future. +// +const pvAttachReturn & pvAttachReturn::operator = ( casPV *pPVIn ) +{ + if ( pPVIn != NULL ) { + this->stat = S_casApp_success; + } + else { + this->stat = S_casApp_pvNotFound; + } + this->pPV = pPVIn; + return *this; +} + +caStatus pvAttachReturn::getStatus () const +{ + return this->stat; +} + +casPV * pvAttachReturn::getPV () const +{ + return this->pPV; +} + diff --git a/src/cas/generic/pvExistReturn.cc b/src/cas/generic/pvExistReturn.cc new file mode 100644 index 000000000..79321d897 --- /dev/null +++ b/src/cas/generic/pvExistReturn.cc @@ -0,0 +1,59 @@ + +/*************************************************************************\ +* 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. +\*************************************************************************/ + +// +// $Id$ +// +// Author: Jeffrey O. Hill +// johill@lanl.gov +// + +#define epicsExportSharedSymbols +#include "casdef.h" + +pvExistReturn::pvExistReturn ( pvExistReturnEnum s ) : + status ( s ) {} + +pvExistReturn::pvExistReturn ( const caNetAddr & addressIn ) : + status ( pverExistsHere ) {} + +pvExistReturn::~pvExistReturn () +{ +} + +const pvExistReturn & pvExistReturn::operator = ( pvExistReturnEnum rhs ) +{ + this->status = rhs; + this->address.clear (); + return * this; +} + +const pvExistReturn & pvExistReturn::operator = ( const caNetAddr & rhs ) +{ + this->status = pverExistsHere; + this->address = rhs; + return * this; +} + +pvExistReturnEnum pvExistReturn::getStatus () const +{ + return this->status; +} + +caNetAddr pvExistReturn::getAddr () const +{ + return this->address; +} + +bool pvExistReturn::addrIsValid () const +{ + return this->address.isValid (); +}