Birkbeck College Mobile and Ubiquitous Computing IoT Lab Exercise 2
Dependencies: BLE_API_Native_blog
mbed/FileSystemLike.h@0:e8fdba0ed044, 2015-03-07 (annotated)
- Committer:
- gkroussos
- Date:
- Sat Mar 07 16:34:53 2015 +0000
- Revision:
- 0:e8fdba0ed044
MUC IoT Workshop v1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gkroussos | 0:e8fdba0ed044 | 1 | /* mbed Microcontroller Library |
gkroussos | 0:e8fdba0ed044 | 2 | * Copyright (c) 2006-2013 ARM Limited |
gkroussos | 0:e8fdba0ed044 | 3 | * |
gkroussos | 0:e8fdba0ed044 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
gkroussos | 0:e8fdba0ed044 | 5 | * you may not use this file except in compliance with the License. |
gkroussos | 0:e8fdba0ed044 | 6 | * You may obtain a copy of the License at |
gkroussos | 0:e8fdba0ed044 | 7 | * |
gkroussos | 0:e8fdba0ed044 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
gkroussos | 0:e8fdba0ed044 | 9 | * |
gkroussos | 0:e8fdba0ed044 | 10 | * Unless required by applicable law or agreed to in writing, software |
gkroussos | 0:e8fdba0ed044 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
gkroussos | 0:e8fdba0ed044 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
gkroussos | 0:e8fdba0ed044 | 13 | * See the License for the specific language governing permissions and |
gkroussos | 0:e8fdba0ed044 | 14 | * limitations under the License. |
gkroussos | 0:e8fdba0ed044 | 15 | */ |
gkroussos | 0:e8fdba0ed044 | 16 | #ifndef MBED_FILESYSTEMLIKE_H |
gkroussos | 0:e8fdba0ed044 | 17 | #define MBED_FILESYSTEMLIKE_H |
gkroussos | 0:e8fdba0ed044 | 18 | |
gkroussos | 0:e8fdba0ed044 | 19 | #include "platform.h" |
gkroussos | 0:e8fdba0ed044 | 20 | |
gkroussos | 0:e8fdba0ed044 | 21 | #include "FileBase.h" |
gkroussos | 0:e8fdba0ed044 | 22 | #include "FileHandle.h" |
gkroussos | 0:e8fdba0ed044 | 23 | #include "DirHandle.h" |
gkroussos | 0:e8fdba0ed044 | 24 | |
gkroussos | 0:e8fdba0ed044 | 25 | namespace mbed { |
gkroussos | 0:e8fdba0ed044 | 26 | |
gkroussos | 0:e8fdba0ed044 | 27 | /** A filesystem-like object is one that can be used to open files |
gkroussos | 0:e8fdba0ed044 | 28 | * though it by fopen("/name/filename", mode) |
gkroussos | 0:e8fdba0ed044 | 29 | * |
gkroussos | 0:e8fdba0ed044 | 30 | * Implementations must define at least open (the default definitions |
gkroussos | 0:e8fdba0ed044 | 31 | * of the rest of the functions just return error values). |
gkroussos | 0:e8fdba0ed044 | 32 | */ |
gkroussos | 0:e8fdba0ed044 | 33 | class FileSystemLike : public FileBase { |
gkroussos | 0:e8fdba0ed044 | 34 | |
gkroussos | 0:e8fdba0ed044 | 35 | public: |
gkroussos | 0:e8fdba0ed044 | 36 | /** FileSystemLike constructor |
gkroussos | 0:e8fdba0ed044 | 37 | * |
gkroussos | 0:e8fdba0ed044 | 38 | * @param name The name to use for the filesystem. |
gkroussos | 0:e8fdba0ed044 | 39 | */ |
gkroussos | 0:e8fdba0ed044 | 40 | FileSystemLike(const char *name); |
gkroussos | 0:e8fdba0ed044 | 41 | |
gkroussos | 0:e8fdba0ed044 | 42 | virtual ~FileSystemLike(); |
gkroussos | 0:e8fdba0ed044 | 43 | |
gkroussos | 0:e8fdba0ed044 | 44 | static DirHandle *opendir(); |
gkroussos | 0:e8fdba0ed044 | 45 | friend class BaseDirHandle; |
gkroussos | 0:e8fdba0ed044 | 46 | |
gkroussos | 0:e8fdba0ed044 | 47 | /** Opens a file from the filesystem |
gkroussos | 0:e8fdba0ed044 | 48 | * |
gkroussos | 0:e8fdba0ed044 | 49 | * @param filename The name of the file to open. |
gkroussos | 0:e8fdba0ed044 | 50 | * @param flags One of O_RDONLY, O_WRONLY, or O_RDWR, OR'd with |
gkroussos | 0:e8fdba0ed044 | 51 | * zero or more of O_CREAT, O_TRUNC, or O_APPEND. |
gkroussos | 0:e8fdba0ed044 | 52 | * |
gkroussos | 0:e8fdba0ed044 | 53 | * @returns |
gkroussos | 0:e8fdba0ed044 | 54 | * A pointer to a FileHandle object representing the |
gkroussos | 0:e8fdba0ed044 | 55 | * file on success, or NULL on failure. |
gkroussos | 0:e8fdba0ed044 | 56 | */ |
gkroussos | 0:e8fdba0ed044 | 57 | virtual FileHandle *open(const char *filename, int flags) = 0; |
gkroussos | 0:e8fdba0ed044 | 58 | |
gkroussos | 0:e8fdba0ed044 | 59 | /** Remove a file from the filesystem. |
gkroussos | 0:e8fdba0ed044 | 60 | * |
gkroussos | 0:e8fdba0ed044 | 61 | * @param filename the name of the file to remove. |
gkroussos | 0:e8fdba0ed044 | 62 | * @param returns 0 on success, -1 on failure. |
gkroussos | 0:e8fdba0ed044 | 63 | */ |
gkroussos | 0:e8fdba0ed044 | 64 | virtual int remove(const char *filename) { return -1; }; |
gkroussos | 0:e8fdba0ed044 | 65 | |
gkroussos | 0:e8fdba0ed044 | 66 | /** Rename a file in the filesystem. |
gkroussos | 0:e8fdba0ed044 | 67 | * |
gkroussos | 0:e8fdba0ed044 | 68 | * @param oldname the name of the file to rename. |
gkroussos | 0:e8fdba0ed044 | 69 | * @param newname the name to rename it to. |
gkroussos | 0:e8fdba0ed044 | 70 | * |
gkroussos | 0:e8fdba0ed044 | 71 | * @returns |
gkroussos | 0:e8fdba0ed044 | 72 | * 0 on success, |
gkroussos | 0:e8fdba0ed044 | 73 | * -1 on failure. |
gkroussos | 0:e8fdba0ed044 | 74 | */ |
gkroussos | 0:e8fdba0ed044 | 75 | virtual int rename(const char *oldname, const char *newname) { return -1; }; |
gkroussos | 0:e8fdba0ed044 | 76 | |
gkroussos | 0:e8fdba0ed044 | 77 | /** Opens a directory in the filesystem and returns a DirHandle |
gkroussos | 0:e8fdba0ed044 | 78 | * representing the directory stream. |
gkroussos | 0:e8fdba0ed044 | 79 | * |
gkroussos | 0:e8fdba0ed044 | 80 | * @param name The name of the directory to open. |
gkroussos | 0:e8fdba0ed044 | 81 | * |
gkroussos | 0:e8fdba0ed044 | 82 | * @returns |
gkroussos | 0:e8fdba0ed044 | 83 | * A DirHandle representing the directory stream, or |
gkroussos | 0:e8fdba0ed044 | 84 | * NULL on failure. |
gkroussos | 0:e8fdba0ed044 | 85 | */ |
gkroussos | 0:e8fdba0ed044 | 86 | virtual DirHandle *opendir(const char *name) { return NULL; }; |
gkroussos | 0:e8fdba0ed044 | 87 | |
gkroussos | 0:e8fdba0ed044 | 88 | /** Creates a directory in the filesystem. |
gkroussos | 0:e8fdba0ed044 | 89 | * |
gkroussos | 0:e8fdba0ed044 | 90 | * @param name The name of the directory to create. |
gkroussos | 0:e8fdba0ed044 | 91 | * @param mode The permissions to create the directory with. |
gkroussos | 0:e8fdba0ed044 | 92 | * |
gkroussos | 0:e8fdba0ed044 | 93 | * @returns |
gkroussos | 0:e8fdba0ed044 | 94 | * 0 on success, |
gkroussos | 0:e8fdba0ed044 | 95 | * -1 on failure. |
gkroussos | 0:e8fdba0ed044 | 96 | */ |
gkroussos | 0:e8fdba0ed044 | 97 | virtual int mkdir(const char *name, mode_t mode) { return -1; } |
gkroussos | 0:e8fdba0ed044 | 98 | |
gkroussos | 0:e8fdba0ed044 | 99 | // TODO other filesystem functions (mkdir, rm, rn, ls etc) |
gkroussos | 0:e8fdba0ed044 | 100 | }; |
gkroussos | 0:e8fdba0ed044 | 101 | |
gkroussos | 0:e8fdba0ed044 | 102 | } // namespace mbed |
gkroussos | 0:e8fdba0ed044 | 103 | |
gkroussos | 0:e8fdba0ed044 | 104 | #endif |