diff options
author | razb <razb@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2005-04-01 21:33:36 +0000 |
---|---|---|
committer | razb <razb@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2005-04-01 21:33:36 +0000 |
commit | 35510d5b8bf25a8bd3e9bd7066fed560d95cbedb (patch) | |
tree | 3bd83ae862afed9cfd68b764a2f73b5990a682c5 | |
parent | 8e3487ac18ee569b74fb542137b77cd6064f5ed9 (diff) | |
download | ATCD-35510d5b8bf25a8bd3e9bd7066fed560d95cbedb.tar.gz |
*** empty log message ***
-rw-r--r-- | examples/netlink_pingpong/netlinkgateway.cpp | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/examples/netlink_pingpong/netlinkgateway.cpp b/examples/netlink_pingpong/netlinkgateway.cpp new file mode 100644 index 00000000000..d11209bea24 --- /dev/null +++ b/examples/netlink_pingpong/netlinkgateway.cpp @@ -0,0 +1,108 @@ +// $Id$ +/*! \file netlinkgateway.h +\brief netlinkgateway gateway code . +handles the io coming from the driver and dispatches it. + +IO coming from the driver is always at the size of msg+pagesize. +i should this when i would use shared memeory. +*/ + +#include "netlinkgateway.h" +#include "ace/Basic_Types.h" +#include "ace/Reactor.h" + +#define NETLINK_UNUSED 14 //! this value must match the driver family's values + + +CNetlinkGateway* CSingleton<CNetlinkGateway>::m_instance=0; + +CNetlinkGateway::CNetlinkGateway() +: ACE_Event_Handler(), CSingleton<CNetlinkGateway>(){} + + + +CNetlinkGateway::~CNetlinkGateway(){} + +/*! \fn CNetlinkGateway::open() +\brief registers in the reactor and registers in the driver. +*/ +int CNetlinkGateway::open() +{ +m_Addr.set(0,0); +printf("CNetlinkGateway::open \n"); + +if ( 0> m_Socket.open(m_Addr, AF_NETLINK,NETLINK_UNUSED) ){ + + ACE_ERROR((LM_ERROR,"CNetlinkGateway::open() failed to open socket\n")); + return -1; +} + + + reactor(ACE_Reactor::instance()); + if ( reactor() == NULL ){ + ACE_ERROR((LM_ERROR,"CNetlinkGateway::open() failed to get reactor")); + return (-1); + } + + if (reactor()->register_handler(this, + ACE_Event_Handler::READ_MASK + ) ){ + ACE_ERROR((LM_ERROR,"CNetlinkGateway::open() failed to rgisters to reactor\n")); + return -1; + } +} + +/*! \fn CNetlinkGateway::handle_input + \brief handle input must be a multithread function . when it is invoked +*/ +int CNetlinkGateway::handle_input(ACE_HANDLE fd) +{ + + NetlinkMsg msg; + // + //Size of message if fixed at PAGE_SIZE+sizeof(scipio_Msg) + // + int ret = m_Socket.recv(&msg,sizeof(msg),0); + if (ret>0){ + Ping(msg); + }else{ + ACE_ERROR((LM_ERROR,"CNetlinkGateway::handle_input no msg recived")); + } + return ret; +} + + +int CNetlinkGateway::handle_close(ACE_HANDLE fd,ACE_Reactor_Mask close_mask) +{ + m_Socket.close(); + return 0; +} + +// +// I am not supposed to get here +// +int CNetlinkGateway::handle_output(ACE_HANDLE fd) +{ + ACE_ERROR((LM_ERROR,"CNetlinkGateway::handle_output")); + return 0; +} + +/*! \fn CNetlinkGateway::Pong + \brief Pong method send a reply message back to the driver +*/ +int CNetlinkGateway::Ping(NetlinkMsg& msg){ + + NetlinkMsg Reply; + + strcpy(msg.data,"Pong"); + Reply.h.dw_num = msg.h.dw_num++; + Reply.h.dw_pid=getpid(); + + int ret = m_Socket.send(&Reply,sizeof(Reply),0) ; + if ( 0< ret ){ + printf("pong %d\n",Reply.h.dw_num); + }else{ + printf("pong %d failed \n",Reply.h.dw_num); + } + return ret; +} |