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