Knight KE
/
Game_Master
游戏王对战板,目前code还是空的
mbed-os/platform/LocalFileSystem.h@0:9b3d4731edbb, 2018-06-21 (annotated)
- Committer:
- WFKnight
- Date:
- Thu Jun 21 13:51:43 2018 +0000
- Revision:
- 0:9b3d4731edbb
UART, RTOS, LED
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
WFKnight | 0:9b3d4731edbb | 1 | /* mbed Microcontroller Library |
WFKnight | 0:9b3d4731edbb | 2 | * Copyright (c) 2006-2013 ARM Limited |
WFKnight | 0:9b3d4731edbb | 3 | * |
WFKnight | 0:9b3d4731edbb | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
WFKnight | 0:9b3d4731edbb | 5 | * you may not use this file except in compliance with the License. |
WFKnight | 0:9b3d4731edbb | 6 | * You may obtain a copy of the License at |
WFKnight | 0:9b3d4731edbb | 7 | * |
WFKnight | 0:9b3d4731edbb | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
WFKnight | 0:9b3d4731edbb | 9 | * |
WFKnight | 0:9b3d4731edbb | 10 | * Unless required by applicable law or agreed to in writing, software |
WFKnight | 0:9b3d4731edbb | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
WFKnight | 0:9b3d4731edbb | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
WFKnight | 0:9b3d4731edbb | 13 | * See the License for the specific language governing permissions and |
WFKnight | 0:9b3d4731edbb | 14 | * limitations under the License. |
WFKnight | 0:9b3d4731edbb | 15 | */ |
WFKnight | 0:9b3d4731edbb | 16 | #ifndef MBED_LOCALFILESYSTEM_H |
WFKnight | 0:9b3d4731edbb | 17 | #define MBED_LOCALFILESYSTEM_H |
WFKnight | 0:9b3d4731edbb | 18 | |
WFKnight | 0:9b3d4731edbb | 19 | #include "platform/platform.h" |
WFKnight | 0:9b3d4731edbb | 20 | |
WFKnight | 0:9b3d4731edbb | 21 | #if DEVICE_LOCALFILESYSTEM |
WFKnight | 0:9b3d4731edbb | 22 | |
WFKnight | 0:9b3d4731edbb | 23 | #include "platform/FileSystemLike.h" |
WFKnight | 0:9b3d4731edbb | 24 | #include "platform/PlatformMutex.h" |
WFKnight | 0:9b3d4731edbb | 25 | #include "platform/NonCopyable.h" |
WFKnight | 0:9b3d4731edbb | 26 | |
WFKnight | 0:9b3d4731edbb | 27 | namespace mbed { |
WFKnight | 0:9b3d4731edbb | 28 | /** \addtogroup platform */ |
WFKnight | 0:9b3d4731edbb | 29 | /** @{*/ |
WFKnight | 0:9b3d4731edbb | 30 | /** |
WFKnight | 0:9b3d4731edbb | 31 | * \defgroup platform_LocalFileSystem LocalFileSystem functions |
WFKnight | 0:9b3d4731edbb | 32 | * @{ |
WFKnight | 0:9b3d4731edbb | 33 | */ |
WFKnight | 0:9b3d4731edbb | 34 | |
WFKnight | 0:9b3d4731edbb | 35 | FILEHANDLE local_file_open(const char* name, int flags); |
WFKnight | 0:9b3d4731edbb | 36 | |
WFKnight | 0:9b3d4731edbb | 37 | /** |
WFKnight | 0:9b3d4731edbb | 38 | * @class LocalFileHandle |
WFKnight | 0:9b3d4731edbb | 39 | * @ingroup platform |
WFKnight | 0:9b3d4731edbb | 40 | */ |
WFKnight | 0:9b3d4731edbb | 41 | class LocalFileHandle : public FileHandle, private NonCopyable<LocalFileHandle> { |
WFKnight | 0:9b3d4731edbb | 42 | |
WFKnight | 0:9b3d4731edbb | 43 | public: |
WFKnight | 0:9b3d4731edbb | 44 | LocalFileHandle(FILEHANDLE fh); |
WFKnight | 0:9b3d4731edbb | 45 | |
WFKnight | 0:9b3d4731edbb | 46 | virtual int close(); |
WFKnight | 0:9b3d4731edbb | 47 | |
WFKnight | 0:9b3d4731edbb | 48 | virtual ssize_t write(const void *buffer, size_t length); |
WFKnight | 0:9b3d4731edbb | 49 | |
WFKnight | 0:9b3d4731edbb | 50 | virtual ssize_t read(void *buffer, size_t length); |
WFKnight | 0:9b3d4731edbb | 51 | |
WFKnight | 0:9b3d4731edbb | 52 | virtual int isatty(); |
WFKnight | 0:9b3d4731edbb | 53 | |
WFKnight | 0:9b3d4731edbb | 54 | virtual off_t seek(off_t position, int whence); |
WFKnight | 0:9b3d4731edbb | 55 | |
WFKnight | 0:9b3d4731edbb | 56 | virtual int sync(); |
WFKnight | 0:9b3d4731edbb | 57 | |
WFKnight | 0:9b3d4731edbb | 58 | virtual off_t size(); |
WFKnight | 0:9b3d4731edbb | 59 | |
WFKnight | 0:9b3d4731edbb | 60 | protected: |
WFKnight | 0:9b3d4731edbb | 61 | virtual void lock(); |
WFKnight | 0:9b3d4731edbb | 62 | virtual void unlock(); |
WFKnight | 0:9b3d4731edbb | 63 | FILEHANDLE _fh; |
WFKnight | 0:9b3d4731edbb | 64 | int pos; |
WFKnight | 0:9b3d4731edbb | 65 | PlatformMutex _mutex; |
WFKnight | 0:9b3d4731edbb | 66 | }; |
WFKnight | 0:9b3d4731edbb | 67 | |
WFKnight | 0:9b3d4731edbb | 68 | /** A filesystem for accessing the local mbed Microcontroller USB disk drive |
WFKnight | 0:9b3d4731edbb | 69 | * |
WFKnight | 0:9b3d4731edbb | 70 | * This allows programs to read and write files on the same disk drive that is used to program the |
WFKnight | 0:9b3d4731edbb | 71 | * mbed Microcontroller. Once created, the standard C file access functions are used to open, |
WFKnight | 0:9b3d4731edbb | 72 | * read and write files. |
WFKnight | 0:9b3d4731edbb | 73 | * |
WFKnight | 0:9b3d4731edbb | 74 | * @note Synchronization level: Thread safe |
WFKnight | 0:9b3d4731edbb | 75 | * |
WFKnight | 0:9b3d4731edbb | 76 | * Example: |
WFKnight | 0:9b3d4731edbb | 77 | * @code |
WFKnight | 0:9b3d4731edbb | 78 | * #include "mbed.h" |
WFKnight | 0:9b3d4731edbb | 79 | * |
WFKnight | 0:9b3d4731edbb | 80 | * LocalFileSystem local("local"); // Create the local filesystem under the name "local" |
WFKnight | 0:9b3d4731edbb | 81 | * |
WFKnight | 0:9b3d4731edbb | 82 | * int main() { |
WFKnight | 0:9b3d4731edbb | 83 | * FILE *fp = fopen("/local/out.txt", "w"); // Open "out.txt" on the local file system for writing |
WFKnight | 0:9b3d4731edbb | 84 | * fprintf(fp, "Hello World!"); |
WFKnight | 0:9b3d4731edbb | 85 | * fclose(fp); |
WFKnight | 0:9b3d4731edbb | 86 | * remove("/local/out.txt"); // Removes the file "out.txt" from the local file system |
WFKnight | 0:9b3d4731edbb | 87 | * |
WFKnight | 0:9b3d4731edbb | 88 | * DIR *d = opendir("/local"); // Opens the root directory of the local file system |
WFKnight | 0:9b3d4731edbb | 89 | * struct dirent *p; |
WFKnight | 0:9b3d4731edbb | 90 | * while((p = readdir(d)) != NULL) { // Print the names of the files in the local file system |
WFKnight | 0:9b3d4731edbb | 91 | * printf("%s\n", p->d_name); // to stdout. |
WFKnight | 0:9b3d4731edbb | 92 | * } |
WFKnight | 0:9b3d4731edbb | 93 | * closedir(d); |
WFKnight | 0:9b3d4731edbb | 94 | * } |
WFKnight | 0:9b3d4731edbb | 95 | * @endcode |
WFKnight | 0:9b3d4731edbb | 96 | * |
WFKnight | 0:9b3d4731edbb | 97 | * @note |
WFKnight | 0:9b3d4731edbb | 98 | * If the microcontroller program makes an access to the local drive, it will be marked as "removed" |
WFKnight | 0:9b3d4731edbb | 99 | * on the Host computer. This means it is no longer accessible from the Host Computer. |
WFKnight | 0:9b3d4731edbb | 100 | * |
WFKnight | 0:9b3d4731edbb | 101 | * The drive will only re-appear when the microcontroller program exists. Note that if the program does |
WFKnight | 0:9b3d4731edbb | 102 | * not exit, you will need to hold down reset on the mbed Microcontroller to be able to see the drive again! |
WFKnight | 0:9b3d4731edbb | 103 | * @ingroup platform |
WFKnight | 0:9b3d4731edbb | 104 | */ |
WFKnight | 0:9b3d4731edbb | 105 | class LocalFileSystem : public FileSystemLike, private NonCopyable<LocalFileSystem> { |
WFKnight | 0:9b3d4731edbb | 106 | // No modifiable state |
WFKnight | 0:9b3d4731edbb | 107 | |
WFKnight | 0:9b3d4731edbb | 108 | public: |
WFKnight | 0:9b3d4731edbb | 109 | LocalFileSystem(const char* n) : FileSystemLike(n) { |
WFKnight | 0:9b3d4731edbb | 110 | |
WFKnight | 0:9b3d4731edbb | 111 | } |
WFKnight | 0:9b3d4731edbb | 112 | |
WFKnight | 0:9b3d4731edbb | 113 | virtual int open(FileHandle **file, const char *path, int flags); |
WFKnight | 0:9b3d4731edbb | 114 | virtual int open(DirHandle **dir, const char *name); |
WFKnight | 0:9b3d4731edbb | 115 | virtual int remove(const char *filename); |
WFKnight | 0:9b3d4731edbb | 116 | }; |
WFKnight | 0:9b3d4731edbb | 117 | |
WFKnight | 0:9b3d4731edbb | 118 | /**@}*/ |
WFKnight | 0:9b3d4731edbb | 119 | |
WFKnight | 0:9b3d4731edbb | 120 | /**@}*/ |
WFKnight | 0:9b3d4731edbb | 121 | |
WFKnight | 0:9b3d4731edbb | 122 | } // namespace mbed |
WFKnight | 0:9b3d4731edbb | 123 | |
WFKnight | 0:9b3d4731edbb | 124 | #endif |
WFKnight | 0:9b3d4731edbb | 125 | |
WFKnight | 0:9b3d4731edbb | 126 | #endif |
WFKnight | 0:9b3d4731edbb | 127 |