m2etis  0.4
ChannelConfigurationImpl.h
Go to the documentation of this file.
1 /*
2  Copyright (2016) Michael Baer, Daniel Bonrath, All rights reserved.
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15  */
16 
22 #ifndef m2etis_ChannelConfigurationImpl_h
23 #define m2etis_ChannelConfigurationImpl_h
24 
26 
27 namespace m2etis {
28 namespace pubsub {
29 
30  struct ChannelVector {
31  std::vector<ChannelEventInterface *> channels_;
32  };
33 
34  template<ChannelName... ChannelNames>
35  class ChannelManager : public ChannelVector, private ChannelT<ChannelNames>... {
36  public:
37  ChannelManager(const std::string & ip, const uint16_t port, const std::string & known_hostname, const uint16_t known_hostport, PubSubSystemEnvironment * pssi, const std::vector<std::string> & rootList) :
38  ChannelT<ChannelNames>(ip, port, known_hostname, known_hostport, pssi, channels_, rootList)... {
39  }
40 
42  for (size_t i = 0; i < channels_.size(); ++i) {
43  delete channels_[i];
44  }
45  channels_.clear();
46  }
47  };
48 
50  private:
52  CManager channelmanager_;
53 
54  public:
56 
57  ChannelConfigurationImpl(const std::string & ip, const uint16_t port, const std::string & known_hostname, const uint16_t known_hostport, PubSubSystemEnvironment * pssi, const std::vector<std::string> & rootList) :
58  channelmanager_(CManager(ip, port, known_hostname, known_hostport, pssi, rootList)) {
59  }
60 
61  const std::vector<ChannelEventInterface *> & channels() const {
62  return channelmanager_.channels_;
63  }
64 
65  /* data structure to hold the channels which the optimizer creates.
66  As the virtual member functions publish and subscribe of a ChannelInterface
67  operate on parameters of types BasicM2etisMessage<EventType> or
68  BasicDeliverCallbackInterface<EventType>, elements of this data structure have
69  to be downcasted into a BasicChannelInterface<EventType> in order to call publish
70  or subscribe. The downcast is chosen in favor of more clumsy approaches
71  towards covariance (the EventType is special for each ChannelInterface)
72  as described in the following paper:
73  http:// portal.cbpf.br/attachments/CDI/Exemplo1NT.pdf
74  */
75 
76  // Furthermore, by using a downcast the current m2etis architecture does not
77  // have to be changed (open-closed principle).
78  };
79 
80 } /* namespace pubsub */
81 } /* namespace m2etis */
82 #endif
83 
std::vector< ChannelEventInterface * > channels_
const std::vector< ChannelEventInterface * > & channels() const
ChannelManager(const std::string &ip, const uint16_t port, const std::string &known_hostname, const uint16_t known_hostport, PubSubSystemEnvironment *pssi, const std::vector< std::string > &rootList)
ChannelConfigurationImpl(const std::string &ip, const uint16_t port, const std::string &known_hostname, const uint16_t known_hostport, PubSubSystemEnvironment *pssi, const std::vector< std::string > &rootList)