YAMI4 Core
agent.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 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 namespace yami
26 {
27 
28 namespace details
29 {
30 class channel_group;
31 } // namespace details
32 
33 namespace core
34 {
35 
36 class parameters;
37 class serializable;
38 
51 class DLL agent
52 {
53 public:
54 
64  agent();
65 
102  result init(
103  incoming_message_dispatch_function dispatch_callback,
104  void * dispatch_hint,
105  closed_connection_function disconnection_hook = NULL,
106  void * disconnection_hook_hint = NULL,
107  void * working_area = NULL, std::size_t area_size = 0);
108 
116  result init(const parameters & configuration_options,
117  incoming_message_dispatch_function dispatch_callback,
118  void * dispatch_hint,
119  closed_connection_function disconnection_hook = NULL,
120  void * disconnection_hook_hint = NULL,
121  void * working_area = NULL, std::size_t area_size = 0);
122 
131  void install_event_notifications(
132  event_notification_function event_notification_callback,
133  void * event_notification_hint);
134 
143  void install_io_error_logger(
144  io_error_function io_error_callback,
145  void * io_error_callback_hint);
146 
160  void clean();
161 
165  ~agent();
166 
193  result open(const char * target);
194 
210  result open(const char * target, channel_descriptor & cd,
211  bool & created_new_channel);
212 
219  result open(const char * target, channel_descriptor & cd,
220  bool & created_new_channel, const parameters * overriding_options);
221 
232  result is_open(const char * target,
233  channel_descriptor & existing_channel) const;
234 
254  result close(channel_descriptor cd, std::size_t priority = 0);
255 
262  result close(const char * target, std::size_t priority = 0);
263 
275  result hard_close(channel_descriptor cd);
276 
282  result hard_close(const char * target);
283 
319  result post(channel_descriptor cd,
320  const serializable & message_header,
321  const serializable & message_body,
322  std::size_t priority = 0,
323  message_progress_function progress_callback = NULL,
324  void * progress_hint = NULL);
325 
333  result post(const char * target,
334  const serializable & message_header,
335  const serializable & message_body,
336  std::size_t priority = 0,
337  message_progress_function progress_callback = NULL,
338  void * progress_hint = NULL);
339 
375  result add_listener(const char * target,
376  new_incoming_connection_function connection_hook = NULL,
377  void * connection_hook_hint = NULL,
378  const char * * resolved_target = NULL);
379 
390  result remove_listener(const char * target);
391 
421  result do_some_work(std::size_t timeout,
422  bool allow_outgoing_traffic = true,
423  bool allow_incoming_traffic = true);
424 
426  result interrupt_work_waiter();
427 
429  void get_channel_usage(int & max_allowed, int & used);
430 
432  result get_pending_outgoing_bytes(
433  channel_descriptor cd, std::size_t & bytes);
434  result get_pending_outgoing_bytes(
435  const char * target, std::size_t & bytes);
436 
437 private:
438 
439  agent(const agent &);
440  void operator=(const agent &);
441 
442  result do_init(const parameters * configuration_options,
444  void * dispatch_hint,
445  core::closed_connection_function disconnection_hook,
446  void * disconnection_hook_hint,
447  void * working_area, std::size_t area_size);
448 
449  bool initialized_;
450 
451  details::allocator alloc_;
452  bool uses_private_area_;
453 
454  details::channel_group * ch_group_;
455 
456  int max_channels_allowed_;
457  int channels_used_;
458 };
459 
460 } // namespace core
461 
462 } // namespace yami
463 
464 #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:51
Namespace devoted for everything related to YAMI4.
Definition: agent.h:25
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