SPKT

Dependencies:   F746_GUI SD_PlayerSkeleton F746_SAI_IO

Committer:
phungductung
Date:
Tue Jun 04 09:08:29 2019 +0000
Revision:
0:aa3fc5ad02f7
SPKT

Who changed what in which revision?

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