YAMI4 C++ Library 2.0.0
Messaging Solution for Distributed Systems
Loading...
Searching...
No Matches
value_publisher.h
1// Copyright Maciej Sobczak 2008-2022.
2// This file is part of YAMI4.
3// See the package-level LICENSE.txt file.
4
5#ifndef YAMICPP_VALUE_PUBLISHER_H_INCLUDED
6#define YAMICPP_VALUE_PUBLISHER_H_INCLUDED
7
8#include "incoming_message_generic_dispatcher.h"
9#include "value_publisher_overflow_generic_dispatcher.h"
10#include <yami4-core/dll.h>
11
12#include <memory>
13#include <string>
14#include <utility>
15#include <vector>
16
17namespace yami
18{
19
20class agent;
21class incoming_message;
22class serializable;
23
24namespace details
25{
26class value_publisher_impl;
27}
28
36{
37public:
38
44
52
66 template <typename functor>
67 value_publisher(functor & f)
68 {
69 user_command_handler_.reset(
71 init(user_command_handler_.get());
72 }
73
92 template <typename incoming_message_functor,
93 typename queue_overflow_functor>
94 value_publisher(incoming_message_functor & f,
95 std::size_t max_queue_length, queue_overflow_functor & qof)
96 {
97 user_command_handler_.reset(
99 incoming_message_functor>(f));
100 user_overflow_handler_.reset(
102 queue_overflow_functor>(qof));
103 init(user_command_handler_.get(),
104 max_queue_length, user_overflow_handler_.get());
105 }
106
113 void register_at(agent & controlling_agent,
114 const std::string & object_name);
115
118
128 void subscribe(const std::string & destination_target,
129 const std::string & destination_object);
130
134 void unsubscribe(const std::string & destination_target);
135
144 void publish(const serializable & value, std::size_t priority = 0);
145
147 std::size_t get_number_of_subscribers() const;
148
154 std::vector<std::pair<std::string, std::string> >
156
157private:
158
160 void operator=(const value_publisher &);
161
162 void init(details::incoming_message_dispatcher_base * imd = NULL,
163 std::size_t max_queue_length = 1,
165
166 details::value_publisher_impl * pimpl_;
167
168 std::unique_ptr<details::incoming_message_dispatcher_base>
169 user_command_handler_;
170 std::unique_ptr<details::value_publisher_overflow_dispatcher_base>
171 user_overflow_handler_;
172};
173
174} // namespace yami
175
176#endif // YAMICPP_VALUE_PUBLISHER_H_INCLUDED
Message broker.
Definition: agent.h:45
Definition: incoming_message_dispatcher_base.h:20
Definition: incoming_message_generic_dispatcher.h:23
Definition: value_publisher_overflow_dispatcher_base.h:21
Definition: value_publisher_overflow_generic_dispatcher.h:20
Common interface for serializable data source.
Definition: serializable.h:21
Simple subscription publisher.
Definition: value_publisher.h:36
value_publisher(incoming_message_functor &f, std::size_t max_queue_length, queue_overflow_functor &qof)
Constructor.
Definition: value_publisher.h:94
value_publisher()
Constructor.
void publish(const serializable &value, std::size_t priority=0)
Publishes the new value.
void unregister()
Unregisters the publisher from its associated agent.
void unsubscribe(const std::string &destination_target)
Unsubscribes the given listener.
void register_at(agent &controlling_agent, const std::string &object_name)
Registers the publisher at the given agent.
value_publisher(functor &f)
Constructor.
Definition: value_publisher.h:67
~value_publisher()
Destructor.
std::vector< std::pair< std::string, std::string > > get_subscribers() const
Returns the information about all active subscribers.
void subscribe(const std::string &destination_target, const std::string &destination_object)
Subscribes the new listener.
std::size_t get_number_of_subscribers() const
Returns the number of active subscribers.
Namespace devoted to everything related to YAMI4.
Definition: agent.h:21