justin kim / httpServer_ntpsetting

Fork of httpServer by justin kim

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers FsHandler.h Source File

FsHandler.h

00001 /* FsHandler.h */
00002 /*
00003 Copyright (c) 2013 Henry Leinen (henry[dot]leinen [at] online [dot] de)
00004  
00005 Permission is hereby granted, free of charge, to any person obtaining a copy
00006 of this software and associated documentation files (the "Software"), to deal
00007 in the Software without restriction, including without limitation the rights
00008 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00009 copies of the Software, and to permit persons to whom the Software is
00010 furnished to do so, subject to the following conditions:
00011  
00012 The above copyright notice and this permission notice shall be included in
00013 all copies or substantial portions of the Software.
00014  
00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00016 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00017 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00018 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00019 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00020 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00021 THE SOFTWARE.
00022 */
00023 #ifndef __FSHANDLER_H__
00024 #define __FSHANDLER_H__
00025 
00026 #include "mbed.h"
00027 #include "HTTPRequestHandler.h"
00028 #include "HTTPConnection.h"
00029 #include "EthernetInterface.h"
00030 #include "SNTPClient.h"
00031 
00032 #include <map>
00033 #include <list>
00034 #include <string>
00035 
00036 /** class HTTPFsRequestHandler serves requests with file-system objects
00037 */
00038 class HTTPFsRequestHandler : public HTTPRequestHandler
00039 {
00040         std::string m_rootPath;
00041         std::string m_localPath;
00042 
00043     public:
00044 
00045         /** constructor for HTTPFsRequestHandler object and stores the request related data locally. 
00046         * the request handling will be initiated from within the constructor.
00047         * @param rootPath : The path under which the handler was registered.
00048         * @param localPath : The path which is relative to the registered file system root.
00049         * @param Msg : Message request information that comes with the request.
00050         * @param Tcp : The socket connection for communicating with the client.
00051         */
00052         HTTPFsRequestHandler(const char* rootPath, const char* localPath, HTTPConnection::HTTPMessage& Msg, TCPSocketConnection& Tcp);
00053         
00054         /** Destructor 
00055         */
00056         virtual ~HTTPFsRequestHandler();
00057   
00058         /** static creation function for this object.
00059         */
00060         static inline HTTPRequestHandler* create(const char* rootPath, const char* localPath, HTTPConnection::HTTPMessage& msg, TCPSocketConnection& tcp) { return new HTTPFsRequestHandler(rootPath, localPath, msg, tcp); }
00061               
00062         /** Handler function to serve GET requests
00063         */
00064         virtual int handleGetRequest();
00065         
00066         /** Handler function to serve PUT requests
00067         */
00068         virtual int handlePutRequest();
00069         
00070         /** Handler function to serve POST requests
00071         */
00072         virtual int handlePostRequest();
00073 
00074         /** Map to register different file system types and associate them with different root paths
00075         */
00076         static std::map<const char*, const char*> m_fsMap;
00077         
00078         /** static function to register a new file system type with a logical root path
00079         */
00080         static void mount(const char* requestPath, const char* localPath) { m_fsMap[requestPath] = localPath; }
00081         
00082         //Test
00083         //static std::list<EthernetInterface> m_eth_list;
00084         static std::map<int, EthernetInterface*> m_eth_list;
00085         static void mount_eth(EthernetInterface* eth) { m_eth_list[0] = eth; }
00086         
00087         /** Parse a uri string for uri file name and argument:value pairs
00088         */
00089         int parseUriArgs(string uri, map<string, string>& args);
00090         
00091         uint32_t get_http_param_value(char* param_name);
00092 };
00093 
00094 extern datetime ntptime;
00095 extern PwmOut myservo;
00096 #endif // __FSHANDLER_H__