Documented GViewport a small amount, fixed a translation bug in BasicViewport.
[aesalon.git] / src / visualizer / DataInput.cpp
blobc76c8ea0620520405fe78681893352bfe28009c6
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/visualizer/DataInput.cpp
8 */
10 #include "visualizer/DataInput.h"
11 #include "comm/Packet.h"
12 #include "util/MessageSystem.h"
13 #include "informer/PacketFormat.h"
14 #include "visualizer/PIDAllocator.h"
16 namespace Visualizer {
18 DataInput::DataInput(ArtisanManager *artisanManager) : m_artisanManager(artisanManager) {
22 void DataInput::addData(QByteArray data) {
23 Message(Debug, "Data added . . .");
24 m_unprocessed += data;
26 while(m_unprocessed.size() >= int(sizeof(Comm::PacketHeader))) {
27 Comm::PacketHeader *header = reinterpret_cast<Comm::PacketHeader *>(m_unprocessed.data());
28 if(m_unprocessed.size() < int(sizeof(Comm::PacketHeader) + header->dataSize)) break;
30 Comm::Packet packet(
31 Comm::PacketHeader(
32 header->moduleID, m_processIDMap[header->processID], header->threadID, header->dataSize),
33 reinterpret_cast<uint8_t *>(m_unprocessed.data()) + sizeof(Comm::PacketHeader));
35 if(packet.header().moduleID == 0) processInformerPacket(&packet);
36 else if(m_artisanMap[packet.header().moduleID] != NULL) {
37 Artisan::Interface *interface;
38 if((interface = m_artisanMap[packet.header().moduleID]->interface()) != NULL)
39 interface->dataStore()->process(&packet);
41 /* If there is no artisan loaded for the packet, just ignore it. */
43 m_unprocessed.remove(0, sizeof(Comm::PacketHeader) + header->dataSize);
47 void DataInput::processInformerPacket(Comm::Packet *packet) {
48 Informer::PacketType type = static_cast<Informer::PacketType>(packet->data()[0]);
50 switch(type) {
51 case Informer::ModuleLoaded: {
52 Message(Debug, "Loading module . . .");
53 ModuleID moduleID = *reinterpret_cast<ModuleID *>(packet->data() + 1);
54 std::string name = reinterpret_cast<char *>(packet->data() + 3);
55 ArtisanWrapper *artisan = m_artisanManager->artisan(name);
56 m_artisanMap[moduleID] = artisan;
57 break;
59 case Informer::FileLoaded: {
60 Message(Warning, "Recieved FileLoaded packet in visualizer -- these are for the monitor only!");
61 break;
63 case Informer::NewProcess: {
64 uint32_t informerID = *reinterpret_cast<uint32_t *>(packet->data() + 1);
65 m_processIDMap[informerID] = PIDAllocator::nextID();
66 break;
68 default: break;
72 } // namespace Visualizer