#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) throw (CORBA::SystemException) |
void | dump_content (void) |
Static Public Member Functions | |
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 <value> pairs separated by a single space, where 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.
|
Definition at line 101 of file ECG_Complex_Address_Server.h. |
|
Destructor.
Definition at line 19 of file ECG_Complex_Address_Server.cpp.
00020 { 00021 } |
|
Constructor (protected). Clients can create new TAO_ECG_Complex_Address_Server objects using the static create() method. 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 } |
|
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, default_addr_, LM_ERROR, mcast_mapping_, ACE_INET_Addr::set(), ACE_OS::strlen(), and ACE_OS::strtol(). Referenced by init().
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 } |
|
Create a new TAO_ECG_Complex_Address_Server object.
Definition at line 8 of file ECG_Complex_Address_Server.i. References ACE_NEW_RETURN. Referenced by TAO_ECG_Mcast_Gateway::init_address_server().
00009 { 00010 TAO_EC_Servant_Var<TAO_ECG_Complex_Address_Server> s; 00011 ACE_NEW_RETURN (s, 00012 TAO_ECG_Complex_Address_Server (is_source_mapping), 00013 s); 00014 return s; 00015 } |
|
Prints out complete content of the address server. Useful for debugging. Definition at line 152 of file ECG_Complex_Address_Server.cpp. References ACE_DEBUG, default_addr_, ACE_INET_Addr::get_port_number(), LM_DEBUG, and mcast_mapping_.
00153 { 00154 ACE_DEBUG ((LM_DEBUG, "Default address: %s:%d\n", 00155 this->default_addr_.get_host_addr (), 00156 this->default_addr_.get_port_number ())); 00157 00158 for (MAP::iterator iter = this->mcast_mapping_.begin (); 00159 iter != this->mcast_mapping_.end (); 00160 iter++) 00161 { 00162 MAP::ENTRY & entry = *iter; 00163 ACE_DEBUG ((LM_DEBUG, "%d --> %s:%d\n", 00164 entry.ext_id_, 00165 this->default_addr_.get_host_addr (), 00166 this->default_addr_.get_port_number ())); 00167 } 00168 } |
|
Definition at line 125 of file ECG_Complex_Address_Server.cpp.
00130 { 00131 CORBA::Long key; 00132 if (this->is_source_mapping_) 00133 key = header.source; 00134 else 00135 key = header.type; 00136 00137 MAP::ENTRY * mapping_entry = 0; 00138 if (this->mcast_mapping_.find (key, mapping_entry) == -1) 00139 { 00140 // Key was not found in the mapping. Use default. 00141 addr.ipaddr = this->default_addr_.get_ip_address (); 00142 addr.port = this->default_addr_.get_port_number (); 00143 } 00144 else 00145 { 00146 addr.ipaddr = mapping_entry->int_id_.get_ip_address (); 00147 addr.port = mapping_entry->int_id_.get_port_number (); 00148 } 00149 } |
|
Initializes the mapping from the string. See class notes for the expected format. Definition at line 24 of file ECG_Complex_Address_Server.cpp. References ACE_CString, ACE_ERROR_RETURN, add_entry(), LM_ERROR, 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 add_entry(), and dump_content(). |
|
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 add_entry(), and dump_content(). |