NetworkSocketAPI
Dependents: HelloWizFi250Interface
Fork of NetworkSocketAPI by
SocketInterface.h@53:26b5f1c69822, 2016-02-25 (annotated)
- Committer:
- Christopher Haster
- Date:
- Thu Feb 25 08:23:06 2016 -0600
- Revision:
- 53:26b5f1c69822
- Parent:
- 48:b3bbe28a7963
- Child:
- 57:3c873fab4207
Fixed issues with protected destructors
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sam_grove | 0:d35446f60233 | 1 | /* SocketInterface Base Class |
sam_grove | 0:d35446f60233 | 2 | * Copyright (c) 2015 ARM Limited |
sam_grove | 0:d35446f60233 | 3 | * |
sam_grove | 0:d35446f60233 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
sam_grove | 0:d35446f60233 | 5 | * you may not use this file except in compliance with the License. |
sam_grove | 0:d35446f60233 | 6 | * You may obtain a copy of the License at |
sam_grove | 0:d35446f60233 | 7 | * |
sam_grove | 0:d35446f60233 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
sam_grove | 0:d35446f60233 | 9 | * |
sam_grove | 0:d35446f60233 | 10 | * Unless required by applicable law or agreed to in writing, software |
sam_grove | 0:d35446f60233 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
sam_grove | 0:d35446f60233 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
sam_grove | 0:d35446f60233 | 13 | * See the License for the specific language governing permissions and |
sam_grove | 0:d35446f60233 | 14 | * limitations under the License. |
sam_grove | 0:d35446f60233 | 15 | */ |
sam_grove | 8:4b7f97a5597b | 16 | |
Christopher Haster |
21:35ed15069189 | 17 | #ifndef SOCKET_INTERFACE_H |
Christopher Haster |
21:35ed15069189 | 18 | #define SOCKET_INTERFACE_H |
bridadan | 2:ce08986b18b5 | 19 | |
sam_grove | 8:4b7f97a5597b | 20 | #include "stdint.h" |
sam_grove | 8:4b7f97a5597b | 21 | |
sam_grove | 8:4b7f97a5597b | 22 | |
Christopher Haster |
21:35ed15069189 | 23 | /** Enum of socket protocols |
sam_grove | 8:4b7f97a5597b | 24 | */ |
Christopher Haster |
42:49893d13c432 | 25 | enum socket_protocol_t { |
sam_grove | 8:4b7f97a5597b | 26 | SOCK_TCP, /*!< Socket connection over TCP */ |
sam_grove | 8:4b7f97a5597b | 27 | SOCK_UDP, /*!< Socket connection over UDP */ |
Christopher Haster |
42:49893d13c432 | 28 | }; |
sam_grove | 8:4b7f97a5597b | 29 | |
Christopher Haster |
21:35ed15069189 | 30 | |
Christopher Haster |
21:35ed15069189 | 31 | /** SocketInterface class |
Christopher Haster |
21:35ed15069189 | 32 | * Common interface for implementation specific sockets created through |
Christopher Haster |
21:35ed15069189 | 33 | * network interfaces. This class is used internally by the |
Christopher Haster |
21:35ed15069189 | 34 | * TCPSocket and UDPSocket classes |
sam_grove | 8:4b7f97a5597b | 35 | */ |
Christopher Haster |
21:35ed15069189 | 36 | class SocketInterface |
sam_grove | 8:4b7f97a5597b | 37 | { |
sam_grove | 8:4b7f97a5597b | 38 | public: |
Christopher Haster |
53:26b5f1c69822 | 39 | virtual ~SocketInterface() {} |
Christopher Haster |
53:26b5f1c69822 | 40 | |
Christopher Haster |
21:35ed15069189 | 41 | /** Set the IP address of the socket |
Christopher Haster |
41:3ec1c97e9bbf | 42 | * @param ip IP address to connect to |
sam_grove | 8:4b7f97a5597b | 43 | */ |
Christopher Haster |
43:09ea32f2eb54 | 44 | virtual void setIPAddress(const char *ip) { (void)ip; } |
sam_grove | 16:658d4943c753 | 45 | |
Christopher Haster |
21:35ed15069189 | 46 | /** Set the port of the socket |
Christopher Haster |
21:35ed15069189 | 47 | * @param port Port to connect to |
sam_grove | 8:4b7f97a5597b | 48 | */ |
Christopher Haster |
43:09ea32f2eb54 | 49 | virtual void setPort(uint16_t port) { (void)port; } |
sam_grove | 8:4b7f97a5597b | 50 | |
Christopher Haster |
38:157fb2ab965f | 51 | /** Status of the socket |
Christopher Haster |
38:157fb2ab965f | 52 | * @return True if connected |
Christopher Haster |
38:157fb2ab965f | 53 | */ |
Christopher Haster |
43:09ea32f2eb54 | 54 | virtual bool isConnected() |
Christopher Haster |
43:09ea32f2eb54 | 55 | { |
Christopher Haster |
43:09ea32f2eb54 | 56 | // By default return true if socket was created successfully |
Christopher Haster |
43:09ea32f2eb54 | 57 | return true; |
Christopher Haster |
43:09ea32f2eb54 | 58 | } |
Christopher Haster |
38:157fb2ab965f | 59 | |
Christopher Haster |
21:35ed15069189 | 60 | /** Open a connection to the underlying address |
Christopher Haster |
36:eab792dfb0d8 | 61 | * @param ip IP address to connect to |
Christopher Haster |
36:eab792dfb0d8 | 62 | * @param port Port to connect to |
Christopher Haster |
21:35ed15069189 | 63 | * @return 0 on success |
sam_grove | 8:4b7f97a5597b | 64 | */ |
Christopher Haster |
36:eab792dfb0d8 | 65 | virtual int32_t open(const char *ip, uint16_t port) = 0; |
Christopher Haster |
21:35ed15069189 | 66 | |
Christopher Haster |
21:35ed15069189 | 67 | /** Close an open connection |
Christopher Haster |
21:35ed15069189 | 68 | * @return 0 on success |
Christopher Haster |
21:35ed15069189 | 69 | */ |
Christopher Haster |
21:35ed15069189 | 70 | virtual int32_t close() = 0; |
sam_grove | 8:4b7f97a5597b | 71 | |
Christopher Haster |
21:35ed15069189 | 72 | /** Send data |
Christopher Haster |
21:35ed15069189 | 73 | * @param data Buffer of data to send |
Christopher Haster |
48:b3bbe28a7963 | 74 | * @param size Size of data to send |
Christopher Haster |
21:35ed15069189 | 75 | * @return 0 on success |
sam_grove | 8:4b7f97a5597b | 76 | */ |
Christopher Haster |
48:b3bbe28a7963 | 77 | virtual int32_t send(const void *data, uint32_t size) = 0; |
sam_grove | 8:4b7f97a5597b | 78 | |
Christopher Haster |
48:b3bbe28a7963 | 79 | /** Receive data |
Christopher Haster |
48:b3bbe28a7963 | 80 | * @note |
Christopher Haster |
48:b3bbe28a7963 | 81 | * This call should return immediately with a value of 0 |
Christopher Haster |
48:b3bbe28a7963 | 82 | * if no data is available. |
Christopher Haster |
48:b3bbe28a7963 | 83 | * |
Christopher Haster |
48:b3bbe28a7963 | 84 | * @param data A buffer to store the data in |
Christopher Haster |
48:b3bbe28a7963 | 85 | * @param size Size of buffer |
Christopher Haster |
48:b3bbe28a7963 | 86 | * @return Number of bytes received or a negative value on failure |
sam_grove | 8:4b7f97a5597b | 87 | */ |
Christopher Haster |
48:b3bbe28a7963 | 88 | virtual int32_t recv(void *data, uint32_t size) = 0; |
sam_grove | 8:4b7f97a5597b | 89 | }; |
sam_grove | 8:4b7f97a5597b | 90 | |
bridadan | 1:291a9d61e58a | 91 | #endif |