Mercurial > hg > vamp-live-host
view host/FDWriteAction.cpp @ 15:df33703ace3b
Get building with newer libraries &c
author | Chris Cannam |
---|---|
date | Tue, 03 Dec 2013 16:05:14 +0000 |
parents | 47b0a143db39 |
children |
line wrap: on
line source
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ #include "FDWriteAction.h" #include <iostream> #include <termios.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <cstdio> #include <QMutexLocker> std::map<QString, int> FDWriteAction::m_fdMap; QString FDWriteAction::m_previousData = ""; FDWriteAction::FDWriteAction(QString file, QString data, bool togglePrevious) : m_data(data), m_togglePrevious(togglePrevious) { QMutexLocker locker(&m_mutex); if (m_fdMap.find(file) != m_fdMap.end()) { m_fd = m_fdMap[file]; } else { m_fd = open(file.toLocal8Bit().data(), O_WRONLY | O_NOCTTY); if (m_fd < 0) { perror("Failed to open output file"); std::cerr << "ERROR: FDWriteAction: Unable to open \"" << file.toStdString() << "\" for writing" << std::endl; return; } struct termios t; tcgetattr(m_fd, &t); t.c_cflag = B9600 | CS8 | CLOCAL; t.c_iflag = 0; t.c_oflag = 0; t.c_lflag = ICANON; tcflush(m_fd, TCOFLUSH); tcsetattr(m_fd, TCSANOW, &t); m_fdMap[file] = m_fd; } } FDWriteAction::~FDWriteAction() { // don't close fds -- lazily leave them for program exit rather // than go to the bother of reference counting } QString FDWriteAction::getName() const { return QString("fdwrite: \"%1\",%2") .arg(m_data) .arg(m_togglePrevious); } void FDWriteAction::fire() { if (m_fd < 0) return; QMutexLocker locker(&m_mutex); if (m_togglePrevious) { if (m_previousData == m_data) return; std::cerr << getName().toStdString() << ": fire" << std::endl; if (m_previousData != "") { // bug here write(m_fd, m_previousData.toLocal8Bit().data(), m_previousData.length()); usleep(100000); } } // bug here write(m_fd, m_data.toLocal8Bit().data(), m_data.length()); m_previousData = m_data; usleep(100000); }