Code snipet

Dependencies:   NySDFileSystem libMiMic mbed-rtos mbed

Fork of AsyncHttpdSample by Ryo Iizuka

Files at this revision

API Documentation at this revision

Comitter:
nyatla
Date:
Sat Nov 16 01:23:18 2013 +0000
Parent:
7:8d030ae8ddc3
Child:
9:c6427be12f0d
Commit message:
update libraries; fix some problem in main.

Changed in this revision

NySDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
libMiMic.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/NySDFileSystem.lib	Thu Jul 11 01:11:26 2013 +0000
+++ b/NySDFileSystem.lib	Sat Nov 16 01:23:18 2013 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/nyatla/code/NySDFileSystem/#22ce3449b224
+http://mbed.org/users/nyatla/code/NySDFileSystem/#b2ca0e66c1f7
--- a/libMiMic.lib	Thu Jul 11 01:11:26 2013 +0000
+++ b/libMiMic.lib	Sat Nov 16 01:23:18 2013 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/nyatla/code/libMiMic/#74390edbe66c
+http://mbed.org/users/nyatla/code/libMiMic/#0a24ad966876
--- a/main.cpp	Thu Jul 11 01:11:26 2013 +0000
+++ b/main.cpp	Sat Nov 16 01:23:18 2013 +0000
@@ -1,32 +1,41 @@
 #include "mimic.h"
+#include "rtos.h"
+/**
+ * @file
+ * This program is a sample which starts httpd by a subtask.
+ * The value counted up by a main thread is returned by Httpd of a subtask.
+ */
  
  
- LocalFileSystem2 lf("local");
-/**
- * 
- */
+static unsigned int counter=0;
+
+
+LocalFileSystem2 lf("local");
 class SimpleHttpd:public MiMic::Httpd
 {
 private:
     ModUrl modurl; //basic URL parser
 public:
-    SimpleHttpd(NetConfig& i_cfg):Httpd(i_cfg._inst.services.http_port)
+    SimpleHttpd(NetConfig& i_cfg):Httpd(i_cfg.getHttpPort())
     {
     }
     virtual void onRequest(HttpdConnection& i_connection)
     {
         char url[32];
         int method;
+        unsigned int v;
+        i_connection.lockHttpd();
+        v=counter;
+        i_connection.unlockHttpd();
         
-        //
-        //write Http handler(s) here!
-        //
-        
+
         //call ModUrl module.
         if(this->modurl.execute(i_connection,url,32,&method)){
             //send 200 OK and requested URL
             i_connection.sendHeader(200,"text/html",NULL);
-            i_connection.sendBodyF("<html><body>Your Request path is %s.</body></html>",url);
+            //show current counter value.
+            i_connection.sendBodyF(
+                "<html><body><h1>Asynchronous test</h1><div>Counter: %u</body></html>",v);
             return;
         }
         
@@ -34,6 +43,7 @@
     }
 };
 
+
 NetConfig cfg; //create network configulation
 int main()
 {
@@ -44,7 +54,13 @@
     
     SimpleHttpd httpd(cfg); //create a httpd instance.
     net.start(cfg);
-    httpd.loop();  //start httpd loop.
+    httpd.loopTask();  //start httpd loop with new task
+    for(;;){
+        httpd.lock();//prepare to access shared resource
+        counter++;
+        httpd.unlock();//release a lock.
+        Thread::wait(1000);
+    }
     return 0;
 }
  
\ No newline at end of file