this will take a image from C328 serial camera and store those images in mbed flash as html and this html page is uploaded into the server at ip:192.168.1.2
lwip/HTTPServer/HTTPStaticPage.h@0:e1a0471e5ffb, 2010-12-15 (annotated)
- Committer:
- mitesh2patel
- Date:
- Wed Dec 15 15:01:56 2010 +0000
- Revision:
- 0:e1a0471e5ffb
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mitesh2patel | 0:e1a0471e5ffb | 1 | #ifndef HTTPSTATICPAGE_H |
mitesh2patel | 0:e1a0471e5ffb | 2 | #define HTTPSTATICPAGE_H |
mitesh2patel | 0:e1a0471e5ffb | 3 | |
mitesh2patel | 0:e1a0471e5ffb | 4 | #include "HTTPServer.h" |
mitesh2patel | 0:e1a0471e5ffb | 5 | |
mitesh2patel | 0:e1a0471e5ffb | 6 | /** |
mitesh2patel | 0:e1a0471e5ffb | 7 | * A datastorage helper for the HTTPStaticPage class. |
mitesh2patel | 0:e1a0471e5ffb | 8 | * Stores only the left upload size. |
mitesh2patel | 0:e1a0471e5ffb | 9 | */ |
mitesh2patel | 0:e1a0471e5ffb | 10 | class HTTPStaticPageData : public HTTPData { |
mitesh2patel | 0:e1a0471e5ffb | 11 | public: int left; |
mitesh2patel | 0:e1a0471e5ffb | 12 | }; |
mitesh2patel | 0:e1a0471e5ffb | 13 | |
mitesh2patel | 0:e1a0471e5ffb | 14 | /** |
mitesh2patel | 0:e1a0471e5ffb | 15 | * This class Provide a Handler to send Static HTTP Pages from the bin file. |
mitesh2patel | 0:e1a0471e5ffb | 16 | */ |
mitesh2patel | 0:e1a0471e5ffb | 17 | class HTTPStaticPage : public HTTPHandler { |
mitesh2patel | 0:e1a0471e5ffb | 18 | public: |
mitesh2patel | 0:e1a0471e5ffb | 19 | /** |
mitesh2patel | 0:e1a0471e5ffb | 20 | * Constructer takes the pagename and the pagedata. |
mitesh2patel | 0:e1a0471e5ffb | 21 | * As long as the pagedata is NULL terminated you have not to tell the data length. |
mitesh2patel | 0:e1a0471e5ffb | 22 | * But if you want to send binary data you should tell us the size. |
mitesh2patel | 0:e1a0471e5ffb | 23 | */ |
mitesh2patel | 0:e1a0471e5ffb | 24 | HTTPStaticPage(const char *path, const char *page, int length = 0) |
mitesh2patel | 0:e1a0471e5ffb | 25 | : HTTPHandler(path), _page(page) { |
mitesh2patel | 0:e1a0471e5ffb | 26 | _size = (length)?length:strlen(_page); |
mitesh2patel | 0:e1a0471e5ffb | 27 | } |
mitesh2patel | 0:e1a0471e5ffb | 28 | |
mitesh2patel | 0:e1a0471e5ffb | 29 | HTTPStaticPage(HTTPServer *server, const char *path, const char *page, int length = 0) |
mitesh2patel | 0:e1a0471e5ffb | 30 | : HTTPHandler(path), _page(page) { |
mitesh2patel | 0:e1a0471e5ffb | 31 | _size = (length)?length:strlen(_page); |
mitesh2patel | 0:e1a0471e5ffb | 32 | server->addHandler(this); |
mitesh2patel | 0:e1a0471e5ffb | 33 | } |
mitesh2patel | 0:e1a0471e5ffb | 34 | |
mitesh2patel | 0:e1a0471e5ffb | 35 | private: |
mitesh2patel | 0:e1a0471e5ffb | 36 | /** |
mitesh2patel | 0:e1a0471e5ffb | 37 | * A this Static Page is requested! |
mitesh2patel | 0:e1a0471e5ffb | 38 | * Prepare a datastorage helper "HTTPStaticPageHelper" to store the left data size. |
mitesh2patel | 0:e1a0471e5ffb | 39 | * And return HTTP_OK |
mitesh2patel | 0:e1a0471e5ffb | 40 | */ |
mitesh2patel | 0:e1a0471e5ffb | 41 | virtual HTTPStatus init(HTTPConnection *con) const { |
mitesh2patel | 0:e1a0471e5ffb | 42 | HTTPStaticPageData *data = new HTTPStaticPageData(); |
mitesh2patel | 0:e1a0471e5ffb | 43 | con->data = data; |
mitesh2patel | 0:e1a0471e5ffb | 44 | data->left = _size; |
mitesh2patel | 0:e1a0471e5ffb | 45 | con->setLength(_size); |
mitesh2patel | 0:e1a0471e5ffb | 46 | return HTTP_OK; |
mitesh2patel | 0:e1a0471e5ffb | 47 | } |
mitesh2patel | 0:e1a0471e5ffb | 48 | |
mitesh2patel | 0:e1a0471e5ffb | 49 | /** |
mitesh2patel | 0:e1a0471e5ffb | 50 | * Send the maximum data out to the client. |
mitesh2patel | 0:e1a0471e5ffb | 51 | * If the file is complete transmitted close connection by returning HTTP_SuccessEnded |
mitesh2patel | 0:e1a0471e5ffb | 52 | */ |
mitesh2patel | 0:e1a0471e5ffb | 53 | virtual HTTPHandle send(HTTPConnection *con, int maximum) const { |
mitesh2patel | 0:e1a0471e5ffb | 54 | HTTPStaticPageData *data = static_cast<HTTPStaticPageData *>(con->data); |
mitesh2patel | 0:e1a0471e5ffb | 55 | int len = min(maximum, data->left); |
mitesh2patel | 0:e1a0471e5ffb | 56 | err_t err; |
mitesh2patel | 0:e1a0471e5ffb | 57 | |
mitesh2patel | 0:e1a0471e5ffb | 58 | do { |
mitesh2patel | 0:e1a0471e5ffb | 59 | err = con->write((void*)&_page[_size - data->left], len, 1); |
mitesh2patel | 0:e1a0471e5ffb | 60 | if(err == ERR_MEM) { |
mitesh2patel | 0:e1a0471e5ffb | 61 | len >>= 1; |
mitesh2patel | 0:e1a0471e5ffb | 62 | } |
mitesh2patel | 0:e1a0471e5ffb | 63 | } while(err == ERR_MEM && len > 1); |
mitesh2patel | 0:e1a0471e5ffb | 64 | if(err == ERR_OK) { |
mitesh2patel | 0:e1a0471e5ffb | 65 | data->left -= len; |
mitesh2patel | 0:e1a0471e5ffb | 66 | } |
mitesh2patel | 0:e1a0471e5ffb | 67 | |
mitesh2patel | 0:e1a0471e5ffb | 68 | return (data->left)? HTTP_Success : HTTP_SuccessEnded; |
mitesh2patel | 0:e1a0471e5ffb | 69 | } |
mitesh2patel | 0:e1a0471e5ffb | 70 | |
mitesh2patel | 0:e1a0471e5ffb | 71 | /** Pointer to the page data */ |
mitesh2patel | 0:e1a0471e5ffb | 72 | const char *_page; |
mitesh2patel | 0:e1a0471e5ffb | 73 | |
mitesh2patel | 0:e1a0471e5ffb | 74 | /** page data size*/ |
mitesh2patel | 0:e1a0471e5ffb | 75 | int _size; |
mitesh2patel | 0:e1a0471e5ffb | 76 | }; |
mitesh2patel | 0:e1a0471e5ffb | 77 | |
mitesh2patel | 0:e1a0471e5ffb | 78 | #endif |