,,

Fork of Application by Daniel Sygut

Committer:
Zaitsev
Date:
Tue Jan 10 20:42:26 2017 +0000
Revision:
10:41552d038a69
USB Serial bi-directional bridge

Who changed what in which revision?

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