/* # Copyright (c) 2009 - OpenSLX Project, Computer Center University of Freiburg # # This program is free software distributed under the GPL version 2. # See http://openslx.org/COPYING # # If you have any feedback please consult http://openslx.org/feedback and # send your suggestions, praise, or complaints to feedback@openslx.org # # General information about OpenSLX can be found at http://openslx.org/ # -------------------------------------------------------------------------- # inputHandlerChain.cpp: # - Forward privileged input events to a special handler process - implementation # -------------------------------------------------------------------------- */ #include #include #include #include #include #include #include #include #include "pvsPrivInputSocket.h" #include "privilegedHandlerForwarder.h" using namespace std; #ifndef UNIX_PATH_MAX # define UNIX_PATH_MAX 108 /* according to unix(7) */ #endif void PrivilegedHandlerForwarder::initialize() { QSettings settings(QSettings::NativeFormat, QSettings::SystemScope, "openslx", "pvsinputd"); QString defaultPath = "/tmp/pvsprivinputd.sock"; QByteArray socketPath = settings.value("socketpath", defaultPath).toString().toLocal8Bit(); _socket = pvsPrivInputMakeClientSocket(); if(_socket < 0) { return; } } void PrivilegedHandlerForwarder::doHandle(InputEvent const& evt, InputEventContext const*) { qDebug("Trying to handle %s in PrivilegedHandlerForwarder", evt.toString().toLocal8Bit().constData()); if(_socket < 0) { initialize(); } QByteArray data; QDataStream strm(&data, QIODevice::WriteOnly); strm.setByteOrder(QDataStream::BigEndian); strm << evt; assert(data.size() == 8); int delta = 0; int count = 0; do { delta = write(_socket, data.constData(), data.size()); if(delta < 0) { qWarning("Error while communicating with pvsprivinputd: %s", strerror(errno)); close(_socket); // Try again: initialize(); } else if(delta != 8) { // This should normally not happen. qWarning("Could not send a complete packet. Only %d bytes sent", delta); } count++; } while(delta != 8 && count < 3); }