author | paule <paule> | 2007-01-28 04:04:14 (UTC) |
---|---|---|
committer | paule <paule> | 2007-01-28 04:04:14 (UTC) |
commit | ec2309cb69365847762db542c41951629cd06cbe (patch) (side-by-side diff) | |
tree | 2f0101c1f0d6268207dbd15eb21f40c812a4fff5 | |
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 | 61 | ||||
-rw-r--r-- | noncore/tools/remote/remote.pro | 4 | ||||
-rw-r--r-- | noncore/tools/remote/remotetab.cpp | 120 | ||||
-rw-r--r-- | noncore/tools/remote/remotetab.h | 7 |
13 files changed, 337 insertions, 748 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 @@ -35,4 +35,6 @@ ButtonDialog::ButtonDialog(QString buttonName, QWidget *parent, const char*name, layout->addSpacing(5); + lh = new LircHandler(); + remote = new QComboBox(false, this, "remote"); QLabel *remoteLabel = new QLabel(remote, "Remote: ", this, "remoteLabel"); @@ -43,5 +45,5 @@ ButtonDialog::ButtonDialog(QString buttonName, QWidget *parent, const char*name, hlayout1->addSpacing(5); remote->insertItem("Remote "); - remote->insertStringList(getRemotes()); + remote->insertStringList(lh->getRemotes()); connect(remote, SIGNAL(activated(const QString&)), this, SLOT(remoteSelected(const QString&)) ); @@ -66,7 +68,12 @@ ButtonDialog::ButtonDialog(QString buttonName, QWidget *parent, const char*name, } +ButtonDialog::~ButtonDialog() +{ + delete lh; +} + void ButtonDialog::remoteSelected(const QString &string) { - button->insertStringList(getButtons(string.latin1()) ); + button->insertStringList(lh->getButtons(string.latin1()) ); list="SEND_ONCE"; list+=string; @@ -87,207 +94,2 @@ QString ButtonDialog::getLabel() return label->text(); } - -QStringList ButtonDialog::getRemotes() -{ - const char write_buffer[] = "LIST\n"; - const char *readbuffer; - int i, numlines; - QStringList list; - - addr.sun_family=AF_UNIX; - strcpy(addr.sun_path,"/dev/lircd"); - - fd = socket(AF_UNIX, SOCK_STREAM, 0); - if(fd == -1) - { - QMessageBox *mb = new QMessageBox("Error!", - "couldnt connect to socket", - QMessageBox::NoIcon, - QMessageBox::Ok, - QMessageBox::NoButton, - QMessageBox::NoButton); - mb->exec(); - perror("ButtonDialog::GetRemotes"); - return NULL; - } - - if(::connect(fd,(struct sockaddr *) &addr, sizeof(addr) ) == -1) - { - QMessageBox *mb = new QMessageBox("Error!", - "couldnt connect to socket", - QMessageBox::NoIcon, - QMessageBox::Ok, - QMessageBox::NoButton, - QMessageBox::NoButton); - mb->exec(); - perror("ButtonDialog::GetRemotes"); - return NULL; - } - - write(fd, write_buffer, strlen(write_buffer)); - - for(i=0; i<5; i++) - { - printf("%d\n", i); - readbuffer = readPacket(); - printf("%s", readbuffer); - printf("%d\n", i); - } - - numlines = atoi(readbuffer); - - for(i=0; i<numlines; i++) - { - list+=readPacket(); - } - - if(strcasecmp(readPacket(), "END") != 0) - { - QMessageBox *mb = new QMessageBox("Error!", - "bad packet", - QMessageBox::NoIcon, - QMessageBox::Ok, - QMessageBox::NoButton, - QMessageBox::NoButton); - mb->exec(); - perror("ButtonDialog::GetRemotes"); - return NULL; - } - - ::close(fd); - return list; -} - -QStringList ButtonDialog::getButtons(const char *remoteName) -{ - QString write_buffer = "LIST "; - const char *readbuffer; - int i, j, numlines; - QStringList list; - QString string; - - write_buffer += remoteName; - write_buffer += '\n'; - - fd = socket(AF_UNIX, SOCK_STREAM, 0); - if(fd == -1) - { - QMessageBox *mb = new QMessageBox("Error!", - "couldnt connect to socket", - QMessageBox::NoIcon, - QMessageBox::Ok, - QMessageBox::NoButton, - QMessageBox::NoButton); - mb->exec(); - perror("ButtonDialog::GetButtons"); - return NULL; - } - - - if(::connect(fd,(struct sockaddr *) &addr, sizeof(addr) ) == -1) - { - QMessageBox *mb = new QMessageBox("Error!", - "couldnt connect to socket", - QMessageBox::NoIcon, - QMessageBox::Ok, - QMessageBox::NoButton, - QMessageBox::NoButton); - mb->exec(); - perror("ButtonDialog::GetButtons"); - return NULL; - } - - write(fd, write_buffer.latin1(), strlen(write_buffer) ); - - for(i=0; i<5; i++) - { - readbuffer = readPacket(); - } - - numlines = atoi(readbuffer); - - for(i=0; i<numlines; i++) - { - list+=readPacket(); - for(j=0; j<list[i].length(); j++) - { - if(list[i][j] == ' ') - break; - } - list[i].remove(0, j+1); - } - - if(strcasecmp(readPacket(), "END") != 0) - { - QMessageBox *mb = new QMessageBox("Error!", - "bad packet", - QMessageBox::NoIcon, - QMessageBox::Ok, - QMessageBox::NoButton, - QMessageBox::NoButton); - mb->exec(); - perror("ButtonDialog::GetButtons"); - return NULL; - } - - ::close(fd); - return list; -} - - -//this function was ripped for rc.c in xrc, it is available here: http://www.lirc.org/software.html -const char *ButtonDialog::readPacket() -{ - static char buffer[PACKET_SIZE+1]=""; - char *end; - static int ptr=0,end_len=0; - ssize_t ret; - timeout = 0; - - if(ptr>0) - { - memmove(buffer,buffer+ptr,strlen(buffer+ptr)+1); - ptr=strlen(buffer); - end=strchr(buffer,'\n'); - } - else - { - end=NULL; - } - alarm(TIMEOUT); - while(end==NULL) - { - if(PACKET_SIZE<=ptr) - { - fprintf(stderr,"bad packet\n"); - ptr=0; - return(NULL); - } - ret=read(fd,buffer+ptr,PACKET_SIZE-ptr); - - if(ret<=0 || timeout) - { - if(timeout) - { - fprintf(stderr,"timeout\n"); - } - else - { - alarm(0); - } - ptr=0; - return(NULL); - } - buffer[ptr+ret]=0; - ptr=strlen(buffer); - end=strchr(buffer,'\n'); - } - alarm(0);timeout=0; - - end[0]=0; - ptr=strlen(buffer)+1; -//# ifdef DEBUG -// printf("buffer: -%s-\n",buffer); -//# endif - return(buffer); -} 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 @@ -32,6 +32,5 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include <errno.h> -#define PACKET_SIZE 256 -#define TIMEOUT 3 +#include "lirchandler.h" class ButtonDialog : public QDialog @@ -40,8 +39,5 @@ class ButtonDialog : public QDialog public: ButtonDialog(QString buttonName, QWidget *parent=0, const char*name=0, bool modal=FALSE, WFlags f=0); - void setIRSocket(int newfd); - const char *readPacket(); - QStringList getRemotes(); - QStringList getButtons(const char *remoteName); + ~ButtonDialog(); QStringList getList(); QString getLabel(); @@ -54,6 +50,4 @@ private: QStringList list; QLineEdit *label; - int fd; - int timeout; - struct sockaddr_un addr; + LircHandler *lh; }; 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 @@ -22,4 +22,6 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA LearnTab::LearnTab(QWidget *parent, const char *name):QWidget(parent,name) { + LircHandler lh; + QVBoxLayout *layout = new QVBoxLayout(this); QHBoxLayout *bottomLayout = new QHBoxLayout(this); @@ -28,5 +30,5 @@ LearnTab::LearnTab(QWidget *parent, const char *name):QWidget(parent,name) remotesBox = new QListBox(this, "remotesBox"); layout->insertWidget(0, remotesBox, 1); - remotesBox->insertStringList(getRemotes()); + remotesBox->insertStringList(lh.getRemotes()); layout->insertSpacing(-1,5); @@ -63,130 +65,2 @@ void LearnTab::del() {} -QStringList LearnTab::getRemotes() -{ - const char write_buffer[] = "LIST\n"; - const char *readbuffer; - int i, numlines; - QStringList list; - - addr.sun_family=AF_UNIX; - strcpy(addr.sun_path,"/dev/lircd"); - - fd = socket(AF_UNIX, SOCK_STREAM, 0); - if(fd == -1) - { - QMessageBox *mb = new QMessageBox("Error!", - "couldnt connect to socket", - QMessageBox::NoIcon, - QMessageBox::Ok, - QMessageBox::NoButton, - QMessageBox::NoButton); - mb->exec(); - perror("LearnTab::GetRemotes"); - return NULL; - } - - if(::connect(fd,(struct sockaddr *) &addr, sizeof(addr) ) == -1) - { - QMessageBox *mb = new QMessageBox("Error!", - "couldnt connect to socket", - QMessageBox::NoIcon, - QMessageBox::Ok, - QMessageBox::NoButton, - QMessageBox::NoButton); - mb->exec(); - perror("LearnTab::GetRemotes"); - return NULL; - } - - write(fd, write_buffer, strlen(write_buffer)); - - for(i=0; i<5; i++) - { - printf("%d\n", i); - readbuffer = readPacket(); - printf("%s", readbuffer); - printf("%d\n", i); - } - - numlines = atoi(readbuffer); - - for(i=0; i<numlines; i++) - { - list+=readPacket(); - } - - if(strcasecmp(readPacket(), "END") != 0) - { - QMessageBox *mb = new QMessageBox("Error!", - "bad packet", - QMessageBox::NoIcon, - QMessageBox::Ok, - QMessageBox::NoButton, - QMessageBox::NoButton); - mb->exec(); - perror("LearnTab::GetRemotes"); - return NULL; - } - - ::close(fd); - return list; -} - -//this function was ripped for rc.c in xrc, it is available here: http://www.lirc.org/software.html -const char *LearnTab::readPacket() -{ - static char buffer[PACKET_SIZE+1]=""; - char *end; - static int ptr=0,end_len=0; - ssize_t ret; - timeout = 0; - - if(ptr>0) - { - memmove(buffer,buffer+ptr,strlen(buffer+ptr)+1); - ptr=strlen(buffer); - end=strchr(buffer,'\n'); - } - else - { - end=NULL; - } - alarm(TIMEOUT); - while(end==NULL) - { - if(PACKET_SIZE<=ptr) - { - fprintf(stderr,"bad packet\n"); - ptr=0; - return(NULL); - } - ret=read(fd,buffer+ptr,PACKET_SIZE-ptr); - - if(ret<=0 || timeout) - { - if(timeout) - { - fprintf(stderr,"timeout\n"); - } - else - { - alarm(0); - } - ptr=0; - return(NULL); - } - buffer[ptr+ret]=0; - ptr=strlen(buffer); - end=strchr(buffer,'\n'); - } - alarm(0);timeout=0; - - end[0]=0; - ptr=strlen(buffer)+1; - //# ifdef DEBUG - // printf("buffer: -%s-\n",buffer); - //# endif - return(buffer); -} - 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 @@ -33,7 +33,5 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "recorddialog.h" - -#define PACKET_SIZE 256 -#define TIMEOUT 3 +#include "lirchandler.h" class LearnTab : public QWidget @@ -42,6 +40,4 @@ class LearnTab : public QWidget public: LearnTab(QWidget *parent=0, const char *name=0); - const char *readPacket(); - QStringList getRemotes(); public slots: void add(); @@ -50,6 +46,3 @@ public slots: private: QListBox *remotesBox; - int fd; - int timeout; - struct sockaddr_un addr; }; 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 @@ +/* +Opie-Remote. emulates remote controls on an iPaq (and maybe a Zaurus) in Opie. +Copyright (C) 2007 Paul Eggleton & Thomas Stephens + +This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public +License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the +implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +Public License for more details. + +You should have received a copy of the GNU General Public License along with this program; if not, write to the Free +Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/socket.h> +#include <sys/types.h> +#include <sys/un.h> +#include <unistd.h> +#include <errno.h> + +#include <qstring.h> +#include <qmessagebox.h> +#include <qobject.h> +#include <opie2/oprocess.h> + +#include "lirchandler.h" + +#define PACKET_SIZE 256 +#define TIMEOUT 3 +#define LIRCD_SOCKET "/dev/lircd" +#define LIRCD_SERVICECMD "/etc/init.d/lircd" + +using namespace Opie::Core; + +LircHandler::LircHandler(void) +{ + fd = 0; + addr.sun_family=AF_UNIX; + strcpy(addr.sun_path, LIRCD_SOCKET); +} + +bool LircHandler::connectLirc(void) +{ + fd = socket(AF_UNIX, SOCK_STREAM, 0); + if(fd == -1) + { + QMessageBox *mb = new QMessageBox(QObject::tr("Error"), + QObject::tr("Unable to create socket"), + QMessageBox::Critical, + QMessageBox::Ok, + QMessageBox::NoButton, + QMessageBox::NoButton); + mb->exec(); + perror("LircHandler::connectLirc"); + return false; + } + + if(::connect(fd,(struct sockaddr *) &addr, sizeof(addr) ) == -1) + { + QMessageBox *mb = new QMessageBox(QObject::tr("Error"), + QObject::tr("Could not connect to lircd"), + QMessageBox::Critical, + QMessageBox::Ok, + QMessageBox::NoButton, + QMessageBox::NoButton); + mb->exec(); + perror("LircHandler::connectLirc"); + return false; + } + + return true; +} + +//this function was ripped for rc.c in xrc, it is available here: http://www.lirc.org/software.html +const char *LircHandler::readPacket() +{ + static char buffer[PACKET_SIZE+1]=""; + char *end; + static int ptr=0; + ssize_t ret; + int timeout = 0; + + if(ptr>0) + { + memmove(buffer,buffer+ptr,strlen(buffer+ptr)+1); + ptr=strlen(buffer); + end=strchr(buffer,'\n'); + } + else + { + end=NULL; + } + alarm(TIMEOUT); + while(end==NULL) + { + if(PACKET_SIZE<=ptr) + { + fprintf(stderr,"readPacket: bad packet\n"); + ptr=0; + return(NULL); + } + ret=read(fd,buffer+ptr,PACKET_SIZE-ptr); + + if(ret<=0 || timeout) + { + if(timeout) + { + fprintf(stderr,"readPacket: timeout\n"); + } + else + { + alarm(0); + } + ptr=0; + return(NULL); + } + buffer[ptr+ret]=0; + ptr=strlen(buffer); + end=strchr(buffer,'\n'); + } + alarm(0); + + end[0]=0; + ptr=strlen(buffer)+1; +//# ifdef DEBUG +// printf("buffer: -%s-\n",buffer); +//# endif + return(buffer); +} + +QStringList LircHandler::getRemotes(void) +{ + const char write_buffer[] = "LIST\n"; + const char *readbuffer; + int i, numlines; + QStringList list; + + if(connectLirc()) { + write(fd, write_buffer, strlen(write_buffer) ); + + for(i=0; i<5; i++) + { + readbuffer = readPacket(); + } + + numlines = atoi(readbuffer); + + for(i=0; i<numlines; i++) + { + list+=readPacket(); + } + + if(strcasecmp(readPacket(), "END") != 0) + { + QMessageBox *mb = new QMessageBox(QObject::tr("Error"), + QObject::tr("Bad packet while communicating with lircd"), + QMessageBox::Critical, + QMessageBox::Ok, + QMessageBox::NoButton, + QMessageBox::NoButton); + mb->exec(); + perror("LircHandler::getRemotes"); + return NULL; + } + + ::close(fd); + } + + return list; +} + +QStringList LircHandler::getButtons(const char *remoteName) +{ + QString write_buffer = "LIST "; + const char *readbuffer; + int i, j, numlines; + QStringList list; + QString string; + + write_buffer += remoteName; + write_buffer += '\n'; + + if(connectLirc()) { + write(fd, write_buffer.latin1(), strlen(write_buffer) ); + + for(i=0; i<5; i++) + { + readbuffer = readPacket(); + } + + numlines = atoi(readbuffer); + + for(i=0; i<numlines; i++) + { + list+=readPacket(); + for(j=0; j<list[i].length(); j++) + { + if(list[i][j] == ' ') + break; + } + list[i].remove(0, j+1); + } + + if(strcasecmp(readPacket(), "END") != 0) + { + QMessageBox *mb = new QMessageBox(QObject::tr("Error"), + QObject::tr("Bad packet while communicating with lircd"), + QMessageBox::Critical, + QMessageBox::Ok, + QMessageBox::NoButton, + QMessageBox::NoButton); + mb->exec(); + perror("LircHandler::getRemotes"); + return NULL; + } + + ::close(fd); + } + + return list; +} + +int LircHandler::sendIR(const char *irbutton) +{ + const char *read_buffer; + bool done=false; + + if(connectLirc()) { + printf("fd2: %d\n", fd); + printf("%s", irbutton); + + printf("1\n"); + printf("%d\n", write(fd, irbutton, strlen(irbutton) ) ); + printf("2\n"); + while(!done) + { + read_buffer=readPacket(); + printf("%s\n", read_buffer); + if(strcasecmp(read_buffer, "END") == 0) + { + printf("done reading packet\n"); + done=true; + } + } + ::close(fd); + return 1; + } + else + return 0; +} + +bool LircHandler::startLircd(void) +{ + return (system(LIRCD_SERVICECMD " start") == 0); +} + +bool LircHandler::stopLircd(void) +{ + return (system(LIRCD_SERVICECMD " stop") == 0); +} + +bool LircHandler::isLircdRunning(void) +{ + return (OProcess::processPID("lircd") != 0); +} 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 @@ +/* +Opie-Remote. emulates remote controls on an iPaq (and maybe a Zaurus) in Opie. +Copyright (C) 2007 Paul Eggleton & Thomas Stephens + +This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public +License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the +implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +Public License for more details. + +You should have received a copy of the GNU General Public License along with this program; if not, write to the Free +Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef LIRCHANDLER_H +#define LIRCHANDLER_H + +class LircHandler +{ +private: + bool connectLirc(void); + const char *readPacket(); + + struct sockaddr_un addr; + int fd; +public: + LircHandler(void); + QStringList getRemotes(void); + QStringList getButtons(const char *remoteName); + int sendIR(const char *irbutton); + bool startLircd(void); + bool stopLircd(void); + bool isLircdRunning(void); +}; + +#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 @@ -35,6 +35,4 @@ MainView::MainView(QWidget *parent, const char *name) : QWidget(parent, name) connect(config, SIGNAL(remotesChanged()), this, SLOT(updateRemotesList()) ); - remote->setIRSocket(fd); - tabs->addTab(remote, tr("Remote") ); tabs->addTab(learn,tr("Learn") ); @@ -50,15 +48,4 @@ MainView::MainView(QWidget *parent, const char *name) : QWidget(parent, name) } -int MainView::getIRSocket() -{ - return fd; -} - -void MainView::setIRSocket(int newfd) -{ - fd = newfd; - remote->setIRSocket(fd); -} - void MainView::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 @@ -42,10 +42,7 @@ class MainView : public QWidget public: MainView(QWidget *parent=0, const char *name=0); - int getIRSocket(); - void setIRSocket(int newfd); public slots: void updateRemotesList(); private: - int fd; RemoteTab *remote; ConfigTab *config; 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 @@ -/* -Opie-Remote. emulates remote controlls on an iPaq (and maybe a Zaurus) in Opie. -Copyright (C) 2002 Thomas Stephens - -This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public -License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later -version. - -This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the -implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -Public License for more details. - -You should have received a copy of the GNU General Public License along with this program; if not, write to the Free -Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -file not used -*/ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/socket.h> -#include <sys/types.h> -#include <sys/un.h> -#include <unistd.h> -#include <errno.h> - -#define PACKET_SIZE 256 -#define TIMEOUT 3 - -//this function was ripped for rc.c in xrc, it is available here: http://www.lirc.org/software.html -const char *readPacket(int fd) -{ - static char buffer[PACKET_SIZE+1]=""; - char *end; - static int ptr=0,end_len=0; - ssize_t ret; - - if(ptr>0) - { - memmove(buffer,buffer+ptr,strlen(buffer+ptr)+1); - ptr=strlen(buffer); - end=strchr(buffer,'\n'); - } - else - { - end=NULL; - } - alarm(TIMEOUT); - while(end==NULL) - { - if(PACKET_SIZE<=ptr) - { -// fprintf(stderr,"%s: bad packet\n",progname); - ptr=0; - return(NULL); - } - ret=read(fd,buffer+ptr,PACKET_SIZE-ptr); - - if(ret<=0 || timeout) - { - if(timeout) - { -// fprintf(stderr,"%s: timeout\n",progname); - } - else - { - alarm(0); - } - ptr=0; - return(NULL); - } - buffer[ptr+ret]=0; - ptr=strlen(buffer); - end=strchr(buffer,'\n'); - } - alarm(0);timeout=0; - - end[0]=0; - ptr=strlen(buffer)+1; -//# ifdef DEBUG -// printf("buffer: -%s-\n",buffer); -//# endif - return(buffer); -} -QStringList getRemotes(int fd) -{ - const char write_buffer[] = "LIST\n"; - const char *readbuffer; - int i, numlines; - QStringList list; - - fd = socket(AF_UNIX, SOCK_STREAM, 0); - - if(std::connect(fd,(struct sockaddr *) &addr, sizeof(addr) ) == -1) - { - QMessageBox *mb = new QMessageBox("Error!", - "couldnt connect to socket", - QMessageBox::NoIcon, - QMessageBox::Ok, - QMessageBox::NoButton, - QMessageBox::NoButton); - mb->exec(); - perror("ConfigTab::GetRemotes"); - return NULL; - } - - write(fd, write_buffer, strlen(write_buffer) ); - - for(i=0; i<5; i++) - { - readbuffer = readPacket(int fd); - } - - numlines = atoi(readbuffer); - - for(i=0; i<numlines; i++) - { - list+=readPacket(); - } - - if(strcasecmp(readPacket(), "END") != 0) - { - QMessageBox *mb = new QMessageBox("Error!", - "bad packet", - QMessageBox::NoIcon, - QMessageBox::Ok, - QMessageBox::NoButton, - QMessageBox::NoButton); - mb->exec(); - perror("ConfigTab::GetRemotes"); - return NULL; - } - - std::close(fd); - return list; -} - -QStringList getButtons(int fd, const char *remoteName) -{ - QString write_buffer = "LIST "; - const char *readbuffer; - int i, j, numlines; - QStringList list; - QString string; - - write_buffer += remoteName; - write_buffer += '\n'; - - fd = socket(AF_UNIX, SOCK_STREAM, 0); - - if(std::connect(fd,(struct sockaddr *) &addr, sizeof(addr) ) == -1) - { - QMessageBox *mb = new QMessageBox("Error!", - "couldnt connect to socket", - QMessageBox::NoIcon, - QMessageBox::Ok, - QMessageBox::NoButton, - QMessageBox::NoButton); - mb->exec(); - perror("ConfigTab::GetRemotes"); - return NULL; - } - - write(fd, write_buffer.latin1(), strlen(write_buffer) ); - - for(i=0; i<5; i++) - { - readbuffer = readPacket(); - } - - numlines = atoi(readbuffer); - - for(i=0; i<numlines; i++) - { - list+=readPacket(); - for(j=0; j<list[i].length(); j++) - { - if(list[i][j] == ' ') - break; - } - list[i].remove(0, j+1); - } - - if(strcasecmp(readPacket(), "END") != 0) - { - QMessageBox *mb = new QMessageBox("Error!", - "bad packet", - QMessageBox::NoIcon, - QMessageBox::Ok, - QMessageBox::NoButton, - QMessageBox::NoButton); - mb->exec(); - perror("ConfigTab::GetRemotes"); - return NULL; - } - - std::close(fd); - return list; -} 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 @@ -38,68 +38,23 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -/*void reconnect(int &fd) -{ -// struct sockaddr_un addr; - - addr.sun_family=AF_UNIX; - strcpy(addr.sun_path,"/dev/lircd"); - fd = socket(AF_UNIX, SOCK_STREAM, 0); - - if(connect(fd,(struct sockaddr *) &addr, sizeof(addr) ) == -1) - { - QMessageBox *mb = new QMessageBox("error", - "couldnt connect to socket", - QMessageBox::NoIcon, - QMessageBox::Ok, - QMessageBox::NoButton, - QMessageBox::NoButton); - mb->exec(); - } -} -*/ - int main( int argc, char **argv ) { QPEApplication a( argc, argv ); MainView w; + a.setMainWidget( &w ); + QPEApplication::showWidget( &w ); - int fd; - // struct sockaddr_un addr; - // char read_buffer[BUFFERSIZE+1]; - // char write_buffer[] = "LIST\n"; - - // addr.sun_family=AF_UNIX; - // strcpy(addr.sun_path,"/dev/lircd"); - // fd = socket(AF_UNIX, SOCK_STREAM, 0); - - // printf("fd1: %d\n", fd); - /* - if(connect(fd,(struct sockaddr *) &addr, sizeof(addr) ) == -1) - { - QMessageBox *mb = new QMessageBox("error", - "couldnt connect to socket", + LircHandler lh; + if(!lh.isLircdRunning()) { + QMessageBox mb("Error!", + "Lircd is not running", QMessageBox::NoIcon, QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton); - mb->exec(); - } - */ - - // printf("%d\n", write(fd, write_buffer, sizeof(write_buffer) ) ); - - // printf("%d\n", read(fd, read_buffer, BUFFERSIZE ) ); + mb.exec(); - // QMessageBox *mbtest = new QMessageBox("lirc test", - // *new QString((const char *) read_buffer), - // QMessageBox::NoIcon, - // QMessageBox::Ok, - // QMessageBox::NoButton, - // QMessageBox::NoButton); - // mbtest->exec(); + } - a.setMainWidget( &w ); - w.setIRSocket(fd); - QPEApplication::showWidget( &w ); return a.exec(); } 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 @@ -2,6 +2,6 @@ TEMPLATE =app CONFIG +=qt warn_on DESTDIR =$(OPIEDIR)/bin -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 -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 +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 +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 INCLUDEPATH +=$(OPIEDIR)/include DEPENDPATH +=$(OPIEDIR)/include 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 @@ -16,4 +16,5 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "remotetab.h" +#include "lirchandler.h" RemoteTab::RemoteTab(QWidget *parent, const char *name):QWidget(parent,name) @@ -45,9 +46,4 @@ RemoteTab::RemoteTab(QWidget *parent, const char *name):QWidget(parent,name) this->setMaximumWidth(240); - - timeout = 0; - - addr.sun_family=AF_UNIX; - strcpy(addr.sun_path,"/dev/lircd"); } @@ -57,117 +53,7 @@ int RemoteTab::sendIR() QString string = cfg->readEntry(button->name()); string+='\n'; - const char *write_buffer = string.latin1(); - const char *read_buffer; - bool done=false; - - fd = socket(AF_UNIX, SOCK_STREAM, 0); - if(fd == -1) - { - QMessageBox *mb = new QMessageBox("Error!", - "couldnt connect to socket", - QMessageBox::NoIcon, - QMessageBox::Ok, - QMessageBox::NoButton, - QMessageBox::NoButton); - mb->exec(); - perror("RemoteTab::SendIR"); - return 0; - } - - - if(::connect(fd,(struct sockaddr *) &addr, sizeof(addr) ) == -1) - { - QMessageBox *mb = new QMessageBox("Error!", - "couldnt connect to socket", - QMessageBox::NoIcon, - QMessageBox::Ok, - QMessageBox::NoButton, - QMessageBox::NoButton); - mb->exec(); - perror("RemoteTab::SendIR"); - } - - printf("fd2: %d\n", fd); - printf("%s", write_buffer); - - printf("1\n"); - printf("%d\n", write(fd, write_buffer, strlen(write_buffer) ) ); - printf("2\n"); - while(!done) - { - read_buffer=readPacket(); - printf("%s\n", read_buffer); - if(strcasecmp(read_buffer, "END") == 0) - { - printf("done reading packet\n"); - done=true; - } - } - ::close(fd); -} - -// printf("%s\n", readPacket()); -// printf("%d\n", read(fd, read_buffer,sizeof(read_buffer)) ); -// printf("%s", read_buffer); - -//this function was ripped for rc.c in xrc, it is available here: http://www.lirc.org/software.html -const char *RemoteTab::readPacket() -{ - static char buffer[PACKET_SIZE+1]=""; - char *end; - static int ptr=0,end_len=0; - ssize_t ret; - - if(ptr>0) - { - memmove(buffer,buffer+ptr,strlen(buffer+ptr)+1); - ptr=strlen(buffer); - end=strchr(buffer,'\n'); - } - else - { - end=NULL; - } - alarm(TIMEOUT); - while(end==NULL) - { - if(PACKET_SIZE<=ptr) - { -// fprintf(stderr,"%s: bad packet\n",progname); - ptr=0; - return(NULL); - } - ret=read(fd,buffer+ptr,PACKET_SIZE-ptr); - - if(ret<=0 || timeout) - { - if(timeout) - { -// fprintf(stderr,"%s: timeout\n",progname); - } - else - { - alarm(0); - } - ptr=0; - return(NULL); - } - buffer[ptr+ret]=0; - ptr=strlen(buffer); - end=strchr(buffer,'\n'); - } - alarm(0);timeout=0; - end[0]=0; - ptr=strlen(buffer)+1; -//# ifdef DEBUG -// printf("buffer: -%s-\n",buffer); -//# endif - return(buffer); -} - -void RemoteTab::setIRSocket(int newfd) -{ - fd = newfd; + LircHandler lh; + return lh.sendIR(string.latin1()); } 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 @@ -38,7 +38,4 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "vcrgroup.h" -#define PACKET_SIZE 256 -#define TIMEOUT 3 - class RemoteTab : public QWidget { @@ -46,5 +43,4 @@ class RemoteTab : public QWidget public: RemoteTab(QWidget *parent=0, const char *name=0); - void setIRSocket(int newfd); const char *readPacket(); void setConfig(Config *newCfg); @@ -54,7 +50,4 @@ public slots: void remoteSelected(const QString &string); private: - int fd; - int timeout; - struct sockaddr_un addr; Config *cfg; TopGroup *topGroup; |