IOTIO

Dependencies:   Nucleo_BLE_API_IOTIO Nucleo_BLE_BlueNRG Nucleo_BLE_DemoApp Nucleo_Sensor_Shield mbed

Dependents:   Nucleo_BLE_Demo_IOTIO

Fork of Nucleo_BLE_Demo by Cortex Challenge Team

Committer:
16038618
Date:
Wed Mar 08 10:24:56 2017 +0000
Revision:
2:c69117fc79da
Parent:
1:4bdfa7d7e8bf
IOTIO

Who changed what in which revision?

UserRevisionLine numberNew contents of line
16038618 1:4bdfa7d7e8bf 1 /* mbed Microcontroller Library
16038618 1:4bdfa7d7e8bf 2 * Copyright (c) 2006-2013 ARM Limited
16038618 1:4bdfa7d7e8bf 3 *
16038618 1:4bdfa7d7e8bf 4 * Licensed under the Apache License, Version 2.0 (the "License");
16038618 1:4bdfa7d7e8bf 5 * you may not use this file except in compliance with the License.
16038618 1:4bdfa7d7e8bf 6 * You may obtain a copy of the License at
16038618 1:4bdfa7d7e8bf 7 *
16038618 1:4bdfa7d7e8bf 8 * http://www.apache.org/licenses/LICENSE-2.0
16038618 1:4bdfa7d7e8bf 9 *
16038618 1:4bdfa7d7e8bf 10 * Unless required by applicable law or agreed to in writing, software
16038618 1:4bdfa7d7e8bf 11 * distributed under the License is distributed on an "AS IS" BASIS,
16038618 1:4bdfa7d7e8bf 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16038618 1:4bdfa7d7e8bf 13 * See the License for the specific language governing permissions and
16038618 1:4bdfa7d7e8bf 14 * limitations under the License.
16038618 1:4bdfa7d7e8bf 15 */
16038618 1:4bdfa7d7e8bf 16 #ifndef MBED_FILEHANDLE_H
16038618 1:4bdfa7d7e8bf 17 #define MBED_FILEHANDLE_H
16038618 1:4bdfa7d7e8bf 18
16038618 1:4bdfa7d7e8bf 19 typedef int FILEHANDLE;
16038618 1:4bdfa7d7e8bf 20
16038618 1:4bdfa7d7e8bf 21 #include <stdio.h>
16038618 1:4bdfa7d7e8bf 22
16038618 1:4bdfa7d7e8bf 23 #if defined(__ARMCC_VERSION) || defined(__ICCARM__)
16038618 1:4bdfa7d7e8bf 24 typedef int ssize_t;
16038618 1:4bdfa7d7e8bf 25 typedef long off_t;
16038618 1:4bdfa7d7e8bf 26
16038618 1:4bdfa7d7e8bf 27 #else
16038618 1:4bdfa7d7e8bf 28 # include <sys/types.h>
16038618 1:4bdfa7d7e8bf 29 #endif
16038618 1:4bdfa7d7e8bf 30
16038618 1:4bdfa7d7e8bf 31 namespace mbed {
16038618 1:4bdfa7d7e8bf 32
16038618 1:4bdfa7d7e8bf 33 /** An OO equivalent of the internal FILEHANDLE variable
16038618 1:4bdfa7d7e8bf 34 * and associated _sys_* functions.
16038618 1:4bdfa7d7e8bf 35 *
16038618 1:4bdfa7d7e8bf 36 * FileHandle is an abstract class, needing at least sys_write and
16038618 1:4bdfa7d7e8bf 37 * sys_read to be implmented for a simple interactive device.
16038618 1:4bdfa7d7e8bf 38 *
16038618 1:4bdfa7d7e8bf 39 * No one ever directly tals to/instanciates a FileHandle - it gets
16038618 1:4bdfa7d7e8bf 40 * created by FileSystem, and wrapped up by stdio.
16038618 1:4bdfa7d7e8bf 41 */
16038618 1:4bdfa7d7e8bf 42 class FileHandle {
16038618 1:4bdfa7d7e8bf 43
16038618 1:4bdfa7d7e8bf 44 public:
16038618 1:4bdfa7d7e8bf 45 /** Write the contents of a buffer to the file
16038618 1:4bdfa7d7e8bf 46 *
16038618 1:4bdfa7d7e8bf 47 * @param buffer the buffer to write from
16038618 1:4bdfa7d7e8bf 48 * @param length the number of characters to write
16038618 1:4bdfa7d7e8bf 49 *
16038618 1:4bdfa7d7e8bf 50 * @returns
16038618 1:4bdfa7d7e8bf 51 * The number of characters written (possibly 0) on success, -1 on error.
16038618 1:4bdfa7d7e8bf 52 */
16038618 1:4bdfa7d7e8bf 53 virtual ssize_t write(const void* buffer, size_t length) = 0;
16038618 1:4bdfa7d7e8bf 54
16038618 1:4bdfa7d7e8bf 55 /** Close the file
16038618 1:4bdfa7d7e8bf 56 *
16038618 1:4bdfa7d7e8bf 57 * @returns
16038618 1:4bdfa7d7e8bf 58 * Zero on success, -1 on error.
16038618 1:4bdfa7d7e8bf 59 */
16038618 1:4bdfa7d7e8bf 60 virtual int close() = 0;
16038618 1:4bdfa7d7e8bf 61
16038618 1:4bdfa7d7e8bf 62 /** Function read
16038618 1:4bdfa7d7e8bf 63 * Reads the contents of the file into a buffer
16038618 1:4bdfa7d7e8bf 64 *
16038618 1:4bdfa7d7e8bf 65 * @param buffer the buffer to read in to
16038618 1:4bdfa7d7e8bf 66 * @param length the number of characters to read
16038618 1:4bdfa7d7e8bf 67 *
16038618 1:4bdfa7d7e8bf 68 * @returns
16038618 1:4bdfa7d7e8bf 69 * The number of characters read (zero at end of file) on success, -1 on error.
16038618 1:4bdfa7d7e8bf 70 */
16038618 1:4bdfa7d7e8bf 71 virtual ssize_t read(void* buffer, size_t length) = 0;
16038618 1:4bdfa7d7e8bf 72
16038618 1:4bdfa7d7e8bf 73 /** Check if the handle is for a interactive terminal device.
16038618 1:4bdfa7d7e8bf 74 * If so, line buffered behaviour is used by default
16038618 1:4bdfa7d7e8bf 75 *
16038618 1:4bdfa7d7e8bf 76 * @returns
16038618 1:4bdfa7d7e8bf 77 * 1 if it is a terminal,
16038618 1:4bdfa7d7e8bf 78 * 0 otherwise
16038618 1:4bdfa7d7e8bf 79 */
16038618 1:4bdfa7d7e8bf 80 virtual int isatty() = 0;
16038618 1:4bdfa7d7e8bf 81
16038618 1:4bdfa7d7e8bf 82 /** Move the file position to a given offset from a given location.
16038618 1:4bdfa7d7e8bf 83 *
16038618 1:4bdfa7d7e8bf 84 * @param offset The offset from whence to move to
16038618 1:4bdfa7d7e8bf 85 * @param whence SEEK_SET for the start of the file, SEEK_CUR for the
16038618 1:4bdfa7d7e8bf 86 * current file position, or SEEK_END for the end of the file.
16038618 1:4bdfa7d7e8bf 87 *
16038618 1:4bdfa7d7e8bf 88 * @returns
16038618 1:4bdfa7d7e8bf 89 * new file position on success,
16038618 1:4bdfa7d7e8bf 90 * -1 on failure or unsupported
16038618 1:4bdfa7d7e8bf 91 */
16038618 1:4bdfa7d7e8bf 92 virtual off_t lseek(off_t offset, int whence) = 0;
16038618 1:4bdfa7d7e8bf 93
16038618 1:4bdfa7d7e8bf 94 /** Flush any buffers associated with the FileHandle, ensuring it
16038618 1:4bdfa7d7e8bf 95 * is up to date on disk
16038618 1:4bdfa7d7e8bf 96 *
16038618 1:4bdfa7d7e8bf 97 * @returns
16038618 1:4bdfa7d7e8bf 98 * 0 on success or un-needed,
16038618 1:4bdfa7d7e8bf 99 * -1 on error
16038618 1:4bdfa7d7e8bf 100 */
16038618 1:4bdfa7d7e8bf 101 virtual int fsync() = 0;
16038618 1:4bdfa7d7e8bf 102
16038618 1:4bdfa7d7e8bf 103 virtual off_t flen() {
16038618 1:4bdfa7d7e8bf 104 /* remember our current position */
16038618 1:4bdfa7d7e8bf 105 off_t pos = lseek(0, SEEK_CUR);
16038618 1:4bdfa7d7e8bf 106 if(pos == -1) return -1;
16038618 1:4bdfa7d7e8bf 107 /* seek to the end to get the file length */
16038618 1:4bdfa7d7e8bf 108 off_t res = lseek(0, SEEK_END);
16038618 1:4bdfa7d7e8bf 109 /* return to our old position */
16038618 1:4bdfa7d7e8bf 110 lseek(pos, SEEK_SET);
16038618 1:4bdfa7d7e8bf 111 return res;
16038618 1:4bdfa7d7e8bf 112 }
16038618 1:4bdfa7d7e8bf 113
16038618 1:4bdfa7d7e8bf 114 virtual ~FileHandle();
16038618 1:4bdfa7d7e8bf 115 };
16038618 1:4bdfa7d7e8bf 116
16038618 1:4bdfa7d7e8bf 117 } // namespace mbed
16038618 1:4bdfa7d7e8bf 118
16038618 1:4bdfa7d7e8bf 119 #endif