#include <ECG_Complex_Address_Server.h>
Collaboration diagram for TAO_ECG_Complex_Address_Server:
Public Member Functions | |
virtual | ~TAO_ECG_Complex_Address_Server (void) |
Destructor. | |
int | init (const char *arg) |
virtual void | get_addr (const RtecEventComm::EventHeader &header, RtecUDPAdmin::UDP_Addr_out addr) |
virtual void | get_address (const RtecEventComm::EventHeader &header, RtecUDPAdmin::UDP_Address_out addr6) |
void | dump_content (void) |
Static Public Member Functions | |
static TAO_EC_Servant_Var< TAO_ECG_Complex_Address_Server > | create (int is_source_mapping=1) |
Create a new TAO_ECG_Complex_Address_Server object. | |
Protected Member Functions | |
TAO_ECG_Complex_Address_Server (int is_source_mapping=1) | |
Private Types | |
typedef ACE_Hash_Map_Manager_Ex< CORBA::Long, ACE_INET_Addr, ACE_Hash< CORBA::Long >, ACE_Equal_To< CORBA::Long >, ACE_Null_Mutex > | MAP |
Private Member Functions | |
int | add_entry (const char *key, const char *mcast_addr) |
Private Attributes | |
int | is_source_mapping_ |
MAP | mcast_mapping_ |
ACE_INET_Addr | default_addr_ |
INITIALIZATION STRING FORMAT
The string is a sequence of <key><value> pairs separated by a single space, where <key> is event source (or type) and
is the corresponding mcast address. Example: "34@230.100.0.2:2300 45@230.100.123.43:2300" The string above represents two key-value pairs.
A special key "*" is used to specify the default mcast address, i.e., the one that will be returned for event sources that weren't explicitly specified in the initialization string. Example: "*@230.100.0.2:2300 45@230.100.123.43:2300"
Definition at line 49 of file ECG_Complex_Address_Server.h.
typedef ACE_Hash_Map_Manager_Ex<CORBA::Long, ACE_INET_Addr, ACE_Hash<CORBA::Long>, ACE_Equal_To<CORBA::Long>, ACE_Null_Mutex> TAO_ECG_Complex_Address_Server::MAP [private] |
Definition at line 101 of file ECG_Complex_Address_Server.h.
TAO_ECG_Complex_Address_Server::~TAO_ECG_Complex_Address_Server | ( | void | ) | [virtual] |
TAO_BEGIN_VERSIONED_NAMESPACE_DECL TAO_ECG_Complex_Address_Server::TAO_ECG_Complex_Address_Server | ( | int | is_source_mapping = 1 |
) | [protected] |
Constructor (protected). Clients can create new TAO_ECG_Complex_Address_Server objects using the static create() method. <is_source_mapping> flag indicates whether this server maps based on event header source or event header type.
Definition at line 13 of file ECG_Complex_Address_Server.cpp.
00015 : is_source_mapping_ (is_source_mapping) 00016 { 00017 }
int TAO_ECG_Complex_Address_Server::add_entry | ( | const char * | key, | |
const char * | mcast_addr | |||
) | [private] |
Helper. Given key and mcast address in string form, add them to the mapping.
Definition at line 78 of file ECG_Complex_Address_Server.cpp.
References ACE_ERROR_RETURN, LM_ERROR, ACE_INET_Addr::set(), ACE_OS::strlen(), and ACE_OS::strtol().
00080 { 00081 // Check whether this is the default mcast address. 00082 if (ACE_OS::strlen (key) == 1 00083 && *key == '*') 00084 { 00085 if (this->default_addr_.set (mcast_addr) == -1) 00086 ACE_ERROR_RETURN ((LM_ERROR, "Unable to initialize: invalid " 00087 "mcast address specified: %s.\n", 00088 mcast_addr), 00089 -1); 00090 return 0; 00091 } 00092 00093 // Convert strings to values. 00094 char * endptr = 0; 00095 CORBA::Long header_value = ACE_OS::strtol (key, &endptr, 0); 00096 if (*endptr != '\0') 00097 { 00098 ACE_ERROR_RETURN ((LM_ERROR, "Unable to initialize: invalid " 00099 "source/type specified: %s.\n", 00100 key), 00101 -1); 00102 } 00103 00104 ACE_INET_Addr addr; 00105 if (addr.set (mcast_addr) == -1) 00106 { 00107 ACE_ERROR_RETURN ((LM_ERROR, "Unable to initialize: invalid " 00108 "mcast address specified: %s.\n", 00109 mcast_addr), 00110 -1); 00111 } 00112 00113 if (this->mcast_mapping_.bind (header_value, addr) == -1) 00114 { 00115 ACE_ERROR_RETURN ((LM_ERROR, "Unable to initialize: error adding " 00116 "new entry to the mapping.\n"), 00117 -1); 00118 } 00119 00120 return 0; 00121 }
static TAO_EC_Servant_Var<TAO_ECG_Complex_Address_Server> TAO_ECG_Complex_Address_Server::create | ( | int | is_source_mapping = 1 |
) | [static] |
Create a new TAO_ECG_Complex_Address_Server object.
Referenced by TAO_ECG_Mcast_Gateway::init_address_server().
void TAO_ECG_Complex_Address_Server::dump_content | ( | void | ) |
Prints out complete content of the address server. Useful for debugging.
Definition at line 192 of file ECG_Complex_Address_Server.cpp.
References ACE_DEBUG, default_addr_, ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::end(), ACE_INET_Addr::get_port_number(), LM_DEBUG, and mcast_mapping_.
00193 { 00194 ACE_DEBUG ((LM_DEBUG, "Default address: %s:%d\n", 00195 this->default_addr_.get_host_addr (), 00196 this->default_addr_.get_port_number ())); 00197 00198 for (MAP::iterator iter = this->mcast_mapping_.begin (); 00199 iter != this->mcast_mapping_.end (); 00200 iter++) 00201 { 00202 MAP::ENTRY & entry = *iter; 00203 ACE_DEBUG ((LM_DEBUG, "%d --> %s:%d\n", 00204 entry.ext_id_, 00205 this->default_addr_.get_host_addr (), 00206 this->default_addr_.get_port_number ())); 00207 } 00208 }
void TAO_ECG_Complex_Address_Server::get_addr | ( | const RtecEventComm::EventHeader & | header, | |
RtecUDPAdmin::UDP_Addr_out | addr | |||
) | [virtual] |
Definition at line 125 of file ECG_Complex_Address_Server.cpp.
References CORBA::COMPLETED_YES, default_addr_, ACE_INET_Addr::get_ip_address(), ACE_INET_Addr::get_port_number(), RtecEventComm::EventHeader::source, and RtecEventComm::EventHeader::type.
00128 { 00129 CORBA::Long key; 00130 if (this->is_source_mapping_) 00131 key = header.source; 00132 else 00133 key = header.type; 00134 00135 MAP::ENTRY * mapping_entry = 0; 00136 if (this->mcast_mapping_.find (key, mapping_entry) == -1) 00137 { 00138 // Key was not found in the mapping. Use default. 00139 #if defined (ACE_HAS_IPV6) 00140 if (this->default_addr_.get_type() == PF_INET6) 00141 throw CORBA::DATA_CONVERSION(0, CORBA::COMPLETED_YES); 00142 #endif /* ACE_HAS_IPV6 */ 00143 addr.ipaddr = this->default_addr_.get_ip_address (); 00144 addr.port = this->default_addr_.get_port_number (); 00145 } 00146 else 00147 { 00148 #if defined (ACE_HAS_IPV6) 00149 if (mapping_entry->int_id_.get_type() == PF_INET6) 00150 throw CORBA::DATA_CONVERSION(0, CORBA::COMPLETED_YES); 00151 #endif /* ACE_HAS_IPV6 */ 00152 addr.ipaddr = mapping_entry->int_id_.get_ip_address (); 00153 addr.port = mapping_entry->int_id_.get_port_number (); 00154 } 00155 }
void TAO_ECG_Complex_Address_Server::get_address | ( | const RtecEventComm::EventHeader & | header, | |
RtecUDPAdmin::UDP_Address_out | addr6 | |||
) | [virtual] |
Definition at line 158 of file ECG_Complex_Address_Server.cpp.
References ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::find(), ACE_INET_Addr::get_addr(), ACE_INET_Addr::get_ip_address(), ACE_INET_Addr::get_port_number(), ACE_Addr::get_type(), RtecUDPAdmin::UDP_Addr::ipaddr, mcast_mapping_, ACE_OS::memcpy(), RtecUDPAdmin::UDP_Addr::port, RtecEventComm::EventHeader::source, and RtecEventComm::EventHeader::type.
00161 { 00162 CORBA::Long key; 00163 if (this->is_source_mapping_) 00164 key = header.source; 00165 else 00166 key = header.type; 00167 00168 MAP::ENTRY * mapping_entry = 0; 00169 ACE_INET_Addr &src_addr = 00170 (this->mcast_mapping_.find (key, mapping_entry) == -1) ? 00171 this->default_addr_ : mapping_entry->int_id_; 00172 #if defined (ACE_HAS_IPV6) 00173 if (src_addr.get_type() == PF_INET6) 00174 { 00175 RtecUDPAdmin::UDP_Addr_v6 v6; 00176 sockaddr_in6 *in6 = 00177 reinterpret_cast<sockaddr_in6 *>(src_addr.get_addr()); 00178 ACE_OS::memcpy (v6.ipaddr,&in6->sin6_addr,16); 00179 v6.port = src_addr.get_port_number(); 00180 addr.v6_addr (v6); 00181 return; 00182 } 00183 #endif /* ACE_HAS_IPV6 */ 00184 RtecUDPAdmin::UDP_Addr v4; 00185 v4.ipaddr = src_addr.get_ip_address(); 00186 v4.port = src_addr.get_port_number(); 00187 addr.v4_addr (v4); 00188 }
int TAO_ECG_Complex_Address_Server::init | ( | const char * | arg | ) |
Initializes the mapping from the <arg> string. See class notes for the expected format.
Definition at line 24 of file ECG_Complex_Address_Server.cpp.
References ACE_ERROR_RETURN, ACE_String_Base< CHAR >::c_str(), LM_ERROR, ACE_String_Base< CHAR >::set(), ACE_OS::strchr(), and ACE_OS::strlen().
00025 { 00026 ACE_CString key_string; 00027 ACE_CString mcast_string; 00028 00029 // Our position in parsing initialization string. 00030 const char * data = arg; 00031 00032 // Parse initialization string until we reach the end. 00033 while (*data != '\0') 00034 { 00035 // Extract lookup value (it is followed by '@'). 00036 const char * location = 0; 00037 location = ACE_OS::strchr (data, '@'); 00038 if (!location) 00039 { 00040 ACE_ERROR_RETURN ((LM_ERROR, 00041 "Unable to initialize address " 00042 "server: cannot find <@> separator " 00043 "in initialization string " 00044 "as expected\n"), 00045 -1); 00046 } 00047 size_t len = location - data; 00048 key_string.set (data, len, 1); 00049 data += len + 1; 00050 00051 // Extract mcast address to be mapped to just extracted lookup 00052 // value. 00053 location = 0; 00054 location = ACE_OS::strchr (data, ' '); 00055 if (location) 00056 { 00057 len = location - data; 00058 mcast_string.set (data, len, 1); 00059 data += len + 1; 00060 } 00061 else 00062 { 00063 // This must be the last entry in the mapping. 00064 len = ACE_OS::strlen (data); 00065 mcast_string.set (data, len, 1); 00066 data += len; 00067 } 00068 00069 // Add new entry to the mapping. 00070 if (this->add_entry (key_string.c_str (), 00071 mcast_string.c_str ()) == -1) 00072 return -1; 00073 } 00074 return 0; 00075 }
Mcast group to be used for all sources (or types) not explicitly mapped.
Definition at line 107 of file ECG_Complex_Address_Server.h.
Referenced by dump_content(), and get_addr().
int TAO_ECG_Complex_Address_Server::is_source_mapping_ [private] |
Flag indicating whether this address server maps event source or event type to mcast groups.
Definition at line 98 of file ECG_Complex_Address_Server.h.
Definition at line 103 of file ECG_Complex_Address_Server.h.
Referenced by dump_content(), and get_address().