YAMI4 Core Library 2.0.0
Messaging Solution for Distributed Systems
Loading...
Searching...
No Matches
agent.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 YAMICORE_AGENT_H_INCLUDED
6#define YAMICORE_AGENT_H_INCLUDED
7
8#include "allocator.h"
9#include "channel_descriptor.h"
10#include "core.h"
11#include "dll.h"
12
13namespace yami
14{
15
16namespace details
17{
18class channel_group;
19} // namespace details
20
21namespace core
22{
23
24class parameters;
25class serializable;
26
39class DLL agent
40{
41public:
42
53
78 incoming_message_dispatch_function dispatch_callback,
79 void * dispatch_hint,
80 closed_connection_function disconnection_hook = NULL,
81 void * disconnection_hook_hint = NULL,
82 allocator * alloc = NULL);
83
91 result init(const parameters & configuration_options,
92 incoming_message_dispatch_function dispatch_callback,
93 void * dispatch_hint,
94 closed_connection_function disconnection_hook = NULL,
95 void * disconnection_hook_hint = NULL,
96 allocator * alloc = NULL);
97
107 event_notification_function event_notification_callback,
108 void * event_notification_hint);
109
125 frame_acceptor_function frame_acceptor,
126 void * frame_acceptor_hint);
127
137 io_error_function io_error_callback,
138 void * io_error_callback_hint);
139
153 void clean();
154
159
186 result open(const char * target);
187
203 result open(const char * target, channel_descriptor & cd,
204 bool & created_new_channel);
205
212 result open(const char * target, channel_descriptor & cd,
213 bool & created_new_channel, const parameters * overriding_options);
214
226 result is_open(const char * target,
227 channel_descriptor & existing_channel) const;
228
248 result close(channel_descriptor cd, std::size_t priority = 0);
249
256 result close(const char * target, std::size_t priority = 0);
257
270
276 result hard_close(const char * target);
277
314 const serializable & message_header,
315 const serializable & message_body,
316 std::size_t priority = 0,
317 message_progress_function progress_callback = NULL,
318 void * progress_hint = NULL);
319
327 result post(const char * target,
328 const serializable & message_header,
329 const serializable & message_body,
330 std::size_t priority = 0,
331 message_progress_function progress_callback = NULL,
332 void * progress_hint = NULL);
333
369 result add_listener(const char * target,
370 new_incoming_connection_function connection_hook = NULL,
371 void * connection_hook_hint = NULL,
372 const char * * resolved_target = NULL);
373
384 result remove_listener(const char * target);
385
415 result do_some_work(std::size_t timeout,
416 bool allow_outgoing_traffic = true,
417 bool allow_incoming_traffic = true);
418
421
423 void get_channel_usage(std::size_t & max_allowed, std::size_t & used);
424
427 channel_descriptor cd, std::size_t & bytes);
428 result get_pending_outgoing_bytes(
429 const char * target, std::size_t & bytes);
430
431private:
432
433 agent(const agent &);
434 void operator=(const agent &);
435
436 result do_init(const parameters * configuration_options,
437 core::incoming_message_dispatch_function dispatch_callback,
438 void * dispatch_hint,
439 core::closed_connection_function disconnection_hook,
440 void * disconnection_hook_hint,
441 allocator * alloc);
442
443 bool initialized_;
444
445 standard_allocator default_alloc_;
446 allocator * alloc_;
447
448 details::channel_group * ch_group_;
449
450 std::size_t max_channels_allowed_;
451 std::size_t channels_used_;
452};
453
454} // namespace core
455
456} // namespace yami
457
458#endif // YAMICORE_AGENT_H_INCLUDED
Message broker.
Definition: agent.h:40
result open(const char *target, channel_descriptor &cd, bool &created_new_channel, const parameters *overriding_options)
Create new channel for the given target with a set of overriding options.
result post(const char *target, const serializable &message_header, const serializable &message_body, std::size_t priority=0, message_progress_function progress_callback=NULL, void *progress_hint=NULL)
Posts new message for sending.
result open(const char *target, channel_descriptor &cd, bool &created_new_channel)
Create new channel for the given target.
result add_listener(const char *target, new_incoming_connection_function connection_hook=NULL, void *connection_hook_hint=NULL, const char **resolved_target=NULL)
Adds new listener.
result interrupt_work_waiter()
Artificially interrupts the wait state of do_some_work.
result close(const char *target, std::size_t priority=0)
Closes the given channel.
void clean()
Cleanup.
result post(channel_descriptor cd, const serializable &message_header, const serializable &message_body, std::size_t priority=0, message_progress_function progress_callback=NULL, void *progress_hint=NULL)
Posts new message for sending.
result hard_close(const char *target)
Immediately closes the given channel.
void install_io_error_logger(io_error_function io_error_callback, void *io_error_callback_hint)
Installation of I/O error logging callback.
void get_channel_usage(std::size_t &max_allowed, std::size_t &used)
Returns the selector's channel usage counters.
agent()
Constructor.
void install_frame_acceptor(frame_acceptor_function frame_acceptor, void *frame_acceptor_hint)
Installation of frame acceptor callback.
result get_pending_outgoing_bytes(channel_descriptor cd, std::size_t &bytes)
Returns the size of outgoing queue for the given channel.
result remove_listener(const char *target)
Removes existing listener.
result hard_close(channel_descriptor cd)
Immediately closes the given channel.
result is_open(const char *target, channel_descriptor &existing_channel) const
Checks if the given channel is already open.
result open(const char *target)
Creates new channel for the given target.
result init(incoming_message_dispatch_function dispatch_callback, void *dispatch_hint, closed_connection_function disconnection_hook=NULL, void *disconnection_hook_hint=NULL, allocator *alloc=NULL)
Initialization.
result close(channel_descriptor cd, std::size_t priority=0)
Closes the given channel.
void install_event_notifications(event_notification_function event_notification_callback, void *event_notification_hint)
Installation of logging notifications callback.
result do_some_work(std::size_t timeout, bool allow_outgoing_traffic=true, bool allow_incoming_traffic=true)
Performs a portion of I/O or internal management work.
~agent()
Destructor.
result init(const parameters &configuration_options, incoming_message_dispatch_function dispatch_callback, void *dispatch_hint, closed_connection_function disconnection_hook=NULL, void *disconnection_hook_hint=NULL, allocator *alloc=NULL)
Initialization.
Common interface for the custom memory allocator.
Definition: allocator.h:20
Descriptor handle for the physical channel.
Definition: channel_descriptor.h:27
Collection of message parameters.
Definition: parameters.h:83
Common interface for serializable data source.
Definition: serializable.h:24
Standard (malloc/free), default allocator.
Definition: allocator.h:29
result
General type for reporting success and error states.
Definition: core.h:21
Namespace devoted for everything related to YAMI4.
Definition: agent.h:14