Renesas GR-PEACH OpenCV Development / gr-peach-opencv-project-sd-card_update

Fork of gr-peach-opencv-project-sd-card by the do

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LocalFileSystem.h Source File

LocalFileSystem.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_LOCALFILESYSTEM_H
00017 #define MBED_LOCALFILESYSTEM_H
00018 
00019 #include "platform/platform.h"
00020 
00021 #if DEVICE_LOCALFILESYSTEM
00022 
00023 #include "platform/FileSystemLike.h"
00024 #include "platform/PlatformMutex.h"
00025 
00026 namespace mbed {
00027 /** \addtogroup platform */
00028 /** @{*/
00029 
00030 FILEHANDLE local_file_open(const char* name, int flags);
00031 /** @}*/
00032 
00033 /**
00034  * @class LocalFileHandle
00035  * @ingroup platform
00036  */
00037 class LocalFileHandle : public FileHandle {
00038 
00039 public:
00040     LocalFileHandle(FILEHANDLE fh);
00041 
00042     virtual int close();
00043 
00044     virtual ssize_t write(const void *buffer, size_t length);
00045 
00046     virtual ssize_t read(void *buffer, size_t length);
00047 
00048     virtual int isatty();
00049 
00050     virtual off_t seek(off_t position, int whence);
00051 
00052     virtual int sync();
00053 
00054     virtual off_t size();
00055 
00056 protected:
00057     virtual void lock();
00058     virtual void unlock();
00059     FILEHANDLE _fh;
00060     int pos;
00061     PlatformMutex _mutex;
00062 };
00063 
00064 /** A filesystem for accessing the local mbed Microcontroller USB disk drive
00065  *
00066  *  This allows programs to read and write files on the same disk drive that is used to program the
00067  *  mbed Microcontroller. Once created, the standard C file access functions are used to open,
00068  *  read and write files.
00069  *
00070  * @note Synchronization level: Thread safe
00071  *
00072  * Example:
00073  * @code
00074  * #include "mbed.h"
00075  *
00076  * LocalFileSystem local("local");               // Create the local filesystem under the name "local"
00077  *
00078  * int main() {
00079  *     FILE *fp = fopen("/local/out.txt", "w");  // Open "out.txt" on the local file system for writing
00080  *     fprintf(fp, "Hello World!");
00081  *     fclose(fp);
00082  *     remove("/local/out.txt");                 // Removes the file "out.txt" from the local file system
00083  *
00084  *     DIR *d = opendir("/local");               // Opens the root directory of the local file system
00085  *     struct dirent *p;
00086  *     while((p = readdir(d)) != NULL) {         // Print the names of the files in the local file system
00087  *       printf("%s\n", p->d_name);              // to stdout.
00088  *     }
00089  *     closedir(d);
00090  * }
00091  * @endcode
00092  *
00093  * @note
00094  *  If the microcontroller program makes an access to the local drive, it will be marked as "removed"
00095  *  on the Host computer. This means it is no longer accessible from the Host Computer.
00096  *
00097  *  The drive will only re-appear when the microcontroller program exists. Note that if the program does
00098  *  not exit, you will need to hold down reset on the mbed Microcontroller to be able to see the drive again!
00099  * @ingroup platform
00100  */
00101 class LocalFileSystem : public FileSystemLike {
00102     // No modifiable state
00103 
00104 public:
00105     LocalFileSystem(const char* n) : FileSystemLike(n) {
00106 
00107     }
00108 
00109     virtual int open(FileHandle **file, const char *path, int flags);
00110     virtual int open(DirHandle **dir, const char *name);
00111     virtual int remove(const char *filename);
00112 };
00113 
00114 } // namespace mbed
00115 
00116 #endif
00117 
00118 #endif
00119 
00120