From 5cbaa57af98a3c3c621b4e3adf75ce2680292c05 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Wed, 5 Aug 2015 08:36:43 -0400 Subject: [PATCH] Resolve naming conflicts between FS and SD library --- cores/esp8266/FS.cpp | 2 ++ cores/esp8266/FS.h | 8 ++++++++ cores/esp8266/FSImpl.h | 3 +++ cores/esp8266/spiffs_api.cpp | 2 ++ libraries/ESP8266WebServer/src/ESP8266WebServer.cpp | 3 ++- libraries/ESP8266WebServer/src/ESP8266WebServer.h | 4 ++-- 6 files changed, 19 insertions(+), 3 deletions(-) diff --git a/cores/esp8266/FS.cpp b/cores/esp8266/FS.cpp index 030d79f0d..7a13dcede 100644 --- a/cores/esp8266/FS.cpp +++ b/cores/esp8266/FS.cpp @@ -21,6 +21,8 @@ #include "FS.h" #include "FSImpl.h" +using namespace fs; + static bool sflags(const char* mode, OpenMode& om, AccessMode& am); size_t File::write(uint8_t c) { diff --git a/cores/esp8266/FS.h b/cores/esp8266/FS.h index c2b29ba09..3e1b1b4fc 100644 --- a/cores/esp8266/FS.h +++ b/cores/esp8266/FS.h @@ -24,6 +24,8 @@ #include #include +namespace fs { + class File; class Dir; @@ -106,6 +108,12 @@ protected: }; +} // namespace fs + +using fs::FS; +using fs::File; +using fs::Dir; + extern FS SPIFFS; #endif //FS_H diff --git a/cores/esp8266/FSImpl.h b/cores/esp8266/FSImpl.h index f11342f12..8e48a9fda 100644 --- a/cores/esp8266/FSImpl.h +++ b/cores/esp8266/FSImpl.h @@ -23,6 +23,8 @@ #include #include +namespace fs { + class FileImpl { public: virtual ~FileImpl() { } @@ -67,5 +69,6 @@ public: }; +} // namespace fs #endif //FSIMPL_H diff --git a/cores/esp8266/spiffs_api.cpp b/cores/esp8266/spiffs_api.cpp index 480755087..157ae86bc 100644 --- a/cores/esp8266/spiffs_api.cpp +++ b/cores/esp8266/spiffs_api.cpp @@ -32,6 +32,8 @@ extern "C" { #include "spi_flash.h" } +using namespace fs; + extern int32_t spiffs_hal_write(uint32_t addr, uint32_t size, uint8_t *src); extern int32_t spiffs_hal_erase(uint32_t addr, uint32_t size); extern int32_t spiffs_hal_read(uint32_t addr, uint32_t size, uint8_t *dst); diff --git a/libraries/ESP8266WebServer/src/ESP8266WebServer.cpp b/libraries/ESP8266WebServer/src/ESP8266WebServer.cpp index bc0073774..c709dcfdd 100644 --- a/libraries/ESP8266WebServer/src/ESP8266WebServer.cpp +++ b/libraries/ESP8266WebServer/src/ESP8266WebServer.cpp @@ -24,6 +24,7 @@ #include #include "WiFiServer.h" #include "WiFiClient.h" +#include "FS.h" #include "ESP8266WebServer.h" #include "detail/RequestHandler.h" // #define DEBUG @@ -77,7 +78,7 @@ void ESP8266WebServer::_addRequestHandler(RequestHandler* handler) { } } -void ESP8266WebServer::serveStatic(const char* uri, FS fs, const char* path) { +void ESP8266WebServer::serveStatic(const char* uri, FS& fs, const char* path) { _addRequestHandler(new StaticRequestHandler(fs, uri)); } diff --git a/libraries/ESP8266WebServer/src/ESP8266WebServer.h b/libraries/ESP8266WebServer/src/ESP8266WebServer.h index 49c610294..74d3ecb45 100644 --- a/libraries/ESP8266WebServer/src/ESP8266WebServer.h +++ b/libraries/ESP8266WebServer/src/ESP8266WebServer.h @@ -25,7 +25,6 @@ #define ESP8266WEBSERVER_H #include -#include enum HTTPMethod { HTTP_ANY, HTTP_GET, HTTP_POST, HTTP_PUT, HTTP_PATCH, HTTP_DELETE }; enum HTTPUploadStatus { UPLOAD_FILE_START, UPLOAD_FILE_WRITE, UPLOAD_FILE_END }; @@ -39,6 +38,7 @@ enum HTTPUploadStatus { UPLOAD_FILE_START, UPLOAD_FILE_WRITE, UPLOAD_FILE_END }; #define CONTENT_LENGTH_NOT_SET ((size_t) -2) class RequestHandler; +class FS; typedef struct { HTTPUploadStatus status; @@ -62,7 +62,7 @@ public: typedef std::function THandlerFunction; void on(const char* uri, THandlerFunction handler); void on(const char* uri, HTTPMethod method, THandlerFunction fn); - void serveStatic(const char* uri, FS fs, const char* path); + void serveStatic(const char* uri, FS& fs, const char* path); void onNotFound(THandlerFunction fn); //called when handler is not assigned void onFileUpload(THandlerFunction fn); //handle file uploads