mbed library sources(for async_print)

Dependents:   AsyncPrint

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Tue Nov 20 17:24:08 2012 +0000
Revision:
0:fd0d7bdfcdc2
Child:
1:62685faffa05
mbed sources

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:fd0d7bdfcdc2 1 /* mbed Microcontroller Library
mbed_official 0:fd0d7bdfcdc2 2 * Copyright (c) 2006-2012 ARM Limited
mbed_official 0:fd0d7bdfcdc2 3 *
mbed_official 0:fd0d7bdfcdc2 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
mbed_official 0:fd0d7bdfcdc2 5 * of this software and associated documentation files (the "Software"), to deal
mbed_official 0:fd0d7bdfcdc2 6 * in the Software without restriction, including without limitation the rights
mbed_official 0:fd0d7bdfcdc2 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
mbed_official 0:fd0d7bdfcdc2 8 * copies of the Software, and to permit persons to whom the Software is
mbed_official 0:fd0d7bdfcdc2 9 * furnished to do so, subject to the following conditions:
mbed_official 0:fd0d7bdfcdc2 10 *
mbed_official 0:fd0d7bdfcdc2 11 * The above copyright notice and this permission notice shall be included in
mbed_official 0:fd0d7bdfcdc2 12 * all copies or substantial portions of the Software.
mbed_official 0:fd0d7bdfcdc2 13 *
mbed_official 0:fd0d7bdfcdc2 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
mbed_official 0:fd0d7bdfcdc2 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
mbed_official 0:fd0d7bdfcdc2 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
mbed_official 0:fd0d7bdfcdc2 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
mbed_official 0:fd0d7bdfcdc2 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
mbed_official 0:fd0d7bdfcdc2 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
mbed_official 0:fd0d7bdfcdc2 20 * SOFTWARE.
mbed_official 0:fd0d7bdfcdc2 21 */
mbed_official 0:fd0d7bdfcdc2 22 #ifndef MBED_FILESYSTEMLIKE_H
mbed_official 0:fd0d7bdfcdc2 23 #define MBED_FILESYSTEMLIKE_H
mbed_official 0:fd0d7bdfcdc2 24
mbed_official 0:fd0d7bdfcdc2 25 #ifdef __ARMCC_VERSION
mbed_official 0:fd0d7bdfcdc2 26 # define O_RDONLY 0
mbed_official 0:fd0d7bdfcdc2 27 # define O_WRONLY 1
mbed_official 0:fd0d7bdfcdc2 28 # define O_RDWR 2
mbed_official 0:fd0d7bdfcdc2 29 # define O_CREAT 0x0200
mbed_official 0:fd0d7bdfcdc2 30 # define O_TRUNC 0x0400
mbed_official 0:fd0d7bdfcdc2 31 # define O_APPEND 0x0008
mbed_official 0:fd0d7bdfcdc2 32 typedef int mode_t;
mbed_official 0:fd0d7bdfcdc2 33
mbed_official 0:fd0d7bdfcdc2 34 #else
mbed_official 0:fd0d7bdfcdc2 35 # include <sys/fcntl.h>
mbed_official 0:fd0d7bdfcdc2 36 #endif
mbed_official 0:fd0d7bdfcdc2 37
mbed_official 0:fd0d7bdfcdc2 38 #include "platform.h"
mbed_official 0:fd0d7bdfcdc2 39
mbed_official 0:fd0d7bdfcdc2 40 #include "FileHandle.h"
mbed_official 0:fd0d7bdfcdc2 41 #include "DirHandle.h"
mbed_official 0:fd0d7bdfcdc2 42
mbed_official 0:fd0d7bdfcdc2 43 namespace mbed {
mbed_official 0:fd0d7bdfcdc2 44
mbed_official 0:fd0d7bdfcdc2 45 /** A filesystem-like object is one that can be used to open files
mbed_official 0:fd0d7bdfcdc2 46 * though it by fopen("/name/filename", mode)
mbed_official 0:fd0d7bdfcdc2 47 *
mbed_official 0:fd0d7bdfcdc2 48 * Implementations must define at least open (the default definitions
mbed_official 0:fd0d7bdfcdc2 49 * of the rest of the functions just return error values).
mbed_official 0:fd0d7bdfcdc2 50 */
mbed_official 0:fd0d7bdfcdc2 51 class FileSystemLike {
mbed_official 0:fd0d7bdfcdc2 52
mbed_official 0:fd0d7bdfcdc2 53 public:
mbed_official 0:fd0d7bdfcdc2 54 /** FileSystemLike constructor
mbed_official 0:fd0d7bdfcdc2 55 *
mbed_official 0:fd0d7bdfcdc2 56 * @param name The name to use for the filesystem.
mbed_official 0:fd0d7bdfcdc2 57 */
mbed_official 0:fd0d7bdfcdc2 58 FileSystemLike(const char *name);
mbed_official 0:fd0d7bdfcdc2 59
mbed_official 0:fd0d7bdfcdc2 60 virtual ~FileSystemLike();
mbed_official 0:fd0d7bdfcdc2 61
mbed_official 0:fd0d7bdfcdc2 62 /* Function lookup
mbed_official 0:fd0d7bdfcdc2 63 * Lookup and return the object that has the given name.
mbed_official 0:fd0d7bdfcdc2 64 *
mbed_official 0:fd0d7bdfcdc2 65 * Variables
mbed_official 0:fd0d7bdfcdc2 66 * name - the name to lookup.
mbed_official 0:fd0d7bdfcdc2 67 * len - the length of name.
mbed_official 0:fd0d7bdfcdc2 68 */
mbed_official 0:fd0d7bdfcdc2 69 static FileSystemLike *lookup(const char *name, unsigned int len);
mbed_official 0:fd0d7bdfcdc2 70
mbed_official 0:fd0d7bdfcdc2 71 static DirHandle *opendir();
mbed_official 0:fd0d7bdfcdc2 72 friend class BaseDirHandle;
mbed_official 0:fd0d7bdfcdc2 73
mbed_official 0:fd0d7bdfcdc2 74 /** Opens a file from the filesystem
mbed_official 0:fd0d7bdfcdc2 75 *
mbed_official 0:fd0d7bdfcdc2 76 * @param filename The name of the file to open.
mbed_official 0:fd0d7bdfcdc2 77 * @param flags One of O_RDONLY, O_WRONLY, or O_RDWR, OR'd with
mbed_official 0:fd0d7bdfcdc2 78 * zero or more of O_CREAT, O_TRUNC, or O_APPEND.
mbed_official 0:fd0d7bdfcdc2 79 *
mbed_official 0:fd0d7bdfcdc2 80 * @returns
mbed_official 0:fd0d7bdfcdc2 81 * A pointer to a FileHandle object representing the
mbed_official 0:fd0d7bdfcdc2 82 * file on success, or NULL on failure.
mbed_official 0:fd0d7bdfcdc2 83 */
mbed_official 0:fd0d7bdfcdc2 84 virtual FileHandle *open(const char *filename, int flags) = 0;
mbed_official 0:fd0d7bdfcdc2 85
mbed_official 0:fd0d7bdfcdc2 86 /** Remove a file from the filesystem.
mbed_official 0:fd0d7bdfcdc2 87 *
mbed_official 0:fd0d7bdfcdc2 88 * @param filename the name of the file to remove.
mbed_official 0:fd0d7bdfcdc2 89 * @param returns 0 on success, -1 on failure.
mbed_official 0:fd0d7bdfcdc2 90 */
mbed_official 0:fd0d7bdfcdc2 91 virtual int remove(const char *filename) { return -1; };
mbed_official 0:fd0d7bdfcdc2 92
mbed_official 0:fd0d7bdfcdc2 93 /** Rename a file in the filesystem.
mbed_official 0:fd0d7bdfcdc2 94 *
mbed_official 0:fd0d7bdfcdc2 95 * @param oldname the name of the file to rename.
mbed_official 0:fd0d7bdfcdc2 96 * @param newname the name to rename it to.
mbed_official 0:fd0d7bdfcdc2 97 *
mbed_official 0:fd0d7bdfcdc2 98 * @returns
mbed_official 0:fd0d7bdfcdc2 99 * 0 on success,
mbed_official 0:fd0d7bdfcdc2 100 * -1 on failure.
mbed_official 0:fd0d7bdfcdc2 101 */
mbed_official 0:fd0d7bdfcdc2 102 virtual int rename(const char *oldname, const char *newname) { return -1; };
mbed_official 0:fd0d7bdfcdc2 103
mbed_official 0:fd0d7bdfcdc2 104 /** Opens a directory in the filesystem and returns a DirHandle
mbed_official 0:fd0d7bdfcdc2 105 * representing the directory stream.
mbed_official 0:fd0d7bdfcdc2 106 *
mbed_official 0:fd0d7bdfcdc2 107 * @param name The name of the directory to open.
mbed_official 0:fd0d7bdfcdc2 108 *
mbed_official 0:fd0d7bdfcdc2 109 * @returns
mbed_official 0:fd0d7bdfcdc2 110 * A DirHandle representing the directory stream, or
mbed_official 0:fd0d7bdfcdc2 111 * NULL on failure.
mbed_official 0:fd0d7bdfcdc2 112 */
mbed_official 0:fd0d7bdfcdc2 113 virtual DirHandle *opendir(const char *name) { return NULL; };
mbed_official 0:fd0d7bdfcdc2 114
mbed_official 0:fd0d7bdfcdc2 115 /** Creates a directory in the filesystem.
mbed_official 0:fd0d7bdfcdc2 116 *
mbed_official 0:fd0d7bdfcdc2 117 * @param name The name of the directory to create.
mbed_official 0:fd0d7bdfcdc2 118 * @param mode The permissions to create the directory with.
mbed_official 0:fd0d7bdfcdc2 119 *
mbed_official 0:fd0d7bdfcdc2 120 * @returns
mbed_official 0:fd0d7bdfcdc2 121 * 0 on success,
mbed_official 0:fd0d7bdfcdc2 122 * -1 on failure.
mbed_official 0:fd0d7bdfcdc2 123 */
mbed_official 0:fd0d7bdfcdc2 124 virtual int mkdir(const char *name, mode_t mode) { return -1; }
mbed_official 0:fd0d7bdfcdc2 125
mbed_official 0:fd0d7bdfcdc2 126 // TODO other filesystem functions (mkdir, rm, rn, ls etc)
mbed_official 0:fd0d7bdfcdc2 127
mbed_official 0:fd0d7bdfcdc2 128 protected:
mbed_official 0:fd0d7bdfcdc2 129 static FileSystemLike *_head;
mbed_official 0:fd0d7bdfcdc2 130 FileSystemLike *_next;
mbed_official 0:fd0d7bdfcdc2 131 const char *_name;
mbed_official 0:fd0d7bdfcdc2 132 };
mbed_official 0:fd0d7bdfcdc2 133
mbed_official 0:fd0d7bdfcdc2 134 class FilePath {
mbed_official 0:fd0d7bdfcdc2 135 public:
mbed_official 0:fd0d7bdfcdc2 136 FilePath(const char* file_path);
mbed_official 0:fd0d7bdfcdc2 137
mbed_official 0:fd0d7bdfcdc2 138 const char* fileName(void);
mbed_official 0:fd0d7bdfcdc2 139 FileSystemLike* fileSystem(void);
mbed_official 0:fd0d7bdfcdc2 140
mbed_official 0:fd0d7bdfcdc2 141 static FileSystemLike* getFileSystem(const char* path);
mbed_official 0:fd0d7bdfcdc2 142
mbed_official 0:fd0d7bdfcdc2 143 private:
mbed_official 0:fd0d7bdfcdc2 144 const char* file_name;
mbed_official 0:fd0d7bdfcdc2 145 FileSystemLike* fs;
mbed_official 0:fd0d7bdfcdc2 146 };
mbed_official 0:fd0d7bdfcdc2 147
mbed_official 0:fd0d7bdfcdc2 148 } // namespace mbed
mbed_official 0:fd0d7bdfcdc2 149
mbed_official 0:fd0d7bdfcdc2 150 #endif