IoT Home Alarm System

Dependents:   IoTBurglar_and_Fire_AlarmSystem

Committer:
kbrahmbhatt6
Date:
Fri Apr 29 06:59:59 2016 +0000
Revision:
0:2f388b030837
1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kbrahmbhatt6 0:2f388b030837 1 /* mbed Microcontroller Library
kbrahmbhatt6 0:2f388b030837 2 * Copyright (c) 2006-2013 ARM Limited
kbrahmbhatt6 0:2f388b030837 3 *
kbrahmbhatt6 0:2f388b030837 4 * Licensed under the Apache License, Version 2.0 (the "License");
kbrahmbhatt6 0:2f388b030837 5 * you may not use this file except in compliance with the License.
kbrahmbhatt6 0:2f388b030837 6 * You may obtain a copy of the License at
kbrahmbhatt6 0:2f388b030837 7 *
kbrahmbhatt6 0:2f388b030837 8 * http://www.apache.org/licenses/LICENSE-2.0
kbrahmbhatt6 0:2f388b030837 9 *
kbrahmbhatt6 0:2f388b030837 10 * Unless required by applicable law or agreed to in writing, software
kbrahmbhatt6 0:2f388b030837 11 * distributed under the License is distributed on an "AS IS" BASIS,
kbrahmbhatt6 0:2f388b030837 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
kbrahmbhatt6 0:2f388b030837 13 * See the License for the specific language governing permissions and
kbrahmbhatt6 0:2f388b030837 14 * limitations under the License.
kbrahmbhatt6 0:2f388b030837 15 */
kbrahmbhatt6 0:2f388b030837 16 #ifndef MBED_FILESYSTEMLIKE_H
kbrahmbhatt6 0:2f388b030837 17 #define MBED_FILESYSTEMLIKE_H
kbrahmbhatt6 0:2f388b030837 18
kbrahmbhatt6 0:2f388b030837 19 #include "platform.h"
kbrahmbhatt6 0:2f388b030837 20
kbrahmbhatt6 0:2f388b030837 21 #include "FileBase.h"
kbrahmbhatt6 0:2f388b030837 22 #include "FileHandle.h"
kbrahmbhatt6 0:2f388b030837 23 #include "DirHandle.h"
kbrahmbhatt6 0:2f388b030837 24
kbrahmbhatt6 0:2f388b030837 25 namespace mbed {
kbrahmbhatt6 0:2f388b030837 26
kbrahmbhatt6 0:2f388b030837 27 /** A filesystem-like object is one that can be used to open files
kbrahmbhatt6 0:2f388b030837 28 * though it by fopen("/name/filename", mode)
kbrahmbhatt6 0:2f388b030837 29 *
kbrahmbhatt6 0:2f388b030837 30 * Implementations must define at least open (the default definitions
kbrahmbhatt6 0:2f388b030837 31 * of the rest of the functions just return error values).
kbrahmbhatt6 0:2f388b030837 32 */
kbrahmbhatt6 0:2f388b030837 33 class FileSystemLike : public FileBase {
kbrahmbhatt6 0:2f388b030837 34
kbrahmbhatt6 0:2f388b030837 35 public:
kbrahmbhatt6 0:2f388b030837 36 /** FileSystemLike constructor
kbrahmbhatt6 0:2f388b030837 37 *
kbrahmbhatt6 0:2f388b030837 38 * @param name The name to use for the filesystem.
kbrahmbhatt6 0:2f388b030837 39 */
kbrahmbhatt6 0:2f388b030837 40 FileSystemLike(const char *name);
kbrahmbhatt6 0:2f388b030837 41
kbrahmbhatt6 0:2f388b030837 42 virtual ~FileSystemLike();
kbrahmbhatt6 0:2f388b030837 43
kbrahmbhatt6 0:2f388b030837 44 static DirHandle *opendir();
kbrahmbhatt6 0:2f388b030837 45 friend class BaseDirHandle;
kbrahmbhatt6 0:2f388b030837 46
kbrahmbhatt6 0:2f388b030837 47 /** Opens a file from the filesystem
kbrahmbhatt6 0:2f388b030837 48 *
kbrahmbhatt6 0:2f388b030837 49 * @param filename The name of the file to open.
kbrahmbhatt6 0:2f388b030837 50 * @param flags One of O_RDONLY, O_WRONLY, or O_RDWR, OR'd with
kbrahmbhatt6 0:2f388b030837 51 * zero or more of O_CREAT, O_TRUNC, or O_APPEND.
kbrahmbhatt6 0:2f388b030837 52 *
kbrahmbhatt6 0:2f388b030837 53 * @returns
kbrahmbhatt6 0:2f388b030837 54 * A pointer to a FileHandle object representing the
kbrahmbhatt6 0:2f388b030837 55 * file on success, or NULL on failure.
kbrahmbhatt6 0:2f388b030837 56 */
kbrahmbhatt6 0:2f388b030837 57 virtual FileHandle *open(const char *filename, int flags) = 0;
kbrahmbhatt6 0:2f388b030837 58
kbrahmbhatt6 0:2f388b030837 59 /** Remove a file from the filesystem.
kbrahmbhatt6 0:2f388b030837 60 *
kbrahmbhatt6 0:2f388b030837 61 * @param filename the name of the file to remove.
kbrahmbhatt6 0:2f388b030837 62 * @param returns 0 on success, -1 on failure.
kbrahmbhatt6 0:2f388b030837 63 */
kbrahmbhatt6 0:2f388b030837 64 virtual int remove(const char *filename) { return -1; };
kbrahmbhatt6 0:2f388b030837 65
kbrahmbhatt6 0:2f388b030837 66 /** Rename a file in the filesystem.
kbrahmbhatt6 0:2f388b030837 67 *
kbrahmbhatt6 0:2f388b030837 68 * @param oldname the name of the file to rename.
kbrahmbhatt6 0:2f388b030837 69 * @param newname the name to rename it to.
kbrahmbhatt6 0:2f388b030837 70 *
kbrahmbhatt6 0:2f388b030837 71 * @returns
kbrahmbhatt6 0:2f388b030837 72 * 0 on success,
kbrahmbhatt6 0:2f388b030837 73 * -1 on failure.
kbrahmbhatt6 0:2f388b030837 74 */
kbrahmbhatt6 0:2f388b030837 75 virtual int rename(const char *oldname, const char *newname) { return -1; };
kbrahmbhatt6 0:2f388b030837 76
kbrahmbhatt6 0:2f388b030837 77 /** Opens a directory in the filesystem and returns a DirHandle
kbrahmbhatt6 0:2f388b030837 78 * representing the directory stream.
kbrahmbhatt6 0:2f388b030837 79 *
kbrahmbhatt6 0:2f388b030837 80 * @param name The name of the directory to open.
kbrahmbhatt6 0:2f388b030837 81 *
kbrahmbhatt6 0:2f388b030837 82 * @returns
kbrahmbhatt6 0:2f388b030837 83 * A DirHandle representing the directory stream, or
kbrahmbhatt6 0:2f388b030837 84 * NULL on failure.
kbrahmbhatt6 0:2f388b030837 85 */
kbrahmbhatt6 0:2f388b030837 86 virtual DirHandle *opendir(const char *name) { return NULL; };
kbrahmbhatt6 0:2f388b030837 87
kbrahmbhatt6 0:2f388b030837 88 /** Creates a directory in the filesystem.
kbrahmbhatt6 0:2f388b030837 89 *
kbrahmbhatt6 0:2f388b030837 90 * @param name The name of the directory to create.
kbrahmbhatt6 0:2f388b030837 91 * @param mode The permissions to create the directory with.
kbrahmbhatt6 0:2f388b030837 92 *
kbrahmbhatt6 0:2f388b030837 93 * @returns
kbrahmbhatt6 0:2f388b030837 94 * 0 on success,
kbrahmbhatt6 0:2f388b030837 95 * -1 on failure.
kbrahmbhatt6 0:2f388b030837 96 */
kbrahmbhatt6 0:2f388b030837 97 virtual int mkdir(const char *name, mode_t mode) { return -1; }
kbrahmbhatt6 0:2f388b030837 98
kbrahmbhatt6 0:2f388b030837 99 // TODO other filesystem functions (mkdir, rm, rn, ls etc)
kbrahmbhatt6 0:2f388b030837 100 };
kbrahmbhatt6 0:2f388b030837 101
kbrahmbhatt6 0:2f388b030837 102 } // namespace mbed
kbrahmbhatt6 0:2f388b030837 103
kbrahmbhatt6 0:2f388b030837 104 #endif