I am beginning to question the need for a marshaller.
[aesalon.git] / src / monitor / ZoneReader.cpp
blob58dc41ba0886972223ab8b89e0582a3e595f54b0
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"
14 namespace Monitor {
16 ZoneReader::ZoneReader(SHMReader *shmReader) : m_shmReader(shmReader) {
20 ZoneReader::~ZoneReader() {
24 void ZoneReader::run() {
25 run(this);
28 void ZoneReader::start() {
29 pthread_create(&m_threadID, NULL, run, this);
32 void ZoneReader::wait() {
33 pthread_join(m_threadID, NULL);
36 void *ZoneReader::run(void *voidInstance) {
37 Message(Debug, "Beginning ZoneReader loop . . .");
38 ZoneReader *instance = static_cast<ZoneReader *>(voidInstance);
39 SHMReader *reader = instance->m_shmReader;
40 SHMReader::ReadBroker broker;
42 while(true) {
43 reader->waitForPacket();
44 int32_t zone = reader->zoneWithData();
45 if(zone == -1) break;
47 SHM::PacketHeader *packetHeader;
48 broker.setupRequest(zone, sizeof(SHM::PacketHeader));
49 reader->processRequest(broker);
50 packetHeader = static_cast<SHM::PacketHeader *>(broker.data());
52 uint8_t *packetData;
53 broker.setupRequest(zone, packetHeader->packetSize);
54 reader->processRequest(broker);
55 packetData = static_cast<uint8_t *>(broker.data());
57 Message(Log, "Recieved packet from module " << packetHeader->moduleID << ", size " << packetHeader->packetSize);
62 Message(Debug, "Ending ZoneReader loop . . .");
64 return NULL;
67 } // namespace Monitor