Browse Source

HTTP update test

willi 5 năm trước cách đây
mục cha
commit
1a9015ea2b
5 tập tin đã thay đổi với 219 bổ sung133 xóa
  1. 110 99
      .idea/workspace.xml
  2. 2 0
      lib/include/ModuleHTTP.h
  3. 28 13
      lib/src/ModuleHTTP.cpp
  4. 2 1
      lib/test/server/server.py
  5. 77 20
      lib/test/test_ModuleHTTP.cpp

+ 110 - 99
.idea/workspace.xml

@@ -15,10 +15,8 @@
   </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>
@@ -39,10 +37,34 @@
   <component name="FileEditorManager">
     <leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
       <file pinned="false" current-in-tab="false">
+        <entry file="file://$PROJECT_DIR$/lib/src/ModuleMath.cpp">
+          <provider selected="true" editor-type-id="text-editor">
+            <state relative-caret-position="120">
+              <caret line="9" column="39" lean-forward="true" selection-start-line="9" selection-start-column="39" selection-end-line="9" selection-end-column="39" />
+              <folding>
+                <element signature="e#0#23#0" expanded="true" />
+              </folding>
+            </state>
+          </provider>
+        </entry>
+      </file>
+      <file pinned="false" current-in-tab="false">
+        <entry file="file://$PROJECT_DIR$/lib/test/test_ModuleMath.cpp">
+          <provider selected="true" editor-type-id="text-editor">
+            <state relative-caret-position="578">
+              <caret line="59" selection-start-line="59" selection-end-line="59" />
+              <folding>
+                <element signature="e#0#24#0" expanded="true" />
+              </folding>
+            </state>
+          </provider>
+        </entry>
+      </file>
+      <file pinned="false" current-in-tab="true">
         <entry file="file://$PROJECT_DIR$/lib/src/ModuleHTTP.cpp">
           <provider selected="true" editor-type-id="text-editor">
-            <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" />
+            <state relative-caret-position="421">
+              <caret line="119" column="9" selection-start-line="119" selection-start-column="9" selection-end-line="119" selection-end-column="9" />
               <folding>
                 <element signature="e#0#23#0" expanded="true" />
               </folding>
@@ -62,8 +84,8 @@
       <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" />
+            <state relative-caret-position="345">
+              <caret line="23" column="16" selection-start-line="23" selection-start-column="16" selection-end-line="23" selection-end-column="16" />
               <folding>
                 <element signature="e#51#74#0" expanded="true" />
               </folding>
@@ -74,8 +96,8 @@
       <file pinned="false" current-in-tab="false">
         <entry file="file://$PROJECT_DIR$/lib/src/Input.cpp">
           <provider selected="true" editor-type-id="text-editor">
-            <state relative-caret-position="420">
-              <caret line="37" column="21" lean-forward="true" selection-start-line="37" selection-start-column="21" selection-end-line="37" selection-end-column="21" />
+            <state relative-caret-position="330">
+              <caret line="31" column="5" lean-forward="true" selection-start-line="31" selection-start-column="5" selection-end-line="31" selection-end-column="5" />
             </state>
           </provider>
         </entry>
@@ -89,11 +111,11 @@
           </provider>
         </entry>
       </file>
-      <file pinned="false" current-in-tab="true">
+      <file pinned="false" current-in-tab="false">
         <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" />
+            <state relative-caret-position="184">
+              <caret line="126" selection-start-line="126" selection-end-line="126" />
               <folding>
                 <element signature="e#0#24#0" expanded="true" />
                 <element signature="e#91#119#0" expanded="true" />
@@ -103,19 +125,13 @@
         </entry>
       </file>
       <file pinned="false" current-in-tab="false">
-        <entry file="file:///usr/include/c++/7/bits/stl_vector.h">
-          <provider selected="true" editor-type-id="text-editor">
-            <state relative-caret-position="199">
-              <caret line="563" selection-start-line="563" selection-end-line="563" />
-            </state>
-          </provider>
-        </entry>
-      </file>
-      <file pinned="false" current-in-tab="false">
-        <entry file="file:///usr/include/c++/7/bits/shared_ptr_base.h">
+        <entry file="file://$PROJECT_DIR$/lib/include/IInput.h">
           <provider selected="true" editor-type-id="text-editor">
