--- a/.hgignore Tue Aug 20 18:59:39 2019 +0200
+++ b/.hgignore Thu Aug 29 17:57:30 2019 +0200
@@ -10,3 +10,4 @@
^[^/]+/dist/
^[^/]+/build/
^[^/]+/nbproject/private/
+^[^/]+/src/generated-sources/
--- a/cadMousePro-daemon/nbproject/configurations.xml Tue Aug 20 18:59:39 2019 +0200
+++ b/cadMousePro-daemon/nbproject/configurations.xml Thu Aug 29 17:57:30 2019 +0200
@@ -41,10 +41,54 @@
<configurationDescriptor version="100">
<logicalFolder name="root" displayName="root" projectFiles="true" kind="ROOT">
<df root="." name="0">
+ <df name="build">
+ <df name="Debug">
+ <df name="src">
+ <df name="generated-sources">
+ <in>DBusAdaptor.cpp</in>
+ </df>
+ <in>DBusAdaptor.cpp</in>
+ </df>
+ </df>
+ <df name="qt">
+ <df name="src">
+ <df name="cadMousePro_autogen">
+ <in>mocs_compilation.cpp</in>
+ </df>
+ </df>
+ </df>
+ </df>
<df name="src">
+ <df name="generated-sources">
+ <in>DBusAdaptor.cpp</in>
+ </df>
+ <in>Daemon.h</in>
<in>cadMousePro.cpp</in>
</df>
</df>
+ <logicalFolder name="cadMousePro_autogen"
+ displayName="cadMousePro_autogen"
+ projectFiles="true"
+ root="build/Debug/src/cadMousePro_autogen">
+ <logicalFolder name="7JU4VIX55Q" displayName="7JU4VIX55Q" projectFiles="true">
+ <itemPath>build/Debug/src/cadMousePro_autogen/7JU4VIX55Q/moc_DBusAdaptor.cpp</itemPath>
+ </logicalFolder>
+ <logicalFolder name="EWIEGA46WW" displayName="EWIEGA46WW" projectFiles="true">
+ <itemPath>build/Debug/src/cadMousePro_autogen/EWIEGA46WW/moc_DBusAdaptor.cpp</itemPath>
+ <itemPath>build/Debug/src/cadMousePro_autogen/EWIEGA46WW/moc_Daemon.cpp</itemPath>
+ </logicalFolder>
+ <logicalFolder name="S5VNLJ26FI" displayName="S5VNLJ26FI" projectFiles="true">
+ <itemPath>build/Debug/src/cadMousePro_autogen/S5VNLJ26FI/moc_DBusAdaptor.cpp</itemPath>
+ </logicalFolder>
+ <itemPath>build/Debug/src/cadMousePro_autogen/mocs_compilation.cpp</itemPath>
+ </logicalFolder>
+ <logicalFolder name="Modules"
+ displayName="Modules"
+ projectFiles="true"
+ root="/usr/share/cmake-3.10/Modules">
+ <itemPath>/usr/share/cmake-3.10/Modules/CMakeCXXCompilerABI.cpp</itemPath>
+ <itemPath>/usr/share/cmake-3.10/Modules/CMakeCompilerABI.h</itemPath>
+ </logicalFolder>
<logicalFolder name="ExternalFiles"
displayName="Important Files"
projectFiles="false"
@@ -67,7 +111,9 @@
<rebuildPropChanged>false</rebuildPropChanged>
</toolsSet>
<flagsDictionary>
- <element flagsID="0" commonFlags="-fsanitize=address"/>
+ <element flagsID="0" commonFlags="-fsanitize=address -fPIC -std=gnu++11"/>
+ <element flagsID="1"
+ commonFlags="-mtune=generic -march=x86-64 -std=gnu++11 -fsanitize=address -fPIC -fstack-protector-strong"/>
</flagsDictionary>
<codeAssistance>
</codeAssistance>
@@ -77,12 +123,6 @@
<buildCommand>${MAKE} -f Makefile</buildCommand>
<cleanCommand>${MAKE} -f Makefile clean</cleanCommand>
<executablePath>build/Debug/src/welcome</executablePath>
- <ccTool>
- <incDir>
- <pElem>/usr/include/hidapi</pElem>
- <pElem>build/Debug/src</pElem>
- </incDir>
- </ccTool>
</makeTool>
<preBuild>
<preBuildCommandWorkingDir>build/Debug</preBuildCommandWorkingDir>
@@ -90,7 +130,154 @@
<preBuildFirst>true</preBuildFirst>
</preBuild>
</makefileType>
- <item path="src/cadMousePro.cpp" ex="false" tool="1" flavor2="0">
+ <item path="/home/fiki/projekty/spacenav/cadMousePro/cadMousePro-daemon/src/generated-sources/DBusAdaptor.cpp"
+ ex="false"
+ tool="1"
+ flavor2="8">
+ <ccTool flags="0">
+ </ccTool>
+ </item>
+ <item path="/usr/share/cmake-3.10/Modules/CMakeCXXCompilerABI.cpp"
+ ex="false"
+ tool="1"
+ flavor2="11">
+ </item>
+ <item path="build/Debug/src/DBusAdaptor.cpp" ex="false" tool="1" flavor2="8">
+ <ccTool flags="0">
+ <incDir>
+ <pElem>build/Debug/src/cadMousePro_autogen/include</pElem>
+ </incDir>
+ </ccTool>
+ </item>
+ <item path="build/Debug/src/cadMousePro_autogen/7JU4VIX55Q/moc_DBusAdaptor.cpp"
+ ex="true"
+ tool="3"
+ flavor2="0">
+ </item>
+ <item path="build/Debug/src/cadMousePro_autogen/EWIEGA46WW/moc_DBusAdaptor.cpp"
+ ex="true"
+ tool="3"
+ flavor2="0">
+ </item>
+ <item path="build/Debug/src/cadMousePro_autogen/EWIEGA46WW/moc_Daemon.cpp"
+ ex="true"
+ tool="3"
+ flavor2="0">
+ </item>
+ <item path="build/Debug/src/cadMousePro_autogen/S5VNLJ26FI/moc_DBusAdaptor.cpp"
+ ex="true"
+ tool="3"
+ flavor2="0">
+ </item>
+ <item path="build/Debug/src/cadMousePro_autogen/mocs_compilation.cpp"
+ ex="false"
+ tool="1"
+ flavor2="8">
+ <ccTool flags="0">
+ </ccTool>
+ </item>
+ <item path="build/Debug/src/generated-sources/DBusAdaptor.cpp"
+ ex="false"
+ tool="1"
+ flavor2="8">
+ <ccTool flags="0">
+ </ccTool>
+ </item>
+ <item path="build/qt/src/cadMousePro_autogen/mocs_compilation.cpp"
+ ex="false"
+ tool="1"
+ flavor2="8">
+ <ccTool flags="1">
+ </ccTool>
+ </item>
+ <folder path="0/build">
+ <ccTool>
+ <incDir>
+ <pElem>/usr/include/hidapi</pElem>
+ <pElem>/usr/include/x86_64-linux-gnu/qt5</pElem>
+ <pElem>/usr/include/x86_64-linux-gnu/qt5/QtDBus</pElem>
+ <pElem>/usr/include/x86_64-linux-gnu/qt5/QtCore</pElem>
+ <pElem>/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++</pElem>
+ </incDir>
+ </ccTool>
+ </folder>
+ <folder path="0/build/Debug">
+ <ccTool>
+ <incDir>
+ <pElem>build/Debug/src</pElem>
+ <pElem>src</pElem>
+ </incDir>
+ <preprocessorList>
+ <Elem>QT_CORE_LIB</Elem>
+ <Elem>QT_DBUS_LIB</Elem>
+ </preprocessorList>
+ </ccTool>
+ </folder>
+ <folder path="0/build/qt">
+ <ccTool>
+ <incDir>
+ <pElem>src</pElem>
+ <pElem>build/qt/src/cadMousePro_autogen/EWIEGA46WW</pElem>
+ <pElem>build/qt/src/cadMousePro_autogen</pElem>
+ <pElem>build/qt/src</pElem>
+ </incDir>
+ </ccTool>
+ </folder>
+ <folder path="0/src">
+ <ccTool>
+ <incDir>
+ <pElem>build/Debug/src</pElem>
+ <pElem>src</pElem>
+ <pElem>build/Debug/src/cadMousePro_autogen/include</pElem>
+ <pElem>/usr/include/hidapi</pElem>
+ <pElem>/usr/include/x86_64-linux-gnu/qt5</pElem>
+ <pElem>/usr/include/x86_64-linux-gnu/qt5/QtDBus</pElem>
+ <pElem>/usr/include/x86_64-linux-gnu/qt5/QtCore</pElem>
+ <pElem>/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++</pElem>
+ </incDir>
+ <preprocessorList>
+ <Elem>QT_CORE_LIB</Elem>
+ <Elem>QT_DBUS_LIB</Elem>
+ </preprocessorList>
+ </ccTool>
+ </folder>
+ <folder path="Modules">
+ <ccTool>
+ <incDir>
+ <pElem>build/Debug/src</pElem>
+ <pElem>src</pElem>
+ <pElem>build/Debug/src/cadMousePro_autogen/include</pElem>
+ <pElem>/usr/include/hidapi</pElem>
+ <pElem>/usr/include/x86_64-linux-gnu/qt5</pElem>
+ <pElem>/usr/include/x86_64-linux-gnu/qt5/QtDBus</pElem>
+ <pElem>/usr/include/x86_64-linux-gnu/qt5/QtCore</pElem>
+ <pElem>/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++</pElem>
+ </incDir>
+ <preprocessorList>
+ <Elem>QT_CORE_LIB</Elem>
+ <Elem>QT_DBUS_LIB</Elem>
+ </preprocessorList>
+ </ccTool>
+ </folder>
+ <folder path="cadMousePro_autogen">
+ <ccTool>
+ <incDir>
+ <pElem>build/Debug/src</pElem>
+ <pElem>src</pElem>
+ <pElem>build/Debug/src/cadMousePro_autogen/include</pElem>
+ <pElem>/usr/include/hidapi</pElem>
+ <pElem>/usr/include/x86_64-linux-gnu/qt5</pElem>
+ <pElem>/usr/include/x86_64-linux-gnu/qt5/QtDBus</pElem>
+ <pElem>/usr/include/x86_64-linux-gnu/qt5/QtCore</pElem>
+ <pElem>/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++</pElem>
+ </incDir>
+ <preprocessorList>
+ <Elem>QT_CORE_LIB</Elem>
+ <Elem>QT_DBUS_LIB</Elem>
+ </preprocessorList>
+ </ccTool>
+ </folder>
+ <item path="src/cadMousePro.cpp" ex="false" tool="1" flavor2="8">
<ccTool flags="0">
</ccTool>
</item>
@@ -127,6 +314,8 @@
<preBuildFirst>true</preBuildFirst>
</preBuild>
</makefileType>
+ <item path="src/Daemon.h" ex="false" tool="3" flavor2="0">
+ </item>
<item path="src/cadMousePro.cpp" ex="false" tool="1" flavor2="0">
<ccTool flags="0">
</ccTool>
--- a/cadMousePro-daemon/src/CLIException.h Tue Aug 20 18:59:39 2019 +0200
+++ b/cadMousePro-daemon/src/CLIException.h Thu Aug 29 17:57:30 2019 +0200
@@ -30,7 +30,7 @@
CLIException(std::wstring message, int exitCode) : message(message), exitCode(exitCode) {
}
- std::wstring getMessge() const {
+ std::wstring getMessage() const {
return message;
}
--- a/cadMousePro-daemon/src/CLIParser.h Tue Aug 20 18:59:39 2019 +0200
+++ b/cadMousePro-daemon/src/CLIParser.h Thu Aug 29 17:57:30 2019 +0200
@@ -37,7 +37,9 @@
else throw CLIException(L"Unable to parse boolean value „" + value + L"“ – expecting „true“ or „false“", CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
}
- Frequency parseFrequency(std::wstring value) {
+public:
+
+ static Frequency parseFrequency(std::wstring value) {
if (value == L"125") return Frequency::Hz_0125;
else if (value == L"250") return Frequency::Hz_0250;
else if (value == L"500") return Frequency::Hz_0500;
@@ -45,8 +47,6 @@
else throw CLIException(L"Unable to parse frequency value „" + value + L"“ – expecting „125“ or „250“ or „500“ or „1000“", CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
}
-public:
-
static const std::wstring OPTION_FREQUENCY;
static const std::wstring OPTION_SMART_SCROLLING;
static const std::wstring OPTION_LIFT_OFF_DETECTION;
--- a/cadMousePro-daemon/src/CMakeLists.txt Tue Aug 20 18:59:39 2019 +0200
+++ b/cadMousePro-daemon/src/CMakeLists.txt Thu Aug 29 17:57:30 2019 +0200
@@ -2,6 +2,13 @@
# USB libraries:
INCLUDE(FindPkgConfig)
+
+# Qt libraries:
+set(CMAKE_INCLUDE_CURRENT_DIR ON) # Find includes in corresponding build directories
+set(CMAKE_AUTOMOC ON) # Instruct CMake to run moc automatically when needed
+set(CMAKE_AUTOUIC ON) # Create code from a list of Qt designer ui files
+find_package(Qt5 CONFIG REQUIRED Core DBus)
+
pkg_check_modules (USB_LIBS hidapi-hidraw)
include_directories(${USB_LIBS_INCLUDE_DIRS})
link_directories(${USB_LIBS_LIBRARY_DIRS})
@@ -13,9 +20,12 @@
# Executable output:
add_executable(
${EXECUTABLE_FILE}
+ Daemon.h
+ generated-sources/DBusAdaptor.h
+ generated-sources/DBusAdaptor.cpp
cadMousePro.cpp
)
# Link libraries:
-target_link_libraries(${EXECUTABLE_FILE} ${USB_LIBS_LIBRARIES})
+target_link_libraries(${EXECUTABLE_FILE} ${USB_LIBS_LIBRARIES} Qt5::DBus)
set_property(TARGET ${EXECUTABLE_FILE} PROPERTY INSTALL_RPATH_USE_LINK_PATH TRUE)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/cadMousePro-daemon/src/Common.h Thu Aug 29 17:57:30 2019 +0200
@@ -0,0 +1,37 @@
+/**
+ * cadMousePro
+ * Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#pragma once
+
+#include "CadMouseConfig.h"
+#include "CLI.h"
+#include "CLIException.h"
+
+class Common {
+public:
+
+ static Frequency parseFrequency(std::wstring value) {
+ if (value == L"125") return Frequency::Hz_0125;
+ else if (value == L"250") return Frequency::Hz_0250;
+ else if (value == L"500") return Frequency::Hz_0500;
+ else if (value == L"1000") return Frequency::Hz_1000;
+ else throw CLIException(L"Unable to parse frequency value „" + value + L"“ – expecting „125“ or „250“ or „500“ or „1000“", CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
+ }
+
+ // TODO: refactor exceptions
+
+};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/cadMousePro-daemon/src/Daemon.h Thu Aug 29 17:57:30 2019 +0200
@@ -0,0 +1,88 @@
+/**
+ * cadMousePro
+ * Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#pragma once
+
+#include <iostream>
+#include <QObject>
+#include <QDBusContext>
+#include <qt5/QtDBus/qdbusconnection.h>
+
+#include "HID.h"
+#include "CadMouseConfig.h"
+#include "Common.h"
+
+class Daemon : public QObject, public QDBusContext {
+ Q_OBJECT;
+
+private:
+
+ HIDDevice getMouse() {
+ return HIDDevice(VENDOR_ID, PRODUCT_ID, nullptr);
+ }
+
+ void logException(const HIDException& e) {
+ std::wcout << L"HIDException: " << e.getMessage() << std::endl;
+ }
+public:
+
+ static unsigned short const VENDOR_ID = 0x256f;
+ static unsigned short const PRODUCT_ID = 0xc652;
+
+ Daemon(QObject* parent = nullptr) : QObject(parent) {
+ }
+
+ Q_PROPERTY(bool devicePresent READ devicePresent)
+ bool devicePresent() {
+ std::wcout << L"checking mouse presence" << std::endl;
+ try {
+ getMouse();
+ return true;
+ } catch (const HIDException& e) {
+ logException(e);
+ return false;
+ }
+ }
+
+ Q_PROPERTY(QString deviceName READ deviceName)
+ QString deviceName() {
+ std::wcout << L"reading mouse name" << std::endl;
+ try {
+ return QString::fromStdWString(getMouse().getProductName());
+ } catch (HIDException& e) {
+ logException(e);
+ return QString();
+ }
+ }
+
+ void configure(bool liftOffDetection, bool smartScrolling, int frequency) {
+ std::wcout << L"configuring mouse" << std::endl;
+ try {
+ CadMouseConfig config;
+ config.setLiftOffDetection(liftOffDetection);
+ config.setSmartScrolling(smartScrolling);
+ config.setFrequency(Common::parseFrequency(std::to_wstring(frequency)));
+ getMouse().sendFeatureReport(config.serialize());
+ } catch (HIDException& e) {
+ logException(e);
+ sendErrorReply(QDBusError::ErrorType::Failed, QString::fromStdWString(e.getMessage()));
+ } catch (CLIException& e) {
+ sendErrorReply(QDBusError::ErrorType::Failed, QString::fromStdWString(e.getMessage()));
+ }
+ }
+
+};
--- a/cadMousePro-daemon/src/cadMousePro.cpp Tue Aug 20 18:59:39 2019 +0200
+++ b/cadMousePro-daemon/src/cadMousePro.cpp Thu Aug 29 17:57:30 2019 +0200
@@ -17,10 +17,15 @@
*/
#include <iostream>
+#include <QCoreApplication>
+#include <QtDBus/QDBusConnection>
+
#include "CadMouseConfig.h"
#include "CLI.h"
#include "CLIParser.h"
#include "HID.h"
+#include "Daemon.h"
+#include "generated-sources/DBusAdaptor.h" // to generate this file run: d-bus/generate.sh adaptor
int main(int argc, char** argv) {
try {
@@ -34,13 +39,29 @@
if (configuration.daemon) {
// TODO: run D-Bus service
std::wcout << L"will start daemon" << std::endl;
+ std::wcout << L"uid = " << getuid() << std::endl;
+ QCoreApplication qtApplication(argc, argv);
+
+ Daemon* daemon = new Daemon(&qtApplication);
+ DBusAdaptor* dbusAdaptor = new DBusAdaptor(daemon);
+
+ QDBusConnection connection = getuid() ? QDBusConnection::sessionBus() : QDBusConnection::systemBus();
+ //QDBusConnection connection = QDBusConnection::sessionBus();
+ std::wcout << (connection.isConnected() ? L"připojeno" : L"nepřipojeno") << std::endl;
+ std::wcout << connection.name().toStdWString() << std::endl;
+ std::wcout << connection.lastError().message().toStdWString() << std::endl;
+ connection.registerObject("/info/globalcode/mouse/cadMousePro", daemon);
+ connection.registerService("info.globalcode.mouse.cadMousePro");
+
+ return qtApplication.exec();
+
} else {
- HIDDevice mouse(0x256f, 0xc652, nullptr);
+ HIDDevice mouse(Daemon::VENDOR_ID, Daemon::PRODUCT_ID, nullptr);
std::wcout << L"mouse opened" << std::endl;
std::wcout << L"manufacturer: " << mouse.getManufacturerName() << std::endl;
std::wcout << L"product: " << mouse.getProductName() << std::endl;
// std::wcout << L"serial number: " << mouse.getSerialNumber() << std::endl; // throws exception
-
+
mouse.sendFeatureReport(configuration.cadMouseConfig.serialize());
}
@@ -49,7 +70,7 @@
std::wcout << L"HIDException: " << e.getMessage() << std::endl;
return CLI::EXIT_CODE_UNEXPECTED_ERROR;
} catch (const CLIException& e) {
- std::wcout << L"CLIException: " << e.getMessge() << std::endl;
+ std::wcout << L"CLIException: " << e.getMessage() << std::endl;
return e.getExitCode();
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/d-bus/generate.sh Thu Aug 29 17:57:30 2019 +0200
@@ -0,0 +1,22 @@
+#!/bin/bash
+
+cd "$(dirname "$0")"
+ADAPTOR_DIR="../cadMousePro-daemon/src/generated-sources"
+PROXY_DIR="../cadMousePro-gui/src/generated-sources"
+XML="info.globalcode.mouse.cadMousePro.xml"
+
+case "$1" in
+ adaptor)
+ qdbusxml2cpp -a DBusAdaptor.h:DBusAdaptor.cpp -c DBusAdaptor -l Daemon -i ../Daemon.h "$XML"
+ mkdir -p "$ADAPTOR_DIR"
+ mv DBusAdaptor.h DBusAdaptor.cpp "$ADAPTOR_DIR"
+ ;;
+ proxy)
+ qdbusxml2cpp -l Daemon -i ../Daemon.h -p Proxy.h "$XML"
+ mkdir -p "$PROXY_DIR"
+ mv Proxy.h "$PROXY_DIR"
+ ;;
+ *)
+ echo $"Usage: $0 (adaptor|proxy)"
+ exit 1
+esac
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/d-bus/info.globalcode.mouse.cadMousePro.xml Thu Aug 29 17:57:30 2019 +0200
@@ -0,0 +1,23 @@
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+<!--
+ n.b. in current version, this is not a stable public API and might change in later versions;
+ now it server only as an internal interface between the daemon and the GUI application.
+
+ generate C++ code from this XML:
+ d-bus/generate.sh adaptor
+ d-bus/generate.sh proxy
+-->
+<node name="/info/globalcode/mouse/cadMousePro">
+ <interface name="info.globalcode.mouse.cadMousePro">
+
+ <property name="devicePresent" type="b" access="read"/>
+ <property name="deviceName" type="s" access="read"/>
+
+ <method name="configure">
+ <arg name="liftOffDetection" type="b" direction="in"/>
+ <arg name="smartScrolling" type="b" direction="in"/>
+ <arg name="frequency" type="i" direction="in"/>
+ </method>
+
+ </interface>
+</node>