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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with this program; if not, write to the Free Software | 15 * along with this program; if not, write to the Free Software |
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 * | 17 * |
18 * Authors: Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu> | 18 * Authors: Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu> |
19 */ | 19 */ |
20 | 20 |
21 #ifndef DEVICE_ENERGY_MODEL | 21 #ifndef DEVICE_ENERGY_MODEL_H |
22 #define DEVICE_ENERGY_MODEL | 22 #define DEVICE_ENERGY_MODEL_H |
23 | 23 |
24 #include "ns3/object.h" | 24 #include "ns3/object.h" |
25 #include "energy-source.h" | 25 #include "ns3/ptr.h" |
| 26 #include "ns3/type-id.h" |
| 27 #include "ns3/node.h" |
26 | 28 |
27 namespace ns3 { | 29 namespace ns3 { |
28 | 30 |
29 class EnergySource; | 31 class EnergySource; |
30 | 32 |
31 /** | 33 /** |
32 * \brief Base class for device energy models. | 34 * \brief Base class for device energy models. |
33 * | 35 * |
34 * A device energy model should represent the energy consumption behavior of a | 36 * A device energy model should represent the energy consumption behavior of a |
35 * specific device. It will update remaining energy stored in the EnergySource | 37 * specific device. It will update remaining energy stored in the EnergySource |
36 * object installed on node. When energy is depleted, each DeviceEnergyModel | 38 * object installed on node. When energy is depleted, each DeviceEnergyModel |
37 * object installed on the same node will be informed by the EnergySource. | 39 * object installed on the same node will be informed by the EnergySource. |
38 */ | 40 */ |
39 class DeviceEnergyModel : public Object | 41 class DeviceEnergyModel : public Object |
40 { | 42 { |
41 public: | 43 public: |
| 44 /** |
| 45 * Callback type for ChangeState function. Devices uses this state to notify |
| 46 * DeviceEnergyModel of a state change. |
| 47 */ |
| 48 typedef Callback<void, int> ChangeStateCallback; |
42 | 49 |
| 50 public: |
43 static TypeId GetTypeId (void); | 51 static TypeId GetTypeId (void); |
44 DeviceEnergyModel (); | 52 DeviceEnergyModel (); |
45 virtual ~DeviceEnergyModel (); | 53 virtual ~DeviceEnergyModel (); |
46 | 54 |
47 /** | 55 /** |
| 56 * \param source Pointer to energy source installed on node. |
| 57 * |
| 58 * This function sets the pointer to energy source installed on node. Should |
| 59 * be called only by DeviceEnergyModel helper classes. |
| 60 */ |
| 61 virtual void SetEnergySource (Ptr<EnergySource> source) = 0; |
| 62 |
| 63 /** |
| 64 * \returns Total energy consumption of the device. |
| 65 * |
| 66 * DeviceEnergyModel records its own energy consumption during simulation. |
| 67 */ |
| 68 virtual double GetTotalEnergyConsumption (void) const = 0; |
| 69 |
| 70 /** |
| 71 * \param newState New state the device is in. |
| 72 * |
| 73 * DeviceEnergyModel is a state based model. This function is implemented by |
| 74 * all child of DeviceEnergyModel to change the model's state. States are to |
| 75 * be defined by each child using an enum (int). |
| 76 */ |
| 77 virtual void ChangeState (int newState) = 0; |
| 78 |
| 79 /** |
| 80 * \returns Current draw of the device, in Ampere. |
| 81 * |
| 82 * This function returns the current draw at the device in its current state. |
| 83 * This function is called from the EnergySource to obtain the total current |
| 84 * draw at any given time during simulation. |
| 85 */ |
| 86 double GetCurrentA (void) const; |
| 87 |
| 88 /** |
48 * This function is called by the EnergySource object when energy stored in | 89 * This function is called by the EnergySource object when energy stored in |
49 * the energy source is depleted. Should be implemented by child classes. | 90 * the energy source is depleted. Should be implemented by child classes. |
50 */ | 91 */ |
51 void HandleEnergyDepletion (void); | 92 virtual void HandleEnergyDepletion (void) = 0; |
52 | 93 |
53 /// Sets the pointer to node energy source. | |
54 void SetEnergySource (Ptr<EnergySource> source); | |
55 | 94 |
56 private: | 95 private: |
57 | 96 /** |
58 /* | 97 * \returns 0.0 as the current value, in Ampere. |
59 * Do not include DoStart in any child of this base class. DeviceEnergyModel | 98 * |
60 * is *not* aggregated to the node hence DoStart will *not* be called. | 99 * Child class does not have to implement this method if current draw for its |
| 100 * states are not know. This default method will always return 0.0A. For the |
| 101 * devices who does know the current draw of its states, this method must be |
| 102 * overwritten. |
61 */ | 103 */ |
62 | 104 virtual double DoGetCurrentA (void) const; |
63 /** | |
64 * All child's implementation must call BreakSourceRefCycle to ensure | |
65 * reference cycle to EnergySource object is broken. | |
66 */ | |
67 void DoDispose (void); | |
68 | |
69 /// Implements HandleEnergyDepletion. | |
70 virtual void DoHandleEnergyDepletion (void) = 0; | |
71 | |
72 private: | |
73 | |
74 /// Pointer to EnergySource object | |
75 Ptr<EnergySource> m_energySourcePtr; | |
76 | |
77 protected: | |
78 | |
79 /// This function is used to access the private energy source pointer. | |
80 void DecreaseRemainingEnergy (double energyJ); | |
81 | |
82 /// This function is used to access the private energy source pointer. | |
83 void IncreaseRemainingEnergy (double energyJ); | |
84 | |
85 /** | |
86 * This function is called to break reference cycle between DeviceEnergyModel | |
87 * and EnergySource. Child of the DeviceEnergyModel base class must call this | |
88 * function in their implementation of DoDispose to make sure the reference | |
89 * cycle is broken. | |
90 * | |
91 * Normally this work will be completed by the DoDispose function. However it | |
92 * will be overridden in the child class. Hence we introduced this function. | |
93 */ | |
94 void BreakSourceRefCycle (void); | |
95 | 105 |
96 }; | 106 }; |
97 | 107 |
98 } | 108 } |
99 | 109 |
100 #endif /* DEVICE_ENERGY_MODEL */ | 110 #endif /* DEVICE_ENERGY_MODEL_H */ |
LEFT | RIGHT |