Packet.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 "Packet.h"
00025 #include "BadPacket.h"
00026 #include "Imports.cpp"
00027 
00028 #if 0
00029 
00030 Packet::Packet()
00031     : packet (new BadPacket (QByteArray(), QByteArray(), QByteArray()))
00032 {
00033 }
00034 
00036 Packet::Packet (const PacketBase &p)
00037     : packet (p.copy())
00038 {
00039 }
00040 
00042 Packet::Packet (const Packet &p)
00043     : packet (p.packet->copy())
00044 {
00045 }
00046 
00048 Packet::~Packet()
00049 {
00050 }
00051 
00053 Packet & Packet::operator= (const Packet &other)
00054 {
00055     packet = other.packet->copy();
00056     return *this;
00057 }
00058 
00060 
00069 bool Packet::operator== (const Packet &other) const
00070 {
00071     return typeid (*packet) == typeid (*other.packet) &&
00072            packet->rawHeader() == other.packet->rawHeader() &&
00073            packet->rawPayload() == other.packet->rawPayload() &&
00074            packet->rawTrailer() == other.packet->rawTrailer();
00075 }
00076 
00078 QString Packet::protocol() const
00079 {
00080     return packet->protocol();
00081 }
00082 
00084 QString Packet::name() const
00085 {
00086     return packet->name();
00087 }
00088 
00090 Packet* Packet::copy() const
00091 {
00092     return new Packet (*this);
00093 }
00094 
00096 bool Packet::parse (const QByteArray &rawHeader,
00097                     const QByteArray &rawPayload,
00098                     const QByteArray &rawTrailer)
00099 {
00100     return packet->parse (rawHeader, rawPayload, rawTrailer);
00101 }
00102 
00104 QByteArray Packet::rawHeader() const
00105 {
00106     return packet->rawHeader();
00107 }
00108 
00110 QByteArray Packet::rawPayload() const
00111 {
00112     return packet->rawPayload();
00113 }
00114 
00116 QByteArray Packet::rawTrailer() const
00117 {
00118     return packet->rawTrailer();
00119 }
00120 
00121 PacketBase & Packet::object()
00122 {
00123     return *packet;
00124 }
00125 
00126 const PacketBase & Packet::object() const
00127 {
00128     return *packet;
00129 }
00130 #endif