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