convert UdpSocket and Udp to Ptr<Node>

Mathieu Lacage 2007-05-10 07:51:59 +02:00
parent ad8424e6d1
commit 96e58ed708
5 changed files with 17 additions and 29 deletions

View File

@ -26,7 +26,7 @@
namespace ns3 {
UdpSocket::UdpSocket (Node *node, Udp *udp)
UdpSocket::UdpSocket (Ptr<Node> node, Udp *udp)
: m_endPoint (0),
m_node (node),
m_udp (udp),
@ -36,15 +36,10 @@ UdpSocket::UdpSocket (Node *node, Udp *udp)
m_connected (false)
{
m_udp->Ref ();
m_node->Ref ();
}
UdpSocket::~UdpSocket ()
{
if (m_node != 0)
{
m_node->Unref ();
m_node = 0;
}
m_node = 0;
if (m_endPoint != 0)
{
NS_ASSERT (m_udp != 0);
@ -67,8 +62,8 @@ UdpSocket::~UdpSocket ()
}
}
Node *
UdpSocket::PeekNode (void) const
Ptr<Node>
UdpSocket::GetNode (void) const
{
return m_node;
}
@ -76,11 +71,7 @@ UdpSocket::PeekNode (void) const
void
UdpSocket::Destroy (void)
{
if (m_node != 0)
{
m_node->Unref ();
m_node = 0;
}
m_node = 0;
m_endPoint = 0;
if (m_udp != 0)
{

View File

@ -24,6 +24,7 @@
#include <stdint.h>
#include "ns3/callback.h"
#include "ns3/socket.h"
#include "ns3/ptr.h"
namespace ns3 {
@ -38,11 +39,11 @@ public:
/**
* Create an unbound udp socket.
*/
UdpSocket (Node *node, Udp *udp);
UdpSocket (Ptr<Node> node, Udp *udp);
virtual ~UdpSocket ();
virtual enum SocketErrno GetErrno (void) const;
virtual Node *PeekNode (void) const;
virtual Ptr<Node> GetNode (void) const;
virtual int Bind (void);
virtual int Bind (Ipv4Address address);
virtual int Bind (uint16_t port);
@ -81,7 +82,7 @@ private:
ns3::Callback<void, Socket*, uint32_t> dataSent);
Ipv4EndPoint *m_endPoint;
Node *m_node;
Ptr<Node> m_node;
Udp *m_udp;
Ipv4Address m_defaultAddress;
uint16_t m_defaultPort;

View File

@ -38,13 +38,11 @@ namespace ns3 {
/* see http://www.iana.org/assignments/protocol-numbers */
const uint8_t Udp::PROT_NUMBER = 17;
Udp::Udp (Node *node)
Udp::Udp (Ptr<Node> node)
: Ipv4L4Protocol (PROT_NUMBER, 2),
m_node (node),
m_endPoints (new Ipv4EndPointDemux ())
{
m_node->Ref ();
}
{}
Udp::~Udp ()
{}
@ -63,11 +61,7 @@ Udp::DoDispose (void)
delete m_endPoints;
m_endPoints = 0;
}
if (m_node != 0)
{
m_node->Unref ();
m_node = 0;
}
m_node = 0;
Ipv4L4Protocol::DoDispose ();
}

View File

@ -26,6 +26,7 @@
#include "ns3/packet.h"
#include "ns3/ipv4-address.h"
#include "ns3/ptr.h"
#include "ipv4-end-point-demux.h"
#include "ipv4-l4-protocol.h"
@ -40,7 +41,7 @@ class Udp : public Ipv4L4Protocol {
public:
static const uint8_t PROT_NUMBER;
Udp (Node *node);
Udp (Ptr<Node> node);
virtual ~Udp ();
virtual TraceResolver *CreateTraceResolver (TraceContext const &context);
@ -67,7 +68,7 @@ public:
protected:
virtual void DoDispose (void);
private:
Node *m_node;
Ptr<Node> m_node;
Ipv4EndPointDemux *m_endPoints;
};

View File

@ -22,6 +22,7 @@
#define __SOCKET_H__
#include "ns3/callback.h"
#include "ns3/ptr.h"
#include "ipv4-address.h"
#include "ns3/object.h"
#include <stdint.h>
@ -65,7 +66,7 @@ public:
/**
* \returns the node this socket is associated with.
*/
virtual Node *PeekNode (void) const = 0;
virtual Ptr<Node> GetNode (void) const = 0;
/**
* Allocate a free port number and