Sfoglia il codice sorgente

optimize HTML connection

willi 5 anni fa
parent
commit
96e17c8f8b

+ 80 - 90
.idea/workspace.xml

@@ -15,7 +15,10 @@
   </component>
   <component name="ChangeListManager">
     <list default="true" id="4ddbafad-b85e-492e-80ec-3c73ef45688f" name="Default Changelist" comment="">
+      <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/lib/include/ModuleHTTP.h" beforeDir="false" afterPath="$PROJECT_DIR$/lib/include/ModuleHTTP.h" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/lib/src/ModuleHTTP.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/lib/src/ModuleHTTP.cpp" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/lib/test/server/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/lib/test/server/.gitignore" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/lib/test/server/server.py" beforeDir="false" afterPath="$PROJECT_DIR$/lib/test/server/server.py" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/lib/test/test_ModuleHTTP.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/lib/test/test_ModuleHTTP.cpp" afterDir="false" />
     </list>
@@ -35,11 +38,11 @@
   </component>
   <component name="FileEditorManager">
     <leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
-      <file pinned="false" current-in-tab="true">
+      <file pinned="false" current-in-tab="false">
         <entry file="file://$PROJECT_DIR$/lib/src/ModuleHTTP.cpp">
           <provider selected="true" editor-type-id="text-editor">
-            <state relative-caret-position="361">
-              <caret line="88" column="27" lean-forward="true" selection-start-line="88" selection-start-column="27" selection-end-line="88" selection-end-column="27" />
+            <state relative-caret-position="285">
+              <caret line="19" column="25" lean-forward="true" selection-start-line="19" selection-start-column="25" selection-end-line="19" selection-end-column="25" />
               <folding>
                 <element signature="e#0#23#0" expanded="true" />
               </folding>
@@ -50,12 +53,24 @@
       <file pinned="false" current-in-tab="false">
         <entry file="file:///usr/include/c++/7/thread">
           <provider selected="true" editor-type-id="text-editor">
-            <state relative-caret-position="184">
+            <state relative-caret-position="202">
               <caret line="134" selection-start-line="134" selection-end-line="134" />
             </state>
           </provider>
         </entry>
       </file>
+      <file pinned="false" current-in-tab="false">
+        <entry file="file://$PROJECT_DIR$/lib/include/ModuleHTTP.h">
+          <provider selected="true" editor-type-id="text-editor">
+            <state relative-caret-position="225">
+              <caret line="15" column="15" selection-start-line="15" selection-start-column="15" selection-end-line="15" selection-end-column="15" />
+              <folding>
+                <element signature="e#51#74#0" expanded="true" />
+              </folding>
+            </state>
+          </provider>
+        </entry>
+      </file>
       <file pinned="false" current-in-tab="false">
         <entry file="file://$PROJECT_DIR$/lib/src/Input.cpp">
           <provider selected="true" editor-type-id="text-editor">
@@ -74,11 +89,11 @@
           </provider>
         </entry>
       </file>
-      <file pinned="false" current-in-tab="false">
+      <file pinned="false" current-in-tab="true">
         <entry file="file://$PROJECT_DIR$/lib/test/test_ModuleHTTP.cpp">
           <provider selected="true" editor-type-id="text-editor">
-            <state relative-caret-position="373">
-              <caret line="96" column="31" lean-forward="true" selection-start-line="96" selection-start-column="31" selection-end-line="96" selection-end-column="31" />
+            <state relative-caret-position="82">
+              <caret line="40" column="62" selection-start-line="40" selection-start-column="62" selection-end-line="40" selection-end-column="62" />
               <folding>
                 <element signature="e#0#24#0" expanded="true" />
                 <element signature="e#91#119#0" expanded="true" />
@@ -114,18 +129,6 @@
           </provider>
         </entry>
       </file>
