Skip to content

Commit e7085e4

Browse files
committed
Removed unused client code from Duet 2 builds to save flash space
1 parent bc56400 commit e7085e4

File tree

5 files changed

+40
-25
lines changed

5 files changed

+40
-25
lines changed

src/Networking/Network.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ void MacAddress::SetFromBytes(const uint8_t mb[6]) noexcept
8686
// Network members
8787
Network::Network(Platform& p) noexcept : platform(p)
8888
#if HAS_RESPONDERS
89-
, responders(nullptr), clients(nullptr), nextResponderToPoll(nullptr)
89+
, responders(nullptr), nextResponderToPoll(nullptr)
90+
#endif
91+
#if HAS_CLIENTS
92+
, clients(nullptr)
9093
#endif
9194
{
9295
#if HAS_NETWORKING
@@ -239,6 +242,7 @@ GCodeResult Network::EnableProtocol(unsigned int interface, NetworkProtocol prot
239242
#if HAS_NETWORKING
240243
if (interface < GetNumNetworkInterfaces())
241244
{
245+
# if HAS_CLIENTS
242246
bool hasFree = false;
243247
bool client = false;
244248
// Check if there are enough clients to accomodate enabling the protocol. Check if
@@ -262,7 +266,7 @@ GCodeResult Network::EnableProtocol(unsigned int interface, NetworkProtocol prot
262266
reply.printf("No more instances for client protocol.\n");
263267
return GCodeResult::error;
264268
}
265-
269+
# endif
266270
return interfaces[interface]->EnableProtocol(protocol, port, ip, secure, reply);
267271
}
268272

@@ -281,6 +285,7 @@ GCodeResult Network::DisableProtocol(unsigned int interface, NetworkProtocol pro
281285
{
282286
bool client = false;
283287

288+
# if HAS_CLIENTS
284289
// Check if a client handles the protocol. If so, termination is handled
285290
// by the client itself, after attempting to disconnect gracefully.
286291
for (NetworkClient *c = clients; c != nullptr; c = c->GetNext())
@@ -291,57 +296,58 @@ GCodeResult Network::DisableProtocol(unsigned int interface, NetworkProtocol pro
291296
break;
292297
}
293298
}
299+
# endif
294300

295301
NetworkInterface * const iface = interfaces[interface];
296302
const GCodeResult ret = iface->DisableProtocol(protocol, reply, !client);
297303

298304
if (ret == GCodeResult::ok)
299305
{
300-
#if HAS_RESPONDERS
306+
# if HAS_RESPONDERS
301307
if (!client)
302308
{
303309
TerminateResponders(iface, protocol);
304310
}
305311

306312
switch (protocol)
307313
{
308-
#if SUPPORT_HTTP
314+
# if SUPPORT_HTTP
309315
case HttpProtocol:
310316
HttpResponder::DisableInterface(iface); // free up output buffers etc.
311317
break;
312-
#endif
318+
# endif
313319

314-
#if SUPPORT_FTP
320+
# if SUPPORT_FTP
315321
case FtpProtocol:
316322
// TODO the following isn't quite right, because we shouldn't free up output buffers if another network interface is still serving this protocol.
317323
FtpResponder::Disable();
318324
break;
319-
#endif
325+
# endif
320326

321-
#if SUPPORT_TELNET
327+
# if SUPPORT_TELNET
322328
case TelnetProtocol:
323329
// TODO the following isn't quite right, because we shouldn't free up output buffers if another network interface is still serving this protocol.
324330
TelnetResponder::Disable();
325331
break;
326-
#endif
332+
# endif
327333

328-
#if SUPPORT_MULTICAST_DISCOVERY
334+
# if SUPPORT_MULTICAST_DISCOVERY
329335
// TODO the following isn't quite right, because we shouldn't free up output buffers if another network interface is still serving this protocol.
330336
case MulticastDiscoveryProtocol:
331337
break;
332-
#endif
338+
# endif
333339

334-
#if SUPPORT_MQTT
340+
# if SUPPORT_MQTT
335341
case MqttProtocol:
336342
// TODO the following isn't quite right, because we shouldn't free up output buffers if another network interface is still serving this protocol.
337343
MqttClient::Disable();
338344
break;
339-
#endif
345+
# endif
340346

341347
default:
342348
break;
343349
}
344-
#endif // HAS_RESPONDERS
350+
# endif // HAS_RESPONDERS
345351
}
346352
return ret;
347353
}
@@ -740,11 +746,8 @@ bool Network::UsingDhcp(unsigned int interface) const noexcept
740746
return interface < GetNumNetworkInterfaces() && interfaces[interface]->UsingDhcp();
741747
}
742748

743-
#endif
744-
745749
void Network::SetHostname(const char *name) noexcept
746750
{
747-
#if HAS_NETWORKING
748751
size_t i = 0;
749752
while (*name && i < ARRAY_UPB(hostname))
750753
{
@@ -776,11 +779,8 @@ void Network::SetHostname(const char *name) noexcept
776779
iface->UpdateHostname(hostname);
777780
}
778781
}
779-
#endif
780782
}
781783

