Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

pana_mcast_transport.h

00001 /* BEGIN_COPYRIGHT                                                        */
00002 /*                                                                        */
00003 /* Open Diameter: Open-source software for the Diameter and               */
00004 /*                Diameter related protocols                              */
00005 /*                                                                        */
00006 /* Copyright (C) 2002-2004 Open Diameter Project                          */
00007 /*                                                                        */
00008 /* This library is free software; you can redistribute it and/or modify   */
00009 /* it under the terms of the GNU Lesser General Public License as         */
00010 /* published by the Free Software Foundation; either version 2.1 of the   */
00011 /* License, or (at your option) any later version.                        */
00012 /*                                                                        */
00013 /* This library is distributed in the hope that it will be useful,        */
00014 /* but WITHOUT ANY WARRANTY; without even the implied warranty of         */
00015 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU      */
00016 /* Lesser General Public License for more details.                        */
00017 /*                                                                        */
00018 /* You should have received a copy of the GNU Lesser General Public       */
00019 /* License along with this library; if not, write to the Free Software    */
00020 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307    */
00021 /* USA.                                                                   */
00022 /*                                                                        */
00023 /* In addition, when you copy and redistribute some or the entire part of */
00024 /* the source code of this software with or without modification, you     */
00025 /* MUST include this copyright notice in each copy.                       */
00026 /*                                                                        */
00027 /* If you make any changes that are appeared to be useful, please send    */
00028 /* sources that include the changed part to                               */
00029 /* diameter-developers@lists.sourceforge.net so that we can reflect your  */
00030 /* changes to one unified version of this software.                       */
00031 /*                                                                        */
00032 /* END_COPYRIGHT                                                          */
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); // un-supported by this platform
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 /* __PANA_MCAST_TRANSPORT_H__ */
00094 

Generated on Fri Jun 25 19:18:29 2004 for PANA by doxygen 1.3.5