Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of OmniWheels by
FileHandle_stub.h
00001 /* 00002 * Copyright (c) , Arm Limited and affiliates. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 #ifndef __FILE_HANDLE_STUB_H__ 00018 #define __FILE_HANDLE_STUB_H__ 00019 00020 #include "FileHandle.h" 00021 00022 00023 namespace mbed { 00024 00025 static uint8_t filehandle_stub_short_value_counter = 0; 00026 static char *filehandle_stub_table = NULL; 00027 static uint8_t filehandle_stub_table_pos = 0; 00028 00029 class FileHandle_stub : public FileHandle 00030 { 00031 public: 00032 size_t size_value; 00033 00034 FileHandle_stub() {size_value = 0;} 00035 00036 virtual ssize_t read(void *buffer, size_t size){ 00037 if (filehandle_stub_table) { 00038 ssize_t ret = strlen(filehandle_stub_table) - filehandle_stub_table_pos; 00039 if (size < ret) { 00040 ret = size; 00041 } 00042 memcpy(buffer, filehandle_stub_table, ret); 00043 filehandle_stub_table_pos += ret; 00044 return ret; 00045 } 00046 return 0; 00047 } 00048 00049 virtual ssize_t write(const void *buffer, size_t size){ 00050 if( size_value ) { 00051 size_value--; 00052 return size; 00053 } 00054 return 0; 00055 } 00056 00057 virtual off_t seek(off_t offset, int whence = SEEK_SET){return 0;} 00058 00059 virtual int close(){} 00060 00061 virtual short poll(short events) const{ 00062 if (filehandle_stub_short_value_counter) { 00063 filehandle_stub_short_value_counter--; 00064 return short_value; 00065 } 00066 return 0; 00067 } 00068 00069 virtual void sigio(Callback<void()> func){func();} 00070 00071 short short_value; 00072 }; 00073 00074 } 00075 00076 #endif 00077 00078
Generated on Fri Jul 22 2022 04:53:49 by
1.7.2
