1 /** Aesalon, a tool to visualize program behaviour in real time.
2 Copyright (C) 2009-2011, Aesalon development team.
4 Aesalon is distributed under the terms of the GNU GPLv3. See
5 the included file LICENSE for more information.
7 @file src/monitor/ZoneReader.cpp
10 #include "monitor/ZoneReader.h"
11 #include "shm/PacketHeader.h"
12 #include "util/MessageSystem.h"
13 #include "comm/Packet.h"
14 #include "monitor/Coordinator.h"
15 #include "monitor/MarshalList.h"
19 ZoneReader::ZoneReader(SHMReader
*shmReader
) : m_shmReader(shmReader
) {
23 ZoneReader::~ZoneReader() {
27 void ZoneReader::run() {
31 void ZoneReader::start() {
32 pthread_create(&m_threadID
, NULL
, run
, this);
35 void ZoneReader::wait() {
36 pthread_join(m_threadID
, NULL
);
39 void *ZoneReader::run(void *voidInstance
) {
40 Message(Debug
, "Beginning ZoneReader loop . . .");
41 ZoneReader
*instance
= static_cast<ZoneReader
*>(voidInstance
);
42 SHMReader
*reader
= instance
->m_shmReader
;
43 SHMReader::ReadBroker broker
;
45 MarshalList
*marshalList
= Coordinator::instance()->marshalList();
46 DataOutputController
*doc
= Coordinator::instance()->dataOutputController();
49 reader
->waitForPacket();
50 int32_t zone
= reader
->zoneWithData();
53 SHM::PacketHeader
*packetHeader
;
54 broker
.setupRequest(zone
, sizeof(SHM::PacketHeader
));
55 reader
->processRequest(broker
);
56 packetHeader
= static_cast<SHM::PacketHeader
*>(broker
.data());
59 broker
.setupRequest(zone
, packetHeader
->packetSize
);
60 reader
->processRequest(broker
);
61 packetData
= static_cast<uint8_t *>(broker
.data());
63 Message(Log
, "Recieved packet from module " << packetHeader
->moduleID
<< ", size " << packetHeader
->packetSize
);
65 Comm::Packet
packet(Comm::PacketHeader(packetHeader
->moduleID
, reader
->zoneProcessID(zone
),
66 reader
->zoneThreadID(zone
), packetHeader
->packetSize
), packetData
);
68 Marshal
*marshal
= marshalList
->marshal(packetHeader
->moduleID
);
70 if(marshal
== NULL
) doc
->output(&packet
);
72 Comm::Packet
*repacket
= marshal
->interface()->marshal(&packet
);
73 if(repacket
!= NULL
) doc
->output(repacket
);
77 Message(Debug
, "Ending ZoneReader loop . . .");
82 } // namespace Monitor