author | paule <paule> | 2007-02-06 04:51:37 (UTC) |
---|---|---|
committer | paule <paule> | 2007-02-06 04:51:37 (UTC) |
commit | 97b2152a21890f05a2217dddfcba6c820c00aa24 (patch) (unidiff) | |
tree | 55b859fbea71840f15368ec7b4b9e2de2c4f9879 | |
parent | a505f79190d4d14a7c9595af3e9b78d9c613da21 (diff) | |
download | opie-97b2152a21890f05a2217dddfcba6c820c00aa24.zip opie-97b2152a21890f05a2217dddfcba6c820c00aa24.tar.gz opie-97b2152a21890f05a2217dddfcba6c820c00aa24.tar.bz2 |
Start lircd on application start, and stop it on quit
-rw-r--r-- | noncore/tools/remote/lirchandler.cpp | 25 | ||||
-rw-r--r-- | noncore/tools/remote/lirchandler.h | 5 | ||||
-rw-r--r-- | noncore/tools/remote/remote.cpp | 40 |
3 files changed, 51 insertions, 19 deletions
diff --git a/noncore/tools/remote/lirchandler.cpp b/noncore/tools/remote/lirchandler.cpp index 263b740..ec1e275 100644 --- a/noncore/tools/remote/lirchandler.cpp +++ b/noncore/tools/remote/lirchandler.cpp | |||
@@ -6,40 +6,40 @@ This program is free software; you can redistribute it and/or modify it under th | |||
6 | License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later | 6 | License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later |
7 | version. | 7 | version. |
8 | 8 | ||
9 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the | 9 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the |
10 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | 10 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
11 | Public License for more details. | 11 | Public License for more details. |
12 | 12 | ||
13 | You should have received a copy of the GNU General Public License along with this program; if not, write to the Free | 13 | You should have received a copy of the GNU General Public License along with this program; if not, write to the Free |
14 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 14 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
15 | */ | 15 | */ |
16 | 16 | ||
17 | #include <stdio.h> | 17 | #include <stdio.h> |
18 | #include <stdlib.h> | 18 | #include <stdlib.h> |
19 | #include <string.h> | 19 | #include <string.h> |
20 | #include <sys/socket.h> | 20 | #include <sys/socket.h> |
21 | #include <sys/types.h> | 21 | #include <sys/types.h> |
22 | #include <sys/un.h> | ||
23 | #include <unistd.h> | 22 | #include <unistd.h> |
24 | #include <errno.h> | 23 | #include <errno.h> |
25 | 24 | ||
26 | #include <qstring.h> | 25 | #include <qstring.h> |
27 | #include <qmessagebox.h> | 26 | #include <qmessagebox.h> |
28 | #include <qobject.h> | 27 | #include <qobject.h> |
29 | #include <opie2/oprocess.h> | 28 | #include <opie2/oprocess.h> |
29 | #include <qpe/qcopenvelope_qws.h> | ||
30 | 30 | ||
31 | #include "lirchandler.h" | 31 | #include "lirchandler.h" |
32 | 32 | ||
33 | #define PACKET_SIZE 256 | 33 | #define PACKET_SIZE 256 |
34 | #define TIMEOUT 3 | 34 | #define TIMEOUT 3 |
35 | #define LIRCD_SOCKET "/dev/lircd" | 35 | #define LIRCD_SOCKET "/dev/lircd" |
36 | #define LIRCD_SERVICECMD "/etc/init.d/lircd" | 36 | #define LIRCD_SERVICECMD "/etc/init.d/lircd" |
37 | 37 | ||
38 | using namespace Opie::Core; | 38 | using namespace Opie::Core; |
39 | 39 | ||
40 | LircHandler::LircHandler(void) | 40 | LircHandler::LircHandler(void) |
41 | { | 41 | { |
42 | fd = 0; | 42 | fd = 0; |
43 | addr.sun_family=AF_UNIX; | 43 | addr.sun_family=AF_UNIX; |
44 | strcpy(addr.sun_path, LIRCD_SOCKET); | 44 | strcpy(addr.sun_path, LIRCD_SOCKET); |
45 | } | 45 | } |
@@ -255,16 +255,39 @@ int LircHandler::sendIR(const char *lircaction) | |||
255 | } | 255 | } |
256 | 256 | ||
257 | bool LircHandler::startLircd(void) | 257 | bool LircHandler::startLircd(void) |
258 | { | 258 | { |
259 | return (system(LIRCD_SERVICECMD " start") == 0); | 259 | return (system(LIRCD_SERVICECMD " start") == 0); |
260 | } | 260 | } |
261 | 261 | ||
262 | bool LircHandler::stopLircd(void) | 262 | bool LircHandler::stopLircd(void) |
263 | { | 263 | { |
264 | return (system(LIRCD_SERVICECMD " stop") == 0); | 264 | return (system(LIRCD_SERVICECMD " stop") == 0); |
265 | } | 265 | } |
266 | 266 | ||
267 | bool LircHandler::isLircdRunning(void) | 267 | bool LircHandler::isLircdRunning(void) |
268 | { | 268 | { |
269 | return (OProcess::processPID("lircd") != 0); | 269 | return (OProcess::processPID("lircd") != 0); |
270 | } | 270 | } |
271 | |||
272 | bool LircHandler::setupModules(void) | ||
273 | { | ||
274 | // Remove IrDA modules which get in the way | ||
275 | system("rmmod ircomm-tty ircomm"); | ||
276 | // Load LIRC device driver | ||
277 | system("modprobe lirc_sir"); | ||
278 | return true; | ||
279 | } | ||
280 | |||
281 | bool LircHandler::cleanupModules(void) | ||
282 | { | ||
283 | // Unload LIRC device driver | ||
284 | system("rmmod lirc_sir"); | ||
285 | // Load IrDA drivers back in | ||
286 | system("modprobe ircomm-tty"); | ||
287 | return true; | ||
288 | } | ||
289 | |||
290 | void LircHandler::disableIrDA(void) | ||
291 | { | ||
292 | QCopEnvelope e("QPE/IrDaApplet", "disableIrda()"); | ||
293 | } | ||
diff --git a/noncore/tools/remote/lirchandler.h b/noncore/tools/remote/lirchandler.h index c7665cb..4e56b6b 100644 --- a/noncore/tools/remote/lirchandler.h +++ b/noncore/tools/remote/lirchandler.h | |||
@@ -4,35 +4,40 @@ Copyright (C) 2007 Paul Eggleton & Thomas Stephens | |||
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public | 5 | This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public |
6 | License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later | 6 | License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later |
7 | version. | 7 | version. |
8 | 8 | ||
9 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the | 9 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the |
10 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | 10 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
11 | Public License for more details. | 11 | Public License for more details. |
12 | 12 | ||
13 | You should have received a copy of the GNU General Public License along with this program; if not, write to the Free | 13 | You should have received a copy of the GNU General Public License along with this program; if not, write to the Free |
14 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 14 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
15 | */ | 15 | */ |
16 | 16 | ||
17 | #ifndef LIRCHANDLER_H | 17 | #ifndef LIRCHANDLER_H |
18 | #define LIRCHANDLER_H | 18 | #define LIRCHANDLER_H |
19 | 19 | ||
20 | #include <sys/un.h> | ||
21 | |||
20 | class LircHandler | 22 | class LircHandler |
21 | { | 23 | { |
22 | private: | 24 | private: |
23 | bool connectLirc(void); | 25 | bool connectLirc(void); |
24 | const char *readPacket(); | 26 | const char *readPacket(); |
25 | 27 | ||
26 | struct sockaddr_un addr; | 28 | struct sockaddr_un addr; |
27 | int fd; | 29 | int fd; |
28 | public: | 30 | public: |
29 | LircHandler(void); | 31 | LircHandler(void); |
30 | QStringList getRemotes(void); | 32 | QStringList getRemotes(void); |
31 | QStringList getButtons(const char *remoteName); | 33 | QStringList getButtons(const char *remoteName); |
32 | int sendIR(const char *lircaction); | 34 | int sendIR(const char *lircaction); |
33 | bool startLircd(void); | 35 | bool startLircd(void); |
34 | bool stopLircd(void); | 36 | bool stopLircd(void); |
35 | bool isLircdRunning(void); | 37 | bool isLircdRunning(void); |
38 | bool setupModules(void); | ||
39 | bool cleanupModules(void); | ||
40 | void disableIrDA(void); | ||
36 | }; | 41 | }; |
37 | 42 | ||
38 | #endif | 43 | #endif |
diff --git a/noncore/tools/remote/remote.cpp b/noncore/tools/remote/remote.cpp index 67fc57d..5b756cb 100644 --- a/noncore/tools/remote/remote.cpp +++ b/noncore/tools/remote/remote.cpp | |||
@@ -26,35 +26,39 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
26 | #include <qlayout.h> | 26 | #include <qlayout.h> |
27 | #include <qmessagebox.h> | 27 | #include <qmessagebox.h> |
28 | #include <qpaintdevice.h> | 28 | #include <qpaintdevice.h> |
29 | #include <qobject.h> | 29 | #include <qobject.h> |
30 | 30 | ||
31 | /* STD */ | 31 | /* STD */ |
32 | #include <sys/socket.h> | 32 | #include <sys/socket.h> |
33 | #include <sys/types.h> | 33 | #include <sys/types.h> |
34 | #include <sys/un.h> | 34 | #include <sys/un.h> |
35 | #include <unistd.h> | 35 | #include <unistd.h> |
36 | #include <stdio.h> | 36 | #include <stdio.h> |
37 | #include <signal.h> | 37 | #include <signal.h> |
38 | 38 | ||
39 | 39 | ||
40 | int main( int argc, char **argv ) | 40 | int main( int argc, char **argv ) |
41 | { | 41 | { |
42 | QPEApplication a( argc, argv ); | 42 | QPEApplication a( argc, argv ); |
43 | MainView w; | 43 | |
44 | a.setMainWidget( &w ); | 44 | LircHandler lh; |
45 | QPEApplication::showWidget( &w ); | 45 | |
46 | 46 | lh.disableIrDA(); | |
47 | LircHandler lh; | 47 | lh.setupModules(); |
48 | if(!lh.isLircdRunning()) { | 48 | lh.startLircd(); |
49 | QMessageBox mb("Error!", | 49 | if(!lh.isLircdRunning()) { |
50 | "Lircd is not running", | 50 | QMessageBox::critical(NULL, QObject::tr("Error"), |
51 | QMessageBox::NoIcon, | 51 | QObject::tr("Unable to start lircd"), |
52 | QMessageBox::Ok, | 52 | QMessageBox::Ok, QMessageBox::NoButton); |
53 | QMessageBox::NoButton, | 53 | } |
54 | QMessageBox::NoButton); | 54 | |
55 | mb.exec(); | 55 | MainView w; |
56 | 56 | a.setMainWidget( &w ); | |
57 | } | 57 | QPEApplication::showWidget( &w ); |
58 | 58 | int result = a.exec(); | |
59 | return a.exec(); | 59 | |
60 | lh.stopLircd(); | ||
61 | lh.cleanupModules(); | ||
62 | |||
63 | return result; | ||
60 | } | 64 | } |