Committer:
borlanic
Date:
Thu Mar 29 07:02:09 2018 +0000
Revision:
0:380207fcb5c1
Encoder, IMU --> OK; Controller --> in bearbeitung

Who changed what in which revision?

UserRevisionLine numberNew contents of line
borlanic 0:380207fcb5c1 1 /* mbed Microcontroller Library
borlanic 0:380207fcb5c1 2 * Copyright (c) 2015 ARM Limited
borlanic 0:380207fcb5c1 3 *
borlanic 0:380207fcb5c1 4 * Licensed under the Apache License, Version 2.0 (the "License");
borlanic 0:380207fcb5c1 5 * you may not use this file except in compliance with the License.
borlanic 0:380207fcb5c1 6 * You may obtain a copy of the License at
borlanic 0:380207fcb5c1 7 *
borlanic 0:380207fcb5c1 8 * http://www.apache.org/licenses/LICENSE-2.0
borlanic 0:380207fcb5c1 9 *
borlanic 0:380207fcb5c1 10 * Unless required by applicable law or agreed to in writing, software
borlanic 0:380207fcb5c1 11 * distributed under the License is distributed on an "AS IS" BASIS,
borlanic 0:380207fcb5c1 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
borlanic 0:380207fcb5c1 13 * See the License for the specific language governing permissions and
borlanic 0:380207fcb5c1 14 * limitations under the License.
borlanic 0:380207fcb5c1 15 */
borlanic 0:380207fcb5c1 16
borlanic 0:380207fcb5c1 17 #ifndef FILE_H
borlanic 0:380207fcb5c1 18 #define FILE_H
borlanic 0:380207fcb5c1 19
borlanic 0:380207fcb5c1 20 #include "filesystem/FileSystem.h"
borlanic 0:380207fcb5c1 21 #include "platform/FileHandle.h"
borlanic 0:380207fcb5c1 22
borlanic 0:380207fcb5c1 23 namespace mbed {
borlanic 0:380207fcb5c1 24 /** \addtogroup filesystem */
borlanic 0:380207fcb5c1 25 /** @{*/
borlanic 0:380207fcb5c1 26
borlanic 0:380207fcb5c1 27
borlanic 0:380207fcb5c1 28 /** File class
borlanic 0:380207fcb5c1 29 */
borlanic 0:380207fcb5c1 30 class File : public FileHandle {
borlanic 0:380207fcb5c1 31 public:
borlanic 0:380207fcb5c1 32 /** Create an uninitialized file
borlanic 0:380207fcb5c1 33 *
borlanic 0:380207fcb5c1 34 * Must call open to initialize the file on a file system
borlanic 0:380207fcb5c1 35 */
borlanic 0:380207fcb5c1 36 File();
borlanic 0:380207fcb5c1 37
borlanic 0:380207fcb5c1 38 /** Create a file on a filesystem
borlanic 0:380207fcb5c1 39 *
borlanic 0:380207fcb5c1 40 * Creates and opens a file on a filesystem
borlanic 0:380207fcb5c1 41 *
borlanic 0:380207fcb5c1 42 * @param fs Filesystem as target for the file
borlanic 0:380207fcb5c1 43 * @param path The name of the file to open
borlanic 0:380207fcb5c1 44 * @param flags The flags to open the file in, one of O_RDONLY, O_WRONLY, O_RDWR,
borlanic 0:380207fcb5c1 45 * bitwise or'd with one of O_CREAT, O_TRUNC, O_APPEND
borlanic 0:380207fcb5c1 46 */
borlanic 0:380207fcb5c1 47 File(FileSystem *fs, const char *path, int flags = O_RDONLY);
borlanic 0:380207fcb5c1 48
borlanic 0:380207fcb5c1 49 /** Destroy a file
borlanic 0:380207fcb5c1 50 *
borlanic 0:380207fcb5c1 51 * Closes file if the file is still open
borlanic 0:380207fcb5c1 52 */
borlanic 0:380207fcb5c1 53 virtual ~File();
borlanic 0:380207fcb5c1 54
borlanic 0:380207fcb5c1 55 /** Open a file on the filesystem
borlanic 0:380207fcb5c1 56 *
borlanic 0:380207fcb5c1 57 * @param fs Filesystem as target for the file
borlanic 0:380207fcb5c1 58 * @param path The name of the file to open
borlanic 0:380207fcb5c1 59 * @param flags The flags to open the file in, one of O_RDONLY, O_WRONLY, O_RDWR,
borlanic 0:380207fcb5c1 60 * bitwise or'd with one of O_CREAT, O_TRUNC, O_APPEND
borlanic 0:380207fcb5c1 61 * @return 0 on success, negative error code on failure
borlanic 0:380207fcb5c1 62 */
borlanic 0:380207fcb5c1 63 virtual int open(FileSystem *fs, const char *path, int flags=O_RDONLY);
borlanic 0:380207fcb5c1 64
borlanic 0:380207fcb5c1 65 /** Close a file
borlanic 0:380207fcb5c1 66 *
borlanic 0:380207fcb5c1 67 * @return 0 on success, negative error code on failure
borlanic 0:380207fcb5c1 68 */
borlanic 0:380207fcb5c1 69 virtual int close();
borlanic 0:380207fcb5c1 70
borlanic 0:380207fcb5c1 71 /** Read the contents of a file into a buffer
borlanic 0:380207fcb5c1 72 *
borlanic 0:380207fcb5c1 73 * @param buffer The buffer to read in to
borlanic 0:380207fcb5c1 74 * @param size The number of bytes to read
borlanic 0:380207fcb5c1 75 * @return The number of bytes read, 0 at end of file, negative error on failure
borlanic 0:380207fcb5c1 76 */
borlanic 0:380207fcb5c1 77
borlanic 0:380207fcb5c1 78 virtual ssize_t read(void *buffer, size_t size);
borlanic 0:380207fcb5c1 79
borlanic 0:380207fcb5c1 80 /** Write the contents of a buffer to a file
borlanic 0:380207fcb5c1 81 *
borlanic 0:380207fcb5c1 82 * @param buffer The buffer to write from
borlanic 0:380207fcb5c1 83 * @param size The number of bytes to write
borlanic 0:380207fcb5c1 84 * @return The number of bytes written, negative error on failure
borlanic 0:380207fcb5c1 85 */
borlanic 0:380207fcb5c1 86 virtual ssize_t write(const void *buffer, size_t size);
borlanic 0:380207fcb5c1 87
borlanic 0:380207fcb5c1 88 /** Flush any buffers associated with the file
borlanic 0:380207fcb5c1 89 *
borlanic 0:380207fcb5c1 90 * @return 0 on success, negative error code on failure
borlanic 0:380207fcb5c1 91 */
borlanic 0:380207fcb5c1 92 virtual int sync();
borlanic 0:380207fcb5c1 93
borlanic 0:380207fcb5c1 94 /** Check if the file in an interactive terminal device
borlanic 0:380207fcb5c1 95 *
borlanic 0:380207fcb5c1 96 * @return True if the file is a terminal
borlanic 0:380207fcb5c1 97 */
borlanic 0:380207fcb5c1 98 virtual int isatty();
borlanic 0:380207fcb5c1 99
borlanic 0:380207fcb5c1 100 /** Move the file position to a given offset from from a given location
borlanic 0:380207fcb5c1 101 *
borlanic 0:380207fcb5c1 102 * @param offset The offset from whence to move to
borlanic 0:380207fcb5c1 103 * @param whence The start of where to seek
borlanic 0:380207fcb5c1 104 * SEEK_SET to start from beginning of file,
borlanic 0:380207fcb5c1 105 * SEEK_CUR to start from current position in file,
borlanic 0:380207fcb5c1 106 * SEEK_END to start from end of file
borlanic 0:380207fcb5c1 107 * @return The new offset of the file
borlanic 0:380207fcb5c1 108 */
borlanic 0:380207fcb5c1 109 virtual off_t seek(off_t offset, int whence = SEEK_SET);
borlanic 0:380207fcb5c1 110
borlanic 0:380207fcb5c1 111 /** Get the file position of the file
borlanic 0:380207fcb5c1 112 *
borlanic 0:380207fcb5c1 113 * @return The current offset in the file
borlanic 0:380207fcb5c1 114 */
borlanic 0:380207fcb5c1 115 virtual off_t tell();
borlanic 0:380207fcb5c1 116
borlanic 0:380207fcb5c1 117 /** Rewind the file position to the beginning of the file
borlanic 0:380207fcb5c1 118 *
borlanic 0:380207fcb5c1 119 * @note This is equivalent to file_seek(file, 0, FS_SEEK_SET)
borlanic 0:380207fcb5c1 120 */
borlanic 0:380207fcb5c1 121 virtual void rewind();
borlanic 0:380207fcb5c1 122
borlanic 0:380207fcb5c1 123 /** Get the size of the file
borlanic 0:380207fcb5c1 124 *
borlanic 0:380207fcb5c1 125 * @return Size of the file in bytes
borlanic 0:380207fcb5c1 126 */
borlanic 0:380207fcb5c1 127 virtual off_t size();
borlanic 0:380207fcb5c1 128
borlanic 0:380207fcb5c1 129 private:
borlanic 0:380207fcb5c1 130 FileSystem *_fs;
borlanic 0:380207fcb5c1 131 fs_file_t _file;
borlanic 0:380207fcb5c1 132 };
borlanic 0:380207fcb5c1 133
borlanic 0:380207fcb5c1 134
borlanic 0:380207fcb5c1 135 /** @}*/
borlanic 0:380207fcb5c1 136 } // namespace mbed
borlanic 0:380207fcb5c1 137
borlanic 0:380207fcb5c1 138 #endif