PacketStub.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 "PacketStub.h"
00025 #include "Imports.cpp"
00026 
00028 
00039 PacketStub::PacketStub (const QByteArray &header,
00040                         const QByteArray &payload,
00041                         bool checkReadBytes)
00042     : PacketBase (new Data)
00043 {
00044     Q_SD (Data);
00045     d->header           = header;
00046     d->payload          = payload;
00047     d->checkReadBytes   = checkReadBytes;
00048 }
00049 
00050 QString PacketStub::name() const
00051 {
00052     return "PacketStub";
00053 }
00054 
00055 QString PacketStub::protocol() const
00056 {
00057     return "StubProtocol";
00058 }
00059 
00060 auto_ptr <DataBase> PacketStub::copy() const
00061 {
00062     return auto_ptr <DataBase> (new PacketStub (*this));
00063 }
00064 
00070 bool PacketStub::readHeader (const QByteArray &rawHeader)
00071 {
00072     Q_SD (Data);
00073     if (d->checkReadBytes)
00074         return d->header == rawHeader;
00075     d->header = rawHeader;
00076     return true;
00077 }
00078 
00085 bool PacketStub::readPayload (const QByteArray &rawPayload)
00086 {
00087     Q_SD (Data);
00088     if (d->checkReadBytes)
00089         return d->payload == rawPayload;
00090     d->payload = rawPayload;
00091     return true;
00092 }
00093 
00094 QByteArray PacketStub::writeHeader() const
00095 {
00096     Q_SD (const Data);
00097     return d->header;
00098 }
00099 
00100 QByteArray PacketStub::writePayload() const
00101 {
00102     Q_SD (const Data);
00103     return d->payload;
00104 }