Host library for controlling a WiConnect enabled Wi-Fi module.

Dependents:   wiconnect-ota_example wiconnect-web_setup_example wiconnect-test-console wiconnect-tcp_server_example ... more

SocketInterface.h

Committer:
dan_ackme
Date:
2014-08-12
Revision:
11:ea484e1b7fc4
Parent:
1:6ec9998427ad
Child:
13:2b51f5267c92

File content as of revision 11:ea484e1b7fc4:

/*
 * Copyright 2014, ACKme Networks
 * All Rights Reserved.
 *
 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of ACKme Networks;
 * the contents of this file may not be disclosed to third parties, copied
 * or duplicated in any form, in whole or in part, without the prior
 * written permission of ACKme Networks.
 */

#pragma once

#include "Wiconnect.h"
#include "types/Socket.h"
#include "types/SocketIrqHandlerMap.h"


/**
 * @namespace wiconnect
 */
namespace wiconnect {


/**
 * @ingroup types_socket
 *
 * @brief The provides an interface for creating TCP/UDP/TLS/HTTP client sockets.
 * A client socket connects to a remote server.
 *
 */
class SocketInterface
{
public:
    /**
     * @ingroup api_socket_misc
     *
     * @brief Close all opened sockets.
     */
    WiconnectResult closeAllSockets();

    /**
     * @ingroup api_socket_misc
     *
     * @brief Register a host pin as an external interrupt. When the external interrupt is
     * triggered, the supplied callback is executed.
     */
    WiconnectResult registerSocketIrqHandler(Pin irqPin, const Callback &handler);

    /**
     * @ingroup api_socket_misc
     *
     * @brief Unregister a previously registered IRQ pin.
     */
    WiconnectResult unregisterSocketIrqHandler(Pin irqPin);


    /**
     * @ingroup api_socket_misc
     *
     * @brief Connect to remote server.
     */
    WiconnectResult connect(Socket &socket, SocketType type, const char *host, uint16_t remortPort, uint16_t localPort, const void *args, Pin irqPin);


    // ------------------------------------------------------------------------

    /**
     * @ingroup api_socket_tcp
     *
     * @brief Connect to remote TCP server.
     */
    WiconnectResult tcpConnect(Socket &socket, const char *host, uint16_t remortPort, Pin irqPin = NC);


    // ------------------------------------------------------------------------

    /**
     * @ingroup api_socket_tls
     *
     * @brief Connect to remote TLS server.
     */
    WiconnectResult tlsConnect(Socket &socket, const char *host, uint16_t remortPort, const char *certFilename = NULL, Pin irqPin = NC);


    // ------------------------------------------------------------------------

    /**
     * @ingroup api_socket_udp
     *
     * @brief Connect to remote UDP server.
     */
    WiconnectResult udpConnect(Socket &socket, const char *host, uint16_t remortPort, uint16_t localPort = SOCKET_ANY_PORT, Pin irqPin = NC);


    // ------------------------------------------------------------------------

    /**
     * @ingroup api_socket_http
     *
     * @brief Connect to remote HTTP server.
     */
    WiconnectResult httpConnect(Socket &socket, const char *url, const HttpSocketArgs *args);

    /**
     * @ingroup api_socket_http
     *
     * @brief Issue HTTP GET Request
     */
    WiconnectResult httpGet(Socket &socket, const char *url, bool openOnly = false, const char *certFilename = NULL);

    /**
     * @ingroup api_socket_http
     *
     * @brief Issue HTTP POST Request
     */
    WiconnectResult httpPost(Socket &socket, const char *url, const char *contextType, bool openOnly = true, const char *certFilename = NULL);

    /**
     * @ingroup api_socket_http
     *
     * @brief Issue HTTP HEAD Request
     */
    WiconnectResult httpHead(Socket &socket, const char *url, const char *certFilename = NULL);

    /**
     * @ingroup api_socket_http
     *
     * @brief Add HTTP header key/value pair to opened HTTP request.
     */
    WiconnectResult httpAddHeader(Socket &socket, const char *key, const char *value);

    /**
     * @ingroup api_socket_http
     *
     * @brief Get the HTTP status code from HTTP request.
     */
    WiconnectResult httpGetStatus(Socket &socket, uint32_t *statusCodePtr);

protected:
    SocketInterface(Wiconnect *wiconnect);

    SocketIrqHandlerMap irqHandlers;

private:
    Wiconnect *wiconnect;
};

}