Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

funneldevice.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002     funneldevice.cpp  -  Definitions of the FunnelDevice class methods.
00003                              -------------------
00004     begin                : June 21 2002
00005     copyright            : (C) 2003 by Vojtìch Toman
00006     email                : vtoman@lit.cz
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00026 #ifdef __GNUG__
00027 # pragma implementation
00028 #endif
00029 
00030 #include "funneldevice.h"
00031 
00032 
00033 
00034 
00044 FunnelDevice::FunnelDevice(UserOfFunnelDevice *rcvr, bool isImmediate = false, size_t size = DEFAULT_FUNNEL_BUFFER_SIZE)
00045   : IODevice()
00046 {
00047   receiver = rcvr;
00048 
00049   bufferSize = size;
00050   buffer = 0;
00051 
00052   immediate = isImmediate;
00053 
00054   bw = 0;
00055 
00056   //device is "empty"
00057   dataLength = 0;
00058   dataPresent = false;
00059 }
00060 
00061 
00065 FunnelDevice::~FunnelDevice(void)
00066 {
00067   if (buffer)
00068     DELETE_ARRAY(buffer);
00069 }
00070 
00074 void FunnelDevice::prepare(void) throw (ExaltIOException)
00075 {
00076   NEW(buffer, XmlChar[bufferSize]);
00077 
00078   dataLength = 0;
00079 }
00080 
00084 void FunnelDevice::flush(void) throw (ExaltIOException)
00085 {
00086   if (dataPresent)
00087     {
00088       try
00089         {
00090           receiver->receiveData(buffer, dataLength);
00091         }
00092       catch (ExaltException)
00093         {
00094           throw ExaltIOException();
00095         }
00096       
00097       //buffer is now empty
00098       dataLength = 0;
00099       dataPresent = false;
00100     }
00101 }
00102 
00103 
00107 void FunnelDevice::finish(void) throw (ExaltIOException)
00108 {
00109   flush();
00110 
00111   //buffer is empty
00112   dataLength = 0;
00113   dataPresent = false;
00114   bw = 0;
00115 }
00116 
00117 
00126 IOState FunnelDevice::readData(char *buf, IOSize length) throw (ExaltIOException)
00127 {
00128   return ReadOk;
00129 }
00130 
00138 IOState FunnelDevice::getChar(int *c) throw (ExaltIOException)
00139 {
00140   *c = 0;
00141   return ReadOk;
00142 }
00143 
00152 IOState FunnelDevice::writeData(const char *buf, IOSize length) throw (ExaltIOException)
00153 {
00154   bw += length;
00155 
00156   if (!buffer)
00157     {
00158       throw ExaltDeviceNotPreparedIOException();
00159       return WriteError;
00160     }
00161 
00162   if (length + dataLength > bufferSize)
00163     {
00164       throw ExaltDeviceFullIOException();
00165       return WriteError;
00166     }
00167 
00168   for (size_t i = 0; i < length; i++)
00169     {
00170       buffer[dataLength + i] = ((XmlChar *)buf)[i];
00171     }
00172 
00173   if (length)
00174     dataPresent = true;
00175   else
00176     dataPresent = false;
00177 
00178   dataLength += length;
00179 
00180   if (immediate)
00181     flush();
00182 
00183   return WriteOk;
00184 }
00185 
00186 
00194 IOState FunnelDevice::putChar(int c) throw (ExaltIOException)
00195 {
00196   bw++;
00197 
00198   if (!buffer)
00199     {
00200       throw ExaltDeviceNotPreparedIOException();
00201       return WriteError;
00202     }
00203 
00204   if (dataLength >= bufferSize)
00205     {
00206       throw ExaltDeviceFullIOException();
00207       return WriteError;
00208     }
00209 
00210 
00211   buffer[dataLength] = (XmlChar)c;
00212   dataPresent = true;
00213   dataLength++;
00214 
00215 
00216   if (immediate)
00217     flush();
00218 
00219 
00220   return ReadOk;
00221 }
00222 
00228 IOSize FunnelDevice::bytesReadTotal(void)
00229 {
00230   return 0;
00231 }
00232 
00238 IOSize FunnelDevice::bytesRead(void)
00239 {
00240   return 0;
00241 }
00242 
00248 IOSize FunnelDevice::bytesWritten(void)
00249 {
00250   return bw;
00251 }
00252 
00258 bool FunnelDevice::errorOccurred(void)
00259 {
00260   return false;
00261 }
00262 
00268 bool FunnelDevice::eof(void)
00269 {
00270   return false;
00271 }
00272 

Generated on Wed Feb 5 10:43:01 2003 for Exalt by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002