MASA-Core
NullBuffer.cpp
Go to the documentation of this file.
00001 /*******************************************************************************
00002  *
00003  * Copyright (c) 2010-2015   Edans Sandes
00004  *
00005  * This file is part of MASA-Core.
00006  * 
00007  * MASA-Core is free software: you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation, either version 3 of the License, or
00010  * (at your option) any later version.
00011  * 
00012  * MASA-Core is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with MASA-Core.  If not, see <http://www.gnu.org/licenses/>.
00019  *
00020  ******************************************************************************/
00021 
00022 #include "NullBuffer.hpp"
00023 
00024 #include <stdio.h>
00025 #include <string.h>
00026 
00027 NullBuffer::NullBuffer(int size) {
00028         if (size <= 0) {
00029                 this->size = 0x7FFFFFFF;
00030         } else {
00031                 this->size = size;
00032         }
00033 
00034 }
00035 
00036 NullBuffer::~NullBuffer() {
00037     Buffer::destroy();
00038     //Buffer::joinThreads();
00039 }
00040 
00041 void NullBuffer::initAutoFlush() {
00042 }
00043 
00044 void NullBuffer::initAutoLoad() {
00045 }
00046 
00047 void NullBuffer::autoFlushThread() {
00048         fprintf(stderr, "Flushing data to null buffer.\n");
00049     char data[512];
00050 
00051     int pos = 0;
00052     while (!isDestroyed()) {
00053         int len = readBuffer(data, 1, sizeof(data));
00054         pos += len;
00055     }
00056     fprintf(stderr, "End of flush data: %d bytes\n", pos);
00057 }
00058 
00059 void NullBuffer::autoLoadThread() {
00060     char data[512];
00061     memset(data, 0, sizeof(data));
00062     int pos = 0;
00063         fprintf(stderr, "Load data from null buffer.\n");
00064     while (!isDestroyed()) {
00065         int len = sizeof(data);
00066         if (pos+len < size) {
00067                 writeBuffer(data, 1, len);
00068                 pos += len;
00069         } else {
00070             writeBuffer(data, 1, size-pos);
00071             pos += size-pos;
00072             break;
00073         }
00074     }
00075     fprintf(stderr, "End of input Buffer: %d bytes\n", pos);
00076 }
00077 
00078 void NullBuffer::destroyAutoFlush() {
00079 }
00080 
00081 void NullBuffer::destroyAutoLoad() {
00082 }
00083 
00084 
00085