Module.cc
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
17 #include "Module.hh"
18 #include "Module.ih"
19 
20 // Custom includes
21 #include <senf/Utils/algorithm.hh>
22 #include <senf/Utils/String.hh>
23 #include "Events.hh"
24 #include "Connectors.hh"
25 
26 //#include "Module.mpp"
27 #define prefix_
28 //-/////////////////////////////////////////////////////////////////////////////////////////////////
29 
30 //-/////////////////////////////////////////////////////////////////////////////////////////////////
31 // senf::ppi::module::Module
32 
33 //-/////////////////////////////////////////////////////////////////////////////////////////////////
34 // public members
35 
36 #ifdef DOXYGEN
37 
41 {}
44 {}
45 
46 prefix_ senf::ppi::RouteRoute<connector::EventDescriptor, connector::OutputConnector> &
48 
49 #else
50 
51 #define route_impl( Source, Target ) \
52  prefix_ senf::ppi::Route<senf::ppi::Source, senf::ppi::Target> & \
53  senf::ppi::module::Module::route(Source & source, Target & target) \
54  { \
55  detail::RouteHelper<Source,Target>::route(*this, source, target, source, target); \
56  return static_cast< Route<Source,Target> & >( \
57  addRoute(std::unique_ptr< RouteBase >( \
58  new Route<Source,Target>(source, target)))); \
59  }
60 
69 
70 #undef route_impl
71 
72 #endif
73 
74 //-/////////////////////////////////////////////////////////////////////////////////////////////////
75 // private members
76 
77 namespace {
78  template <class T>
79  std::string consoleDirectoryName(T & t) {
80  return senf::prettyBaseName(typeid(t)) + "_" + senf::str(&t);
81  }
82 }
83 
84 prefix_ void senf::ppi::module::Module::registerConnector(connector::Connector & connector)
85 {
86  if (! senf::contains(connectorRegistry_, &connector)) {
87  connectorRegistry_.push_back(&connector);
88  connector.setModule(*this);
89  sysConsoleDir().add( consoleDirectoryName(connector), connector.consoleDir())
90  .doc( senf::prettyName(typeid(connector)) + " " + senf::str(&connector));
91  }
92 }
93 
94 prefix_ void senf::ppi::module::Module::unregisterConnector(connector::Connector & connector)
95 {
96  ConnectorRegistry::iterator i (std::find(connectorRegistry_.begin(), connectorRegistry_.end(),
97  &connector));
98  if (i != connectorRegistry_.end())
99  connectorRegistry_.erase(i);
100 
101  routes_.erase_if(boost::bind(&RouteBase::hasConnector, _1, boost::cref(connector)));
102 }
103 
105 senf::ppi::module::Module::addRoute(std::unique_ptr<RouteBase> route)
106 {
107  routes_.push_back(route.release());
108  return routes_.back();
109 }
110 
111 //-/////////////////////////////////////////////////////////////////////////////////////////////////
112 // protected members
113 
115 {
116  registerConnector(connector);
117  connector.setModule(*this);
118 }
119 
121 {
122  // we can't do this in the constructor,
123  // since we want that typeid returns the type of the most derived complete object.
124  moduleManager().consoleDir()["modules"].add( consoleDirectoryName(*this), sysConsoleDir_)
125  .doc( senf::prettyName(typeid(*this)) + " " + senf::str(this));
126 }
127 
128 //-/////////////////////////////////////////////////////////////////////////////////////////////////
129 #undef prefix_
130 //#include "Module.mpp"
131 
132 
133 // Local Variables:
134 // mode: c++
135 // fill-column: 100
136 // comment-column: 40
137 // c-file-style: "senf"
138 // indent-tabs-mode: nil
139 // ispell-local-dictionary: "american"
140 // compile-command: "scons -u test"
141 // End:
#define prefix_
Definition: Module.cc:27
Connectors public header.
Module public header.
Route< connector::InputConnector, connector::OutputConnector > & route(connector::InputConnector &input, connector::OutputConnector &output)
Define flow information.
Definition: Module.cc:39
Combination of PassiveConnector and OutputConnector.
Definition: Connectors.hh:513
Combination of ActiveConnector and InputConnector.
Definition: Connectors.hh:538
Input connector base-class.
Definition: Connectors.hh:397
void noroute(connector::Connector &connector)
Define terminal connectors.
Definition: Module.cc:114
Output connector base-class.
Definition: Connectors.hh:449
Generic event interface base-class.
Definition: Events.hh:60
Combination of ActiveConnector and OutputConnector.
Definition: Connectors.hh:563
NodeType & add(std::string const &name, boost::shared_ptr< NodeType > node)
console::DirectoryNode & consoleDir() const
Connector base-class.
Definition: Connectors.hh:156
Route descriptor.
Definition: predecl.hh:36
Routing base class.
Definition: Route.hh:34
Combination of PassiveConnector and InputConnector.
Definition: Connectors.hh:478
Events public header.
virtual void v_init()
Called after module setup.
Definition: Module.cc:120
bool hasConnector(connector::Connector const &conn) const
true, if route has connector conn
console::DirectoryNode & sysConsoleDir() const