EMANE  1.2.1
transportdirector.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) 2009-2010 - 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 
35 #include "transportdirector.h"
36 #include <sstream>
37 
38 /*
39  * Constructor
40  *
41  * @param filename reference to the base XML filename
42  * @param builder reference to the TransportBuilder
43  */
45  TransportBuilder &builder):
46  transportConfig_(filename),
47  rTransportBuilder_(builder)
48 {}
49 
50 /*
51  * Destructor
52  */
54 {}
55 
56 /*
57  * Constructs the event agent and generators
58  *
59  */
60 std::unique_ptr<EMANE::Application::TransportManager>
62 {
63  /* Now go through configuration of each instance and build appropriately */
64  EMANE::TransportInstanceConfigurations::const_iterator instanceIter =
65  transportConfig_.getInstances().begin();
66 
67  TransportAdapters adapters;
68  for ( ; instanceIter != transportConfig_.getInstances().end(); ++instanceIter)
69  {
70  /* Create the adapter for this transport */
71 
72  auto pTransport = createTransport(*instanceIter);
73 
74  adapters.push_back(rTransportBuilder_.buildTransportAdapter(pTransport,
75  (*instanceIter)->getConfigurationUpdateRequest()));
76  }
77 
78  /* Build TransportManager */
79  return rTransportBuilder_.buildTransportManager(uuid,
80  adapters,
81  transportConfig_.getConfigurationUpdateRequest());
82 }
83 
84 /*
85  * Uses the passed-in builder to create a Transport and return
86  * a pointer to it.
87  *
88  * @param pTIConfig Pointer to the Instance XML configuration
89  *
90  * @exception ConfigureException
91  */
92 std::unique_ptr<EMANE::NEMLayer>
93 EMANE::Application::TransportDirector::createTransport(TransportInstanceConfiguration *pTIConfig)
94 {
95  EMANE::LayerConfigurations::const_iterator transportIter =
96  pTIConfig->getLayers().begin();
97 
98  EMANE::LayerConfiguration *pTransportConfig = (*transportIter);
99 
100  if (pTransportConfig == 0)
101  {
102  std::stringstream excStream;
103  excStream << "Transport inside instance "
104  << pTIConfig->getId() << " is NOT properly configured!"
105  << std::ends;
106  throw ConfigureException(excStream.str());
107  }
108 
109  return rTransportBuilder_.buildTransport(pTIConfig->getId(),
110  pTransportConfig->getLibrary(),
111  pTransportConfig->getConfigurationUpdateRequest());
112 }
Provides default implementation to common layer functionalities.
std::unique_ptr< NEMLayer > buildTransport(NEMId id, const std::string &sLibraryFile, const ConfigurationUpdateRequest &request, bool bSkipConfigure=false) const
std::string getLibrary() const
std::unique_ptr< TransportManager > construct(const uuid_t &uuid)
std::list< std::unique_ptr< TransportAdapter > > TransportAdapters
std::unique_ptr< TransportAdapter > buildTransportAdapter(std::unique_ptr< NEMLayer > &pTransport, const ConfigurationUpdateRequest &request) const
Exception thrown when failures in configuration occur.
TransportDirector(const std::string &filename, TransportBuilder &builder)
const ConfigurationUpdateRequest getConfigurationUpdateRequest()
Provides methods for contructing transports and a manager to contain and control them as a a group...
const TransportInstanceConfigurations & getInstances()
Contains all configuration associated with a TransportInstance.
std::unique_ptr< TransportManager > buildTransportManager(const uuid_t &uuid, TransportAdapters &adapters, const ConfigurationUpdateRequest &request) const