Add a ChannelList namespace (bug 680)
This commit is contained in:
1 parent
f440883a85
commit
f6c663f434
5 files changed
+286
-3
No files matched your search
@@ -0,0 +1,182 @@
|
||||
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2009 University of Washington
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "ns3/simulator.h"
|
||||
#include "ns3/object-vector.h"
|
||||
#include "ns3/config.h"
|
||||
#include "ns3/log.h"
|
||||
#include "ns3/assert.h"
|
||||
#include "channel-list.h"
|
||||
#include "channel.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("ChannelList");
|
||||
|
||||
/**
|
||||
* \brief private implementation detail of the ChannelList API.
|
||||
*/
|
||||
class ChannelListPriv : public Object
|
||||
{
|
||||
public:
|
||||
static TypeId GetTypeId (void);
|
||||
ChannelListPriv ();
|
||||
~ChannelListPriv ();
|
||||
|
||||
uint32_t Add (Ptr<Channel> channel);
|
||||
|
||||
ChannelList::Iterator Begin (void) const;
|
||||
ChannelList::Iterator End (void) const;
|
||||
|
||||
Ptr<Channel> GetChannel (uint32_t n);
|
||||
uint32_t GetNChannels (void);
|
||||
|
||||
static Ptr<ChannelListPriv> Get (void);
|
||||
|
||||
private:
|
||||
static Ptr<ChannelListPriv> *DoGet (void);
|
||||
static void Delete (void);
|
||||
std::vector<Ptr<Channel> > m_channels;
|
||||
};
|
||||
|
||||
NS_OBJECT_ENSURE_REGISTERED (ChannelListPriv);
|
||||
|
||||
TypeId
|
||||
ChannelListPriv::GetTypeId (void)
|
||||
{
|
||||
static TypeId tid = TypeId ("ns3::ChannelListPriv")
|
||||
.SetParent<Object> ()
|
||||
.AddAttribute ("ChannelList", "The list of all channels created during the simulation.",
|
||||
ObjectVectorValue (),
|
||||
MakeObjectVectorAccessor (&ChannelListPriv::m_channels),
|
||||
MakeObjectVectorChecker<Channel> ())
|
||||
;
|
||||
return tid;
|
||||
}
|
||||
|
||||
Ptr<ChannelListPriv>
|
||||
ChannelListPriv::Get (void)
|
||||
{
|
||||
return *DoGet ();
|
||||
}
|
||||
|
||||
Ptr<ChannelListPriv> *
|
||||
ChannelListPriv::DoGet (void)
|
||||
{
|
||||
static Ptr<ChannelListPriv> ptr = 0;
|
||||
if (ptr == 0)
|
||||
{
|
||||
ptr = CreateObject<ChannelListPriv> ();
|
||||
Config::RegisterRootNamespaceObject (ptr);
|
||||
Simulator::ScheduleDestroy (&ChannelListPriv::Delete);
|
||||
}
|
||||
return &ptr;
|
||||
}
|
||||
|
||||
void
|
||||
ChannelListPriv::Delete (void)
|
||||
{
|
||||
NS_LOG_FUNCTION_NOARGS ();
|
||||
Config::UnregisterRootNamespaceObject (Get ());
|
||||
(*DoGet ()) = 0;
|
||||
}
|
||||
|
||||
ChannelListPriv::ChannelListPriv ()
|
||||
{
|
||||
NS_LOG_FUNCTION_NOARGS ();
|
||||
}
|
||||
|
||||
ChannelListPriv::~ChannelListPriv ()
|
||||
{
|
||||
NS_LOG_FUNCTION_NOARGS ();
|
||||
for (std::vector<Ptr<Channel> >::iterator i = m_channels.begin ();
|
||||
i != m_channels.end (); i++)
|
||||
{
|
||||
Ptr<Channel> channel = *i;
|
||||
channel->Dispose ();
|
||||
*i = 0;
|
||||
}
|
||||
m_channels.erase (m_channels.begin (), m_channels.end ());
|
||||
}
|
||||
|
||||
uint32_t
|
||||
ChannelListPriv::Add (Ptr<Channel> channel)
|
||||
{
|
||||
uint32_t index = m_channels.size ();
|
||||
m_channels.push_back (channel);
|
||||
return index;
|
||||
|
||||
}
|
||||
|
||||
ChannelList::Iterator
|
||||
ChannelListPriv::Begin (void) const
|
||||
{
|
||||
return m_channels.begin ();
|
||||
}
|
||||
|
||||
ChannelList::Iterator
|
||||
ChannelListPriv::End (void) const
|
||||
{
|
||||
return m_channels.end ();
|
||||
}
|
||||
|
||||
uint32_t
|
||||
ChannelListPriv::GetNChannels (void)
|
||||
{
|
||||
return m_channels.size ();
|
||||
}
|
||||
|
||||
Ptr<Channel>
|
||||
ChannelListPriv::GetChannel (uint32_t n)
|
||||
{
|
||||
NS_ASSERT_MSG (n < m_channels.size (), "Channel index " << n <<
|
||||
" is out of range (only have " << m_channels.size () << " channels).");
|
||||
return m_channels[n];
|
||||
}
|
||||
|
||||
uint32_t
|
||||
ChannelList::Add (Ptr<Channel> channel)
|
||||
{
|
||||
return ChannelListPriv::Get ()->Add (channel);
|
||||
}
|
||||
|
||||
ChannelList::Iterator
|
||||
ChannelList::Begin (void)
|
||||
{
|
||||
return ChannelListPriv::Get ()->Begin ();
|
||||
}
|
||||
|
||||
ChannelList::Iterator
|
||||
ChannelList::End (void)
|
||||
{
|
||||
return ChannelListPriv::Get ()->End ();
|
||||
}
|
||||
|
||||
Ptr<Channel>
|
||||
ChannelList::GetChannel (uint32_t n)
|
||||
{
|
||||
return ChannelListPriv::Get ()->GetChannel (n);
|
||||
}
|
||||
|
||||
uint32_t
|
||||
ChannelList::GetNChannels (void)
|
||||
{
|
||||
return ChannelListPriv::Get ()->GetNChannels ();
|
||||
}
|
||||
|
||||
} //namespace ns3
|
||||
@@ -0,0 +1,74 @@
|
||||
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2009 University of Washington
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef CHANNEL_LIST_H
|
||||
#define CHANNEL_LIST_H
|
||||
|
||||
#include <vector>
|
||||
#include "ns3/ptr.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class Channel;
|
||||
class CallbackBase;
|
||||
|
||||
|
||||
/**
|
||||
* \ingroup node
|
||||
*
|
||||
* \brief the list of simulation channels.
|
||||
*
|
||||
* Every Channel created is automatically added to this list.
|
||||
*/
|
||||
class ChannelList
|
||||
{
|
||||
public:
|
||||
typedef std::vector< Ptr<Channel> >::const_iterator Iterator;
|
||||
|
||||
/**
|
||||
* \param channel channel to add
|
||||
* \returns index of channel in list.
|
||||
*
|
||||
* This method is called automatically from Channel::Channel so
|
||||
* the user has little reason to call it himself.
|
||||
*/
|
||||
static uint32_t Add (Ptr<Channel> channel);
|
||||
/**
|
||||
* \returns a C++ iterator located at the beginning of this
|
||||
* list.
|
||||
*/
|
||||
static Iterator Begin (void);
|
||||
/**
|
||||
* \returns a C++ iterator located at the end of this
|
||||
* list.
|
||||
*/
|
||||
static Iterator End (void);
|
||||
/**
|
||||
* \param n index of requested channel.
|
||||
* \returns the Channel associated to index n.
|
||||
*/
|
||||
static Ptr<Channel> GetChannel (uint32_t n);
|
||||
/**
|
||||
* \returns the number of channels currently in the list.
|
||||
*/
|
||||
static uint32_t GetNChannels (void);
|
||||
};
|
||||
|
||||
}//namespace ns3
|
||||
|
||||
#endif /* CHANNEL_LIST_H */
|
||||
+18
-3
@@ -16,10 +16,13 @@
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "ns3/log.h"
|
||||
#include "channel.h"
|
||||
#include "channel-list.h"
|
||||
#include "net-device.h"
|
||||
|
||||
#include "ns3/log.h"
|
||||
#include "ns3/uinteger.h"
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("Channel");
|
||||
|
||||
namespace ns3 {
|
||||
@@ -30,19 +33,31 @@ TypeId
|
||||
Channel::GetTypeId (void)
|
||||
{
|
||||
static TypeId tid = TypeId ("ns3::Channel")
|
||||
.SetParent<Object> ();
|
||||
.SetParent<Object> ()
|
||||
.AddAttribute ("Id", "The id (unique integer) of this Channel.",
|
||||
TypeId::ATTR_GET,
|
||||
UintegerValue (0),
|
||||
MakeUintegerAccessor (&Channel::m_id),
|
||||
MakeUintegerChecker<uint32_t> ());
|
||||
return tid;
|
||||
}
|
||||
|
||||
Channel::Channel ()
|
||||
: m_id(0)
|
||||
{
|
||||
NS_LOG_FUNCTION_NOARGS ();
|
||||
m_id = ChannelList::Add (this);
|
||||
}
|
||||
|
||||
|
||||
Channel::~Channel ()
|
||||
{
|
||||
NS_LOG_FUNCTION_NOARGS ();
|
||||
}
|
||||
|
||||
uint32_t
|
||||
Channel::GetId (void) const
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
|
||||
} // namespace ns3
|
||||
@@ -45,6 +45,14 @@ public:
|
||||
Channel ();
|
||||
virtual ~Channel ();
|
||||
|
||||
/**
|
||||
* \returns the unique id of this channel
|
||||
*
|
||||
* This unique id happens to be also the index of the Channel into
|
||||
* the ChannelList.
|
||||
*/
|
||||
uint32_t GetId (void) const;
|
||||
|
||||
/**
|
||||
* \returns the number of NetDevices connected to this Channel.
|
||||
*
|
||||
@@ -59,6 +67,8 @@ public:
|
||||
*/
|
||||
virtual Ptr<NetDevice> GetDevice (uint32_t i) const = 0;
|
||||
|
||||
private:
|
||||
uint32_t m_id; // Channel id for this channel
|
||||
};
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
@@ -24,6 +24,7 @@ def build(bld):
|
||||
'drop-tail-queue.cc',
|
||||
'channel.cc',
|
||||
'node-list.cc',
|
||||
'channel-list.cc',
|
||||
'socket.cc',
|
||||
'socket-factory.cc',
|
||||
'packet-socket-factory.cc',
|
||||
@@ -72,6 +73,7 @@ def build(bld):
|
||||
'ethernet-trailer.h',
|
||||
'channel.h',
|
||||
'node-list.h',
|
||||
'channel-list.h',
|
||||
'socket.h',
|
||||
'socket-factory.h',
|
||||
'packet-socket-factory.h',
|
||||
|
||||
Reference in new issue
Block a user