1 /* mbed Microcontroller Library
2  * Copyright (c) 2006-2013 ARM Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef MBED_DIRHANDLE_H
17 #define MBED_DIRHANDLE_H
18 
19 #include <stdint.h>
20 #include "platform/platform.h"
21 
22 #include "FileHandle.h"
23 
24 namespace mbed {
25 /** \addtogroup drivers */
26 /** @{*/
27 
28 /** Represents a directory stream. Objects of this type are returned
29  *  by a FileSystemLike's opendir method. Implementations must define
30  *  at least closedir, readdir and rewinddir.
31  *
32  *  If a FileSystemLike class defines the opendir method, then the
33  *  directories of an object of that type can be accessed by
34  *  DIR *d = opendir("/example/directory") (or opendir("/example")
35  *  to open the root of the filesystem), and then using readdir(d) etc.
36  *
37  *  The root directory is considered to contain all FileLike and
38  *  FileSystemLike objects, so the DIR* returned by opendir("/") will
39  *  reflect this.
40  *
41  *  @Note Synchronization level: Set by subclass
42  */
43 class DirHandle {
44 public:
45     MBED_DEPRECATED_SINCE("mbed-os-5.4",
46         "The mbed 2 filesystem classes have been superseeded by the FileSystem api, "
47         "Replaced by File")
DirHandle()48     DirHandle() {}
49 
50     /** Closes the directory.
51      *
52      *  @returns
53      *    0 on success,
54      *   -1 on error.
55      */
56     virtual int closedir()=0;
57 
58     /** Return the directory entry at the current position, and
59      *  advances the position to the next entry.
60      *
61      * @returns
62      *  A pointer to a dirent structure representing the
63      *  directory entry at the current position, or NULL on reaching
64      *  end of directory or error.
65      */
66     virtual struct dirent *readdir()=0;
67 
68     /** Resets the position to the beginning of the directory.
69      */
70     virtual void rewinddir()=0;
71 
72     /** Returns the current position of the DirHandle.
73      *
74      * @returns
75      *   the current position,
76      *  -1 on error.
77      */
telldir()78     virtual off_t telldir() { return -1; }
79 
80     /** Sets the position of the DirHandle.
81      *
82      *  @param location The location to seek to. Must be a value returned by telldir.
83      */
seekdir(off_t location)84     virtual void seekdir(off_t location) { (void)location;}
85 
~DirHandle()86     virtual ~DirHandle() {}
87 
88 protected:
89 
90     /** Acquire exclusive access to this object.
91      */
lock()92     virtual void lock() {
93         // Stub
94     }
95 
96     /** Release exclusive access to this object.
97      */
unlock()98     virtual void unlock() {
99         // Stub
100     }
101 
102 protected:
103     /** Internal-only constructor to work around deprecated notices when not used
104      *. due to nested deprecations and difficulty of compilers finding their way around
105      *  the class hierarchy
106      */
107     friend class FileSystemLike;
DirHandle(int)108     DirHandle(int) {}
109 };
110 
111 } // namespace mbed
112 
113 #endif /* MBED_DIRHANDLE_H */
114 
115 /** @}*/
116