EMANE  1.0.1
transportbuilder.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2014,2016 - Adjacent Link LLC, Bridgewater,
3  * New Jersey
4  * Copyright (c) 2008-2012 - DRS CenGen, LLC, Columbia, Maryland
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  * * Neither the name of DRS CenGen, LLC nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  */
34 
36 #include "emane/buildexception.h"
37 #include "transportmanagerimpl.h"
38 #include "transportadapterimpl.h"
40 #include "logservice.h"
41 #include "timerserviceproxy.h"
42 #include "eventservice.h"
43 #include "nemplatformservice.h"
44 #include "buildidservice.h"
45 #include "registrarproxy.h"
46 #include "transportlayer.h"
47 #include "nemstatefullayer.h"
48 
50 
52 
53 std::unique_ptr<EMANE::Application::TransportManager>
55  TransportAdapters & adapters,
56  const ConfigurationUpdateRequest& request) const
57 {
58  if(adapters.empty())
59  {
60  throw BuildException("Trying to build a TransportManager without any TransportAdapters");
61  }
62 
63  std::unique_ptr<TransportManager> pManager{new TransportManagerImpl{uuid}};
64 
66 
67  RegistrarProxy registrarProxy{buildId};
68 
69  pManager->initialize(registrarProxy);
70 
71  // configure
72  pManager->configure(ConfigurationServiceSingleton::instance()->buildUpdates(buildId,request));
73 
74  std::for_each(adapters.begin(),
75  adapters.end(),
76  [&pManager](std::unique_ptr<TransportAdapter> & pAdapter)
77  {
78  pManager->add(pAdapter);
79  });
80 
81  return pManager;
82 }
83 
84 
85 std::unique_ptr<EMANE::Application::TransportAdapter>
86 EMANE::Application::TransportBuilder::buildTransportAdapter(std::unique_ptr<NEMLayer> & pTransport,
87  const ConfigurationUpdateRequest& request) const
88 {
89  if(pTransport == NULL)
90  {
91  throw BuildException("Trying to build a TransportAdapter without a Transport");
92  }
93 
94  std::unique_ptr<TransportAdapter> pAdapter{new TransportAdapterImpl{pTransport->getNEMId()}};
95 
97 
98  RegistrarProxy registrarProxy{buildId};
99 
100  pAdapter->initialize(registrarProxy);
101 
102  // configure
103  pAdapter->configure(ConfigurationServiceSingleton::instance()->buildUpdates(buildId,request));
104 
105  pAdapter->setTransport(pTransport);
106 
107  return pAdapter;
108 }
109 
110 
111 std::unique_ptr<EMANE::NEMLayer>
113  const std::string & sLibraryFile,
114  const ConfigurationUpdateRequest & request,
115  bool bSkipConfigure) const
116 {
117  std::string sNativeLibraryFile = "lib" +
118  sLibraryFile +
119  ".so";
120 
121  const TransportFactory & transportLayerFactory =
123 
124  // new platform service
125  NEMPlatformService * pPlatformService{new NEMPlatformService{}};
126 
127  // create plugin
128  Transport * pImpl =
129  transportLayerFactory.createTransport(id, pPlatformService);
130 
131  std::unique_ptr<NEMQueuedLayer> pNEMLayer{new TransportLayer{id,
132  new NEMStatefulLayer{id,
133  pImpl,
134  pPlatformService},
135  pPlatformService}};
136 
137  // register to the component map
140  sLibraryFile)};
141 
143  pNEMLayer.get());
144 
145  // pass nem layer to platform service
146  pPlatformService->setNEMLayer(buildId,
147  pNEMLayer.get());
148 
149 
150  // register event service handler with event service
152  pNEMLayer.get(),
153  id);
154 
155  RegistrarProxy registrarProxy{buildId};
156 
157  // initialize
158  pNEMLayer->initialize(registrarProxy);
159 
160  if(!bSkipConfigure)
161  {
162  pNEMLayer->configure(ConfigurationServiceSingleton::instance()->buildUpdates(buildId,
163  request));
164  }
165 
166  return std::unique_ptr<EMANE::NEMLayer>(pNEMLayer.release());
167 }
168 
169 
171 EMANE::Application::TransportBuilder::newPlatformService() const
172 {
173  return new EMANE::NEMPlatformService{};
174 }
175 
176 
177 std::unique_ptr<EMANE::Application::TransportAdapter>
178 EMANE::Application::TransportBuilder::buildTransportWithAdapter_i(Transport * pTransport,
179  PlatformServiceProvider * pProvider,
180  const ConfigurationUpdateRequest & request,
181  const std::string & sPlatformEndpoint,
182  const std::string & sTransportEndpoint) const
183 {
184  // pass transport to platform service
185  EMANE::NEMPlatformService * pPlatformService{dynamic_cast<EMANE::NEMPlatformService*>(pProvider)};
186 
187  NEMId id{pTransport->getNEMId()};
188 
189  std::unique_ptr<NEMQueuedLayer> pNEMLayer{new TransportLayer{id,
190  new NEMStatefulLayer{id,
191  pTransport,
192  pPlatformService},
193  pPlatformService}};
194 
195  // register to the component map
196 
198 
200  pNEMLayer.get());
201 
202  // pass nem layer to platform service
203  pPlatformService->setNEMLayer(buildId,
204  pNEMLayer.get());
205 
206  // register event service handler with event service
208  pNEMLayer.get(),
209  id);
210 
211  RegistrarProxy registrarProxy{buildId};
212 
213  // initialize
214  pNEMLayer->initialize(registrarProxy);
215 
216  pNEMLayer->configure(ConfigurationServiceSingleton::instance()->buildUpdates(buildId,
217  request));
218  std::unique_ptr<NEMLayer> p{pNEMLayer.release()};
219 
220  auto pTransportAdapter = buildTransportAdapter(p,
221  {
222  {"platformendpoint",{sPlatformEndpoint}},
223  {"transportendpoint",{sTransportEndpoint}}
224  });
225 
226 
227  return pTransportAdapter;
228 }
std::unique_ptr< NEMLayer > buildTransport(NEMId id, const std::string &sLibraryFile, const ConfigurationUpdateRequest &request, bool bSkipConfigure=false) const
Base class for all transports.
Definition: transport.h:49
Manages all instantiated transports.
const TransportFactory & getTransportFactory(const std::string &sLibraryFile)
Implementation of the Transport Adapter interface. Connects a Transport implemenation with its respec...
std::list< std::unique_ptr< TransportAdapter > > TransportAdapters
std::unique_ptr< TransportAdapter > buildTransportAdapter(std::unique_ptr< NEMLayer > &pTransport, const ConfigurationUpdateRequest &request) const
The PlatformServiceProvider interface provides access to emulator services.
Exception thrown by builders when constructing and assembling application objects and containers...
void registerRunningStateMutable(BuildId buildId, RunningStateMutable *pRunningStateMutable)
Transport * createTransport(NEMId nemId, PlatformServiceProvider *pPlatformService) const
BuildId registerBuildable(Application::NEMManager *pNEMManager)
std::uint16_t NEMId
Definition: types.h:52
Bridge for the Transport NEM layer. Decouples a TransportLayerImplementor implementation from the NEM...
Factory for creating Transports. The factory manages the DLL allowing for the creation of multiple tr...
std::vector< ConfigurationNameStringValues > ConfigurationUpdateRequest
void registerEventServiceUser(BuildId buildId, EventServiceUser *pEventServiceUser, NEMId=0)
Definition: eventservice.cc:85
A layer stack that enforces component state transition rules. The stateful layer is not a fully funct...
std::unique_ptr< TransportManager > buildTransportManager(const uuid_t &uuid, TransportAdapters &adapters, const ConfigurationUpdateRequest &request) const
static BuildIdService * instance()
Definition: singleton.h:56
std::uint32_t BuildId
Definition: types.h:60
NEMId getNEMId() const
Definition: transport.h:62
NEM platform service.