Give water to plants if dry amd pla meanwhile music the music vou can define with note length bind and breake also select several instruments for the sound

Dependencies:   mbed

Committer:
helmut
Date:
Wed Sep 19 14:16:56 2012 +0000
Revision:
0:5150b09127e3
plays mostly music that you can do with notes length breakes and bind; Some already defined; Tool is to start a pump for water to give plant is too dry.; Meanwhie plays music the most part of all

Who changed what in which revision?

UserRevisionLine numberNew contents of line
helmut 0:5150b09127e3 1
helmut 0:5150b09127e3 2 /*
helmut 0:5150b09127e3 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
helmut 0:5150b09127e3 4
helmut 0:5150b09127e3 5 Permission is hereby granted, free of charge, to any person obtaining a copy
helmut 0:5150b09127e3 6 of this software and associated documentation files (the "Software"), to deal
helmut 0:5150b09127e3 7 in the Software without restriction, including without limitation the rights
helmut 0:5150b09127e3 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
helmut 0:5150b09127e3 9 copies of the Software, and to permit persons to whom the Software is
helmut 0:5150b09127e3 10 furnished to do so, subject to the following conditions:
helmut 0:5150b09127e3 11
helmut 0:5150b09127e3 12 The above copyright notice and this permission notice shall be included in
helmut 0:5150b09127e3 13 all copies or substantial portions of the Software.
helmut 0:5150b09127e3 14
helmut 0:5150b09127e3 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
helmut 0:5150b09127e3 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
helmut 0:5150b09127e3 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
helmut 0:5150b09127e3 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
helmut 0:5150b09127e3 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
helmut 0:5150b09127e3 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
helmut 0:5150b09127e3 21 THE SOFTWARE.
helmut 0:5150b09127e3 22 */
helmut 0:5150b09127e3 23
helmut 0:5150b09127e3 24 /** \file
helmut 0:5150b09127e3 25 HTTP Server header file
helmut 0:5150b09127e3 26 */
helmut 0:5150b09127e3 27
helmut 0:5150b09127e3 28 #ifndef HTTP_SERVER_H
helmut 0:5150b09127e3 29 #define HTTP_SERVER_H
helmut 0:5150b09127e3 30
helmut 0:5150b09127e3 31 class HTTPRequestHandler;
helmut 0:5150b09127e3 32 class HTTPRequestDispatcher;
helmut 0:5150b09127e3 33
helmut 0:5150b09127e3 34 #include "core/net.h"
helmut 0:5150b09127e3 35 #include "HTTPRequestHandler.h"
helmut 0:5150b09127e3 36 #include "HTTPRequestDispatcher.h"
helmut 0:5150b09127e3 37
helmut 0:5150b09127e3 38 #include <string>
helmut 0:5150b09127e3 39 using std::string;
helmut 0:5150b09127e3 40
helmut 0:5150b09127e3 41 #include <map>
helmut 0:5150b09127e3 42 using std::map;
helmut 0:5150b09127e3 43
helmut 0:5150b09127e3 44 ///A simple HTTP server implementation
helmut 0:5150b09127e3 45 /**
helmut 0:5150b09127e3 46 The HTTPServer is composed of:
helmut 0:5150b09127e3 47 - The actual server (HTTPServer)
helmut 0:5150b09127e3 48 - A request dispatcher, instanciated on each request (HTTPRequestDispatcher)
helmut 0:5150b09127e3 49 - Request handlers instanciated by the dispatcher(deriving from HTTPRequestHandler)
helmut 0:5150b09127e3 50 */
helmut 0:5150b09127e3 51 class HTTPServer
helmut 0:5150b09127e3 52 {
helmut 0:5150b09127e3 53 public:
helmut 0:5150b09127e3 54 ///Instantiates the HTTP Server
helmut 0:5150b09127e3 55 HTTPServer();
helmut 0:5150b09127e3 56 ~HTTPServer();
helmut 0:5150b09127e3 57
helmut 0:5150b09127e3 58 struct handlersComp //Used to order handlers in the right way
helmut 0:5150b09127e3 59 {
helmut 0:5150b09127e3 60 bool operator() (const string& handler1, const string& handler2) const
helmut 0:5150b09127e3 61 {
helmut 0:5150b09127e3 62 //The first handler is longer than the second one
helmut 0:5150b09127e3 63 if (handler1.length() > handler2.length())
helmut 0:5150b09127e3 64 return true; //Returns true if handler1 is to appear before handler2
helmut 0:5150b09127e3 65 else if (handler1.length() < handler2.length())
helmut 0:5150b09127e3 66 return false;
helmut 0:5150b09127e3 67 else //To avoid the == case, sort now by address
helmut 0:5150b09127e3 68 return ((&handler1)>(&handler2));
helmut 0:5150b09127e3 69 }
helmut 0:5150b09127e3 70 };
helmut 0:5150b09127e3 71
helmut 0:5150b09127e3 72 ///Adds a handler
helmut 0:5150b09127e3 73 /**
helmut 0:5150b09127e3 74 Appends a handler to the handlers list
helmut 0:5150b09127e3 75 @param T : class which will be instanciated to serve these requests
helmut 0:5150b09127e3 76 @param path : requests starting with this path will be served using this handler
helmut 0:5150b09127e3 77 */
helmut 0:5150b09127e3 78 template<typename T>
helmut 0:5150b09127e3 79 void addHandler(const char* path) //Template decl in header
helmut 0:5150b09127e3 80 { m_lpHandlers[path] = &T::inst; }
helmut 0:5150b09127e3 81
helmut 0:5150b09127e3 82 ///Starts listening
helmut 0:5150b09127e3 83 /**
helmut 0:5150b09127e3 84 Binds server to a specific port and starts listening
helmut 0:5150b09127e3 85 @param port : port on which to listen for incoming connections
helmut 0:5150b09127e3 86 */
helmut 0:5150b09127e3 87 void bind(int port = 80);
helmut 0:5150b09127e3 88
helmut 0:5150b09127e3 89 private:
helmut 0:5150b09127e3 90 friend class HTTPRequestDispatcher;
helmut 0:5150b09127e3 91
helmut 0:5150b09127e3 92 void onTCPSocketEvent(TCPSocketEvent e);
helmut 0:5150b09127e3 93
helmut 0:5150b09127e3 94 TCPSocket* m_pTCPSocket;
helmut 0:5150b09127e3 95 map< string, HTTPRequestHandler*(*)(const char*, const char*, TCPSocket*), handlersComp > m_lpHandlers;
helmut 0:5150b09127e3 96
helmut 0:5150b09127e3 97 };
helmut 0:5150b09127e3 98
helmut 0:5150b09127e3 99 //Including handlers here for more convenience
helmut 0:5150b09127e3 100 #include "impl/RPCHandler.h"
helmut 0:5150b09127e3 101 #include "impl/FSHandler.h"
helmut 0:5150b09127e3 102 #include "impl/SimpleHandler.h"
helmut 0:5150b09127e3 103
helmut 0:5150b09127e3 104 #endif