summaryrefslogtreecommitdiff
path: root/core/obex/btobex.cpp
Unidiff
Diffstat (limited to 'core/obex/btobex.cpp') (more/less context) (show whitespace changes)
-rw-r--r--core/obex/btobex.cpp60
1 files changed, 46 insertions, 14 deletions
diff --git a/core/obex/btobex.cpp b/core/obex/btobex.cpp
index a5bfe5f..212a084 100644
--- a/core/obex/btobex.cpp
+++ b/core/obex/btobex.cpp
@@ -1,79 +1,100 @@
1/*
2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 Maximilian Reiss <max.reiss@gmx.de>
4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can
6.> <,   >  .   <= redistribute it and/or modify it under
7:=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; version 2 of the License.
10     ._= =}       :
11    .%+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=| MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more
18++=   -.     .     .: details.
19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with
22   --        :-= this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28/*
29 * The Bluetooth OBEX manipulating class implementation
30 */
1 31
2#include "btobex.h" 32#include "btobex.h"
3#include <manager.h> 33#include <manager.h>
4#include <services.h> 34#include <services.h>
5 35
6/* OPIE */ 36/* OPIE */
7#include <opie2/oprocess.h> 37#include <opie2/oprocess.h>
8#include <opie2/odebug.h> 38#include <opie2/odebug.h>
9 39
10/* QT */ 40/* QT */
11#include <qfileinfo.h> 41#include <qfileinfo.h>
12#include <qstring.h> 42#include <qstring.h>
13#include <qmap.h> 43#include <qmap.h>
14#include <qmessagebox.h> 44#include <qmessagebox.h>
15 45
16using namespace OpieObex; 46using namespace OpieObex;
17 47
18using namespace Opie::Core; 48using namespace Opie::Core;
19/* TRANSLATOR OpieObex::Obex */ 49/* TRANSLATOR OpieObex::Obex */
20using namespace OpieTooth; 50using namespace OpieTooth;
21 51
22BtObex::BtObex( QObject *parent, const char* name ) 52BtObex::BtObex( QObject *parent, const char* name )
23 : QObject(parent, name ) 53 : ObexBase(parent, name )
24{ 54{
25 m_rec = 0; 55 m_rec = 0;
26 m_send=0; 56 m_send=0;
27 m_count = 0;
28 m_receive = false;
29 connect( this, SIGNAL(error(int) ), // for recovering to receive
30 SLOT(slotError() ) );
31 connect( this, SIGNAL(sent(bool) ),
32 SLOT(slotError() ) );
33 btManager = NULL; 57 btManager = NULL;
34}; 58};
35 59
36BtObex::~BtObex() { 60BtObex::~BtObex() {
37 delete btManager; 61 delete btManager;
38 delete m_rec; 62 delete m_rec;
39 delete m_send; 63 delete m_send;
40} 64}
41 65
42void BtObex::receive() { 66void BtObex::receive() {
43 m_receive = true; 67 ObexBase::receive();
44 m_outp = QString::null; 68 m_rec = new ObexServer();
45 m_rec = new OProcess();
46 69
70 odebug << "BT OBEX do receive" << oendl;
47 // TODO mbhaynie: No idea if this actually works -- maybe opd is better. 71 // TODO mbhaynie: No idea if this actually works -- maybe opd is better.
48 *m_rec << "obexftpd" << "-b";
49 // connect to the necessary slots 72 // connect to the necessary slots
50 connect(m_rec, SIGNAL(processExited(Opie::Core::OProcess*) ), 73 connect(m_rec, SIGNAL(processExited(Opie::Core::OProcess*) ),
51 this, SLOT(slotExited(Opie::Core::OProcess*) ) ); 74 this, SLOT(slotExited(Opie::Core::OProcess*) ) );
52 75
53 connect(m_rec, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ), 76 connect(m_rec, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ),
54 this, SLOT(slotStdOut(Opie::Core::OProcess*, char*, int) ) ); 77 this, SLOT(slotStdOut(Opie::Core::OProcess*, char*, int) ) );
55 78
56 if(!m_rec->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { 79 if(!m_rec->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) {
57 emit done( false ); 80 emit done( false );
58 delete m_rec; 81 delete m_rec;
59 m_rec = 0; 82 m_rec = 0;
60 } 83 }
61} 84}
62 85
63void BtObex::send( const QString& fileName, const QString& bdaddr) { 86void BtObex::send( const QString& fileName, const QString& bdaddr) {
87 ObexBase::send(fileName, bdaddr);
64 // if currently receiving stop it send receive 88 // if currently receiving stop it send receive
65 m_count = 0;
66 m_file = fileName;
67 m_bdaddr = bdaddr;
68 if (m_send != 0) { 89 if (m_send != 0) {
69 if (m_send->isSending()) 90 if (m_send->isSending())
70 return; 91 return;
71 else { 92 else {
72 delete m_send; 93 delete m_send;
73 m_send = 0; 94 m_send = 0;
74 } 95 }
75 } 96 }
76 if (m_rec != 0 ) { 97 if (m_rec != 0 ) {
77 if (m_rec->isRunning() ) { 98 if (m_rec->isRunning() ) {
78 emit error(-1 ); 99 emit error(-1 );
79 delete m_rec; 100 delete m_rec;
@@ -141,51 +162,58 @@ void BtObex::sendNow(){
141 return; 162 return;
142 } 163 }
143 // OProcess inititialisation 164 // OProcess inititialisation
144 m_send = new ObexPush(); 165 m_send = new ObexPush();
145 // connect to slots Exited and and StdOut 166 // connect to slots Exited and and StdOut
146 connect(m_send, SIGNAL(sendComplete(int)), 167 connect(m_send, SIGNAL(sendComplete(int)),
147 this, SLOT(slotPushComplete(int)) ); 168 this, SLOT(slotPushComplete(int)) );
148 connect(m_send, SIGNAL(sendError(int)), 169 connect(m_send, SIGNAL(sendError(int)),
149 this, SLOT(slotPushError(int)) ); 170 this, SLOT(slotPushError(int)) );
150 connect(m_send, SIGNAL(status(QCString&)), 171 connect(m_send, SIGNAL(status(QCString&)),
151 this, SLOT(slotPushStatus(QCString&) ) ); 172 this, SLOT(slotPushStatus(QCString&) ) );
152 173
174 /*
175 * FIXME: this delay is made because some cell phones understands an error
176 * later.
177 */
153 ::sleep(4); 178 ::sleep(4);
154 // now start it 179 // now start it
155 result = m_send->send(m_bdaddr, m_port, m_file, m_dst); 180 result = m_send->send(m_bdaddr, m_port, m_file, m_dst);
156 if (result > 0) //Sending process is actually running 181 if (result > 0) //Sending process is actually running
157 return; 182 return;
158 else if (result < 0) { 183 else if (result < 0) {
159 m_count = 25; 184 m_count = 25;
160 emit error(-1 ); 185 emit error(-1 );
161 delete m_send; 186 delete m_send;
162 m_send=0; 187 m_send=0;
163 } 188 }
164 // end 189 // end
165 m_count++; 190 m_count++;
166 emit currentTry( m_count ); 191 emit currentTry( m_count );
167} 192}
168 193
169void BtObex::slotExited(OProcess* proc ){ 194void BtObex::slotExited(OProcess* proc ){
170 odebug << proc->name() << " exited with result " 195 odebug << proc->name() << " exited with result "
171 << proc->exitStatus() << oendl; 196 << proc->exitStatus() << oendl;
172 if (proc == m_rec ) // receive process 197 if (proc == m_rec ) // receive process
173 received(); 198 received();
199
174} 200}
175void BtObex::slotStdOut(OProcess* proc, char* buf, int len){ 201void BtObex::slotStdOut(OProcess* proc, char* buf, int len){
176 if ( proc == m_rec ) { // only receive 202 if ( proc == m_rec ) { // only receive
177 QByteArray ar( len ); 203 QByteArray ar( len );
178 memcpy( ar.data(), buf, len ); 204 memcpy( ar.data(), buf, len );
179 m_outp.append( ar ); 205 m_outp.append( ar );
206 QCString str(buf, len);
207 odebug << str << oendl;
180 } 208 }
181} 209}
182 210
183void BtObex::slotPushComplete(int result) { 211void BtObex::slotPushComplete(int result) {
184 if (result == 0) { 212 if (result == 0) {
185 delete m_send; 213 delete m_send;
186 m_send=0; 214 m_send=0;
187 emit sent(true); 215 emit sent(true);
188 } else { // it failed maybe the other side wasn't ready 216 } else { // it failed maybe the other side wasn't ready
189 // let's try it again 217 // let's try it again
190 delete m_send; 218 delete m_send;
191 m_send = 0; 219 m_send = 0;
@@ -198,24 +226,25 @@ void BtObex::slotPushError(int) {
198 delete m_send; 226 delete m_send;
199 m_send = 0; 227 m_send = 0;
200} 228}
201 229
202void BtObex::slotPushStatus(QCString& str) { 230void BtObex::slotPushStatus(QCString& str) {
203 odebug << str << oendl; 231 odebug << str << oendl;
204} 232}
205 233
206void BtObex::received() { 234void BtObex::received() {
207 if (m_rec->normalExit() ) { 235 if (m_rec->normalExit() ) {
208 if ( m_rec->exitStatus() == 0 ) { // we got one 236 if ( m_rec->exitStatus() == 0 ) { // we got one
209 QString filename = parseOut(); 237 QString filename = parseOut();
238 odebug << "OBEX " << filename << " received" << oendl;
210 emit receivedFile( filename ); 239 emit receivedFile( filename );
211 } 240 }
212 }else{ 241 }else{
213 emit done(false); 242 emit done(false);
214 }; 243 };
215 delete m_rec; 244 delete m_rec;
216 m_rec = 0; 245 m_rec = 0;
217 receive(); 246 receive();
218} 247}
219 248
220// This probably doesn't do anything useful for bt. 249// This probably doesn't do anything useful for bt.
221QString BtObex::parseOut(){ 250QString BtObex::parseOut(){
@@ -231,28 +260,31 @@ QString BtObex::parseOut(){
231 path = (*it).remove( pos, (*it).length() - pos ); 260 path = (*it).remove( pos, (*it).length() - pos );
232 path = path.mid(6 ); 261 path = path.mid(6 );
233 path = path.stripWhiteSpace(); 262 path = path.stripWhiteSpace();
234 } 263 }
235 } 264 }
236 } 265 }
237 return path; 266 return path;
238} 267}
239/** 268/**
240 * when sent is done slotError is called we will start receive again 269 * when sent is done slotError is called we will start receive again
241 */ 270 */
242void BtObex::slotError() { 271void BtObex::slotError() {
272 ObexBase::slotError();
243 if ( m_receive ) 273 if ( m_receive )
244 receive(); 274 receive();
245}; 275};
246void BtObex::setReceiveEnabled( bool receive ) { 276void BtObex::setReceiveEnabled( bool receive ) {
277 odebug << "BT OBEX setReceiveEnabled " << receive << oendl;
278 ObexBase::setReceiveEnabled(receive);
247 if ( !receive ) { // 279 if ( !receive ) { //
248 m_receive = false; 280 m_receive = false;
249 shutDownReceive(); 281 shutDownReceive();
250 } 282 }
251} 283}
252 284
253void BtObex::shutDownReceive() { 285void BtObex::shutDownReceive() {
254 if (m_rec != 0 ) { 286 if (m_rec != 0 ) {
255 if (m_rec->isRunning() ) { 287 if (m_rec->isRunning() ) {
256 emit error(-1 ); 288 emit error(-1 );
257 delete m_rec; 289 delete m_rec;
258 m_rec = 0; 290 m_rec = 0;