Diffstat (limited to 'noncore/tools/remote/remotetab.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/tools/remote/remotetab.cpp | 122 |
1 files changed, 4 insertions, 118 deletions
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) |