EMANE  1.2.1
eventgeneratormanagerimpl.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  */
34 #include "logservice.h"
35 #include "eventservice.h"
36 #include "timerservice.h"
37 #include "eventserviceexception.h"
38 
40 #include "emane/startexception.h"
41 
43  EventGeneratorManager{uuid}{}
44 
46 
47 void EMANE::Application::EventGeneratorManagerImpl::add(std::unique_ptr<EventGenerator> & pGenerator)
48 {
49  eventGenerators_.push_back(std::move(pGenerator));
50 }
51 
53 {
54  auto & configRegistrar = registrar.configurationRegistrar();
55 
56  configRegistrar.registerNonNumeric<INETAddr>("eventservicegroup",
58  {},
59  "IPv4 or IPv6 Event Service channel multicast endpoint.");
60 
61  configRegistrar.registerNonNumeric<std::string>("eventservicedevice",
63  {},
64  "Device to associate with the Event Service channel multicast endpoint.");
65 
66  configRegistrar.registerNumeric<std::uint8_t>("eventservicettl",
68  {1},
69  "Device to associate with the Event Service channel multicast endpoint.");
70 }
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  "EventGeneratorManagerImpl::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  "EventGeneratorManagerImpl::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  "EventGeneratorManagerImpl::configure %s: %hhu",
105  item.first.c_str(),
106  u8EventServiceTTL_);
107  }
108  else
109  {
110  throw makeException<ConfigureException>("EventGeneratorManagerImpl: "
111  "Unexpected configuration item %s",
112  item.first.c_str());
113  }
114  }
115 
116 }
117 
119 {
120  try
121  {
122  EventServiceSingleton::instance()->open(eventServiceGroupAddr_,
123  sEventServiceDevice_,
124  u8EventServiceTTL_,
125  true,
126  uuid_);
127  }
128  catch(EventServiceException & e)
129  {
130  throw StartException(e.what());
131  }
132 
133  std::for_each(eventGenerators_.begin(),
134  eventGenerators_.end(),
135  std::bind(&Component::start,std::placeholders::_1));
136 }
137 
139 {
140  std::for_each(eventGenerators_.begin(),
141  eventGenerators_.end(),
142  std::bind(&Component::postStart,std::placeholders::_1));
143 }
144 
146 {
147  std::for_each(eventGenerators_.begin(),
148  eventGenerators_.end(),
149  std::bind(&Component::stop,std::placeholders::_1));
150 }
151 
153  throw()
154 {
155  std::for_each(eventGenerators_.begin(),
156  eventGenerators_.end(),
157  std::bind(&Component::destroy,std::placeholders::_1));
158 }
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 add(std::unique_ptr< EventGenerator > &pEventGenerator) override
virtual void postStart()
Definition: component.h:119
virtual void stop()=0
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
Deployment event server interface.
virtual void start()=0
#define LOGGER_STANDARD_LOGGING(logger, level, fmt, args...)
void configure(const ConfigurationUpdate &update) override
static LogService * instance()
Definition: singleton.h:56
Exception thrown during open/establishment of the event service communication channel.