1/* 2 Copyright (c) 2013 Arduino LLC. All right reserved. 3 4 This library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Lesser General Public 6 License as published by the Free Software Foundation; either 7 version 2.1 of the License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 14 You should have received a copy of the GNU Lesser General Public 15 License along with this library; if not, write to the Free Software 16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17*/ 18 19#ifndef _BRIDGE_CLIENT_H_ 20#define _BRIDGE_CLIENT_H_ 21 22#include <Bridge.h> 23#include <Client.h> 24 25class BridgeClient :public Client { 26public: 27// Constructor with a user provided BridgeClass instance 28BridgeClient(uint8_t _h, BridgeClass &_b = Bridge); 29BridgeClient(BridgeClass &_b = Bridge); 30~BridgeClient(); 31 32// Stream methods 33// (read message) 34virtualintavailable(); 35virtualintread(); 36virtualintread(uint8_t*buf,size_t size); 37virtualintpeek(); 38// (write response) 39virtualsize_twrite(uint8_t); 40virtualsize_twrite(const uint8_t*buf,size_t size); 41virtualvoidflush(); 42// TODO: add optimized function for block write 43 44virtual operatorbool() { 45return opened; 46} 47 48virtual BridgeClient&operator=(const BridgeClient &_x); 49 50virtualvoidstop(); 51virtualuint8_tconnected(); 52 53virtualintconnect(IPAddress ip,uint16_t port); 54virtualintconnect(const char*host,uint16_t port); 55intconnectSSL(const char* host,uint16_t port); 56 57private: 58 BridgeClass &bridge; 59uint8_t handle; 60 boolean opened; 61 62private: 63voiddoBuffer(); 64uint8_t buffered; 65uint8_t readPos; 66static const int BUFFER_SIZE =64; 67uint8_t buffer[BUFFER_SIZE]; 68 69}; 70 71#endif// _BRIDGE_CLIENT_H_