Initial commit

Dependencies:   FastPWM

Committer:
lypinator
Date:
Wed Sep 16 01:11:49 2020 +0000
Revision:
0:bb348c97df44
Added PWM

Who changed what in which revision?

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