Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of TUKS-COURSE-TIMER by
FileSystemLike.cpp
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 #include "drivers/FileSystemLike.h" 00017 00018 namespace mbed { 00019 00020 class BaseDirHandle : public DirHandle { 00021 public: 00022 /* 00023 We keep track of our current location as the n'th object in the 00024 FileSystemLike list. Using a Base* instead would cause problems if that 00025 object were to be destroyed between readdirs. 00026 Using this method does mean though that destroying/creating objects can 00027 give unusual results from readdir. 00028 */ 00029 off_t n; 00030 struct dirent cur_entry; 00031 00032 BaseDirHandle() : n(0), cur_entry() { 00033 } 00034 00035 virtual int closedir() { 00036 // No lock can be used in destructor 00037 delete this; 00038 return 0; 00039 } 00040 00041 virtual struct dirent *readdir() { 00042 lock(); 00043 FileBase *ptr = FileBase::get(n); 00044 if (ptr == NULL) { 00045 unlock(); 00046 return NULL; 00047 } 00048 00049 /* Increment n, so next readdir gets the next item */ 00050 n++; 00051 00052 /* Setup cur entry and return a pointer to it */ 00053 std::strncpy(cur_entry.d_name, ptr->getName(), NAME_MAX); 00054 unlock(); 00055 return &cur_entry; 00056 } 00057 00058 virtual off_t telldir() { 00059 lock(); 00060 off_t offset = n; 00061 unlock(); 00062 return offset; 00063 } 00064 00065 virtual void seekdir(off_t offset) { 00066 lock(); 00067 n = offset; 00068 unlock(); 00069 } 00070 00071 virtual void rewinddir() { 00072 lock(); 00073 n = 0; 00074 unlock(); 00075 } 00076 00077 protected: 00078 PlatformMutex _mutex; 00079 00080 virtual void lock() { 00081 _mutex.lock(); 00082 } 00083 00084 virtual void unlock() { 00085 _mutex.unlock(); 00086 } 00087 }; 00088 00089 FileSystemLike::FileSystemLike(const char *name) : FileBase(name, FileSystemPathType) { 00090 00091 } 00092 00093 FileSystemLike::~FileSystemLike() { 00094 00095 } 00096 00097 DirHandle *FileSystemLike::opendir() { 00098 return new BaseDirHandle(); 00099 } 00100 00101 } // namespace mbed
Generated on Tue Jul 12 2022 17:38:48 by
