HttpServer Library for "mbed-os" which added a snapshot handler.

Dependents:   GR-PEACH-webcam GR-Boards_WebCamera GR-Boards_WebCamera GR-Boards_WebCamera

Fork of HttpServer_snapshot by Renesas

Revision:
11:0700755d64ae
Parent:
10:4ab2f287d06d
Child:
13:d3571c244759
--- a/HTTPServer.h	Tue Apr 19 02:21:29 2016 +0000
+++ b/HTTPServer.h	Fri Oct 28 06:15:29 2016 +0000
@@ -16,15 +16,10 @@
 #include "HTTPRequestHandler.h"
 #include "rtos.h"
 #include "mbed.h"
-#include "EthernetInterface.h"
-//#include "HTTPRequestDispatcher.h"
-
-//#include "dbg/dbg.h"
 
 #define THREAD_MAX 5
 Thread *threads[THREAD_MAX];
 Thread *xthread;
-//#include "HTTPServer2.h"
 
 struct handlersComp { //Used to order handlers in the right way
     bool operator() (const string& handler1, const string& handler2) const {
@@ -38,7 +33,7 @@
     }
 };
 
-map< string, HTTPRequestHandler*(*)(const char*, const char* , TCPSocketConnection* ), handlersComp > m_lpHandlers;
+map< string, HTTPRequestHandler*(*)(const char*, const char* , TCPSocket* ), handlersComp > m_lpHandlers;
 template<typename T>
 void HTTPServerAddHandler(const char* path)  //Template decl in header
 {
@@ -52,7 +47,7 @@
     HTTP_HEAD
 };
 
-bool getRequest(TCPSocketConnection* client,string* path, string* meth)
+bool getRequest(TCPSocket* client, string* path, string* meth)
 {
     char req[128];
     char c_path[128];
@@ -63,7 +58,7 @@
     int ret;
     int len = 0;
     for(int i = 0; i < maxLen - 1; i++) {
-        ret = client->receive(p, 1);
+        ret = client->recv(p, 1);
         if(!ret) {
             break;
         }
@@ -89,7 +84,7 @@
     return true;
 }
 
-void dispatchRequest(TCPSocketConnection* client)
+void dispatchRequest(TCPSocket* client)
 {
     string path;
     string meth;
@@ -129,7 +124,7 @@
 #ifdef _DEBUG_HTTP_SERVER_H
     printf("Looking for a handler\r\n");
 #endif
-    map< string, HTTPRequestHandler*(*)(const char*, const char*, TCPSocketConnection*), handlersComp >::iterator it;
+    map< string, HTTPRequestHandler*(*)(const char*, const char*, TCPSocket*), handlersComp >::iterator it;
     int root_len = 0;
     for (it = m_lpHandlers.begin(); it != m_lpHandlers.end(); it++) {
 #ifdef _DEBUG_HTTP_SERVER_H
@@ -180,7 +175,7 @@
     }
     delete pHdlr;
     // delete client;
-    // delete m_pTCPSocketConnection;
+    // delete m_pTCPSocket;
 #ifdef _DEBUG_HTTP_SERVER_H
     printf("(dispatcherRequest)return\r\n");
 #endif
@@ -192,7 +187,7 @@
 #ifdef _DEBUG_HTTP_SERVER_H
     printf("HTTPServerChiled Start......\r\n");
 #endif
-    TCPSocketConnection* client = (TCPSocketConnection*)arg;
+    TCPSocket* client = (TCPSocket*)arg;
 
     for (;;) {
 #ifdef _DEBUG_HTTP_SERVER_H
@@ -203,7 +198,6 @@
         printf("(HTTPServer.h<HTTPServerChild>)Close %s\r\n", client->get_address());
 #endif
         client->close();
-        client->reset_address();
         //delete client;
         Thread::signal_wait(1);
     }
@@ -211,7 +205,7 @@
 
 void HTTPServerCloser (void const *arg)
 {
-    TCPSocketConnection *client = (TCPSocketConnection*)arg;
+    TCPSocket *client = (TCPSocket*)arg;
 
     for (;;) {
         client->close();
@@ -222,18 +216,18 @@
     }
 }
 
-void HTTPServerStart(int port = 80)
+void HTTPServerStart(NetworkInterface *net, int port = 80)
 {
     int i, t = 0;
-    TCPSocketConnection clients[THREAD_MAX];
-    TCPSocketConnection xclient;
+    TCPSocket clients[THREAD_MAX];
+    TCPSocket xclient;
 
     for (i = 0; i < THREAD_MAX; i ++) {
         threads[i] = NULL;
     }
     xthread = NULL;
 
-    TCPSocketServer server;
+    TCPServer server(net);
     server.bind(port);
     server.listen();
     // server.set_blocking(false);
@@ -245,7 +239,7 @@
         printf("**Start Loop** \r\n");
 #endif
         if (t >= 0) {
-            if(server.accept(clients[t])==0) {
+            if(server.accept(&clients[t])==0) {
                 // fork child process
                 if (threads[t]) {
                     threads[t]->signal_set(1);
@@ -257,7 +251,7 @@
 #endif
             }
         } else {
-            if(server.accept(xclient)==0) {
+            if(server.accept(&xclient)==0) {
                 // closer process
                 if (xthread) {
                     xthread->signal_set(1);
@@ -273,7 +267,7 @@
         t = -1;
         for (i = 0; i < THREAD_MAX; i ++) {
             if ((threads[i] == NULL)
-             || ((threads[i]->get_state() == Thread::WaitingAnd) && (*clients[i].get_address() == 0))) {
+             || ((threads[i]->get_state() == Thread::WaitingAnd))) {
                 if (t < 0) t = i; // next empty thread
             }
         }