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