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