libraries / Bridge / src / BridgeClient.hon commit Added final version of code (649c546)
   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 {
  26  public:
  27    // Constructor with a user provided BridgeClass instance
  28    BridgeClient(uint8_t _h, BridgeClass &_b = Bridge);
  29    BridgeClient(BridgeClass &_b = Bridge);
  30    ~BridgeClient();
  31
  32    // Stream methods
  33    // (read message)
  34    virtual int available();
  35    virtual int read();
  36    virtual int read(uint8_t *buf, size_t size);
  37    virtual int peek();
  38    // (write response)
  39    virtual size_t write(uint8_t);
  40    virtual size_t write(const uint8_t *buf, size_t size);
  41    virtual void flush();
  42    // TODO: add optimized function for block write
  43
  44    virtual operator bool () {
  45      return opened;
  46    }
  47
  48    virtual BridgeClient& operator=(const BridgeClient &_x);
  49
  50    virtual void stop();
  51    virtual uint8_t connected();
  52
  53    virtual int connect(IPAddress ip, uint16_t port);
  54    virtual int connect(const char *host, uint16_t port);
  55    int connectSSL(const char* host, uint16_t port);
  56
  57  private:
  58    BridgeClass &bridge;
  59    uint8_t handle;
  60    boolean opened;
  61
  62  private:
  63    void doBuffer();
  64    uint8_t buffered;
  65    uint8_t readPos;
  66    static const int BUFFER_SIZE = 64;
  67    uint8_t buffer[BUFFER_SIZE];
  68
  69};
  70
  71#endif // _BRIDGE_CLIENT_H_