BBR 1 Ebene

Committer:
borlanic
Date:
Mon May 14 11:29:06 2018 +0000
Revision:
0:fbdae7e6d805
BBR

Who changed what in which revision?

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