-      <file pinned="false" current-in-tab="false">
-        <entry file="file://$PROJECT_DIR$/lib/src/ModuleSwitch.cpp">
-          <provider selected="true" editor-type-id="text-editor">
-            <state relative-caret-position="112">
-              <caret line="8" column="39" lean-forward="true" selection-start-line="8" selection-start-column="39" selection-end-line="8" selection-end-column="39" />
-              <folding>
-                <element signature="e#0#25#0" expanded="true" />
-              </folding>
-            </state>
-          </provider>
-        </entry>
-      </file>
     </leaf>
   </component>
   <component name="FileTemplateManagerImpl">
@@ -150,7 +153,6 @@
   <component name="IdeDocumentHistory">
     <option name="CHANGED_PATHS">
       <list>
-        <option value="$PROJECT_DIR$/src/TestClass.h" />
         <option value="$PROJECT_DIR$/lib/src/TestClass.cpp" />
         <option value="$PROJECT_DIR$/cmake/auslegung-config.cmake" />
         <option value="$PROJECT_DIR$/lib/test/test_TestClass.cpp" />
@@ -196,11 +198,12 @@
         <option value="$PROJECT_DIR$/lib/include/ModuleBase.h" />
         <option value="$PROJECT_DIR$/lib/test/CMakeLists.txt" />
         <option value="$PROJECT_DIR$/.gitignore" />
-        <option value="$PROJECT_DIR$/lib/include/ModuleHTTP.h" />
         <option value="$PROJECT_DIR$/lib/src/ModuleMath.cpp" />
         <option value="$PROJECT_DIR$/lib/src/ModuleSwitch.cpp" />
-        <option value="$PROJECT_DIR$/lib/test/test_ModuleHTTP.cpp" />
+        <option value="$PROJECT_DIR$/lib/test/server/.gitignore" />
+        <option value="$PROJECT_DIR$/lib/include/ModuleHTTP.h" />
         <option value="$PROJECT_DIR$/lib/src/ModuleHTTP.cpp" />
+        <option value="$PROJECT_DIR$/lib/test/test_ModuleHTTP.cpp" />
       </list>
     </option>
   </component>
@@ -258,6 +261,14 @@
               <item name="lib" type="462c0819:PsiDirectoryNode" />
               <item name="test" type="462c0819:PsiDirectoryNode" />
             </path>
+            <path>
+              <item name="mdd" type="b2602c69:ProjectViewProjectNode" />
+              <item name="master_thesis_ws" type="47feb1d3:ProjectViewModuleNode" />
+              <item name="master_thesis_ws" type="462c0819:PsiDirectoryNode" />
+              <item name="lib" type="462c0819:PsiDirectoryNode" />
+              <item name="test" type="462c0819:PsiDirectoryNode" />
+              <item name="server" type="462c0819:PsiDirectoryNode" />
+            </path>
             <path>
               <item name="mdd" type="b2602c69:ProjectViewProjectNode" />
               <item name="master_thesis_ws" type="47feb1d3:ProjectViewModuleNode" />
@@ -407,44 +418,44 @@
       <workItem from="1590496125616" duration="6000" />
       <workItem from="1590497401566" duration="1517000" />
       <workItem from="1590576799306" duration="7324000" />
-      <workItem from="1590657068263" duration="9859000" />
+      <workItem from="1590657068263" duration="11635000" />
     </task>
     <servers />
   </component>
   <component name="TestHistory">
-    <history-entry file="All_in_auslegung_test - 2020.05.28 at 13h 28m 50s.xml">
+    <history-entry file="All_in_auslegung_test - 2020.05.28 at 14h 14m 54s.xml">
       <configuration name="All in auslegung_test" configurationId="CMakeGoogleTestRunConfigurationType" />
     </history-entry>
-    <history-entry file="All_in_auslegung_test - 2020.05.28 at 13h 31m 56s.xml">
+    <history-entry file="All_in_auslegung_test - 2020.05.28 at 14h 15m 02s.xml">
       <configuration name="All in auslegung_test" configurationId="CMakeGoogleTestRunConfigurationType" />
     </history-entry>
-    <history-entry file="All_in_auslegung_test - 2020.05.28 at 13h 32m 04s.xml">
+    <history-entry file="All_in_auslegung_test - 2020.05.28 at 14h 17m 59s.xml">
       <configuration name="All in auslegung_test" configurationId="CMakeGoogleTestRunConfigurationType" />
     </history-entry>
