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_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
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__