INET Framework for OMNeT++/OMNEST
inet::DelegateSignalConfigurator Class Reference

This is a 3-in-1 class: More...

#include <DelegateSignalConfigurator.h>

Inheritance diagram for inet::DelegateSignalConfigurator:

Classes

class  DelegatingListener
 
class  FigureRecorder
 

Protected Member Functions

virtual void initialize () override
 
virtual void configure (cModule *module)
 
virtual void configureDisplaySignal (cModule *module, cProperty *property)
 
virtual void configureDelegateSignal (cModule *module, cProperty *property)
 
virtual void parseSignalPath (const char *signalPath, cModule *context, cModule *&module, simsignal_t &signal)
 
virtual void refreshDisplay () const override
 

Protected Attributes

std::vector< IIndicatorFigure * > indicatorFigures
 

Detailed Description

This is a 3-in-1 class:

  1. implements the properties
  2. implements the properties (not used)
  3. invokes refreshDisplay() methods on IMeterFigures

Probably none of the above will be needed in OMNeT++ 5.1, so this class can go away then.

Member Function Documentation

void inet::DelegateSignalConfigurator::configure ( cModule *  module)
protectedvirtual

Referenced by initialize().

30 {
31  cProperties *properties = module->getProperties();
32  for (int i = 0; i < properties->getNumProperties(); i++)
33  if (!strcmp(properties->get(i)->getName(), "displaysignal"))
34  configureDisplaySignal(module, properties->get(i));
35  else if (!strcmp(properties->get(i)->getName(), "delegatesignal"))
36  configureDelegateSignal(module, properties->get(i));
37 
38 
39  for (cModule::SubmoduleIterator it(module); !it.end(); ++it)
40  configure(*it);
41 }
virtual void configure(cModule *module)
Definition: DelegateSignalConfigurator.cc:29
virtual void configureDelegateSignal(cModule *module, cProperty *property)
Definition: DelegateSignalConfigurator.cc:90
virtual void configureDisplaySignal(cModule *module, cProperty *property)
Definition: DelegateSignalConfigurator.cc:43
void inet::DelegateSignalConfigurator::configureDelegateSignal ( cModule *  module,
cProperty *  property 
)
protectedvirtual

Referenced by configure().

91 {
92  try {
93  EV_DETAIL << "Processing @" << property->getFullName() << " on " << module->getFullPath() << endl;
94 
95  // parse signals
96  cModule *sourceModule, *targetModule;
97  simsignal_t sourceSignal, targetSignal;
98  parseSignalPath(property->getValue("source"), module, sourceModule, sourceSignal);
99  parseSignalPath(property->getValue("target"), module, targetModule, targetSignal);
100 
101  // add delegatingListener
102  cIListener *listener = new DelegatingListener(targetModule, targetSignal);
103  sourceModule->subscribe(sourceSignal, listener);
104  }
105  catch (std::exception& e) {
106  throw cRuntimeError("While processing @%s on %s: %s", property->getFullName(), module->getFullPath().c_str(), e.what());
107  }
108 }
virtual void parseSignalPath(const char *signalPath, cModule *context, cModule *&module, simsignal_t &signal)
Definition: DelegateSignalConfigurator.cc:110
const value< double, units::C > e(1.602176487e-19)
void inet::DelegateSignalConfigurator::configureDisplaySignal ( cModule *  module,
cProperty *  property 
)
protectedvirtual

Referenced by configure().

44 {
45  try {
46  EV_DETAIL << "Processing @" << property->getFullName() << " on " << module->getFullPath() << endl;
47 
48  // find source signal
49  cModule *sourceModule;
50  simsignal_t signal;
51  parseSignalPath(property->getValue("source"), module, sourceModule, signal);
52 
53  // instantiate filter
54  cResultFilter *filter = nullptr;
55  if (const char *filterName = property->getValue("filter")) {
56  filter = cResultFilterType::get(filterName)->create();
57  }
58 
59  // find figure
60  const char *figurePath = property->getValue("figure");
61  if (!figurePath)
62  figurePath = property->getIndex();
63  cFigure *figure = module->getCanvas()->getFigureByPath(figurePath);
64  if (!figure)
65  throw cRuntimeError("Figure '%s' not found", figurePath);
66  IIndicatorFigure *meterFigure = check_and_cast<IIndicatorFigure *>(figure);
67  indicatorFigures.push_back(meterFigure);
68 
69  // instantiate figure recorder
70  const char *seriesAttr = property->getValue("series");
71  int series = seriesAttr ? utils::atoul(seriesAttr) : 0;
72  if (series > meterFigure->getNumSeries())
73  throw cRuntimeError("series=%d is out of bounds, figure supports %d series", series, meterFigure->getNumSeries());
74  FigureRecorder *figureRecorder = new FigureRecorder(meterFigure, series);
75  figureRecorder->init(module, nullptr, nullptr, property);
76 
77  // hook it up on the signal
78  cResultListener *listener = figureRecorder;
79  if (filter) {
80  filter->addDelegate(figureRecorder);
81  listener = filter;
82  }
83  sourceModule->subscribe(signal, listener);
84  }
85  catch (std::exception& e) {
86  throw cRuntimeError("While processing @%s on %s: %s", property->getFullName(), module->getFullPath().c_str(), e.what());
87  }
88 }
std::vector< IIndicatorFigure * > indicatorFigures
Definition: DelegateSignalConfigurator.h:65
virtual void parseSignalPath(const char *signalPath, cModule *context, cModule *&module, simsignal_t &signal)
Definition: DelegateSignalConfigurator.cc:110
unsigned long atoul(const char *s)
Converts string to unsigned long.
Definition: INETUtils.cc:47
const value< double, units::C > e(1.602176487e-19)
void inet::DelegateSignalConfigurator::initialize ( )
overrideprotectedvirtual
25 {
26  configure(getSystemModule());
27 }
virtual void configure(cModule *module)
Definition: DelegateSignalConfigurator.cc:29
void inet::DelegateSignalConfigurator::parseSignalPath ( const char *  signalPath,
cModule *  context,
cModule *&  module,
simsignal_t &  signal 
)
protectedvirtual

Referenced by configureDelegateSignal(), and configureDisplaySignal().

111 {
112  const char *signalName;
113  if (strchr(signalPath, '.') == nullptr) {
114  module = context;
115  signalName = signalPath;
116  }
117  else {
118  const char *lastDot = strrchr(signalPath, '.');
119  std::string modulePath = std::string(".") + std::string(signalPath, lastDot - signalPath);
120  module = context->getModuleByPath(modulePath.c_str());
121  if (!module)
122  throw cRuntimeError("Module '%s' not found", modulePath.c_str());
123  signalName = lastDot + 1;
124  }
125  signal = registerSignal(signalName);
126 }
void inet::DelegateSignalConfigurator::refreshDisplay ( ) const
overrideprotectedvirtual
129 {
130  for (IIndicatorFigure *figure : indicatorFigures)
131  figure->refreshDisplay();
132 }
std::vector< IIndicatorFigure * > indicatorFigures
Definition: DelegateSignalConfigurator.h:65

Member Data Documentation

std::vector<IIndicatorFigure *> inet::DelegateSignalConfigurator::indicatorFigures
protected

The documentation for this class was generated from the following files: