61 "EEL Text input file.",
65 configRegistrar.registerNonNumeric<std::string>(
"loader",
75 for(
const auto & item : update)
77 if(item.first ==
"inputfile")
79 for(
const auto & any : item.second)
81 std::string sInputFile = any.asString();
85 "EEL::Generator::start %s: %s",
89 inputFileNameVector_.push_back(sInputFile);
92 else if(item.first ==
"loader")
96 for(
const auto & any : item.second)
98 std::string sLoaderPlugin = any.asString();
100 size_t pos = sLoaderPlugin.find(
':');
102 if(pos != std::string::npos)
104 std::string sEventTypes = sLoaderPlugin.substr(0,pos);
106 size_t pos2 = sLoaderPlugin.find(
':',pos + 1);
108 std::string sLibraryName = sLoaderPlugin.substr(pos + 1,pos2- pos -1);
112 if(pos2 != std::string::npos)
114 std::string sPublishMode = sLoaderPlugin.substr(pos2 + 1);
116 if(sPublishMode ==
"delta")
120 else if(sPublishMode ==
"full")
126 throw makeException<ConfigureException>(
"EEL::Generator: Unkown 'loader' " 128 sPublishMode.c_str());
134 pPluginFactory->construct(
"lib" + sLibraryName +
".so");
136 pluginFactoryList_.push_back(pPluginFactory);
138 std::pair<LoaderPlugin *,EventPublishMode> loaderEntry =
139 std::make_pair(pPluginFactory->createPlugin(),publishMode);
143 pos2 = sLoaderPlugin.find(
',');
145 while(pos2 != std::string::npos)
147 std::string sEventType = sEventTypes.substr(pos1,pos2 - pos1);
149 eventPluginMap_.insert(std::make_pair(sEventType,loaderEntry));
153 "EEL::Generator::configure %s: plugin %s will load %s sentences mode:%s",
155 sLoaderPlugin.c_str(),
157 publishMode ==
DELTA ?
"delta" :
"full");
160 pos2 = sEventTypes.find(
',',pos1);
163 std::string sEventType = sEventTypes.substr(pos1);
165 eventPluginMap_.insert(std::make_pair(sEventType,loaderEntry));
169 "EEL::Generator::configure %s: plugin %s will load %s sentences mode:%s",
171 sLoaderPlugin.c_str(),
173 publishMode ==
DELTA ?
"delta" :
"full");
177 throw makeException<ConfigureException>(
"EEL::Generator: Bad configuration 'loader' " 179 sLoaderPlugin.c_str());
185 throw makeException<ConfigureException>(
"EEL::Generator: Factory exception %s",
191 throw makeException<ConfigureException>(
"EEL::Generator: " 192 "Unexpected configuration item %s",
200 thread_ = std::thread{&Generator::generate,
this};
205 if(thread_.joinable())
219 void EMANE::Generators::EEL::Generator::generate()
222 float fCurrentTime = 0;
223 float fEventTime = 0;
224 unsigned long ulCurrentLine = 1;
226 InputFileNameVector::const_iterator iterFileName = inputFileNameVector_.begin();
230 auto testStartTime = Clock::now();
232 for(; iterFileName != inputFileNameVector_.end(); ++iterFileName)
234 std::ifstream eelInputStream;
236 eelInputStream.open(iterFileName->c_str());
240 std::stringstream sstream;
241 sstream<<
"EEL::Generator: Unable to open "<<*iterFileName<<std::ends;
248 "EEL::Generator: Parsing %s",
249 iterFileName->c_str());
255 while(eelInputStream.getline(buf,
sizeof(buf)))
257 std::string sEventType;
258 std::string sModuleId;
263 if(parser.
parse(std::string(buf),
271 size_t pos = sModuleId.find(
':');
273 if(pos != std::string::npos)
275 sModuleType = sModuleId.substr(0,pos);
281 if(fEventTime != fCurrentTime)
283 if(!waitAndSendEvents(testStartTime,fCurrentTime))
288 fCurrentTime = fEventTime;
291 EventPluginMap::iterator iterPlugin;
293 if((iterPlugin = eventPluginMap_.find(sEventType)) !=
294 eventPluginMap_.end())
298 "Registered EEL event type '%s' at time %f for %s",
303 iterPlugin->second.first->load(sModuleType,
312 "Unregistered EEL event type '%s' at time %f for %s",
323 waitAndSendEvents(testStartTime,fCurrentTime);
331 iterFileName->c_str(),
336 bool EMANE::Generators::EEL::Generator::waitAndSendEvents(
const TimePoint & testStartTime,
341 EventPluginMap::iterator iterPlugin = eventPluginMap_.begin();
343 for(;iterPlugin != eventPluginMap_.end(); ++iterPlugin)
346 iterPlugin->second.first->getEvents(iterPlugin->second.second);
348 currentTimeEventList.insert(currentTimeEventList.end(),
355 if(!currentTimeEventList.empty())
357 std::unique_lock<std::mutex> lock{mutex_};
359 std::cv_status status{};
361 while(!bCancel_ && status != std::cv_status::timeout)
363 status = cond_.wait_until(lock,
377 "Sending all events for time %f",
380 EventInfoList::iterator eventIter =
381 currentTimeEventList.begin();
383 for(; eventIter != currentTimeEventList.end(); ++eventIter)
386 eventIter->getEventId(),
387 eventIter->getSerialization());
The Registrar interface provides access to all of the emulator registrars.
std::vector< std::string > InputArguments
Factory for creating plugins . The factory manages the DLL allowing for the creation of plugins of th...
virtual ConfigurationRegistrar & configurationRegistrar()=0
#define LOGGER_VERBOSE_LOGGING(logger, level, fmt, args...)
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={})
Exception base class that allows for type and description information.
Base class for all event generators.
const char * what() const
Exception thrown during the creation of a layer factory.
std::chrono::duration< double > DoubleSeconds
Generator(PlatformServiceProvider *pPlatformService)
std::vector< ConfigurationNameAnyValues > ConfigurationUpdate
Clock::time_point TimePoint
void configure(const ConfigurationUpdate &update) override
#define LOGGER_STANDARD_LOGGING(logger, level, fmt, args...)
std::list< EventInfo > EventInfoList
virtual void sendEvent(NEMId nemId, const Event &event)=0
Parameter conversion class with range checks.
DECLARE_EVENT_GENERATOR(EMANE::Generators::EEL::Generator)
void initialize(Registrar ®istrar) override