ACKme Logo WiConnect Host Library- API Reference Guide
 
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Groups Pages
SocketInterface.h
1 
29 #pragma once
30 
31 #include "Wiconnect.h"
32 #include "types/WiconnectSocket.h"
33 #include "types/WiconnectUdpServer.h"
34 
35 #ifdef WICONNECT_GPIO_IRQ_ENABLED
36 #include "types/SocketIrqHandlerMap.h"
37 #endif
38 
42 namespace wiconnect {
43 
44 #ifdef WICONNECT_GPIO_IRQ_ENABLED
45 #define GPIO_IRQ_ARG_NC ,Pin irqPin = PIN_NC
46 #define GPIO_IRQ_ARG ,Pin irqPin
47 #define GPIO_IRQ_PARAM ,irqPin
48 #else
49 #define GPIO_IRQ_ARG_NC
50 #define GPIO_IRQ_ARG
51 #define GPIO_IRQ_PARAM
52 #endif
53 
64 {
65 public:
78 
79 #ifdef WICONNECT_GPIO_IRQ_ENABLED
80 
108  WiconnectResult registerSocketIrqHandler(Pin irqPin, const Callback &handler);
109 
121  WiconnectResult unregisterSocketIrqHandler(Pin irqPin);
122 #endif
123 
140  WiconnectResult connect(WiconnectSocket &socket, SocketType type, const char *host, uint16_t remortPort, uint16_t localPort, const void *args GPIO_IRQ_ARG);
141 
142 
143  // ------------------------------------------------------------------------
144 
156  WiconnectResult tcpConnect(WiconnectSocket &socket, const char *host, uint16_t remortPort GPIO_IRQ_ARG_NC);
157 
158 
159  // ------------------------------------------------------------------------
160 
171  WiconnectResult tcpListen(uint16_t listeningPort, int maxClients = 0 GPIO_IRQ_ARG_NC);
172 
173 
174  // ------------------------------------------------------------------------
175 
185  WiconnectResult tcpAccept(WiconnectSocket &socket, uint32_t timeoutMs = WICONNECT_WAIT_FOREVER);
186 
187 
188  // ------------------------------------------------------------------------
189 
198 
199 
200  // ------------------------------------------------------------------------
201 
214  WiconnectResult tlsConnect(WiconnectSocket &socket, const char *host, uint16_t remortPort, const char *certFilename = NULL GPIO_IRQ_ARG_NC);
215 
216 
217  // ------------------------------------------------------------------------
218 
231  WiconnectResult udpConnect(WiconnectSocket &socket, const char *host, uint16_t remortPort, uint16_t localPort = SOCKET_ANY_PORT GPIO_IRQ_ARG_NC);
232 
242  WiconnectResult udpListen(WiconnectUdpServer &udpServer, uint16_t listeningPort);
243 
244 
245  // ------------------------------------------------------------------------
246 
269  WiconnectResult httpConnect(WiconnectSocket &socket, const char *url, const HttpSocketArgs *args);
270 
288  WiconnectResult httpGet(WiconnectSocket &socket, const char *url, bool openOnly = false, const char *certFilename = NULL);
289 
308  WiconnectResult httpPost(WiconnectSocket &socket, const char *url, const char *contextType, bool openOnly = true, const char *certFilename = NULL);
309 
320  WiconnectResult httpHead(WiconnectSocket &socket, const char *url, const char *certFilename = NULL);
321 
339  WiconnectResult httpAddHeader(WiconnectSocket &socket, const char *key, const char *value);
340 
353  WiconnectResult httpGetStatus(WiconnectSocket &socket, uint32_t *statusCodePtr);
354 
355 protected:
356  SocketInterface(Wiconnect *wiconnect);
357  ~SocketInterface();
358 
359 #ifdef WICONNECT_GPIO_IRQ_ENABLED
360  SocketIrqHandlerMap irqHandlers;
361 #endif
362 
363  uint32_t serverConnectedClientList;
364 
365  WiconnectResult pollForServerClient(uint8_t *handle = NULL, uint16_t *localPort = NULL, uint16_t *remotePort = NULL, uint32_t *ipAddress = NULL);
366 
367  void socketClosedCallback(const WiconnectSocket *socket);
368 
369  friend class GhmInterface;
370 
371 private:
372  Wiconnect *wiconnect;
373 };
374 
375 }
WiconnectResult udpConnect(WiconnectSocket &socket, const char *host, uint16_t remortPort, uint16_t localPort=SOCKET_ANY_PORT GPIO_IRQ_ARG_NC)
Connect to remote UDP server.
SocketType
Socket type.
WiconnectResult httpPost(WiconnectSocket &socket, const char *url, const char *contextType, bool openOnly=true, const char *certFilename=NULL)
Issue HTTP POST Request.
UDP Server Listening socket.
WiconnectResult
API Result code.
Generic callback function.
Definition: Callback.h:49
WiconnectResult tcpListen(uint16_t listeningPort, int maxClients=0 GPIO_IRQ_ARG_NC)
Start internal TCP server and listen on specified port.
WiconnectResult tlsConnect(WiconnectSocket &socket, const char *host, uint16_t remortPort, const char *certFilename=NULL GPIO_IRQ_ARG_NC)
Connect to remote TLS server.
WiconnectResult tcpConnect(WiconnectSocket &socket, const char *host, uint16_t remortPort GPIO_IRQ_ARG_NC)
Connect to remote TCP server.
The provides an interface for http://goHACK.me.
Definition: GhmInterface.h:81
#define SOCKET_ANY_PORT
Default which indicates to use the most optimal port.
WiconnectResult httpAddHeader(WiconnectSocket &socket, const char *key, const char *value)
Add HTTP header key/value pair to opened HTTP request.
WiconnectResult closeAllSockets()
Close all opened sockets.
WiconnectResult httpConnect(WiconnectSocket &socket, const char *url, const HttpSocketArgs *args)
Connect to remote HTTP server.
PinName Pin
Pin name on HOST.
Definition: sdk.h:134
WiconnectResult httpGet(WiconnectSocket &socket, const char *url, bool openOnly=false, const char *certFilename=NULL)
Issue HTTP GET Request.
WiconnectResult tcpAccept(WiconnectSocket &socket, uint32_t timeoutMs=WICONNECT_WAIT_FOREVER)
Wait for next client to connect to TCP server.
WiconnectResult httpHead(WiconnectSocket &socket, const char *url, const char *certFilename=NULL)
Issue HTTP HEAD Request.
WiconnectResult connect(WiconnectSocket &socket, SocketType type, const char *host, uint16_t remortPort, uint16_t localPort, const void *args GPIO_IRQ_ARG)
Connect to remote server.
Connection object to remote server.
#define WICONNECT_WAIT_FOREVER
Never timeout.
The provides an interface for creating TCP/UDP/TLS/HTTP client sockets. A client socket connects to a...
WiconnectResult tcpServerStop(void)
Stop TCP server from listening on port. Close all connected clients.
The root WiConnect library class. This class inheriets all WiConnect functionality.
WiconnectResult udpListen(WiconnectUdpServer &udpServer, uint16_t listeningPort)
Start a UDP server listening on the given port.
Struct for hold HTTP socket configuration.
WiconnectResult httpGetStatus(WiconnectSocket &socket, uint32_t *statusCodePtr)
Get the HTTP status code from HTTP request.