author | zecke <zecke> | 2002-06-13 19:04:05 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-06-13 19:04:05 (UTC) |
commit | ed10b73df98c1b4c41a0b940e4f8729fe28c2b8a (patch) (unidiff) | |
tree | 9fe7679c82a41b21de3378090ce211c00a8bc178 /core/applets/obex/obex.cc | |
parent | 9939c618389465ef5837bf510186d583891e65e3 (diff) | |
download | opie-ed10b73df98c1b4c41a0b940e4f8729fe28c2b8a.zip opie-ed10b73df98c1b4c41a0b940e4f8729fe28c2b8a.tar.gz opie-ed10b73df98c1b4c41a0b940e4f8729fe28c2b8a.tar.bz2 |
Stop receiving when wanting to send
-rw-r--r-- | core/applets/obex/obex.cc | 164 |
1 files changed, 110 insertions, 54 deletions
diff --git a/core/applets/obex/obex.cc b/core/applets/obex/obex.cc index 683964b..2218dbc 100644 --- a/core/applets/obex/obex.cc +++ b/core/applets/obex/obex.cc | |||
@@ -10,87 +10,116 @@ using namespace OpieObex; | |||
10 | Obex::Obex( QObject *parent, const char* name ) | 10 | Obex::Obex( QObject *parent, const char* name ) |
11 | : QObject(parent, name ) | 11 | : QObject(parent, name ) |
12 | { | 12 | { |
13 | m_rec = 0; | 13 | m_rec = 0; |
14 | m_send=0; | 14 | m_send=0; |
15 | m_count = 0; | 15 | m_count = 0; |
16 | m_receive = false; | ||
17 | connect( this, SIGNAL(error(int) ), // for recovering to receive | ||
18 | SLOT(slotError() ) ); | ||
19 | connect( this, SIGNAL(sent() ), | ||
20 | SLOT(slotError() ) ); | ||
16 | }; | 21 | }; |
17 | Obex::~Obex() { | 22 | Obex::~Obex() { |
18 | delete m_rec; | 23 | delete m_rec; |
19 | delete m_send; | 24 | delete m_send; |
20 | } | 25 | } |
21 | void Obex::receive() { | 26 | void Obex::receive() { |
22 | qWarning("Receive" ); | 27 | m_receive = true; |
23 | m_rec = new OProcess(); | 28 | qWarning("Receive" ); |
24 | *m_rec << "irobex_palm3"; | 29 | m_rec = new OProcess(); |
25 | // connect to the necessary slots | 30 | *m_rec << "irobex_palm3"; |
26 | connect(m_rec, SIGNAL(processExited(OProcess*) ), | 31 | // connect to the necessary slots |
27 | this, SLOT(slotExited(OProcess*) ) ); | 32 | connect(m_rec, SIGNAL(processExited(OProcess*) ), |
33 | this, SLOT(slotExited(OProcess*) ) ); | ||
28 | 34 | ||
29 | connect(m_rec, SIGNAL(receivedStdout(OProcess*, char*, int ) ), | 35 | connect(m_rec, SIGNAL(receivedStdout(OProcess*, char*, int ) ), |
30 | this, SLOT(slotStdOut(OProcess*, char*, int) ) ); | 36 | this, SLOT(slotStdOut(OProcess*, char*, int) ) ); |
31 | 37 | ||
32 | if(!m_rec->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { | 38 | if(!m_rec->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { |
33 | qWarning("could not start :("); | 39 | qWarning("could not start :("); |
34 | emit done( false ); | 40 | emit done( false ); |
35 | } | 41 | delete m_rec; |
36 | emit currentTry(m_count ); | 42 | m_rec = 0; |
43 | } | ||
44 | // emit currentTry(m_count ); | ||
37 | 45 | ||
38 | } | 46 | } |
39 | void Obex::send( const QString& fileName) { | 47 | void Obex::send( const QString& fileName) { // if currently receiving stop it send receive |
40 | m_count = 0; | 48 | m_count = 0; |
41 | m_file = fileName; | 49 | m_file = fileName; |
42 | sendNow(); | 50 | qWarning("send"); |
51 | if (m_rec != 0 ) { | ||
52 | qWarning("running"); | ||
53 | if (m_rec->isRunning() ) { | ||
54 | emit error(-1 ); | ||
55 | qWarning("is running"); | ||
56 | delete m_rec; | ||
57 | m_rec = 0; | ||
58 | |||
59 | }else{ | ||
60 | qWarning("is not running"); | ||
61 | emit error( -1 ); // we did not delete yet but it's not running slotExited is pending | ||
62 | return; | ||
63 | } | ||
64 | } | ||
65 | sendNow(); | ||
43 | } | 66 | } |
44 | void Obex::sendNow(){ | 67 | void Obex::sendNow(){ |
45 | if ( m_count >= 25 ) { // could not send | 68 | qWarning("sendNow"); |
46 | emit error(-1 ); | 69 | if ( m_count >= 25 ) { // could not send |
47 | return; | 70 | emit error(-1 ); |
48 | } | 71 | return; |
49 | // OProcess inititialisation | 72 | } |
50 | m_send = new OProcess(); | 73 | // OProcess inititialisation |
51 | *m_send << "irobex_palm3"; | 74 | m_send = new OProcess(); |
52 | *m_send << m_file; | 75 | *m_send << "irobex_palm3"; |
76 | *m_send << m_file; | ||
53 | 77 | ||
54 | // connect to slots Exited and and StdOut | 78 | // connect to slots Exited and and StdOut |
55 | connect(m_send, SIGNAL(processExited(OProcess*) ), | 79 | connect(m_send, SIGNAL(processExited(OProcess*) ), |
56 | this, SLOT(slotExited(OProcess*)) ); | 80 | this, SLOT(slotExited(OProcess*)) ); |
57 | connect(m_send, SIGNAL(receivedStdout(OProcess*, char*, int )), | 81 | connect(m_send, SIGNAL(receivedStdout(OProcess*, char*, int )), |
58 | this, SLOT(slotStdOut(OProcess*, char*, int) ) ); | 82 | this, SLOT(slotStdOut(OProcess*, char*, int) ) ); |
59 | // now start it | 83 | |
60 | if (!m_send->start(/*OProcess::NotifyOnExit, OProcess::AllOutput*/ ) ) { | 84 | // now start it |
61 | qWarning("could not send" ); | 85 | if (!m_send->start(/*OProcess::NotifyOnExit, OProcess::AllOutput*/ ) ) { |
62 | m_count = 25; | 86 | qWarning("could not send" ); |
63 | emit error(-1 ); | 87 | m_count = 25; |
64 | } | 88 | emit error(-1 ); |
65 | // end | 89 | delete m_send; |
66 | m_count++; | 90 | m_send=0; |
67 | emit currentTry( m_count ); | 91 | } |
92 | // end | ||
93 | m_count++; | ||
94 | emit currentTry( m_count ); | ||
68 | } | 95 | } |
69 | 96 | ||
70 | void Obex::slotExited(OProcess* proc ){ | 97 | void Obex::slotExited(OProcess* proc ){ |
71 | if (proc == m_rec ) { // recieve process | 98 | if (proc == m_rec ) { // recieve process |
72 | recieved(); | 99 | recieved(); |
73 | }else if ( proc == m_send ) { | 100 | }else if ( proc == m_send ) { |
74 | sendEnd(); | 101 | sendEnd(); |
75 | } | 102 | } |
76 | } | 103 | } |
77 | void Obex::slotStdOut(OProcess* proc, char* buf, int len){ | 104 | void Obex::slotStdOut(OProcess* proc, char* buf, int len){ |
78 | if ( proc == m_rec ) { // only recieve | 105 | if ( proc == m_rec ) { // only recieve |
79 | QCString cstring( buf, len ); | 106 | QCString cstring( buf, len ); |
80 | m_outp.append( cstring.data() ); | 107 | m_outp.append( cstring.data() ); |
81 | } | 108 | } |
82 | } | 109 | } |
83 | 110 | ||
84 | void Obex::recieved() { | 111 | void Obex::recieved() { |
85 | if (m_rec->normalExit() ) { | 112 | if (m_rec->normalExit() ) { |
86 | if ( m_rec->exitStatus() == 0 ) { // we got one | 113 | if ( m_rec->exitStatus() == 0 ) { // we got one |
87 | QString filename = parseOut(); | 114 | QString filename = parseOut(); |
88 | emit receivedFile( filename ); | 115 | emit receivedFile( filename ); |
89 | } | 116 | } |
90 | }else{ | 117 | }else{ |
91 | emit error(-1); | 118 | emit done(false); |
92 | }; | 119 | }; |
93 | delete m_rec; | 120 | delete m_rec; |
121 | m_rec = 0; | ||
122 | receive(); | ||
94 | } | 123 | } |
95 | 124 | ||
96 | void Obex::sendEnd() { | 125 | void Obex::sendEnd() { |
@@ -126,3 +155,30 @@ QString Obex::parseOut( ){ | |||
126 | } | 155 | } |
127 | return path; | 156 | return path; |
128 | } | 157 | } |
158 | /** | ||
159 | * when sent is done slotError is called we will start receive again | ||
160 | */ | ||
161 | void Obex::slotError() { | ||
162 | qWarning("slotError"); | ||
163 | if ( m_receive ) | ||
164 | receive(); | ||
165 | }; | ||
166 | void Obex::setReceiveEnabled( bool receive ) { | ||
167 | if ( !receive ) { // | ||
168 | m_receive = false; | ||
169 | shutDownReceive(); | ||
170 | } | ||
171 | } | ||
172 | |||
173 | void Obex::shutDownReceive() { | ||
174 | if (m_rec != 0 ) { | ||
175 | qWarning("running"); | ||
176 | if (m_rec->isRunning() ) { | ||
177 | emit error(-1 ); | ||
178 | qWarning("is running"); | ||
179 | delete m_rec; | ||
180 | m_rec = 0; | ||
181 | } | ||
182 | } | ||
183 | |||
184 | } | ||