mbed library sources. Supersedes mbed-src.

Dependents:   SPIne CH_Communicatuin_Test CH_Communicatuin_Test2 MCP_SPIne ... more

Fork of mbed-dev-f303 by Ben Katz

Committer:
AnnaBridge
Date:
Thu Jul 06 15:42:05 2017 +0100
Revision:
168:9672193075cf
Parent:
167:e84263d55307
This updates the lib to the mbed lib v 146

Who changed what in which revision?

UserRevisionLine numberNew 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 168:9672193075cf 22 #include "platform/NonCopyable.h"
AnnaBridge 167:e84263d55307 23
AnnaBridge 167:e84263d55307 24 namespace mbed {
AnnaBridge 167:e84263d55307 25 /** \addtogroup platform */
AnnaBridge 167:e84263d55307 26
AnnaBridge 167:e84263d55307 27
AnnaBridge 167:e84263d55307 28 /** Represents a directory stream. Objects of this type are returned
AnnaBridge 167:e84263d55307 29 * by an opendir function. The core functions are read and seek,
AnnaBridge 167:e84263d55307 30 * but only a subset needs to be provided.
AnnaBridge 167:e84263d55307 31 *
AnnaBridge 167:e84263d55307 32 * If a FileSystemLike class defines the opendir method, then the
AnnaBridge 167:e84263d55307 33 * directories of an object of that type can be accessed by
AnnaBridge 167:e84263d55307 34 * DIR *d = opendir("/example/directory") (or opendir("/example")
AnnaBridge 167:e84263d55307 35 * to open the root of the filesystem), and then using readdir(d) etc.
AnnaBridge 167:e84263d55307 36 *
AnnaBridge 167:e84263d55307 37 * The root directory is considered to contain all FileHandle and
AnnaBridge 167:e84263d55307 38 * FileSystem objects, so the DIR* returned by opendir("/") will
AnnaBridge 167:e84263d55307 39 * reflect this.
AnnaBridge 167:e84263d55307 40 *
AnnaBridge 167:e84263d55307 41 * @note to create a directory, @see Dir
AnnaBridge 167:e84263d55307 42 * @note Synchronization level: Set by subclass
AnnaBridge 167:e84263d55307 43 * @ingroup platform
AnnaBridge 167:e84263d55307 44 */
AnnaBridge 168:9672193075cf 45 class DirHandle : private NonCopyable<DirHandle> {
AnnaBridge 167:e84263d55307 46 public:
AnnaBridge 167:e84263d55307 47 virtual ~DirHandle() {}
AnnaBridge 167:e84263d55307 48
AnnaBridge 167:e84263d55307 49 /** Read the next directory entry
AnnaBridge 167:e84263d55307 50 *
AnnaBridge 167:e84263d55307 51 * @param ent The directory entry to fill out
AnnaBridge 167:e84263d55307 52 * @return 1 on reading a filename, 0 at end of directory, negative error on failure
AnnaBridge 167:e84263d55307 53 */
AnnaBridge 167:e84263d55307 54 virtual ssize_t read(struct dirent *ent) = 0;
AnnaBridge 167:e84263d55307 55
AnnaBridge 167:e84263d55307 56 /** Close a directory
AnnaBridge 167:e84263d55307 57 *
AnnaBridge 167:e84263d55307 58 * @return 0 on success, negative error code on failure
AnnaBridge 167:e84263d55307 59 */
AnnaBridge 167:e84263d55307 60 virtual int close() = 0;
AnnaBridge 167:e84263d55307 61
AnnaBridge 167:e84263d55307 62 /** Set the current position of the directory
AnnaBridge 167:e84263d55307 63 *
AnnaBridge 167:e84263d55307 64 * @param offset Offset of the location to seek to,
AnnaBridge 167:e84263d55307 65 * must be a value returned from tell
AnnaBridge 167:e84263d55307 66 */
AnnaBridge 167:e84263d55307 67 virtual void seek(off_t offset) = 0;
AnnaBridge 167:e84263d55307 68
AnnaBridge 167:e84263d55307 69 /** Get the current position of the directory
AnnaBridge 167:e84263d55307 70 *
AnnaBridge 167:e84263d55307 71 * @return Position of the directory that can be passed to rewind
AnnaBridge 167:e84263d55307 72 */
AnnaBridge 167:e84263d55307 73 virtual off_t tell() = 0;
AnnaBridge 167:e84263d55307 74
AnnaBridge 167:e84263d55307 75 /** Rewind the current position to the beginning of the directory
AnnaBridge 167:e84263d55307 76 */
AnnaBridge 167:e84263d55307 77 virtual void rewind() = 0;
AnnaBridge 167:e84263d55307 78
AnnaBridge 167:e84263d55307 79 /** Get the sizeof the directory
AnnaBridge 167:e84263d55307 80 *
AnnaBridge 167:e84263d55307 81 * @return Number of files in the directory
AnnaBridge 167:e84263d55307 82 */
AnnaBridge 167:e84263d55307 83 virtual size_t size()
AnnaBridge 167:e84263d55307 84 {
AnnaBridge 167:e84263d55307 85 off_t off = tell();
AnnaBridge 167:e84263d55307 86 size_t size = 0;
AnnaBridge 167:e84263d55307 87 struct dirent *ent = new struct dirent;
AnnaBridge 167:e84263d55307 88
AnnaBridge 167:e84263d55307 89 rewind();
AnnaBridge 167:e84263d55307 90 while (read(ent) > 0) {
AnnaBridge 167:e84263d55307 91 size += 1;
AnnaBridge 167:e84263d55307 92 }
AnnaBridge 167:e84263d55307 93 seek(off);
AnnaBridge 167:e84263d55307 94
AnnaBridge 167:e84263d55307 95 delete ent;
AnnaBridge 167:e84263d55307 96 return size;
AnnaBridge 167:e84263d55307 97 }
AnnaBridge 167:e84263d55307 98
AnnaBridge 167:e84263d55307 99 /** Closes the directory.
AnnaBridge 167:e84263d55307 100 *
AnnaBridge 167:e84263d55307 101 * @returns
AnnaBridge 167:e84263d55307 102 * 0 on success,
AnnaBridge 167:e84263d55307 103 * -1 on error.
AnnaBridge 167:e84263d55307 104 */
AnnaBridge 167:e84263d55307 105 MBED_DEPRECATED_SINCE("mbed-os-5.4", "Replaced by DirHandle::close")
AnnaBridge 167:e84263d55307 106 virtual int closedir() { return close(); };
AnnaBridge 167:e84263d55307 107
AnnaBridge 167:e84263d55307 108 /** Return the directory entry at the current position, and
AnnaBridge 167:e84263d55307 109 * advances the position to the next entry.
AnnaBridge 167:e84263d55307 110 *
AnnaBridge 167:e84263d55307 111 * @returns
AnnaBridge 167:e84263d55307 112 * A pointer to a dirent structure representing the
AnnaBridge 167:e84263d55307 113 * directory entry at the current position, or NULL on reaching
AnnaBridge 167:e84263d55307 114 * end of directory or error.
AnnaBridge 167:e84263d55307 115 */
AnnaBridge 167:e84263d55307 116 MBED_DEPRECATED_SINCE("mbed-os-5.4", "Replaced by DirHandle::read")
AnnaBridge 167:e84263d55307 117 virtual struct dirent *readdir()
AnnaBridge 167:e84263d55307 118 {
AnnaBridge 167:e84263d55307 119 static struct dirent ent;
AnnaBridge 167:e84263d55307 120 return (read(&ent) > 0) ? &ent : NULL;
AnnaBridge 167:e84263d55307 121 }
AnnaBridge 167:e84263d55307 122
AnnaBridge 167:e84263d55307 123 /** Resets the position to the beginning of the directory.
AnnaBridge 167:e84263d55307 124 */
AnnaBridge 167:e84263d55307 125 MBED_DEPRECATED_SINCE("mbed-os-5.4", "Replaced by DirHandle::rewind")
AnnaBridge 167:e84263d55307 126 virtual void rewinddir() { rewind(); }
AnnaBridge 167:e84263d55307 127
AnnaBridge 167:e84263d55307 128 /** Returns the current position of the DirHandle.
AnnaBridge 167:e84263d55307 129 *
AnnaBridge 167:e84263d55307 130 * @returns
AnnaBridge 167:e84263d55307 131 * the current position,
AnnaBridge 167:e84263d55307 132 * -1 on error.
AnnaBridge 167:e84263d55307 133 */
AnnaBridge 167:e84263d55307 134 MBED_DEPRECATED_SINCE("mbed-os-5.4", "Replaced by DirHandle::tell")
AnnaBridge 167:e84263d55307 135 virtual off_t telldir() { return tell(); }
AnnaBridge 167:e84263d55307 136
AnnaBridge 167:e84263d55307 137 /** Sets the position of the DirHandle.
AnnaBridge 167:e84263d55307 138 *
AnnaBridge 167:e84263d55307 139 * @param location The location to seek to. Must be a value returned by telldir.
AnnaBridge 167:e84263d55307 140 */
AnnaBridge 167:e84263d55307 141 MBED_DEPRECATED_SINCE("mbed-os-5.4", "Replaced by DirHandle::seek")
AnnaBridge 167:e84263d55307 142 virtual void seekdir(off_t location) { seek(location); }
AnnaBridge 167:e84263d55307 143 };
AnnaBridge 167:e84263d55307 144
AnnaBridge 167:e84263d55307 145
AnnaBridge 167:e84263d55307 146 } // namespace mbed
AnnaBridge 167:e84263d55307 147
AnnaBridge 167:e84263d55307 148 #endif /* MBED_DIRHANDLE_H */