PacketModel.h

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 2005-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 #ifndef PACKETMODEL_H
00024 #define PACKETMODEL_H
00025 
00026 #include "Gnutella/Namespace.h"
00027 #include "Gnutella/Packets/Namespace.h"
00028 
00029 enum Packets {ping=0x00, pong=0x02, query=0x04, queryHit=0x08, queryRoutingReset=0x10, queryRoutingPatch=0x20,
00030               incomming=0x40, outgoing=0x80};
00031 Q_DECLARE_FLAGS(PacketFlags, Packets)
00032 Q_DECLARE_OPERATORS_FOR_FLAGS(PacketFlags)
00033 
00034 #define MAX_ITEMS_TO_HOLD 50
00035 
00036 using Gnutella::LocalPeer;
00037 using Gnutella::Packets::Packet;
00038 
00039 class PacketModel : public QAbstractTableModel
00040 {
00041     Q_OBJECT
00042 
00043 public:
00044     enum Direction
00045     {
00046         Incomming,
00047         Outgoing
00048     };
00049 
00050     PacketModel();
00051     ~PacketModel();
00052 
00053     int         rowCount (const QModelIndex &parent = QModelIndex()) const;
00054     int         columnCount (const QModelIndex &parent = QModelIndex()) const;
00055     QVariant    data (const QModelIndex &index, int role = Qt::DisplayRole) const;
00056     QVariant    headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
00057 
00058     bool        insertPacket (const Packet *packet, Direction direction);
00059     void        setFlags (PacketFlags &falgs);
00060 
00061 private:
00062 /*  struct PacketInfo
00063     {
00064 //      QTime       timestamp;
00065         QString     timestamp;
00066         Packet      *packet;
00067         Direction   direction;
00068     };
00069 */
00070     struct PacketInfo
00071     {
00072 //      QTime       timestamp;
00073         QString     timestamp;
00074         QString     packetName;
00075         uchar       packetTtl;
00076         uchar       packetHops;
00077         QString     packetDescriptorId;
00078         QString     packetRawPayload;
00079         Direction   direction;
00080 
00081         PacketInfo() : timestamp(), packetName(), packetTtl (0), packetHops (0),
00082                        packetDescriptorId(), packetRawPayload(),
00083                        direction (Incomming)
00084         {}
00085     };
00086 
00087     typedef QList <PacketInfo *> PacketList;
00088     PacketList  packetList;
00089 
00090     QIcon           inIcon;
00091     QIcon           outIcon;
00092     //QFile         logFile;
00093     //QTextStream       *log;
00094 public:
00095     PacketFlags     packetFlags;
00096     QMap<QString, int> flagValues;
00097 };
00098 
00099 #endif // _PACKETMODEL_H