libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
msg_processor_impl.hpp
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright © 2015 by J.M.McGuiness, coder@hussar.me.uk
3 **
4 ** This library is free software; you can redistribute it and/or
5 ** modify it under the terms of the GNU Lesser General Public
6 ** License as published by the Free Software Foundation; either
7 ** version 2.1 of the License, or (at your option) any later version.
8 **
9 ** This library is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ** Lesser General Public License for more details.
13 **
14 ** You should have received a copy of the GNU Lesser General Public
15 ** License along with this library; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 
19 namespace jmmcg { namespace LIBJMMCG_VER_NAMESPACE { namespace socket {
20 
21 template<class ProcessingRules> inline
22 msg_processor<ProcessingRules>::msg_processor(proc_rules_t const &proc_rules)
23 : processing_rules(proc_rules) {
24 }
25 
26 template<class ProcessingRules>
27 template<class SktT>
28 inline bool
29 msg_processor<ProcessingRules>::read_msg_into_buff(SktT &src_skt, msg_buffer_t &buff) noexcept(false) {
30  return src_skt.template read<msg_details_t>(buff);
31 }
32 
33 template<class ProcessingRules>
34 template<class SktT, class LatencyTimestamps>
35 inline typename std::enable_if<std::is_class<typename LatencyTimestamps::period>::value, bool>::type
36 msg_processor<ProcessingRules>::read_and_process_a_msg(SktT &src_skt, SktT &dest_skt, LatencyTimestamps &ts) noexcept(false) {
37  ALIGN_TO_L1_CACHE msg_buffer_t buff;
38  if (!read_msg_into_buff(src_skt, buff)) {
39  const typename LatencyTimestamps::period t(ts);
40  return processing_rules.process_msg(buff, src_skt, dest_skt);
41  } else {
42  return true;
43  }
44 }
45 
46 template<class ProcessingRules>
47 template<class SktT, class ClientCxn, class LatencyTimestamps>
48 inline typename std::enable_if<std::is_class<typename LatencyTimestamps::period>::value, bool>::type
49 msg_processor<ProcessingRules>::read_and_process_a_msg(SktT &src_skt, ClientCxn &dest_cxn, LatencyTimestamps &ts) noexcept(false) {
50  ALIGN_TO_L1_CACHE msg_buffer_t buff;
51  if (!read_msg_into_buff(src_skt, buff)) {
52  const typename LatencyTimestamps::period t(ts);
53  return processing_rules.process_msg(buff, src_skt, dest_cxn);
54  } else {
55  return true;
56  }
57 }
58 
59 template<class ProcessingRules> inline std::string
60 msg_processor<ProcessingRules>::to_string() const noexcept(false) {
61  std::ostringstream ss;
62  ss
63  <<ppd::api_threading_traits<ppd::platform_api, ppd::sequential_mode>::demangle_name(typeid(*this))
64  <<",\nprocessing_rules: "<<processing_rules;
65  return ss.str();
66 }
67 
68 template<class ProcessingRules> inline std::ostream &
69 operator<<(std::ostream &os, msg_processor<ProcessingRules> const &ec) noexcept(false) {
70  os<<ec.to_string();
71  return os;
72 }
73 
74 } } }