Explorar el Código

Implemented controller.

jcsyshc hace 2 años
padre
commit
d83ea2293f
Se han modificado 1 ficheros con 29 adiciones y 2 borrados
  1. 29 2
      src/main.cpp

+ 29 - 2
src/main.cpp

@@ -12,6 +12,8 @@
 #include <glad/gl.h>
 #include <GLFW/glfw3.h>
 
+#include <boost/process/child.hpp>
+
 #include <spdlog/spdlog.h>
 
 #include <thread>
@@ -25,7 +27,7 @@ GLFWwindow *main_window = nullptr;
 // for receiver
 video_decoder decoder;
 
-void controller_main() {
+void controller_main(const char *this_name) {
 
     // setup imgui context
     IMGUI_CHECKVERSION();
@@ -43,6 +45,9 @@ void controller_main() {
         free(server_address);
     });
 
+    namespace bp = boost::process;
+    bp::child *worker = nullptr;
+
     // main loop
     while (!glfwWindowShouldClose(main_window)) {
 
@@ -58,9 +63,24 @@ void controller_main() {
             // action
             ImGui::SeparatorText("Actions");
 
+            if (worker == nullptr) {
+                if (ImGui::Button("Start")) {
+                    worker = new bp::child{this_name, std::to_string(monitor_index),
+                                           server_address, std::to_string(server_port)};
+                }
+            } else {
+                if (ImGui::Button("Stop")) {
+                    worker->terminate();
+                    worker = nullptr;
+                }
+            }
+
             // configs
             ImGui::SeparatorText("Configs");
             ImGui::PushItemWidth(200);
+            if (worker != nullptr) {
+                ImGui::BeginDisabled();
+            }
 
             // monitor
             int monitor_count;
@@ -89,6 +109,9 @@ void controller_main() {
             static uint16_t val_one = 1;
             ImGui::InputScalar("Server Port", ImGuiDataType_U16, &server_port, &val_one, nullptr, "%u");
 
+            if (worker != nullptr) {
+                ImGui::EndDisabled();
+            }
             ImGui::PopItemWidth();
         }
         ImGui::End();
@@ -103,6 +126,10 @@ void controller_main() {
         ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
         glfwSwapBuffers(main_window);
     }
+
+    if (worker != nullptr) {
+        worker->terminate();
+    }
 }
 
 void render_main() {
@@ -197,7 +224,7 @@ int main(int argc, char *argv[]) {
 #endif
 
     if (is_controller) {
-        controller_main();
+        controller_main(argv[0]);
     } else {
         render_main();
     }