LEFT | RIGHT |
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle. | 3 * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle. |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 5 * This program is free software; you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 2 as | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 WifiRadioEnergyModel::WifiRadioEnergyDepletionCallback callback) | 48 WifiRadioEnergyModel::WifiRadioEnergyDepletionCallback callback) |
49 { | 49 { |
50 m_depletionCallback = callback; | 50 m_depletionCallback = callback; |
51 } | 51 } |
52 | 52 |
53 /* | 53 /* |
54 * Private function starts here. | 54 * Private function starts here. |
55 */ | 55 */ |
56 | 56 |
57 Ptr<DeviceEnergyModel> | 57 Ptr<DeviceEnergyModel> |
58 WifiRadioEnergyModelHelper::DoInstall (Ptr<NetDevice> device) const | 58 WifiRadioEnergyModelHelper::DoInstall (Ptr<NetDevice> device, |
| 59 Ptr<EnergySource> source) const |
59 { | 60 { |
60 NS_ASSERT (device != NULL); | 61 NS_ASSERT (device != NULL); |
| 62 NS_ASSERT (source != NULL); |
61 // check if device is WifiNetDevice | 63 // check if device is WifiNetDevice |
62 std::string deviceName = device->GetInstanceTypeId ().GetName (); | 64 std::string deviceName = device->GetInstanceTypeId ().GetName (); |
63 if (deviceName.compare ("ns3::WifiNetDevice") != 0) | 65 if (deviceName.compare ("ns3::WifiNetDevice") != 0) |
64 { | 66 { |
65 NS_FATAL_ERROR ("NetDevice type is not WifiNetDevice!"); | 67 NS_FATAL_ERROR ("NetDevice type is not WifiNetDevice!"); |
66 } | 68 } |
67 // check if energy source is installed | |
68 Ptr<Node> node = device->GetNode (); | 69 Ptr<Node> node = device->GetNode (); |
69 Ptr<EnergySource> source = node->GetObject<EnergySource> (); | 70 Ptr<WifiRadioEnergyModel> model = m_radioEnergy.Create ()->GetObject<WifiRadio
EnergyModel> (); |
70 if (source != NULL) | 71 NS_ASSERT (model != NULL); |
71 { | 72 // set energy source pointer |
72 Ptr<WifiRadioEnergyModel> model = m_radioEnergy.Create ()-> | 73 model->SetEnergySource (source); |
73 GetObject<WifiRadioEnergyModel> (); | 74 // set energy depletion callback |
74 NS_ASSERT (model != NULL); | 75 model->SetEnergyDepletionCallback (m_depletionCallback); |
75 // set node pointer | 76 // add model to device model list in energy source |
76 model->SetNode (node); | 77 source->AppendDeviceEnergyModel (model); |
77 // set energy source pointer | 78 // create and register energy model phy listener |
78 model->SetEnergySource (source); | 79 Ptr<WifiNetDevice> wifiDevice = DynamicCast<WifiNetDevice> (device); |
79 // set energy depletion callback | 80 Ptr<WifiPhy> wifiPhy = wifiDevice->GetPhy (); |
80 model->SetEnergyDepletionCallback (m_depletionCallback); | 81 wifiPhy->RegisterListener (model->GetPhyListener ()); |
81 // add model to device model list in energy source | 82 return model; |
82 source->AppendDeviceEnergyModel (model); | |
83 // create and install energy model callback | |
84 Ptr<WifiNetDevice> wifiDevice = DynamicCast<WifiNetDevice> (device); | |
85 Ptr<WifiPhy> wifiPhy = wifiDevice->GetPhy (); | |
86 DeviceEnergyModel::ChangeStateCallback callback; | |
87 callback = MakeCallback (&DeviceEnergyModel::ChangeState, model); | |
88 /* | |
89 wifiPhy->SetEnergyModelCallback (callback); | |
90 */ | |
91 return model; | |
92 } | |
93 else | |
94 { | |
95 NS_FATAL_ERROR ("Energy source NOT installed!"); | |
96 return NULL; | |
97 } | |
98 } | 83 } |
99 | 84 |
100 } // namespace ns3 | 85 } // namespace ns3 |
LEFT | RIGHT |