EMANE  1.2.1
eventgeneratorbuilder.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 - 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"
39 #include "logservice.h"
40 #include "eventservice.h"
41 #include "platformservice.h"
42 #include "timerserviceproxy.h"
43 #include "buildidservice.h"
44 #include "registrarproxy.h"
46 
48 
50 
51 std::unique_ptr<EMANE::Application::EventGeneratorManager>
53  EventGenerators & generators,
54  const ConfigurationUpdateRequest & request)
55 {
56  if(generators.empty())
57  {
58  throw BuildException("Trying to build an EventGeneratorManager without any EventGenerators");
59  }
60 
61  std::unique_ptr<EventGeneratorManager> pManager{new EventGeneratorManagerImpl{uuid}};
62 
64 
65  RegistrarProxy registrarProxy{buildId};
66 
67  pManager->initialize(registrarProxy);
68 
69  pManager->configure(ConfigurationServiceSingleton::instance()->buildUpdates(buildId,request));
70 
71  std::for_each(generators.begin(),
72  generators.end(),
73  [&pManager](std::unique_ptr<EventGenerator> & pGenerator)
74  {
75  pManager->add(pGenerator);
76  });
77 
78  return pManager;
79 }
80 
81 
82 std::unique_ptr<EMANE::EventGenerator>
84  const ConfigurationUpdateRequest& request,
85  bool bSkipConfigure)
86 {
87  std::string sNativeLibraryFile = "lib" +
88  sLibraryFile +
89  ".so";
90 
91  const EMANE::EventGeneratorFactory & eventGeneratorFactory =
93 
94  // new platform service
96  pPlatformService{new EMANE::PlatformService{}};
97 
98  // create generator
99  std::unique_ptr<EMANE::EventGenerator>
100  pGenerator{eventGeneratorFactory.createEventGenerator(pPlatformService)};
101 
102  BuildId buildId{BuildIdServiceSingleton::instance()->registerBuildable(pGenerator.get())};
103 
104  // pass generator to platform service
105  pPlatformService->setPlatformServiceUser(buildId,pGenerator.get());
106 
107  // set the NOPFileDescriptorService (not available to generators)
108  pPlatformService->setFileDescriptorServiceProvider(NOPFileDescriptorService::instance());
109 
110  // register event service user with event service
111  // event generators will get any event they register for
112  // regardless of target nem
114  pGenerator.get(),
115  0);
116 
117  RegistrarProxy registrarProxy{buildId};
118 
119  // initialize
120  pGenerator->initialize(registrarProxy);
121 
122  if(!bSkipConfigure)
123  {
124  // configure
125  pGenerator->configure(ConfigurationServiceSingleton::instance()->buildUpdates(buildId,request));
126  }
127 
128  return pGenerator;
129 }
Factory for creating EventGenerators. The factory manages the DLL allowing for the creation of multip...
std::unique_ptr< EventGeneratorManager > buildEventGeneratorManager(const uuid_t &uuid, EventGenerators &generators, const ConfigurationUpdateRequest &request)
std::list< std::unique_ptr< EventGenerator > > EventGenerators
Exception thrown by builders when constructing and assembling application objects and containers...
platform service
BuildId registerBuildable(Application::NEMManager *pNEMManager)
std::unique_ptr< EventGenerator > buildEventGenerator(const std::string &sLibraryFile, const ConfigurationUpdateRequest &request, bool bSkipConfigure=false)
std::vector< ConfigurationNameStringValues > ConfigurationUpdateRequest
EventGenerator * createEventGenerator(PlatformServiceProvider *pPlatformService) const
void registerEventServiceUser(BuildId buildId, EventServiceUser *pEventServiceUser, NEMId=0)
Definition: eventservice.cc:85
const EventGeneratorFactory & getEventGeneratorFactory(const std::string &sLibraryFile)
static BuildIdService * instance()
Definition: singleton.h:56
std::uint32_t BuildId
Definition: types.h:60