Skip to content

Commit e960fda

Browse files
fixup! [TMP] extending Client apis
1 parent d8938f7 commit e960fda

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

api/net/TCPClient.h

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,40 @@ namespace arduino { namespace net {
2222
// - middleware definition: between TCPclient and the user there are multiple middleware layers
2323
// that act as layer 5/6 of iso/osi stack, TLS is one of them (are there any others?)
2424
// - sort of client embedding, which may be more flexible
25-
// - I always instantiate a TCPClient, but if I need Http, I will add it as middleware to the current instance
25+
// + I always instantiate a TCPClient, but if I need Http, I will add it as middleware to the current instance
2626
// + If HttpClient has different specifics from a TCPClient they might be hard to expose
2727
// - It could be nice to have an explicit connectSSL in client which enables SSL
2828

29+
// We can make this Client available to platforms with enough resources.
30+
31+
/* The idea of client factories is that they are going to be defined by the platform, so that depending on the network stack
32+
* implementation one can make use of a generic TCP client. For instance zephyr or mbed core can apply an implementation
33+
* that is not dependant on the network interface that is being used. on other cores, on which local routing is not implemented
34+
* the client is bound to the interface, thus depending on which one is the default interface one has to select the proper class
35+
*
36+
* Example zephyr, this can be placed in the library SocketWrapper:
37+
*
38+
* void __setClientFactory() __attribute__((constructor)) {
39+
* TCPClientConnect::setFactory([]() {
40+
* new ZephyrClient()
41+
* );
42+
* });
43+
* }
44+
*
45+
* Example Mbed os, this can be placed in the library Ethernet:
46+
*
47+
* void __setClientFactory() __attribute__((constructor)) {
48+
* // check that there is no other factory already defined. First defined First used
49+
* if(TCPClientConnect::factory != nullptr) {
50+
* TCPClientConnect::setFactory([]() {
51+
* return unique_ptr(
52+
* new EthernetClient()
53+
* );
54+
* });
55+
* }
56+
* }
57+
*/
58+
2959
class TCPClientConnect: public ClientConnect {
3060
public:
3161

@@ -43,7 +73,7 @@ class TCPClientConnect: public ClientConnect {
4373
uint8_t connected() override;
4474
operator bool() override;
4575

46-
protected:
76+
protected: // TODO should this be private?
4777
// the factory should provide a way to allocate and deallocate the client
4878
// there should be a default factory that uses to use the default network interface
4979
static std::function<std::unique_ptr<Client>()> _factory;

0 commit comments

Comments
 (0)