Single instance HTTP Server using new Ethernet Interface. Blocking mode only; this improved stability, but the HTTP server must be started from a separate thread.

Dependents:   SmartLight

Fork of HTTPServer by Henry Leinen

Files at this revision

API Documentation at this revision

Comitter:
leihen
Date:
Sat Aug 17 16:17:55 2013 +0000
Parent:
15:909dcf44c3db
Child:
17:d7186c696729
Commit message:
- Removed old Debug message helper macros and replaced them with new hl_debug.h macros.
; - Renamed debug.h file to hl_debug.h to avoid conflict with EthernetInterface.
; - Fixed incorrectly used debug macro where an ERR was used instead of an INFO

Changed in this revision

HTTPConnection.cpp Show annotated file Show diff for this revision Revisions of this file
HTTPRequestHandler.cpp Show annotated file Show diff for this revision Revisions of this file
HTTPServer.cpp Show annotated file Show diff for this revision Revisions of this file
Handler/FsHandler.cpp Show annotated file Show diff for this revision Revisions of this file
Handler/RpcHandler.cpp Show annotated file Show diff for this revision Revisions of this file
debug.h Show diff for this revision Revisions of this file
hl_debug.h Show annotated file Show diff for this revision Revisions of this file
--- a/HTTPConnection.cpp	Sat Aug 17 15:34:07 2013 +0000
+++ b/HTTPConnection.cpp	Sat Aug 17 16:17:55 2013 +0000
@@ -3,7 +3,7 @@
 #include "mbed.h"
 #include "HTTPConnection.h"
 #define DEBUG
-#include "debug.h"
+#include "hl_debug.h"
 
 #include <vector>
 using std::vector;
--- a/HTTPRequestHandler.cpp	Sat Aug 17 15:34:07 2013 +0000
+++ b/HTTPRequestHandler.cpp	Sat Aug 17 16:17:55 2013 +0000
@@ -2,7 +2,7 @@
 #include "mbed.h"
 #include "HTTPRequestHandler.h"
 #define DEBUG
-#include "debug.h"
+#include "hl_debug.h"
 #include <ctype.h>
 
 
--- a/HTTPServer.cpp	Sat Aug 17 15:34:07 2013 +0000
+++ b/HTTPServer.cpp	Sat Aug 17 16:17:55 2013 +0000
@@ -1,16 +1,8 @@
 #include "mbed.h"
 #include "HTTPServer.h"
 #define DEBUG
-#include "debug.h"
-
-#define _DEBUG      1
+#include "hl_debug.h"
 
-#ifdef _DEBUG
-DigitalOut led1(LED1);
-DigitalOut led2(LED2);
-DigitalOut led3(LED3);
-DigitalOut led4(LED4);
-#endif
 
 
 /* Constructor */
@@ -93,7 +85,7 @@
         return false;
     }
 
-    ERR("Connected !");
+    INFO("Connected !");
     //  set into non blocking operation
     m_Svr.set_blocking(false, 100);
 
@@ -103,34 +95,15 @@
 
 int HTTPServer::poll(bool blocking)
 {
-#ifdef _DEBUG
-    led4 = 1;   //  Indicate we are waiting for a new connection
-#endif
     //  This thread basically checks if there is a new incoming connection.
     //  If so , a new HTTPConnection is created and the connection thread is started.
     TCPSocketConnection Clnt;
     if (m_Svr.accept(Clnt) < 0) {
-#ifdef _DEBUG
-        led4 = 0;
-        led3 = 1;   //  ERROR
-        led2 = 0;
-        led1 = 0;
-#endif
         return -1;
     }
 
     //   a new connection was received
     INFO("Client (IP=%s) is connected !\n", Clnt.get_address());
-#ifdef _DEBUG
-    led4 = 0;
-    led3 = 0;
-    led2 = 0;
-#endif
-
-#ifdef _DEBUG
-    led3 = 1;
-    led2 = 1;
-#endif
     HTTPConnection con(Clnt);
     int c = con.poll();
     if (c == 0) {
@@ -141,11 +114,6 @@
     if (c == -1) {
 //        break;
     }
-#ifdef _DEBUG
-    led2 = 0;
-    led3 = 0;
-#endif
-
 
     INFO("Leaving polling thread");
     return 0;
--- a/Handler/FsHandler.cpp	Sat Aug 17 15:34:07 2013 +0000
+++ b/Handler/FsHandler.cpp	Sat Aug 17 16:17:55 2013 +0000
@@ -2,7 +2,7 @@
 #include "mbed.h"
 #include "FsHandler.h"
 #define DEBUG
-#include "debug.h"
+#include "hl_debug.h"
 
 
 
--- a/Handler/RpcHandler.cpp	Sat Aug 17 15:34:07 2013 +0000
+++ b/Handler/RpcHandler.cpp	Sat Aug 17 16:17:55 2013 +0000
@@ -4,17 +4,8 @@
 #include "mbed_rpc.h"
 
 
-#define _DEBUG 0
-
-#if (_DEBUG && !defined(TARGET_LPC11U24))
-#define INFO(x, ...) std::printf("[HTTPRpcHandler : DBG]"x"\r\n", ##__VA_ARGS__);
-#define WARN(x, ...) std::printf("[HTTPRpcHandler : DBG]"x"\r\n", ##__VA_ARGS__);
-#define ERR(x, ...) std::printf("[HTTPRpcHandler : DBG]"x"\r\n", ##__VA_ARGS__);
-#else
-#define INFO(x, ...)
-#define WARN(x, ...)
-#define ERR(x, ...)
-#endif
+#define DEBUG 1
+#include "hl_debug.h"
 
 RPC rpc("rpc");
 
--- a/debug.h	Sat Aug 17 15:34:07 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,16 +0,0 @@
-#ifndef __DEBUG_H__
-#define __DEBUG_H__
-
-
-#ifdef DEBUG
-#define INFO(x, ...) std::printf("[INFO: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
-#define WARN(x, ...) std::printf("[WARN: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
-#define ERR(x, ...) std::printf("[ERR: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
-#else
-#define INFO(x, ...)
-#define WARN(x, ...)
-#define ERR(x, ...)
-#endif
-
-
-#endif //   __DEBUG_H__#ifndef __DEBUG_H__
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hl_debug.h	Sat Aug 17 16:17:55 2013 +0000
@@ -0,0 +1,16 @@
+#ifndef __DEBUG_H__
+#define __DEBUG_H__
+
+
+#ifdef DEBUG
+#define INFO(x, ...) std::printf("[INFO: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
+#define WARN(x, ...) std::printf("[WARN: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
+#define ERR(x, ...) std::printf("[ERR: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
+#else
+#define INFO(x, ...)
+#define WARN(x, ...)
+#define ERR(x, ...)
+#endif
+
+
+#endif //   __DEBUG_H__#ifndef __DEBUG_H__