-    <history-entry file="All_in_auslegung_test - 2020.05.28 at 13h 32m 36s.xml">
+    <history-entry file="All_in_auslegung_test - 2020.05.28 at 14h 18m 07s.xml">
       <configuration name="All in auslegung_test" configurationId="CMakeGoogleTestRunConfigurationType" />
     </history-entry>
-    <history-entry file="All_in_auslegung_test - 2020.05.28 at 13h 41m 30s.xml">
+    <history-entry file="All_in_auslegung_test - 2020.05.28 at 14h 19m 54s.xml">
       <configuration name="All in auslegung_test" configurationId="CMakeGoogleTestRunConfigurationType" />
     </history-entry>
-    <history-entry file="All_in_auslegung_test - 2020.05.28 at 13h 45m 13s.xml">
+    <history-entry file="All_in_auslegung_test - 2020.05.28 at 14h 20m 23s.xml">
       <configuration name="All in auslegung_test" configurationId="CMakeGoogleTestRunConfigurationType" />
     </history-entry>
-    <history-entry file="All_in_auslegung_test - 2020.05.28 at 13h 45m 37s.xml">
+    <history-entry file="All_in_auslegung_test - 2020.05.28 at 14h 20m 56s.xml">
       <configuration name="All in auslegung_test" configurationId="CMakeGoogleTestRunConfigurationType" />
     </history-entry>
-    <history-entry file="All_in_auslegung_test - 2020.05.28 at 13h 47m 29s.xml">
+    <history-entry file="All_in_auslegung_test - 2020.05.28 at 14h 22m 56s.xml">
       <configuration name="All in auslegung_test" configurationId="CMakeGoogleTestRunConfigurationType" />
     </history-entry>
-    <history-entry file="All_in_auslegung_test - 2020.05.28 at 13h 49m 41s.xml">
+    <history-entry file="All_in_auslegung_test - 2020.05.28 at 14h 24m 13s.xml">
       <configuration name="All in auslegung_test" configurationId="CMakeGoogleTestRunConfigurationType" />
     </history-entry>
-    <history-entry file="All_in_auslegung_test - 2020.05.28 at 13h 51m 31s.xml">
+    <history-entry file="All_in_auslegung_test - 2020.05.28 at 14h 24m 20s.xml">
       <configuration name="All in auslegung_test" configurationId="CMakeGoogleTestRunConfigurationType" />
     </history-entry>
   </component>
   <component name="TimeTrackingManager">
-    <option name="totallyTimeSpent" value="186507000" />
+    <option name="totallyTimeSpent" value="188283000" />
   </component>
   <component name="TodoView" selected-index="1">
     <todo-panel id="selected-file">
@@ -459,12 +470,12 @@
     <frame x="0" y="-2" width="1920" height="1082" extended-state="6" />
     <editor active="true" />
     <layout>
-      <window_info content_ui="combo" id="Project" order="0" sideWeight="0.49921754" visible="true" weight="0.2614728" />
+      <window_info active="true" content_ui="combo" id="Project" order="0" sideWeight="0.49921754" visible="true" weight="0.2614728" />
       <window_info id="Structure" order="1" sideWeight="0.5007825" side_tool="true" weight="0.22572039" />
       <window_info id="Favorites" order="2" sideWeight="0.5007825" side_tool="true" weight="0.22572039" />
       <window_info anchor="bottom" id="Message" order="0" />
       <window_info anchor="bottom" id="Find" order="1" />
-      <window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.3557188" />
+      <window_info anchor="bottom" id="Run" order="2" visible="true" weight="0.3557188" />
       <window_info anchor="bottom" id="Debug" order="3" weight="0.3336831" />
       <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
       <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
@@ -541,45 +552,25 @@
   <component name="XDebuggerManager">
     <breakpoint-manager>
       <breakpoints>
