installed

This commit is contained in:
Jeff Hill
2002-08-21 16:33:50 +00:00
parent d1ddd2627b
commit 23225348d6
3 changed files with 354 additions and 0 deletions
+201
View File
@@ -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 <stdio.h>
#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, "<Undefined Address>", 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 <const struct sockaddr_in*> ( & 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 <struct sockaddr_in*> ( & 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 ();
}
+94
View File
@@ -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;
}
+59
View File
@@ -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 ();
}