15 * You should have received a copy of the GNU General Public License |
15 * You should have received a copy of the GNU General Public License |
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 */ |
17 */ |
18 #include <iostream> |
18 #include <iostream> |
19 |
19 |
|
20 #include <QCoreApplication> |
|
21 #include <QtDBus/QDBusConnection> |
|
22 |
20 #include "CadMouseConfig.h" |
23 #include "CadMouseConfig.h" |
21 #include "CLI.h" |
24 #include "CLI.h" |
22 #include "CLIParser.h" |
25 #include "CLIParser.h" |
23 #include "HID.h" |
26 #include "HID.h" |
|
27 #include "Daemon.h" |
|
28 #include "generated-sources/DBusAdaptor.h" // to generate this file run: d-bus/generate.sh adaptor |
24 |
29 |
25 int main(int argc, char** argv) { |
30 int main(int argc, char** argv) { |
26 try { |
31 try { |
27 CLI cli(argc, argv); |
32 CLI cli(argc, argv); |
28 |
33 |
32 CLIConfiguration configuration = cliParser.parse(cli.arguments()); |
37 CLIConfiguration configuration = cliParser.parse(cli.arguments()); |
33 |
38 |
34 if (configuration.daemon) { |
39 if (configuration.daemon) { |
35 // TODO: run D-Bus service |
40 // TODO: run D-Bus service |
36 std::wcout << L"will start daemon" << std::endl; |
41 std::wcout << L"will start daemon" << std::endl; |
|
42 std::wcout << L"uid = " << getuid() << std::endl; |
|
43 QCoreApplication qtApplication(argc, argv); |
|
44 |
|
45 Daemon* daemon = new Daemon(&qtApplication); |
|
46 DBusAdaptor* dbusAdaptor = new DBusAdaptor(daemon); |
|
47 |
|
48 QDBusConnection connection = getuid() ? QDBusConnection::sessionBus() : QDBusConnection::systemBus(); |
|
49 //QDBusConnection connection = QDBusConnection::sessionBus(); |
|
50 std::wcout << (connection.isConnected() ? L"připojeno" : L"nepřipojeno") << std::endl; |
|
51 std::wcout << connection.name().toStdWString() << std::endl; |
|
52 std::wcout << connection.lastError().message().toStdWString() << std::endl; |
|
53 connection.registerObject("/info/globalcode/mouse/cadMousePro", daemon); |
|
54 connection.registerService("info.globalcode.mouse.cadMousePro"); |
|
55 |
|
56 return qtApplication.exec(); |
|
57 |
37 } else { |
58 } else { |
38 HIDDevice mouse(0x256f, 0xc652, nullptr); |
59 HIDDevice mouse(Daemon::VENDOR_ID, Daemon::PRODUCT_ID, nullptr); |
39 std::wcout << L"mouse opened" << std::endl; |
60 std::wcout << L"mouse opened" << std::endl; |
40 std::wcout << L"manufacturer: " << mouse.getManufacturerName() << std::endl; |
61 std::wcout << L"manufacturer: " << mouse.getManufacturerName() << std::endl; |
41 std::wcout << L"product: " << mouse.getProductName() << std::endl; |
62 std::wcout << L"product: " << mouse.getProductName() << std::endl; |
42 // std::wcout << L"serial number: " << mouse.getSerialNumber() << std::endl; // throws exception |
63 // std::wcout << L"serial number: " << mouse.getSerialNumber() << std::endl; // throws exception |
43 |
64 |
44 mouse.sendFeatureReport(configuration.cadMouseConfig.serialize()); |
65 mouse.sendFeatureReport(configuration.cadMouseConfig.serialize()); |
45 } |
66 } |
46 |
67 |
47 return CLI::EXIT_CODE_SUCCESS; |
68 return CLI::EXIT_CODE_SUCCESS; |
48 } catch (const HIDException& e) { |
69 } catch (const HIDException& e) { |
49 std::wcout << L"HIDException: " << e.getMessage() << std::endl; |
70 std::wcout << L"HIDException: " << e.getMessage() << std::endl; |
50 return CLI::EXIT_CODE_UNEXPECTED_ERROR; |
71 return CLI::EXIT_CODE_UNEXPECTED_ERROR; |
51 } catch (const CLIException& e) { |
72 } catch (const CLIException& e) { |
52 std::wcout << L"CLIException: " << e.getMessge() << std::endl; |
73 std::wcout << L"CLIException: " << e.getMessage() << std::endl; |
53 return e.getExitCode(); |
74 return e.getExitCode(); |
54 } |
75 } |
55 |
76 |
56 } |
77 } |