restruturing according to arduino library guidlines

This commit is contained in:
Noah Laptop 2019-02-19 14:29:50 -08:00
parent 0cb8cce548
commit 32fa4ac11d
20 changed files with 106 additions and 4 deletions

22
.vscode/c_cpp_properties.json vendored Normal file
View file

@ -0,0 +1,22 @@
{
"configurations": [
{
"name": "SAMD",
"includePath": [
"${workspaceFolder}/**",
"C:/Users/Noah/AppData/Local/Arduino15/packages/adafruit/hardware/samd/1.2.9/cores/arduino/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.17763.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/Hostx64/x64/cl.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "msvc-x64"
}
],
"version": 4
}

25
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,25 @@
{
"files.associations": {
"cmath": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"cwchar": "cpp",
"exception": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"limits": "cpp",
"memory": "cpp",
"new": "cpp",
"type_traits": "cpp",
"typeinfo": "cpp",
"utility": "cpp",
"xmemory": "cpp",
"xmemory0": "cpp",
"xstddef": "cpp",
"xtr1common": "cpp",
"xutility": "cpp"
}
}

45
src/Client.h Normal file
View file

@ -0,0 +1,45 @@
/*
Client.h - Base class that provides Client
Copyright (c) 2011 Adrian McEwen. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef client_h
#define client_h
#include "Print.h"
#include "Stream.h"
#include "IPAddress.h"
class Client : public Stream {
public:
virtual int connect(IPAddress ip, uint16_t port) =0;
virtual int connect(const char *host, uint16_t port) =0;
virtual size_t write(uint8_t) =0;
virtual size_t write(const uint8_t *buf, size_t size) =0;
virtual int available() = 0;
virtual int read() = 0;
virtual int read(uint8_t *buf, size_t size) = 0;
virtual int peek() = 0;
virtual void flush() = 0;
virtual void stop() = 0;
virtual uint8_t connected() = 0;
virtual operator bool() = 0;
protected:
uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); };
};
#endif

View file

@ -19,4 +19,3 @@
*/ */
#include "SSLClient.h" #include "SSLClient.h"

View file

@ -40,7 +40,17 @@
template <class C> template <class C>
class SSLClient : public Client { class SSLClient : public Client {
/** static type checks
* I'm a java developer, so I want to ensure that my inheritance is safe.
* These checks ensure that all the functions we use on class C are
* actually present on class C. It does this by first checking that the
* class inherits from Client, and then that it contains a status() function.
*/
static_assert(std::is_base_of(Client, C)::value, "C must be a Client Class!");
static_assert(std::is_function(decltype(C::status))::value, "C must have a status() function!");
public: public:
/** Ctor /** Ctor
* Creates a new dynamically allocated Client object based on the * Creates a new dynamically allocated Client object based on the
* one passed to client * one passed to client
@ -48,7 +58,6 @@ public:
* is going to exists past the inital creation of the SSLClient. * is going to exists past the inital creation of the SSLClient.
* @param client the (Ethernet)client object * @param client the (Ethernet)client object
*/ */
static_assert(std::is_base_of(Client, C)::value, "C must be a Client Class!");
SSLClient(const C &client): SSLClient(const C &client):
m_client(client) m_client(client)
{ {
@ -61,7 +70,7 @@ public:
* Most of them smply pass through * Most of them smply pass through
*/ */
virtual int availableForWrite(void) const { return m_client.availableForWrite(); }; virtual int availableForWrite(void) const { return m_client.availableForWrite(); };
virtual operator bool() const { return static_cast<bool>(m_client); } virtual operator bool() const { return m_client.bool(); }
virtual bool operator==(const bool value) const { return bool() == value; } virtual bool operator==(const bool value) const { return bool() == value; }
virtual bool operator!=(const bool value) const { return bool() != value; } virtual bool operator!=(const bool value) const { return bool() != value; }
virtual bool operator==(const C& rhs) const { return m_client.operator==(rhs); } virtual bool operator==(const C& rhs) const { return m_client.operator==(rhs); }
@ -87,6 +96,8 @@ public:
virtual void stop(); virtual void stop();
virtual uint8_t connected(); virtual uint8_t connected();
/** get the client object */
C& getClient() { return m_client; }
private: private:
// create a copy of the class // create a copy of the class