This is Unofficial EPICS BASE Doxygen Site
caServerID.h
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  * L O S A L A M O S
12  * Los Alamos National Laboratory
13  * Los Alamos, New Mexico 87545
14  *
15  * Copyright, 1986, The Regents of the University of California.
16  *
17  * Author: Jeff Hill
18  */
19 
20 #ifndef INC_caServerID_H
21 #define INC_caServerID_H
22 
23 #include "osiSock.h"
24 #include "resourceLib.h"
25 #include "caProto.h"
26 
27 class caServerID {
28 public:
29  caServerID ( const struct sockaddr_in & addrIn, unsigned priority );
30  bool operator == ( const caServerID & ) const;
31  resTableIndex hash () const;
32  osiSockAddr address () const;
33  unsigned priority () const;
34 private:
35  struct sockaddr_in addr;
36  ca_uint8_t pri;
37 };
38 
40  const struct sockaddr_in & addrIn, unsigned priorityIn ) :
41  addr ( addrIn ), pri ( static_cast <ca_uint8_t> ( priorityIn ) )
42 {
43  assert ( priorityIn <= 0xff );
44 }
45 
46 inline bool caServerID::operator == ( const caServerID & rhs ) const
47 {
48  if ( this->addr.sin_addr.s_addr == rhs.addr.sin_addr.s_addr &&
49  this->addr.sin_port == rhs.addr.sin_port &&
50  this->pri == rhs.pri ) {
51  return true;
52  }
53  return false;
54 }
55 
57 {
58  // start with a very small server table to speed
59  // up the flush traverse for the frequent case -
60  // a small numbers of servers
61  const unsigned caServerMinIndexBitWidth = 2u;
62  const unsigned caServerMaxIndexBitWidth = 32u;
63 
64  unsigned index;
65  index = this->addr.sin_addr.s_addr;
66  index ^= this->addr.sin_port;
67  index ^= this->addr.sin_port >> 8u;
68  index ^= this->pri;
69  return integerHash ( caServerMinIndexBitWidth,
70  caServerMaxIndexBitWidth, index );
71 }
72 
74 {
75  osiSockAddr tmp;
76  tmp.ia = this->addr;
77  return tmp;
78 }
79 
80 inline unsigned caServerID::priority () const
81 {
82  return this->pri;
83 }
84 
85 #endif // ifdef INC_caServerID_H
#define assert(exp)
Declare that a condition should be true.
Definition: epicsAssert.h:70
struct sockaddr_in ia
Definition: osiSock.h:157
unsigned priority() const
Definition: caServerID.h:80
bool operator==(const caServerID &) const
Definition: caServerID.h:46
resTableIndex hash() const
Definition: caServerID.h:56
caServerID(const struct sockaddr_in &addrIn, unsigned priority)
Definition: caServerID.h:39
size_t resTableIndex
Definition: resourceLib.h:45
resTableIndex integerHash(unsigned MIN_INDEX_WIDTH, unsigned MAX_ID_WIDTH, const T &id)
Definition: resourceLib.h:1032
unsigned char ca_uint8_t
Definition: caProto.h:74
osiSockAddr address() const
Definition: caServerID.h:73