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