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