Skip to content

Commit

Permalink
Bridge: Fixed File "duplicate definitions" when using SD and Bridge l…
Browse files Browse the repository at this point in the history
…ibraries together

The two File classes have been enclosed into different namespaces.

To guarantee compatibility with old sketches that uses only one of the two
libraries an additional line:

   using namespace xxxxx;

has been added so the users can still use "File" where there is no ambiguity.

BridgeLib::File and SDLib::File classes have been also aliased to BridgeFile
and SDFile respectively, users are encouraged to use that instead of File.
  • Loading branch information
cmaglie committed Jun 30, 2015
1 parent 36c2216 commit 954f59d
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 2 deletions.
1 change: 1 addition & 0 deletions libraries/Bridge/keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ connected KEYWORD2

# FileIO Class
File KEYWORD2
BridgeFile KEYWORD2
seek KEYWORD2
position KEYWORD2
size KEYWORD2
Expand Down
2 changes: 1 addition & 1 deletion libraries/Bridge/library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Bridge
version=1.0.7
version=1.1.0
author=Arduino
maintainer=Arduino <[email protected]>
sentence=Enables the communication between the Linux processor and the AVR. For Arduino Yún and TRE only.
Expand Down
4 changes: 3 additions & 1 deletion libraries/Bridge/src/FileIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include <FileIO.h>


namespace BridgeLib {

File::File(BridgeClass &b) : mode(255), bridge(b) {
// Empty
Expand Down Expand Up @@ -279,3 +279,5 @@ boolean FileSystemClass::rmdir(const char *filepath) {
}

FileSystemClass FileSystem;

}
17 changes: 17 additions & 0 deletions libraries/Bridge/src/FileIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#define FILE_WRITE 1
#define FILE_APPEND 2

namespace BridgeLib {

class File : public Stream {

public:
Expand Down Expand Up @@ -100,4 +102,19 @@ class FileSystemClass {

extern FileSystemClass FileSystem;

};

// We enclose File and FileSystem classes in namespace BridgeLib to avoid
// conflicts with legacy SD library.

// This ensure compatibility with older sketches that uses only Bridge lib
// (the user can still use File instead of BridgeFile)
using namespace BridgeLib;

// This allows sketches to use BridgeLib::File together with SD library
// (you must use BridgeFile instead of File when needed to disambiguate)
typedef BridgeLib::File BridgeFile;
typedef BridgeLib::FileSystemClass BridgeFileSystemClass;
#define BridgeFileSystem BridgeLib::FileSystem

#endif
1 change: 1 addition & 0 deletions libraries/SD/keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

SD KEYWORD1 SD
File KEYWORD1 SD
SDFile KEYWORD1 SD

#######################################
# Methods and Functions (KEYWORD2)
Expand Down
4 changes: 4 additions & 0 deletions libraries/SD/src/SD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@

#include "SD.h"

namespace SDLib {

// Used by `getNextPathComponent`
#define MAX_COMPONENT_LEN 12 // What is max length?
#define PATH_COMPONENT_BUFFER_LEN MAX_COMPONENT_LEN+1
Expand Down Expand Up @@ -614,3 +616,5 @@ void File::rewindDirectory(void) {
}

SDClass SD;

};
16 changes: 16 additions & 0 deletions libraries/SD/src/SD.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#define FILE_READ O_READ
#define FILE_WRITE (O_READ | O_WRITE | O_CREAT)

namespace SDLib {

class File : public Stream {
private:
char _name[13]; // our name
Expand Down Expand Up @@ -104,4 +106,18 @@ class SDClass {

extern SDClass SD;

};

// We enclose File and SD classes in namespace SDLib to avoid conflicts
// with others legacy libraries that redefines File class.

// This ensure compatibility with sketches that uses only SD library
using namespace SDLib;

// This allows sketches to use SDLib::File with other libraries (in the
// sketch you must use SDFile instead of File to disambiguate)
typedef SDLib::File SDFile;
typedef SDLib::SDClass SDFileSystemClass;
#define SDFileSystem SDLib::SD

#endif

0 comments on commit 954f59d

Please sign in to comment.