Changeset View
Changeset View
Standalone View
Standalone View
plugins/process/network/helper/Accumulator.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * This file is part of KSysGuard. | ||||
3 | * Copyright 2019 Arjen Hiemstra <ahiemstra@heimr.nl> | ||||
4 | * | ||||
5 | * This program is free software; you can redistribute it and/or | ||||
6 | * modify it under the terms of the GNU General Public License as | ||||
7 | * published by the Free Software Foundation; either version 2 of | ||||
8 | * the License or (at your option) version 3 or any later version | ||||
9 | * accepted by the membership of KDE e.V. (or its successor approved | ||||
10 | * by the membership of KDE e.V.), which shall act as a proxy | ||||
11 | * defined in Section 14 of version 3 of the license. | ||||
12 | * | ||||
13 | * This program is distributed in the hope that it will be useful, | ||||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
16 | * GNU General Public License for more details. | ||||
17 | * | ||||
18 | * You should have received a copy of the GNU General Public License | ||||
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
20 | */ | ||||
21 | | ||||
22 | #ifndef ACCUMULATOR_H | ||||
23 | #define ACCUMULATOR_H | ||||
24 | | ||||
25 | #include <memory> | ||||
26 | #include <thread> | ||||
27 | #include <atomic> | ||||
28 | #include <unordered_map> | ||||
29 | | ||||
30 | #include "TimeStamps.h" | ||||
31 | #include "Packet.h" | ||||
32 | | ||||
33 | class Capture; | ||||
34 | class ConnectionMapping; | ||||
35 | class Packet; | ||||
36 | | ||||
37 | class Accumulator | ||||
38 | { | ||||
39 | | ||||
40 | public: | ||||
41 | using InboundOutboundData = std::pair<int, int>; | ||||
42 | using PidDataCounterHash = std::unordered_map<int, InboundOutboundData>; | ||||
43 | | ||||
44 | Accumulator(std::shared_ptr<Capture> capture, std::shared_ptr<ConnectionMapping> mapping); | ||||
45 | | ||||
46 | PidDataCounterHash data(); | ||||
47 | | ||||
48 | void stop(); | ||||
49 | | ||||
50 | private: | ||||
51 | void addData(Packet::Direction direction, const Packet &packet, int pid); | ||||
52 | void loop(); | ||||
53 | | ||||
54 | std::shared_ptr<Capture> m_capture; | ||||
55 | std::shared_ptr<ConnectionMapping> m_mapping; | ||||
56 | | ||||
57 | std::thread m_thread; | ||||
58 | std::atomic_bool m_running; | ||||
59 | | ||||
60 | PidDataCounterHash m_data; | ||||
61 | }; | ||||
62 | | ||||
63 | #endif // ACCUMULATOR_H |