-        <line-breakpoint enabled="true" type="com.jetbrains.cidr.execution.debugger.OCBreakpointType">
-          <url>file://$PROJECT_DIR$/lib/test/test_ModuleHTTP.cpp</url>
-          <line>95</line>
-          <option name="timeStamp" value="32" />
-        </line-breakpoint>
-        <line-breakpoint enabled="true" type="com.jetbrains.cidr.execution.debugger.OCBreakpointType">
-          <url>file://$PROJECT_DIR$/lib/test/test_ModuleHTTP.cpp</url>
-          <line>89</line>
-          <option name="timeStamp" value="34" />
-        </line-breakpoint>
-        <line-breakpoint enabled="true" type="com.jetbrains.cidr.execution.debugger.OCBreakpointType">
-          <url>file://$PROJECT_DIR$/lib/test/test_ModuleHTTP.cpp</url>
-          <line>85</line>
-          <option name="timeStamp" value="35" />
-        </line-breakpoint>
         <line-breakpoint enabled="true" type="com.jetbrains.cidr.execution.debugger.OCBreakpointType">
           <url>file://$PROJECT_DIR$/lib/src/ModuleHTTP.cpp</url>
-          <line>92</line>
+          <line>114</line>
           <option name="timeStamp" value="36" />
         </line-breakpoint>
         <line-breakpoint enabled="true" type="com.jetbrains.cidr.execution.debugger.OCBreakpointType">
           <url>file://$PROJECT_DIR$/lib/src/ModuleHTTP.cpp</url>
-          <line>40</line>
+          <line>62</line>
           <option name="timeStamp" value="37" />
         </line-breakpoint>
         <line-breakpoint enabled="true" type="com.jetbrains.cidr.execution.debugger.OCBreakpointType">
           <url>file://$PROJECT_DIR$/lib/src/ModuleHTTP.cpp</url>
-          <line>85</line>
-          <option name="timeStamp" value="38" />
-        </line-breakpoint>
-        <line-breakpoint enabled="true" type="com.jetbrains.cidr.execution.debugger.OCBreakpointType">
-          <url>file://$PROJECT_DIR$/lib/src/ModuleHTTP.cpp</url>
-          <line>90</line>
-          <option name="timeStamp" value="39" />
+          <line>95</line>
+          <option name="timeStamp" value="40" />
         </line-breakpoint>
         <line-breakpoint enabled="true" type="com.jetbrains.cidr.execution.debugger.OCBreakpointType">
           <url>file://$PROJECT_DIR$/lib/src/ModuleHTTP.cpp</url>
-          <line>73</line>
-          <option name="timeStamp" value="40" />
+          <line>111</line>
+          <option name="timeStamp" value="43" />
         </line-breakpoint>
       </breakpoints>
     </breakpoint-manager>
@@ -590,14 +581,6 @@
     </watches-manager>
   </component>
   <component name="editorHistoryManager">
-    <entry file="file://$PROJECT_DIR$/thirdparty/json/README.md">
-      <provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
-        <state split_layout="SPLIT">
-          <first_editor />
-          <second_editor />
-        </state>
-      </provider>
-    </entry>
     <entry file="file:///usr/include/c++/7/bits/vector.tcc">
       <provider selected="true" editor-type-id="text-editor">
         <state relative-caret-position="164">
@@ -777,16 +760,6 @@
         </state>
       </provider>
     </entry>
-    <entry file="file://$PROJECT_DIR$/lib/include/ModuleHTTP.h">
-      <provider selected="true" editor-type-id="text-editor">
-        <state relative-caret-position="240">
-          <caret line="16" column="20" selection-start-line="16" selection-start-column="20" selection-end-line="16" selection-end-column="20" />
-          <folding>
-            <element signature="e#51#74#0" expanded="true" />
-          </folding>
-        </state>
-      </provider>
-    </entry>
     <entry file="file://$PROJECT_DIR$/thirdparty/cpp-httplib/httplib.h">
       <provider selected="true" editor-type-id="text-editor">
         <state relative-caret-position="3150">
@@ -934,33 +907,50 @@
         </state>
       </provider>
     </entry>
-    <entry file="file:///usr/include/c++/7/thread">
+    <entry file="file://$PROJECT_DIR$/lib/test/server/.gitignore">
       <provider selected="true" editor-type-id="text-editor">
