modified by ohneta
Dependents: HelloESP8266Interface_mine
Fork of NetworkSocketAPI by
NetworkInterface.h@20:efe7e291422b, 2015-11-10 (annotated)
- Committer:
- ohneta
- Date:
- Tue Nov 10 14:56:42 2015 +0000
- Revision:
- 20:efe7e291422b
- Parent:
- 15:e657a90d9511
modified syntax error.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sam_grove | 0:d35446f60233 | 1 | /* NetworkInterface 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 | 3:167dd63981b6 | 16 | |
bridadan | 1:291a9d61e58a | 17 | #ifndef NETWORKINTERFACE_H |
bridadan | 1:291a9d61e58a | 18 | #define NETWORKINTERFACE_H |
bridadan | 1:291a9d61e58a | 19 | |
sam_grove | 7:b147c08301be | 20 | #include "stdint.h" |
bridadan | 11:47c32687a44c | 21 | #include "SocketInterface.h" |
bridadan | 11:47c32687a44c | 22 | #include <map> |
bridadan | 11:47c32687a44c | 23 | |
bridadan | 1:291a9d61e58a | 24 | /** NetworkInterface class. |
sam_grove | 7:b147c08301be | 25 | This is a common interface that is shared between all hardware that connect |
sam_grove | 7:b147c08301be | 26 | to a network over IP. |
bridadan | 1:291a9d61e58a | 27 | */ |
sam_grove | 3:167dd63981b6 | 28 | class NetworkInterface |
sam_grove | 3:167dd63981b6 | 29 | { |
bridadan | 1:291a9d61e58a | 30 | public: |
austin.blackstone@arm.com | 4:f09f0932db4a | 31 | |
sam_grove | 7:b147c08301be | 32 | /** Initialize the network interface with DHCP. |
sam_grove | 7:b147c08301be | 33 | @returns 0 on success, a negative number on failure |
bridadan | 1:291a9d61e58a | 34 | */ |
sarahmarshy | 13:f84e69b3fdd3 | 35 | virtual int32_t init(void) = 0; |
sam_grove | 3:167dd63981b6 | 36 | |
sam_grove | 7:b147c08301be | 37 | /** Initialize the network interface with a static IP address. |
sam_grove | 7:b147c08301be | 38 | @param ip The static IP address to use |
sam_grove | 7:b147c08301be | 39 | @param mask The IP address mask |
sam_grove | 7:b147c08301be | 40 | @param gateway The gateway to use |
sam_grove | 7:b147c08301be | 41 | @returns 0 on success, a negative number on failure |
bridadan | 1:291a9d61e58a | 42 | */ |
sarahmarshy | 13:f84e69b3fdd3 | 43 | virtual int32_t init(const char *ip, const char *mask, const char *gateway) = 0; |
sam_grove | 7:b147c08301be | 44 | |
sam_grove | 3:167dd63981b6 | 45 | |
sam_grove | 7:b147c08301be | 46 | /** Start the interface, using DHCP if needed. |
sam_grove | 7:b147c08301be | 47 | @param timeout_ms Time in miliseconds to wait while attempting to connect before timing out |
sam_grove | 7:b147c08301be | 48 | @returns 0 on success, a negative number on failure |
sam_grove | 3:167dd63981b6 | 49 | */ |
sarahmarshy | 13:f84e69b3fdd3 | 50 | virtual int32_t connect(uint32_t timeout_ms = 15000) = 0; |
sam_grove | 3:167dd63981b6 | 51 | |
sam_grove | 7:b147c08301be | 52 | /** Stop the interface, bringing down dhcp if necessary. |
sam_grove | 7:b147c08301be | 53 | @returns 0 on success, a negative number on failure |
bridadan | 1:291a9d61e58a | 54 | */ |
sarahmarshy | 15:e657a90d9511 | 55 | virtual int32_t disconnect(void) = 0; |
sam_grove | 3:167dd63981b6 | 56 | |
sam_grove | 7:b147c08301be | 57 | /** Get the current IP address. |
sam_grove | 7:b147c08301be | 58 | @returns a pointer to a string containing the IP address. |
bridadan | 1:291a9d61e58a | 59 | */ |
sarahmarshy | 13:f84e69b3fdd3 | 60 | virtual char *getIPAddress(void) = 0; |
sam_grove | 3:167dd63981b6 | 61 | |
sam_grove | 7:b147c08301be | 62 | /** Get the current gateway address. |
sam_grove | 7:b147c08301be | 63 | @returns a pointer to a string containing the gateway address. |
bridadan | 1:291a9d61e58a | 64 | */ |
sam_grove | 3:167dd63981b6 | 65 | virtual char *getGateway(void) const = 0; |
sam_grove | 3:167dd63981b6 | 66 | |
sam_grove | 3:167dd63981b6 | 67 | |
sam_grove | 7:b147c08301be | 68 | /** Get the current network mask. |
sam_grove | 7:b147c08301be | 69 | @returns a pointer to a string containing the network mask. |
bridadan | 1:291a9d61e58a | 70 | */ |
sam_grove | 3:167dd63981b6 | 71 | virtual char *getNetworkMask(void) const = 0; |
sam_grove | 3:167dd63981b6 | 72 | |
sam_grove | 7:b147c08301be | 73 | /** Get the devices MAC address. |
sam_grove | 7:b147c08301be | 74 | @returns a pointer to a string containing the mac address. |
sam_grove | 3:167dd63981b6 | 75 | */ |
sam_grove | 3:167dd63981b6 | 76 | virtual char *getMACAddress(void) const = 0; |
sam_grove | 3:167dd63981b6 | 77 | |
sam_grove | 7:b147c08301be | 78 | /** Get the current status of the interface connection. |
sam_grove | 7:b147c08301be | 79 | @returns true if connected, a negative number on failure |
bridadan | 1:291a9d61e58a | 80 | */ |
sarahmarshy | 13:f84e69b3fdd3 | 81 | virtual int32_t isConnected(void) = 0; |
bridadan | 11:47c32687a44c | 82 | |
bridadan | 11:47c32687a44c | 83 | /** Allocate space for a socket. |
sam_grove | 12:ab3679eb4d9d | 84 | @param The type of socket you want to open, SOCK_TCP or SOCK_UDP |
bridadan | 11:47c32687a44c | 85 | @returns a pointer to the allocated socket. |
bridadan | 11:47c32687a44c | 86 | */ |
sarahmarshy | 13:f84e69b3fdd3 | 87 | virtual SocketInterface* allocateSocket(socket_protocol_t socketProtocol) = 0; |
bridadan | 11:47c32687a44c | 88 | |
bridadan | 11:47c32687a44c | 89 | /** Deallocate space for a socket. |
sam_grove | 12:ab3679eb4d9d | 90 | @param An allocated SocketInterface |
sam_grove | 12:ab3679eb4d9d | 91 | @returns 0 if object is destroyed, -1 otherwise |
bridadan | 11:47c32687a44c | 92 | */ |
sarahmarshy | 13:f84e69b3fdd3 | 93 | virtual int deallocateSocket(SocketInterface* socket) = 0; |
bridadan | 11:47c32687a44c | 94 | |
bridadan | 11:47c32687a44c | 95 | protected: |
bridadan | 11:47c32687a44c | 96 | /** Map used to keep track of all SocketInterface instances */ |
bridadan | 14:9e1bd182ef07 | 97 | std::map<uint32_t, SocketInterface*> sockets; |
bridadan | 11:47c32687a44c | 98 | |
bridadan | 11:47c32687a44c | 99 | /** Counter used to create unique handles for new sockets. |
bridadan | 11:47c32687a44c | 100 | Should be incremented whenever a new socket is created. |
bridadan | 11:47c32687a44c | 101 | */ |
bridadan | 11:47c32687a44c | 102 | uint32_t uuidCounter; |
bridadan | 1:291a9d61e58a | 103 | }; |
bridadan | 1:291a9d61e58a | 104 | |
bridadan | 1:291a9d61e58a | 105 | #endif |