author | František Kučera <franta-hg@frantovo.cz> |
Wed, 23 Oct 2019 22:43:29 +0200 | |
branch | v_0 |
changeset 26 | fff8e9a86e85 |
parent 13 | 52d92c1b340e |
child 33 | 0dc4e2942840 |
permissions | -rw-r--r-- |
6 | 1 |
/** |
2 |
* cadMousePro |
|
3 |
* Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info) |
|
4 |
* |
|
5 |
* This program is free software: you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
26
fff8e9a86e85
fix license version: GNU GPLv3
František Kučera <franta-hg@frantovo.cz>
parents:
13
diff
changeset
|
7 |
* the Free Software Foundation, version 3 of the License. |
6 | 8 |
* |
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 |
*/ |
|
0
6ff501639c23
project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
17 |
#include <iostream> |
6ff501639c23
project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
18 |
|
12 | 19 |
#include <QCoreApplication> |
20 |
#include <QtDBus/QDBusConnection> |
|
21 |
||
5
6799cec5c2f8
refactoring: separate into several files
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
22 |
#include "CadMouseConfig.h" |
7
148f8dd077e8
CLI options and parser of configuration parameters instead of hardcoded values
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
23 |
#include "CLI.h" |
148f8dd077e8
CLI options and parser of configuration parameters instead of hardcoded values
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
24 |
#include "CLIParser.h" |
5
6799cec5c2f8
refactoring: separate into several files
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
25 |
#include "HID.h" |
12 | 26 |
#include "Daemon.h" |
13
52d92c1b340e
generate C++ classes from D-Bus XML using cmake instead of a custom script
František Kučera <franta-hg@frantovo.cz>
parents:
12
diff
changeset
|
27 |
#include "generated-sources/DBusAdaptor.h" |
4
405aa9de65d2
CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
28 |
|
0
6ff501639c23
project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
29 |
int main(int argc, char** argv) { |
6ff501639c23
project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
30 |
try { |
7
148f8dd077e8
CLI options and parser of configuration parameters instead of hardcoded values
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
31 |
CLI cli(argc, argv); |
0
6ff501639c23
project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
32 |
|
6ff501639c23
project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
33 |
std::wcout << L"cadMousePro" << std::endl; |
1
29cbe171cd43
first working version: disables „free wheel“ a.k.a. „smart scrolling“ feature
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
34 |
|
7
148f8dd077e8
CLI options and parser of configuration parameters instead of hardcoded values
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
35 |
CLIParser cliParser; |
148f8dd077e8
CLI options and parser of configuration parameters instead of hardcoded values
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
36 |
CLIConfiguration configuration = cliParser.parse(cli.arguments()); |
1
29cbe171cd43
first working version: disables „free wheel“ a.k.a. „smart scrolling“ feature
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
37 |
|
10
05dbed834852
prepare daemon config
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
38 |
if (configuration.daemon) { |
05dbed834852
prepare daemon config
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
39 |
// TODO: run D-Bus service |
05dbed834852
prepare daemon config
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
40 |
std::wcout << L"will start daemon" << std::endl; |
12 | 41 |
std::wcout << L"uid = " << getuid() << std::endl; |
42 |
QCoreApplication qtApplication(argc, argv); |
|
43 |
||
44 |
Daemon* daemon = new Daemon(&qtApplication); |
|
45 |
DBusAdaptor* dbusAdaptor = new DBusAdaptor(daemon); |
|
46 |
||
47 |
QDBusConnection connection = getuid() ? QDBusConnection::sessionBus() : QDBusConnection::systemBus(); |
|
48 |
//QDBusConnection connection = QDBusConnection::sessionBus(); |
|
49 |
std::wcout << (connection.isConnected() ? L"připojeno" : L"nepřipojeno") << std::endl; |
|
50 |
std::wcout << connection.name().toStdWString() << std::endl; |
|
51 |
std::wcout << connection.lastError().message().toStdWString() << std::endl; |
|
52 |
connection.registerObject("/info/globalcode/mouse/cadMousePro", daemon); |
|
53 |
connection.registerService("info.globalcode.mouse.cadMousePro"); |
|
54 |
||
55 |
return qtApplication.exec(); |
|
56 |
||
10
05dbed834852
prepare daemon config
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
57 |
} else { |
12 | 58 |
HIDDevice mouse(Daemon::VENDOR_ID, Daemon::PRODUCT_ID, nullptr); |
10
05dbed834852
prepare daemon config
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
59 |
std::wcout << L"mouse opened" << std::endl; |
05dbed834852
prepare daemon config
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
60 |
std::wcout << L"manufacturer: " << mouse.getManufacturerName() << std::endl; |
05dbed834852
prepare daemon config
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
61 |
std::wcout << L"product: " << mouse.getProductName() << std::endl; |
05dbed834852
prepare daemon config
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
62 |
// std::wcout << L"serial number: " << mouse.getSerialNumber() << std::endl; // throws exception |
12 | 63 |
|
10
05dbed834852
prepare daemon config
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
64 |
mouse.sendFeatureReport(configuration.cadMouseConfig.serialize()); |
05dbed834852
prepare daemon config
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
65 |
} |
1
29cbe171cd43
first working version: disables „free wheel“ a.k.a. „smart scrolling“ feature
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
66 |
|
7
148f8dd077e8
CLI options and parser of configuration parameters instead of hardcoded values
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
67 |
return CLI::EXIT_CODE_SUCCESS; |
0
6ff501639c23
project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
68 |
} catch (const HIDException& e) { |
6ff501639c23
project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
69 |
std::wcout << L"HIDException: " << e.getMessage() << std::endl; |
7
148f8dd077e8
CLI options and parser of configuration parameters instead of hardcoded values
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
70 |
return CLI::EXIT_CODE_UNEXPECTED_ERROR; |
148f8dd077e8
CLI options and parser of configuration parameters instead of hardcoded values
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
71 |
} catch (const CLIException& e) { |
12 | 72 |
std::wcout << L"CLIException: " << e.getMessage() << std::endl; |
7
148f8dd077e8
CLI options and parser of configuration parameters instead of hardcoded values
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
73 |
return e.getExitCode(); |
0
6ff501639c23
project skeleton, open USB HID device
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
74 |
} |
7
148f8dd077e8
CLI options and parser of configuration parameters instead of hardcoded values
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
75 |
|
4
405aa9de65d2
CadMouseConfig class, frequency, lift-off detection, smart scrolling
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
76 |
} |