Skip to content

Commit

Permalink
all templates
Browse files Browse the repository at this point in the history
  • Loading branch information
bertmelis authored Dec 19, 2023
1 parent 885e631 commit 094cd8a
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 207 deletions.
2 changes: 1 addition & 1 deletion src/MqttClientSetup.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ the LICENSE file.

#include "MqttClient.h"

template <typename T>
template<template <class> class T, class MQTTVERSION>
class MqttClientSetup : public MqttClient {
public:
T& setKeepAlive(uint16_t keepAlive) {
Expand Down
25 changes: 25 additions & 0 deletions src/MqttVersion.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
Copyright (c) 2022 Bert Melis. All rights reserved.
This work is licensed under the terms of the MIT license.
For a copy, see <https://opensource.org/licenses/MIT> or
the LICENSE file.
*/

#pragma once

namespace MqttVersion {

class v3_1 {
// empty
};

class v3_1_1 {
// empty
};

class v5 {
// empty
};

} // end namespace MqttVersion
113 changes: 0 additions & 113 deletions src/espMqttClient.cpp

This file was deleted.

134 changes: 111 additions & 23 deletions src/espMqttClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,60 +21,148 @@ the LICENSE file.
#include "MqttClientSetup.h"

#if defined(ARDUINO_ARCH_ESP8266)
class espMqttClient : public MqttClientSetup<espMqttClient> {

template<class MQTTVERSION>
class espMqttClient : public MqttClientSetup<espMqttClient, MQTTVERSION> {
public:
espMqttClient();
espMqttClient()
: MqttClientSetup<espMqttClient, MQTTVERSION>(espMqttClientTypes::UseInternalTask::NO)
, _client() {
_transport = &_client;
}

protected:
espMqttClientInternals::ClientSync _client;
};

class espMqttClientSecure : public MqttClientSetup<espMqttClientSecure> {
template<class MQTTVERSION>
class espMqttClientSecure : public MqttClientSetup<espMqttClientSecure, MQTTVERSION> {
public:
espMqttClientSecure();
espMqttClientSecure& setInsecure();
espMqttClientSecure& setFingerprint(const uint8_t fingerprint[20]);
espMqttClientSecure& setTrustAnchors(const X509List *ta);
espMqttClientSecure& setClientRSACert(const X509List *cert, const PrivateKey *sk);
espMqttClientSecure& setClientECCert(const X509List *cert, const PrivateKey *sk, unsigned allowed_usages, unsigned cert_issuer_key_type);
espMqttClientSecure& setCertStore(CertStoreBase *certStore);
espMqttClient()
: MqttClientSetup<espMqttClient, MQTTVERSION>(espMqttClientTypes::UseInternalTask::NO)
, _client() {
_transport = &_client;
}

espMqttClientSecure()
: MqttClientSetup<espMqttClient, MQTTVERSION>(espMqttClientTypes::UseInternalTask::NO)
, _client() {
_transport = &_client;
}

espMqttClientSecure& setInsecure() {
_client.client.setInsecure();
return *this;
}

espMqttClientSecure& setFingerprint(const uint8_t fingerprint[20]) {
_client.client.setFingerprint(fingerprint);
return *this;
}

espMqttClientSecure& setTrustAnchors(const X509List *ta) {
_client.client.setTrustAnchors(ta);
return *this;
}

espMqttClientSecure& setClientRSACert(const X509List *cert, const PrivateKey *sk) {
_client.client.setClientRSACert(cert, sk);
return *this;
}

espMqttClientSecure& setClientECCert(const X509List *cert, const PrivateKey *sk, unsigned allowed_usages, unsigned cert_issuer_key_type) {
_client.client.setClientECCert(cert, sk, allowed_usages, cert_issuer_key_type);
return *this;
}

espMqttClientSecure& setCertStore(CertStoreBase *certStore) {
_client.client.setCertStore(certStore);
return *this;
}

protected:
espMqttClientInternals::ClientSecureSync _client;
};
#endif

#if defined(ARDUINO_ARCH_ESP32)
class espMqttClient : public MqttClientSetup<espMqttClient> {
template<class MQTTVERSION>
class espMqttClient : public MqttClientSetup<espMqttClient, MQTTVERSION> {
public:
explicit espMqttClient(espMqttClientTypes::UseInternalTask useInternalTask);
explicit espMqttClient(uint8_t priority = 1, uint8_t core = 1);
explicit espMqttClient(espMqttClientTypes::UseInternalTask useInternalTask)
: MqttClientSetup<espMqttClient, MQTTVERSION>(useInternalTask)
, _client() {
_transport = &_client;
}

espMqttClient(uint8_t priority, uint8_t core)
: MqttClientSetup<espMqttClient, MQTTVERSION>(espMqttClientTypes::UseInternalTask::YES, priority, core)
, _client() {
_transport = &_client;
}

protected:
espMqttClientInternals::ClientSync _client;
};

class espMqttClientSecure : public MqttClientSetup<espMqttClientSecure> {
template<class MQTTVERSION>
class espMqttClientSecure : public MqttClientSetup<espMqttClientSecure, MQTTVERSION> {
public:
explicit espMqttClientSecure(espMqttClientTypes::UseInternalTask useInternalTask);
explicit espMqttClientSecure(uint8_t priority = 1, uint8_t core = 1);
espMqttClientSecure& setInsecure();
espMqttClientSecure& setCACert(const char* rootCA);
espMqttClientSecure& setCertificate(const char* clientCa);
espMqttClientSecure& setPrivateKey(const char* privateKey);
espMqttClientSecure& setPreSharedKey(const char* pskIdent, const char* psKey);
espMqttClientSecure(espMqttClientTypes::UseInternalTask useInternalTask)
: MqttClientSetup<espMqttClient, MQTTVERSION>(useInternalTask)
, _client() {
_transport = &_client;
}

espMqttClientSecure(uint8_t priority, uint8_t core)
: MqttClientSetup<espMqttClient, MQTTVERSION>(espMqttClientTypes::UseInternalTask::YES, priority, core)
, _client() {
_transport = &_client;
}

espMqttClientSecure& setInsecure() {
_client.client.setInsecure();
return *this;
}

espMqttClientSecure& setCACert(const char* rootCA) {
_client.client.setCACert(rootCA);
return *this;
}

espMqttClientSecure& setCertificate(const char* clientCa) {
_client.client.setCertificate(clientCa);
return *this;
}

espMqttClientSecure& setPrivateKey(const char* privateKey) {
_client.client.setPrivateKey(privateKey);
return *this;
}

espMqttClientSecure& esetPreSharedKey(const char* pskIdent, const char* psKey) {
_client.client.setPreSharedKey(pskIdent, psKey);
return *this;
}

protected:
espMqttClientInternals::ClientSecureSync _client;
};
#endif

#if defined(__linux__)
class espMqttClient : public MqttClientSetup<espMqttClient> {
template<class MQTTVERSION>
class espMqttClient : public MqttClientSetup<espMqttClient, MQTTVERSION> {
public:
espMqttClient();
espMqttClient()
: MqttClientSetup<espMqttClient, MQTTVERSION>(espMqttClientTypes::UseInternalTask::NO)
, _client() {
_transport = &_client;
}

protected:
espMqttClientInternals::ClientPosix _client;
};
#endif

#define espMqttClient(...) espMqttClient<MqttVersion::v3_1_1>(__VA_ARGS__)
61 changes: 0 additions & 61 deletions src/espMqttClientAsync.cpp

This file was deleted.

Loading

0 comments on commit 094cd8a

Please sign in to comment.