-        <state relative-caret-position="184">
-          <caret line="134" selection-start-line="134" selection-end-line="134" />
+        <state relative-caret-position="15">
+          <caret line="1" column="11" lean-forward="true" selection-start-line="1" selection-start-column="11" selection-end-line="1" selection-end-column="11" />
         </state>
       </provider>
     </entry>
-    <entry file="file://$PROJECT_DIR$/lib/test/test_ModuleHTTP.cpp">
+    <entry file="file://$PROJECT_DIR$/lib/include/ModuleHTTP.h">
       <provider selected="true" editor-type-id="text-editor">
-        <state relative-caret-position="373">
-          <caret line="96" column="31" lean-forward="true" selection-start-line="96" selection-start-column="31" selection-end-line="96" selection-end-column="31" />
+        <state relative-caret-position="225">
+          <caret line="15" column="15" selection-start-line="15" selection-start-column="15" selection-end-line="15" selection-end-column="15" />
           <folding>
-            <element signature="e#0#24#0" expanded="true" />
-            <element signature="e#91#119#0" expanded="true" />
+            <element signature="e#51#74#0" expanded="true" />
           </folding>
         </state>
       </provider>
     </entry>
+    <entry file="file:///usr/include/c++/7/thread">
+      <provider selected="true" editor-type-id="text-editor">
+        <state relative-caret-position="202">
+          <caret line="134" selection-start-line="134" selection-end-line="134" />
+        </state>
+      </provider>
+    </entry>
     <entry file="file://$PROJECT_DIR$/lib/src/ModuleHTTP.cpp">
       <provider selected="true" editor-type-id="text-editor">
-        <state relative-caret-position="361">
-          <caret line="88" column="27" lean-forward="true" selection-start-line="88" selection-start-column="27" selection-end-line="88" selection-end-column="27" />
+        <state relative-caret-position="285">
+          <caret line="19" column="25" lean-forward="true" selection-start-line="19" selection-start-column="25" selection-end-line="19" selection-end-column="25" />
           <folding>
             <element signature="e#0#23#0" expanded="true" />
           </folding>
         </state>
       </provider>
     </entry>
+    <entry file="file://$PROJECT_DIR$/lib/test/test_ModuleHTTP.cpp">
+      <provider selected="true" editor-type-id="text-editor">
+        <state relative-caret-position="82">
+          <caret line="40" column="62" selection-start-line="40" selection-start-column="62" selection-end-line="40" selection-end-column="62" />
+          <folding>
+            <element signature="e#0#24#0" expanded="true" />
+            <element signature="e#91#119#0" expanded="true" />
+          </folding>
+        </state>
+      </provider>
+    </entry>
   </component>
 </project>

+ 1 - 0
lib/include/ModuleHTTP.h

