make capabilities and sockets refcounted

Mathieu Lacage 2007-05-02 23:18:51 +02:00
parent 5528c400d0
commit e5d10e4bf7
12 changed files with 32 additions and 17 deletions

View File

@ -37,7 +37,7 @@ ApplicationList::Dispose (void)
{
Application *app = *i;
app->Dispose ();
delete app;
app->Unref ();
}
m_apps.clear ();
}

View File

@ -25,17 +25,19 @@
#define __APPLICATION_LIST_H__
#include "application.h"
#include "ns3/object.h"
#include <vector>
namespace ns3 {
class ApplicationList {
class ApplicationList : public Object
{
public:
ApplicationList(Node*);
// Copy constructor not needed, default one is correct
virtual ~ApplicationList();
// Inherited from Capabilty
void Dispose (void);
virtual void Dispose (void);
virtual ApplicationList* Copy(Node*) const;
virtual void SetNode(Node *); // Sets the node for all apps
virtual void Add(Application*); // Add an already new'ed app

View File

@ -49,13 +49,15 @@
#include "ns3/event-id.h"
#include "ns3/nstime.h"
#include "ns3/object.h"
namespace ns3 {
class Node;
class RandomVariable;
class Application {
class Application : public Object
{
public:
Application(Node *);
Application(const Application&); // Copy constructor

View File

@ -78,20 +78,20 @@ void InternetNode::Dispose()
if (m_l3Demux != 0)
{
m_l3Demux->Dispose ();
delete m_l3Demux;
m_l3Demux->Unref ();
m_l3Demux = 0;
}
if (m_ipv4L4Demux != 0)
{
m_ipv4L4Demux->Dispose ();
delete m_ipv4L4Demux;
m_ipv4L4Demux->Unref ();
m_ipv4L4Demux = 0;
}
if (m_applicationList != 0)
{
m_applicationList->Dispose ();
delete m_applicationList;
m_applicationList->Unref ();
m_applicationList = 0;
}

View File

@ -46,7 +46,7 @@ Ipv4L4Demux::Dispose (void)
for (L4List_t::const_iterator i = m_protocols.begin(); i != m_protocols.end(); ++i)
{
(*i)->Dispose ();
delete *i;
(*i)->Unref ();
}
m_protocols.clear ();
if (m_node != 0)

View File

@ -26,7 +26,7 @@
#define IPV4_L4_DEMUX_H
#include <list>
#include "ns3/object.h"
namespace ns3 {
@ -38,7 +38,8 @@ class TraceContext;
/**
* \brief L4 Ipv4 Demux
*/
class Ipv4L4Demux {
class Ipv4L4Demux : public Object
{
public:
typedef int Ipv4L4ProtocolTraceType;
Ipv4L4Demux (Node *node);

View File

@ -25,6 +25,7 @@
#ifndef IPV4_L4_PROTOCOL_H
#define IPV4_L4_PROTOCOL_H
#include "ns3/object.h"
namespace ns3 {
@ -44,7 +45,8 @@ class TraceContext;
* If you want to implement a new L4 protocol, all you have to do is
* implement a subclass of this base class and add it to an L4Demux.
*/
class Ipv4L4Protocol {
class Ipv4L4Protocol : public Object
{
public:
Ipv4L4Protocol(int protocolNumber, int version);
virtual ~Ipv4L4Protocol ();

View File

@ -46,7 +46,7 @@ L3Demux::Dispose (void)
for (L3Map_t::iterator i = m_protocols.begin(); i != m_protocols.end(); ++i)
{
i->second->Dispose ();
delete i->second;
i->second->Unref ();
}
m_protocols.clear ();
if (m_node != 0)

View File

@ -28,6 +28,7 @@
#define L3_DEMUX_H
#include <map>
#include "ns3/object.h"
namespace ns3 {
@ -39,7 +40,7 @@ class TraceContext;
/**
* \brief L3 Demux
*/
class L3Demux
class L3Demux : public Object
{
public:
typedef int ProtocolTraceType;

View File

@ -25,6 +25,8 @@
#ifndef L3_PROTOCOL_H
#define L3_PROTOCOL_H
#include "ns3/object.h"
namespace ns3 {
class Packet;
@ -36,7 +38,7 @@ class TraceContext;
/**
* ::Send is always defined in subclasses.
*/
class L3Protocol {
class L3Protocol : public Object {
public:
L3Protocol(int protocolNumber, int version);
virtual ~L3Protocol ();

View File

@ -95,11 +95,14 @@ OnOffApplication::~OnOffApplication()
void
OnOffApplication::Dispose (void)
{
delete m_socket;
if (m_socket != 0)
{
m_socket->Unref ();
m_socket = 0;
}
delete m_onTime;
delete m_offTime;
m_socket = 0;
m_onTime = 0;
m_offTime = 0;

View File

@ -23,6 +23,7 @@
#include "ns3/callback.h"
#include "ipv4-address.h"
#include "ns3/object.h"
#include <stdint.h>
namespace ns3 {
@ -38,7 +39,8 @@ class Node;
* to the BSD API to make it easier those who know the BSD API to use
* this API.
*/
class Socket {
class Socket : public Object
{
public:
virtual ~Socket();