EMANE  1.2.1
buildidservice.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 - Adjacent Link LLC, Bridgewater, New Jersey
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * * Neither the name of Adjacent Link LLC nor the names of its
16  * contributors may be used to endorse or promote products derived
17  * from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #include "buildidservice.h"
34 #include "emane/buildexception.h"
35 
37  buildId_{},
38  nemManagerBuildId_{},
39  transportManagerBuildId_{},
40  eventGeneratorManagerBuildId_{},
41  eventAgentManagerBuildId_{}{}
42 
43 
45 EMANE::BuildIdService::assignBuildId(Buildable *pBuildable)
46 {
47  ++buildId_;
48  pBuildable->setBuildId(buildId_);
49  return buildId_;
50 }
51 
53 {
54  if(!nemManagerBuildId_)
55  {
56  nemManagerBuildId_ = assignBuildId(pNEMManager);
57  }
58  else
59  {
60  throw BuildException("NEM Manager already registered");
61  }
62 
63  return nemManagerBuildId_;
64 }
65 
66 EMANE::BuildId EMANE::BuildIdService::registerBuildable(NEMLayer * pLayer, ComponentType type,const std::string & sPluginName)
67 {
68  auto iter = NEMLayerComponentBuildIdMap_.find(pLayer->getNEMId());
69 
70  BuildId buildId{assignBuildId(pLayer)};
71 
72  if(iter != NEMLayerComponentBuildIdMap_.end())
73  {
74  iter->second.push_back(std::make_tuple(buildId,type,sPluginName));
75  }
76  else
77  {
78  NEMLayerComponentBuildIdMap_.insert(std::make_pair(pLayer->getNEMId(),
79  std::vector<std::tuple<BuildId,ComponentType,std::string>>{std::make_tuple(buildId,type,sPluginName)}));
80  }
81 
82  return buildId;
83 }
84 
86 {
87  if(!transportManagerBuildId_)
88  {
89  transportManagerBuildId_ = assignBuildId(pTransportManager);
90  }
91  else
92  {
93  throw BuildException("Transport Manager already registered");
94  }
95 
96  return transportManagerBuildId_;
97 }
98 
100 {
101  BuildId buildId{assignBuildId(pTransport)};
102 
103  NEMTransportBuildIdMap_.insert(std::make_pair(pTransport->getNEMId(),buildId));
104 
105  return buildId;
106 }
107 
109 {
110  BuildId buildId{assignBuildId(pNEM)};
111 
112  NEMBuildIdMap_.insert(std::make_pair(pNEM->getNEMId(),buildId));
113 
114  return buildId;
115 }
116 
118 {
119  BuildId buildId{assignBuildId(pTransportAdapter)};
120 
121  NEMTransportAdapterBuildIdMap_.insert(std::make_pair(pTransportAdapter->getNEMId(),
122  buildId));
123  return buildId;
124 }
125 
127 {
128  if(!eventGeneratorManagerBuildId_)
129  {
130  eventGeneratorManagerBuildId_ = assignBuildId(pEventGeneratorManager);
131  }
132  else
133  {
134  throw BuildException("Event Generator Manager already registered");
135  }
136 
137  return eventGeneratorManagerBuildId_;
138 }
139 
141 {
142  BuildId buildId{assignBuildId(pGenerator)};
143 
144  eventGeneratorBuildIds_.push_back(buildId);
145 
146  return buildId;
147 }
148 
150 {
151  if(!eventAgentManagerBuildId_)
152  {
153  eventAgentManagerBuildId_ = assignBuildId(pEventAgentManager);
154  }
155  else
156  {
157  throw BuildException("Event Agent Manager already registered");
158  }
159 
160  return eventAgentManagerBuildId_;
161 }
162 
164 {
165  BuildId buildId{assignBuildId(pEventAgent)};
166 
167  eventAgentBuildIds_.push_back(buildId);
168 
169  return buildId;
170 }
171 
173 {
174  return NEMLayerComponentBuildIdMap_;
175 }
176 
177 // EMANE::BuildId EMANE::BuildIdService::getNEMManagerBuildId()
178 // {
179 // return pNEMManager_->getBuildId();
180 // }
181 
182 // std::vector<std::pair<EMANE::BuildId,EMANE::NEMId>> EMANE::BuildIdService::getNEMBuildIds() const
183 // {
184 
185 // }
186 
187 // EMANE::BuildId
188 // EMANE::BuildIdService::getNEMLayerBuildId(NEMId nemId, ComponentType type) const
189 // {
190 // }
191 
192 // std::vector<std::pair<EMANE::BuildId,EMANE::ComponentType>>
193 // EMANE::BuildIdService::getNEMLayerBuildIds(NEMId nemId)
194 // {
195 // }
196 
197 // EMANE::BuildId EMANE::BuildIdService::getTransportManagerBuildId() const
198 // {
199 // return pTransportManager_->getBuildId();
200 // }
201 
202 // EMANE::BuildId EMANE::BuildIdService::getTransportBuildId(NEMId nemId) const
203 // {
204 // const auto iter = NEMTransportMap_.find(nemId);
205 
206 // if(iter != NEMTransportMap_.end())
207 // {
208 // return iter->second->getBuildId();
209 // }
210 // else
211 // {
212 // return 0;
213 // }
214 // }
215 
216 // std::vector<EMANE::BuildId> EMANE::BuildIdService::getTransportBuildIds() const
217 // {
218 // std::vector<EMANE::BuildId> ids;
219 // std::transform(NEMTransportMap_.begin(),
220 // NEMTransportMap_.end(),
221 // back_inserter(ids),
222 // std::bind(&Buildable::getBuildId,
223 // std::bind(&NEMTransportMap::value_type::second,
224 // std::placeholders::_1)));
225 // }
226 
227 // EMANE::BuildId EMANE::BuildIdService::getEventGeneratorManagerBuildId() const
228 // {
229 // return pEventGeneratorManager_->getBuildId();
230 // }
231 
232 // std::vector<EMANE::BuildId> EMANE::BuildIdService::getEventGeneratorBuildIds() const
233 // {
234 // std::vector<EMANE::BuildId> ids;
235 // std::transform(eventGenerators_.begin(),
236 // eventGenerators_.end(),
237 // back_inserter(ids),
238 // std::bind(&Buildable::getBuildId,
239 // std::placeholders::_1));
240 // }
241 
242 // EMANE::BuildId EMANE::BuildIdService::getEventAgentManagerBuildId() const
243 // {
244 // return pEventAgentManager_->getBuildId();
245 // }
246 
247 // std::vector<EMANE::BuildId> EMANE::BuildIdService::getEventAgentBuildIds() const
248 // {
249 // std::vector<EMANE::BuildId> ids;
250 // std::transform(eventAgents_.begin(),
251 // eventAgents_.end(),
252 // back_inserter(ids),
253 // std::bind(&Buildable::getBuildId,
254 // std::placeholders::_1));
255 // }
std::map< NEMId, std::vector< std::tuple< BuildId, ComponentType, std::string > >> NEMLayerComponentBuildIdMap
Network emulation module container interface. A container for NEM component layers connected to a tra...
Definition: nem.h:53
Base class for all transports.
Definition: transport.h:49
virtual NEMId getNEMId() const =0
Base class for NEMLayer containers. Builders construct NEMLayer objects to contain derived instances ...
Definition: nemlayer.h:57
const NEMLayerComponentBuildIdMap & getNEMLayerComponentBuildIdMap() const
Exception thrown by builders when constructing and assembling application objects and containers...
Base class for all event generators.
NEMId getNEMId() const
Definition: nemlayer.h:72
Contains and manages NEM instances.
Definition: nemmanager.h:54
A interface to mark objects with a unique application wide build Id. Builders manipulate buildable ob...
Definition: buildable.h:49
Base class for all event agents.
Definition: eventagent.h:52
BuildId registerBuildable(Application::NEMManager *pNEMManager)
void setBuildId(BuildId bid)
Definition: buildable.inl:40
Transport Adapter interface. A Transport Adapter combines with a Transport to connect with its respec...
Manages all instantiated transports.
Deployment event server interface.
std::uint32_t BuildId
Definition: types.h:60
NEMId getNEMId() const
Definition: transport.h:62