CDY version that shares functionality with Counter
Dependencies: SDFileSystem_HelloWorld mbed FATFileSystem
mbed/drivers/DirHandle.h@3:c547dba5d39b, 2018-11-05 (annotated)
- Committer:
- Charles David Young
- Date:
- Mon Nov 05 09:52:17 2018 -0700
- Revision:
- 3:c547dba5d39b
- Parent:
- 0:aa13e1c335cd
debug
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Charles David Young |
0:aa13e1c335cd | 1 | /* mbed Microcontroller Library |
Charles David Young |
0:aa13e1c335cd | 2 | * Copyright (c) 2006-2013 ARM Limited |
Charles David Young |
0:aa13e1c335cd | 3 | * |
Charles David Young |
0:aa13e1c335cd | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Charles David Young |
0:aa13e1c335cd | 5 | * you may not use this file except in compliance with the License. |
Charles David Young |
0:aa13e1c335cd | 6 | * You may obtain a copy of the License at |
Charles David Young |
0:aa13e1c335cd | 7 | * |
Charles David Young |
0:aa13e1c335cd | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Charles David Young |
0:aa13e1c335cd | 9 | * |
Charles David Young |
0:aa13e1c335cd | 10 | * Unless required by applicable law or agreed to in writing, software |
Charles David Young |
0:aa13e1c335cd | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
Charles David Young |
0:aa13e1c335cd | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Charles David Young |
0:aa13e1c335cd | 13 | * See the License for the specific language governing permissions and |
Charles David Young |
0:aa13e1c335cd | 14 | * limitations under the License. |
Charles David Young |
0:aa13e1c335cd | 15 | */ |
Charles David Young |
0:aa13e1c335cd | 16 | #ifndef MBED_DIRHANDLE_H |
Charles David Young |
0:aa13e1c335cd | 17 | #define MBED_DIRHANDLE_H |
Charles David Young |
0:aa13e1c335cd | 18 | |
Charles David Young |
0:aa13e1c335cd | 19 | #if defined(__ARMCC_VERSION) || defined(__ICCARM__) |
Charles David Young |
0:aa13e1c335cd | 20 | # define NAME_MAX 255 |
Charles David Young |
0:aa13e1c335cd | 21 | typedef int mode_t; |
Charles David Young |
0:aa13e1c335cd | 22 | |
Charles David Young |
0:aa13e1c335cd | 23 | #else |
Charles David Young |
0:aa13e1c335cd | 24 | # include <sys/syslimits.h> |
Charles David Young |
0:aa13e1c335cd | 25 | #endif |
Charles David Young |
0:aa13e1c335cd | 26 | |
Charles David Young |
0:aa13e1c335cd | 27 | #include "FileHandle.h" |
Charles David Young |
0:aa13e1c335cd | 28 | |
Charles David Young |
0:aa13e1c335cd | 29 | struct dirent { |
Charles David Young |
0:aa13e1c335cd | 30 | char d_name[NAME_MAX+1]; |
Charles David Young |
0:aa13e1c335cd | 31 | }; |
Charles David Young |
0:aa13e1c335cd | 32 | |
Charles David Young |
0:aa13e1c335cd | 33 | namespace mbed { |
Charles David Young |
0:aa13e1c335cd | 34 | /** \addtogroup drivers */ |
Charles David Young |
0:aa13e1c335cd | 35 | /** @{*/ |
Charles David Young |
0:aa13e1c335cd | 36 | |
Charles David Young |
0:aa13e1c335cd | 37 | /** Represents a directory stream. Objects of this type are returned |
Charles David Young |
0:aa13e1c335cd | 38 | * by a FileSystemLike's opendir method. Implementations must define |
Charles David Young |
0:aa13e1c335cd | 39 | * at least closedir, readdir and rewinddir. |
Charles David Young |
0:aa13e1c335cd | 40 | * |
Charles David Young |
0:aa13e1c335cd | 41 | * If a FileSystemLike class defines the opendir method, then the |
Charles David Young |
0:aa13e1c335cd | 42 | * directories of an object of that type can be accessed by |
Charles David Young |
0:aa13e1c335cd | 43 | * DIR *d = opendir("/example/directory") (or opendir("/example") |
Charles David Young |
0:aa13e1c335cd | 44 | * to open the root of the filesystem), and then using readdir(d) etc. |
Charles David Young |
0:aa13e1c335cd | 45 | * |
Charles David Young |
0:aa13e1c335cd | 46 | * The root directory is considered to contain all FileLike and |
Charles David Young |
0:aa13e1c335cd | 47 | * FileSystemLike objects, so the DIR* returned by opendir("/") will |
Charles David Young |
0:aa13e1c335cd | 48 | * reflect this. |
Charles David Young |
0:aa13e1c335cd | 49 | * |
Charles David Young |
0:aa13e1c335cd | 50 | * @Note Synchronization level: Set by subclass |
Charles David Young |
0:aa13e1c335cd | 51 | */ |
Charles David Young |
0:aa13e1c335cd | 52 | class DirHandle { |
Charles David Young |
0:aa13e1c335cd | 53 | |
Charles David Young |
0:aa13e1c335cd | 54 | public: |
Charles David Young |
0:aa13e1c335cd | 55 | /** Closes the directory. |
Charles David Young |
0:aa13e1c335cd | 56 | * |
Charles David Young |
0:aa13e1c335cd | 57 | * @returns |
Charles David Young |
0:aa13e1c335cd | 58 | * 0 on success, |
Charles David Young |
0:aa13e1c335cd | 59 | * -1 on error. |
Charles David Young |
0:aa13e1c335cd | 60 | */ |
Charles David Young |
0:aa13e1c335cd | 61 | virtual int closedir()=0; |
Charles David Young |
0:aa13e1c335cd | 62 | |
Charles David Young |
0:aa13e1c335cd | 63 | /** Return the directory entry at the current position, and |
Charles David Young |
0:aa13e1c335cd | 64 | * advances the position to the next entry. |
Charles David Young |
0:aa13e1c335cd | 65 | * |
Charles David Young |
0:aa13e1c335cd | 66 | * @returns |
Charles David Young |
0:aa13e1c335cd | 67 | * A pointer to a dirent structure representing the |
Charles David Young |
0:aa13e1c335cd | 68 | * directory entry at the current position, or NULL on reaching |
Charles David Young |
0:aa13e1c335cd | 69 | * end of directory or error. |
Charles David Young |
0:aa13e1c335cd | 70 | */ |
Charles David Young |
0:aa13e1c335cd | 71 | virtual struct dirent *readdir()=0; |
Charles David Young |
0:aa13e1c335cd | 72 | |
Charles David Young |
0:aa13e1c335cd | 73 | /** Resets the position to the beginning of the directory. |
Charles David Young |
0:aa13e1c335cd | 74 | */ |
Charles David Young |
0:aa13e1c335cd | 75 | virtual void rewinddir()=0; |
Charles David Young |
0:aa13e1c335cd | 76 | |
Charles David Young |
0:aa13e1c335cd | 77 | /** Returns the current position of the DirHandle. |
Charles David Young |
0:aa13e1c335cd | 78 | * |
Charles David Young |
0:aa13e1c335cd | 79 | * @returns |
Charles David Young |
0:aa13e1c335cd | 80 | * the current position, |
Charles David Young |
0:aa13e1c335cd | 81 | * -1 on error. |
Charles David Young |
0:aa13e1c335cd | 82 | */ |
Charles David Young |
0:aa13e1c335cd | 83 | virtual off_t telldir() { return -1; } |
Charles David Young |
0:aa13e1c335cd | 84 | |
Charles David Young |
0:aa13e1c335cd | 85 | /** Sets the position of the DirHandle. |
Charles David Young |
0:aa13e1c335cd | 86 | * |
Charles David Young |
0:aa13e1c335cd | 87 | * @param location The location to seek to. Must be a value returned by telldir. |
Charles David Young |
0:aa13e1c335cd | 88 | */ |
Charles David Young |
0:aa13e1c335cd | 89 | virtual void seekdir(off_t location) { (void)location;} |
Charles David Young |
0:aa13e1c335cd | 90 | |
Charles David Young |
0:aa13e1c335cd | 91 | virtual ~DirHandle() {} |
Charles David Young |
0:aa13e1c335cd | 92 | |
Charles David Young |
0:aa13e1c335cd | 93 | protected: |
Charles David Young |
0:aa13e1c335cd | 94 | |
Charles David Young |
0:aa13e1c335cd | 95 | /** Acquire exclusive access to this object. |
Charles David Young |
0:aa13e1c335cd | 96 | */ |
Charles David Young |
0:aa13e1c335cd | 97 | virtual void lock() { |
Charles David Young |
0:aa13e1c335cd | 98 | // Stub |
Charles David Young |
0:aa13e1c335cd | 99 | } |
Charles David Young |
0:aa13e1c335cd | 100 | |
Charles David Young |
0:aa13e1c335cd | 101 | /** Release exclusive access to this object. |
Charles David Young |
0:aa13e1c335cd | 102 | */ |
Charles David Young |
0:aa13e1c335cd | 103 | virtual void unlock() { |
Charles David Young |
0:aa13e1c335cd | 104 | // Stub |
Charles David Young |
0:aa13e1c335cd | 105 | } |
Charles David Young |
0:aa13e1c335cd | 106 | }; |
Charles David Young |
0:aa13e1c335cd | 107 | |
Charles David Young |
0:aa13e1c335cd | 108 | } // namespace mbed |
Charles David Young |
0:aa13e1c335cd | 109 | |
Charles David Young |
0:aa13e1c335cd | 110 | typedef mbed::DirHandle DIR; |
Charles David Young |
0:aa13e1c335cd | 111 | |
Charles David Young |
0:aa13e1c335cd | 112 | extern "C" { |
Charles David Young |
0:aa13e1c335cd | 113 | DIR *opendir(const char*); |
Charles David Young |
0:aa13e1c335cd | 114 | struct dirent *readdir(DIR *); |
Charles David Young |
0:aa13e1c335cd | 115 | int closedir(DIR*); |
Charles David Young |
0:aa13e1c335cd | 116 | void rewinddir(DIR*); |
Charles David Young |
0:aa13e1c335cd | 117 | long telldir(DIR*); |
Charles David Young |
0:aa13e1c335cd | 118 | void seekdir(DIR*, long); |
Charles David Young |
0:aa13e1c335cd | 119 | int mkdir(const char *name, mode_t n); |
Charles David Young |
0:aa13e1c335cd | 120 | }; |
Charles David Young |
0:aa13e1c335cd | 121 | |
Charles David Young |
0:aa13e1c335cd | 122 | #endif /* MBED_DIRHANDLE_H */ |
Charles David Young |
0:aa13e1c335cd | 123 | |
Charles David Young |
0:aa13e1c335cd | 124 | /** @}*/ |