YAMI4 Core
agent.h
1 // Copyright Maciej Sobczak 2008-2020.
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 YAMICORE_AGENT_H_INCLUDED
18 #define YAMICORE_AGENT_H_INCLUDED
19 
20 #include "allocator.h"
21 #include "channel_descriptor.h"
22 #include "core.h"
23 #include "dll.h"
24 
25 #ifdef YAMI4_WITH_NETX
26 #include <nx_api.h>
27 #endif // YAMI4_WITH_NETX
28 
29 namespace yami
30 {
31 
32 namespace details
33 {
34 class channel_group;
35 } // namespace details
36 
37 namespace core
38 {
39 
40 class parameters;
41 class serializable;
42 
55 class DLL agent
56 {
57 public:
58 
68  agent();
69 
106  result init(
107  incoming_message_dispatch_function dispatch_callback,
108  void * dispatch_hint,
109  closed_connection_function disconnection_hook = NULL,
110  void * disconnection_hook_hint = NULL,
111  void * working_area = NULL, std::size_t area_size = 0);
112 
120  result init(const parameters & configuration_options,
121  incoming_message_dispatch_function dispatch_callback,
122  void * dispatch_hint,
123  closed_connection_function disconnection_hook = NULL,
124  void * disconnection_hook_hint = NULL,
125  void * working_area = NULL, std::size_t area_size = 0);
126 
127 #ifdef YAMI4_WITH_NETX
128  void set_netx_context(NX_IP * ip, NX_PACKET_POOL * packet_pool);
133 #endif // YAMI4_WITH_NETX
134 
143  void install_event_notifications(
144  event_notification_function event_notification_callback,
145  void * event_notification_hint);
146 
155  void install_io_error_logger(
156  io_error_function io_error_callback,
157  void * io_error_callback_hint);
158 
172  void clean();
173 
177  ~agent();
178 
205  result open(const char * target);
206 
222  result open(const char * target, channel_descriptor & cd,
223  bool & created_new_channel);
224 
231  result open(const char * target, channel_descriptor & cd,
232  bool & created_new_channel, const parameters * overriding_options);
233 
244  result is_open(const char * target,
245  channel_descriptor & existing_channel) const;
246 
266  result close(channel_descriptor cd, std::size_t priority = 0);
267 
274  result close(const char * target, std::size_t priority = 0);
275 
287  result hard_close(channel_descriptor cd);
288 
294  result hard_close(const char * target);
295 
331  result post(channel_descriptor cd,
332  const serializable & message_header,
333  const serializable & message_body,
334  std::size_t priority = 0,
335  message_progress_function progress_callback = NULL,
336  void * progress_hint = NULL);
337 
345  result post(const char * target,
346  const serializable & message_header,
347  const serializable & message_body,
348  std::size_t priority = 0,
349  message_progress_function progress_callback = NULL,
350  void * progress_hint = NULL);
351 
387  result add_listener(const char * target,
388  new_incoming_connection_function connection_hook = NULL,
389  void * connection_hook_hint = NULL,
390  const char * * resolved_target = NULL);
391 
402  result remove_listener(const char * target);
403 
433  result do_some_work(std::size_t timeout,
434  bool allow_outgoing_traffic = true,
435  bool allow_incoming_traffic = true);
436 
438  result interrupt_work_waiter();
439 
441  void get_channel_usage(std::size_t & max_allowed, std::size_t & used);
442 
444  result get_pending_outgoing_bytes(
445  channel_descriptor cd, std::size_t & bytes);
446  result get_pending_outgoing_bytes(
447  const char * target, std::size_t & bytes);
448 
449 private:
450 
451  agent(const agent &);
452  void operator=(const agent &);
453 
454  result do_init(const parameters * configuration_options,
456  void * dispatch_hint,
457  core::closed_connection_function disconnection_hook,
458  void * disconnection_hook_hint,
459  void * working_area, std::size_t area_size);
460 
461  bool initialized_;
462 
463  details::allocator alloc_;
464  bool uses_private_area_;
465 
466  details::channel_group * ch_group_;
467 
468  std::size_t max_channels_allowed_;
469  std::size_t channels_used_;
470 };
471 
472 } // namespace core
473 
474 } // namespace yami
475 
476 #endif // YAMICORE_AGENT_H_INCLUDED
Descriptor handle for the physical channel.
Definition: channel_descriptor.h:38
void(* closed_connection_function)(void *hint, const char *name, result reason)
Definition: core.h:103
void(* io_error_function)(void *hint, int error_code, const char *description)
Type of function callback for internal I/O error logging.
Definition: core.h:149
Collection of message parameters.
Definition: parameters.h:91
void(* message_progress_function)(void *hint, std::size_t sent_bytes, std::size_t total_byte_count)
Definition: core.h:121
void(* new_incoming_connection_function)(void *hint, const char *source, std::size_t index, std::size_t sequence_number)
Definition: core.h:90
Message broker.
Definition: agent.h:55
Namespace devoted for everything related to YAMI4.
Definition: agent.h:29
void(* incoming_message_dispatch_function)(void *hint, const char *source, const char *header_buffers[], std::size_t header_buffer_sizes[], std::size_t num_of_header_buffers, const char *body_buffers[], std::size_t body_buffer_sizes[], std::size_t num_of_body_buffers)
Definition: core.h:70
void(* event_notification_function)(void *hint, event_notification e, const char *str, std::size_t size)
Definition: core.h:142
Common interface for serializable data source.
Definition: serializable.h:35
result
General type for reporting success and error states.
Definition: core.h:32