Began implementing the VCommunication namespace.
[aesalon.git] / monitor / src / vcommunication / LogSink.cpp
bloba01263903ddc241b6e01680b49d67d8eccb86573
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>
15 #include "vcommunication/LogSink.h"
17 #include "Coordinator.h"
18 #include "common/PathSanitizer.h"
20 namespace Monitor {
21 namespace VCommunication {
23 LogSink::LogSink() {
24 std::string filename = Common::PathSanitizer::sanitize(Coordinator::instance()->vault()->get("logFile"));
26 if(filename == "") {
27 m_fd = -1;
29 else {
30 m_fd = open(filename.c_str(), O_RDWR);
32 sem_init(&m_logLock, 0, 1);
36 LogSink::~LogSink() {
37 if(m_fd != -1) {
38 sem_destroy(&m_logLock);
39 close(m_fd);
43 void LogSink::sinkPacket(Packet *packet) {
44 if(m_fd == -1) return;
46 sem_wait(&m_logLock);
50 sem_post(&m_logLock);
53 } // namespace VCommunication
54 } // namespace Monitor