1 // -*- Mode:NS3 -*- |
|
2 // |
|
3 // Copyright (c) 2006 Georgia Tech Research Corporation |
|
4 // All rights reserved. |
|
5 // |
|
6 // This program is free software; you can redistribute it and/or modify |
|
7 // it under the terms of the GNU General Public License version 2 as |
|
8 // published by the Free Software Foundation; |
|
9 // |
|
10 // This program is distributed in the hope that it will be useful, |
|
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 // GNU General Public License for more details. |
|
14 // |
|
15 // You should have received a copy of the GNU General Public License |
|
16 // along with this program; if not, write to the Free Software |
|
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 // |
|
19 // Author: George F. Riley<riley@ece.gatech.edu> |
|
20 // |
|
21 // Implement the application list capability for NS3 nodes |
|
22 // George F. Riley, Georgia Tech, Spring 2007 |
|
23 |
|
24 #include "application.h" |
|
25 #include "application-list.h" |
|
26 #include "ns3/iid-manager.h" |
|
27 |
|
28 namespace ns3{ |
|
29 |
|
30 const uint32_t ApplicationList::iid = IidManager::Allocate ("ApplicationList"); |
|
31 |
|
32 ApplicationList::ApplicationList(Node* n) |
|
33 : NsUnknown (ApplicationList::iid) |
|
34 {} |
|
35 |
|
36 void |
|
37 ApplicationList::DoDispose (void) |
|
38 { |
|
39 for (std::vector<Application*>::const_iterator i = m_apps.begin(); |
|
40 i != m_apps.end(); ++i) |
|
41 { |
|
42 Application *app = *i; |
|
43 app->Dispose (); |
|
44 app->Unref (); |
|
45 } |
|
46 m_apps.clear (); |
|
47 NsUnknown::DoDispose (); |
|
48 } |
|
49 |
|
50 ApplicationList::~ApplicationList() |
|
51 {} |
|
52 |
|
53 ApplicationList* ApplicationList::Copy(Node * n) const |
|
54 { // Copy this app list |
|
55 ApplicationList* r = new ApplicationList(n); |
|
56 return r; |
|
57 } |
|
58 |
|
59 void |
|
60 ApplicationList::Add(Application* a) |
|
61 { |
|
62 a->Ref (); |
|
63 m_apps.push_back(a); |
|
64 } |
|
65 |
|
66 void ApplicationList::SetNode(Node * n) |
|
67 { |
|
68 // Set the node pointer in each application |
|
69 for (std::vector<Application *>::const_iterator i = m_apps.begin(); |
|
70 i != m_apps.end(); ++i) |
|
71 { // Set correct node pointer in each app |
|
72 (*i)->SetNode(n); |
|
73 } |
|
74 } |
|
75 |
|
76 |
|
77 uint32_t ApplicationList::Count() const |
|
78 { |
|
79 return m_apps.size(); |
|
80 } |
|
81 |
|
82 Application* ApplicationList::Get(uint32_t i) const |
|
83 { // Get the i'th application. Note, this is linear time in N |
|
84 if (m_apps.empty()) return 0; // List is empty |
|
85 return m_apps[i]; |
|
86 } |
|
87 |
|
88 }//namespace ns3 |
|