EMANE  1.2.1
eventagentmanagerimpl.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2015 - Adjacent Link LLC, Bridgewater, New Jersey
3  * Copyright (c) 2011-2012 - DRS CenGen, LLC, Columbia, Maryland
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in
14  * the documentation and/or other materials provided with the
15  * distribution.
16  * * Neither the name of DRS CenGen, LLC nor the names of its
17  * contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #include "eventagentmanagerimpl.h"
35 #include "logservice.h"
36 #include "eventservice.h"
37 #include "timerservice.h"
38 #include "eventserviceexception.h"
39 
41 #include "emane/startexception.h"
42 
44  EventAgentManager{uuid}{}
45 
47 
48 void EMANE::Application::EventAgentManagerImpl::add(std::unique_ptr<EventAgent> & pAgent)
49 {
50  eventAgents_.push_back(std::move(pAgent));
51 }
52 
54 {
55  auto & configRegistrar = registrar.configurationRegistrar();
56 
57  configRegistrar.registerNonNumeric<INETAddr>("eventservicegroup",
59  {},
60  "IPv4 or IPv6 Event Service channel multicast endpoint.");
61 
62  configRegistrar.registerNonNumeric<std::string>("eventservicedevice",
64  {},
65  "Device to associate with the Event Service channel multicast endpoint.");
66 
67  configRegistrar.registerNumeric<std::uint8_t>("eventservicettl",
69  {1},
70  "Device to associate with the Event Service channel multicast endpoint.");
71 }
72 
74 {
75  for(const auto & item : update)
76  {
77  if(item.first == "eventservicegroup")
78  {
79  eventServiceGroupAddr_ = item.second[0].asINETAddr();
80 
82  INFO_LEVEL,
83  "EventAgentManagerImpl::configure %s: %s",
84  item.first.c_str(),
85  eventServiceGroupAddr_.str().c_str());
86  }
87  else if(item.first == "eventservicedevice")
88  {
89  sEventServiceDevice_ = item.second[0].asString();
90 
92  INFO_LEVEL,
93  "EventAgentManagerImpl::configure %s: %s",
94  item.first.c_str(),
95  sEventServiceDevice_.c_str());
96 
97  }
98  else if(item.first == "eventservicettl")
99  {
100  u8EventServiceTTL_ = item.second[0].asUINT8();
101 
103  INFO_LEVEL,
104  "EventAgentManagerImpl::configure %s: %hhu",
105  item.first.c_str(),
106  u8EventServiceTTL_);
107  }
108  else
109  {
110  throw makeException<ConfigureException>("EventAgentManagerImpl: "
111  "Unexpected configuration item %s",
112  item.first.c_str());
113  }
114  }
115 }
116 
118 {
119  try
120  {
121  EventServiceSingleton::instance()->open(eventServiceGroupAddr_,
122  sEventServiceDevice_,
123  u8EventServiceTTL_,
124  true,
125  uuid_);
126  }
127  catch(EventServiceException & e)
128  {
129  throw StartException(e.what());
130  }
131 
132  std::for_each(eventAgents_.begin(),
133  eventAgents_.end(),
134  std::bind(&Component::start,std::placeholders::_1));
135 }
136 
138 {
139  std::for_each(eventAgents_.begin(),
140  eventAgents_.end(),
141  std::bind(&Component::postStart,std::placeholders::_1));
142 }
143 
145 {
146  std::for_each(eventAgents_.begin(),
147  eventAgents_.end(),
148  std::bind(&Component::stop,std::placeholders::_1));
149 }
150 
152  throw()
153 {
154  std::for_each(eventAgents_.begin(),
155  eventAgents_.end(),
156  std::bind(&Component::destroy,std::placeholders::_1));
157 }
The Registrar interface provides access to all of the emulator registrars.
Definition: registrar.h:50
virtual ConfigurationRegistrar & configurationRegistrar()=0
void registerNonNumeric(const std::string &sName, const ConfigurationProperties &properties=ConfigurationProperties::NONE, const std::initializer_list< T > &values={}, const std::string &sUsage="", std::size_t minOccurs=1, std::size_t maxOccurs=1, const std::string &sRegexPattern={})
void configure(const ConfigurationUpdate &update) override
virtual void postStart()
Definition: component.h:119
virtual void stop()=0
void initialize(Registrar &registrar) override
const char * what() const
Definition: exception.h:62
void open(const INETAddr &eventChannelAddress, const std::string &sDevice, int iTTL, bool loopbackEnable, const uuid_t &uuid)
Definition: eventservice.cc:92
std::string str(bool bWithPort=true) const
Definition: inetaddr.cc:409
Component start exception is used to indicate an exception during transition to the start state...
std::vector< ConfigurationNameAnyValues > ConfigurationUpdate
virtual void destroy()=0
virtual void start()=0
#define LOGGER_STANDARD_LOGGING(logger, level, fmt, args...)
static LogService * instance()
Definition: singleton.h:56
Exception thrown during open/establishment of the event service communication channel.
void add(std::unique_ptr< EventAgent > &pEventAgent) override