rework the Wifi API to not use a single WifiNetDevice::Setup method
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Thu, 13 Mar 2008 11:21:12 -0700
changeset 2601 4297e8c61615
parent 2600 6c389d0c717d
child 2602 d9262bff6df2
rework the Wifi API to not use a single WifiNetDevice::Setup method
src/devices/wifi/wifi-helper.cc
src/devices/wifi/wifi-net-device.cc
src/devices/wifi/wifi-net-device.h
--- a/src/devices/wifi/wifi-helper.cc	Thu Mar 13 11:10:38 2008 -0700
+++ b/src/devices/wifi/wifi-helper.cc	Thu Mar 13 11:21:12 2008 -0700
@@ -110,7 +110,10 @@
       Ptr<WifiRemoteStationManager> manager = m_stationManager.Create<WifiRemoteStationManager> ();
       Ptr<WifiMac> mac = m_mac.Create<WifiMac> ();
       Ptr<WifiPhy> phy = m_phy.Create<WifiPhy> ();
-      device->Setup (node, mac, phy, manager, channel);
+      device->SetMac (mac);
+      device->SetPhy (phy);
+      device->SetRemoteStationManager (manager);
+      device->SetChannel (channel);
       node->AddDevice (device);
       devices.Add (device);
       NS_LOG_DEBUG ("node="<<node<<", mob="<<node->GetObject<MobilityModel> ());
--- a/src/devices/wifi/wifi-net-device.cc	Thu Mar 13 11:10:38 2008 -0700
+++ b/src/devices/wifi/wifi-net-device.cc	Thu Mar 13 11:21:12 2008 -0700
@@ -80,25 +80,57 @@
 }
   
 void 
-WifiNetDevice::Setup (Ptr<Node> node, Ptr<WifiMac> mac, Ptr<WifiPhy> phy,
-                      Ptr<WifiRemoteStationManager> manager,
-                      Ptr<WifiChannel> channel)
+WifiNetDevice::SetMac (Ptr<WifiMac> mac)
+{
+  m_mac = mac;
+  Setup ();
+}
+void 
+WifiNetDevice::SetPhy (Ptr<WifiPhy> phy)
+{
+  m_phy = phy;
+  Setup ();
+}
+void 
+WifiNetDevice::SetRemoteStationManager (Ptr<WifiRemoteStationManager> manager)
 {
-  m_node = node;
-  m_mac = mac;
-  m_phy = phy;
   m_stationManager = manager;
+  Setup ();
+}
+void 
+WifiNetDevice::SetChannel (Ptr<WifiChannel> channel)
+{
+  m_channel = channel;
+  Setup ();
+}
+void 
+WifiNetDevice::Setup (void)
+{
+  if (m_phy != 0 && m_channel != 0)
+    {
+      m_channel->Add (this, m_phy);
+      m_phy->SetChannel (m_channel);
+    }
 
-  m_stationManager->SetupPhy (m_phy);
+  if (m_stationManager != 0 && m_phy != 0)
+    {
+      m_stationManager->SetupPhy (m_phy);
+    }
 
-  m_mac->SetWifiRemoteStationManager (m_stationManager);
-  m_mac->SetWifiPhy (m_phy);
-  m_mac->SetForwardUpCallback (MakeCallback (&WifiNetDevice::ForwardUp, this));
-  m_mac->SetLinkUpCallback (MakeCallback (&WifiNetDevice::LinkUp, this));
-  m_mac->SetLinkDownCallback (MakeCallback (&WifiNetDevice::LinkDown, this));
-  channel->Add (this, m_phy);
-
-  m_phy->SetChannel (channel);
+  if (m_mac != 0)
+    {
+      if (m_stationManager != 0)
+        {
+          m_mac->SetWifiRemoteStationManager (m_stationManager);
+        }
+      if (m_phy != 0)
+        {
+          m_mac->SetWifiPhy (m_phy);
+        }
+      m_mac->SetForwardUpCallback (MakeCallback (&WifiNetDevice::ForwardUp, this));
+      m_mac->SetLinkUpCallback (MakeCallback (&WifiNetDevice::LinkUp, this));
+      m_mac->SetLinkDownCallback (MakeCallback (&WifiNetDevice::LinkDown, this));
+    }
 }
 Ptr<WifiMac> 
 WifiNetDevice::GetMac (void) const
@@ -139,7 +171,7 @@
 Ptr<Channel> 
 WifiNetDevice::GetChannel (void) const
 {
-  return m_phy->GetChannel ();
+  return m_channel;
 }
 Address 
 WifiNetDevice::GetAddress (void) const
--- a/src/devices/wifi/wifi-net-device.h	Thu Mar 13 11:10:38 2008 -0700
+++ b/src/devices/wifi/wifi-net-device.h	Thu Mar 13 11:21:12 2008 -0700
@@ -46,10 +46,10 @@
   WifiNetDevice ();
   virtual ~WifiNetDevice ();
 
-  
-  void Setup (Ptr<Node> node, Ptr<WifiMac> mac, Ptr<WifiPhy> phy,
-              Ptr<WifiRemoteStationManager> manager,
-              Ptr<WifiChannel> channel);
+  void SetMac (Ptr<WifiMac> mac);
+  void SetPhy (Ptr<WifiPhy> phy);
+  void SetRemoteStationManager (Ptr<WifiRemoteStationManager> manager);
+  void SetChannel (Ptr<WifiChannel> channel);
   Ptr<WifiMac> GetMac (void) const;
   Ptr<WifiPhy> GetPhy (void) const;
   Ptr<WifiRemoteStationManager> GetRemoteStationManager (void) const;
@@ -83,8 +83,10 @@
   void ForwardUp (Ptr<Packet> packet, const Mac48Address &from);
   void LinkUp (void);
   void LinkDown (void);
+  void Setup (void);
   Ptr<Node> m_node;
   Ptr<WifiPhy> m_phy;
+  Ptr<WifiChannel> m_channel;
   Ptr<WifiMac> m_mac;
   Ptr<WifiRemoteStationManager> m_stationManager;
   Callback <bool,Ptr<NetDevice>,Ptr<Packet>,uint16_t,const Address &> m_forwardUp;