main.cpp
Go to the documentation of this file.
1 #include <ros/ros.h>
2 
4 #include "ffi/rust_functions.h"
5 
6 int main(int argc, char** argv) {
7  // 日本語を出力する場合のため
8  setlocale(LC_CTYPE, "ja_JP.UTF-8");
9  ros::init(argc, argv, "skyway");
10  ros::AsyncSpinner spinner(4);
11  spinner.start();
12 
13  // Rust側からC++側の関数を呼び出すためのセッティング
17  // Rust側の処理開始
19 
20  if (response.flag) {
21  // Rust側の処理が正常に開始した
22  ROS_DEBUG("program starts successfully");
23  Injector<CallbackFromRust> apiInjector(getCallbackFromRustComponent);
24  std::shared_ptr<CallbackFromRust> ffi =
25  apiInjector.get<std::shared_ptr<CallbackFromRust>>();
26 
27  //メインスレッドはここで止めてあとはSeviceとActionからの処理を待ち受け続ける
29  } else {
30  // Rust側の処理が正常に開始しなかった
31  // registerを忘れているケースなので通常発生しない
32  ROS_ERROR("some errors occurred");
33  }
34 
35  spinner.stop();
36  ros::shutdown();
37  // Rust側のthreadが終了するまで待機する
38  if (response.flag) {
39  ROS_DEBUG("Waiting for Rust side thread to finish");
40  join_handler(response.handler);
41  }
42 
43  return 0;
44 }
void register_program_state(bool_void_func is_running_c, bool_void_func is_shutting_down_c, void_double_func sleep_c, void_void_func wait_for_shutdown_c, void_void_func shutdown_c)
Component< CallbackFromRust > getCallbackFromRustComponent()
void log_debug_c(char *message)
void register_logger(void_char_func debug, void_char_func info, void_char_func warn, void_char_func error)
int main(int argc, char **argv)
Definition: main.cpp:6
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void join_handler(void *handler)
void shutdown_c()
void log_warn_c(char *message)
bool flag
Definition: common.h:36
void ros_sleep_c(double dur)
void log_info_c(char *message)
void * handler
Definition: common.h:37
run_response_t run()
bool is_ok_c()
void wait_for_shutdown_c()
ROSCPP_DECL void shutdown()
bool is_shutting_down_c()
#define ROS_ERROR(...)
void log_err_c(char *message)
const std::string response
ROSCPP_DECL void waitForShutdown()
#define ROS_DEBUG(...)


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