Skip to content

Commit ab4244d

Browse files
committed
Cleanup URLStream design
1 parent c4c8f52 commit ab4244d

File tree

6 files changed

+56
-133
lines changed

6 files changed

+56
-133
lines changed

src/AudioHttp/AudioHttp.h

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

88
#include "AudioHttp/URLStream.h"
9-
#include "AudioHttp/URLStreamESP32.h"
9+
#include "AudioHttp/URLStreamBuffered.h"
1010
#include "AudioHttp/AudioServer.h"
1111
#include "AudioHttp/ICYStream.h"
12-
#include "AudioHttp/ICYStreamESP32.h"
12+
#include "AudioHttp/ICYStreamBuffered.h"

src/AudioHttp/HttpRequest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace audio_tools {
2929

3030
class HttpRequest {
3131
public:
32-
friend class URLStreamDefault;
32+
friend class URLStream;
3333

3434
HttpRequest() {
3535
LOGI("HttpRequest");

src/AudioHttp/ICYStream.h

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#ifdef USE_URL_ARDUINO
33

44
#include "AudioConfig.h"
5-
#include "AudioHttp/URLStreamESP32.h"
5+
#include "AudioHttp/URLStreamBuffered.h"
66
#include "AudioMetaData/MetaDataICY.h"
77

88
namespace audio_tools {
@@ -12,35 +12,35 @@ namespace audio_tools {
1212
* regular stream functions. The metadata is handled with the help of the MetaDataICY state machine and provided via a callback method.
1313
*
1414
* This is basically just a URLStream with the metadata turned on.
15-
*
15+
* @ingroup http
1616
* @author Phil Schatzmann
1717
* @copyright GPLv3
1818
*/
1919

2020

21-
class ICYStreamDefault : public AbstractURLStream {
21+
class ICYStream : public AbstractURLStream {
2222

2323
public:
24-
ICYStreamDefault(int readBufferSize=DEFAULT_BUFFER_SIZE){
24+
ICYStream(int readBufferSize=DEFAULT_BUFFER_SIZE){
2525
TRACEI();
26-
url = new URLStreamDefault(readBufferSize);
26+
url = new URLStream(readBufferSize);
2727
checkUrl();
2828
}
2929

30-
ICYStreamDefault(Client &clientPar, int readBufferSize=DEFAULT_BUFFER_SIZE){
30+
ICYStream(Client &clientPar, int readBufferSize=DEFAULT_BUFFER_SIZE){
3131
TRACEI();
32-
url = new URLStreamDefault(clientPar, readBufferSize);
32+
url = new URLStream(clientPar, readBufferSize);
3333
checkUrl();
3434
}
3535

3636
/// Default constructor
37-
ICYStreamDefault(const char* network, const char *password, int readBufferSize=DEFAULT_BUFFER_SIZE) {
37+
ICYStream(const char* network, const char *password, int readBufferSize=DEFAULT_BUFFER_SIZE) {
3838
TRACEI();
39-
url = new URLStreamDefault(network, password, readBufferSize);
39+
url = new URLStream(network, password, readBufferSize);
4040
checkUrl();
4141
}
4242

43-
~ICYStreamDefault(){
43+
~ICYStream(){
4444
TRACEI();
4545
if (url!=nullptr) delete url;
4646
}
@@ -83,7 +83,7 @@ class ICYStreamDefault : public AbstractURLStream {
8383
icy.end();
8484
}
8585

86-
/// provides the available method from the URLStreamDefault
86+
/// provides the available method from the URLStream
8787
virtual int available() override {
8888
return url->available();
8989
}
@@ -162,7 +162,7 @@ class ICYStreamDefault : public AbstractURLStream {
162162

163163

164164
protected:
165-
URLStreamDefault *url = nullptr;
165+
URLStream *url = nullptr;
166166
MetaDataICY icy; // icy state machine
167167
void (*callback)(MetaDataType info, const char* str, int len)=nullptr;
168168

@@ -174,31 +174,5 @@ class ICYStreamDefault : public AbstractURLStream {
174174

175175
};
176176

177-
#ifndef USE_URLSTREAM_TASK
178-
/**
179-
* @brief ICYStream for all environment except ESP32
180-
* @ingroup http
181-
* @author Phil Schatzmann
182-
* @copyright GPLv3
183-
*/
184-
class ICYStream : public ICYStreamDefault {
185-
public:
186-
ICYStream(int readBufferSize=DEFAULT_BUFFER_SIZE)
187-
:ICYStreamDefault(readBufferSize){
188-
TRACEI();
189-
}
190-
ICYStream(Client &clientPar, int readBufferSize=DEFAULT_BUFFER_SIZE)
191-
:ICYStreamDefault(clientPar, readBufferSize){
192-
TRACEI();
193-
}
194-
195-
ICYStream(const char* network, const char *password, int readBufferSize=DEFAULT_BUFFER_SIZE)
196-
:ICYStreamDefault(network,password,readBufferSize) {
197-
TRACEI();
198-
}
199-
};
200-
201-
#endif
202-
203177
} // namespace
204178
#endif

src/AudioHttp/ICYStreamESP32.h renamed to src/AudioHttp/ICYStreamBuffered.h

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#pragma once
2+
#ifdef ESP32
23
#include "AudioConfig.h"
3-
#ifdef USE_URLSTREAM_TASK
4-
54
#include "AudioHttp/ICYStream.h"
65

76
namespace audio_tools {
@@ -12,33 +11,33 @@ namespace audio_tools {
1211
* regular stream functions. The metadata is handled with the help of the MetaDataICY state machine and provided via a callback method.
1312
*
1413
* This is basically just a URLStream with the metadata turned on.
15-
*
14+
* @ingroup http
1615
* @author Phil Schatzmann
1716
* @copyright GPLv3
1817
*/
1918

20-
class ICYStream : public AbstractURLStream {
19+
class ICYStreamBuffered : public AbstractURLStream {
2120
public:
2221

23-
ICYStream(int readBufferSize=DEFAULT_BUFFER_SIZE){
22+
ICYStreamBuffered(int readBufferSize=DEFAULT_BUFFER_SIZE){
2423
TRACEI();
25-
p_urlStream = new ICYStreamDefault(readBufferSize);
24+
p_urlStream = new ICYStream(readBufferSize);
2625
taskStream.setInput(*p_urlStream);
2726
}
2827

29-
ICYStream(Client &clientPar, int readBufferSize=DEFAULT_BUFFER_SIZE){
28+
ICYStreamBuffered(Client &clientPar, int readBufferSize=DEFAULT_BUFFER_SIZE){
3029
TRACEI();
31-
p_urlStream = new ICYStreamDefault(clientPar, readBufferSize);
30+
p_urlStream = new ICYStream(clientPar, readBufferSize);
3231
taskStream.setInput(*p_urlStream);
3332
}
3433

35-
ICYStream(const char* network, const char *password, int readBufferSize=DEFAULT_BUFFER_SIZE) {
34+
ICYStreamBuffered(const char* network, const char *password, int readBufferSize=DEFAULT_BUFFER_SIZE) {
3635
TRACEI();
37-
p_urlStream = new ICYStreamDefault(network, password, readBufferSize);
36+
p_urlStream = new ICYStream(network, password, readBufferSize);
3837
taskStream.setInput(*p_urlStream);
3938
}
4039

41-
~ICYStream(){
40+
~ICYStreamBuffered(){
4241
TRACEI();
4342
if (p_urlStream!=nullptr) delete p_urlStream;
4443
}
@@ -103,7 +102,7 @@ class ICYStream : public AbstractURLStream {
103102

104103
protected:
105104
BufferedTaskStream taskStream;
106-
ICYStreamDefault* p_urlStream=nullptr;
105+
ICYStream* p_urlStream=nullptr;
107106

108107
};
109108

src/AudioHttp/URLStream.h

Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
#ifdef USE_URL_ARDUINO
55

66
#if defined(ESP32)
7-
#include <Client.h>
8-
#include <WiFiClientSecure.h>
9-
#include <esp_wifi.h>
7+
# include <Client.h>
8+
# include <WiFiClientSecure.h>
9+
# include <esp_wifi.h>
1010
#elif defined(ESP8266)
11-
#include <ESP8266WiFi.h>
11+
# include <ESP8266WiFi.h>
1212
#elif defined(IS_DESKTOP)
13-
#include <Client.h>
14-
#include <WiFiClient.h>
13+
# include <Client.h>
14+
# include <WiFiClient.h>
1515
typedef WiFiClient WiFiClientSecure;
1616
#endif
1717

@@ -32,31 +32,32 @@ namespace audio_tools {
3232
/**
3333
* @brief Represents the content of a URL as Stream. We use the WiFi.h API
3434
* @author Phil Schatzmann
35+
* @ingroup http
3536
* @copyright GPLv3
3637
*
3738
*/
38-
class URLStreamDefault : public AbstractURLStream {
39+
class URLStream : public AbstractURLStream {
3940
public:
4041

41-
URLStreamDefault(int readBufferSize=DEFAULT_BUFFER_SIZE){
42+
URLStream(int readBufferSize=DEFAULT_BUFFER_SIZE){
4243
TRACEI();
4344
read_buffer_size = readBufferSize;
4445
}
4546

46-
URLStreamDefault(Client &clientPar, int readBufferSize=DEFAULT_BUFFER_SIZE){
47+
URLStream(Client &clientPar, int readBufferSize=DEFAULT_BUFFER_SIZE){
4748
TRACEI();
4849
read_buffer_size = readBufferSize;
4950
client = &clientPar;
5051
}
5152

52-
URLStreamDefault(const char* network, const char *password, int readBufferSize=DEFAULT_BUFFER_SIZE) {
53+
URLStream(const char* network, const char *password, int readBufferSize=DEFAULT_BUFFER_SIZE) {
5354
TRACEI();
5455
read_buffer_size = readBufferSize;
5556
this->network = (char*)network;
5657
this->password = (char*)password;
5758
}
5859

59-
~URLStreamDefault(){
60+
~URLStream(){
6061
TRACEI();
6162
#ifdef USE_WIFI_CLIENT_SECURE
6263
if (clientSecure!=nullptr){
@@ -160,7 +161,7 @@ class URLStreamDefault : public AbstractURLStream {
160161
clientTimeout = ms;
161162
}
162163

163-
/// if set to true, it activates the power save mode which comes at the cost of porformance! - By default this is deactivated.
164+
/// if set to true, it activates the power save mode which comes at the cost of porformance! - By default this is deactivated. ESP32 Only!
164165
void setPowerSave(bool ps){
165166
is_power_save = ps;
166167
}
@@ -271,7 +272,7 @@ class URLStreamDefault : public AbstractURLStream {
271272
void login(){
272273
#ifndef IS_DESKTOP
273274
LOGD("connectWiFi");
274-
if (WiFi.status() != WL_CONNECTED && network!=nullptr && password != nullptr){
275+
if (network!=nullptr && password != nullptr && WiFi.status() != WL_CONNECTED){
275276
WiFi.begin(network, password);
276277
while (WiFi.status() != WL_CONNECTED){
277278
Serial.print(".");
@@ -300,33 +301,6 @@ class URLStreamDefault : public AbstractURLStream {
300301
}
301302
};
302303

303-
#ifndef USE_URLSTREAM_TASK
304-
305-
/**
306-
* @brief URLStream implementation for all envionments except ESP32
307-
* @author Phil Schatzmann
308-
* @copyright GPLv3
309-
*/
310-
class URLStream : public URLStreamDefault {
311-
public:
312-
URLStream(int readBufferSize=DEFAULT_BUFFER_SIZE)
313-
:URLStreamDefault(readBufferSize){
314-
TRACEI();
315-
}
316-
317-
URLStream(Client &clientPar, int readBufferSize=DEFAULT_BUFFER_SIZE)
318-
:URLStreamDefault(clientPar, readBufferSize){
319-
TRACEI();
320-
}
321-
322-
URLStream(const char* network, const char *password, int readBufferSize=DEFAULT_BUFFER_SIZE)
323-
:URLStreamDefault(network,password,readBufferSize) {
324-
TRACEI();
325-
}
326-
};
327-
328-
#endif
329-
330304
}
331305

332306
#endif

0 commit comments

Comments
 (0)