The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
Kojto
Date:
Wed Jul 19 16:46:19 2017 +0100
Revision:
147:a97add6d7e64
Parent:
146:22da6e220af6
Release 147 of the mbed library.

Who changed what in which revision?

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