-            <state relative-caret-position="202">
-              <caret line="682" selection-start-line="682" selection-end-line="682" />
+            <state relative-caret-position="120">
+              <caret line="8" column="28" selection-start-line="8" selection-start-column="28" selection-end-line="8" selection-end-column="28" />
+              <folding>
+                <element signature="e#43#63#0" expanded="true" />
+              </folding>
             </state>
           </provider>
         </entry>
@@ -144,6 +160,7 @@
       <find>output</find>
       <find>Gener</find>
       <find>st</find>
+      <find>std::cout</find>
     </findStrings>
   </component>
   <component name="Git.Settings">
@@ -202,8 +219,8 @@
         <option value="$PROJECT_DIR$/lib/src/ModuleSwitch.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" />
+        <option value="$PROJECT_DIR$/lib/src/ModuleHTTP.cpp" />
       </list>
     </option>
   </component>
@@ -418,44 +435,44 @@
       <workItem from="1590496125616" duration="6000" />
       <workItem from="1590497401566" duration="1517000" />
       <workItem from="1590576799306" duration="7324000" />
-      <workItem from="1590657068263" duration="11635000" />
+      <workItem from="1590657068263" duration="18515000" />
     </task>
     <servers />
   </component>
   <component name="TestHistory">
-    <history-entry file="All_in_auslegung_test - 2020.05.28 at 14h 14m 54s.xml">
+    <history-entry file="All_in_auslegung_test - 2020.05.28 at 16h 08m 43s.xml">
       <configuration name="All in auslegung_test" configurationId="CMakeGoogleTestRunConfigurationType" />
     </history-entry>
-    <history-entry file="All_in_auslegung_test - 2020.05.28 at 14h 15m 02s.xml">
+    <history-entry file="All_in_auslegung_test - 2020.05.28 at 16h 09m 36s.xml">
       <configuration name="All in auslegung_test" configurationId="CMakeGoogleTestRunConfigurationType" />
     </history-entry>
-    <history-entry file="All_in_auslegung_test - 2020.05.28 at 14h 17m 59s.xml">
+    <history-entry file="All_in_auslegung_test - 2020.05.28 at 16h 13m 28s.xml">
       <configuration name="All in auslegung_test" configurationId="CMakeGoogleTestRunConfigurationType" />
     </history-entry>
-    <history-entry file="All_in_auslegung_test - 2020.05.28 at 14h 18m 07s.xml">
+    <history-entry file="All_in_auslegung_test - 2020.05.28 at 16h 13m 35s.xml">
       <configuration name="All in auslegung_test" configurationId="CMakeGoogleTestRunConfigurationType" />
     </history-entry>
-    <history-entry file="All_in_auslegung_test - 2020.05.28 at 14h 19m 54s.xml">
+    <history-entry file="All_in_auslegung_test - 2020.05.28 at 16h 13m 58s.xml">
       <configuration name="All in auslegung_test" configurationId="CMakeGoogleTestRunConfigurationType" />
     </history-entry>
-    <history-entry file="All_in_auslegung_test - 2020.05.28 at 14h 20m 23s.xml">
+    <history-entry file="All_in_auslegung_test - 2020.05.28 at 16h 16m 51s.xml">
       <configuration name="All in auslegung_test" configurationId="CMakeGoogleTestRunConfigurationType" />
     </history-entry>
-    <history-entry file="All_in_auslegung_test - 2020.05.28 at 14h 20m 56s.xml">
+    <history-entry file="All_in_auslegung_test - 2020.05.28 at 16h 17m 10s.xml">
       <configuration name="All in auslegung_test" configurationId="CMakeGoogleTestRunConfigurationType" />
     </history-entry>
-    <history-entry file="All_in_auslegung_test - 2020.05.28 at 14h 22m 56s.xml">
+    <history-entry file="All_in_auslegung_test - 2020.05.28 at 16h 17m 47s.xml">
       <configuration name="All in auslegung_test" configurationId="CMakeGoogleTestRunConfigurationType" />
     </history-entry>
