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