-rw-r--r-- | core/obex/obex.cc | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/core/obex/obex.cc b/core/obex/obex.cc index 3c99af6..7c40b90 100644 --- a/core/obex/obex.cc +++ b/core/obex/obex.cc | |||
@@ -1,200 +1,205 @@ | |||
1 | 1 | ||
2 | #include "obex.h" | ||
3 | |||
4 | /* OPIE */ | ||
5 | #include <opie2/oprocess.h> | ||
6 | #include <opie2/odebug.h> | ||
7 | |||
8 | /* QT */ | ||
2 | #include <qfileinfo.h> | 9 | #include <qfileinfo.h> |
3 | 10 | ||
4 | 11 | ||
5 | #include <opie2/oprocess.h> | ||
6 | #include "obex.h" | ||
7 | 12 | ||
8 | using namespace OpieObex; | 13 | using namespace OpieObex; |
9 | 14 | ||
10 | using namespace Opie::Core; | 15 | using namespace Opie::Core; |
11 | /* TRANSLATOR OpieObex::Obex */ | 16 | /* TRANSLATOR OpieObex::Obex */ |
12 | 17 | ||
13 | Obex::Obex( QObject *parent, const char* name ) | 18 | Obex::Obex( QObject *parent, const char* name ) |
14 | : QObject(parent, name ) | 19 | : QObject(parent, name ) |
15 | { | 20 | { |
16 | m_rec = 0; | 21 | m_rec = 0; |
17 | m_send=0; | 22 | m_send=0; |
18 | m_count = 0; | 23 | m_count = 0; |
19 | m_receive = false; | 24 | m_receive = false; |
20 | connect( this, SIGNAL(error(int) ), // for recovering to receive | 25 | connect( this, SIGNAL(error(int) ), // for recovering to receive |
21 | SLOT(slotError() ) ); | 26 | SLOT(slotError() ) ); |
22 | connect( this, SIGNAL(sent(bool) ), | 27 | connect( this, SIGNAL(sent(bool) ), |
23 | SLOT(slotError() ) ); | 28 | SLOT(slotError() ) ); |
24 | }; | 29 | }; |
25 | Obex::~Obex() { | 30 | Obex::~Obex() { |
26 | delete m_rec; | 31 | delete m_rec; |
27 | delete m_send; | 32 | delete m_send; |
28 | } | 33 | } |
29 | void Obex::receive() { | 34 | void Obex::receive() { |
30 | m_receive = true; | 35 | m_receive = true; |
31 | m_outp = QString::null; | 36 | m_outp = QString::null; |
32 | qWarning("Receive" ); | 37 | owarn << "Receive" << oendl; |
33 | m_rec = new OProcess(); | 38 | m_rec = new OProcess(); |
34 | *m_rec << "irobex_palm3"; | 39 | *m_rec << "irobex_palm3"; |
35 | // connect to the necessary slots | 40 | // connect to the necessary slots |
36 | connect(m_rec, SIGNAL(processExited(Opie::Core::OProcess*) ), | 41 | connect(m_rec, SIGNAL(processExited(Opie::Core::OProcess*) ), |
37 | this, SLOT(slotExited(Opie::Core::OProcess*) ) ); | 42 | this, SLOT(slotExited(Opie::Core::OProcess*) ) ); |
38 | 43 | ||
39 | connect(m_rec, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ), | 44 | connect(m_rec, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ), |
40 | this, SLOT(slotStdOut(Opie::Core::OProcess*, char*, int) ) ); | 45 | this, SLOT(slotStdOut(Opie::Core::OProcess*, char*, int) ) ); |
41 | 46 | ||
42 | if(!m_rec->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { | 47 | if(!m_rec->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { |
43 | qWarning("could not start :("); | 48 | owarn << "could not start :(" oendl; |
44 | emit done( false ); | 49 | emit done( false ); |
45 | delete m_rec; | 50 | delete m_rec; |
46 | m_rec = 0; | 51 | m_rec = 0; |
47 | } | 52 | } |
48 | // emit currentTry(m_count ); | 53 | // emit currentTry(m_count ); |
49 | 54 | ||
50 | } | 55 | } |
51 | void Obex::send( const QString& fileName) { // if currently receiving stop it send receive | 56 | void Obex::send( const QString& fileName) { // if currently receiving stop it send receive |
52 | m_count = 0; | 57 | m_count = 0; |
53 | m_file = fileName; | 58 | m_file = fileName; |
54 | qWarning("send %s", fileName.latin1() ); | 59 | owarn << "send " << fileName.latin1() << oendl; |
55 | if (m_rec != 0 ) { | 60 | if (m_rec != 0 ) { |
56 | qWarning("running"); | 61 | owarn << "running" oendl; |
57 | if (m_rec->isRunning() ) { | 62 | if (m_rec->isRunning() ) { |
58 | emit error(-1 ); | 63 | emit error(-1 ); |
59 | qWarning("is running"); | 64 | owarn << "is running" << oendl; |
60 | delete m_rec; | 65 | delete m_rec; |
61 | m_rec = 0; | 66 | m_rec = 0; |
62 | 67 | ||
63 | }else{ | 68 | }else{ |
64 | qWarning("is not running"); | 69 | owarn << "is not running" << oendl; |
65 | emit error( -1 ); // we did not delete yet but it's not running slotExited is pending | 70 | emit error( -1 ); // we did not delete yet but it's not running slotExited is pending |
66 | return; | 71 | return; |
67 | } | 72 | } |
68 | } | 73 | } |
69 | sendNow(); | 74 | sendNow(); |
70 | } | 75 | } |
71 | void Obex::sendNow(){ | 76 | void Obex::sendNow(){ |
72 | qWarning("sendNow"); | 77 | owarn << "sendNow" << oendl; |
73 | if ( m_count >= 25 ) { // could not send | 78 | if ( m_count >= 25 ) { // could not send |
74 | emit error(-1 ); | 79 | emit error(-1 ); |
75 | emit sent(false); | 80 | emit sent(false); |
76 | return; | 81 | return; |
77 | } | 82 | } |
78 | // OProcess inititialisation | 83 | // OProcess inititialisation |
79 | m_send = new OProcess(); | 84 | m_send = new OProcess(); |
80 | *m_send << "irobex_palm3"; | 85 | *m_send << "irobex_palm3"; |
81 | *m_send << QFile::encodeName(m_file); | 86 | *m_send << QFile::encodeName(m_file); |
82 | 87 | ||
83 | // connect to slots Exited and and StdOut | 88 | // connect to slots Exited and and StdOut |
84 | connect(m_send, SIGNAL(processExited(Opie::Core::OProcess*) ), | 89 | connect(m_send, SIGNAL(processExited(Opie::Core::OProcess*) ), |
85 | this, SLOT(slotExited(Opie::Core::OProcess*)) ); | 90 | this, SLOT(slotExited(Opie::Core::OProcess*)) ); |
86 | connect(m_send, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int )), | 91 | connect(m_send, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int )), |
87 | this, SLOT(slotStdOut(Opie::Core::OProcess*, char*, int) ) ); | 92 | this, SLOT(slotStdOut(Opie::Core::OProcess*, char*, int) ) ); |
88 | 93 | ||
89 | // now start it | 94 | // now start it |
90 | if (!m_send->start(/*OProcess::NotifyOnExit, OProcess::AllOutput*/ ) ) { | 95 | if (!m_send->start(/*OProcess::NotifyOnExit, OProcess::AllOutput*/ ) ) { |
91 | qWarning("could not send" ); | 96 | owarn << "could not send" << oendl; |
92 | m_count = 25; | 97 | m_count = 25; |
93 | emit error(-1 ); | 98 | emit error(-1 ); |
94 | delete m_send; | 99 | delete m_send; |
95 | m_send=0; | 100 | m_send=0; |
96 | } | 101 | } |
97 | // end | 102 | // end |
98 | m_count++; | 103 | m_count++; |
99 | emit currentTry( m_count ); | 104 | emit currentTry( m_count ); |
100 | } | 105 | } |
101 | 106 | ||
102 | void Obex::slotExited(OProcess* proc ){ | 107 | void Obex::slotExited(OProcess* proc ){ |
103 | if (proc == m_rec ) { // receive process | 108 | if (proc == m_rec ) { // receive process |
104 | received(); | 109 | received(); |
105 | }else if ( proc == m_send ) { | 110 | }else if ( proc == m_send ) { |
106 | sendEnd(); | 111 | sendEnd(); |
107 | } | 112 | } |
108 | } | 113 | } |
109 | void Obex::slotStdOut(OProcess* proc, char* buf, int len){ | 114 | void Obex::slotStdOut(OProcess* proc, char* buf, int len){ |
110 | if ( proc == m_rec ) { // only receive | 115 | if ( proc == m_rec ) { // only receive |
111 | QByteArray ar( len ); | 116 | QByteArray ar( len ); |
112 | memcpy( ar.data(), buf, len ); | 117 | memcpy( ar.data(), buf, len ); |
113 | qWarning("parsed: %s", ar.data() ); | 118 | owarn << "parsed: " << ar.data() << oendl; |
114 | m_outp.append( ar ); | 119 | m_outp.append( ar ); |
115 | } | 120 | } |
116 | } | 121 | } |
117 | 122 | ||
118 | void Obex::received() { | 123 | void Obex::received() { |
119 | if (m_rec->normalExit() ) { | 124 | if (m_rec->normalExit() ) { |
120 | if ( m_rec->exitStatus() == 0 ) { // we got one | 125 | if ( m_rec->exitStatus() == 0 ) { // we got one |
121 | QString filename = parseOut(); | 126 | QString filename = parseOut(); |
122 | qWarning("ACHTUNG %s", filename.latin1() ); | 127 | owarn << "ACHTUNG " << filename.latin1() << oendl; |
123 | emit receivedFile( filename ); | 128 | emit receivedFile( filename ); |
124 | } | 129 | } |
125 | }else{ | 130 | }else{ |
126 | emit done(false); | 131 | emit done(false); |
127 | }; | 132 | }; |
128 | delete m_rec; | 133 | delete m_rec; |
129 | m_rec = 0; | 134 | m_rec = 0; |
130 | receive(); | 135 | receive(); |
131 | } | 136 | } |
132 | 137 | ||
133 | void Obex::sendEnd() { | 138 | void Obex::sendEnd() { |
134 | if (m_send->normalExit() ) { | 139 | if (m_send->normalExit() ) { |
135 | if ( m_send->exitStatus() == 0 ) { | 140 | if ( m_send->exitStatus() == 0 ) { |
136 | delete m_send; | 141 | delete m_send; |
137 | m_send=0; | 142 | m_send=0; |
138 | qWarning("done" ); | 143 | owarn << "done" << oendl; |
139 | emit sent(true); | 144 | emit sent(true); |
140 | }else if (m_send->exitStatus() == 255 ) { // it failed maybe the other side wasn't ready | 145 | }else if (m_send->exitStatus() == 255 ) { // it failed maybe the other side wasn't ready |
141 | // let's try it again | 146 | // let's try it again |
142 | delete m_send; | 147 | delete m_send; |
143 | m_send = 0; | 148 | m_send = 0; |
144 | qWarning("try sending again" ); | 149 | owarn << "try sending again" << oendl; |
145 | sendNow(); | 150 | sendNow(); |
146 | } | 151 | } |
147 | }else { | 152 | }else { |
148 | emit error( -1 ); | 153 | emit error( -1 ); |
149 | delete m_send; | 154 | delete m_send; |
150 | m_send = 0; | 155 | m_send = 0; |
151 | } | 156 | } |
152 | } | 157 | } |
153 | QString Obex::parseOut( ){ | 158 | QString Obex::parseOut( ){ |
154 | QString path; | 159 | QString path; |
155 | QStringList list = QStringList::split("\n", m_outp); | 160 | QStringList list = QStringList::split("\n", m_outp); |
156 | QStringList::Iterator it; | 161 | QStringList::Iterator it; |
157 | for (it = list.begin(); it != list.end(); ++it ) { | 162 | for (it = list.begin(); it != list.end(); ++it ) { |
158 | if ( (*it).startsWith("Wrote" ) ) { | 163 | if ( (*it).startsWith("Wrote" ) ) { |
159 | int pos = (*it).findRev('(' ); | 164 | int pos = (*it).findRev('(' ); |
160 | if ( pos > 0 ) { | 165 | if ( pos > 0 ) { |
161 | qWarning( "%d %s", pos, (*it).mid(6 ).latin1() ) ; | 166 | owarn << pos << " " << (*it).mid(6 ).latin1() << oendl; |
162 | qWarning("%d %d", (*it).length(), (*it).length()-pos ); | 167 | owarn << (*it).length() << " " << (*it).length()-pos << oendl; |
163 | 168 | ||
164 | path = (*it).remove( pos, (*it).length() - pos ); | 169 | path = (*it).remove( pos, (*it).length() - pos ); |
165 | qWarning("%s", path.latin1() ); | 170 | owarn << path.latin1() << oendl; |
166 | path = path.mid(6 ); | 171 | path = path.mid(6 ); |
167 | path = path.stripWhiteSpace(); | 172 | path = path.stripWhiteSpace(); |
168 | qWarning("path %s", path.latin1() ); | 173 | owarn << "path " << path.latin1() << oendl; |
169 | } | 174 | } |
170 | } | 175 | } |
171 | } | 176 | } |
172 | return path; | 177 | return path; |
173 | } | 178 | } |
174 | /** | 179 | /** |
175 | * when sent is done slotError is called we will start receive again | 180 | * when sent is done slotError is called we will start receive again |
176 | */ | 181 | */ |
177 | void Obex::slotError() { | 182 | void Obex::slotError() { |
178 | qWarning("slotError"); | 183 | owarn << "slotError" << oendl; |
179 | if ( m_receive ) | 184 | if ( m_receive ) |
180 | receive(); | 185 | receive(); |
181 | }; | 186 | }; |
182 | void Obex::setReceiveEnabled( bool receive ) { | 187 | void Obex::setReceiveEnabled( bool receive ) { |
183 | if ( !receive ) { // | 188 | if ( !receive ) { // |
184 | m_receive = false; | 189 | m_receive = false; |
185 | shutDownReceive(); | 190 | shutDownReceive(); |
186 | } | 191 | } |
187 | } | 192 | } |
188 | 193 | ||
189 | void Obex::shutDownReceive() { | 194 | void Obex::shutDownReceive() { |
190 | if (m_rec != 0 ) { | 195 | if (m_rec != 0 ) { |
191 | qWarning("running"); | 196 | owarn << "running" << oendl; |
192 | if (m_rec->isRunning() ) { | 197 | if (m_rec->isRunning() ) { |
193 | emit error(-1 ); | 198 | emit error(-1 ); |
194 | qWarning("is running"); | 199 | owarn << "is running" << oendl; |
195 | delete m_rec; | 200 | delete m_rec; |
196 | m_rec = 0; | 201 | m_rec = 0; |
197 | } | 202 | } |
198 | } | 203 | } |
199 | 204 | ||
200 | } | 205 | } |