This is my quadcopter prototype software, still in development!
quadv3/mbed/DirHandle.h@1:ac68f0368a77, 2013-07-23 (annotated)
- Committer:
- Anaesthetix
- Date:
- Tue Jul 23 14:01:42 2013 +0000
- Revision:
- 1:ac68f0368a77
- Parent:
- 0:978110f7f027
Other accelerometer added
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Anaesthetix | 0:978110f7f027 | 1 | /* mbed Microcontroller Library - DirHandler |
Anaesthetix | 0:978110f7f027 | 2 | * Copyright (c) 2008-2009 ARM Limited. All rights reserved. |
Anaesthetix | 0:978110f7f027 | 3 | */ |
Anaesthetix | 0:978110f7f027 | 4 | |
Anaesthetix | 0:978110f7f027 | 5 | #ifndef MBED_DIRHANDLE_H |
Anaesthetix | 0:978110f7f027 | 6 | #define MBED_DIRHANDLE_H |
Anaesthetix | 0:978110f7f027 | 7 | |
Anaesthetix | 0:978110f7f027 | 8 | #ifdef __ARMCC_VERSION |
Anaesthetix | 0:978110f7f027 | 9 | # define NAME_MAX 255 |
Anaesthetix | 0:978110f7f027 | 10 | typedef int mode_t; |
Anaesthetix | 0:978110f7f027 | 11 | #else |
Anaesthetix | 0:978110f7f027 | 12 | # include <sys/syslimits.h> |
Anaesthetix | 0:978110f7f027 | 13 | #endif |
Anaesthetix | 0:978110f7f027 | 14 | #include "FileHandle.h" |
Anaesthetix | 0:978110f7f027 | 15 | |
Anaesthetix | 0:978110f7f027 | 16 | struct dirent { |
Anaesthetix | 0:978110f7f027 | 17 | char d_name[NAME_MAX+1]; |
Anaesthetix | 0:978110f7f027 | 18 | }; |
Anaesthetix | 0:978110f7f027 | 19 | |
Anaesthetix | 0:978110f7f027 | 20 | namespace mbed { |
Anaesthetix | 0:978110f7f027 | 21 | |
Anaesthetix | 0:978110f7f027 | 22 | /* Class DirHandle |
Anaesthetix | 0:978110f7f027 | 23 | * Represents a directory stream. Objects of this type are returned |
Anaesthetix | 0:978110f7f027 | 24 | * by a FileSystemLike's opendir method. Implementations must define |
Anaesthetix | 0:978110f7f027 | 25 | * at least closedir, readdir and rewinddir. |
Anaesthetix | 0:978110f7f027 | 26 | * |
Anaesthetix | 0:978110f7f027 | 27 | * If a FileSystemLike class defines the opendir method, then the |
Anaesthetix | 0:978110f7f027 | 28 | * directories of an object of that type can be accessed by |
Anaesthetix | 0:978110f7f027 | 29 | * DIR *d = opendir("/example/directory") (or opendir("/example") |
Anaesthetix | 0:978110f7f027 | 30 | * to open the root of the filesystem), and then using readdir(d) etc. |
Anaesthetix | 0:978110f7f027 | 31 | * |
Anaesthetix | 0:978110f7f027 | 32 | * The root directory is considered to contain all FileLike and |
Anaesthetix | 0:978110f7f027 | 33 | * FileSystemLike objects, so the DIR* returned by opendir("/") will |
Anaesthetix | 0:978110f7f027 | 34 | * reflect this. |
Anaesthetix | 0:978110f7f027 | 35 | */ |
Anaesthetix | 0:978110f7f027 | 36 | class DirHandle { |
Anaesthetix | 0:978110f7f027 | 37 | |
Anaesthetix | 0:978110f7f027 | 38 | public: |
Anaesthetix | 0:978110f7f027 | 39 | /* Function closedir |
Anaesthetix | 0:978110f7f027 | 40 | * Closes the directory. |
Anaesthetix | 0:978110f7f027 | 41 | * |
Anaesthetix | 0:978110f7f027 | 42 | * Variables |
Anaesthetix | 0:978110f7f027 | 43 | * returns - 0 on success, or -1 on error. |
Anaesthetix | 0:978110f7f027 | 44 | */ |
Anaesthetix | 0:978110f7f027 | 45 | virtual int closedir()=0; |
Anaesthetix | 0:978110f7f027 | 46 | |
Anaesthetix | 0:978110f7f027 | 47 | /* Function readdir |
Anaesthetix | 0:978110f7f027 | 48 | * Return the directory entry at the current position, and |
Anaesthetix | 0:978110f7f027 | 49 | * advances the position to the next entry. |
Anaesthetix | 0:978110f7f027 | 50 | * |
Anaesthetix | 0:978110f7f027 | 51 | * Returns |
Anaesthetix | 0:978110f7f027 | 52 | * A pointer to a dirent structure representing the |
Anaesthetix | 0:978110f7f027 | 53 | * directory entry at the current position, or NULL on reaching |
Anaesthetix | 0:978110f7f027 | 54 | * end of directory or error. |
Anaesthetix | 0:978110f7f027 | 55 | */ |
Anaesthetix | 0:978110f7f027 | 56 | virtual struct dirent *readdir()=0; |
Anaesthetix | 0:978110f7f027 | 57 | |
Anaesthetix | 0:978110f7f027 | 58 | /* Function rewinddir |
Anaesthetix | 0:978110f7f027 | 59 | * Resets the position to the beginning of the directory. |
Anaesthetix | 0:978110f7f027 | 60 | */ |
Anaesthetix | 0:978110f7f027 | 61 | virtual void rewinddir()=0; |
Anaesthetix | 0:978110f7f027 | 62 | |
Anaesthetix | 0:978110f7f027 | 63 | /* Function telldir |
Anaesthetix | 0:978110f7f027 | 64 | * Returns the current position of the DirHandle. |
Anaesthetix | 0:978110f7f027 | 65 | * |
Anaesthetix | 0:978110f7f027 | 66 | * Returns |
Anaesthetix | 0:978110f7f027 | 67 | * The current position, or -1 on error. |
Anaesthetix | 0:978110f7f027 | 68 | */ |
Anaesthetix | 0:978110f7f027 | 69 | virtual off_t telldir() { return -1; } |
Anaesthetix | 0:978110f7f027 | 70 | |
Anaesthetix | 0:978110f7f027 | 71 | /* Function seekdir |
Anaesthetix | 0:978110f7f027 | 72 | * Sets the position of the DirHandle. |
Anaesthetix | 0:978110f7f027 | 73 | * |
Anaesthetix | 0:978110f7f027 | 74 | * Variables |
Anaesthetix | 0:978110f7f027 | 75 | * location - The location to seek to. Must be a value returned |
Anaesthetix | 0:978110f7f027 | 76 | * by telldir. |
Anaesthetix | 0:978110f7f027 | 77 | */ |
Anaesthetix | 0:978110f7f027 | 78 | virtual void seekdir(off_t location) { } |
Anaesthetix | 0:978110f7f027 | 79 | |
Anaesthetix | 0:978110f7f027 | 80 | }; |
Anaesthetix | 0:978110f7f027 | 81 | |
Anaesthetix | 0:978110f7f027 | 82 | } // namespace mbed |
Anaesthetix | 0:978110f7f027 | 83 | |
Anaesthetix | 0:978110f7f027 | 84 | typedef mbed::DirHandle DIR; |
Anaesthetix | 0:978110f7f027 | 85 | |
Anaesthetix | 0:978110f7f027 | 86 | extern "C" { |
Anaesthetix | 0:978110f7f027 | 87 | DIR *opendir(const char*); |
Anaesthetix | 0:978110f7f027 | 88 | struct dirent *readdir(DIR *); |
Anaesthetix | 0:978110f7f027 | 89 | int closedir(DIR*); |
Anaesthetix | 0:978110f7f027 | 90 | void rewinddir(DIR*); |
Anaesthetix | 0:978110f7f027 | 91 | long telldir(DIR*); |
Anaesthetix | 0:978110f7f027 | 92 | void seekdir(DIR*, long); |
Anaesthetix | 0:978110f7f027 | 93 | int mkdir(const char *name, mode_t n); |
Anaesthetix | 0:978110f7f027 | 94 | }; |
Anaesthetix | 0:978110f7f027 | 95 | |
Anaesthetix | 0:978110f7f027 | 96 | #endif /* MBED_DIRHANDLE_H */ |