-    <history-entry file="All_in_auslegung_test - 2020.05.28 at 14h 24m 13s.xml">
+    <history-entry file="All_in_auslegung_test - 2020.05.28 at 16h 18m 35s.xml">
       <configuration name="All in auslegung_test" configurationId="CMakeGoogleTestRunConfigurationType" />
     </history-entry>
-    <history-entry file="All_in_auslegung_test - 2020.05.28 at 14h 24m 20s.xml">
+    <history-entry file="All_in_auslegung_test - 2020.05.28 at 16h 19m 46s.xml">
       <configuration name="All in auslegung_test" configurationId="CMakeGoogleTestRunConfigurationType" />
     </history-entry>
   </component>
   <component name="TimeTrackingManager">
-    <option name="totallyTimeSpent" value="188283000" />
+    <option name="totallyTimeSpent" value="195163000" />
   </component>
   <component name="TodoView" selected-index="1">
     <todo-panel id="selected-file">
@@ -468,14 +485,13 @@
   </component>
   <component name="ToolWindowManager">
     <frame x="0" y="-2" width="1920" height="1082" extended-state="6" />
-    <editor active="true" />
     <layout>
-      <window_info active="true" content_ui="combo" id="Project" order="0" sideWeight="0.49921754" visible="true" weight="0.2614728" />
+      <window_info 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 anchor="bottom" id="Run" order="2" visible="true" weight="0.3557188" />
+      <window_info anchor="bottom" id="Run" order="2" 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" />
@@ -553,24 +569,19 @@
     <breakpoint-manager>
       <breakpoints>
         <line-breakpoint enabled="true" type="com.jetbrains.cidr.execution.debugger.OCBreakpointType">
-          <url>file://$PROJECT_DIR$/lib/src/ModuleHTTP.cpp</url>
-          <line>114</line>
-          <option name="timeStamp" value="36" />
+          <url>file://$PROJECT_DIR$/lib/test/test_ModuleHTTP.cpp</url>
+          <line>145</line>
+          <option name="timeStamp" value="64" />
         </line-breakpoint>
         <line-breakpoint enabled="true" type="com.jetbrains.cidr.execution.debugger.OCBreakpointType">
-          <url>file://$PROJECT_DIR$/lib/src/ModuleHTTP.cpp</url>
-          <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>95</line>
-          <option name="timeStamp" value="40" />
+          <url>file://$PROJECT_DIR$/lib/test/test_ModuleHTTP.cpp</url>
+          <line>126</line>
+          <option name="timeStamp" value="69" />
         </line-breakpoint>
         <line-breakpoint enabled="true" type="com.jetbrains.cidr.execution.debugger.OCBreakpointType">
           <url>file://$PROJECT_DIR$/lib/src/ModuleHTTP.cpp</url>
-          <line>111</line>
-          <option name="timeStamp" value="43" />
+          <line>120</line>
+          <option name="timeStamp" value="70" />
         </line-breakpoint>
       </breakpoints>
     </breakpoint-manager>
@@ -750,16 +761,6 @@
         </state>
       </provider>
     </entry>
-    <entry file="file://$PROJECT_DIR$/lib/test/test_ModuleMath.cpp">
-      <provider selected="true" editor-type-id="text-editor">
-        <state relative-caret-position="702">
-          <caret line="59" selection-start-line="59" selection-end-line="59" />
-          <folding>
-            <element signature="e#0#24#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">
@@ -791,16 +792,6 @@
         </state>
       </provider>
     </entry>
-    <entry file="file://$PROJECT_DIR$/lib/include/IInput.h">
-      <provider selected="true" editor-type-id="text-editor">
-        <state relative-caret-position="120">
-          <caret line="8" column="28" selection-start-line="8" selection-start-column="28" selection-end-line="8" selection-end-column="28" />
-          <folding>
-            <element signature="e#43#63#0" expanded="true" />
-          </folding>
-        </state>
-      </provider>
-    </entry>
     <entry file="file://$PROJECT_DIR$/lib/include/IOutput.h">
       <provider selected="true" editor-type-id="text-editor">
         <state relative-caret-position="210">
