BA / SerialCom

Fork of OmniWheels by Gustav Atmel

Committer:
gustavatmel
Date:
Tue May 01 15:47:08 2018 +0000
Revision:
1:9c5af431a1f1
sdf

Who changed what in which revision?

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