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_DIRHANDLE_H
kbrahmbhatt6 0:2f388b030837 17 #define MBED_DIRHANDLE_H
kbrahmbhatt6 0:2f388b030837 18
kbrahmbhatt6 0:2f388b030837 19 #if defined(__ARMCC_VERSION) || defined(__ICCARM__)
kbrahmbhatt6 0:2f388b030837 20 # define NAME_MAX 255
kbrahmbhatt6 0:2f388b030837 21 typedef int mode_t;
kbrahmbhatt6 0:2f388b030837 22
kbrahmbhatt6 0:2f388b030837 23 #else
kbrahmbhatt6 0:2f388b030837 24 # include <sys/syslimits.h>
kbrahmbhatt6 0:2f388b030837 25 #endif
kbrahmbhatt6 0:2f388b030837 26
kbrahmbhatt6 0:2f388b030837 27 #include "FileHandle.h"
kbrahmbhatt6 0:2f388b030837 28
kbrahmbhatt6 0:2f388b030837 29 struct dirent {
kbrahmbhatt6 0:2f388b030837 30 char d_name[NAME_MAX+1];
kbrahmbhatt6 0:2f388b030837 31 };
kbrahmbhatt6 0:2f388b030837 32
kbrahmbhatt6 0:2f388b030837 33 namespace mbed {
kbrahmbhatt6 0:2f388b030837 34
kbrahmbhatt6 0:2f388b030837 35 /** Represents a directory stream. Objects of this type are returned
kbrahmbhatt6 0:2f388b030837 36 * by a FileSystemLike's opendir method. Implementations must define
kbrahmbhatt6 0:2f388b030837 37 * at least closedir, readdir and rewinddir.
kbrahmbhatt6 0:2f388b030837 38 *
kbrahmbhatt6 0:2f388b030837 39 * If a FileSystemLike class defines the opendir method, then the
kbrahmbhatt6 0:2f388b030837 40 * directories of an object of that type can be accessed by
kbrahmbhatt6 0:2f388b030837 41 * DIR *d = opendir("/example/directory") (or opendir("/example")
kbrahmbhatt6 0:2f388b030837 42 * to open the root of the filesystem), and then using readdir(d) etc.
kbrahmbhatt6 0:2f388b030837 43 *
kbrahmbhatt6 0:2f388b030837 44 * The root directory is considered to contain all FileLike and
kbrahmbhatt6 0:2f388b030837 45 * FileSystemLike objects, so the DIR* returned by opendir("/") will
kbrahmbhatt6 0:2f388b030837 46 * reflect this.
kbrahmbhatt6 0:2f388b030837 47 */
kbrahmbhatt6 0:2f388b030837 48 class DirHandle {
kbrahmbhatt6 0:2f388b030837 49
kbrahmbhatt6 0:2f388b030837 50 public:
kbrahmbhatt6 0:2f388b030837 51 /** Closes the directory.
kbrahmbhatt6 0:2f388b030837 52 *
kbrahmbhatt6 0:2f388b030837 53 * @returns
kbrahmbhatt6 0:2f388b030837 54 * 0 on success,
kbrahmbhatt6 0:2f388b030837 55 * -1 on error.
kbrahmbhatt6 0:2f388b030837 56 */
kbrahmbhatt6 0:2f388b030837 57 virtual int closedir()=0;
kbrahmbhatt6 0:2f388b030837 58
kbrahmbhatt6 0:2f388b030837 59 /** Return the directory entry at the current position, and
kbrahmbhatt6 0:2f388b030837 60 * advances the position to the next entry.
kbrahmbhatt6 0:2f388b030837 61 *
kbrahmbhatt6 0:2f388b030837 62 * @returns
kbrahmbhatt6 0:2f388b030837 63 * A pointer to a dirent structure representing the
kbrahmbhatt6 0:2f388b030837 64 * directory entry at the current position, or NULL on reaching
kbrahmbhatt6 0:2f388b030837 65 * end of directory or error.
kbrahmbhatt6 0:2f388b030837 66 */
kbrahmbhatt6 0:2f388b030837 67 virtual struct dirent *readdir()=0;
kbrahmbhatt6 0:2f388b030837 68
kbrahmbhatt6 0:2f388b030837 69 /** Resets the position to the beginning of the directory.
kbrahmbhatt6 0:2f388b030837 70 */
kbrahmbhatt6 0:2f388b030837 71 virtual void rewinddir()=0;
kbrahmbhatt6 0:2f388b030837 72
kbrahmbhatt6 0:2f388b030837 73 /** Returns the current position of the DirHandle.
kbrahmbhatt6 0:2f388b030837 74 *
kbrahmbhatt6 0:2f388b030837 75 * @returns
kbrahmbhatt6 0:2f388b030837 76 * the current position,
kbrahmbhatt6 0:2f388b030837 77 * -1 on error.
kbrahmbhatt6 0:2f388b030837 78 */
kbrahmbhatt6 0:2f388b030837 79 virtual off_t telldir() { return -1; }
kbrahmbhatt6 0:2f388b030837 80
kbrahmbhatt6 0:2f388b030837 81 /** Sets the position of the DirHandle.
kbrahmbhatt6 0:2f388b030837 82 *
kbrahmbhatt6 0:2f388b030837 83 * @param location The location to seek to. Must be a value returned by telldir.
kbrahmbhatt6 0:2f388b030837 84 */
kbrahmbhatt6 0:2f388b030837 85 virtual void seekdir(off_t location) { }
kbrahmbhatt6 0:2f388b030837 86
kbrahmbhatt6 0:2f388b030837 87 virtual ~DirHandle() {}
kbrahmbhatt6 0:2f388b030837 88 };
kbrahmbhatt6 0:2f388b030837 89
kbrahmbhatt6 0:2f388b030837 90 } // namespace mbed
kbrahmbhatt6 0:2f388b030837 91
kbrahmbhatt6 0:2f388b030837 92 typedef mbed::DirHandle DIR;
kbrahmbhatt6 0:2f388b030837 93
kbrahmbhatt6 0:2f388b030837 94 extern "C" {
kbrahmbhatt6 0:2f388b030837 95 DIR *opendir(const char*);
kbrahmbhatt6 0:2f388b030837 96 struct dirent *readdir(DIR *);
kbrahmbhatt6 0:2f388b030837 97 int closedir(DIR*);
kbrahmbhatt6 0:2f388b030837 98 void rewinddir(DIR*);
kbrahmbhatt6 0:2f388b030837 99 long telldir(DIR*);
kbrahmbhatt6 0:2f388b030837 100 void seekdir(DIR*, long);
kbrahmbhatt6 0:2f388b030837 101 int mkdir(const char *name, mode_t n);
kbrahmbhatt6 0:2f388b030837 102 };
kbrahmbhatt6 0:2f388b030837 103
kbrahmbhatt6 0:2f388b030837 104 #endif /* MBED_DIRHANDLE_H */