mbed library sources, mbed-dev only for TYBLE16
Fork of mbed-dev by
Please refer flowing link.
/users/kenjiArai/notebook/tyble16-module-will-become-a-mbed-family--mbedliza/
platform/FileBase.cpp@182:976b131d2800, 2018-02-25 (annotated)
- Committer:
- kenjiArai
- Date:
- Sun Feb 25 02:00:51 2018 +0000
- Revision:
- 182:976b131d2800
- Parent:
- 167:e84263d55307
Only for TYBLE16
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AnnaBridge | 167:e84263d55307 | 1 | /* mbed Microcontroller Library |
AnnaBridge | 167:e84263d55307 | 2 | * Copyright (c) 2006-2013 ARM Limited |
AnnaBridge | 167:e84263d55307 | 3 | * |
AnnaBridge | 167:e84263d55307 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
AnnaBridge | 167:e84263d55307 | 5 | * you may not use this file except in compliance with the License. |
AnnaBridge | 167:e84263d55307 | 6 | * You may obtain a copy of the License at |
AnnaBridge | 167:e84263d55307 | 7 | * |
AnnaBridge | 167:e84263d55307 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
AnnaBridge | 167:e84263d55307 | 9 | * |
AnnaBridge | 167:e84263d55307 | 10 | * Unless required by applicable law or agreed to in writing, software |
AnnaBridge | 167:e84263d55307 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
AnnaBridge | 167:e84263d55307 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
AnnaBridge | 167:e84263d55307 | 13 | * See the License for the specific language governing permissions and |
AnnaBridge | 167:e84263d55307 | 14 | * limitations under the License. |
AnnaBridge | 167:e84263d55307 | 15 | */ |
AnnaBridge | 167:e84263d55307 | 16 | #include "platform/FileBase.h" |
AnnaBridge | 167:e84263d55307 | 17 | #include "platform/FileLike.h" |
AnnaBridge | 167:e84263d55307 | 18 | #include "platform/FileHandle.h" |
AnnaBridge | 167:e84263d55307 | 19 | |
AnnaBridge | 167:e84263d55307 | 20 | namespace mbed { |
AnnaBridge | 167:e84263d55307 | 21 | |
AnnaBridge | 167:e84263d55307 | 22 | FileBase *FileBase::_head = NULL; |
AnnaBridge | 167:e84263d55307 | 23 | SingletonPtr<PlatformMutex> FileBase::_mutex; |
AnnaBridge | 167:e84263d55307 | 24 | |
AnnaBridge | 167:e84263d55307 | 25 | FileBase::FileBase(const char *name, PathType t) : _next(NULL), |
AnnaBridge | 167:e84263d55307 | 26 | _name(name), |
AnnaBridge | 167:e84263d55307 | 27 | _path_type(t) { |
AnnaBridge | 167:e84263d55307 | 28 | _mutex->lock(); |
AnnaBridge | 167:e84263d55307 | 29 | if (name != NULL) { |
AnnaBridge | 167:e84263d55307 | 30 | // put this object at head of the list |
AnnaBridge | 167:e84263d55307 | 31 | _next = _head; |
AnnaBridge | 167:e84263d55307 | 32 | _head = this; |
AnnaBridge | 167:e84263d55307 | 33 | } else { |
AnnaBridge | 167:e84263d55307 | 34 | _next = NULL; |
AnnaBridge | 167:e84263d55307 | 35 | } |
AnnaBridge | 167:e84263d55307 | 36 | _mutex->unlock(); |
AnnaBridge | 167:e84263d55307 | 37 | } |
AnnaBridge | 167:e84263d55307 | 38 | |
AnnaBridge | 167:e84263d55307 | 39 | FileBase::~FileBase() { |
AnnaBridge | 167:e84263d55307 | 40 | _mutex->lock(); |
AnnaBridge | 167:e84263d55307 | 41 | if (_name != NULL) { |
AnnaBridge | 167:e84263d55307 | 42 | // remove this object from the list |
AnnaBridge | 167:e84263d55307 | 43 | if (_head == this) { // first in the list, so just drop me |
AnnaBridge | 167:e84263d55307 | 44 | _head = _next; |
AnnaBridge | 167:e84263d55307 | 45 | } else { // find the object before me, then drop me |
AnnaBridge | 167:e84263d55307 | 46 | FileBase *p = _head; |
AnnaBridge | 167:e84263d55307 | 47 | while (p->_next != this) { |
AnnaBridge | 167:e84263d55307 | 48 | p = p->_next; |
AnnaBridge | 167:e84263d55307 | 49 | } |
AnnaBridge | 167:e84263d55307 | 50 | p->_next = _next; |
AnnaBridge | 167:e84263d55307 | 51 | } |
AnnaBridge | 167:e84263d55307 | 52 | } |
AnnaBridge | 167:e84263d55307 | 53 | _mutex->unlock(); |
AnnaBridge | 167:e84263d55307 | 54 | |
AnnaBridge | 167:e84263d55307 | 55 | if (getPathType() == FilePathType) { |
AnnaBridge | 167:e84263d55307 | 56 | extern void remove_filehandle(FileHandle *file); |
AnnaBridge | 167:e84263d55307 | 57 | remove_filehandle(static_cast<FileHandle*>(static_cast<FileLike*>(this))); |
AnnaBridge | 167:e84263d55307 | 58 | } |
AnnaBridge | 167:e84263d55307 | 59 | } |
AnnaBridge | 167:e84263d55307 | 60 | |
AnnaBridge | 167:e84263d55307 | 61 | FileBase *FileBase::lookup(const char *name, unsigned int len) { |
AnnaBridge | 167:e84263d55307 | 62 | _mutex->lock(); |
AnnaBridge | 167:e84263d55307 | 63 | FileBase *p = _head; |
AnnaBridge | 167:e84263d55307 | 64 | while (p != NULL) { |
AnnaBridge | 167:e84263d55307 | 65 | /* Check that p->_name matches name and is the correct length */ |
AnnaBridge | 167:e84263d55307 | 66 | if (p->_name != NULL && std::strncmp(p->_name, name, len) == 0 && std::strlen(p->_name) == len) { |
AnnaBridge | 167:e84263d55307 | 67 | _mutex->unlock(); |
AnnaBridge | 167:e84263d55307 | 68 | return p; |
AnnaBridge | 167:e84263d55307 | 69 | } |
AnnaBridge | 167:e84263d55307 | 70 | p = p->_next; |
AnnaBridge | 167:e84263d55307 | 71 | } |
AnnaBridge | 167:e84263d55307 | 72 | _mutex->unlock(); |
AnnaBridge | 167:e84263d55307 | 73 | return NULL; |
AnnaBridge | 167:e84263d55307 | 74 | } |
AnnaBridge | 167:e84263d55307 | 75 | |
AnnaBridge | 167:e84263d55307 | 76 | FileBase *FileBase::get(int n) { |
AnnaBridge | 167:e84263d55307 | 77 | _mutex->lock(); |
AnnaBridge | 167:e84263d55307 | 78 | FileBase *p = _head; |
AnnaBridge | 167:e84263d55307 | 79 | int m = 0; |
AnnaBridge | 167:e84263d55307 | 80 | while (p != NULL) { |
AnnaBridge | 167:e84263d55307 | 81 | if (m == n) { |
AnnaBridge | 167:e84263d55307 | 82 | _mutex->unlock(); |
AnnaBridge | 167:e84263d55307 | 83 | return p; |
AnnaBridge | 167:e84263d55307 | 84 | } |
AnnaBridge | 167:e84263d55307 | 85 | |
AnnaBridge | 167:e84263d55307 | 86 | m++; |
AnnaBridge | 167:e84263d55307 | 87 | p = p->_next; |
AnnaBridge | 167:e84263d55307 | 88 | } |
AnnaBridge | 167:e84263d55307 | 89 | _mutex->unlock(); |
AnnaBridge | 167:e84263d55307 | 90 | return NULL; |
AnnaBridge | 167:e84263d55307 | 91 | } |
AnnaBridge | 167:e84263d55307 | 92 | |
AnnaBridge | 167:e84263d55307 | 93 | const char* FileBase::getName(void) { |
AnnaBridge | 167:e84263d55307 | 94 | // Constant read so no lock needed |
AnnaBridge | 167:e84263d55307 | 95 | return _name; |
AnnaBridge | 167:e84263d55307 | 96 | } |
AnnaBridge | 167:e84263d55307 | 97 | |
AnnaBridge | 167:e84263d55307 | 98 | PathType FileBase::getPathType(void) { |
AnnaBridge | 167:e84263d55307 | 99 | // Constant read so no lock needed |
AnnaBridge | 167:e84263d55307 | 100 | return _path_type; |
AnnaBridge | 167:e84263d55307 | 101 | } |
AnnaBridge | 167:e84263d55307 | 102 | |
AnnaBridge | 167:e84263d55307 | 103 | } // namespace mbed |
AnnaBridge | 167:e84263d55307 | 104 |