Browse Source

Decoupled main_ctx.

jcsyshc 1 year ago
parent
commit
05d0f1ac66

+ 7 - 8
src/device/impl/orb_camera_ui.cpp

@@ -8,11 +8,10 @@
 using boost::asio::io_context;
 using boost::asio::post;
 
-extern io_context *main_ctx;
-
 orb_camera_ui::impl::impl(create_config conf) {
+    ctx = conf.ctx;
     cam_c_conf.stream = conf.stream;
-    cam_c_conf.ctx = main_ctx;
+    cam_c_conf.ctx = ctx;
     cam_s_conf.color.name = conf.cf_name;
     cam_s_conf.depth.name = conf.df_name;
 
@@ -78,7 +77,7 @@ void orb_camera_ui::impl::show_config() {
     }
     ImGui::SameLine();
     if (ImGui::Button("R")) {
-        post(*main_ctx, [this] { refresh_dev_info_list(); });
+        post(*ctx, [this] { refresh_dev_info_list(); });
     }
 
     // select video config
@@ -122,21 +121,21 @@ void orb_camera_ui::impl::show() {
     if (cam == nullptr) {
         auto guard = imgui_disable_guard(dev_info_list.empty());
         if (ImGui::Button("Open")) {
-            post(*main_ctx, [this] { open_camera(); });
+            post(*ctx, [this] { open_camera(); });
         }
     } else {
         assert(cam != nullptr);
         if (ImGui::Button("Close")) {
-            post(*main_ctx, [this] { cam = nullptr; });
+            post(*ctx, [this] { cam = nullptr; });
         }
         ImGui::SameLine();
         if (!cam->is_capturing()) {
             if (ImGui::Button("Start")) {
-                post(*main_ctx, [this] { start_camera(); });
+                post(*ctx, [this] { start_camera(); });
             }
         } else {
             if (ImGui::Button("Stop")) {
-                post(*main_ctx, [this] { cam->stop(); });
+                post(*ctx, [this] { cam->stop(); });
             }
         }
     }

+ 2 - 0
src/device/impl/orb_camera_ui_impl.h

@@ -10,6 +10,8 @@ using boost::asio::io_context;
 
 struct orb_camera_ui::impl {
 
+    io_context *ctx = nullptr;
+
     orb_camera::device_info_list_type dev_info_list;
     int dev_index = 0;
 

+ 1 - 0
src/device/orb_camera_ui.h

@@ -12,6 +12,7 @@ public:
     struct create_config {
         obj_name_type cf_name = invalid_obj_name; // color frame name
         obj_name_type df_name = invalid_obj_name; // depth frame name
+        boost::asio::io_context *ctx = nullptr;
         smart_cuda_stream *stream = default_cuda_stream;
     };
 

+ 1 - 1
src/impl/main_impl.cpp

@@ -130,7 +130,7 @@ void init_om() {
 void init_modules() {
     auto orb_cam_conf = orb_camera_ui::create_config{
             .cf_name = img_color, .df_name = img_depth,
-            .stream = default_cuda_stream,
+            .ctx = main_ctx, .stream = default_cuda_stream,
     };
     orb_cam = std::make_unique<orb_camera_ui>(orb_cam_conf);