NetworkSocketAPI

Dependencies:   DnsQuery

Dependents:   HelloWizFi250Interface

Fork of NetworkSocketAPI by NetworkSocketAPI

NetworkInterface.h

Committer:
Christopher Haster
Date:
2016-02-18
Branch:
api-changes
Revision:
21:35ed15069189
Parent:
15:e657a90d9511
Child:
23:1e86d9fb3d86

File content as of revision 21:35ed15069189:

/* NetworkInterface Base Class
 * Copyright (c) 2015 ARM Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef NETWORK_INTERFACE_H
#define NETWORK_INTERFACE_H

#include "stdint.h"
#include "SocketInterface.h"


/** NetworkInterface class
 *  Common interface that is shared between all hardware that
 *  can connect to a network over IP.
 */
class NetworkInterface
{
public:
    virtual ~NetworkInterface() = default;


    /** Enables DHCP and clears any static address
     *  DHCP is enabled by default
     *  @return 0 on success
     */
    virtual int32_t useDHCP() = 0;

    /** Set the static IP address of the network interface
     *  @param ip Static IP address, copied internally
     */
    virtual void setIPAddress(const char *ip);

    /** Set the static network mask of the network interface
     *  @param mask Static network mask, copied internally
     */
    virtual void setNetworkMask(const char *mask);

    /** Set the static gateway of the network interface
     *  @param gateway Gateway address, copied internally
     */
    virtual void setGateway(const char *gateway);

    /** Get the IP address
     *  @return IP address of the interface
     */
    virtual const char *getIPAddress();

    /** Get the network mask
     *  @return Network mask of the interface
     */
    virtual const char *getNetworkMask();

    /** Get the gateway
     *  @return Gateway address of the interface
     */
    virtual const char *getGateway();

    /** Get the current MAC address
     *  @return String MAC address of the interface
     */
    virtual const char *getMACAddress() = 0;

    /** Get the current status of the interface
        @return true if connected
     */
    virtual bool isConnected(void) = 0;


private:
    friend class TCPSocket;
    friend class UDPSocket;

    /** Internally create a socket
     *  @param proto The type of socket to open, SOCK_TCP or SOCK_UDP
     *  @return The allocated socket
     */
    virtual SocketInterface *createSocket(socket_protocol_t proto) = 0;
    
    /** Internally destroy a socket
     *  @param socket An allocated SocketInterface
     *  @returns 0 on success
     */
    virtual void destroySocket(SocketInterface *socket) = 0;

private:
    const char *_ip_address;
    const char *_network_mask;
    const char *_gateway;
};

#endif