Willi Zschiebsch преди 5 години
родител
ревизия
236d589ee2
променени са 7 файла, в които са добавени 50 реда и са изтрити 18 реда
  1. 3 0
      CMakeLists.txt
  2. 2 0
      lib/CMakeLists.txt
  3. 1 1
      lib/include/Input.h
  4. 12 1
      lib/include/ModuleHTTP.h
  5. 28 12
      lib/src/ModuleHTTP.cpp
  6. 2 4
      lib/test/CMakeLists.txt
  7. 2 0
      thirdparty/json/single_include/json.hpp

+ 3 - 0
CMakeLists.txt

@@ -13,6 +13,9 @@ if(${TESTS_ENABLED})
     add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/googletest)
 endif()
 
+FIND_PACKAGE( Boost REQUIRED  COMPONENTS program_options )
+INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIR} )
+
 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/json/single_include)
 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/cpp-httplib)
 add_subdirectory(lib)

+ 2 - 0
lib/CMakeLists.txt

@@ -34,6 +34,8 @@ target_include_directories(${PROJECT_NAME} PUBLIC
         $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
         $<INSTALL_INTERFACE:include>)
 
+target_link_libraries(${PROJECT_NAME} Boost::programm_options)
+
 install(DIRECTORY include DESTINATION .)
 
 install(TARGETS ${PROJECT_NAME} DESTINATION lib/$<CONFIG> EXPORT targets)

+ 1 - 1
lib/include/Input.h

@@ -4,7 +4,7 @@
 #include <string>
 #include <functional>
 #include "Output.h"
-#include <bits/shared_ptr.h>
+#include <memory>
 #include "IUnique.h"
 
 namespace mdd {

+ 12 - 1
lib/include/ModuleHTTP.h

@@ -3,7 +3,13 @@
 
 #include "ModuleBase.h"
 #include <httplib.h>
+
+#ifdef WIN32
+
+#else
 #include <unistd.h>
+#endif
+
 
 
 using namespace httplib;
@@ -14,7 +20,12 @@ namespace mdd{
         std::string _fname;
         std::string _id;
         int _port;
-        pid_t _child_pid = 0;
+#ifdef WIN32
+
+#else
+		pid_t _child_pid = 0;
+#endif
+        
     protected:
         bool connect();
         std::string str_to_json(const std::string& input);

+ 28 - 12
lib/src/ModuleHTTP.cpp

@@ -2,7 +2,12 @@
 #include <httplib.h>
 #include <iostream>
 #include <thread>
+#ifdef WIN32
+
+#else
 #include <wait.h>
+#endif
+
 #include <chrono>
 
 using namespace httplib;
@@ -117,12 +122,17 @@ namespace mdd{
         setType("HTTP");
 
         if(!fname.empty()){
-            _child_pid = fork();
-            if(_child_pid == 0)
-            {
-                char*const arghs[] = {"python3", (char*const)fname.c_str(), NULL};
-                execvp("python3", arghs);
-            }
+#ifdef WIN32
+
+#else
+			_child_pid = fork();
+			if (_child_pid == 0)
+			{
+				char* const arghs[] = { "python3", (char* const)fname.c_str(), NULL };
+				execvp("python3", arghs);
+			}
+#endif
+            
         }
         while(!connect()){
             std::this_thread::sleep_for(std::chrono::microseconds(500));
@@ -132,12 +142,18 @@ namespace mdd{
 
     ModuleHTTP::~ModuleHTTP()
     {
-        if(_child_pid != 0)
-        {
-            kill(_child_pid, SIGINT);
-            int status;
-            waitpid(_child_pid, &status, 0);
-        }
+#ifdef WIN32
+
+#else
+		if (_child_pid != 0)
+		{
+
+			kill(_child_pid, SIGINT);
+			int status;
+			waitpid(_child_pid, &status, 0);
+	}
+#endif
+        
     }
 
     bool ModuleHTTP::update() {

+ 2 - 4
lib/test/CMakeLists.txt

@@ -1,4 +1,4 @@
-if(EXISTS /usr/src/gtest)
+
     add_executable(auslegung_test
             test_ModuleHTTP
             test_ModuleMath.cpp
@@ -6,6 +6,4 @@ if(EXISTS /usr/src/gtest)
             test_ProcessorManual.cpp
             )
     target_link_libraries(auslegung_test gtest gtest_main ${PROJECT_NAME})
-    add_test(auslegung_test auslegung_test)
-
-endif()
+    add_test(auslegung_test auslegung_test)

+ 2 - 0
thirdparty/json/single_include/json.hpp

@@ -0,0 +1,2 @@
+#include "nlohmann/json.hpp"
+using json = nlohmann::json;