summaryrefslogtreecommitdiffstats
path: root/src/input/privilegedHandlerForwarder.cpp
diff options
context:
space:
mode:
authorSebastien Braun2010-10-05 15:30:04 +0200
committerSebastien Braun2010-10-05 18:15:51 +0200
commitac05f7d367ae9983e7996738871efbdbf3ec66e8 (patch)
treecff16aee36f2afcb00df6842cb0e9bab82c86c16 /src/input/privilegedHandlerForwarder.cpp
parentAdd description to input event handlers so they can (diff)
downloadpvs-ac05f7d367ae9983e7996738871efbdbf3ec66e8.tar.gz
pvs-ac05f7d367ae9983e7996738871efbdbf3ec66e8.tar.xz
pvs-ac05f7d367ae9983e7996738871efbdbf3ec66e8.zip
Implement privileged input daemon, first version without handlers.
Diffstat (limited to 'src/input/privilegedHandlerForwarder.cpp')
-rw-r--r--src/input/privilegedHandlerForwarder.cpp82
1 files changed, 82 insertions, 0 deletions
diff --git a/src/input/privilegedHandlerForwarder.cpp b/src/input/privilegedHandlerForwarder.cpp
new file mode 100644
index 0000000..3c0b3bd
--- /dev/null
+++ b/src/input/privilegedHandlerForwarder.cpp
@@ -0,0 +1,82 @@
+/*
+ # 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 <sys/socket.h>
+#include <sys/un.h>
+#include <cassert>
+#include <cerrno>
+#include <cstring>
+#include <string>
+#include <QSettings>
+#include <QtDebug>
+#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::handle(InputEvent const& evt, InputEventContext const*)
+{
+ qDebug("Trying to handle %s in PrivilegedHandlerForwarder", evt.toString().c_str());
+ 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);
+}