lib

Fork of mbed-dev by mbed official

Committer:
<>
Date:
Fri Oct 28 11:17:30 2016 +0100
Revision:
149:156823d33999
This updates the lib to the mbed lib v128

NOTE: This release includes a restructuring of the file and directory locations and thus some
include paths in your code may need updating accordingly.

Who changed what in which revision?

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