vanilla/app/backend.cpp

432 lines
12 KiB
C++
Raw Normal View History

#include "backend.h"
#include <QCoreApplication>
#include <QDir>
#include <QMessageBox>
2024-08-02 13:46:16 -04:00
#include <QNetworkDatagram>
#include <QtConcurrent/QtConcurrent>
2024-08-02 13:46:16 -04:00
#include <arpa/inet.h>
2024-05-23 22:47:32 -04:00
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <vanilla.h>
2024-05-23 22:47:32 -04:00
#include "../pipe/pipe.h"
void vanillaEventHandler(void *context, int type, const char *data, size_t dataLength)
{
Backend *backend = static_cast<Backend*>(context);
2024-05-18 15:55:00 -04:00
switch (type) {
case VANILLA_EVENT_VIDEO:
emit backend->videoAvailable(QByteArray(data, dataLength));
break;
case VANILLA_EVENT_AUDIO:
emit backend->audioAvailable(QByteArray(data, dataLength));
break;
case VANILLA_EVENT_VIBRATE:
Squashed commit of the following: commit 51a1ca73ad257b32053faf293ef0dc5eb0bd0181 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 28 16:11:50 2024 -0700 try installing binfmt-support commit a1c2cbcf4add6e304684ce815f7644399f550723 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 28 15:53:54 2024 -0700 back to static i suppose commit 70a8db69a1b7be39bb082d8aec57493ea42d069f Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 28 15:52:57 2024 -0700 try binfmt only? commit 1bb5a2025e1b070a22abe5fb3ac01dcf13e9147d Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 28 15:52:02 2024 -0700 try installing qemu-user-binfmt? commit cb0710e57ac7da46d5e25c170d9f4843c360c688 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 28 15:45:51 2024 -0700 install qemu-user-static commit 06a1bde5e98d18c16f55e0d92bea6beb00b97e81 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 28 15:43:53 2024 -0700 try building aarch64 commit 939201a538ce40320003033b55fc76258c97fa24 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 28 15:43:46 2024 -0700 initialize managed value commit 7b21f934512ba55d735cc3d003d92e879d3e575f Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 28 15:43:32 2024 -0700 use more parallel building commit da50fd5d5f8f17edbc76026cc3b448874c3f2e9a Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 28 12:54:41 2024 -0700 name artifact after uploading commit 0b10c1ea02842eba77d008a824e0f276fb95b39a Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 28 12:51:08 2024 -0700 pull docker image rather than build in CI commit 344316a6654e3c2e355555fd60f65c064663ca5d Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 28 12:38:23 2024 -0700 create appdir This works! commit e9f22966f7aab63e360c12fc3b388953c9b0fc85 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 28 12:13:42 2024 -0700 auto configure wpa supplicant with cmake commit cd088b6a8613d47d73dbb6cd1d8bbd4f1390eeba Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 28 12:13:21 2024 -0700 ensure pipe is installed commit 9b576758333a230172c1b05e09f9bd8fca8175cc Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 28 12:13:03 2024 -0700 Update .gitignore commit 9f0e5655f77d84288ecb29d278072df539cea7e2 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Mon May 27 21:32:06 2024 -0700 disable non x86_64 builds for now commit 518a37cf7ee105a389786252dc435f0d9a65d29b Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Mon May 27 21:31:40 2024 -0700 disable connect button disabling commit d5bcbc709b7038046332e0e164d114ec96b27bb7 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Mon May 27 14:58:20 2024 -0700 add files to gitignore commit 874eddeb6fca586aee32ee2105221175a022ccb2 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Mon May 27 14:57:19 2024 -0700 don't build arm32 for now since we know it doesn't work for some reason commit ba52be114ecd081c9bfcb464a1bae6270f995d1b Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Mon May 27 14:56:17 2024 -0700 fix comment commit 6fbf28fabfbfac5855bae1367df2a2ffcade9f8c Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Mon May 27 12:39:56 2024 -0700 no need for TARGETARCH anymore commit 83c0c80b7836b32ed5ad242709b18781c5941221 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Mon May 27 12:38:36 2024 -0700 fix va arg call commit 60a4a18e244b3c3e31abbdff113150366fd3c9b2 Author: MattKC <34096995+itsmattkc@users.noreply.github.com> Date: Sat May 25 18:31:30 2024 -0700 disable ffmpeg qt integration commit c091b3bbe376eea76d52ea9902944ee5c5fea51c Author: MattKC <34096995+itsmattkc@users.noreply.github.com> Date: Sat May 25 01:32:40 2024 -0700 get rid of dumb superfluous qt shit commit f06a66e402a59889f056416ac5b95debdd6b1e85 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Fri May 24 23:31:13 2024 -0700 Update Dockerfile commit 22f8af190251600a7e631486651e6fdc4cd70750 Author: MattKC <34096995+itsmattkc@users.noreply.github.com> Date: Fri May 24 15:51:04 2024 -0700 link pipe with pthread commit ad6d581b85c3ec221e2379045d9b28bf6ddaf92c Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Fri May 24 14:40:42 2024 -0700 fix cmake commit 28336979a0de1ceac7c196362d6e2567da151dbe Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Fri May 24 14:34:02 2024 -0700 build cmake manually commit 5fb7f386c80a58a8406314936942d5e8ae09e87b Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Fri May 24 14:23:29 2024 -0700 oops commit 86cdaa7bdc6bef8f4aa0952af0a945980c381db4 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Fri May 24 14:21:57 2024 -0700 sigh commit 5333ecb8bc43bac54fb54da97c368721e6a63a3c Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Fri May 24 13:35:36 2024 -0700 you fucking moron commit 593e80e330caa026a3d05621fd8ba958e8eae78c Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Fri May 24 12:48:40 2024 -0700 always save cache after build commit e55449e7ca98422694419245000d4700f51da04f Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Fri May 24 12:45:23 2024 -0700 don't bother with ack for button/touch commit d2df3676105053bd45e8544641635167a4d86134 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Fri May 24 12:44:09 2024 -0700 use actual byte for rumble info commit 2ef512e8a2de80df367ee4ca4df29997cb4e88f9 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Fri May 24 12:43:52 2024 -0700 actually read the data payload from the pipe commit 135f2a31f2b11f392d4cfcefc08046bae810031e Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Fri May 24 12:43:33 2024 -0700 nicer sync animation commit 0dfca4710623b948b1a5278da8ee1fc23fb7c68a Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Fri May 24 11:21:25 2024 -0700 attempt to build both x86_64 and arm64 commit a48041466990b86a4bb746ea0a89b15e18e34e6a Merge: d622309 3b3b11d Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Fri May 24 11:18:20 2024 -0700 Merge branch 'master' into ci commit d622309cd697bbc7da20276421b3c5cef2f4de86 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Fri May 24 11:18:02 2024 -0700 use other dockerfile commit 1236186aa2f9c977cc929585f2e8d86265caa04b Author: MattKC <34096995+itsmattkc@users.noreply.github.com> Date: Thu May 23 12:20:59 2024 -0700 Update Dockerfile commit a36cbc3e11293bb8f8b4aef4b0724c6d57b3bb3d Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Thu May 23 12:01:12 2024 -0700 abs path to dhclient and force stdout in wpa supplicant build commit 0677e1f03d8cb16da98c83478da312c885d2a160 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Thu May 23 11:20:28 2024 -0700 don't hash dockerfile for cache ID commit a416cc6ce123b0cc20e53c46728e52744a9c873c Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Thu May 23 11:00:59 2024 -0700 copy dhclient and libOpenGL into AppDir commit e46f7b63ff8ec269de728597ed7b65604e90cbce Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Wed May 22 14:30:26 2024 -0700 Update Dockerfile commit 4bf49d818623d10c2518e8dbc3bcc5c62a958cee Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Wed May 22 13:46:48 2024 -0700 Update Dockerfile commit 3289f48be2011277ca2fdfb5565f2b1b6107f99e Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Wed May 22 13:46:14 2024 -0700 copy config into place commit eb400f7636ab5847cca253fa73a97aa57716bade Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Wed May 22 12:58:17 2024 -0700 oops commit c76857e4e65fe9cbf54740efc9b859ab15acb3f1 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Wed May 22 12:56:59 2024 -0700 try different stuff commit fbbe8816eedfaf7094547b138e35a296f41a2e3f Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Wed May 22 12:55:08 2024 -0700 build using docker commit 43c15518d7ac547cd0cf34b64790629717ddaf05 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Wed May 22 12:44:14 2024 -0700 Create Dockerfile commit 7a503bb2d75259dfb5016ef2565704664016a2d7 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Wed May 22 11:45:55 2024 -0700 install desktop file and icon commit 6f081759bab541dff53cb9a935b7a03db904f902 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Wed May 22 09:35:31 2024 -0700 we're gonna packaging using system libraries and don't need any of this stuff commit 0671b18eb5e5ba6bfb60c957d8cc8502b74af132 Author: MattKC <34096995+itsmattkc@users.noreply.github.com> Date: Wed May 22 08:22:35 2024 -0700 start work on arm64 build [skip ci] commit 2d87806c1f796c548430537789f1908307f7ced2 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 22:04:52 2024 -0700 skip more steps if cache is restored successfully commit da1ad1b783ad57b7d8909df26e9b9379fafa45d7 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 22:00:59 2024 -0700 fixed more xcb libraries commit 5e5c3216d233d4fff5d53197fadd3bfdeebec3d6 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 21:53:05 2024 -0700 enable verbose debugging commit 68df89f7be1deb04db09c239409a80496448f2a9 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 21:41:39 2024 -0700 fixed xcb deps commit 8e8a634ab81c8891efee5e2dc6b104ee33d45fb0 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 21:16:11 2024 -0700 install xcb libs commit d37f22265f4c998d685bea6e4fc4ec559bd13e69 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 20:57:38 2024 -0700 install libxcb-glx0-dev libts-dev commit 1b2a1507ad3886b3d78d1a8f172164334fc4f6de Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 20:46:58 2024 -0700 install libpulse-dev commit e00a6a4750b787ce6b28264c0babeb79ada9491c Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 20:46:09 2024 -0700 install libatspi2.0-dev commit 35dce7046e3263b978d707d3bbda89774b61a5e1 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 20:20:07 2024 -0700 install libx11-xcb-dev commit bd61c3af2df71077c793d0c61325727bbaa619a1 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 20:07:36 2024 -0700 install libxkbcommon-x11-dev commit e517b27ac893d847b99e781603e3b98b2ee00d57 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 19:58:48 2024 -0700 install libxkbcommon-dev commit 4057fca7a74a5a07caae9c992e034b913dc127a1 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 19:51:48 2024 -0700 ensure qt 6 builds with xcb commit e85626b918a9e6e3ffb5db4dc35ced76e0a869b5 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 18:52:32 2024 -0700 build ICU with rpath commit 41bb9525fc1aac8d63bc7b190bba0bc4472b28ba Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 18:17:47 2024 -0700 remove libicu commit c1a507dcf1c26bbbc4895525a9bdb196aaae5880 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 17:18:48 2024 -0700 allow ICU post checkout hook commit 6408f043836f809743f12d289f1f986c78da0954 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 17:14:55 2024 -0700 install ICU and cache everything else commit 9f4855654d53a5d4aa5f2b022558db51f30a3124 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 16:51:11 2024 -0700 set LDFLAGS commit 8903b8f841bf9257a7c4b31ae0c6e6578f1d3c63 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 16:47:45 2024 -0700 move to build stage commit e9eb176fd7860840a884649778f54f0eee200587 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 16:39:49 2024 -0700 list stuff in pkgconfig folder commit 3aacef645b8ef549a97a7e8219761d728ec0a61f Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 16:36:01 2024 -0700 print PKG_CONFIG_PATH commit 5bc07a6e7aa2db8a09c961876fc8378e3aeb83a9 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 16:22:23 2024 -0700 export maybe? commit 56412231e5530905e346339d1ab69eabed4570e1 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 16:18:57 2024 -0700 fix pkg_config_path commit 19d188a13fc7f35dec68f182be8fa29627932ca2 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 16:16:23 2024 -0700 set pkg_config_path commit 4cccf4ce25e484ddef15d9cab9b80176341da6b9 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 16:09:15 2024 -0700 install libnl manually commit 07ebf31177db4c199a4b5d4b5e5685aee12917fe Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 16:01:49 2024 -0700 install desktop-file-utils commit 49dc4906e0648e37704f806a59678cd288fa3097 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 15:59:56 2024 -0700 fix chmod typo commit 49f9b827eb20602fdf71e89c639b69647463ec63 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 15:58:14 2024 -0700 grab appimagetool commit d9f54867c8505069354291501a780ecee1ffddbb Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 15:53:57 2024 -0700 fix pathing in deploy commit 3f67fbd6b5a6ae8964b61a4f0cd980c8354d7ed6 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 15:51:54 2024 -0700 link with pthread commit b51d6b6973cd910f8a67cc0df4d6b6b652a1f4b6 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 15:50:07 2024 -0700 install libnl-genl-3 commit f7db3360168572e00f484a38114ac9d1e727b902 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 15:48:16 2024 -0700 install libnl3 commit b44465706c89ef470becb1e0b0c686197c39ff14 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 14:58:38 2024 -0700 cache deps post-build commit 168dbb6fd26bc83f87700d73ee1ff4aa3bf6edd0 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 14:53:07 2024 -0700 put wpa supplicant config in place commit 359c39cba8b4a48dea68288cd8a1a705c8c6945f Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 13:46:32 2024 -0700 install ffmpeg and sdl2 commit 60fdde71462fadf4b5d0df01542fab424aec5590 Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 13:01:59 2024 -0700 try git protocol commit fe16f0234d438ad6ed2b4301ce328a5f0008b35b Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 13:00:33 2024 -0700 build later version because why not commit e4bfdef10b1dcd882174fbe63e19e89d746ac3ab Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 12:50:31 2024 -0700 install gles2 and egl commit 15ee9a74eb5845a4263b44dce74b1fdfe861aefd Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 12:29:14 2024 -0700 improve qt6 build commit b3018b132aed5f34afbd5f26ca321befab58d74b Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 11:25:29 2024 -0700 install qt 6 commit fc4d11cb2c405e420dc08fad3c5516163bdbdbcc Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 10:52:13 2024 -0700 use apt for deps for now commit 511c57447f6874e59bde687595ff617d64cc629f Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 10:48:47 2024 -0700 sudo commit 4e94bae9fc894ca79ced4d1c08c7cdf25ab9512e Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 10:48:16 2024 -0700 withhhhhhhhh commit 20ccd8f23012bf810b476d82c908bb5c34b3112f Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 10:47:39 2024 -0700 for fucks sake vscode commit 67d0e2bad7d33d6d4f599031a905cf01961a7ecb Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 10:46:30 2024 -0700 ensure build tools are installed commit 5f0c2162974f158712e1e3db50f8b5f28625caee Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 10:45:11 2024 -0700 probably no need to use ninja commit 45a20ab4401c0a83bde9eabc15c8e31b474e757f Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 10:44:24 2024 -0700 move to the fucking workflows folder commit d9bd06ac9cced483fd9b035da2ea5215be4f1b0a Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 10:42:46 2024 -0700 build all branches commit bffeb35ac13599b63cacb202975888a3e105822c Author: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Tue May 21 10:38:22 2024 -0700 initial CI commit
2024-05-29 03:09:17 -04:00
emit backend->vibrate(*data);
2024-05-18 15:55:00 -04:00
break;
}
}
Backend::Backend(QObject *parent) : QObject(parent)
{
2024-08-02 13:46:16 -04:00
}
2024-08-02 13:46:16 -04:00
void Backend::init()
{
emit ready();
}
2024-08-02 13:46:16 -04:00
BackendViaLocalRoot::BackendViaLocalRoot(const QString &wirelessInterface, QObject *parent) : Backend(parent)
{
m_wirelessInterface = wirelessInterface;
}
2024-08-02 13:46:16 -04:00
BackendViaPipe::BackendViaPipe(QObject *parent) : Backend(parent)
{
}
2024-08-02 13:46:16 -04:00
BackendViaNamedPipe::BackendViaNamedPipe(const QString &wirelessInterface, QObject *parent) : BackendViaPipe(parent)
{
m_pipeIn = -1;
m_pipeOut = -1;
m_pipeThread = new QThread(this);
m_pipe = new BackendPipe(wirelessInterface, this);
connect(m_pipe, &BackendPipe::pipesAvailable, this, &BackendViaNamedPipe::setUpPipes);
connect(m_pipe, &BackendPipe::closed, this, &BackendViaNamedPipe::closed);
}
2024-08-02 13:46:16 -04:00
void BackendViaNamedPipe::init()
{
2024-08-02 13:46:16 -04:00
m_pipe->setParent(nullptr);
m_pipeThread->start();
m_pipe->moveToThread(m_pipeThread);
QMetaObject::invokeMethod(m_pipe, &BackendPipe::start, Qt::QueuedConnection);
}
BackendViaSocket::BackendViaSocket(const QHostAddress &backendAddr, quint16 backendPort, QObject *parent) : BackendViaPipe(parent)
2024-08-02 13:46:16 -04:00
{
m_socket = new BackendUdpWrapper(backendAddr, backendPort, this);
connect(m_socket, &BackendUdpWrapper::socketReady, this, &BackendViaSocket::socketReady);
connect(m_socket, &BackendUdpWrapper::receivedData, this, &BackendViaSocket::receivedData, Qt::DirectConnection);
connect(m_socket, &BackendUdpWrapper::closed, this, &BackendViaSocket::closed);
connect(m_socket, &BackendUdpWrapper::error, this, &BackendViaSocket::error);
2024-08-02 13:46:16 -04:00
m_socketThread = new QThread(this);
}
BackendViaSocket::~BackendViaSocket()
{
2024-08-02 13:46:16 -04:00
m_socket->deleteLater();
m_socketThread->quit();
m_socketThread->wait();
}
void BackendViaSocket::init()
{
2024-08-02 13:46:16 -04:00
m_socketThread->start();
m_socket->setParent(nullptr);
m_socket->moveToThread(m_socketThread);
QMetaObject::invokeMethod(m_socket, &BackendUdpWrapper::start, Qt::QueuedConnection);
}
2024-08-02 13:46:16 -04:00
void BackendViaPipe::quitPipe()
{
2024-08-02 13:46:16 -04:00
pipe_control_code cmd;
cmd.code = VANILLA_PIPE_IN_QUIT;
writeToPipe(&cmd, sizeof(cmd));
}
2024-08-02 13:46:16 -04:00
BackendViaNamedPipe::~BackendViaNamedPipe()
{
2024-08-02 13:46:16 -04:00
quitPipe();
m_pipe->deleteLater();
m_pipeThread->quit();
m_pipeThread->wait();
}
2024-08-02 13:46:16 -04:00
void BackendViaLocalRoot::interrupt()
2024-06-13 21:43:58 -04:00
{
2024-08-02 13:46:16 -04:00
vanilla_stop();
2024-06-13 21:43:58 -04:00
}
2024-08-02 13:46:16 -04:00
void BackendViaPipe::interrupt()
{
2024-08-02 13:46:16 -04:00
pipe_control_code cmd;
cmd.code = VANILLA_PIPE_IN_INTERRUPT;
writeToPipe(&cmd, sizeof(cmd));
}
2024-08-02 13:46:16 -04:00
void BackendViaLocalRoot::requestIDR()
{
vanilla_request_idr();
}
2024-08-02 13:46:16 -04:00
void BackendViaPipe::requestIDR()
{
pipe_control_code cmd;
cmd.code = VANILLA_PIPE_IN_REQ_IDR;
writeToPipe(&cmd, sizeof(cmd));
}
2024-08-02 13:46:16 -04:00
void BackendViaLocalRoot::connectToConsole()
{
QtConcurrent::run(connectInternal, this, m_wirelessInterface);
}
int BackendViaLocalRoot::connectInternal(BackendViaLocalRoot *instance, const QString &intf)
{
QByteArray wirelessInterfaceC = intf.toUtf8();
return vanilla_connect_to_console(wirelessInterfaceC.constData(), vanillaEventHandler, instance);
2024-08-02 13:46:16 -04:00
}
2024-08-02 13:46:16 -04:00
void BackendViaPipe::connectToConsole()
{
// Request pipe to connect
pipe_control_code conn_cmd;
conn_cmd.code = VANILLA_PIPE_IN_CONNECT;
writeToPipe(&conn_cmd, sizeof(conn_cmd));
uint8_t cmd[UINT16_MAX];
while (true) {
ssize_t read_size = readFromPipe(cmd, sizeof(cmd));
if (read_size == 0) {
continue;
}
2024-08-02 13:46:16 -04:00
pipe_control_code *cc = (pipe_control_code *) cmd;
2024-08-02 13:46:16 -04:00
if (cc->code == VANILLA_PIPE_OUT_EOF) {
break;
} else if (cc->code == VANILLA_PIPE_OUT_DATA) {
pipe_data_command *event = (pipe_data_command *) cmd;
event->data_size = ntohs(event->data_size);
vanillaEventHandler(this, event->event_type, (const char *) event->data, event->data_size);
}
}
}
2024-05-20 19:16:40 -04:00
2024-08-02 13:46:16 -04:00
void BackendViaLocalRoot::updateTouch(int x, int y)
2024-05-20 19:16:40 -04:00
{
2024-08-02 13:46:16 -04:00
vanilla_set_touch(x, y);
2024-05-23 21:47:04 -04:00
}
2024-08-02 13:46:16 -04:00
void BackendViaPipe::updateTouch(int x, int y)
2024-05-23 21:47:04 -04:00
{
2024-08-02 13:46:16 -04:00
pipe_touch_command cmd;
cmd.base.code = VANILLA_PIPE_IN_TOUCH;
cmd.x = htonl(x);
cmd.y = htonl(y);
writeToPipe(&cmd, sizeof(cmd));
2024-05-23 21:47:04 -04:00
}
2024-08-02 13:46:16 -04:00
void BackendViaLocalRoot::setButton(int button, int32_t value)
{
2024-08-02 13:46:16 -04:00
vanilla_set_button(button, value);
}
2024-08-02 13:46:16 -04:00
void BackendViaPipe::setButton(int button, int32_t value)
{
2024-08-02 13:46:16 -04:00
pipe_button_command cmd;
cmd.base.code = VANILLA_PIPE_IN_BUTTON;
cmd.id = htonl(button);
cmd.value = htonl(value);
writeToPipe(&cmd, sizeof(cmd));
}
2024-08-02 13:46:16 -04:00
void BackendViaLocalRoot::setRegion(int region)
2024-05-23 21:47:04 -04:00
{
2024-08-02 13:46:16 -04:00
vanilla_set_region(region);
}
2024-08-02 13:46:16 -04:00
void BackendViaPipe::setRegion(int region)
{
pipe_region_command cmd;
cmd.base.code = VANILLA_PIPE_IN_REGION;
cmd.region = region;
writeToPipe(&cmd, sizeof(cmd));
}
2024-08-02 13:46:16 -04:00
void BackendViaLocalRoot::setBatteryStatus(int status)
{
vanilla_set_battery_status(status);
}
void BackendViaPipe::setBatteryStatus(int status)
{
pipe_battery_command cmd;
cmd.base.code = VANILLA_PIPE_IN_BATTERY;
cmd.battery = status;
writeToPipe(&cmd, sizeof(cmd));
}
2024-08-02 13:46:16 -04:00
void BackendViaLocalRoot::sync(uint16_t code)
{
QFutureWatcher<int> *watcher = new QFutureWatcher<int>(this);
2024-08-04 14:28:08 -04:00
connect(watcher, &QFutureWatcher<int>::finished, this, &BackendViaLocalRoot::syncFutureCompleted);
watcher->setFuture(QtConcurrent::run(syncInternal, m_wirelessInterface, code));
}
int BackendViaLocalRoot::syncInternal(const QString &intf, uint16_t code)
{
QByteArray wirelessInterfaceC = intf.toUtf8();
return vanilla_sync_with_console(wirelessInterfaceC.constData(), code);
}
void BackendViaLocalRoot::syncFutureCompleted()
{
QFutureWatcher<int> *watcher = static_cast<QFutureWatcher<int>*>(sender());
int r = watcher->result();
2024-08-02 13:46:16 -04:00
emit syncCompleted(r == VANILLA_SUCCESS);
watcher->deleteLater();
2024-08-02 13:46:16 -04:00
}
2024-05-23 22:47:32 -04:00
2024-08-02 13:46:16 -04:00
void BackendViaPipe::sync(uint16_t code)
{
// Request pipe to sync
pipe_sync_command cmd;
cmd.base.code = VANILLA_PIPE_IN_SYNC;
2024-08-04 12:53:51 -04:00
cmd.code = htons(code);
2024-08-02 13:46:16 -04:00
writeToPipe(&cmd, sizeof(cmd));
// See if pipe accepted our request to sync
uint8_t cc;
readFromPipe(&cc, sizeof(cc));
if (cc != VANILLA_PIPE_ERR_SUCCESS) {
emit syncCompleted(false);
return;
}
2024-05-23 22:47:32 -04:00
2024-08-02 13:46:16 -04:00
// Wait for sync status
readFromPipe(&cc, sizeof(cc));
if (cc == VANILLA_PIPE_OUT_SYNC_STATE) {
readFromPipe(&cc, sizeof(cc));
emit syncCompleted(cc == VANILLA_SUCCESS);
2024-05-23 22:47:32 -04:00
} else {
2024-08-02 13:46:16 -04:00
emit syncCompleted(false);
2024-05-23 22:47:32 -04:00
}
}
2024-08-02 13:46:16 -04:00
void BackendViaNamedPipe::setUpPipes(const QString &in, const QString &out)
2024-05-23 22:47:32 -04:00
{
QByteArray inUtf8 = in.toUtf8();
QByteArray outUtf8 = out.toUtf8();
m_pipeIn = open(inUtf8.constData(), O_RDONLY);
if (m_pipeIn == -1) {
QMessageBox::critical(nullptr, tr("Pipe Error"), tr("Failed to create in pipe: %1").arg(strerror(errno)));
}
m_pipeOut = open(outUtf8.constData(), O_WRONLY);
if (m_pipeOut == -1) {
QMessageBox::critical(nullptr, tr("Pipe Error"), tr("Failed to create out pipe: %1").arg(strerror(errno)));
}
2024-05-30 15:58:58 -04:00
printf("Established connection with backend\n");
2024-08-02 13:46:16 -04:00
emit ready();
}
2024-08-02 13:46:16 -04:00
BackendPipe::BackendPipe(const QString &wirelessInterface, QObject *parent) : QObject(parent)
{
m_process = nullptr;
2024-08-02 13:46:16 -04:00
m_wirelessInterface = wirelessInterface;
}
BackendPipe::~BackendPipe()
{
waitForFinished();
QFile::remove(m_pipeInFilename);
QFile::remove(m_pipeOutFilename);
}
void BackendPipe::waitForFinished()
{
if (m_process) {
m_process->waitForFinished();
}
}
void BackendPipe::start()
{
const QString pipe_bin = QDir(QCoreApplication::applicationDirPath()).filePath(QStringLiteral("vanilla-pipe"));
m_process = new QProcess(this);
m_process->setReadChannel(QProcess::StandardError);
connect(m_process, &QProcess::readyReadStandardError, this, &BackendPipe::receivedData);
2024-08-02 13:46:16 -04:00
connect(m_process, &QProcess::finished, this, &BackendPipe::closed);
m_pipeOutFilename = QStringLiteral("/tmp/vanilla-fifo-in-%0").arg(QString::number(QDateTime::currentMSecsSinceEpoch()));
m_pipeInFilename = QStringLiteral("/tmp/vanilla-fifo-out-%0").arg(QString::number(QDateTime::currentMSecsSinceEpoch()));
2024-08-02 13:46:16 -04:00
m_process->start(QStringLiteral("pkexec"), {pipe_bin, m_wirelessInterface, QStringLiteral("-pipe"), m_pipeOutFilename, m_pipeInFilename});
}
void BackendPipe::receivedData()
{
while (m_process->canReadLine()) {
QByteArray a = m_process->readLine().trimmed();
if (a == QByteArrayLiteral("READY")) {
emit pipesAvailable(m_pipeInFilename, m_pipeOutFilename);
} else {
printf("%s\n", a.constData());
}
2024-05-23 22:47:32 -04:00
}
2024-08-02 13:46:16 -04:00
}
ssize_t BackendViaNamedPipe::readFromPipe(void *data, size_t length)
{
return read(m_pipeIn, data, length);
}
ssize_t BackendViaNamedPipe::writeToPipe(const void *data, size_t length)
{
return write(m_pipeOut, data, length);
}
BackendUdpWrapper::BackendUdpWrapper(const QHostAddress &backendAddr, quint16 backendPort, QObject *parent) : QObject(parent)
{
m_backendAddress = backendAddr;
m_backendPort = backendPort;
m_socket = new QUdpSocket(this);
connect(m_socket, &QUdpSocket::readyRead, this, &BackendUdpWrapper::readPendingDatagrams);
}
void BackendUdpWrapper::start()
{
bool connected = false;
for (m_frontendPort = 10100; m_frontendPort < 10200; m_frontendPort++) {
printf("Trying to bind to port %u\n", m_frontendPort);
if (m_socket->bind(QHostAddress::Any, m_frontendPort)) {
printf("Bound to port %u\n", m_frontendPort);
connected = true;
break;
}
}
if (connected) {
emit socketReady(m_frontendPort);
} else {
printf("Failed to bind to port\n");
emit error(tr("Failed to bind to UDP port"));
emit closed();
}
}
void BackendUdpWrapper::readPendingDatagrams()
{
while (m_socket->hasPendingDatagrams()) {
QNetworkDatagram datagram = m_socket->receiveDatagram();
emit receivedData(datagram.data());
}
}
void BackendUdpWrapper::write(const QByteArray &data)
{
m_socket->writeDatagram(data, m_backendAddress, m_backendPort);
}
ssize_t BackendViaSocket::readFromPipe(void *data, size_t length)
2024-08-02 13:46:16 -04:00
{
m_readMutex.lock();
2024-08-04 12:53:51 -04:00
if (m_buffer.isEmpty()) {
2024-08-02 13:46:16 -04:00
m_readWaitCond.wait(&m_readMutex);
}
2024-08-04 12:53:51 -04:00
if (m_buffer.size() < length) {
length = m_buffer.size();
}
2024-08-02 13:46:16 -04:00
memcpy(data, m_buffer.constData(), length);
m_buffer.remove(0, length);
m_readMutex.unlock();
return length;
}
ssize_t BackendViaSocket::writeToPipe(const void *data, size_t length)
2024-08-02 13:46:16 -04:00
{
QMetaObject::invokeMethod(m_socket, "write", Q_ARG(QByteArray, QByteArray((const char *) data, length)));
return length;
}
void BackendViaSocket::receivedData(const QByteArray &data)
2024-08-02 13:46:16 -04:00
{
m_readMutex.lock();
m_buffer.append(data);
m_readWaitCond.wakeAll();
m_readMutex.unlock();
}
void BackendViaSocket::socketReady(quint16 port)
2024-08-02 13:46:16 -04:00
{
pipe_control_code cmd;
cmd.code = VANILLA_PIPE_IN_BIND;
writeToPipe(&cmd, sizeof(cmd));
uint8_t cc;
readFromPipe(&cc, sizeof(cc));
if (cc == VANILLA_PIPE_OUT_BOUND_SUCCESSFUL) {
emit ready();
}
2024-05-20 19:16:40 -04:00
}