Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of libMiMic by
mbed/mod/ModWebSocket.h@115:fa79286d8ea4, 2017-02-24 (annotated)
- Committer:
- furutani
- Date:
- Fri Feb 24 04:43:41 2017 +0000
- Revision:
- 115:fa79286d8ea4
- Parent:
- 81:e5e4f2264d24
Delete missing include line.; Add parameter "timeout" to TCPSocket::connect(), precv().; Fix to send ARP request to default gateway when connecting to IP address of different segment.;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| nyatla | 58:03b89038b21a | 1 | #pragma once |
| nyatla | 58:03b89038b21a | 2 | #include "NyLPC_net.h" |
| nyatla | 58:03b89038b21a | 3 | #include "ModBaseClass.h" |
| nyatla | 58:03b89038b21a | 4 | #include "HttpdConnection.h" |
| nyatla | 58:03b89038b21a | 5 | #include "Httpd.h" |
| nyatla | 58:03b89038b21a | 6 | #include "Net.h" |
| nyatla | 58:03b89038b21a | 7 | |
| nyatla | 58:03b89038b21a | 8 | namespace MiMic |
| nyatla | 58:03b89038b21a | 9 | { |
| nyatla | 58:03b89038b21a | 10 | class HttpdConnection; |
| nyatla | 58:03b89038b21a | 11 | |
| nyatla | 58:03b89038b21a | 12 | /** |
| nyatla | 58:03b89038b21a | 13 | * This class is Websocket module. |
| nyatla | 58:03b89038b21a | 14 | * The class provides 3 services. |
| nyatla | 58:03b89038b21a | 15 | * <ul> |
| nyatla | 58:03b89038b21a | 16 | * <li>d.xml - a device description.</li> |
| nyatla | 58:03b89038b21a | 17 | * <li>control/xx - soap handler</li> |
| nyatla | 58:03b89038b21a | 18 | * <li>event/xx -event handler.</li> |
| nyatla | 58:03b89038b21a | 19 | * </ul> |
| nyatla | 58:03b89038b21a | 20 | */ |
| nyatla | 58:03b89038b21a | 21 | class ModWebSocket:ModBaseClass |
| nyatla | 58:03b89038b21a | 22 | { |
| nyatla | 58:03b89038b21a | 23 | private: |
| nyatla | 58:03b89038b21a | 24 | protected: |
| nyatla | 58:03b89038b21a | 25 | NyLPC_TcModWebSocket_t* _mod; |
| nyatla | 58:03b89038b21a | 26 | public: |
| nyatla | 58:03b89038b21a | 27 | ModWebSocket(); |
| nyatla | 58:03b89038b21a | 28 | ModWebSocket(const char* i_path); |
| nyatla | 58:03b89038b21a | 29 | virtual ~ModWebSocket(); |
| nyatla | 81:e5e4f2264d24 | 30 | void setParam(const char* i_path); |
| nyatla | 81:e5e4f2264d24 | 31 | bool isStarted(); |
| nyatla | 58:03b89038b21a | 32 | /** |
| nyatla | 58:03b89038b21a | 33 | * This function executes websocket negotiation to the current connection. |
| nyatla | 58:03b89038b21a | 34 | * Should be handle websocket session if function successful. |
| nyatla | 58:03b89038b21a | 35 | * @return |
| nyatla | 58:03b89038b21a | 36 | * true if negotiation successful;otherwishe false. |
| nyatla | 58:03b89038b21a | 37 | */ |
| nyatla | 58:03b89038b21a | 38 | bool execute(HttpdConnection& i_connection); |
| nyatla | 58:03b89038b21a | 39 | /** |
| nyatla | 58:03b89038b21a | 40 | * Write data to websocket stream. |
| nyatla | 58:03b89038b21a | 41 | * @return |
| nyatla | 58:03b89038b21a | 42 | * true if successful;otherwishe false and connection closed. |
| nyatla | 58:03b89038b21a | 43 | */ |
| nyatla | 58:03b89038b21a | 44 | bool write(const void* i_tx_buf,int i_tx_size); |
| nyatla | 58:03b89038b21a | 45 | /** |
| nyatla | 58:03b89038b21a | 46 | * This function sends data to websocket stream. |
| nyatla | 58:03b89038b21a | 47 | * @param i_fmt |
| nyatla | 58:03b89038b21a | 48 | * printf like format text. |
| nyatla | 58:03b89038b21a | 49 | * @param ... |
| nyatla | 58:03b89038b21a | 50 | * argument list for i_fmt |
| nyatla | 58:03b89038b21a | 51 | */ |
| nyatla | 72:c118a7aa37a3 | 52 | bool writeFormat(const char* i_fmt,...); |
| nyatla | 58:03b89038b21a | 53 | |
| nyatla | 58:03b89038b21a | 54 | /** |
| nyatla | 58:03b89038b21a | 55 | * This function receives data from websocket stream. |
| nyatla | 58:03b89038b21a | 56 | * @return |
| nyatla | 58:03b89038b21a | 57 | * <ul> |
| nyatla | 58:03b89038b21a | 58 | * <li>r<0 Error. The socket already closed. |
| nyatla | 58:03b89038b21a | 59 | * <li>r==0 Timeout. The connection is continued. |
| nyatla | 58:03b89038b21a | 60 | * <li>r>0 Success. Received data size. |
| nyatla | 58:03b89038b21a | 61 | * </ul> |
| nyatla | 58:03b89038b21a | 62 | * If an Error found, application should be call close and exit handler. |
| nyatla | 58:03b89038b21a | 63 | */ |
| nyatla | 58:03b89038b21a | 64 | int read(void* i_rx_buf,int i_rx_size); |
| nyatla | 58:03b89038b21a | 65 | /** |
| nyatla | 58:03b89038b21a | 66 | * This function terminates websocket connection. |
| nyatla | 58:03b89038b21a | 67 | * Should be called if execute function successful. |
| nyatla | 58:03b89038b21a | 68 | */ |
| nyatla | 58:03b89038b21a | 69 | void close(); |
| nyatla | 58:03b89038b21a | 70 | /** |
| nyatla | 58:03b89038b21a | 71 | * This function returns read function status. |
| nyatla | 58:03b89038b21a | 72 | * This is to confirm that "read" can call without blocking. |
| nyatla | 58:03b89038b21a | 73 | * @return |
| nyatla | 58:03b89038b21a | 74 | * true if can be call "read" with no-wait. otherwise, "read" might be wait. |
| nyatla | 58:03b89038b21a | 75 | */ |
| nyatla | 58:03b89038b21a | 76 | bool canRead(); |
| nyatla | 58:03b89038b21a | 77 | |
| nyatla | 58:03b89038b21a | 78 | |
| nyatla | 58:03b89038b21a | 79 | }; |
| nyatla | 58:03b89038b21a | 80 | } |
