aboutsummaryrefslogtreecommitdiffstats
path: root/ui/qt/models/expert_info_model.h
blob: 471cd6700ab1928ee9c2bf4454891cf175b9d454 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/* expert_info_model.h
 * Data model for Expert Info tap data.
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0+
 */

#ifndef EXPERT_INFO_MODEL_H
#define EXPERT_INFO_MODEL_H

#include <config.h>

#include <QAbstractItemModel>
#include <QList>
#include <QMap>

#include <ui/qt/capture_file.h>

#include <epan/expert.h>
#include <epan/column-utils.h>

class ExpertPacketItem
{
public:
    ExpertPacketItem(expert_info_t& expert_info, column_info *cinfo, ExpertPacketItem* parent);
    virtual ~ExpertPacketItem();

    unsigned int packetNum() const { return packet_num_; }
    int group() const { return group_; }
    int severity() const { return severity_; }
    int hfId() const { return hf_id_; }
    QString protocol() const { return protocol_; }
    QString summary() const { return summary_; }
    QString colInfo() const { return info_; }

    static QString groupKey(bool group_by_summary, int severity, int group, QString protocol, int expert_hf);
    QString groupKey(bool group_by_summary);

    void appendChild(ExpertPacketItem* child, QString hash);
    ExpertPacketItem* child(int row);
    ExpertPacketItem* child(QString hash);
    int childCount() const;
    int row() const;
    ExpertPacketItem* parentItem();

private:
    unsigned int packet_num_;
    int group_;
    int severity_;
    int hf_id_;
    // Half-hearted attempt at conserving memory. If this isn't sufficient,
    // PacketListRecord interns column strings in a GStringChunk.
    QByteArray protocol_;
    QByteArray summary_;
    QByteArray info_;

    QList<ExpertPacketItem*> childItems_;
    ExpertPacketItem* parentItem_;
    QHash<QString, ExpertPacketItem*> hashChild_;    //optimization for insertion
};

class ExpertInfoModel : public QAbstractItemModel
{
    Q_OBJECT

public:
    ExpertInfoModel(CaptureFile& capture_file, QObject *parent = 0);

    enum ExpertColumn {
        colSeverity = 0,
        colSummary,
        colGroup,
        colProtocol,
        colCount,
        colPacket,
        colHf,
        colLast
    };

    enum ExpertSeverity {
        severityError = PI_ERROR,
        severityWarn = PI_WARN,
        severityNote = PI_NOTE,
        severityChat = PI_CHAT,
        severityComment = PI_COMMENT
    };

    QModelIndex index(int row, int column,
                      const QModelIndex & = QModelIndex()) const;
    QModelIndex parent(const QModelIndex &) const;
#if 0
    Qt::ItemFlags flags(const QModelIndex &index) const;
#endif
    QVariant data(const QModelIndex &index, int role) const;

    int rowCount(const QModelIndex &parent = QModelIndex()) const;
    int columnCount(const QModelIndex &parent = QModelIndex()) const;

    int numEvents(enum ExpertSeverity severity);

    void clear();

    //GUI helpers
    void setGroupBySummary(bool group_by_summary);

    // Called from tapPacket
    void addExpertInfo(struct expert_info_s& expert_info);

    // Callbacks for register_tap_listener
    static void tapReset(void *eid_ptr);
    static gboolean tapPacket(void *eid_ptr, struct _packet_info *pinfo, struct epan_dissect *, const void *data);
    static void tapDraw(void *eid_ptr);

private:
    CaptureFile& capture_file_;

    ExpertPacketItem* createRootItem();

    bool group_by_summary_;
    ExpertPacketItem* root_;

    QHash<enum ExpertSeverity, int> eventCounts_;
};
#endif // EXPERT_INFO_MODEL_H

/*
 * Editor modelines
 *
 * Local Variables:
 * c-basic-offset: 4
 * tab-width: 8
 * indent-tabs-mode: nil
 * End:
 *
 * ex: set shiftwidth=4 tabstop=8 expandtab:
 * :indentSize=4:tabSize=8:noTabs=true:
 */