kenji tanaka / Mbed 2 deprecated Sha1Test

Dependencies:   mbed

Committer:
gtk2k
Date:
Sun Apr 29 03:58:08 2012 +0000
Revision:
0:74be48b504a5
WebSocketServer

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gtk2k 0:74be48b504a5 1
gtk2k 0:74be48b504a5 2 /*
gtk2k 0:74be48b504a5 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
gtk2k 0:74be48b504a5 4
gtk2k 0:74be48b504a5 5 Permission is hereby granted, free of charge, to any person obtaining a copy
gtk2k 0:74be48b504a5 6 of this software and associated documentation files (the "Software"), to deal
gtk2k 0:74be48b504a5 7 in the Software without restriction, including without limitation the rights
gtk2k 0:74be48b504a5 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
gtk2k 0:74be48b504a5 9 copies of the Software, and to permit persons to whom the Software is
gtk2k 0:74be48b504a5 10 furnished to do so, subject to the following conditions:
gtk2k 0:74be48b504a5 11
gtk2k 0:74be48b504a5 12 The above copyright notice and this permission notice shall be included in
gtk2k 0:74be48b504a5 13 all copies or substantial portions of the Software.
gtk2k 0:74be48b504a5 14
gtk2k 0:74be48b504a5 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
gtk2k 0:74be48b504a5 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
gtk2k 0:74be48b504a5 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
gtk2k 0:74be48b504a5 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
gtk2k 0:74be48b504a5 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
gtk2k 0:74be48b504a5 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
gtk2k 0:74be48b504a5 21 THE SOFTWARE.
gtk2k 0:74be48b504a5 22 */
gtk2k 0:74be48b504a5 23
gtk2k 0:74be48b504a5 24 /** \file
gtk2k 0:74be48b504a5 25 UDP Socket header file
gtk2k 0:74be48b504a5 26 */
gtk2k 0:74be48b504a5 27
gtk2k 0:74be48b504a5 28 #ifndef UDPSOCKET_H
gtk2k 0:74be48b504a5 29 #define UDPSOCKET_H
gtk2k 0:74be48b504a5 30
gtk2k 0:74be48b504a5 31 #include "core/net.h"
gtk2k 0:74be48b504a5 32 #include "core/host.h"
gtk2k 0:74be48b504a5 33 //Essentially it is a safe interface to NetUdpSocket
gtk2k 0:74be48b504a5 34
gtk2k 0:74be48b504a5 35 ///UDP Socket error codes
gtk2k 0:74be48b504a5 36 enum UDPSocketErr
gtk2k 0:74be48b504a5 37 {
gtk2k 0:74be48b504a5 38 __UDPSOCKET_MIN = -0xFFFF,
gtk2k 0:74be48b504a5 39 UDPSOCKET_SETUP, ///<UDPSocket not properly configured
gtk2k 0:74be48b504a5 40 UDPSOCKET_IF, ///<Interface has problems, does not exist or is not initialized
gtk2k 0:74be48b504a5 41 UDPSOCKET_MEM, ///<Not enough mem
gtk2k 0:74be48b504a5 42 UDPSOCKET_INUSE, ///<Interface / Port is in use
gtk2k 0:74be48b504a5 43 //...
gtk2k 0:74be48b504a5 44 UDPSOCKET_OK = 0 ///<Success
gtk2k 0:74be48b504a5 45 };
gtk2k 0:74be48b504a5 46
gtk2k 0:74be48b504a5 47 ///UDP Socket Event(s)
gtk2k 0:74be48b504a5 48 enum UDPSocketEvent //Only one event here for now, but keeps that model in case we need to implement some others
gtk2k 0:74be48b504a5 49 {
gtk2k 0:74be48b504a5 50 UDPSOCKET_READABLE, ///<Data in buf
gtk2k 0:74be48b504a5 51 };
gtk2k 0:74be48b504a5 52
gtk2k 0:74be48b504a5 53 class NetUdpSocket;
gtk2k 0:74be48b504a5 54 enum NetUdpSocketEvent;
gtk2k 0:74be48b504a5 55
gtk2k 0:74be48b504a5 56 ///This is a simple UDP Socket class
gtk2k 0:74be48b504a5 57 /**
gtk2k 0:74be48b504a5 58 This class exposes an API to deal with UDP Sockets
gtk2k 0:74be48b504a5 59 */
gtk2k 0:74be48b504a5 60 class UDPSocket
gtk2k 0:74be48b504a5 61 {
gtk2k 0:74be48b504a5 62 public:
gtk2k 0:74be48b504a5 63 ///Creates a new socket
gtk2k 0:74be48b504a5 64 UDPSocket();
gtk2k 0:74be48b504a5 65
gtk2k 0:74be48b504a5 66 ///Closes and destroys socket
gtk2k 0:74be48b504a5 67 ~UDPSocket(); //close()
gtk2k 0:74be48b504a5 68
gtk2k 0:74be48b504a5 69 ///Binds the socket to local host or a multicast address
gtk2k 0:74be48b504a5 70 UDPSocketErr bind(const Host& me);
gtk2k 0:74be48b504a5 71
gtk2k 0:74be48b504a5 72 ///Sends data
gtk2k 0:74be48b504a5 73 /*
gtk2k 0:74be48b504a5 74 @param pHost : host to send data to
gtk2k 0:74be48b504a5 75 @return a negative error code or the number of bytes transmitted
gtk2k 0:74be48b504a5 76 */
gtk2k 0:74be48b504a5 77 int /*if < 0 : UDPSocketErr*/ sendto(const char* buf, int len, Host* pHost);
gtk2k 0:74be48b504a5 78
gtk2k 0:74be48b504a5 79 ///Receives data
gtk2k 0:74be48b504a5 80 /*
gtk2k 0:74be48b504a5 81 @param pHost : host from which this piece of data comes from
gtk2k 0:74be48b504a5 82 @return a negative error code or the number of bytes received
gtk2k 0:74be48b504a5 83 */
gtk2k 0:74be48b504a5 84 int /*if < 0 : UDPSocketErr*/ recvfrom(char* buf, int len, Host* pHost);
gtk2k 0:74be48b504a5 85
gtk2k 0:74be48b504a5 86 /* TODO NTH : printf / scanf helpers that call send/recv */
gtk2k 0:74be48b504a5 87
gtk2k 0:74be48b504a5 88 ///Closes socket
gtk2k 0:74be48b504a5 89 UDPSocketErr close();
gtk2k 0:74be48b504a5 90
gtk2k 0:74be48b504a5 91 //Callbacks
gtk2k 0:74be48b504a5 92 ///Setups callback
gtk2k 0:74be48b504a5 93 /**
gtk2k 0:74be48b504a5 94 @param pMethod : callback function
gtk2k 0:74be48b504a5 95 */
gtk2k 0:74be48b504a5 96 void setOnEvent( void (*pMethod)(UDPSocketEvent) );
gtk2k 0:74be48b504a5 97
gtk2k 0:74be48b504a5 98 class CDummy;
gtk2k 0:74be48b504a5 99 ///Setups callback
gtk2k 0:74be48b504a5 100 /**
gtk2k 0:74be48b504a5 101 @param pItem : instance of class on which to execute the callback method
gtk2k 0:74be48b504a5 102 @param pMethod : callback method
gtk2k 0:74be48b504a5 103 */
gtk2k 0:74be48b504a5 104 template<class T>
gtk2k 0:74be48b504a5 105 void setOnEvent( T* pItem, void (T::*pMethod)(UDPSocketEvent) )
gtk2k 0:74be48b504a5 106 {
gtk2k 0:74be48b504a5 107 m_pCbItem = (CDummy*) pItem;
gtk2k 0:74be48b504a5 108 m_pCbMeth = (void (CDummy::*)(UDPSocketEvent)) pMethod;
gtk2k 0:74be48b504a5 109 }
gtk2k 0:74be48b504a5 110
gtk2k 0:74be48b504a5 111 ///Disables callback
gtk2k 0:74be48b504a5 112 void resetOnEvent();
gtk2k 0:74be48b504a5 113
gtk2k 0:74be48b504a5 114 protected:
gtk2k 0:74be48b504a5 115 void onNetUdpSocketEvent(NetUdpSocketEvent e);
gtk2k 0:74be48b504a5 116 UDPSocketErr checkInst();
gtk2k 0:74be48b504a5 117
gtk2k 0:74be48b504a5 118 private:
gtk2k 0:74be48b504a5 119 NetUdpSocket* m_pNetUdpSocket;
gtk2k 0:74be48b504a5 120
gtk2k 0:74be48b504a5 121 CDummy* m_pCbItem;
gtk2k 0:74be48b504a5 122 void (CDummy::*m_pCbMeth)(UDPSocketEvent);
gtk2k 0:74be48b504a5 123
gtk2k 0:74be48b504a5 124 void (*m_pCb)(UDPSocketEvent);
gtk2k 0:74be48b504a5 125
gtk2k 0:74be48b504a5 126 };
gtk2k 0:74be48b504a5 127
gtk2k 0:74be48b504a5 128 #endif