Programme+libraires

Dependents:   Serveur_web_pt2 Serveur_web_pt2_V2_avec_index_html Serveur_web_pt2_index_commenter Serveur_web_pt2_index_commenter

Fork of HTTPServer by Donatien Garnier

Files at this revision

API Documentation at this revision

Comitter:
sedid
Date:
Tue Jul 03 12:00:10 2018 +0000
Parent:
6:d753966e4d97
Commit message:
Programme + librairies pour PT2 info2 du serveur web capteur par Sedid dupuis

Changed in this revision

LPC1768/services/http/server/HTTPServer.h Show annotated file Show diff for this revision Revisions of this file
LPC1768/services/http/server/impl/MyOwnHandler.h Show annotated file Show diff for this revision Revisions of this file
diff -r d753966e4d97 -r f88b734870ab LPC1768/services/http/server/HTTPServer.h
--- a/LPC1768/services/http/server/HTTPServer.h	Thu Aug 05 15:12:27 2010 +0000
+++ b/LPC1768/services/http/server/HTTPServer.h	Tue Jul 03 12:00:10 2018 +0000
@@ -100,5 +100,6 @@
 #include "impl/RPCHandler.h"
 #include "impl/FSHandler.h"
 #include "impl/SimpleHandler.h"
+#include "impl/MyOwnHandler.h"
 
 #endif
diff -r d753966e4d97 -r f88b734870ab LPC1768/services/http/server/impl/MyOwnHandler.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LPC1768/services/http/server/impl/MyOwnHandler.h	Tue Jul 03 12:00:10 2018 +0000
@@ -0,0 +1,63 @@
+#ifndef MYOWNHANDLER_H
+#define MYOWNHANDLER_H
+
+#include "../HTTPRequestHandler.h"
+float x,y;
+
+class MyOwnHandler : public HTTPRequestHandler
+{
+  public: 
+  MyOwnHandler(const char* rootPath, const char* path, TCPSocket* pTCPSocket)
+                            : HTTPRequestHandler(rootPath, path, pTCPSocket) {}
+  virtual ~MyOwnHandler() {}
+
+//protected:
+  static inline HTTPRequestHandler* inst(const char* rootPath,
+                                         const char* path, TCPSocket* pTCPSocket)
+                         { return new MyOwnHandler(rootPath, path, pTCPSocket); }
+
+  virtual void doGet();
+  virtual void doPost() {}
+  virtual void doHead() {}
+  
+  virtual void onReadable() {}
+  virtual void onWriteable() { close(); } // Data has been written,
+                                          //   we can close the connection
+  virtual void onClose() {}
+};
+
+void MyOwnHandler::doGet()
+{
+// To get request data, we use the method path()
+// We assume that path() will be:
+//       /variable
+// or    /variable value
+// Get variable string
+      int endVar = path().find_first_of('%', 1);
+      string variable = path().substr(1, endVar-1);
+// Get value string
+      string value;
+      if (endVar!=string::npos) value = path().substr(endVar+3, string::npos);
+// Get a pointer on the variable
+// The type of the variable must be float
+      float *ptr = NULL;
+      if (variable.compare("x")==0) ptr=&x;
+      else if (variable.compare("y")==0) ptr=&y;
+//    else if (variable.compare("variable")==0) ptr=&variable;
+// Get the float value and set the variable value
+      if ((ptr!=NULL)&&(!value.empty())) {
+          float v;
+          if (sscanf(value.c_str(), "%f", &v)!=EOF) *ptr=v;
+      }
+// Server response will be the value of the variable
+      char resp[20];
+      if (ptr!=NULL) {
+          sprintf(resp, "%f", *ptr);
+      } else {
+          sprintf(resp, "Unknown variable");
+      }
+      setContentLen( strlen(resp) );
+      respHeaders()["Connection"] = "close";
+      writeData(resp, strlen(resp));
+}
+ #endif
\ No newline at end of file