YAMI4 C++
value_publisher_impl.h
1 // Copyright Maciej Sobczak 2008-2019.
2 // This file is part of YAMI4.
3 //
4 // YAMI4 is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // YAMI4 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
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with YAMI4. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef YAMICPP_VALUE_PUBLISHER_IMPL_H_INCLUDED
18 #define YAMICPP_VALUE_PUBLISHER_IMPL_H_INCLUDED
19 
20 // selected per platform
21 #include <mutex.h>
22 
23 #include <deque>
24 #include <map>
25 #include <memory>
26 #include <string>
27 #include <utility>
28 #include <vector>
29 
30 namespace yami
31 {
32 
33 class agent;
34 class incoming_message;
35 class outgoing_message;
36 class serializable;
37 class value_publisher;
38 
39 namespace details
40 {
41 
42 class incoming_message_dispatcher_base;
43 class value_publisher_overflow_dispatcher_base;
44 
45 class value_publisher_impl
46 {
47 public:
48 
49  value_publisher_impl(
50  incoming_message_dispatcher_base * imd,
51  std::size_t max_queue_length,
52  value_publisher_overflow_dispatcher_base * qod);
53  ~value_publisher_impl();
54 
55  void register_at(agent & controlling_agent,
56  const std::string & object_name);
57 
58  void unregister();
59 
60  void operator()(incoming_message & message);
61 
62  void subscribe(const std::string & destination_target,
63  const std::string & destination_object);
64 
65  void unsubscribe(const std::string & destination_target);
66 
67  void publish(const serializable & value, std::size_t priority);
68 
69  std::size_t get_number_of_subscribers() const;
70 
71  std::vector<std::pair<std::string, std::string> >
72  get_subscribers() const;
73 
74 private:
75 
76  value_publisher_impl(const value_publisher_impl &);
77  void operator=(const value_publisher_impl &);
78 
79  std::size_t max_queue_length_;
80 
81  // destination target ->
82  // {destination object, previously sent message (or NULL)}
83  typedef std::map<std::string,
84  std::pair<std::string,
85  std::deque<outgoing_message *> > >
86  subscriptions_map_type;
87 
88  void do_unsubscribe(subscriptions_map_type::iterator it);
89  void release_last_messages(subscriptions_map_type::iterator it);
90 
91  incoming_message_dispatcher_base * incoming_message_dispatcher_;
92  value_publisher_overflow_dispatcher_base * overflow_dispatcher_;
93 
94  agent * controlling_agent_;
95  std::string object_name_;
96 
97  subscriptions_map_type subscriptions_;
98  mutable details::mutex mtx_;
99 };
100 
101 } // namespace details
102 
103 } // namespace yami
104 
105 #endif // YAMICPP_VALUE_PUBLISHER_IMPL_H_INCLUDED
Namespace devoted to everything related to YAMI4.
Definition: activity_statistics_monitor.cpp:27