@@ -13,6 +13,7 @@ namespace mdd{
         std::string _id;
         int _port;
     protected:
+        bool connect();
         std::string str_to_json(const std::string& input);
         void updateLayout();
 

+ 25 - 3
lib/src/ModuleHTTP.cpp

@@ -7,6 +7,28 @@ using namespace httplib;
 
 namespace mdd{
 
+    bool ModuleHTTP::connect(){
+        Client cli(_id, _port);
+        std::string body;
+        auto res = cli.Get("/status",
+                           [&](const char *data, size_t data_length) {
+                               body.append(data, data_length);
+                               return true;
+                           });
+        //assert(res->body.empty());
+        if(body.empty()){
+            return false;
+        }
+        body =  std::string(R"()") + body;
+        json status = json::parse(body.c_str());
+        if (status["status"].get<std::string>() == "ready"){
+            return true;
+        }
+        else{
+            return false;
+        }
+    }
+
     std::string ModuleHTTP::str_to_json(const std::string& input){
         if(input.empty()){
             return input;
@@ -86,10 +108,10 @@ namespace mdd{
         if(!fname.empty()){
             std::string command = "python3 " + fname+"&";
             system(command.c_str());
-            usleep(495000);
         }
-        int test = 0;
-        usleep(5000);
+        while(!connect()){
+            usleep(1000);
+        }
         updateLayout();
     }
 

+ 1 - 0
lib/test/server/.gitignore

@@ -1 +1,2 @@
 .idea
+__pycache__

+ 2 - 0
lib/test/server/server.py

@@ -49,6 +49,8 @@ class MainHandler(tornado.web.RequestHandler, ABC):
             self.write(json.dumps(inputs))
         elif param == "outputs":
             self.write(json.dumps(outputs))
+        elif param == "status":
+            self.write("{\"status\": \"ready\"}")
         elif param == "stop":
             instance = tornado.ioloop.IOLoop.instance()
             instance.add_callback(instance.stop)

+ 6 - 17
lib/test/test_ModuleHTTP.cpp

@@ -24,18 +24,7 @@ void serverThread()
             entity["value"] = i;
             input_body.push_back(entity);
         }
-        std::cout<<"RECIVED: /inputs" <<std::endl;
         res.set_content(input_body.dump(), "application/json");
-        auto data = new std::string(input_body.dump());
-
-        res.set_content_provider(
-                data->size(), // Content length
-                [data](size_t offset, size_t length, DataSink &sink) {
-                    const auto &d = *data;
-                    sink.write(&d[offset], std::min(length, length));
-                    return true; // return 'false' if you want to cancel the process.
-                },
-                [data] { delete data; });
     });
 
     svr.Get("/outputs", [](const Request& req, Response& res) {
@@ -46,10 +35,15 @@ void serverThread()
             entity["value"] = i*2;
             output_body.push_back(entity);
         }
-        std::cout<<"RECIVED: /outputs" <<std::endl;
         res.set_content(output_body.dump(), "application/json");
     });
 
+    svr.Get("/status", [](const Request& req, Response& res) {
+        json body;
+        body["status"] = "ready";
+        res.set_content(body.dump(), "application/json");
+    });
+
     svr.Get("/stop", [&](const Request& req, Response& res) {
         svr.stop();
     });
@@ -60,7 +54,6 @@ TEST(ModuleHTTP, updateLayout_intern){
     std::thread server (serverThread);
     ModuleHTTP module("", "localhost", 8888);
 
-
     Client cli("localhost",8888);
     cli.Get("/stop");
     server.join();
@@ -70,7 +63,6 @@ TEST(ModuleHTTP, updateLayout_intern){
     for (int i = 0; i < 5; ++i) {
         EXPECT_EQ(inputs_types[i], "INPUT");
         EXPECT_EQ(module.getInput(inputs_ids[i])->getValue()["value"].get<int>(), i);
-        std::cout << module.getInput(inputs_ids[i])->getValue().dump() << std::endl;
     }
 
     auto outputs_types = module.getOutputs();
@@ -78,7 +70,6 @@ TEST(ModuleHTTP, updateLayout_intern){
     for (int i = 0; i < 3; ++i) {
         EXPECT_EQ(outputs_types[i], "OUTPUT");
         EXPECT_EQ(module.getOutput(outputs_ids[i])->getValue()["value"].get<int>(), i * 2);
-        std::cout << module.getOutput(outputs_ids[i])->getValue().dump() << std::endl;
     }
 }
 
@@ -90,7 +81,6 @@ TEST(ModuleHTTP, updateLayout_extern){
     for(int i = 0; i < 5; ++i){
         EXPECT_EQ(inputs_types[i], "INPUT");
         EXPECT_EQ(module.getInput(inputs_ids[i])->getValue()["value"].get<int>(), i);
-        std::cout << module.getInput(inputs_ids[i])->getValue().dump() << std::endl;
     }
 
     auto outputs_types = module.getOutputs();
@@ -98,7 +88,6 @@ TEST(ModuleHTTP, updateLayout_extern){
     for(int i = 0; i < 3; ++i){
         EXPECT_EQ(outputs_types[i], "OUTPUT");
         EXPECT_EQ(module.getOutput(outputs_ids[i])->getValue()["value"].get<int>(), i*2);
-        std::cout << module.getOutput(outputs_ids[i])->getValue().dump() << std::endl;
     }
     Client cli("localhost",8888);
     cli.Get("/stop");