convert UdpSocket and Udp to Ptr<Node>
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Thu, 10 May 2007 07:51:59 +0200
changeset 557 927a5bb6432a
parent 556 c6f107a2b886
child 558 669c703c04a4
convert UdpSocket and Udp to Ptr<Node>
src/internet-node/udp-socket.cc
src/internet-node/udp-socket.h
src/internet-node/udp.cc
src/internet-node/udp.h
src/node/socket.h
--- a/src/internet-node/udp-socket.cc	Thu May 10 07:44:18 2007 +0200
+++ b/src/internet-node/udp-socket.cc	Thu May 10 07:51:59 2007 +0200
@@ -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 @@
     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 @@
     }
 }
 
-Node *
-UdpSocket::PeekNode (void) const
+Ptr<Node>
+UdpSocket::GetNode (void) const
 {
   return m_node;
 }
@@ -76,11 +71,7 @@
 void 
 UdpSocket::Destroy (void)
 {
-  if (m_node != 0)
-    {
-      m_node->Unref ();
-      m_node = 0;
-    }
+  m_node = 0;
   m_endPoint = 0;
   if (m_udp != 0)
     {
--- a/src/internet-node/udp-socket.h	Thu May 10 07:44:18 2007 +0200
+++ b/src/internet-node/udp-socket.h	Thu May 10 07:51:59 2007 +0200
@@ -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 @@
   /**
    * 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 @@
 		      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;
--- a/src/internet-node/udp.cc	Thu May 10 07:44:18 2007 +0200
+++ b/src/internet-node/udp.cc	Thu May 10 07:51:59 2007 +0200
@@ -38,13 +38,11 @@
 /* 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 @@
       delete m_endPoints;
       m_endPoints = 0;
     }
-  if (m_node != 0)
-    {
-      m_node->Unref ();
-      m_node = 0;
-    }
+  m_node = 0;
   Ipv4L4Protocol::DoDispose ();
 }
 
--- a/src/internet-node/udp.h	Thu May 10 07:44:18 2007 +0200
+++ b/src/internet-node/udp.h	Thu May 10 07:51:59 2007 +0200
@@ -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 @@
 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 @@
 protected:
   virtual void DoDispose (void);
 private:
-  Node *m_node;
+  Ptr<Node> m_node;
   Ipv4EndPointDemux *m_endPoints;
 };
 
--- a/src/node/socket.h	Thu May 10 07:44:18 2007 +0200
+++ b/src/node/socket.h	Thu May 10 07:51:59 2007 +0200
@@ -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 @@
   /**
    * \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