mbed library sources. Supersedes mbed-src.

Fork of mbed-dev by mbed official

Committer:
<>
Date:
Fri Sep 02 15:07:44 2016 +0100
Revision:
144:ef7eb2e8f9f7
Parent:
0:9b334a45a8ff
This updates the lib to the mbed lib v125

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 144:ef7eb2e8f9f7 1 /* mbed Microcontroller Library
<> 144:ef7eb2e8f9f7 2 * Copyright (c) 2006-2013 ARM Limited
<> 144:ef7eb2e8f9f7 3 *
<> 144:ef7eb2e8f9f7 4 * Licensed under the Apache License, Version 2.0 (the "License");
<> 144:ef7eb2e8f9f7 5 * you may not use this file except in compliance with the License.
<> 144:ef7eb2e8f9f7 6 * You may obtain a copy of the License at
<> 144:ef7eb2e8f9f7 7 *
<> 144:ef7eb2e8f9f7 8 * http://www.apache.org/licenses/LICENSE-2.0
<> 144:ef7eb2e8f9f7 9 *
<> 144:ef7eb2e8f9f7 10 * Unless required by applicable law or agreed to in writing, software
<> 144:ef7eb2e8f9f7 11 * distributed under the License is distributed on an "AS IS" BASIS,
<> 144:ef7eb2e8f9f7 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<> 144:ef7eb2e8f9f7 13 * See the License for the specific language governing permissions and
<> 144:ef7eb2e8f9f7 14 * limitations under the License.
<> 144:ef7eb2e8f9f7 15 */
<> 144:ef7eb2e8f9f7 16 #include "FileBase.h"
<> 144:ef7eb2e8f9f7 17
<> 144:ef7eb2e8f9f7 18 namespace mbed {
<> 144:ef7eb2e8f9f7 19
<> 144:ef7eb2e8f9f7 20 FileBase *FileBase::_head = NULL;
<> 144:ef7eb2e8f9f7 21 SingletonPtr<PlatformMutex> FileBase::_mutex;
<> 144:ef7eb2e8f9f7 22
<> 144:ef7eb2e8f9f7 23 FileBase::FileBase(const char *name, PathType t) : _next(NULL),
<> 144:ef7eb2e8f9f7 24 _name(name),
<> 144:ef7eb2e8f9f7 25 _path_type(t) {
<> 144:ef7eb2e8f9f7 26 _mutex->lock();
<> 144:ef7eb2e8f9f7 27 if (name != NULL) {
<> 144:ef7eb2e8f9f7 28 // put this object at head of the list
<> 144:ef7eb2e8f9f7 29 _next = _head;
<> 144:ef7eb2e8f9f7 30 _head = this;
<> 144:ef7eb2e8f9f7 31 } else {
<> 144:ef7eb2e8f9f7 32 _next = NULL;
<> 144:ef7eb2e8f9f7 33 }
<> 144:ef7eb2e8f9f7 34 _mutex->unlock();
<> 144:ef7eb2e8f9f7 35 }
<> 144:ef7eb2e8f9f7 36
<> 144:ef7eb2e8f9f7 37 FileBase::~FileBase() {
<> 144:ef7eb2e8f9f7 38 _mutex->lock();
<> 144:ef7eb2e8f9f7 39 if (_name != NULL) {
<> 144:ef7eb2e8f9f7 40 // remove this object from the list
<> 144:ef7eb2e8f9f7 41 if (_head == this) { // first in the list, so just drop me
<> 144:ef7eb2e8f9f7 42 _head = _next;
<> 144:ef7eb2e8f9f7 43 } else { // find the object before me, then drop me
<> 144:ef7eb2e8f9f7 44 FileBase *p = _head;
<> 144:ef7eb2e8f9f7 45 while (p->_next != this) {
<> 144:ef7eb2e8f9f7 46 p = p->_next;
<> 144:ef7eb2e8f9f7 47 }
<> 144:ef7eb2e8f9f7 48 p->_next = _next;
<> 144:ef7eb2e8f9f7 49 }
<> 144:ef7eb2e8f9f7 50 }
<> 144:ef7eb2e8f9f7 51 _mutex->unlock();
<> 144:ef7eb2e8f9f7 52 }
<> 144:ef7eb2e8f9f7 53
<> 144:ef7eb2e8f9f7 54 FileBase *FileBase::lookup(const char *name, unsigned int len) {
<> 144:ef7eb2e8f9f7 55 _mutex->lock();
<> 144:ef7eb2e8f9f7 56 FileBase *p = _head;
<> 144:ef7eb2e8f9f7 57 while (p != NULL) {
<> 144:ef7eb2e8f9f7 58 /* Check that p->_name matches name and is the correct length */
<> 144:ef7eb2e8f9f7 59 if (p->_name != NULL && std::strncmp(p->_name, name, len) == 0 && std::strlen(p->_name) == len) {
<> 144:ef7eb2e8f9f7 60 _mutex->unlock();
<> 144:ef7eb2e8f9f7 61 return p;
<> 144:ef7eb2e8f9f7 62 }
<> 144:ef7eb2e8f9f7 63 p = p->_next;
<> 144:ef7eb2e8f9f7 64 }
<> 144:ef7eb2e8f9f7 65 _mutex->unlock();
<> 144:ef7eb2e8f9f7 66 return NULL;
<> 144:ef7eb2e8f9f7 67 }
<> 144:ef7eb2e8f9f7 68
<> 144:ef7eb2e8f9f7 69 FileBase *FileBase::get(int n) {
<> 144:ef7eb2e8f9f7 70 _mutex->lock();
<> 144:ef7eb2e8f9f7 71 FileBase *p = _head;
<> 144:ef7eb2e8f9f7 72 int m = 0;
<> 144:ef7eb2e8f9f7 73 while (p != NULL) {
<> 144:ef7eb2e8f9f7 74 if (m == n) {
<> 144:ef7eb2e8f9f7 75 _mutex->unlock();
<> 144:ef7eb2e8f9f7 76 return p;
<> 144:ef7eb2e8f9f7 77 }
<> 144:ef7eb2e8f9f7 78
<> 144:ef7eb2e8f9f7 79 m++;
<> 144:ef7eb2e8f9f7 80 p = p->_next;
<> 144:ef7eb2e8f9f7 81 }
<> 144:ef7eb2e8f9f7 82 _mutex->unlock();
<> 144:ef7eb2e8f9f7 83 return NULL;
<> 144:ef7eb2e8f9f7 84 }
<> 144:ef7eb2e8f9f7 85
<> 144:ef7eb2e8f9f7 86 const char* FileBase::getName(void) {
<> 144:ef7eb2e8f9f7 87 // Constant read so no lock needed
<> 144:ef7eb2e8f9f7 88 return _name;
<> 144:ef7eb2e8f9f7 89 }
<> 144:ef7eb2e8f9f7 90
<> 144:ef7eb2e8f9f7 91 PathType FileBase::getPathType(void) {
<> 144:ef7eb2e8f9f7 92 // Constant read so no lock needed
<> 144:ef7eb2e8f9f7 93 return _path_type;
<> 144:ef7eb2e8f9f7 94 }
<> 144:ef7eb2e8f9f7 95
<> 144:ef7eb2e8f9f7 96 } // namespace mbed
<> 144:ef7eb2e8f9f7 97