BLE temperature profile using digital DS1820 or analog LM35 sensors

Dependencies:   DS1820

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers DirHandle.h Source File

DirHandle.h

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2006-2013 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #ifndef MBED_DIRHANDLE_H
00017 #define MBED_DIRHANDLE_H
00018 
00019 #if defined(__ARMCC_VERSION) || defined(__ICCARM__)
00020 #   define NAME_MAX 255
00021 typedef int mode_t;
00022 
00023 #else
00024 #   include <sys/syslimits.h>
00025 #endif
00026 
00027 #include "FileHandle.h"
00028 
00029 struct dirent {
00030     char d_name[NAME_MAX+1];
00031 };
00032 
00033 namespace mbed {
00034 
00035 /** Represents a directory stream. Objects of this type are returned
00036  *  by a FileSystemLike's opendir method. Implementations must define
00037  *  at least closedir, readdir and rewinddir.
00038  *
00039  *  If a FileSystemLike class defines the opendir method, then the
00040  *  directories of an object of that type can be accessed by
00041  *  DIR *d = opendir("/example/directory") (or opendir("/example")
00042  *  to open the root of the filesystem), and then using readdir(d) etc.
00043  *
00044  *  The root directory is considered to contain all FileLike and
00045  *  FileSystemLike objects, so the DIR* returned by opendir("/") will
00046  *  reflect this.
00047  */
00048 class DirHandle {
00049 
00050 public:
00051     /** Closes the directory.
00052      *
00053      *  @returns
00054      *    0 on success,
00055      *   -1 on error.
00056      */
00057     virtual int closedir()=0;
00058 
00059     /** Return the directory entry at the current position, and
00060      *  advances the position to the next entry.
00061      *
00062      * @returns
00063      *  A pointer to a dirent structure representing the
00064      *  directory entry at the current position, or NULL on reaching
00065      *  end of directory or error.
00066      */
00067     virtual struct dirent *readdir()=0;
00068 
00069     /** Resets the position to the beginning of the directory.
00070      */
00071     virtual void rewinddir()=0;
00072 
00073     /** Returns the current position of the DirHandle.
00074      *
00075      * @returns
00076      *   the current position,
00077      *  -1 on error.
00078      */
00079     virtual off_t telldir() { return -1; }
00080 
00081     /** Sets the position of the DirHandle.
00082      *
00083      *  @param location The location to seek to. Must be a value returned by telldir.
00084      */
00085     virtual void seekdir(off_t location) { }
00086 
00087     virtual ~DirHandle() {}
00088 };
00089 
00090 } // namespace mbed
00091 
00092 typedef mbed::DirHandle DIR;
00093 
00094 extern "C" {
00095     DIR *opendir(const char*);
00096     struct dirent *readdir(DIR *);
00097     int closedir(DIR*);
00098     void rewinddir(DIR*);
00099     long telldir(DIR*);
00100     void seekdir(DIR*, long);
00101     int mkdir(const char *name, mode_t n);
00102 };
00103 
00104 #endif /* MBED_DIRHANDLE_H */