callback_from_rust.cpp
Go to the documentation of this file.
1 //
2 // Created by nakakura on 22/09/04.
3 //
4 
5 #include "callback_from_rust.h"
6 
7 #include <signal.h>
8 
9 #include "rust_functions.h"
10 
11 extern "C" {
12 void create_peer_callback_ffi(char* peer_id, char* token) {
13  create_peer_callback_handler(peer_id, token);
14 }
15 
16 // Peer Closeイベントが発火したときにプログラム全体を終了する
18 
19 PluginLoadResult create_data_callback_ffi(char* target_ip, uint16_t target_port,
20  char* plugin_type,
21  char* plugin_param) {
22  return create_data_callback_handler(target_ip, target_port, plugin_type,
23  plugin_param);
24 }
25 
27  data_connection_close_event_callback_handler(port_num);
28 }
29 
30 // リソース開放処理
31 void release_string_ffi(char* str) { free(str); }
32 }
33 
34 CallbackFromRustImpl::CallbackFromRustImpl(std::shared_ptr<Router> router)
35  : router_(std::move(router)) {
36  create_peer_callback_handler =
38  std::placeholders::_1, std::placeholders::_2);
39 
40  create_data_callback_handler =
42  std::placeholders::_1, std::placeholders::_2,
43  std::placeholders::_3, std::placeholders::_4);
44 
45  data_connection_close_event_callback_handler =
47  std::placeholders::_1);
48 
53  register_callbacks(functions);
54 }
55 
56 void CallbackFromRustImpl::create_peer_callback(char* peer_id, char* token) {
57  router_->OnCreatePeer(peer_id, token);
58 
59  release_string(peer_id);
60  release_string(token);
61 }
62 
64  char* target_ip, uint16_t port, char* plugin_type, char* plugin_param) {
65  auto result =
66  router_->OnConnectData(target_ip, port, plugin_type, plugin_param);
67  release_string(target_ip);
68  release_string(plugin_type);
69  release_string(plugin_param);
70 
71  struct PluginLoadResult response = {.is_success = result.is_success,
72  .port = result.port,
73  .error_message = result.error_message};
74  return response;
75 }
76 
78  router_->OnDeleteData(port_num);
79 }
80 
81 Component<CallbackFromRust> getCallbackFromRustComponent() {
82  return fruit::createComponent()
84  .install(getRouterComponent);
85 }
void peer_deleted_callback_ffi()
bool is_success
Definition: common.h:11
Component< CallbackFromRust > getCallbackFromRustComponent()
void create_peer_callback(char *peer_id, char *token)
std::shared_ptr< Router > router_
Component< Router > getRouterComponent()
Definition: router.cpp:101
void register_callbacks(Function &functions)
void create_peer_callback_ffi(char *peer_id, char *token)
PluginLoadResult create_data_callback_ffi(char *target_ip, uint16_t target_port, char *plugin_type, char *plugin_param)
PluginLoadResult create_data_connection_callback(char *, uint16_t, char *, char *)
void delete_data_connection_callback(uint16_t)
void release_string(char *message)
void data_connection_close_event_callback_ffi(uint16_t port_num)
ROSCPP_DECL void shutdown()
void release_string_ffi(char *str)


skyway
Author(s): Toshiya Nakakura
autogenerated on Sat Apr 15 2023 02:08:21