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