782-
#if HAS_NETWORKING
783-
784784
// Net the MAC address. Pass -1 as the interface number to set the default MAC address for interfaces that don't have one.
785785
GCodeResult Network::SetMacAddress(unsigned int interface, const MacAddress& mac, const StringRef& reply) noexcept
786786
{
@@ -820,7 +820,7 @@ bool Network::FindResponder(Socket *skt, NetworkProtocol protocol) noexcept
820820

821821
bool Network::StartClient(NetworkInterface *interface, NetworkProtocol protocol) noexcept
822822
{
823-
#if HAS_RESPONDERS
823+
#if HAS_CLIENTS
824824
for (NetworkClient *c = clients; c != nullptr; c = c->GetNext())
825825
{
826826
if (c->Start(protocol, interface))
@@ -834,7 +834,7 @@ bool Network::StartClient(NetworkInterface *interface, NetworkProtocol protocol)
834834

835835
void Network::StopClient(NetworkInterface *interface, NetworkProtocol protocol) noexcept
836836
{
837-
#if HAS_RESPONDERS
837+
#if HAS_CLIENTS
838838
for (NetworkClient *c = clients; c != nullptr; c = c->GetNext())
839839
{
840840
c->Stop(protocol, interface);

src/Networking/Network.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ const size_t NumTelnetResponders = 1; // the number of concurrent Telnet session
3838

3939
const size_t NumFtpResponders = 1; // the number of concurrent FTP sessions we support
4040

41-
#define HAS_RESPONDERS (SUPPORT_HTTP || SUPPORT_FTP || SUPPORT_TELNET)
42-
4341
// Forward declarations
4442
class NetworkResponder;
4543
class NetworkClient;
@@ -146,10 +144,13 @@ class Network INHERIT_OBJECT_MODEL
146144

147145
#if HAS_RESPONDERS
148146
NetworkResponder *responders;
149-
NetworkClient *clients;
150147
NetworkResponder *nextResponderToPoll;
151148
#endif
152149

150+
#if HAS_CLIENTS
151+
NetworkClient *clients;
152+
#endif
153+
153154
#if SUPPORT_HTTP
154155
Mutex httpMutex;
155156
#endif

src/Networking/NetworkClient.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
*/
77

88
#include "NetworkClient.h"
9+
10+
#if HAS_CLIENTS
11+
912
#include "Socket.h"
1013
#include <Platform/Platform.h>
1114

@@ -106,3 +109,7 @@ void NetworkClient::ConnectionLost() noexcept
106109
}
107110

108111
NetworkClient *NetworkClient::clients = nullptr;
112+
113+
#endif
114+
115+
// End

src/Networking/NetworkClient.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <RepRapFirmware.h>
1212
#include "NetworkResponder.h"
1313

14+
#if HAS_CLIENTS
15+
1416
// Forward declarations
1517
class NetworkClient;
1618
class NetworkInterface;
@@ -51,4 +53,6 @@ class NetworkClient : public NetworkResponder
5153
static NetworkClient *clients; // Head of the list of all network clients
5254
};
5355

56+
#endif
57+
5458
#endif /* SRC_NETWORKING_NETWORKCLIENT_H_ */

src/Networking/NetworkDefs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
#include <General/IPAddress.h>
1212

13+
#define HAS_RESPONDERS (SUPPORT_HTTP || SUPPORT_FTP || SUPPORT_TELNET)
14+
#define HAS_CLIENTS (SUPPORT_MQTT)
15+
1316
class NetworkBuffer;
1417

1518
typedef uint8_t SocketNumber;

0 commit comments

Comments
 (0)