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