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