Kind-of worked on the R-Tree; not really enough time to do much.
[aesalon.git] / src / monitor / ZoneReader.cpp
blob997ef2e6f71b70791fe5098a204bd94a5ceffa97
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
8 */
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"
17 namespace Monitor {
19 ZoneReader::ZoneReader(SHMReader *shmReader) : m_shmReader(shmReader) {
23 ZoneReader::~ZoneReader() {
27 void ZoneReader::run() {
28 run(this);
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();
48 while(true) {
49 reader->waitForPacket();
50 int32_t zone = reader->zoneWithData();
51 if(zone == -1) break;
53 SHM::PacketHeader *packetHeader;
54 broker.setupRequest(zone, sizeof(SHM::PacketHeader));
55 reader->processRequest(broker);
56 packetHeader = static_cast<SHM::PacketHeader *>(broker.data());
58 uint8_t *packetData;
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 MarshalWrapper *marshal = marshalList->marshal(packetHeader->moduleID);
70 if(marshal == NULL) doc->output(&packet);
71 else {
72 Comm::Packet *repacket = marshal->interface()->marshal(&packet);
73 if(repacket != NULL) doc->output(repacket);
77 Message(Debug, "Ending ZoneReader loop . . .");
79 return NULL;
82 } // namespace Monitor