Redesign time,
[aesalon.git] / monitor / src / program / Link.cpp
blobbce5ba53dfc182d3b92b262be68c8948ab1157fe
1 /**
2 Aesalon, a tool to visualize a program's behaviour at run-time.
3 Copyright (C) 2010, Aesalon Development Team.
5 Aesalon is distributed under the terms of the GNU GPLv3. For more
6 licensing information, see the file LICENSE included with the distribution.
8 @file monitor/src/program/Link.cpp
12 #include <iostream>
14 #include "program/Link.h"
16 namespace Monitor {
17 namespace Program {
19 Link::Link(std::string name, uint32_t size) : m_sharedMemory(NULL) {
20 m_sharedMemory = new SharedMemory(name, size);
23 Link::~Link() {
24 std::cout << "Link destructing . . ." << std::endl;
27 void Link::listen() {
28 std::cout << "Link: creating thread . . ." << std::endl;
29 pthread_create(&m_threadID, NULL, run, NULL);
32 void Link::terminate() {
33 std::cout << "Link::terminate() called . . .\n";
35 if(m_sharedMemory != NULL) {
36 std::cout << "m_sharedMemory is not NULL, sending termination notice . . ." << std::endl;
37 m_sharedMemory->notifyTermination();
40 std::cout << "Link::terminate(): joining thread . . ." << std::endl;
41 pthread_join(m_threadID, NULL);
44 void *Link::run(void *voidInstance) {
45 std::cout << "Link::run() . . ." << std::endl;
46 Link *instance = reinterpret_cast<Link *>(voidInstance);
48 Packet *packet = NULL;
50 while((packet = instance->m_sharedMemory->readNext()) != NULL) {
51 std::cout << "Received packet!" << std::endl;
54 std::cout << "Link::run() read loop ended. NULL packet recieved." << std::endl;
56 delete instance->m_sharedMemory;
57 instance->m_sharedMemory = NULL;
59 return NULL;
62 } // namespace Program
63 } // namespace Monitor