Opencv 3.1 project on GR-PEACH board

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

Committer:
thedo
Date:
Tue Jul 04 06:23:13 2017 +0000
Revision:
170:54ff26da7eb6
Parent:
166:3a9487d57a5c
project opencv 3.1 on GR PEACH board, no use SD card.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
thedo 166:3a9487d57a5c 1 /* mbed Microcontroller Library
thedo 166:3a9487d57a5c 2 * Copyright (c) 2006-2013 ARM Limited
thedo 166:3a9487d57a5c 3 *
thedo 166:3a9487d57a5c 4 * Licensed under the Apache License, Version 2.0 (the "License");
thedo 166:3a9487d57a5c 5 * you may not use this file except in compliance with the License.
thedo 166:3a9487d57a5c 6 * You may obtain a copy of the License at
thedo 166:3a9487d57a5c 7 *
thedo 166:3a9487d57a5c 8 * http://www.apache.org/licenses/LICENSE-2.0
thedo 166:3a9487d57a5c 9 *
thedo 166:3a9487d57a5c 10 * Unless required by applicable law or agreed to in writing, software
thedo 166:3a9487d57a5c 11 * distributed under the License is distributed on an "AS IS" BASIS,
thedo 166:3a9487d57a5c 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
thedo 166:3a9487d57a5c 13 * See the License for the specific language governing permissions and
thedo 166:3a9487d57a5c 14 * limitations under the License.
thedo 166:3a9487d57a5c 15 */
thedo 166:3a9487d57a5c 16
thedo 166:3a9487d57a5c 17 #include "mbed.h"
thedo 166:3a9487d57a5c 18 #include "filesystem/FileSystem.h"
thedo 166:3a9487d57a5c 19 #include <errno.h>
thedo 166:3a9487d57a5c 20
thedo 166:3a9487d57a5c 21
thedo 166:3a9487d57a5c 22 FileSystem::FileSystem(const char *name)
thedo 166:3a9487d57a5c 23 : FileSystemLike(name)
thedo 166:3a9487d57a5c 24 {
thedo 166:3a9487d57a5c 25 }
thedo 166:3a9487d57a5c 26
thedo 166:3a9487d57a5c 27 int FileSystem::remove(const char *path)
thedo 166:3a9487d57a5c 28 {
thedo 166:3a9487d57a5c 29 return -ENOSYS;
thedo 166:3a9487d57a5c 30 }
thedo 166:3a9487d57a5c 31
thedo 166:3a9487d57a5c 32 int FileSystem::rename(const char *path, const char *newpath)
thedo 166:3a9487d57a5c 33 {
thedo 166:3a9487d57a5c 34 return -ENOSYS;
thedo 166:3a9487d57a5c 35 }
thedo 166:3a9487d57a5c 36
thedo 166:3a9487d57a5c 37 int FileSystem::stat(const char *path, struct stat *st)
thedo 166:3a9487d57a5c 38 {
thedo 166:3a9487d57a5c 39 return -ENOSYS;
thedo 166:3a9487d57a5c 40 }
thedo 166:3a9487d57a5c 41
thedo 166:3a9487d57a5c 42 int FileSystem::mkdir(const char *path, mode_t mode)
thedo 166:3a9487d57a5c 43 {
thedo 166:3a9487d57a5c 44 return -ENOSYS;
thedo 166:3a9487d57a5c 45 }
thedo 166:3a9487d57a5c 46
thedo 166:3a9487d57a5c 47 int FileSystem::file_sync(fs_file_t file)
thedo 166:3a9487d57a5c 48 {
thedo 166:3a9487d57a5c 49 return 0;
thedo 166:3a9487d57a5c 50 }
thedo 166:3a9487d57a5c 51
thedo 166:3a9487d57a5c 52 int FileSystem::file_isatty(fs_file_t file)
thedo 166:3a9487d57a5c 53 {
thedo 166:3a9487d57a5c 54 return false;
thedo 166:3a9487d57a5c 55 }
thedo 166:3a9487d57a5c 56
thedo 166:3a9487d57a5c 57 off_t FileSystem::file_tell(fs_file_t file)
thedo 166:3a9487d57a5c 58 {
thedo 166:3a9487d57a5c 59 return file_seek(file, 0, SEEK_CUR);
thedo 166:3a9487d57a5c 60 }
thedo 166:3a9487d57a5c 61
thedo 166:3a9487d57a5c 62 void FileSystem::file_rewind(fs_file_t file)
thedo 166:3a9487d57a5c 63 {
thedo 166:3a9487d57a5c 64 file_seek(file, 0, SEEK_SET);
thedo 166:3a9487d57a5c 65 }
thedo 166:3a9487d57a5c 66
thedo 166:3a9487d57a5c 67 off_t FileSystem::file_size(fs_file_t file)
thedo 166:3a9487d57a5c 68 {
thedo 166:3a9487d57a5c 69 off_t off = file_tell(file);
thedo 166:3a9487d57a5c 70 off_t size = file_seek(file, 0, SEEK_END);
thedo 166:3a9487d57a5c 71 file_seek(file, off, SEEK_SET);
thedo 166:3a9487d57a5c 72 return size;
thedo 166:3a9487d57a5c 73 }
thedo 166:3a9487d57a5c 74
thedo 166:3a9487d57a5c 75 int FileSystem::dir_open(fs_dir_t *dir, const char *path)
thedo 166:3a9487d57a5c 76 {
thedo 166:3a9487d57a5c 77 return -ENOSYS;
thedo 166:3a9487d57a5c 78 }
thedo 166:3a9487d57a5c 79
thedo 166:3a9487d57a5c 80 int FileSystem::dir_close(fs_dir_t dir)
thedo 166:3a9487d57a5c 81 {
thedo 166:3a9487d57a5c 82 return -ENOSYS;
thedo 166:3a9487d57a5c 83 }
thedo 166:3a9487d57a5c 84
thedo 166:3a9487d57a5c 85 ssize_t FileSystem::dir_read(fs_dir_t dir, struct dirent *ent)
thedo 166:3a9487d57a5c 86 {
thedo 166:3a9487d57a5c 87 return -ENOSYS;
thedo 166:3a9487d57a5c 88 }
thedo 166:3a9487d57a5c 89
thedo 166:3a9487d57a5c 90 void FileSystem::dir_seek(fs_dir_t dir, off_t offset)
thedo 166:3a9487d57a5c 91 {
thedo 166:3a9487d57a5c 92 }
thedo 166:3a9487d57a5c 93
thedo 166:3a9487d57a5c 94 off_t FileSystem::dir_tell(fs_dir_t dir)
thedo 166:3a9487d57a5c 95 {
thedo 166:3a9487d57a5c 96 return 0;
thedo 166:3a9487d57a5c 97 }
thedo 166:3a9487d57a5c 98
thedo 166:3a9487d57a5c 99 void FileSystem::dir_rewind(fs_dir_t dir)
thedo 166:3a9487d57a5c 100 {
thedo 166:3a9487d57a5c 101 // Note, the may not satisfy rewind on all filesystems
thedo 166:3a9487d57a5c 102 dir_seek(dir, 0);
thedo 166:3a9487d57a5c 103 }
thedo 166:3a9487d57a5c 104
thedo 166:3a9487d57a5c 105 size_t FileSystem::dir_size(fs_dir_t dir)
thedo 166:3a9487d57a5c 106 {
thedo 166:3a9487d57a5c 107 off_t off = dir_tell(dir);
thedo 166:3a9487d57a5c 108 size_t size = 0;
thedo 166:3a9487d57a5c 109 struct dirent *ent = new struct dirent;
thedo 166:3a9487d57a5c 110
thedo 166:3a9487d57a5c 111 dir_rewind(dir);
thedo 166:3a9487d57a5c 112 while (true) {
thedo 166:3a9487d57a5c 113 int res = dir_read(dir, ent);
thedo 166:3a9487d57a5c 114 if (res <= 0) {
thedo 166:3a9487d57a5c 115 break;
thedo 166:3a9487d57a5c 116 }
thedo 166:3a9487d57a5c 117
thedo 166:3a9487d57a5c 118 size += 1;
thedo 166:3a9487d57a5c 119 }
thedo 166:3a9487d57a5c 120 dir_seek(dir, off);
thedo 166:3a9487d57a5c 121
thedo 166:3a9487d57a5c 122 delete ent;
thedo 166:3a9487d57a5c 123 return size;
thedo 166:3a9487d57a5c 124 }
thedo 166:3a9487d57a5c 125
thedo 166:3a9487d57a5c 126 // Internally used file wrapper that manages memory on close
thedo 166:3a9487d57a5c 127 template <typename F>
thedo 166:3a9487d57a5c 128 class Managed : public F {
thedo 166:3a9487d57a5c 129 public:
thedo 166:3a9487d57a5c 130 virtual int close() {
thedo 166:3a9487d57a5c 131 int err = F::close();
thedo 166:3a9487d57a5c 132 delete this;
thedo 166:3a9487d57a5c 133 return err;
thedo 166:3a9487d57a5c 134 }
thedo 166:3a9487d57a5c 135 };
thedo 166:3a9487d57a5c 136
thedo 166:3a9487d57a5c 137 int FileSystem::open(FileHandle **file, const char *path, int flags)
thedo 166:3a9487d57a5c 138 {
thedo 166:3a9487d57a5c 139 File *f = new Managed<File>;
thedo 166:3a9487d57a5c 140 int err = f->open(this, path, flags);
thedo 166:3a9487d57a5c 141 if (err) {
thedo 166:3a9487d57a5c 142 delete f;
thedo 166:3a9487d57a5c 143 return err;
thedo 166:3a9487d57a5c 144 }
thedo 166:3a9487d57a5c 145
thedo 166:3a9487d57a5c 146 *file = f;
thedo 166:3a9487d57a5c 147 return 0;
thedo 166:3a9487d57a5c 148 }
thedo 166:3a9487d57a5c 149
thedo 166:3a9487d57a5c 150 int FileSystem::open(DirHandle **dir, const char *path) {
thedo 166:3a9487d57a5c 151 Dir *d = new Managed<Dir>;
thedo 166:3a9487d57a5c 152 int err = d->open(this, path);
thedo 166:3a9487d57a5c 153 if (err) {
thedo 166:3a9487d57a5c 154 delete d;
thedo 166:3a9487d57a5c 155 return err;
thedo 166:3a9487d57a5c 156 }
thedo 166:3a9487d57a5c 157
thedo 166:3a9487d57a5c 158 *dir = d;
thedo 166:3a9487d57a5c 159 return 0;
thedo 166:3a9487d57a5c 160 }
thedo 166:3a9487d57a5c 161