BlockIO.cpp

Go to the documentation of this file.
00001 /****************** <VPR heading BEGIN do not edit this line> *****************
00002  *
00003  * VR Juggler Portable Runtime
00004  *
00005  * Original Authors:
00006  *   Allen Bierbaum, Patrick Hartling, Kevin Meinert, Carolina Cruz-Neira
00007  *
00008  * -----------------------------------------------------------------
00009  * File:          $RCSfile$
00010  * Date modified: $Date: 2005-05-16 15:23:48 -0500 (Mon, 16 May 2005) $
00011  * Version:       $Revision: 17503 $
00012  * -----------------------------------------------------------------
00013  *
00014  ****************** <VPR heading END do not edit this line> ******************/
00015 
00016 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
00017  *
00018  * VR Juggler is (C) Copyright 1998-2005 by Iowa State University
00019  *
00020  * Original Authors:
00021  *   Allen Bierbaum, Christopher Just,
00022  *   Patrick Hartling, Kevin Meinert,
00023  *   Carolina Cruz-Neira, Albert Baker
00024  *
00025  * This library is free software; you can redistribute it and/or
00026  * modify it under the terms of the GNU Library General Public
00027  * License as published by the Free Software Foundation; either
00028  * version 2 of the License, or (at your option) any later version.
00029  *
00030  * This library is distributed in the hope that it will be useful,
00031  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00032  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00033  * Library General Public License for more details.
00034  *
00035  * You should have received a copy of the GNU Library General Public
00036  * License along with this library; if not, write to the
00037  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00038  * Boston, MA 02111-1307, USA.
00039  *
00040  *************** <auto-copyright.pl END do not edit this line> ***************/
00041 
00042 #include <vpr/vprConfig.h>
00043 
00044 #include <vpr/IO/BlockIO.h>
00045 
00046 
00047 namespace vpr
00048 {
00049 
00050 bool BlockIO::isReadBlocked(const vpr::Interval& timeout)
00051 {
00052    bool is_blocked;
00053    vpr::Selector selector;
00054    vpr::IOSys::Handle handle;
00055    vpr::Uint16 num_events;
00056    vpr::ReturnStatus status;
00057 
00058    handle = getHandle();
00059    selector.addHandle(handle);
00060    selector.setIn(handle, vpr::Selector::Read);
00061 
00062    // Test the handle to get its read state.
00063    status = selector.select(num_events, timeout);
00064 
00065    if ( num_events == 1 )
00066    {
00067       is_blocked = false;
00068    }
00069    else
00070    {
00071       is_blocked = true;
00072    }
00073 
00074    return is_blocked;
00075 }
00076 
00077 bool BlockIO::isWriteBlocked(const vpr::Interval& timeout)
00078 {
00079    bool is_blocked;
00080    vpr::Selector selector;
00081    vpr::IOSys::Handle handle;
00082    vpr::Uint16 num_events;
00083    vpr::ReturnStatus status;
00084 
00085    handle = getHandle();
00086    selector.addHandle(handle);
00087    selector.setIn(handle, vpr::Selector::Write);
00088 
00089    // Test the handle to get its write state.
00090    status = selector.select(num_events, timeout);
00091 
00092    if ( num_events == 1 )
00093    {
00094       is_blocked = false;
00095    }
00096    else
00097    {
00098       is_blocked = true;
00099    }
00100 
00101    return is_blocked;
00102 }
00103 
00104 BlockIO::BlockIO()
00105    : mOpen(false)
00106    , mBlocking(true)
00107    , mStatsStrategy(NULL)
00108 {
00109    /* Do nothing. */ ;
00110 }
00111 
00112 BlockIO::BlockIO(const std::string& name)
00113    : mName(name)
00114    , mOpen(false)
00115    , mBlocking(true)
00116    , mStatsStrategy(NULL)
00117 {
00118    /* Do nothing. */ ;
00119 }
00120 
00121 BlockIO::BlockIO(const BlockIO& other)
00122    : mName(other.mName)
00123    , mOpen(other.mOpen)
00124    , mBlocking(other.mBlocking)
00125    , mStatsStrategy(NULL)
00126 {
00127    /* Do nothing. */ ;
00128 }
00129 
00130 BlockIO::~BlockIO()
00131 {
00132    /* Do nothing. */ ;
00133 }
00134 
00135 vpr::ReturnStatus BlockIO::read_s(void* buffer, const vpr::Uint32 length,
00136                                   vpr::Uint32& bytesRead,
00137                                   const vpr::Interval timeout)
00138 {
00139    vpr::ReturnStatus status;
00140 
00141    if(mStatsStrategy != NULL)
00142    {
00143       mStatsStrategy->read_s(status, buffer, length, bytesRead, timeout);
00144    }
00145    else
00146    {
00147       status = read_i(buffer, length, bytesRead, timeout);
00148    }
00149 
00150    return status;
00151 }
00152 
00153 vpr::ReturnStatus BlockIO::readn_s(void* buffer, const vpr::Uint32 length,
00154                                    vpr::Uint32& bytesRead,
00155                                    const vpr::Interval timeout)
00156 {
00157    vpr::ReturnStatus status;
00158 
00159    if(mStatsStrategy != NULL)
00160    {
00161       mStatsStrategy->readn_s(status, buffer, length, bytesRead, timeout);
00162    }
00163    else
00164    {
00165       status = readn_i(buffer, length, bytesRead, timeout);
00166    }
00167 
00168    return status;
00169 }
00170 
00171 vpr::ReturnStatus BlockIO::write_s(const void* buffer,
00172                                    const vpr::Uint32 length,
00173                                    vpr::Uint32& bytesWritten,
00174                                    const vpr::Interval timeout)
00175 {
00176    vpr::ReturnStatus status;
00177 
00178    if(mStatsStrategy != NULL)
00179    {
00180       mStatsStrategy->write_s(status, buffer, length, bytesWritten,
00181                               timeout);
00182    }
00183    else
00184    {
00185        status = write_i(buffer, length, bytesWritten, timeout);
00186    }
00187 
00188    return status;
00189 }
00190 
00191 }

Generated on Thu Jan 4 10:52:09 2007 for VR Juggler Portable Runtime by  doxygen 1.5.1