TransportStub.cpp

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 2006-2007 by Peter Dimov.
00004 
00005 This file is part of Calitko (http://www.calitko.org).
00006 
00007 Calitko 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 2 of the License, or
00010 (at your option) any later version.
00011 
00012 Calitko 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 Calitko; if not, write to the Free Software
00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020 
00021 */
00022 
00023 #include "Qt.h"
00024 #include "TransportStub.h"
00025 #include "Imports.cpp"
00026 
00028 TransportStub::TransportStub()
00029  :  readBuffer(), writeBuffer(), status (0)
00030 {
00031 }
00032 
00034 void TransportStub::connectToNode (const Uri &)
00035 {
00036 }
00037 
00039 void TransportStub::disconnectFromNode()
00040 {
00041 }
00042 
00044 void TransportStub::abort()
00045 {
00046 }
00047 
00048 bool TransportStub::canRead (int count) const
00049 {
00050     return readBuffer.length() >= count;
00051 }
00052 
00053 QByteArray TransportStub::peek (int count) const
00054 {
00055     QByteArray bytes = readBuffer.left (count);
00056     return bytes;
00057 }
00058 
00059 QByteArray TransportStub::peekAtMost (int count) const
00060 {
00061     // left() will not return more bytes than already available:
00062     QByteArray bytes = readBuffer.left (count);
00063     return bytes;
00064 }
00065 
00066 QByteArray TransportStub::peekTo (const QByteArray &delimiter) const
00067 {
00068     QByteArray bytes = readBuffer.left (readBuffer.indexOf (delimiter)
00069                                         + delimiter.length());
00070     return bytes;
00071 }
00072 
00073 QByteArray TransportStub::peekAll() const
00074 {
00075     QByteArray bytes = readBuffer;
00076     return bytes;
00077 }
00078 
00079 QByteArray TransportStub::read (int count)
00080 {
00081     QByteArray bytes = peek (count);
00082     readBuffer = readBuffer.mid (bytes.length());
00083     return bytes;
00084 }
00085 
00086 QByteArray TransportStub::readAtMost (int count)
00087 {
00088     QByteArray bytes = peekAtMost (count);
00089     readBuffer = readBuffer.mid (bytes.length());
00090     return bytes;
00091 }
00092 
00093 QByteArray TransportStub::readTo (const QByteArray &delimiter)
00094 {
00095     QByteArray bytes = peekTo (delimiter);
00096     readBuffer = readBuffer.mid (bytes.length());
00097     return bytes;
00098 }
00099 
00100 QByteArray TransportStub::readAll()
00101 {
00102     QByteArray bytes = peekAll();
00103     readBuffer = QByteArray();
00104     return bytes;
00105 }
00106 
00107 bool TransportStub::canWrite (int count) const
00108 {
00109     return writeBuffer.capacity() - writeBuffer.size() >= count;
00110 }
00111 
00112 bool TransportStub::write (const QByteArray &bytes, bool)
00113 {
00114     writeBuffer += bytes;
00115     return true;
00116 }
00117 
00118 // NodeAddress TransportStub::ownNodeAddress() const
00119 // {
00120 //  return NodeAddress(); // \todo
00121 // }
00122 //
00123 // NodeAddress TransportStub::remoteNodeAddress() const
00124 // {
00125 //  return NodeAddress(); // \todo
00126 // }
00127 
00128 void TransportStub::setTransportStatus (TransportStatus *s)
00129 {
00130     status = s;
00131 }
00132 
00133 TransportStub::operator Transport *()
00134 {
00135     return this;
00136 }