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

pana_channel.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_CHANNEL_H__
00035 #define __PANA_CHANNEL_H__
00036 
00037 #include "pana_exceptions.h"
00038 #include "pana_egress.h"
00039 #include "pana_ingress.h"
00040 
00041 #if defined(PANA_PF_ENABLED)
00042    #if defined(OS_LINUX)
00043       #include "../src/linux/packet_filter.h"
00044       #define PANA_Socket PANA_LinuxTransport
00045    #elif defined(OS_WIN32)
00046       #include "../src/win32/packet_filter_winpcap.h"
00047       #define PANA_Socket PANA_Win32Transport
00048    #else
00049       #error "No link layer transport supported"
00050    #endif
00051 #else
00052    #include "pana_udp_transport.h"
00053    #include "pana_mcast_transport.h"
00054    typedef PANA_UdpTransport   PANA_UdpSocket;
00055    typedef PANA_McastTransport PANA_McastSocket;
00056 #endif 
00057 
00058 /*
00059  * PANA transport abstraction
00060  */
00061 template<class SOCKET>
00062 class PANA_EXPORT PANA_Channel : public PANA_IngressReceiver
00063 {
00064     public:
00065         PANA_Channel(AAA_GroupedJob &g, const char *name = "") :
00066             PANA_IngressReceiver(g, m_Socket, name) {
00067         }
00068         PANA_Channel(AAA_GroupedJob &g, ACE_INET_Addr &addr) :
00069             PANA_IngressReceiver(g, m_Socket) {
00070             Open(addr);
00071         }
00072                 virtual ~PANA_Channel() {
00073                         Close();
00074         }
00075         virtual void Open(ACE_INET_Addr &addr) {
00076             if (m_Socket.open(PANA_CONFIG_GENERAL().iface_name_, addr) < 0) {
00077                 throw (PANA_Exception(PANA_Exception::TRANSPORT_FAILED,
00078                                       "Failed to open device"));
00079             }
00080             if (m_Group.Schedule(this) < 0) {
00081                 throw (PANA_Exception(PANA_Exception::TRANSPORT_FAILED,
00082                                       "Failed to schedule channel"));
00083             }
00084         }
00085         virtual void Close() {
00086             m_Socket.close();
00087                         PANA_IngressReceiver::Wait();
00088         }
00089         virtual void Send(PANA_Message &m) {
00090             PANA_EgressSender egress(m_Group,
00091                                      m_IO,
00092                                      m,
00093                                      NULL,
00094                                      Name().data());
00095             egress.Schedule();
00096         }
00097         virtual void Send(PANA_Session &s, PANA_Message &m) {
00098             PANA_EgressSender egress(m_Group,
00099                                      m_IO,
00100                                      m,
00101                                      &s,
00102                                      Name().data());
00103             egress.Schedule();
00104         }
00105         virtual int GetLocalAddress(PANA_DeviceIdContainer &dev) {
00106             return m_Socket.get_local_addr(dev);
00107         }
00108     protected:
00109         SOCKET m_Socket;
00110 };
00111 
00112 typedef PANA_Channel<PANA_UdpSocket>   PANA_UdpChannel;
00113 typedef PANA_Channel<PANA_McastSocket> PANA_McastChannel;
00114 
00115 #endif // __PANA_CHANNEL_H__

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