summaryrefslogtreecommitdiff
authorzecke <zecke>2006-05-14 14:34:43 (UTC)
committer zecke <zecke>2006-05-14 14:34:43 (UTC)
commit273ffc42b3f0ce593e0d20874a7f224328416445 (patch) (unidiff)
tree04203fc463a711de981fc40ba390fcec8838d1eb
parent89efebff8f5a00089f02397aa0778dd0dbbacdbb (diff)
downloadopie-273ffc42b3f0ce593e0d20874a7f224328416445.zip
opie-273ffc42b3f0ce593e0d20874a7f224328416445.tar.gz
opie-273ffc42b3f0ce593e0d20874a7f224328416445.tar.bz2
core/obex: Patch from Dmitry Korovkin to use opietooth's OBEX implementation
for sending
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/obex/btobex.cpp87
-rw-r--r--core/obex/btobex.h14
2 files changed, 57 insertions, 44 deletions
diff --git a/core/obex/btobex.cpp b/core/obex/btobex.cpp
index 886f3dc..a5bfe5f 100644
--- a/core/obex/btobex.cpp
+++ b/core/obex/btobex.cpp
@@ -1,28 +1,28 @@
1 1
2#include "btobex.h" 2#include "btobex.h"
3#include <opietooth/manager.h> 3#include <manager.h>
4#include <opietooth/services.h> 4#include <services.h>
5 5
6/* OPIE */ 6/* OPIE */
7#include <opie2/oprocess.h> 7#include <opie2/oprocess.h>
8#include <opie2/odebug.h> 8#include <opie2/odebug.h>
9 9
10/* QT */ 10/* QT */
11#include <qfileinfo.h> 11#include <qfileinfo.h>
12#include <qstring.h> 12#include <qstring.h>
13#include <qmap.h> 13#include <qmap.h>
14#include <qmessagebox.h> 14#include <qmessagebox.h>
15 15
16using namespace OpieObex; 16using namespace OpieObex;
17 17
18using namespace Opie::Core; 18using namespace Opie::Core;
19/* TRANSLATOR OpieObex::Obex */ 19/* TRANSLATOR OpieObex::Obex */
20using namespace OpieTooth; 20using namespace OpieTooth;
21 21
22BtObex::BtObex( QObject *parent, const char* name ) 22BtObex::BtObex( QObject *parent, const char* name )
23 : QObject(parent, name ) 23 : QObject(parent, name )
24{ 24{
25 m_rec = 0; 25 m_rec = 0;
26 m_send=0; 26 m_send=0;
27 m_count = 0; 27 m_count = 0;
28 m_receive = false; 28 m_receive = false;
@@ -44,48 +44,56 @@ void BtObex::receive() {
44 m_outp = QString::null; 44 m_outp = QString::null;
45 m_rec = new OProcess(); 45 m_rec = new OProcess();
46 46
47 // TODO mbhaynie: No idea if this actually works -- maybe opd is better. 47 // TODO mbhaynie: No idea if this actually works -- maybe opd is better.
48 *m_rec << "obexftpd" << "-b"; 48 *m_rec << "obexftpd" << "-b";
49 // connect to the necessary slots 49 // connect to the necessary slots
50 connect(m_rec, SIGNAL(processExited(Opie::Core::OProcess*) ), 50 connect(m_rec, SIGNAL(processExited(Opie::Core::OProcess*) ),
51 this, SLOT(slotExited(Opie::Core::OProcess*) ) ); 51 this, SLOT(slotExited(Opie::Core::OProcess*) ) );
52 52
53 connect(m_rec, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ), 53 connect(m_rec, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ),
54 this, SLOT(slotStdOut(Opie::Core::OProcess*, char*, int) ) ); 54 this, SLOT(slotStdOut(Opie::Core::OProcess*, char*, int) ) );
55 55
56 if(!m_rec->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { 56 if(!m_rec->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) {
57 emit done( false ); 57 emit done( false );
58 delete m_rec; 58 delete m_rec;
59 m_rec = 0; 59 m_rec = 0;
60 } 60 }
61} 61}
62 62
63void BtObex::send( const QString& fileName, const QString& bdaddr) { 63void BtObex::send( const QString& fileName, const QString& bdaddr) {
64 // if currently receiving stop it send receive 64 // if currently receiving stop it send receive
65 m_count = 0; 65 m_count = 0;
66 m_file = fileName; 66 m_file = fileName;
67 m_bdaddr = bdaddr; 67 m_bdaddr = bdaddr;
68 if (m_send != 0) {
69 if (m_send->isSending())
70 return;
71 else {
72 delete m_send;
73 m_send = 0;
74 }
75 }
68 if (m_rec != 0 ) { 76 if (m_rec != 0 ) {
69 if (m_rec->isRunning() ) { 77 if (m_rec->isRunning() ) {
70 emit error(-1 ); 78 emit error(-1 );
71 delete m_rec; 79 delete m_rec;
72 m_rec = 0; 80 m_rec = 0;
73 81
74 }else{ 82 }else{
75 emit error( -1 ); // we did not delete yet but it's not running slotExited is pending 83 emit error( -1 ); // we did not delete yet but it's not running slotExited is pending
76 return; 84 return;
77 } 85 }
78 } 86 }
79 //Now we need to find out if the OBEX push is supported for this device 87 //Now we need to find out if the OBEX push is supported for this device
80 //And get the port number 88 //And get the port number
81 if (!btManager) { 89 if (!btManager) {
82 btManager = new Manager("hci0"); 90 btManager = new Manager("hci0");
83 connect(btManager, 91 connect(btManager,
84 SIGNAL(foundServices(const QString&, Services::ValueList)), 92 SIGNAL(foundServices(const QString&, Services::ValueList)),
85 this, SLOT(slotFoundServices(const QString&, Services::ValueList))); 93 this, SLOT(slotFoundServices(const QString&, Services::ValueList)));
86 } 94 }
87 btManager->searchServices(bdaddr); 95 btManager->searchServices(bdaddr);
88} 96}
89 97
90/** 98/**
91 * This function reacts on the service discovery finish 99 * This function reacts on the service discovery finish
@@ -104,131 +112,132 @@ void BtObex::slotFoundServices(const QString&, Services::ValueList svcList)
104 } 112 }
105 for (it = svcList.begin(); it != svcList.end(); it++) { 113 for (it = svcList.begin(); it != svcList.end(); it++) {
106 classList = (*it).classIdList(); 114 classList = (*it).classIdList();
107 classIt = classList.begin(); 115 classIt = classList.begin();
108 if (classIt == classList.end()) 116 if (classIt == classList.end())
109 continue; 117 continue;
110////We really need symbolic names for service IDs 118////We really need symbolic names for service IDs
111 //Ok, we have found the object push service 119 //Ok, we have found the object push service
112 if (classIt.key() == 4357) { 120 if (classIt.key() == 4357) {
113 portNum = (*it).protocolDescriptorList().last().port(); 121 portNum = (*it).protocolDescriptorList().last().port();
114 break; 122 break;
115 } 123 }
116 } 124 }
117 if (portNum == -1) { 125 if (portNum == -1) {
118 QMessageBox::critical(NULL, tr("Object send"), 126 QMessageBox::critical(NULL, tr("Object send"),
119 tr("No OBEX Push service")); 127 tr("No OBEX Push service"));
120 emit error(-1); 128 emit error(-1);
121 return; 129 return;
122 } 130 }
123 m_port = portNum; 131 m_port = portNum;
124 sendNow(); 132 sendNow();
125} 133}
126 134
127void BtObex::sendNow(){ 135void BtObex::sendNow(){
136 QString m_dst = "";
137 int result; //function call result
128 if ( m_count >= 25 ) { // could not send 138 if ( m_count >= 25 ) { // could not send
129 emit error(-1 ); 139 emit error(-1 );
130 emit sent(false); 140 emit sent(false);
131 return; 141 return;
132 } 142 }
133 // OProcess inititialisation 143 // OProcess inititialisation
134 m_send = new OProcess(0, "ussp-push"); 144 m_send = new ObexPush();
135 m_send->setWorkingDirectory( QFileInfo(m_file).dirPath(true) );
136
137 // ussp-push --timeo 30 <btaddr:port> file file
138 *m_send << "ussp-push" << "--timeo 30";
139 *m_send << m_bdaddr + "@" + QString::number(m_port);
140 *m_send << QFile::encodeName(QFileInfo(m_file).fileName());
141 *m_send << QFile::encodeName(QFileInfo(m_file).fileName());
142 m_send->setUseShell(true);
143
144 // connect to slots Exited and and StdOut 145 // connect to slots Exited and and StdOut
145 connect(m_send, SIGNAL(processExited(Opie::Core::OProcess*) ), 146 connect(m_send, SIGNAL(sendComplete(int)),
146 this, SLOT(slotExited(Opie::Core::OProcess*)) ); 147 this, SLOT(slotPushComplete(int)) );
147 connect(m_send, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int)), 148 connect(m_send, SIGNAL(sendError(int)),
148 this, SLOT(slotStdOut(Opie::Core::OProcess*, char*, int) ) ); 149 this, SLOT(slotPushError(int)) );
150 connect(m_send, SIGNAL(status(QCString&)),
151 this, SLOT(slotPushStatus(QCString&) ) );
152
153 ::sleep(4);
149 // now start it 154 // now start it
150 if (!m_send->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { 155 result = m_send->send(m_bdaddr, m_port, m_file, m_dst);
156 if (result > 0) //Sending process is actually running
157 return;
158 else if (result < 0) {
151 m_count = 25; 159 m_count = 25;
152 emit error(-1 ); 160 emit error(-1 );
153 delete m_send; 161 delete m_send;
154 m_send=0; 162 m_send=0;
155 } 163 }
156 // end 164 // end
157 m_count++; 165 m_count++;
158 emit currentTry( m_count ); 166 emit currentTry( m_count );
159} 167}
160 168
161void BtObex::slotExited(OProcess* proc ){ 169void BtObex::slotExited(OProcess* proc ){
162 odebug << proc->name() << " exited with result " 170 odebug << proc->name() << " exited with result "
163 << proc->exitStatus() << oendl; 171 << proc->exitStatus() << oendl;
164 if (proc == m_rec ) // receive process 172 if (proc == m_rec ) // receive process
165 received(); 173 received();
166 else if ( proc == m_send )
167 sendEnd();
168
169} 174}
170void BtObex::slotStdOut(OProcess* proc, char* buf, int len){ 175void BtObex::slotStdOut(OProcess* proc, char* buf, int len){
171 if ( proc == m_rec ) { // only receive 176 if ( proc == m_rec ) { // only receive
172 QByteArray ar( len ); 177 QByteArray ar( len );
173 memcpy( ar.data(), buf, len ); 178 memcpy( ar.data(), buf, len );
174 m_outp.append( ar ); 179 m_outp.append( ar );
175 } 180 }
176} 181}
177 182
183void BtObex::slotPushComplete(int result) {
184 if (result == 0) {
185 delete m_send;
186 m_send=0;
187 emit sent(true);
188 } else { // it failed maybe the other side wasn't ready
189 // let's try it again
190 delete m_send;
191 m_send = 0;
192 sendNow();
193 }
194}
195
196void BtObex::slotPushError(int) {
197 emit error( -1 );
198 delete m_send;
199 m_send = 0;
200}
201
202void BtObex::slotPushStatus(QCString& str) {
203 odebug << str << oendl;
204}
205
178void BtObex::received() { 206void BtObex::received() {
179 if (m_rec->normalExit() ) { 207 if (m_rec->normalExit() ) {
180 if ( m_rec->exitStatus() == 0 ) { // we got one 208 if ( m_rec->exitStatus() == 0 ) { // we got one
181 QString filename = parseOut(); 209 QString filename = parseOut();
182 emit receivedFile( filename ); 210 emit receivedFile( filename );
183 } 211 }
184 }else{ 212 }else{
185 emit done(false); 213 emit done(false);
186 }; 214 };
187 delete m_rec; 215 delete m_rec;
188 m_rec = 0; 216 m_rec = 0;
189 receive(); 217 receive();
190} 218}
191 219
192void BtObex::sendEnd() {
193 if (m_send->normalExit() ) {
194 if ( m_send->exitStatus() == 0 ) {
195 delete m_send;
196 m_send=0;
197 emit sent(true);
198 }else if (m_send->exitStatus() != 0 ) { // it failed maybe the other side wasn't ready
199 // let's try it again
200 delete m_send;
201 m_send = 0;
202 sendNow();
203 }
204 }else {
205 emit error( -1 );
206 delete m_send;
207 m_send = 0;
208 }
209}
210
211// This probably doesn't do anything useful for bt. 220// This probably doesn't do anything useful for bt.
212QString BtObex::parseOut(){ 221QString BtObex::parseOut(){
213 QString path; 222 QString path;
214 QStringList list = QStringList::split("\n", m_outp); 223 QStringList list = QStringList::split("\n", m_outp);
215 QStringList::Iterator it; 224 QStringList::Iterator it;
216 for (it = list.begin(); it != list.end(); ++it ) { 225 for (it = list.begin(); it != list.end(); ++it ) {
217 odebug << (*it) << oendl; 226 odebug << (*it) << oendl;
218 if ( (*it).startsWith("Wrote" ) ) { 227 if ( (*it).startsWith("Wrote" ) ) {
219 int pos = (*it).findRev('(' ); 228 int pos = (*it).findRev('(' );
220 if ( pos > 0 ) { 229 if ( pos > 0 ) {
221 230
222 path = (*it).remove( pos, (*it).length() - pos ); 231 path = (*it).remove( pos, (*it).length() - pos );
223 path = path.mid(6 ); 232 path = path.mid(6 );
224 path = path.stripWhiteSpace(); 233 path = path.stripWhiteSpace();
225 } 234 }
226 } 235 }
227 } 236 }
228 return path; 237 return path;
229} 238}
230/** 239/**
231 * when sent is done slotError is called we will start receive again 240 * when sent is done slotError is called we will start receive again
232 */ 241 */
233void BtObex::slotError() { 242void BtObex::slotError() {
234 if ( m_receive ) 243 if ( m_receive )
diff --git a/core/obex/btobex.h b/core/obex/btobex.h
index ba50064..9c1ab70 100644
--- a/core/obex/btobex.h
+++ b/core/obex/btobex.h
@@ -1,32 +1,33 @@
1 1
2 2
3#ifndef OpieBtObex_H 3#ifndef OpieBtObex_H
4#define OpieBtObex_H 4#define OpieBtObex_H
5 5
6#include <qobject.h> 6#include <qobject.h>
7#include <opietooth/services.h> 7#include <services.h>
8#include <opietooth/manager.h> 8#include <manager.h>
9#include <obexpush.h>
9 10
10namespace Opie {namespace Core {class OProcess;}} 11namespace Opie {namespace Core {class OProcess;}}
11class QCopChannel; 12class QCopChannel;
12using namespace OpieTooth; 13using namespace OpieTooth;
13namespace OpieObex { 14namespace OpieObex {
14 // Maybe this should be derved from Obex. 15 // Maybe this should be derved from Obex.
15 class BtObex : public QObject { 16 class BtObex : public QObject {
16 Q_OBJECT 17 Q_OBJECT
17 public: 18 public:
18 /** 19 /**
19 * BtObex c'tor look 20 * BtObex c'tor look
20 */ 21 */
21 BtObex( QObject *parent, const char* name); 22 BtObex( QObject *parent, const char* name);
22 /** 23 /**
23 * d'tor 24 * d'tor
24 */ 25 */
25 ~BtObex(); 26 ~BtObex();
26 27
27 /** TODO mbhaynie -- Maybe opd would be a better way to receive. 28 /** TODO mbhaynie -- Maybe opd would be a better way to receive.
28 * Starting listening to Bluetooth after enabled by the applet 29 * Starting listening to Bluetooth after enabled by the applet
29 * a signal gets emitted when received a file 30 * a signal gets emitted when received a file
30 */ 31 */
31 void receive(); 32 void receive();
32 void send( const QString&, const QString& ); 33 void send( const QString&, const QString& );
@@ -38,49 +39,52 @@ namespace OpieObex {
38 * @param path The path to the received file 39 * @param path The path to the received file
39 */ 40 */
40 void receivedFile( const QString& path); 41 void receivedFile( const QString& path);
41 /** 42 /**
42 * error signal if the program couldn't be started or the 43 * error signal if the program couldn't be started or the
43 * the connection timed out 44 * the connection timed out
44 */ 45 */
45 void error( int ); 46 void error( int );
46 /** 47 /**
47 * The current try to receive data 48 * The current try to receive data
48 */ 49 */
49 void currentTry(unsigned int); 50 void currentTry(unsigned int);
50 /** 51 /**
51 * signal sent The file got beamed to the remote location 52 * signal sent The file got beamed to the remote location
52 */ 53 */
53 void sent(bool); 54 void sent(bool);
54 void done(bool); 55 void done(bool);
55 56
56 private: 57 private:
57 uint m_count; 58 uint m_count;
58 QString m_file; 59 QString m_file;
59 QString m_outp; 60 QString m_outp;
60 QString m_bdaddr; 61 QString m_bdaddr;
61 int m_port; 62 int m_port;
62 Opie::Core::OProcess *m_send; 63 ObexPush* m_send;
63 Opie::Core::OProcess *m_rec; 64 Opie::Core::OProcess *m_rec;
64 bool m_receive : 1; 65 bool m_receive : 1;
65 OpieTooth::Manager* btManager; 66 OpieTooth::Manager* btManager;
66 void shutDownReceive(); 67 void shutDownReceive();
67 68
68private slots: 69private slots:
69 70
71 // Push process slots
72 void slotPushStatus(QCString&);
73 void slotPushComplete(int);
74 void slotPushError(int);
75
70 // the process exited 76 // the process exited
71 void slotExited(Opie::Core::OProcess*) ; 77 void slotExited(Opie::Core::OProcess*) ;
72 void slotStdOut(Opie::Core::OProcess*, char*, int); 78 void slotStdOut(Opie::Core::OProcess*, char*, int);
73 void slotError(); 79 void slotError();
74 void slotFoundServices(const QString&, Services::ValueList); 80 void slotFoundServices(const QString&, Services::ValueList);
75 81
76 private: 82 private:
77 void sendNow(); 83 void sendNow();
78 QString parseOut(); 84 QString parseOut();
79 void received(); 85 void received();
80 void sendEnd();
81
82 }; 86 };
83}; 87};
84 88
85 89
86#endif 90#endif