author | paule <paule> | 2007-01-28 04:04:14 (UTC) |
---|---|---|
committer | paule <paule> | 2007-01-28 04:04:14 (UTC) |
commit | ec2309cb69365847762db542c41951629cd06cbe (patch) (unidiff) | |
tree | 2f0101c1f0d6268207dbd15eb21f40c812a4fff5 /noncore | |
parent | 3cd37427b5c5f26f62cff583fbde914467ddafe3 (diff) | |
download | opie-ec2309cb69365847762db542c41951629cd06cbe.zip opie-ec2309cb69365847762db542c41951629cd06cbe.tar.gz opie-ec2309cb69365847762db542c41951629cd06cbe.tar.bz2 |
Refactored out all communication with LIRC into new LircHandler class
-rw-r--r-- | noncore/tools/remote/buttondialog.cpp | 216 | ||||
-rw-r--r-- | noncore/tools/remote/buttondialog.h | 12 | ||||
-rw-r--r-- | noncore/tools/remote/learntab.cpp | 132 | ||||
-rw-r--r-- | noncore/tools/remote/learntab.h | 9 | ||||
-rw-r--r-- | noncore/tools/remote/lirchandler.cpp | 270 | ||||
-rw-r--r-- | noncore/tools/remote/lirchandler.h | 38 | ||||
-rw-r--r-- | noncore/tools/remote/mainview.cpp | 13 | ||||
-rw-r--r-- | noncore/tools/remote/mainview.h | 3 | ||||
-rw-r--r-- | noncore/tools/remote/packetread.h | 200 | ||||
-rw-r--r-- | noncore/tools/remote/remote.cpp | 73 | ||||
-rw-r--r-- | noncore/tools/remote/remote.pro | 4 | ||||
-rw-r--r-- | noncore/tools/remote/remotetab.cpp | 122 | ||||
-rw-r--r-- | noncore/tools/remote/remotetab.h | 7 |
13 files changed, 344 insertions, 755 deletions
diff --git a/noncore/tools/remote/buttondialog.cpp b/noncore/tools/remote/buttondialog.cpp index 580f101..56738d1 100644 --- a/noncore/tools/remote/buttondialog.cpp +++ b/noncore/tools/remote/buttondialog.cpp | |||
@@ -33,6 +33,8 @@ ButtonDialog::ButtonDialog(QString buttonName, QWidget *parent, const char*name, | |||
33 | layout->addSpacing(5); | 33 | layout->addSpacing(5); |
34 | layout->addLayout(hlayout3); | 34 | layout->addLayout(hlayout3); |
35 | layout->addSpacing(5); | 35 | layout->addSpacing(5); |
36 | |||
37 | lh = new LircHandler(); | ||
36 | 38 | ||
37 | remote = new QComboBox(false, this, "remote"); | 39 | remote = new QComboBox(false, this, "remote"); |
38 | QLabel *remoteLabel = new QLabel(remote, "Remote: ", this, "remoteLabel"); | 40 | QLabel *remoteLabel = new QLabel(remote, "Remote: ", this, "remoteLabel"); |
@@ -42,7 +44,7 @@ ButtonDialog::ButtonDialog(QString buttonName, QWidget *parent, const char*name, | |||
42 | hlayout1->addWidget(remote); | 44 | hlayout1->addWidget(remote); |
43 | hlayout1->addSpacing(5); | 45 | hlayout1->addSpacing(5); |
44 | remote->insertItem("Remote "); | 46 | remote->insertItem("Remote "); |
45 | remote->insertStringList(getRemotes()); | 47 | remote->insertStringList(lh->getRemotes()); |
46 | connect(remote, SIGNAL(activated(const QString&)), this, SLOT(remoteSelected(const QString&)) ); | 48 | connect(remote, SIGNAL(activated(const QString&)), this, SLOT(remoteSelected(const QString&)) ); |
47 | 49 | ||
48 | button = new QComboBox(false, this, "button"); | 50 | button = new QComboBox(false, this, "button"); |
@@ -65,9 +67,14 @@ ButtonDialog::ButtonDialog(QString buttonName, QWidget *parent, const char*name, | |||
65 | hlayout3->addSpacing(5); | 67 | hlayout3->addSpacing(5); |
66 | } | 68 | } |
67 | 69 | ||
70 | ButtonDialog::~ButtonDialog() | ||
71 | { | ||
72 | delete lh; | ||
73 | } | ||
74 | |||
68 | void ButtonDialog::remoteSelected(const QString &string) | 75 | void ButtonDialog::remoteSelected(const QString &string) |
69 | { | 76 | { |
70 | button->insertStringList(getButtons(string.latin1()) ); | 77 | button->insertStringList(lh->getButtons(string.latin1()) ); |
71 | list="SEND_ONCE"; | 78 | list="SEND_ONCE"; |
72 | list+=string; | 79 | list+=string; |
73 | } | 80 | } |
@@ -86,208 +93,3 @@ QString ButtonDialog::getLabel() | |||
86 | { | 93 | { |
87 | return label->text(); | 94 | return label->text(); |
88 | } | 95 | } |
89 | |||
90 | QStringList ButtonDialog::getRemotes() | ||
91 | { | ||
92 | const char write_buffer[] = "LIST\n"; | ||
93 | const char *readbuffer; | ||
94 | int i, numlines; | ||
95 | QStringList list; | ||
96 | |||
97 | addr.sun_family=AF_UNIX; | ||
98 | strcpy(addr.sun_path,"/dev/lircd"); | ||
99 | |||
100 | fd = socket(AF_UNIX, SOCK_STREAM, 0); | ||
101 | if(fd == -1) | ||
102 | { | ||
103 | QMessageBox *mb = new QMessageBox("Error!", | ||
104 | "couldnt connect to socket", | ||
105 | QMessageBox::NoIcon, | ||
106 | QMessageBox::Ok, | ||
107 | QMessageBox::NoButton, | ||
108 | QMessageBox::NoButton); | ||
109 | mb->exec(); | ||
110 | perror("ButtonDialog::GetRemotes"); | ||
111 | return NULL; | ||
112 | } | ||
113 | |||
114 | if(::connect(fd,(struct sockaddr *) &addr, sizeof(addr) ) == -1) | ||
115 | { | ||
116 | QMessageBox *mb = new QMessageBox("Error!", | ||
117 | "couldnt connect to socket", | ||
118 | QMessageBox::NoIcon, | ||
119 | QMessageBox::Ok, | ||
120 | QMessageBox::NoButton, | ||
121 | QMessageBox::NoButton); | ||
122 | mb->exec(); | ||
123 | perror("ButtonDialog::GetRemotes"); | ||
124 | return NULL; | ||
125 | } | ||
126 | |||
127 | write(fd, write_buffer, strlen(write_buffer)); | ||
128 | |||
129 | for(i=0; i<5; i++) | ||
130 | { | ||
131 | printf("%d\n", i); | ||
132 | readbuffer = readPacket(); | ||
133 | printf("%s", readbuffer); | ||
134 | printf("%d\n", i); | ||
135 | } | ||
136 | |||
137 | numlines = atoi(readbuffer); | ||
138 | |||
139 | for(i=0; i<numlines; i++) | ||
140 | { | ||
141 | list+=readPacket(); | ||
142 | } | ||
143 | |||
144 | if(strcasecmp(readPacket(), "END") != 0) | ||
145 | { | ||
146 | QMessageBox *mb = new QMessageBox("Error!", | ||
147 | "bad packet", | ||
148 | QMessageBox::NoIcon, | ||
149 | QMessageBox::Ok, | ||
150 | QMessageBox::NoButton, | ||
151 | QMessageBox::NoButton); | ||
152 | mb->exec(); | ||
153 | perror("ButtonDialog::GetRemotes"); | ||
154 | return NULL; | ||
155 | } | ||
156 | |||
157 | ::close(fd); | ||
158 | return list; | ||
159 | } | ||
160 | |||
161 | QStringList ButtonDialog::getButtons(const char *remoteName) | ||
162 | { | ||
163 | QString write_buffer = "LIST "; | ||
164 | const char *readbuffer; | ||
165 | int i, j, numlines; | ||
166 | QStringList list; | ||
167 | QString string; | ||
168 | |||
169 | write_buffer += remoteName; | ||
170 | write_buffer += '\n'; | ||
171 | |||
172 | fd = socket(AF_UNIX, SOCK_STREAM, 0); | ||
173 | if(fd == -1) | ||
174 | { | ||
175 | QMessageBox *mb = new QMessageBox("Error!", | ||
176 | "couldnt connect to socket", | ||
177 | QMessageBox::NoIcon, | ||
178 | QMessageBox::Ok, | ||
179 | QMessageBox::NoButton, | ||
180 | QMessageBox::NoButton); | ||
181 | mb->exec(); | ||
182 | perror("ButtonDialog::GetButtons"); | ||
183 | return NULL; | ||
184 | } | ||
185 | |||
186 | |||
187 | if(::connect(fd,(struct sockaddr *) &addr, sizeof(addr) ) == -1) | ||
188 | { | ||
189 | QMessageBox *mb = new QMessageBox("Error!", | ||
190 | "couldnt connect to socket", | ||
191 | QMessageBox::NoIcon, | ||
192 | QMessageBox::Ok, | ||
193 | QMessageBox::NoButton, | ||
194 | QMessageBox::NoButton); | ||
195 | mb->exec(); | ||
196 | perror("ButtonDialog::GetButtons"); | ||
197 | return NULL; | ||
198 | } | ||
199 | |||
200 | write(fd, write_buffer.latin1(), strlen(write_buffer) ); | ||
201 | |||
202 | for(i=0; i<5; i++) | ||
203 | { | ||
204 | readbuffer = readPacket(); | ||
205 | } | ||
206 | |||
207 | numlines = atoi(readbuffer); | ||
208 | |||
209 | for(i=0; i<numlines; i++) | ||
210 | { | ||
211 | list+=readPacket(); | ||
212 | for(j=0; j<list[i].length(); j++) | ||
213 | { | ||
214 | if(list[i][j] == ' ') | ||
215 | break; | ||
216 | } | ||
217 | list[i].remove(0, j+1); | ||
218 | } | ||
219 | |||
220 | if(strcasecmp(readPacket(), "END") != 0) | ||
221 | { | ||
222 | QMessageBox *mb = new QMessageBox("Error!", | ||
223 | "bad packet", | ||
224 | QMessageBox::NoIcon, | ||
225 | QMessageBox::Ok, | ||
226 | QMessageBox::NoButton, | ||
227 | QMessageBox::NoButton); | ||
228 | mb->exec(); | ||
229 | perror("ButtonDialog::GetButtons"); | ||
230 | return NULL; | ||
231 | } | ||
232 | |||
233 | ::close(fd); | ||
234 | return list; | ||
235 | } | ||
236 | |||
237 | |||
238 | //this function was ripped for rc.c in xrc, it is available here: http://www.lirc.org/software.html | ||
239 | const char *ButtonDialog::readPacket() | ||
240 | { | ||
241 | static char buffer[PACKET_SIZE+1]=""; | ||
242 | char *end; | ||
243 | static int ptr=0,end_len=0; | ||
244 | ssize_t ret; | ||
245 | timeout = 0; | ||
246 | |||
247 | if(ptr>0) | ||
248 | { | ||
249 | memmove(buffer,buffer+ptr,strlen(buffer+ptr)+1); | ||
250 | ptr=strlen(buffer); | ||
251 | end=strchr(buffer,'\n'); | ||
252 | } | ||
253 | else | ||
254 | { | ||
255 | end=NULL; | ||
256 | } | ||
257 | alarm(TIMEOUT); | ||
258 | while(end==NULL) | ||
259 | { | ||
260 | if(PACKET_SIZE<=ptr) | ||
261 | { | ||
262 | fprintf(stderr,"bad packet\n"); | ||
263 | ptr=0; | ||
264 | return(NULL); | ||
265 | } | ||
266 | ret=read(fd,buffer+ptr,PACKET_SIZE-ptr); | ||
267 | |||
268 | if(ret<=0 || timeout) | ||
269 | { | ||
270 | if(timeout) | ||
271 | { | ||
272 | fprintf(stderr,"timeout\n"); | ||
273 | } | ||
274 | else | ||
275 | { | ||
276 | alarm(0); | ||
277 | } | ||
278 | ptr=0; | ||
279 | return(NULL); | ||
280 | } | ||
281 | buffer[ptr+ret]=0; | ||
282 | ptr=strlen(buffer); | ||
283 | end=strchr(buffer,'\n'); | ||
284 | } | ||
285 | alarm(0);timeout=0; | ||
286 | |||
287 | end[0]=0; | ||
288 | ptr=strlen(buffer)+1; | ||
289 | //# ifdef DEBUG | ||
290 | //printf("buffer: -%s-\n",buffer); | ||
291 | //# endif | ||
292 | return(buffer); | ||
293 | } | ||
diff --git a/noncore/tools/remote/buttondialog.h b/noncore/tools/remote/buttondialog.h index 33dc4ef..cc697b5 100644 --- a/noncore/tools/remote/buttondialog.h +++ b/noncore/tools/remote/buttondialog.h | |||
@@ -31,18 +31,14 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
31 | #include <unistd.h> | 31 | #include <unistd.h> |
32 | #include <errno.h> | 32 | #include <errno.h> |
33 | 33 | ||
34 | #define PACKET_SIZE 256 | 34 | #include "lirchandler.h" |
35 | #define TIMEOUT 3 | ||
36 | 35 | ||
37 | class ButtonDialog : public QDialog | 36 | class ButtonDialog : public QDialog |
38 | { | 37 | { |
39 | Q_OBJECT | 38 | Q_OBJECT |
40 | public: | 39 | public: |
41 | ButtonDialog(QString buttonName, QWidget *parent=0, const char*name=0, bool modal=FALSE, WFlags f=0); | 40 | ButtonDialog(QString buttonName, QWidget *parent=0, const char*name=0, bool modal=FALSE, WFlags f=0); |
42 | void setIRSocket(int newfd); | 41 | ~ButtonDialog(); |
43 | const char *readPacket(); | ||
44 | QStringList getRemotes(); | ||
45 | QStringList getButtons(const char *remoteName); | ||
46 | QStringList getList(); | 42 | QStringList getList(); |
47 | QString getLabel(); | 43 | QString getLabel(); |
48 | public slots: | 44 | public slots: |
@@ -53,7 +49,5 @@ private: | |||
53 | QComboBox *button; | 49 | QComboBox *button; |
54 | QStringList list; | 50 | QStringList list; |
55 | QLineEdit *label; | 51 | QLineEdit *label; |
56 | int fd; | 52 | LircHandler *lh; |
57 | int timeout; | ||
58 | struct sockaddr_un addr; | ||
59 | }; | 53 | }; |
diff --git a/noncore/tools/remote/learntab.cpp b/noncore/tools/remote/learntab.cpp index 335a3e9..69d2e7f 100644 --- a/noncore/tools/remote/learntab.cpp +++ b/noncore/tools/remote/learntab.cpp | |||
@@ -21,13 +21,15 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
21 | 21 | ||
22 | LearnTab::LearnTab(QWidget *parent, const char *name):QWidget(parent,name) | 22 | LearnTab::LearnTab(QWidget *parent, const char *name):QWidget(parent,name) |
23 | { | 23 | { |
24 | LircHandler lh; | ||
25 | |||
24 | QVBoxLayout *layout = new QVBoxLayout(this); | 26 | QVBoxLayout *layout = new QVBoxLayout(this); |
25 | QHBoxLayout *bottomLayout = new QHBoxLayout(this); | 27 | QHBoxLayout *bottomLayout = new QHBoxLayout(this); |
26 | 28 | ||
27 | layout->insertSpacing(0,5); | 29 | layout->insertSpacing(0,5); |
28 | remotesBox = new QListBox(this, "remotesBox"); | 30 | remotesBox = new QListBox(this, "remotesBox"); |
29 | layout->insertWidget(0, remotesBox, 1); | 31 | layout->insertWidget(0, remotesBox, 1); |
30 | remotesBox->insertStringList(getRemotes()); | 32 | remotesBox->insertStringList(lh.getRemotes()); |
31 | 33 | ||
32 | layout->insertSpacing(-1,5); | 34 | layout->insertSpacing(-1,5); |
33 | layout->insertLayout(-1, bottomLayout); | 35 | layout->insertLayout(-1, bottomLayout); |
@@ -62,131 +64,3 @@ void LearnTab::edit() | |||
62 | void LearnTab::del() | 64 | void LearnTab::del() |
63 | {} | 65 | {} |
64 | 66 | ||
65 | QStringList LearnTab::getRemotes() | ||
66 | { | ||
67 | const char write_buffer[] = "LIST\n"; | ||
68 | const char *readbuffer; | ||
69 | int i, numlines; | ||
70 | QStringList list; | ||
71 | |||
72 | addr.sun_family=AF_UNIX; | ||
73 | strcpy(addr.sun_path,"/dev/lircd"); | ||
74 | |||
75 | fd = socket(AF_UNIX, SOCK_STREAM, 0); | ||
76 | if(fd == -1) | ||
77 | { | ||
78 | QMessageBox *mb = new QMessageBox("Error!", | ||
79 | "couldnt connect to socket", | ||
80 | QMessageBox::NoIcon, | ||
81 | QMessageBox::Ok, | ||
82 | QMessageBox::NoButton, | ||
83 | QMessageBox::NoButton); | ||
84 | mb->exec(); | ||
85 | perror("LearnTab::GetRemotes"); | ||
86 | return NULL; | ||
87 | } | ||
88 | |||
89 | if(::connect(fd,(struct sockaddr *) &addr, sizeof(addr) ) == -1) | ||
90 | { | ||
91 | QMessageBox *mb = new QMessageBox("Error!", | ||
92 | "couldnt connect to socket", | ||
93 | QMessageBox::NoIcon, | ||
94 | QMessageBox::Ok, | ||
95 | QMessageBox::NoButton, | ||
96 | QMessageBox::NoButton); | ||
97 | mb->exec(); | ||
98 | perror("LearnTab::GetRemotes"); | ||
99 | return NULL; | ||
100 | } | ||
101 | |||
102 | write(fd, write_buffer, strlen(write_buffer)); | ||
103 | |||
104 | for(i=0; i<5; i++) | ||
105 | { | ||
106 | printf("%d\n", i); | ||
107 | readbuffer = readPacket(); | ||
108 | printf("%s", readbuffer); | ||
109 | printf("%d\n", i); | ||
110 | } | ||
111 | |||
112 | numlines = atoi(readbuffer); | ||
113 | |||
114 | for(i=0; i<numlines; i++) | ||
115 | { | ||
116 | list+=readPacket(); | ||
117 | } | ||
118 | |||
119 | if(strcasecmp(readPacket(), "END") != 0) | ||
120 | { | ||
121 | QMessageBox *mb = new QMessageBox("Error!", | ||
122 | "bad packet", | ||
123 | QMessageBox::NoIcon, | ||
124 | QMessageBox::Ok, | ||
125 | QMessageBox::NoButton, | ||
126 | QMessageBox::NoButton); | ||
127 | mb->exec(); | ||
128 | perror("LearnTab::GetRemotes"); | ||
129 | return NULL; | ||
130 | } | ||
131 | |||
132 | ::close(fd); | ||
133 | return list; | ||
134 | } | ||
135 | |||
136 | //this function was ripped for rc.c in xrc, it is available here: http://www.lirc.org/software.html | ||
137 | const char *LearnTab::readPacket() | ||
138 | { | ||
139 | static char buffer[PACKET_SIZE+1]=""; | ||
140 | char *end; | ||
141 | static int ptr=0,end_len=0; | ||
142 | ssize_t ret; | ||
143 | timeout = 0; | ||
144 | |||
145 | if(ptr>0) | ||
146 | { | ||
147 | memmove(buffer,buffer+ptr,strlen(buffer+ptr)+1); | ||
148 | ptr=strlen(buffer); | ||
149 | end=strchr(buffer,'\n'); | ||
150 | } | ||
151 | else | ||
152 | { | ||
153 | end=NULL; | ||
154 | } | ||
155 | alarm(TIMEOUT); | ||
156 | while(end==NULL) | ||
157 | { | ||
158 | if(PACKET_SIZE<=ptr) | ||
159 | { | ||
160 | fprintf(stderr,"bad packet\n"); | ||
161 | ptr=0; | ||
162 | return(NULL); | ||
163 | } | ||
164 | ret=read(fd,buffer+ptr,PACKET_SIZE-ptr); | ||
165 | |||
166 | if(ret<=0 || timeout) | ||
167 | { | ||
168 | if(timeout) | ||
169 | { | ||
170 | fprintf(stderr,"timeout\n"); | ||
171 | } | ||
172 | else | ||
173 | { | ||
174 | alarm(0); | ||
175 | } | ||
176 | ptr=0; | ||
177 | return(NULL); | ||
178 | } | ||
179 | buffer[ptr+ret]=0; | ||
180 | ptr=strlen(buffer); | ||
181 | end=strchr(buffer,'\n'); | ||
182 | } | ||
183 | alarm(0);timeout=0; | ||
184 | |||
185 | end[0]=0; | ||
186 | ptr=strlen(buffer)+1; | ||
187 | //# ifdef DEBUG | ||
188 | //printf("buffer: -%s-\n",buffer); | ||
189 | //# endif | ||
190 | return(buffer); | ||
191 | } | ||
192 | |||
diff --git a/noncore/tools/remote/learntab.h b/noncore/tools/remote/learntab.h index cb84600..c9d8e41 100644 --- a/noncore/tools/remote/learntab.h +++ b/noncore/tools/remote/learntab.h | |||
@@ -32,24 +32,17 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
32 | #include <errno.h> | 32 | #include <errno.h> |
33 | 33 | ||
34 | #include "recorddialog.h" | 34 | #include "recorddialog.h" |
35 | 35 | #include "lirchandler.h" | |
36 | #define PACKET_SIZE 256 | ||
37 | #define TIMEOUT 3 | ||
38 | 36 | ||
39 | class LearnTab : public QWidget | 37 | class LearnTab : public QWidget |
40 | { | 38 | { |
41 | Q_OBJECT | 39 | Q_OBJECT |
42 | public: | 40 | public: |
43 | LearnTab(QWidget *parent=0, const char *name=0); | 41 | LearnTab(QWidget *parent=0, const char *name=0); |
44 | const char *readPacket(); | ||
45 | QStringList getRemotes(); | ||
46 | public slots: | 42 | public slots: |
47 | void add(); | 43 | void add(); |
48 | void edit(); | 44 | void edit(); |
49 | void del(); | 45 | void del(); |
50 | private: | 46 | private: |
51 | QListBox *remotesBox; | 47 | QListBox *remotesBox; |
52 | int fd; | ||
53 | int timeout; | ||
54 | struct sockaddr_un addr; | ||
55 | }; | 48 | }; |
diff --git a/noncore/tools/remote/lirchandler.cpp b/noncore/tools/remote/lirchandler.cpp new file mode 100644 index 0000000..f44806e --- a/dev/null +++ b/noncore/tools/remote/lirchandler.cpp | |||
@@ -0,0 +1,270 @@ | |||
1 | /* | ||
2 | Opie-Remote. emulates remote controls on an iPaq (and maybe a Zaurus) in Opie. | ||
3 | Copyright (C) 2007 Paul Eggleton & Thomas Stephens | ||
4 | |||
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 | ||
7 | version. | ||
8 | |||
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 | ||
11 | Public License for more details. | ||
12 | |||
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 | ||
15 | */ | ||
16 | |||
17 | #include <stdio.h> | ||
18 | #include <stdlib.h> | ||
19 | #include <string.h> | ||
20 | #include <sys/socket.h> | ||
21 | #include <sys/types.h> | ||
22 | #include <sys/un.h> | ||
23 | #include <unistd.h> | ||
24 | #include <errno.h> | ||
25 | |||
26 | #include <qstring.h> | ||
27 | #include <qmessagebox.h> | ||
28 | #include <qobject.h> | ||
29 | #include <opie2/oprocess.h> | ||
30 | |||
31 | #include "lirchandler.h" | ||
32 | |||
33 | #define PACKET_SIZE 256 | ||
34 | #define TIMEOUT 3 | ||
35 | #define LIRCD_SOCKET "/dev/lircd" | ||
36 | #define LIRCD_SERVICECMD "/etc/init.d/lircd" | ||
37 | |||
38 | using namespace Opie::Core; | ||
39 | |||
40 | LircHandler::LircHandler(void) | ||
41 | { | ||
42 | fd = 0; | ||
43 | addr.sun_family=AF_UNIX; | ||
44 | strcpy(addr.sun_path, LIRCD_SOCKET); | ||
45 | } | ||
46 | |||
47 | bool LircHandler::connectLirc(void) | ||
48 | { | ||
49 | fd = socket(AF_UNIX, SOCK_STREAM, 0); | ||
50 | if(fd == -1) | ||
51 | { | ||
52 | QMessageBox *mb = new QMessageBox(QObject::tr("Error"), | ||
53 | QObject::tr("Unable to create socket"), | ||
54 | QMessageBox::Critical, | ||
55 | QMessageBox::Ok, | ||
56 | QMessageBox::NoButton, | ||
57 | QMessageBox::NoButton); | ||
58 | mb->exec(); | ||
59 | perror("LircHandler::connectLirc"); | ||
60 | return false; | ||
61 | } | ||
62 | |||
63 | if(::connect(fd,(struct sockaddr *) &addr, sizeof(addr) ) == -1) | ||
64 | { | ||
65 | QMessageBox *mb = new QMessageBox(QObject::tr("Error"), | ||
66 | QObject::tr("Could not connect to lircd"), | ||
67 | QMessageBox::Critical, | ||
68 | QMessageBox::Ok, | ||
69 | QMessageBox::NoButton, | ||
70 | QMessageBox::NoButton); | ||
71 | mb->exec(); | ||
72 | perror("LircHandler::connectLirc"); | ||
73 | return false; | ||
74 | } | ||
75 | |||
76 | return true; | ||
77 | } | ||
78 | |||
79 | //this function was ripped for rc.c in xrc, it is available here: http://www.lirc.org/software.html | ||
80 | const char *LircHandler::readPacket() | ||
81 | { | ||
82 | static char buffer[PACKET_SIZE+1]=""; | ||
83 | char *end; | ||
84 | static int ptr=0; | ||
85 | ssize_t ret; | ||
86 | int timeout = 0; | ||
87 | |||
88 | if(ptr>0) | ||
89 | { | ||
90 | memmove(buffer,buffer+ptr,strlen(buffer+ptr)+1); | ||
91 | ptr=strlen(buffer); | ||
92 | end=strchr(buffer,'\n'); | ||
93 | } | ||
94 | else | ||
95 | { | ||
96 | end=NULL; | ||
97 | } | ||
98 | alarm(TIMEOUT); | ||
99 | while(end==NULL) | ||
100 | { | ||
101 | if(PACKET_SIZE<=ptr) | ||
102 | { | ||
103 | fprintf(stderr,"readPacket: bad packet\n"); | ||
104 | ptr=0; | ||
105 | return(NULL); | ||
106 | } | ||
107 | ret=read(fd,buffer+ptr,PACKET_SIZE-ptr); | ||
108 | |||
109 | if(ret<=0 || timeout) | ||
110 | { | ||
111 | if(timeout) | ||
112 | { | ||
113 | fprintf(stderr,"readPacket: timeout\n"); | ||
114 | } | ||
115 | else | ||
116 | { | ||
117 | alarm(0); | ||
118 | } | ||
119 | ptr=0; | ||
120 | return(NULL); | ||
121 | } | ||
122 | buffer[ptr+ret]=0; | ||
123 | ptr=strlen(buffer); | ||
124 | end=strchr(buffer,'\n'); | ||
125 | } | ||
126 | alarm(0); | ||
127 | |||
128 | end[0]=0; | ||
129 | ptr=strlen(buffer)+1; | ||
130 | //# ifdef DEBUG | ||
131 | //printf("buffer: -%s-\n",buffer); | ||
132 | //# endif | ||
133 | return(buffer); | ||
134 | } | ||
135 | |||
136 | QStringList LircHandler::getRemotes(void) | ||
137 | { | ||
138 | const char write_buffer[] = "LIST\n"; | ||
139 | const char *readbuffer; | ||
140 | int i, numlines; | ||
141 | QStringList list; | ||
142 | |||
143 | if(connectLirc()) { | ||
144 | write(fd, write_buffer, strlen(write_buffer) ); | ||
145 | |||
146 | for(i=0; i<5; i++) | ||
147 | { | ||
148 | readbuffer = readPacket(); | ||
149 | } | ||
150 | |||
151 | numlines = atoi(readbuffer); | ||
152 | |||
153 | for(i=0; i<numlines; i++) | ||
154 | { | ||
155 | list+=readPacket(); | ||
156 | } | ||
157 | |||
158 | if(strcasecmp(readPacket(), "END") != 0) | ||
159 | { | ||
160 | QMessageBox *mb = new QMessageBox(QObject::tr("Error"), | ||
161 | QObject::tr("Bad packet while communicating with lircd"), | ||
162 | QMessageBox::Critical, | ||
163 | QMessageBox::Ok, | ||
164 | QMessageBox::NoButton, | ||
165 | QMessageBox::NoButton); | ||
166 | mb->exec(); | ||
167 | perror("LircHandler::getRemotes"); | ||
168 | return NULL; | ||
169 | } | ||
170 | |||
171 | ::close(fd); | ||
172 | } | ||
173 | |||
174 | return list; | ||
175 | } | ||
176 | |||
177 | QStringList LircHandler::getButtons(const char *remoteName) | ||
178 | { | ||
179 | QString write_buffer = "LIST "; | ||
180 | const char *readbuffer; | ||
181 | int i, j, numlines; | ||
182 | QStringList list; | ||
183 | QString string; | ||
184 | |||
185 | write_buffer += remoteName; | ||
186 | write_buffer += '\n'; | ||
187 | |||
188 | if(connectLirc()) { | ||
189 | write(fd, write_buffer.latin1(), strlen(write_buffer) ); | ||
190 | |||
191 | for(i=0; i<5; i++) | ||
192 | { | ||
193 | readbuffer = readPacket(); | ||
194 | } | ||
195 | |||
196 | numlines = atoi(readbuffer); | ||
197 | |||
198 | for(i=0; i<numlines; i++) | ||
199 | { | ||
200 | list+=readPacket(); | ||
201 | for(j=0; j<list[i].length(); j++) | ||
202 | { | ||
203 | if(list[i][j] == ' ') | ||
204 | break; | ||
205 | } | ||
206 | list[i].remove(0, j+1); | ||
207 | } | ||
208 | |||
209 | if(strcasecmp(readPacket(), "END") != 0) | ||
210 | { | ||
211 | QMessageBox *mb = new QMessageBox(QObject::tr("Error"), | ||
212 | QObject::tr("Bad packet while communicating with lircd"), | ||
213 | QMessageBox::Critical, | ||
214 | QMessageBox::Ok, | ||
215 | QMessageBox::NoButton, | ||
216 | QMessageBox::NoButton); | ||
217 | mb->exec(); | ||
218 | perror("LircHandler::getRemotes"); | ||
219 | return NULL; | ||
220 | } | ||
221 | |||
222 | ::close(fd); | ||
223 | } | ||
224 | |||
225 | return list; | ||
226 | } | ||
227 | |||
228 | int LircHandler::sendIR(const char *irbutton) | ||
229 | { | ||
230 | const char *read_buffer; | ||
231 | bool done=false; | ||
232 | |||
233 | if(connectLirc()) { | ||
234 | printf("fd2: %d\n", fd); | ||
235 | printf("%s", irbutton); | ||
236 | |||
237 | printf("1\n"); | ||
238 | printf("%d\n", write(fd, irbutton, strlen(irbutton) ) ); | ||
239 | printf("2\n"); | ||
240 | while(!done) | ||
241 | { | ||
242 | read_buffer=readPacket(); | ||
243 | printf("%s\n", read_buffer); | ||
244 | if(strcasecmp(read_buffer, "END") == 0) | ||
245 | { | ||
246 | printf("done reading packet\n"); | ||
247 | done=true; | ||
248 | } | ||
249 | } | ||
250 | ::close(fd); | ||
251 | return 1; | ||
252 | } | ||
253 | else | ||
254 | return 0; | ||
255 | } | ||
256 | |||
257 | bool LircHandler::startLircd(void) | ||
258 | { | ||
259 | return (system(LIRCD_SERVICECMD " start") == 0); | ||
260 | } | ||
261 | |||
262 | bool LircHandler::stopLircd(void) | ||
263 | { | ||
264 | return (system(LIRCD_SERVICECMD " stop") == 0); | ||
265 | } | ||
266 | |||
267 | bool LircHandler::isLircdRunning(void) | ||
268 | { | ||
269 | return (OProcess::processPID("lircd") != 0); | ||
270 | } | ||
diff --git a/noncore/tools/remote/lirchandler.h b/noncore/tools/remote/lirchandler.h new file mode 100644 index 0000000..29894b4 --- a/dev/null +++ b/noncore/tools/remote/lirchandler.h | |||
@@ -0,0 +1,38 @@ | |||
1 | /* | ||
2 | Opie-Remote. emulates remote controls on an iPaq (and maybe a Zaurus) in Opie. | ||
3 | Copyright (C) 2007 Paul Eggleton & Thomas Stephens | ||
4 | |||
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 | ||
7 | version. | ||
8 | |||
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 | ||
11 | Public License for more details. | ||
12 | |||
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 | ||
15 | */ | ||
16 | |||
17 | #ifndef LIRCHANDLER_H | ||
18 | #define LIRCHANDLER_H | ||
19 | |||
20 | class LircHandler | ||
21 | { | ||
22 | private: | ||
23 | bool connectLirc(void); | ||
24 | const char *readPacket(); | ||
25 | |||
26 | struct sockaddr_un addr; | ||
27 | int fd; | ||
28 | public: | ||
29 | LircHandler(void); | ||
30 | QStringList getRemotes(void); | ||
31 | QStringList getButtons(const char *remoteName); | ||
32 | int sendIR(const char *irbutton); | ||
33 | bool startLircd(void); | ||
34 | bool stopLircd(void); | ||
35 | bool isLircdRunning(void); | ||
36 | }; | ||
37 | |||
38 | #endif | ||
diff --git a/noncore/tools/remote/mainview.cpp b/noncore/tools/remote/mainview.cpp index 724eba9..8c87785 100644 --- a/noncore/tools/remote/mainview.cpp +++ b/noncore/tools/remote/mainview.cpp | |||
@@ -34,8 +34,6 @@ MainView::MainView(QWidget *parent, const char *name) : QWidget(parent, name) | |||
34 | help = new HelpTab(tabs); | 34 | help = new HelpTab(tabs); |
35 | connect(config, SIGNAL(remotesChanged()), this, SLOT(updateRemotesList()) ); | 35 | connect(config, SIGNAL(remotesChanged()), this, SLOT(updateRemotesList()) ); |
36 | 36 | ||
37 | remote->setIRSocket(fd); | ||
38 | |||
39 | tabs->addTab(remote, tr("Remote") ); | 37 | tabs->addTab(remote, tr("Remote") ); |
40 | tabs->addTab(learn,tr("Learn") ); | 38 | tabs->addTab(learn,tr("Learn") ); |
41 | tabs->addTab(config,tr("Config") ); | 39 | tabs->addTab(config,tr("Config") ); |
@@ -49,17 +47,6 @@ MainView::MainView(QWidget *parent, const char *name) : QWidget(parent, name) | |||
49 | config->setConfig(cfg); | 47 | config->setConfig(cfg); |
50 | } | 48 | } |
51 | 49 | ||
52 | int MainView::getIRSocket() | ||
53 | { | ||
54 | return fd; | ||
55 | } | ||
56 | |||
57 | void MainView::setIRSocket(int newfd) | ||
58 | { | ||
59 | fd = newfd; | ||
60 | remote->setIRSocket(fd); | ||
61 | } | ||
62 | |||
63 | void MainView::updateRemotesList() | 50 | void MainView::updateRemotesList() |
64 | { | 51 | { |
65 | remote->updateRemotesList(); | 52 | remote->updateRemotesList(); |
diff --git a/noncore/tools/remote/mainview.h b/noncore/tools/remote/mainview.h index 7ea82a6..b1ddde4 100644 --- a/noncore/tools/remote/mainview.h +++ b/noncore/tools/remote/mainview.h | |||
@@ -41,12 +41,9 @@ class MainView : public QWidget | |||
41 | Q_OBJECT | 41 | Q_OBJECT |
42 | public: | 42 | public: |
43 | MainView(QWidget *parent=0, const char *name=0); | 43 | MainView(QWidget *parent=0, const char *name=0); |
44 | int getIRSocket(); | ||
45 | void setIRSocket(int newfd); | ||
46 | public slots: | 44 | public slots: |
47 | void updateRemotesList(); | 45 | void updateRemotesList(); |
48 | private: | 46 | private: |
49 | int fd; | ||
50 | RemoteTab *remote; | 47 | RemoteTab *remote; |
51 | ConfigTab *config; | 48 | ConfigTab *config; |
52 | LearnTab *learn; | 49 | LearnTab *learn; |
diff --git a/noncore/tools/remote/packetread.h b/noncore/tools/remote/packetread.h deleted file mode 100644 index 5dc1ad4..0000000 --- a/noncore/tools/remote/packetread.h +++ b/dev/null | |||
@@ -1,200 +0,0 @@ | |||
1 | /* | ||
2 | Opie-Remote. emulates remote controlls on an iPaq (and maybe a Zaurus) in Opie. | ||
3 | Copyright (C) 2002 Thomas Stephens | ||
4 | |||
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 | ||
7 | version. | ||
8 | |||
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 | ||
11 | Public License for more details. | ||
12 | |||
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 | ||
15 | |||
16 | file not used | ||
17 | */ | ||
18 | |||
19 | #include <stdio.h> | ||
20 | #include <stdlib.h> | ||
21 | #include <string.h> | ||
22 | #include <sys/socket.h> | ||
23 | #include <sys/types.h> | ||
24 | #include <sys/un.h> | ||
25 | #include <unistd.h> | ||
26 | #include <errno.h> | ||
27 | |||
28 | #define PACKET_SIZE 256 | ||
29 | #define TIMEOUT 3 | ||
30 | |||
31 | //this function was ripped for rc.c in xrc, it is available here: http://www.lirc.org/software.html | ||
32 | const char *readPacket(int fd) | ||
33 | { | ||
34 | static char buffer[PACKET_SIZE+1]=""; | ||
35 | char *end; | ||
36 | static int ptr=0,end_len=0; | ||
37 | ssize_t ret; | ||
38 | |||
39 | if(ptr>0) | ||
40 | { | ||
41 | memmove(buffer,buffer+ptr,strlen(buffer+ptr)+1); | ||
42 | ptr=strlen(buffer); | ||
43 | end=strchr(buffer,'\n'); | ||
44 | } | ||
45 | else | ||
46 | { | ||
47 | end=NULL; | ||
48 | } | ||
49 | alarm(TIMEOUT); | ||
50 | while(end==NULL) | ||
51 | { | ||
52 | if(PACKET_SIZE<=ptr) | ||
53 | { | ||
54 | // fprintf(stderr,"%s: bad packet\n",progname); | ||
55 | ptr=0; | ||
56 | return(NULL); | ||
57 | } | ||
58 | ret=read(fd,buffer+ptr,PACKET_SIZE-ptr); | ||
59 | |||
60 | if(ret<=0 || timeout) | ||
61 | { | ||
62 | if(timeout) | ||
63 | { | ||
64 | // fprintf(stderr,"%s: timeout\n",progname); | ||
65 | } | ||
66 | else | ||
67 | { | ||
68 | alarm(0); | ||
69 | } | ||
70 | ptr=0; | ||
71 | return(NULL); | ||
72 | } | ||
73 | buffer[ptr+ret]=0; | ||
74 | ptr=strlen(buffer); | ||
75 | end=strchr(buffer,'\n'); | ||
76 | } | ||
77 | alarm(0);timeout=0; | ||
78 | |||
79 | end[0]=0; | ||
80 | ptr=strlen(buffer)+1; | ||
81 | //# ifdef DEBUG | ||
82 | //printf("buffer: -%s-\n",buffer); | ||
83 | //# endif | ||
84 | return(buffer); | ||
85 | } | ||
86 | QStringList getRemotes(int fd) | ||
87 | { | ||
88 | const char write_buffer[] = "LIST\n"; | ||
89 | const char *readbuffer; | ||
90 | int i, numlines; | ||
91 | QStringList list; | ||
92 | |||
93 | fd = socket(AF_UNIX, SOCK_STREAM, 0); | ||
94 | |||
95 | if(std::connect(fd,(struct sockaddr *) &addr, sizeof(addr) ) == -1) | ||
96 | { | ||
97 | QMessageBox *mb = new QMessageBox("Error!", | ||
98 | "couldnt connect to socket", | ||
99 | QMessageBox::NoIcon, | ||
100 | QMessageBox::Ok, | ||
101 | QMessageBox::NoButton, | ||
102 | QMessageBox::NoButton); | ||
103 | mb->exec(); | ||
104 | perror("ConfigTab::GetRemotes"); | ||
105 | return NULL; | ||
106 | } | ||
107 | |||
108 | write(fd, write_buffer, strlen(write_buffer) ); | ||
109 | |||
110 | for(i=0; i<5; i++) | ||
111 | { | ||
112 | readbuffer = readPacket(int fd); | ||
113 | } | ||
114 | |||
115 | numlines = atoi(readbuffer); | ||
116 | |||
117 | for(i=0; i<numlines; i++) | ||
118 | { | ||
119 | list+=readPacket(); | ||
120 | } | ||
121 | |||
122 | if(strcasecmp(readPacket(), "END") != 0) | ||
123 | { | ||
124 | QMessageBox *mb = new QMessageBox("Error!", | ||
125 | "bad packet", | ||
126 | QMessageBox::NoIcon, | ||
127 | QMessageBox::Ok, | ||
128 | QMessageBox::NoButton, | ||
129 | QMessageBox::NoButton); | ||
130 | mb->exec(); | ||
131 | perror("ConfigTab::GetRemotes"); | ||
132 | return NULL; | ||
133 | } | ||
134 | |||
135 | std::close(fd); | ||
136 | return list; | ||
137 | } | ||
138 | |||
139 | QStringList getButtons(int fd, const char *remoteName) | ||
140 | { | ||
141 | QString write_buffer = "LIST "; | ||
142 | const char *readbuffer; | ||
143 | int i, j, numlines; | ||
144 | QStringList list; | ||
145 | QString string; | ||
146 | |||
147 | write_buffer += remoteName; | ||
148 | write_buffer += '\n'; | ||
149 | |||
150 | fd = socket(AF_UNIX, SOCK_STREAM, 0); | ||
151 | |||
152 | if(std::connect(fd,(struct sockaddr *) &addr, sizeof(addr) ) == -1) | ||
153 | { | ||
154 | QMessageBox *mb = new QMessageBox("Error!", | ||
155 | "couldnt connect to socket", | ||
156 | QMessageBox::NoIcon, | ||
157 | QMessageBox::Ok, | ||
158 | QMessageBox::NoButton, | ||
159 | QMessageBox::NoButton); | ||
160 | mb->exec(); | ||
161 | perror("ConfigTab::GetRemotes"); | ||
162 | return NULL; | ||
163 | } | ||
164 | |||
165 | write(fd, write_buffer.latin1(), strlen(write_buffer) ); | ||
166 | |||
167 | for(i=0; i<5; i++) | ||
168 | { | ||
169 | readbuffer = readPacket(); | ||
170 | } | ||
171 | |||
172 | numlines = atoi(readbuffer); | ||
173 | |||
174 | for(i=0; i<numlines; i++) | ||
175 | { | ||
176 | list+=readPacket(); | ||
177 | for(j=0; j<list[i].length(); j++) | ||
178 | { | ||
179 | if(list[i][j] == ' ') | ||
180 | break; | ||
181 | } | ||
182 | list[i].remove(0, j+1); | ||
183 | } | ||
184 | |||
185 | if(strcasecmp(readPacket(), "END") != 0) | ||
186 | { | ||
187 | QMessageBox *mb = new QMessageBox("Error!", | ||
188 | "bad packet", | ||
189 | QMessageBox::NoIcon, | ||
190 | QMessageBox::Ok, | ||
191 | QMessageBox::NoButton, | ||
192 | QMessageBox::NoButton); | ||
193 | mb->exec(); | ||
194 | perror("ConfigTab::GetRemotes"); | ||
195 | return NULL; | ||
196 | } | ||
197 | |||
198 | std::close(fd); | ||
199 | return list; | ||
200 | } | ||
diff --git a/noncore/tools/remote/remote.cpp b/noncore/tools/remote/remote.cpp index 35d06bc..67fc57d 100644 --- a/noncore/tools/remote/remote.cpp +++ b/noncore/tools/remote/remote.cpp | |||
@@ -37,69 +37,24 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
37 | #include <signal.h> | 37 | #include <signal.h> |
38 | 38 | ||
39 | 39 | ||
40 | /*void reconnect(int &fd) | ||
41 | { | ||
42 | //struct sockaddr_un addr; | ||
43 | |||
44 | addr.sun_family=AF_UNIX; | ||
45 | strcpy(addr.sun_path,"/dev/lircd"); | ||
46 | fd = socket(AF_UNIX, SOCK_STREAM, 0); | ||
47 | |||
48 | if(connect(fd,(struct sockaddr *) &addr, sizeof(addr) ) == -1) | ||
49 | { | ||
50 | QMessageBox *mb = new QMessageBox("error", | ||
51 | "couldnt connect to socket", | ||
52 | QMessageBox::NoIcon, | ||
53 | QMessageBox::Ok, | ||
54 | QMessageBox::NoButton, | ||
55 | QMessageBox::NoButton); | ||
56 | mb->exec(); | ||
57 | } | ||
58 | } | ||
59 | */ | ||
60 | |||
61 | int main( int argc, char **argv ) | 40 | int main( int argc, char **argv ) |
62 | { | 41 | { |
63 | QPEApplication a( argc, argv ); | 42 | QPEApplication a( argc, argv ); |
64 | MainView w; | 43 | MainView w; |
65 | |||
66 | int fd; | ||
67 | //struct sockaddr_un addr; | ||
68 | //char read_buffer[BUFFERSIZE+1]; | ||
69 | //char write_buffer[] = "LIST\n"; | ||
70 | |||
71 | //addr.sun_family=AF_UNIX; | ||
72 | //strcpy(addr.sun_path,"/dev/lircd"); | ||
73 | //fd = socket(AF_UNIX, SOCK_STREAM, 0); | ||
74 | |||
75 | //printf("fd1: %d\n", fd); | ||
76 | /* | ||
77 | if(connect(fd,(struct sockaddr *) &addr, sizeof(addr) ) == -1) | ||
78 | { | ||
79 | QMessageBox *mb = new QMessageBox("error", | ||
80 | "couldnt connect to socket", | ||
81 | QMessageBox::NoIcon, | ||
82 | QMessageBox::Ok, | ||
83 | QMessageBox::NoButton, | ||
84 | QMessageBox::NoButton); | ||
85 | mb->exec(); | ||
86 | } | ||
87 | */ | ||
88 | |||
89 | //printf("%d\n", write(fd, write_buffer, sizeof(write_buffer) ) ); | ||
90 | |||
91 | //printf("%d\n", read(fd, read_buffer, BUFFERSIZE ) ); | ||
92 | |||
93 | //QMessageBox *mbtest = new QMessageBox("lirc test", | ||
94 | // *new QString((const char *) read_buffer), | ||
95 | // QMessageBox::NoIcon, | ||
96 | // QMessageBox::Ok, | ||
97 | // QMessageBox::NoButton, | ||
98 | // QMessageBox::NoButton); | ||
99 | //mbtest->exec(); | ||
100 | |||
101 | a.setMainWidget( &w ); | 44 | a.setMainWidget( &w ); |
102 | w.setIRSocket(fd); | ||
103 | QPEApplication::showWidget( &w ); | 45 | QPEApplication::showWidget( &w ); |
104 | return a.exec(); | 46 | |
47 | LircHandler lh; | ||
48 | if(!lh.isLircdRunning()) { | ||
49 | QMessageBox mb("Error!", | ||
50 | "Lircd is not running", | ||
51 | QMessageBox::NoIcon, | ||
52 | QMessageBox::Ok, | ||
53 | QMessageBox::NoButton, | ||
54 | QMessageBox::NoButton); | ||
55 | mb.exec(); | ||
56 | |||
57 | } | ||
58 | |||
59 | return a.exec(); | ||
105 | } | 60 | } |
diff --git a/noncore/tools/remote/remote.pro b/noncore/tools/remote/remote.pro index 880856c..59ea81b 100644 --- a/noncore/tools/remote/remote.pro +++ b/noncore/tools/remote/remote.pro | |||
@@ -1,8 +1,8 @@ | |||
1 | TEMPLATE=app | 1 | TEMPLATE=app |
2 | CONFIG +=qt warn_on | 2 | CONFIG +=qt warn_on |
3 | DESTDIR =$(OPIEDIR)/bin | 3 | DESTDIR =$(OPIEDIR)/bin |
4 | HEADERS = remotetab.h learntab.h configtab.h topgroup.h dvdgroup.h channelgroup.h vcrgroup.h buttondialog.h topgroupconf.h dvdgroupconf.h channelgroupconf.h vcrgroupconf.h mainview.h recorddialog.h helptab.h | 4 | HEADERS = remotetab.h learntab.h configtab.h topgroup.h dvdgroup.h channelgroup.h vcrgroup.h buttondialog.h topgroupconf.h dvdgroupconf.h channelgroupconf.h vcrgroupconf.h mainview.h recorddialog.h helptab.h lirchandler.h |
5 | SOURCES =remote.cpp remotetab.cpp learntab.cpp configtab.cpp topgroup.cpp dvdgroup.cpp channelgroup.cpp vcrgroup.cpp buttondialog.cpp topgroupconf.cpp dvdgroupconf.cpp channelgroupconf.cpp vcrgroupconf.cpp mainview.cpp recorddialog.cpp helptab.cpp | 5 | SOURCES =remote.cpp remotetab.cpp learntab.cpp configtab.cpp topgroup.cpp dvdgroup.cpp channelgroup.cpp vcrgroup.cpp buttondialog.cpp topgroupconf.cpp dvdgroupconf.cpp channelgroupconf.cpp vcrgroupconf.cpp mainview.cpp recorddialog.cpp helptab.cpp lirchandler.cpp |
6 | INCLUDEPATH+=$(OPIEDIR)/include | 6 | INCLUDEPATH+=$(OPIEDIR)/include |
7 | DEPENDPATH+=$(OPIEDIR)/include | 7 | DEPENDPATH+=$(OPIEDIR)/include |
8 | LIBS +=-lqpe -lopiecore2 | 8 | LIBS +=-lqpe -lopiecore2 |
diff --git a/noncore/tools/remote/remotetab.cpp b/noncore/tools/remote/remotetab.cpp index 5b02e94..84038ca 100644 --- a/noncore/tools/remote/remotetab.cpp +++ b/noncore/tools/remote/remotetab.cpp | |||
@@ -15,6 +15,7 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
15 | */ | 15 | */ |
16 | 16 | ||
17 | #include "remotetab.h" | 17 | #include "remotetab.h" |
18 | #include "lirchandler.h" | ||
18 | 19 | ||
19 | RemoteTab::RemoteTab(QWidget *parent, const char *name):QWidget(parent,name) | 20 | RemoteTab::RemoteTab(QWidget *parent, const char *name):QWidget(parent,name) |
20 | { | 21 | { |
@@ -44,11 +45,6 @@ RemoteTab::RemoteTab(QWidget *parent, const char *name):QWidget(parent,name) | |||
44 | layout->addWidget(channelGroup, 0, 0); | 45 | layout->addWidget(channelGroup, 0, 0); |
45 | 46 | ||
46 | this->setMaximumWidth(240); | 47 | this->setMaximumWidth(240); |
47 | |||
48 | timeout = 0; | ||
49 | |||
50 | addr.sun_family=AF_UNIX; | ||
51 | strcpy(addr.sun_path,"/dev/lircd"); | ||
52 | } | 48 | } |
53 | 49 | ||
54 | int RemoteTab::sendIR() | 50 | int RemoteTab::sendIR() |
@@ -56,119 +52,9 @@ int RemoteTab::sendIR() | |||
56 | const QObject *button = sender(); | 52 | const QObject *button = sender(); |
57 | QString string = cfg->readEntry(button->name()); | 53 | QString string = cfg->readEntry(button->name()); |
58 | string+='\n'; | 54 | string+='\n'; |
59 | const char *write_buffer = string.latin1(); | 55 | |
60 | const char *read_buffer; | 56 | LircHandler lh; |
61 | bool done=false; | 57 | return lh.sendIR(string.latin1()); |
62 | |||
63 | fd = socket(AF_UNIX, SOCK_STREAM, 0); | ||
64 | if(fd == -1) | ||
65 | { | ||
66 | QMessageBox *mb = new QMessageBox("Error!", | ||
67 | "couldnt connect to socket", | ||
68 | QMessageBox::NoIcon, | ||
69 | QMessageBox::Ok, | ||
70 | QMessageBox::NoButton, | ||
71 | QMessageBox::NoButton); | ||
72 | mb->exec(); | ||
73 | perror("RemoteTab::SendIR"); | ||
74 | return 0; | ||
75 | } | ||
76 | |||
77 | |||
78 | if(::connect(fd,(struct sockaddr *) &addr, sizeof(addr) ) == -1) | ||
79 | { | ||
80 | QMessageBox *mb = new QMessageBox("Error!", | ||
81 | "couldnt connect to socket", | ||
82 | QMessageBox::NoIcon, | ||
83 | QMessageBox::Ok, | ||
84 | QMessageBox::NoButton, | ||
85 | QMessageBox::NoButton); | ||
86 | mb->exec(); | ||
87 | perror("RemoteTab::SendIR"); | ||
88 | } | ||
89 | |||
90 | printf("fd2: %d\n", fd); | ||
91 | printf("%s", write_buffer); | ||
92 | |||
93 | printf("1\n"); | ||
94 | printf("%d\n", write(fd, write_buffer, strlen(write_buffer) ) ); | ||
95 | printf("2\n"); | ||
96 | while(!done) | ||
97 | { | ||
98 | read_buffer=readPacket(); | ||
99 | printf("%s\n", read_buffer); | ||
100 | if(strcasecmp(read_buffer, "END") == 0) | ||
101 | { | ||
102 | printf("done reading packet\n"); | ||
103 | done=true; | ||
104 | } | ||
105 | } | ||
106 | ::close(fd); | ||
107 | } | ||
108 | |||
109 | // printf("%s\n", readPacket()); | ||
110 | // printf("%d\n", read(fd, read_buffer,sizeof(read_buffer)) ); | ||
111 | // printf("%s", read_buffer); | ||
112 | |||
113 | //this function was ripped for rc.c in xrc, it is available here: http://www.lirc.org/software.html | ||
114 | const char *RemoteTab::readPacket() | ||
115 | { | ||
116 | static char buffer[PACKET_SIZE+1]=""; | ||
117 | char *end; | ||
118 | static int ptr=0,end_len=0; | ||
119 | ssize_t ret; | ||
120 | |||
121 | if(ptr>0) | ||
122 | { | ||
123 | memmove(buffer,buffer+ptr,strlen(buffer+ptr)+1); | ||
124 | ptr=strlen(buffer); | ||
125 | end=strchr(buffer,'\n'); | ||
126 | } | ||
127 | else | ||
128 | { | ||
129 | end=NULL; | ||
130 | } | ||
131 | alarm(TIMEOUT); | ||
132 | while(end==NULL) | ||
133 | { | ||
134 | if(PACKET_SIZE<=ptr) | ||
135 | { | ||
136 | // fprintf(stderr,"%s: bad packet\n",progname); | ||
137 | ptr=0; | ||
138 | return(NULL); | ||
139 | } | ||
140 | ret=read(fd,buffer+ptr,PACKET_SIZE-ptr); | ||
141 | |||
142 | if(ret<=0 || timeout) | ||
143 | { | ||
144 | if(timeout) | ||
145 | { | ||
146 | // fprintf(stderr,"%s: timeout\n",progname); | ||
147 | } | ||
148 | else | ||
149 | { | ||
150 | alarm(0); | ||
151 | } | ||
152 | ptr=0; | ||
153 | return(NULL); | ||
154 | } | ||
155 | buffer[ptr+ret]=0; | ||
156 | ptr=strlen(buffer); | ||
157 | end=strchr(buffer,'\n'); | ||
158 | } | ||
159 | alarm(0);timeout=0; | ||
160 | |||
161 | end[0]=0; | ||
162 | ptr=strlen(buffer)+1; | ||
163 | //# ifdef DEBUG | ||
164 | //printf("buffer: -%s-\n",buffer); | ||
165 | //# endif | ||
166 | return(buffer); | ||
167 | } | ||
168 | |||
169 | void RemoteTab::setIRSocket(int newfd) | ||
170 | { | ||
171 | fd = newfd; | ||
172 | } | 58 | } |
173 | 59 | ||
174 | void RemoteTab::setConfig(Config *newCfg) | 60 | void RemoteTab::setConfig(Config *newCfg) |
diff --git a/noncore/tools/remote/remotetab.h b/noncore/tools/remote/remotetab.h index 38b58e9..da0a543 100644 --- a/noncore/tools/remote/remotetab.h +++ b/noncore/tools/remote/remotetab.h | |||
@@ -37,15 +37,11 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
37 | #include "channelgroup.h" | 37 | #include "channelgroup.h" |
38 | #include "vcrgroup.h" | 38 | #include "vcrgroup.h" |
39 | 39 | ||
40 | #define PACKET_SIZE 256 | ||
41 | #define TIMEOUT 3 | ||
42 | |||
43 | class RemoteTab : public QWidget | 40 | class RemoteTab : public QWidget |
44 | { | 41 | { |
45 | Q_OBJECT | 42 | Q_OBJECT |
46 | public: | 43 | public: |
47 | RemoteTab(QWidget *parent=0, const char *name=0); | 44 | RemoteTab(QWidget *parent=0, const char *name=0); |
48 | void setIRSocket(int newfd); | ||
49 | const char *readPacket(); | 45 | const char *readPacket(); |
50 | void setConfig(Config *newCfg); | 46 | void setConfig(Config *newCfg); |
51 | void updateRemotesList(); | 47 | void updateRemotesList(); |
@@ -53,9 +49,6 @@ public slots: | |||
53 | int sendIR(); | 49 | int sendIR(); |
54 | void remoteSelected(const QString &string); | 50 | void remoteSelected(const QString &string); |
55 | private: | 51 | private: |
56 | int fd; | ||
57 | int timeout; | ||
58 | struct sockaddr_un addr; | ||
59 | Config *cfg; | 52 | Config *cfg; |
60 | TopGroup *topGroup; | 53 | TopGroup *topGroup; |
61 | DVDGroup *dvdGroup; | 54 | DVDGroup *dvdGroup; |