Successfully implemented a cpuTime marshaller.
[aesalon.git] / monitor / src / vcommunication / LogSink.cpp
blob7c18631f468e5a0997743dd3b576b0624d67d557
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/vcommunication/LogSink.cpp
12 #include <string>
13 #include <fcntl.h>
14 #include <stdio.h>
15 #include <iostream>
17 #include "vcommunication/LogSink.h"
19 #include "Coordinator.h"
20 #include "common/PathSanitizer.h"
22 namespace Monitor {
23 namespace VCommunication {
25 LogSink::LogSink() {
26 std::string filename = Common::PathSanitizer::sanitize(Coordinator::instance()->vault()->get("logFile"));
28 std::cout << "LogSink: \"" << filename << "\"\n";
30 if(filename == "") {
31 m_fd = -1;
33 else {
34 m_fd = open(filename.c_str(), O_RDWR | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR);
36 sem_init(&m_logLock, 0, 1);
40 LogSink::~LogSink() {
41 if(m_fd != -1) {
42 sem_destroy(&m_logLock);
43 close(m_fd);
47 void LogSink::sinkPacket(Common::VPacket *packet) {
48 if(m_fd == -1) return;
50 sem_wait(&m_logLock);
52 ModuleID moduleID = packet->moduleID();
53 write(m_fd, &moduleID, sizeof(moduleID));
55 pid_t processID = packet->processID();
56 write(m_fd, &processID, sizeof(processID));
58 pthread_t threadID = packet->threadID();
59 write(m_fd, &threadID, sizeof(threadID));
61 uint32_t dataSize = packet->dataSize();
62 write(m_fd, &dataSize, sizeof(dataSize));
64 write(m_fd, packet->data(), dataSize);
66 sem_post(&m_logLock);
69 } // namespace VCommunication
70 } // namespace Monitor