Joins.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 "Joins.hh"
18 //#include "Joins.ih"
19 
20 // Custom includes
21 #include <algorithm>
22 #include <boost/bind.hpp>
23 #include <boost/lambda/lambda.hpp>
24 #include <boost/lambda/bind.hpp>
25 
26 //#include "Joins.mpp"
27 #define prefix_
28 //-/////////////////////////////////////////////////////////////////////////////////////////////////
29 
30 //-/////////////////////////////////////////////////////////////////////////////////////////////////
31 // senf::ppi::module::PriorityJoin
32 
34 {
35  noroute(output);
36  output.onRequest(&PriorityJoin::request);
37 }
38 
39 //-/////////////////////////////////////////////////////////////////////////////////////////////////
40 // private members
41 
42 prefix_ void
43 senf::ppi::module::PriorityJoin::connectorSetup(PriorityJoin::ConnectorType & conn,
44  int priority)
45 {
46  noroute(conn);
47  conn.onThrottle(&PriorityJoin::onThrottle);
48  conn.onUnthrottle(&PriorityJoin::onUnthrottle);
49 
50  if (priority < 0) {
51  priority = connectors().size() + priority;
52  if (priority < 0)
53  priority = 0;
54  }
55  if (priority >= int(connectors().size())-1)
56  return;
57 
58  connectors().insert(connectors().begin()+priority, connectors().pop_back().release());
59 }
60 
61 prefix_ void senf::ppi::module::PriorityJoin::request()
62 {
63  using boost::lambda::_1;
64  using boost::lambda::bind;
65  PriorityJoin::ContainerType::iterator i (
66  std::find_if(connectors().begin(), connectors().end(),
68  if (SENF_LIKELY(i != connectors().end()))
69  output((*i)());
70 }
71 
72 prefix_ void senf::ppi::module::PriorityJoin::onThrottle()
73 {
74  if (std::find_if(connectors().begin(), connectors().end(),
76  output.throttle();
77 }
78 
79 prefix_ void senf::ppi::module::PriorityJoin::onUnthrottle()
80 {
82 }
83 
84 //-/////////////////////////////////////////////////////////////////////////////////////////////////
85 #undef prefix_
86 //#include "Joins.mpp"
87 
88 
89 // Local Variables:
90 // mode: c++
91 // fill-column: 100
92 // comment-column: 40
93 // c-file-style: "senf"
94 // indent-tabs-mode: nil
95 // ispell-local-dictionary: "american"
96 // compile-command: "scons -u test"
97 // End:
ConnectorType_ ConnectorType
Type of MultiConnector connector.
#define prefix_
Definition: Joins.cc:27
connector::PassiveOutput output
Definition: Joins.hh:102
Joins public header.
#define SENF_LIKELY(x)
bool throttled() const
true, if peer() is throttled
void noroute(connector::Connector &connector)
Define terminal connectors.
Definition: Module.cc:114
void unthrottle()
Revoke native throttling.
void throttle()
Set native throttling.
void onRequest(Handler handler)
Register I/O event handler.
ContainerType_ & connectors()
Get connector container.