@@ -845,16 +836,6 @@
         </state>
       </provider>
     </entry>
-    <entry file="file://$PROJECT_DIR$/lib/src/ModuleMath.cpp">
-      <provider selected="true" editor-type-id="text-editor">
-        <state relative-caret-position="135">
-          <caret line="9" column="39" lean-forward="true" selection-start-line="9" selection-start-column="39" selection-end-line="9" selection-end-column="39" />
-          <folding>
-            <element signature="e#0#23#0" expanded="true" />
-          </folding>
-        </state>
-      </provider>
-    </entry>
     <entry file="file://$PROJECT_DIR$/lib/src/ModuleSwitch.cpp">
       <provider selected="true" editor-type-id="text-editor">
         <state relative-caret-position="112">
@@ -893,13 +874,6 @@
         </state>
       </provider>
     </entry>
-    <entry file="file://$PROJECT_DIR$/lib/src/Input.cpp">
-      <provider selected="true" editor-type-id="text-editor">
-        <state relative-caret-position="420">
-          <caret line="37" column="21" lean-forward="true" selection-start-line="37" selection-start-column="21" selection-end-line="37" selection-end-column="21" />
-        </state>
-      </provider>
-    </entry>
     <entry file="file://$PROJECT_DIR$/lib/src/ModuleBase.cpp">
       <provider selected="true" editor-type-id="text-editor">
         <state relative-caret-position="412">
@@ -914,12 +888,39 @@
         </state>
       </provider>
     </entry>
-    <entry file="file://$PROJECT_DIR$/lib/include/ModuleHTTP.h">
+    <entry file="file://$PROJECT_DIR$/lib/include/IInput.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" />
+        <state relative-caret-position="120">
+          <caret line="8" column="28" selection-start-line="8" selection-start-column="28" selection-end-line="8" selection-end-column="28" />
           <folding>
-            <element signature="e#51#74#0" expanded="true" />
+            <element signature="e#43#63#0" expanded="true" />
+          </folding>
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/lib/src/Input.cpp">
+      <provider selected="true" editor-type-id="text-editor">
+        <state relative-caret-position="330">
+          <caret line="31" column="5" lean-forward="true" selection-start-line="31" selection-start-column="5" selection-end-line="31" selection-end-column="5" />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/lib/src/ModuleMath.cpp">
+      <provider selected="true" editor-type-id="text-editor">
+        <state relative-caret-position="120">
+          <caret line="9" column="39" lean-forward="true" selection-start-line="9" selection-start-column="39" selection-end-line="9" selection-end-column="39" />
+          <folding>
+            <element signature="e#0#23#0" expanded="true" />
+          </folding>
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/lib/test/test_ModuleMath.cpp">
+      <provider selected="true" editor-type-id="text-editor">
+        <state relative-caret-position="578">
+          <caret line="59" selection-start-line="59" selection-end-line="59" />
+          <folding>
+            <element signature="e#0#24#0" expanded="true" />
           </folding>
         </state>
       </provider>
@@ -931,20 +932,20 @@
         </state>
       </provider>
     </entry>
-    <entry file="file://$PROJECT_DIR$/lib/src/ModuleHTTP.cpp">
+    <entry file="file://$PROJECT_DIR$/lib/include/ModuleHTTP.h">
       <provider selected="true" editor-type-id="text-editor">
-        <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" />
+        <state relative-caret-position="345">
+          <caret line="23" column="16" selection-start-line="23" selection-start-column="16" selection-end-line="23" selection-end-column="16" />
           <folding>
-            <element signature="e#0#23#0" expanded="true" />
+            <element signature="e#51#74#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" />
+        <state relative-caret-position="184">
+          <caret line="126" selection-start-line="126" selection-end-line="126" />
           <folding>
             <element signature="e#0#24#0" expanded="true" />
             <element signature="e#91#119#0" expanded="true" />
@@ -952,5 +953,15 @@
         </state>
       </provider>
     </entry>
