Rahul Dahiya / Mbed OS STM32F7 Ethernet
Committer:
rahul_dahiya
Date:
Wed Jan 15 15:57:15 2020 +0530
Revision:
0:fb8047b156bb
STM32F7 LWIP

Who changed what in which revision?

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