I am beginning to question the need for a marshaller.
[aesalon.git] / src / monitor / LogOutput.cpp
blob59f8452ab83843fab6b29acf4e208501fdf6264d
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/LogOutput.cpp
8 */
10 #include <fcntl.h>
11 #include <errno.h>
12 #include <cstring>
14 #include "monitor/LogOutput.h"
15 #include "util/MessageSystem.h"
17 namespace Monitor {
19 LogOutput::LogOutput(std::string spec) {
20 m_fd = open(spec.c_str(), O_RDWR | O_CREAT, S_IWUSR | S_IRUSR);
21 if(m_fd == -1) {
22 Message(Fatal, "Could not open log file \"" << spec << "\": " << std::strerror(errno));
24 sem_init(&m_logSemaphore, 0, 1);
27 LogOutput::~LogOutput() {
28 close(m_fd);
31 void LogOutput::output(Comm::Packet *packet) {
32 sem_wait(&m_logSemaphore);
34 write(m_fd, &packet->header(), sizeof(packet->header()));
35 write(m_fd, packet->data(), packet->header().dataSize);
37 sem_post(&m_logSemaphore);
40 } // namespace Monitor