mbed library sources, mbed-dev only for TYBLE16
Fork of mbed-dev by
Please refer flowing link.
/users/kenjiArai/notebook/tyble16-module-will-become-a-mbed-family--mbedliza/
platform/DirHandle.h@167:e84263d55307, 2017-06-21 (annotated)
- Committer:
- AnnaBridge
- Date:
- Wed Jun 21 17:46:44 2017 +0100
- Revision:
- 167:e84263d55307
- Child:
- 168:9672193075cf
This updates the lib to the mbed lib v 145
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AnnaBridge | 167:e84263d55307 | 1 | /* mbed Microcontroller Library |
AnnaBridge | 167:e84263d55307 | 2 | * Copyright (c) 2006-2013 ARM Limited |
AnnaBridge | 167:e84263d55307 | 3 | * |
AnnaBridge | 167:e84263d55307 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
AnnaBridge | 167:e84263d55307 | 5 | * you may not use this file except in compliance with the License. |
AnnaBridge | 167:e84263d55307 | 6 | * You may obtain a copy of the License at |
AnnaBridge | 167:e84263d55307 | 7 | * |
AnnaBridge | 167:e84263d55307 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
AnnaBridge | 167:e84263d55307 | 9 | * |
AnnaBridge | 167:e84263d55307 | 10 | * Unless required by applicable law or agreed to in writing, software |
AnnaBridge | 167:e84263d55307 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
AnnaBridge | 167:e84263d55307 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
AnnaBridge | 167:e84263d55307 | 13 | * See the License for the specific language governing permissions and |
AnnaBridge | 167:e84263d55307 | 14 | * limitations under the License. |
AnnaBridge | 167:e84263d55307 | 15 | */ |
AnnaBridge | 167:e84263d55307 | 16 | #ifndef MBED_DIRHANDLE_H |
AnnaBridge | 167:e84263d55307 | 17 | #define MBED_DIRHANDLE_H |
AnnaBridge | 167:e84263d55307 | 18 | |
AnnaBridge | 167:e84263d55307 | 19 | #include <stdint.h> |
AnnaBridge | 167:e84263d55307 | 20 | #include "platform/platform.h" |
AnnaBridge | 167:e84263d55307 | 21 | #include "platform/FileHandle.h" |
AnnaBridge | 167:e84263d55307 | 22 | |
AnnaBridge | 167:e84263d55307 | 23 | namespace mbed { |
AnnaBridge | 167:e84263d55307 | 24 | /** \addtogroup platform */ |
AnnaBridge | 167:e84263d55307 | 25 | |
AnnaBridge | 167:e84263d55307 | 26 | |
AnnaBridge | 167:e84263d55307 | 27 | /** Represents a directory stream. Objects of this type are returned |
AnnaBridge | 167:e84263d55307 | 28 | * by an opendir function. The core functions are read and seek, |
AnnaBridge | 167:e84263d55307 | 29 | * but only a subset needs to be provided. |
AnnaBridge | 167:e84263d55307 | 30 | * |
AnnaBridge | 167:e84263d55307 | 31 | * If a FileSystemLike class defines the opendir method, then the |
AnnaBridge | 167:e84263d55307 | 32 | * directories of an object of that type can be accessed by |
AnnaBridge | 167:e84263d55307 | 33 | * DIR *d = opendir("/example/directory") (or opendir("/example") |
AnnaBridge | 167:e84263d55307 | 34 | * to open the root of the filesystem), and then using readdir(d) etc. |
AnnaBridge | 167:e84263d55307 | 35 | * |
AnnaBridge | 167:e84263d55307 | 36 | * The root directory is considered to contain all FileHandle and |
AnnaBridge | 167:e84263d55307 | 37 | * FileSystem objects, so the DIR* returned by opendir("/") will |
AnnaBridge | 167:e84263d55307 | 38 | * reflect this. |
AnnaBridge | 167:e84263d55307 | 39 | * |
AnnaBridge | 167:e84263d55307 | 40 | * @note to create a directory, @see Dir |
AnnaBridge | 167:e84263d55307 | 41 | * @note Synchronization level: Set by subclass |
AnnaBridge | 167:e84263d55307 | 42 | * @ingroup platform |
AnnaBridge | 167:e84263d55307 | 43 | */ |
AnnaBridge | 167:e84263d55307 | 44 | class DirHandle { |
AnnaBridge | 167:e84263d55307 | 45 | public: |
AnnaBridge | 167:e84263d55307 | 46 | virtual ~DirHandle() {} |
AnnaBridge | 167:e84263d55307 | 47 | |
AnnaBridge | 167:e84263d55307 | 48 | /** Read the next directory entry |
AnnaBridge | 167:e84263d55307 | 49 | * |
AnnaBridge | 167:e84263d55307 | 50 | * @param ent The directory entry to fill out |
AnnaBridge | 167:e84263d55307 | 51 | * @return 1 on reading a filename, 0 at end of directory, negative error on failure |
AnnaBridge | 167:e84263d55307 | 52 | */ |
AnnaBridge | 167:e84263d55307 | 53 | virtual ssize_t read(struct dirent *ent) = 0; |
AnnaBridge | 167:e84263d55307 | 54 | |
AnnaBridge | 167:e84263d55307 | 55 | /** Close a directory |
AnnaBridge | 167:e84263d55307 | 56 | * |
AnnaBridge | 167:e84263d55307 | 57 | * @return 0 on success, negative error code on failure |
AnnaBridge | 167:e84263d55307 | 58 | */ |
AnnaBridge | 167:e84263d55307 | 59 | virtual int close() = 0; |
AnnaBridge | 167:e84263d55307 | 60 | |
AnnaBridge | 167:e84263d55307 | 61 | /** Set the current position of the directory |
AnnaBridge | 167:e84263d55307 | 62 | * |
AnnaBridge | 167:e84263d55307 | 63 | * @param offset Offset of the location to seek to, |
AnnaBridge | 167:e84263d55307 | 64 | * must be a value returned from tell |
AnnaBridge | 167:e84263d55307 | 65 | */ |
AnnaBridge | 167:e84263d55307 | 66 | virtual void seek(off_t offset) = 0; |
AnnaBridge | 167:e84263d55307 | 67 | |
AnnaBridge | 167:e84263d55307 | 68 | /** Get the current position of the directory |
AnnaBridge | 167:e84263d55307 | 69 | * |
AnnaBridge | 167:e84263d55307 | 70 | * @return Position of the directory that can be passed to rewind |
AnnaBridge | 167:e84263d55307 | 71 | */ |
AnnaBridge | 167:e84263d55307 | 72 | virtual off_t tell() = 0; |
AnnaBridge | 167:e84263d55307 | 73 | |
AnnaBridge | 167:e84263d55307 | 74 | /** Rewind the current position to the beginning of the directory |
AnnaBridge | 167:e84263d55307 | 75 | */ |
AnnaBridge | 167:e84263d55307 | 76 | virtual void rewind() = 0; |
AnnaBridge | 167:e84263d55307 | 77 | |
AnnaBridge | 167:e84263d55307 | 78 | /** Get the sizeof the directory |
AnnaBridge | 167:e84263d55307 | 79 | * |
AnnaBridge | 167:e84263d55307 | 80 | * @return Number of files in the directory |
AnnaBridge | 167:e84263d55307 | 81 | */ |
AnnaBridge | 167:e84263d55307 | 82 | virtual size_t size() |
AnnaBridge | 167:e84263d55307 | 83 | { |
AnnaBridge | 167:e84263d55307 | 84 | off_t off = tell(); |
AnnaBridge | 167:e84263d55307 | 85 | size_t size = 0; |
AnnaBridge | 167:e84263d55307 | 86 | struct dirent *ent = new struct dirent; |
AnnaBridge | 167:e84263d55307 | 87 | |
AnnaBridge | 167:e84263d55307 | 88 | rewind(); |
AnnaBridge | 167:e84263d55307 | 89 | while (read(ent) > 0) { |
AnnaBridge | 167:e84263d55307 | 90 | size += 1; |
AnnaBridge | 167:e84263d55307 | 91 | } |
AnnaBridge | 167:e84263d55307 | 92 | seek(off); |
AnnaBridge | 167:e84263d55307 | 93 | |
AnnaBridge | 167:e84263d55307 | 94 | delete ent; |
AnnaBridge | 167:e84263d55307 | 95 | return size; |
AnnaBridge | 167:e84263d55307 | 96 | } |
AnnaBridge | 167:e84263d55307 | 97 | |
AnnaBridge | 167:e84263d55307 | 98 | /** Closes the directory. |
AnnaBridge | 167:e84263d55307 | 99 | * |
AnnaBridge | 167:e84263d55307 | 100 | * @returns |
AnnaBridge | 167:e84263d55307 | 101 | * 0 on success, |
AnnaBridge | 167:e84263d55307 | 102 | * -1 on error. |
AnnaBridge | 167:e84263d55307 | 103 | */ |
AnnaBridge | 167:e84263d55307 | 104 | MBED_DEPRECATED_SINCE("mbed-os-5.4", "Replaced by DirHandle::close") |
AnnaBridge | 167:e84263d55307 | 105 | virtual int closedir() { return close(); }; |
AnnaBridge | 167:e84263d55307 | 106 | |
AnnaBridge | 167:e84263d55307 | 107 | /** Return the directory entry at the current position, and |
AnnaBridge | 167:e84263d55307 | 108 | * advances the position to the next entry. |
AnnaBridge | 167:e84263d55307 | 109 | * |
AnnaBridge | 167:e84263d55307 | 110 | * @returns |
AnnaBridge | 167:e84263d55307 | 111 | * A pointer to a dirent structure representing the |
AnnaBridge | 167:e84263d55307 | 112 | * directory entry at the current position, or NULL on reaching |
AnnaBridge | 167:e84263d55307 | 113 | * end of directory or error. |
AnnaBridge | 167:e84263d55307 | 114 | */ |
AnnaBridge | 167:e84263d55307 | 115 | MBED_DEPRECATED_SINCE("mbed-os-5.4", "Replaced by DirHandle::read") |
AnnaBridge | 167:e84263d55307 | 116 | virtual struct dirent *readdir() |
AnnaBridge | 167:e84263d55307 | 117 | { |
AnnaBridge | 167:e84263d55307 | 118 | static struct dirent ent; |
AnnaBridge | 167:e84263d55307 | 119 | return (read(&ent) > 0) ? &ent : NULL; |
AnnaBridge | 167:e84263d55307 | 120 | } |
AnnaBridge | 167:e84263d55307 | 121 | |
AnnaBridge | 167:e84263d55307 | 122 | /** Resets the position to the beginning of the directory. |
AnnaBridge | 167:e84263d55307 | 123 | */ |
AnnaBridge | 167:e84263d55307 | 124 | MBED_DEPRECATED_SINCE("mbed-os-5.4", "Replaced by DirHandle::rewind") |
AnnaBridge | 167:e84263d55307 | 125 | virtual void rewinddir() { rewind(); } |
AnnaBridge | 167:e84263d55307 | 126 | |
AnnaBridge | 167:e84263d55307 | 127 | /** Returns the current position of the DirHandle. |
AnnaBridge | 167:e84263d55307 | 128 | * |
AnnaBridge | 167:e84263d55307 | 129 | * @returns |
AnnaBridge | 167:e84263d55307 | 130 | * the current position, |
AnnaBridge | 167:e84263d55307 | 131 | * -1 on error. |
AnnaBridge | 167:e84263d55307 | 132 | */ |
AnnaBridge | 167:e84263d55307 | 133 | MBED_DEPRECATED_SINCE("mbed-os-5.4", "Replaced by DirHandle::tell") |
AnnaBridge | 167:e84263d55307 | 134 | virtual off_t telldir() { return tell(); } |
AnnaBridge | 167:e84263d55307 | 135 | |
AnnaBridge | 167:e84263d55307 | 136 | /** Sets the position of the DirHandle. |
AnnaBridge | 167:e84263d55307 | 137 | * |
AnnaBridge | 167:e84263d55307 | 138 | * @param location The location to seek to. Must be a value returned by telldir. |
AnnaBridge | 167:e84263d55307 | 139 | */ |
AnnaBridge | 167:e84263d55307 | 140 | MBED_DEPRECATED_SINCE("mbed-os-5.4", "Replaced by DirHandle::seek") |
AnnaBridge | 167:e84263d55307 | 141 | virtual void seekdir(off_t location) { seek(location); } |
AnnaBridge | 167:e84263d55307 | 142 | }; |
AnnaBridge | 167:e84263d55307 | 143 | |
AnnaBridge | 167:e84263d55307 | 144 | |
AnnaBridge | 167:e84263d55307 | 145 | } // namespace mbed |
AnnaBridge | 167:e84263d55307 | 146 | |
AnnaBridge | 167:e84263d55307 | 147 | #endif /* MBED_DIRHANDLE_H */ |