00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef __PANA_MCAST_TRANSPORT_H__
00035 #define __PANA_MCAST_TRANSPORT_H__
00036
00037 #include "ace/SOCK_Dgram_Mcast.h"
00038 #include "pana_io.h"
00039
00040 class PANA_EXPORT PANA_McastTransport : public PANA_IO
00041 {
00042 public:
00043 PANA_McastTransport() { }
00044 virtual ~PANA_McastTransport() { }
00045
00046 virtual ACE_INT32 open(std::string &iface,
00047 ACE_INET_Addr &listenAddr) {
00048 m_Iface = iface;
00049 m_McastAddr.set(listenAddr);
00050 return m_Mcast.join(listenAddr, 1, iface.data());
00051 }
00052 virtual ACE_INT32 recv(void *buf,
00053 size_t n,
00054 ACE_UINT32 &srcPort,
00055 PANA_DeviceIdContainer &srcDevices) {
00056 ACE_INET_Addr srcAddr;
00057 ACE_Time_Value tm(1, 0);
00058 ACE_INT32 pkt_len = m_Mcast.recv((char*)buf, n,
00059 srcAddr, 0, &tm);
00060 if (pkt_len > 0) {
00061
00062 srcPort = srcAddr.get_port_number();
00063
00064 PANA_DeviceId *ip;
00065 ACE_NEW_RETURN(ip, PANA_DeviceId(PANA_DeviceId::IPV4_ADDRESS), (-1));
00066
00067 ACE_UINT32 ipAddr = srcAddr.get_ip_address();
00068 const_cast<std::string&>(ip->id()).assign((char*)&ipAddr,
00069 sizeof(ACE_UINT32));
00070 srcDevices.push_back(ip);
00071 }
00072 return (pkt_len);
00073 }
00074 virtual ACE_INT32 send(void *buf,
00075 size_t n,
00076 ACE_UINT32 destPort,
00077 PANA_DeviceIdContainer &destDevices) {
00078 return m_Mcast.send(buf, n);
00079 }
00080 virtual ACE_INT32 get_local_addr(PANA_DeviceIdContainer &localDevices) {
00081 return (-1);
00082 }
00083 virtual void close() {
00084 m_Mcast.leave(m_McastAddr, m_Iface.data());
00085 }
00086
00087 private:
00088 ACE_SOCK_Dgram_Mcast m_Mcast;
00089 ACE_INET_Addr m_McastAddr;
00090 std::string m_Iface;
00091 };
00092
00093 #endif
00094