+    <entry file="file://$PROJECT_DIR$/lib/src/ModuleHTTP.cpp">
+      <provider selected="true" editor-type-id="text-editor">
+        <state relative-caret-position="421">
+          <caret line="119" column="9" selection-start-line="119" selection-start-column="9" selection-end-line="119" selection-end-column="9" />
+          <folding>
+            <element signature="e#0#23#0" expanded="true" />
+          </folding>
+        </state>
+      </provider>
+    </entry>
   </component>
 </project>

+ 2 - 0
lib/include/ModuleHTTP.h

@@ -15,6 +15,8 @@ namespace mdd{
     protected:
         bool connect();
         std::string str_to_json(const std::string& input);
+        bool updateInputs();
+        bool updateOutputs();
         void updateLayout();
 
     public:

+ 28 - 13
lib/src/ModuleHTTP.cpp

@@ -15,7 +15,6 @@ namespace mdd{
                                body.append(data, data_length);
                                return true;
                            });
-        //assert(res->body.empty());
         if(body.empty()){
             return false;
         }
@@ -47,7 +46,7 @@ namespace mdd{
         return str;
     }
 
-    void ModuleHTTP::updateLayout(){
+    bool ModuleHTTP::updateInputs() {
         Client cli(_id, _port);
 
         std::string body;
@@ -73,9 +72,13 @@ namespace mdd{
             val["value"] = inputs[index]["value"];
             addInput(inputs[index]["type"].get<std::string>(),val);
         }
+    }
+
+    bool ModuleHTTP::updateOutputs() {
+        Client cli(_id, _port);
 
-        body.clear();
-        res = cli.Get("/outputs",
+        std::string body;
+        auto res = cli.Get("/outputs",
                            [&](const char *data, size_t data_length) {
                                body.append(data, data_length);
                                return true;
@@ -100,11 +103,17 @@ namespace mdd{
         }
     }
 
+    void ModuleHTTP::updateLayout(){
+        updateInputs();
+        updateOutputs();
+    }
+
     ModuleHTTP::ModuleHTTP(std::string fname, std::string id, int port):
         _fname(fname),
         _id(id),
         _port(port)
     {
+        setType("HTTP");
         if(!fname.empty()){
             std::string command = "python3 " + fname+"&";
             system(command.c_str());
@@ -116,14 +125,20 @@ namespace mdd{
     }
 
     bool ModuleHTTP::update() {
-        updateLayout();
-        /*Client cli(_id, _port);
-        std::string outputs;
-        auto res = cli.Get("/update",
-                      [&](const char *data, size_t data_length) {
-                          outputs.append(data, data_length);
-                          return true;
-                      });
-                      */
+        Client cli(_id, _port);
+        json new_inputs;
+        for (int i = 0; i < getInputs().size(); ++i) {
+            new_inputs.push_back(getInput(i)->getValue());
+        }
+        std::string content = new_inputs.dump();
+        auto res = cli.Post("/update",content.size(),
+                            [&](size_t offset, size_t length, DataSink &sink) {
+                                sink.write(content.data() + offset, length);
+                                return true; // return 'false' if you want to cancel the request.
+                            },"application/json");
+        while(!connect()){
+            usleep(1000);
+        }
+        updateOutputs();
     }
 }

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

@@ -61,11 +61,12 @@ class MainHandler(tornado.web.RequestHandler, ABC):
     def post(self, param):
         if param == "update":
             if self.json_args is not None:
+                print("INFO: GET /" + param + "with body: " + self.json_args.dump())
                 counter = 0
                 for entity in self.json_args:
                     inputs[counter]['value'] = entity['value']
                     counter = counter + 1
-                update()
+            update()
             self.write(json.dumps(outputs))
         else:
             self.write("Error: POST /" + param)

+ 77 - 20
lib/test/test_ModuleHTTP.cpp

@@ -15,35 +15,63 @@ using namespace httplib;
 void serverThread()
 {
     Server svr;
+    json input;
+    json output;
+    std::string status = "ready";
 
-    svr.Get("/inputs", [](const Request& req, Response& res) {
-        json input_body;
-        for (int i = 0; i < 5; ++i) {
-            json entity;
-            entity["type"] = "INPUT";
-            entity["value"] = i;
-            input_body.push_back(entity);
-        }
-        res.set_content(input_body.dump(), "application/json");
+    for (int i = 0; i < 5; ++i) {
+        json entity;
+        entity["type"] = "INPUT";
+        entity["value"] = i;
+        input.push_back(entity);
+    }
+
+    for (int i = 0; i < 3; ++i) {
+        json entity;
+        entity["type"] = "OUTPUT";
+        entity["value"] = i*2;
+        output.push_back(entity);
+    }
+
+    svr.Get("/inputs", [&](const Request& req, Response& res) {
+        res.set_content(input.dump(), "application/json");
     });
 
-    svr.Get("/outputs", [](const Request& req, Response& res) {
-        json output_body;
-        for (int i = 0; i < 3; ++i) {
-            json entity;
-            entity["type"] = "OUTPUT";
-            entity["value"] = i*2;
-            output_body.push_back(entity);
-        }
-        res.set_content(output_body.dump(), "application/json");
+    svr.Get("/outputs", [&](const Request& req, Response& res) {
+        res.set_content(output.dump(), "application/json");
     });
 
-    svr.Get("/status", [](const Request& req, Response& res) {
+    svr.Get("/status", [&](const Request& req, Response& res) {
         json body;
-        body["status"] = "ready";
+        body["status"] = status;
+        std::cout << status << std::endl;
         res.set_content(body.dump(), "application/json");
     });
 
+    svr.Post("/update",
+            [&](const Request& req, Response& res, const ContentReader &content_reader) {
+                status = "updating...";
+                std::string body;
+                content_reader([&](const char *data, size_t data_length) {
+                    body.append(data, data_length);
+                    return true;
+                });
+                body = std::string(R"()") + body;
+                json inputs = json::parse(body.c_str());
+                for (int i = 0; i < inputs.size(); ++i) {
+                    input[i]["value"] = inputs[i]["value"];
+                }
+                output[0]["value"] = input[0]["value"].get<int>() + input[1]["value"].get<int>();
+                output[1]["value"] = input[2]["value"].get<int>() * input[2]["value"].get<int>();
+                output[2]["value"] = input[3]["value"].get<int>() - input[4]["value"].get<int>();
+                std::cout << output[0].dump() << std::endl;
+                std::cout << output[1].dump() << std::endl;
+                std::cout << output[2].dump() << std::endl;
+                res.set_content(output.dump(), "application/json");
+                status = "ready";
+             }
+    );
+
     svr.Get("/stop", [&](const Request& req, Response& res) {
         svr.stop();
     });
@@ -91,4 +119,33 @@ TEST(ModuleHTTP, updateLayout_extern){
     }
     Client cli("localhost",8888);
     cli.Get("/stop");
+}
+
+TEST(ModuleHTTP, update_intern){
+    std::thread server (serverThread);
+    usleep(500000);
+    ModuleHTTP module("", "localhost", 8888);
+    auto inputs_types = module.getInputs();
+    auto inputs_ids = module.getInputIDs();
+    for (int i = 0; i < 5; ++i) {
+        module.getInput(inputs_ids[i])->setDefaultValue()["value"] = 10-i;
+    }
+    module.update();
+
+    Client cli("localhost",8888);
+    cli.Get("/stop");
+    server.join();
+
+    inputs_types = module.getInputs();
+    inputs_ids = module.getInputIDs();
+    for (int i = 0; i < 5; ++i) {
+        EXPECT_EQ(inputs_types[i], "INPUT");
+        EXPECT_EQ(module.getInput(inputs_ids[i])->getValue()["value"].get<int>(), 10-i);
+    }
+
+    auto outputs_types = module.getOutputs();
+    auto outputs_ids = module.getOutputIDs();
+    EXPECT_EQ(module.getOutput(outputs_ids[0])->getValue()["value"].get<int>(), 19);
+    EXPECT_EQ(module.getOutput(outputs_ids[1])->getValue()["value"].get<int>(), 64);
+    EXPECT_EQ(module.getOutput(outputs_ids[2])->getValue()["value"].get<int>(), 1);
 }