author | korovkin <korovkin> | 2006-07-06 16:28:08 (UTC) |
---|---|---|
committer | korovkin <korovkin> | 2006-07-06 16:28:08 (UTC) |
commit | 43cd66c08de4447998028179d20fd4817aaf16ca (patch) (unidiff) | |
tree | 87888aadc3398c3c633e332cda46d92bb0522d6a | |
parent | adcfc6f4afe184a9eb6fbf458616494dfe0dadda (diff) | |
download | opie-43cd66c08de4447998028179d20fd4817aaf16ca.zip opie-43cd66c08de4447998028179d20fd4817aaf16ca.tar.gz opie-43cd66c08de4447998028179d20fd4817aaf16ca.tar.bz2 |
Added OBEX Push functionality for Bluetooth.
- Added ObexBase - asic class for IR and BT Obex
- Added ObexServer - OBEX Push server.
-rw-r--r-- | core/obex/.cvsignore | 2 | ||||
-rw-r--r-- | core/obex/btobex.cpp | 60 | ||||
-rw-r--r-- | core/obex/btobex.h | 40 | ||||
-rw-r--r-- | core/obex/obex.cpp | 49 | ||||
-rw-r--r-- | core/obex/obex.h | 40 | ||||
-rw-r--r-- | core/obex/obex.pro | 16 | ||||
-rw-r--r-- | core/obex/obexbase.cpp | 74 | ||||
-rw-r--r-- | core/obex/obexbase.h | 99 | ||||
-rw-r--r-- | core/obex/obexhandler.cpp | 44 | ||||
-rw-r--r-- | core/obex/obexhandler.h | 9 | ||||
-rw-r--r-- | core/obex/obexsend.cpp | 2 | ||||
-rw-r--r-- | core/obex/obexserver.cpp | 514 | ||||
-rw-r--r-- | core/obex/obexserver.h | 83 | ||||
-rw-r--r-- | core/obex/receiver.cpp | 9 | ||||
-rw-r--r-- | core/obex/receiver.h | 12 |
15 files changed, 985 insertions, 68 deletions
diff --git a/core/obex/.cvsignore b/core/obex/.cvsignore index ed75078..90f9614 100644 --- a/core/obex/.cvsignore +++ b/core/obex/.cvsignore | |||
@@ -1,4 +1,6 @@ | |||
1 | Makefile | 1 | Makefile |
2 | moc_* | 2 | moc_* |
3 | .moc | 3 | .moc |
4 | .obj | 4 | .obj |
5 | obexsendbase.h | ||
6 | obexsendbase.cpp | ||
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,6 +1,36 @@ | |||
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 */ |
@@ -17,38 +47,31 @@ using namespace OpieObex; | |||
17 | 47 | ||
18 | using namespace Opie::Core; | 48 | using namespace Opie::Core; |
19 | /* TRANSLATOR OpieObex::Obex */ | 49 | /* TRANSLATOR OpieObex::Obex */ |
20 | using namespace OpieTooth; | 50 | using namespace OpieTooth; |
21 | 51 | ||
22 | BtObex::BtObex( QObject *parent, const char* name ) | 52 | BtObex::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 | ||
36 | BtObex::~BtObex() { | 60 | BtObex::~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 | ||
42 | void BtObex::receive() { | 66 | void 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) ) ); |
@@ -58,16 +81,14 @@ void BtObex::receive() { | |||
58 | delete m_rec; | 81 | delete m_rec; |
59 | m_rec = 0; | 82 | m_rec = 0; |
60 | } | 83 | } |
61 | } | 84 | } |
62 | 85 | ||
63 | void BtObex::send( const QString& fileName, const QString& bdaddr) { | 86 | void 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; |
@@ -147,12 +168,16 @@ void BtObex::sendNow(){ | |||
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) { |
@@ -168,18 +193,21 @@ void BtObex::sendNow(){ | |||
168 | 193 | ||
169 | void BtObex::slotExited(OProcess* proc ){ | 194 | void 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 | } |
175 | void BtObex::slotStdOut(OProcess* proc, char* buf, int len){ | 201 | void 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 | ||
183 | void BtObex::slotPushComplete(int result) { | 211 | void BtObex::slotPushComplete(int result) { |
184 | if (result == 0) { | 212 | if (result == 0) { |
185 | delete m_send; | 213 | delete m_send; |
@@ -204,12 +232,13 @@ void BtObex::slotPushStatus(QCString& str) { | |||
204 | } | 232 | } |
205 | 233 | ||
206 | void BtObex::received() { | 234 | void 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; |
@@ -237,16 +266,19 @@ QString BtObex::parseOut(){ | |||
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 | */ |
242 | void BtObex::slotError() { | 271 | void BtObex::slotError() { |
272 | ObexBase::slotError(); | ||
243 | if ( m_receive ) | 273 | if ( m_receive ) |
244 | receive(); | 274 | receive(); |
245 | }; | 275 | }; |
246 | void BtObex::setReceiveEnabled( bool receive ) { | 276 | void 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 | ||
diff --git a/core/obex/btobex.h b/core/obex/btobex.h index 9c1ab70..7e91c06 100644 --- a/core/obex/btobex.h +++ b/core/obex/btobex.h | |||
@@ -1,22 +1,54 @@ | |||
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 declaration | ||
30 | */ | ||
1 | 31 | ||
2 | 32 | ||
3 | #ifndef OpieBtObex_H | 33 | #ifndef OpieBtObex_H |
4 | #define OpieBtObex_H | 34 | #define OpieBtObex_H |
5 | 35 | ||
36 | #include "obexbase.h" | ||
6 | #include <qobject.h> | 37 | #include <qobject.h> |
7 | #include <services.h> | 38 | #include <services.h> |
8 | #include <manager.h> | 39 | #include <manager.h> |
9 | #include <obexpush.h> | 40 | #include <obexpush.h> |
41 | #include "obexserver.h" | ||
10 | 42 | ||
11 | namespace Opie {namespace Core {class OProcess;}} | 43 | namespace Opie {namespace Core {class OProcess;}} |
12 | class QCopChannel; | 44 | class QCopChannel; |
13 | using namespace OpieTooth; | 45 | using namespace OpieTooth; |
14 | namespace OpieObex { | 46 | namespace OpieObex { |
15 | // Maybe this should be derved from Obex. | 47 | // Maybe this should be derved from Obex. |
16 | class BtObex : public QObject { | 48 | class BtObex : public ObexBase { |
17 | Q_OBJECT | 49 | Q_OBJECT |
18 | public: | 50 | public: |
19 | /** | 51 | /** |
20 | * BtObex c'tor look | 52 | * BtObex c'tor look |
21 | */ | 53 | */ |
22 | BtObex( QObject *parent, const char* name); | 54 | BtObex( QObject *parent, const char* name); |
@@ -52,22 +84,18 @@ namespace OpieObex { | |||
52 | * signal sent The file got beamed to the remote location | 84 | * signal sent The file got beamed to the remote location |
53 | */ | 85 | */ |
54 | void sent(bool); | 86 | void sent(bool); |
55 | void done(bool); | 87 | void done(bool); |
56 | 88 | ||
57 | private: | 89 | private: |
58 | uint m_count; | ||
59 | QString m_file; | ||
60 | QString m_outp; | ||
61 | QString m_bdaddr; | ||
62 | int m_port; | 90 | int m_port; |
63 | ObexPush* m_send; | 91 | ObexPush* m_send; |
64 | Opie::Core::OProcess *m_rec; | ||
65 | bool m_receive : 1; | 92 | bool m_receive : 1; |
66 | OpieTooth::Manager* btManager; | 93 | OpieTooth::Manager* btManager; |
67 | void shutDownReceive(); | 94 | void shutDownReceive(); |
95 | ObexServer* m_rec; | ||
68 | 96 | ||
69 | private slots: | 97 | private slots: |
70 | 98 | ||
71 | // Push process slots | 99 | // Push process slots |
72 | void slotPushStatus(QCString&); | 100 | void slotPushStatus(QCString&); |
73 | void slotPushComplete(int); | 101 | void slotPushComplete(int); |
diff --git a/core/obex/obex.cpp b/core/obex/obex.cpp index 36634ec..95c561a 100644 --- a/core/obex/obex.cpp +++ b/core/obex/obex.cpp | |||
@@ -1,6 +1,36 @@ | |||
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 Infrared OBEX handling class implementation | ||
30 | */ | ||
1 | 31 | ||
2 | #include "obex.h" | 32 | #include "obex.h" |
3 | 33 | ||
4 | /* OPIE */ | 34 | /* OPIE */ |
5 | #include <opie2/oprocess.h> | 35 | #include <opie2/oprocess.h> |
6 | #include <opie2/odebug.h> | 36 | #include <opie2/odebug.h> |
@@ -13,30 +43,23 @@ | |||
13 | using namespace OpieObex; | 43 | using namespace OpieObex; |
14 | 44 | ||
15 | using namespace Opie::Core; | 45 | using namespace Opie::Core; |
16 | /* TRANSLATOR OpieObex::Obex */ | 46 | /* TRANSLATOR OpieObex::Obex */ |
17 | 47 | ||
18 | Obex::Obex( QObject *parent, const char* name ) | 48 | Obex::Obex( QObject *parent, const char* name ) |
19 | : QObject(parent, name ) | 49 | : ObexBase(parent, name ) |
20 | { | 50 | { |
21 | m_rec = 0; | 51 | m_rec = 0; |
22 | m_send=0; | 52 | m_send=0; |
23 | m_count = 0; | ||
24 | m_receive = false; | ||
25 | connect( this, SIGNAL(error(int) ), // for recovering to receive | ||
26 | SLOT(slotError() ) ); | ||
27 | connect( this, SIGNAL(sent(bool) ), | ||
28 | SLOT(slotError() ) ); | ||
29 | }; | 53 | }; |
30 | Obex::~Obex() { | 54 | Obex::~Obex() { |
31 | delete m_rec; | 55 | delete m_rec; |
32 | delete m_send; | 56 | delete m_send; |
33 | } | 57 | } |
34 | void Obex::receive() { | 58 | void Obex::receive() { |
35 | m_receive = true; | 59 | ObexBase::receive(); |
36 | m_outp = QString::null; | ||
37 | m_rec = new OProcess(); | 60 | m_rec = new OProcess(); |
38 | *m_rec << "irobex_palm3"; | 61 | *m_rec << "irobex_palm3"; |
39 | // connect to the necessary slots | 62 | // connect to the necessary slots |
40 | connect(m_rec, SIGNAL(processExited(Opie::Core::OProcess*) ), | 63 | connect(m_rec, SIGNAL(processExited(Opie::Core::OProcess*) ), |
41 | this, SLOT(slotExited(Opie::Core::OProcess*) ) ); | 64 | this, SLOT(slotExited(Opie::Core::OProcess*) ) ); |
42 | 65 | ||
@@ -47,15 +70,15 @@ void Obex::receive() { | |||
47 | emit done( false ); | 70 | emit done( false ); |
48 | delete m_rec; | 71 | delete m_rec; |
49 | m_rec = 0; | 72 | m_rec = 0; |
50 | } | 73 | } |
51 | } | 74 | } |
52 | 75 | ||
53 | void Obex::send( const QString& fileName) { // if currently receiving stop it send receive | 76 | // if currently receiving stop it send receive |
54 | m_count = 0; | 77 | void Obex::send(const QString& fileName, const QString& addr) { |
55 | m_file = fileName; | 78 | ObexBase::send(fileName, addr); |
56 | if (m_rec != 0 ) { | 79 | if (m_rec != 0 ) { |
57 | if (m_rec->isRunning() ) { | 80 | if (m_rec->isRunning() ) { |
58 | emit error(-1 ); | 81 | emit error(-1 ); |
59 | delete m_rec; | 82 | delete m_rec; |
60 | m_rec = 0; | 83 | m_rec = 0; |
61 | 84 | ||
@@ -162,16 +185,18 @@ QString Obex::parseOut( ){ | |||
162 | return path; | 185 | return path; |
163 | } | 186 | } |
164 | /** | 187 | /** |
165 | * when sent is done slotError is called we will start receive again | 188 | * when sent is done slotError is called we will start receive again |
166 | */ | 189 | */ |
167 | void Obex::slotError() { | 190 | void Obex::slotError() { |
191 | ObexBase::slotError(); | ||
168 | if ( m_receive ) | 192 | if ( m_receive ) |
169 | receive(); | 193 | receive(); |
170 | }; | 194 | }; |
171 | void Obex::setReceiveEnabled( bool receive ) { | 195 | void Obex::setReceiveEnabled( bool receive ) { |
196 | ObexBase::setReceiveEnabled(receive); | ||
172 | if ( !receive ) { // | 197 | if ( !receive ) { // |
173 | m_receive = false; | 198 | m_receive = false; |
174 | shutDownReceive(); | 199 | shutDownReceive(); |
175 | } | 200 | } |
176 | } | 201 | } |
177 | 202 | ||
diff --git a/core/obex/obex.h b/core/obex/obex.h index 5993976..36ff29a 100644 --- a/core/obex/obex.h +++ b/core/obex/obex.h | |||
@@ -1,17 +1,47 @@ | |||
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. | ||
1 | 26 | ||
27 | */ | ||
28 | /* | ||
29 | * The Infrared OBEX handling class declaration | ||
30 | */ | ||
2 | 31 | ||
3 | #ifndef OpieObex_H | 32 | #ifndef OpieObex_H |
4 | #define OpieObex_H | 33 | #define OpieObex_H |
5 | 34 | ||
35 | #include "obexbase.h" | ||
6 | #include <qobject.h> | 36 | #include <qobject.h> |
7 | 37 | ||
8 | namespace Opie {namespace Core {class OProcess;}} | 38 | namespace Opie {namespace Core {class OProcess;}} |
9 | class QCopChannel; | 39 | class QCopChannel; |
10 | namespace OpieObex { | 40 | namespace OpieObex { |
11 | class Obex : public QObject { | 41 | class Obex : public ObexBase { |
12 | Q_OBJECT | 42 | Q_OBJECT |
13 | public: | 43 | public: |
14 | /** | 44 | /** |
15 | * Obex c'tor look | 45 | * Obex c'tor look |
16 | */ | 46 | */ |
17 | Obex( QObject *parent, const char* name); | 47 | Obex( QObject *parent, const char* name); |
@@ -21,15 +51,15 @@ namespace OpieObex { | |||
21 | ~Obex(); | 51 | ~Obex(); |
22 | 52 | ||
23 | /** | 53 | /** |
24 | * Starting listening to irda after enabled by the applet | 54 | * Starting listening to irda after enabled by the applet |
25 | * a signal gets emitted when received a file | 55 | * a signal gets emitted when received a file |
26 | */ | 56 | */ |
27 | void receive(); | 57 | virtual void receive(); |
28 | void send( const QString& ); | 58 | virtual void send(const QString& filename, const QString& addr); |
29 | void setReceiveEnabled( bool = false ); | 59 | virtual void setReceiveEnabled( bool = false ); |
30 | signals: | 60 | signals: |
31 | 61 | ||
32 | /** | 62 | /** |
33 | * a signal | 63 | * a signal |
34 | * @param path The path to the received file | 64 | * @param path The path to the received file |
35 | */ | 65 | */ |
@@ -66,13 +96,13 @@ private slots: | |||
66 | 96 | ||
67 | //void send(const QString&); | 97 | //void send(const QString&); |
68 | 98 | ||
69 | // the process exited | 99 | // the process exited |
70 | void slotExited(Opie::Core::OProcess* proc) ; | 100 | void slotExited(Opie::Core::OProcess* proc) ; |
71 | void slotStdOut(Opie::Core::OProcess*, char*, int); | 101 | void slotStdOut(Opie::Core::OProcess*, char*, int); |
72 | void slotError(); | 102 | virtual void slotError(); |
73 | 103 | ||
74 | private: | 104 | private: |
75 | void sendNow(); | 105 | void sendNow(); |
76 | QString parseOut(); | 106 | QString parseOut(); |
77 | void received(); | 107 | void received(); |
78 | void sendEnd(); | 108 | void sendEnd(); |
diff --git a/core/obex/obex.pro b/core/obex/obex.pro index 33cb957..1fc6958 100644 --- a/core/obex/obex.pro +++ b/core/obex/obex.pro | |||
@@ -1,14 +1,20 @@ | |||
1 | TEMPLATE= lib | 1 | TEMPLATE= lib |
2 | CONFIG += qt warn_on | 2 | CONFIG += qt warn_on |
3 | HEADERS= obex.h btobex.h obexhandler.h obexsend.h receiver.h obeximpl.h | 3 | HEADERS= obex.h btobex.h obexhandler.h obexsend.h receiver.h obeximpl.h obexbase.h obexserver.h |
4 | SOURCES= obex.cpp btobex.cpp obexsend.cpp obexhandler.cpp receiver.cpp obeximpl.cpp | 4 | SOURCES= obex.cpp btobex.cpp obexsend.cpp obexhandler.cpp receiver.cpp obeximpl.cpp obexbase.cpp obexserver.cpp |
5 | TARGET = opieobex | 5 | TARGET = opieobex |
6 | DESTDIR = $(OPIEDIR)/plugins/obex | 6 | DESTDIR = $(OPIEDIR)/plugins/obex |
7 | INTERFACES = obexsendbase.ui | 7 | INTERFACES = obexsendbase.ui |
8 | INCLUDEPATH += $(OPIEDIR)/include $(OPIEDIR)/core/launcher $(OPIEDIR)/noncore/net/opietooth/lib | 8 | INCLUDEPATH += $(OPIEDIR)/include $(OPIEDIR)/core/launcher |
9 | DEPENDPATH += | 9 | DEPENDPATH += |
10 | LIBS += -lopietooth1 -lqpe -lopiecore2 | 10 | LIBS += -lqpe -lopiecore2 |
11 | VERSION = 0.0.3 | 11 | VERSION = 0.0.4 |
12 | 12 | ||
13 | include( $(OPIEDIR)/include.pro ) | 13 | include( $(OPIEDIR)/include.pro ) |
14 | target.path = $$prefix/plugins/applets | 14 | target.path = $$prefix/plugins/applets |
15 | |||
16 | #FIXME: These parameters are used if bluetooth is used | ||
17 | INCLUDEPATH += $(OPIEDIR)/noncore/net/opietooth/lib | ||
18 | LIBS += -lopietooth1 -lbluetooth -lopenobex | ||
19 | DEFINES += BLUETOOTH | ||
20 | |||
diff --git a/core/obex/obexbase.cpp b/core/obex/obexbase.cpp new file mode 100644 index 0000000..8eda04e --- a/dev/null +++ b/core/obex/obexbase.cpp | |||
@@ -0,0 +1,74 @@ | |||
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 basic class for OBEX manipulating classes implementation | ||
30 | */ | ||
31 | |||
32 | #include "obexbase.h" | ||
33 | |||
34 | /* OPIE */ | ||
35 | #include <opie2/oprocess.h> | ||
36 | #include <opie2/odebug.h> | ||
37 | |||
38 | using namespace OpieObex; | ||
39 | |||
40 | using namespace Opie::Core; | ||
41 | |||
42 | ObexBase::ObexBase(QObject *parent, const char* name) | ||
43 | : QObject(parent, name) | ||
44 | { | ||
45 | m_count = 0; | ||
46 | m_receive = false; | ||
47 | connect( this, SIGNAL(error(int) ), // for recovering to receive | ||
48 | SLOT(slotError() ) ); | ||
49 | connect( this, SIGNAL(sent(bool) ), | ||
50 | SLOT(slotError() ) ); | ||
51 | } | ||
52 | |||
53 | ObexBase::~ObexBase() { | ||
54 | } | ||
55 | |||
56 | void ObexBase::receive() { | ||
57 | m_receive = true; | ||
58 | m_outp = QString::null; | ||
59 | } | ||
60 | |||
61 | void ObexBase::send( const QString& fileName, const QString& bdaddr) { | ||
62 | // if currently receiving stop it send receive | ||
63 | m_count = 0; | ||
64 | m_file = fileName; | ||
65 | m_bdaddr = bdaddr; | ||
66 | } | ||
67 | |||
68 | void ObexBase::setReceiveEnabled(bool) { | ||
69 | } | ||
70 | |||
71 | void ObexBase::slotError() { | ||
72 | } | ||
73 | |||
74 | //eof | ||
diff --git a/core/obex/obexbase.h b/core/obex/obexbase.h new file mode 100644 index 0000000..f65d922 --- a/dev/null +++ b/core/obex/obexbase.h | |||
@@ -0,0 +1,99 @@ | |||
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 basic class for OBEX manipulating classes declaration | ||
30 | */ | ||
31 | #ifndef ObexBase_H | ||
32 | #define ObexBase_H | ||
33 | |||
34 | #include <qobject.h> | ||
35 | |||
36 | namespace Opie {namespace Core {class OProcess;}} | ||
37 | class QCopChannel; | ||
38 | namespace OpieObex { | ||
39 | class ObexBase : public QObject { | ||
40 | Q_OBJECT | ||
41 | public: | ||
42 | /** | ||
43 | * ObexBase constructor look | ||
44 | */ | ||
45 | ObexBase(QObject *parent, const char* name); | ||
46 | /** | ||
47 | * d'tor | ||
48 | */ | ||
49 | virtual ~ObexBase(); | ||
50 | /** | ||
51 | * Starting listening to an interface after enabled by the applet | ||
52 | * a signal gets emitted when received a file | ||
53 | */ | ||
54 | virtual void receive(); | ||
55 | /** | ||
56 | * Send the file | ||
57 | * @param the name of the file | ||
58 | * @param the address of the device | ||
59 | */ | ||
60 | virtual void send(const QString&, const QString&); | ||
61 | /** | ||
62 | * Stop receiving | ||
63 | * @param if true - does nothing if false - stops receiving | ||
64 | */ | ||
65 | virtual void setReceiveEnabled(bool = false); | ||
66 | signals: | ||
67 | /** | ||
68 | * Notify the upper level that we have received the file | ||
69 | * @param path The path to the received file | ||
70 | */ | ||
71 | void receivedFile(const QString& path); | ||
72 | /** | ||
73 | * error signal if the program couldn't be started or the | ||
74 | * the connection timed out | ||
75 | */ | ||
76 | void error(int); | ||
77 | /** | ||
78 | * The current try to receive data | ||
79 | */ | ||
80 | void currentTry(unsigned int); | ||
81 | /** | ||
82 | * signal sent The file got beamed to the remote location | ||
83 | */ | ||
84 | void sent(bool); | ||
85 | void done(bool); | ||
86 | protected: | ||
87 | uint m_count; | ||
88 | QString m_file; | ||
89 | QString m_outp; | ||
90 | QString m_bdaddr; | ||
91 | bool m_receive : 1; | ||
92 | protected slots: | ||
93 | virtual void slotError(); | ||
94 | }; | ||
95 | }; | ||
96 | |||
97 | #endif | ||
98 | //eof | ||
99 | |||
diff --git a/core/obex/obexhandler.cpp b/core/obex/obexhandler.cpp index 28f9b5b..5d98ded 100644 --- a/core/obex/obexhandler.cpp +++ b/core/obex/obexhandler.cpp | |||
@@ -8,60 +8,72 @@ | |||
8 | 8 | ||
9 | using namespace OpieObex; | 9 | using namespace OpieObex; |
10 | 10 | ||
11 | /* TRANSLATOR OpieObex::ObexHandler */ | 11 | /* TRANSLATOR OpieObex::ObexHandler */ |
12 | 12 | ||
13 | ObexHandler::ObexHandler() { | 13 | ObexHandler::ObexHandler() { |
14 | m_wasRec = false; | 14 | m_wasRec[REC_IRDA] = false; |
15 | m_receiver[REC_IRDA] = 0l; | ||
16 | m_wasRec[REC_BLUETOOTH] = false; | ||
17 | m_receiver[REC_BLUETOOTH] = 0l; | ||
15 | m_sender = 0l; | 18 | m_sender = 0l; |
16 | m_receiver = 0l; | 19 | m_type = REC_IRDA; //FIXME: Just to init to something |
17 | QCopChannel* chan = new QCopChannel("QPE/Obex"); | 20 | QCopChannel* chan = new QCopChannel("QPE/Obex"); |
18 | connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ), | 21 | connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ), |
19 | this, SLOT(irdaMessage(const QCString&,const QByteArray&) ) ); | 22 | this, SLOT(irdaMessage(const QCString&,const QByteArray&) ) ); |
20 | } | 23 | } |
21 | ObexHandler::~ObexHandler() { | 24 | ObexHandler::~ObexHandler() { |
22 | delete m_sender; | 25 | delete m_sender; |
23 | delete m_receiver; | 26 | delete m_receiver[REC_IRDA]; |
27 | delete m_receiver[REC_BLUETOOTH]; | ||
24 | } | 28 | } |
25 | void ObexHandler::doSend(const QString& str, const QString& desc) { | 29 | void ObexHandler::doSend(const QString& str, const QString& desc) { |
26 | delete m_sender; | 30 | delete m_sender; |
27 | m_sender = new SendWidget; | 31 | m_sender = new SendWidget; |
28 | m_sender->raise(); | 32 | m_sender->raise(); |
29 | QPEApplication::showWidget( m_sender ); | 33 | QPEApplication::showWidget( m_sender ); |
30 | connect(m_sender, SIGNAL(done() ), | 34 | connect(m_sender, SIGNAL(done() ), |
31 | this, SLOT(slotSent() ) ); | 35 | this, SLOT(slotSent() ) ); |
32 | m_sender->send( str, desc ); | 36 | m_sender->send( str, desc ); |
33 | } | 37 | } |
34 | void ObexHandler::doReceive(bool b) { | 38 | void ObexHandler::doReceive(RecType type, bool b) { |
35 | if (m_receiver && b ) return; // we should enable receiver and it is on | 39 | if (m_receiver[type] && b ) return; // we should enable receiver and it is on |
36 | else if (!m_receiver && !b ) return; // we should disbale receiver and it is off | 40 | else if (!m_receiver[type] && !b ) return; // we should disbale receiver and it is off |
37 | else if (m_receiver && !b ) { | 41 | else if (m_receiver[type] && !b ) { |
38 | delete m_receiver; | 42 | delete m_receiver[type]; |
39 | m_receiver=0; | 43 | m_receiver[type] = 0; |
40 | }else if (!m_receiver && b ) { | 44 | }else if (!m_receiver[type] && b ) { |
41 | m_receiver= new Receiver; | 45 | m_receiver[type] = new Receiver(type); |
42 | } | 46 | } |
43 | } | 47 | } |
44 | void ObexHandler::slotSent() { | 48 | void ObexHandler::slotSent() { |
45 | QString file = m_sender->file(); | 49 | QString file = m_sender->file(); |
46 | delete m_sender; | 50 | delete m_sender; |
47 | m_sender = 0; | 51 | m_sender = 0; |
48 | QCopEnvelope e ("QPE/Obex", "done(QString)" ); | 52 | QCopEnvelope e ("QPE/Obex", "done(QString)" ); |
49 | e << file; | 53 | e << file; |
50 | doReceive(m_wasRec ); | 54 | doReceive(REC_IRDA, m_wasRec[REC_IRDA]); |
51 | m_wasRec = false; | 55 | doReceive(REC_BLUETOOTH, m_wasRec[REC_BLUETOOTH]); |
56 | m_wasRec[REC_IRDA] = false; | ||
57 | m_wasRec[REC_BLUETOOTH] = false; | ||
52 | } | 58 | } |
53 | void ObexHandler::irdaMessage( const QCString& msg, const QByteArray& data) { | 59 | void ObexHandler::irdaMessage( const QCString& msg, const QByteArray& data) { |
54 | QDataStream stream( data, IO_ReadOnly ); | 60 | QDataStream stream( data, IO_ReadOnly ); |
55 | if ( msg == "send(QString,QString,QString)" ) { | 61 | if ( msg == "send(QString,QString,QString)" ) { |
56 | QString name, desc; | 62 | QString name, desc; |
57 | stream >> desc; | 63 | stream >> desc; |
58 | stream >> name; | 64 | stream >> name; |
59 | m_wasRec = (m_receiver != 0 ); | 65 | m_wasRec[REC_IRDA] = (m_receiver[REC_IRDA] != 0 ); |
60 | doReceive( false ); | 66 | m_wasRec[REC_BLUETOOTH] = (m_receiver[REC_BLUETOOTH] != 0 ); |
67 | doReceive(REC_IRDA, false); | ||
68 | doReceive(REC_BLUETOOTH, false); | ||
61 | doSend(name, desc); | 69 | doSend(name, desc); |
62 | }else if (msg == "receive(int)") { | 70 | }else if (msg == "receive(int)") { |
63 | int rec; | 71 | int rec; |
64 | stream >> rec; | 72 | stream >> rec; |
65 | doReceive(rec); | 73 | doReceive(REC_IRDA, rec); |
74 | }else if (msg == "btreceive(int)") { | ||
75 | int rec; | ||
76 | stream >> rec; | ||
77 | doReceive(REC_BLUETOOTH, rec); | ||
66 | } | 78 | } |
67 | } | 79 | } |
diff --git a/core/obex/obexhandler.h b/core/obex/obexhandler.h index 230c4f0..de2232e 100644 --- a/core/obex/obexhandler.h +++ b/core/obex/obexhandler.h | |||
@@ -1,11 +1,12 @@ | |||
1 | #ifndef OPIE_OBEX_HANDLER_H | 1 | #ifndef OPIE_OBEX_HANDLER_H |
2 | #define OPIE_OBEX_HANDLER_H | 2 | #define OPIE_OBEX_HANDLER_H |
3 | 3 | ||
4 | #include <qobject.h> | 4 | #include <qobject.h> |
5 | #include <qstring.h> | 5 | #include <qstring.h> |
6 | #include "receiver.h" | ||
6 | 7 | ||
7 | namespace OpieObex { | 8 | namespace OpieObex { |
8 | /* | 9 | /* |
9 | * The handler is responsible for handling receiving | 10 | * The handler is responsible for handling receiving |
10 | * and sending | 11 | * and sending |
11 | * It will connect to the IrDa QCOP channel and then | 12 | * It will connect to the IrDa QCOP channel and then |
@@ -18,22 +19,22 @@ namespace OpieObex { | |||
18 | public: | 19 | public: |
19 | ObexHandler(); | 20 | ObexHandler(); |
20 | ~ObexHandler(); | 21 | ~ObexHandler(); |
21 | 22 | ||
22 | private slots: | 23 | private slots: |
23 | void doSend(const QString&,const QString& ); | 24 | void doSend(const QString&,const QString& ); |
24 | void doReceive(bool b); | 25 | void doReceive(RecType type, bool b); |
25 | void slotSent(); | 26 | void slotSent(); |
26 | 27 | ||
27 | private slots: // QCOP message | 28 | private slots: // QCOP message |
28 | void irdaMessage( const QCString&, const QByteArray& ); | 29 | void irdaMessage( const QCString&, const QByteArray& ); |
29 | 30 | ||
30 | private: | 31 | private: |
31 | SendWidget* m_sender; | 32 | SendWidget* m_sender; |
32 | Receiver* m_receiver; | 33 | Receiver* m_receiver[2]; //For IRDA and Bluetooth |
33 | bool m_wasRec : 1; | 34 | bool m_wasRec[2]; |
34 | 35 | RecType m_type; //receiver type (IRDA or Bluetooth) | |
35 | }; | 36 | }; |
36 | } | 37 | } |
37 | 38 | ||
38 | 39 | ||
39 | #endif | 40 | #endif |
diff --git a/core/obex/obexsend.cpp b/core/obex/obexsend.cpp index 8432d16..9a30a0a 100644 --- a/core/obex/obexsend.cpp +++ b/core/obex/obexsend.cpp | |||
@@ -145,13 +145,13 @@ void SendWidget::slotStartIrda() { | |||
145 | return; | 145 | return; |
146 | if ( m_irDaIt == m_irDa.end() || !receiverSelected(m_irDaIt.key())) { | 146 | if ( m_irDaIt == m_irDa.end() || !receiverSelected(m_irDaIt.key())) { |
147 | irdaStatus->setText(tr("complete.")); | 147 | irdaStatus->setText(tr("complete.")); |
148 | return; | 148 | return; |
149 | } | 149 | } |
150 | setReceiverStatus( m_irDaIt.key(), tr("Start sending") ); | 150 | setReceiverStatus( m_irDaIt.key(), tr("Start sending") ); |
151 | m_obex->send( m_file ); | 151 | m_obex->send( m_file, tr("noaddress") ); |
152 | } | 152 | } |
153 | 153 | ||
154 | void SendWidget::dispatchBt( const QCString& str, const QByteArray& ar ) { | 154 | void SendWidget::dispatchBt( const QCString& str, const QByteArray& ar ) { |
155 | if ( str == "devices(QStringMap)" ) { | 155 | if ( str == "devices(QStringMap)" ) { |
156 | QDataStream stream( ar, IO_ReadOnly ); | 156 | QDataStream stream( ar, IO_ReadOnly ); |
157 | QMap<QString, QString> btmap; | 157 | QMap<QString, QString> btmap; |
diff --git a/core/obex/obexserver.cpp b/core/obex/obexserver.cpp new file mode 100644 index 0000000..95196de --- a/dev/null +++ b/core/obex/obexserver.cpp | |||
@@ -0,0 +1,514 @@ | |||
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 OBEX server class implementation | ||
30 | * Based on OBEX server from GPE (thanks, guys) | ||
31 | */ | ||
32 | |||
33 | #include "obexserver.h" | ||
34 | #include <unistd.h> | ||
35 | #include <opie2/odebug.h> | ||
36 | #include <sys/types.h> | ||
37 | #include <sys/wait.h> | ||
38 | #include <errno.h> | ||
39 | #include <stdlib.h> | ||
40 | #include <stdio.h> | ||
41 | #include <fcntl.h> | ||
42 | #include <qapplication.h> | ||
43 | #include <opie2/oprocctrl.h> | ||
44 | #include <qstring.h> | ||
45 | #include <qfile.h> | ||
46 | |||
47 | using namespace Opie::Core; | ||
48 | using namespace Opie::Core::Internal; | ||
49 | using namespace OpieObex; | ||
50 | |||
51 | ObexServer::ObexServer() : | ||
52 | OProcess(tr("ObexServer"), 0, "ObexServer") | ||
53 | { | ||
54 | m_obex = NULL; | ||
55 | } | ||
56 | |||
57 | ObexServer::~ObexServer() | ||
58 | { | ||
59 | stop(); | ||
60 | } | ||
61 | |||
62 | /** | ||
63 | * Function handles the file received | ||
64 | * @param name the file name | ||
65 | * @param data the file data | ||
66 | * @param data_len the data length | ||
67 | * @return 0 on success -1 on error | ||
68 | */ | ||
69 | static int file_received(uint8_t* name, const uint8_t* data, size_t data_len) | ||
70 | { | ||
71 | QString path("/tmp/"); | ||
72 | path += (char*)name; | ||
73 | QFile out(path); | ||
74 | int err = 0; | ||
75 | |||
76 | if (!out.open(IO_Raw | IO_ReadWrite | IO_Truncate)) { | ||
77 | printf("File %s open error %d\n", (const char*)path, errno); | ||
78 | err = -1; | ||
79 | goto out; | ||
80 | } | ||
81 | if (out.writeBlock((const char*)data, data_len) < 0) { | ||
82 | printf("File %s write error %d\n", (const char*)path, errno); | ||
83 | err = -1; | ||
84 | goto out; | ||
85 | } | ||
86 | out: | ||
87 | out.close(); | ||
88 | if (err == 0) { | ||
89 | printf("Wrote %s (%d bytes)\n", (const char*)path, data_len); | ||
90 | fflush(stdout); | ||
91 | } | ||
92 | return err; | ||
93 | } | ||
94 | |||
95 | /** | ||
96 | * Function handles the situation when the PUT request has been done | ||
97 | * @param handle OBEX connection handle | ||
98 | * @param object OBEX object itself | ||
99 | */ | ||
100 | static int put_done(obex_t* handle, obex_object_t* object) | ||
101 | { | ||
102 | obex_headerdata_t hv; //Received file header | ||
103 | uint8_t hi; //Type of the request | ||
104 | uint32_t hlen; //File (file name) length | ||
105 | int err = 0; | ||
106 | |||
107 | const uint8_t *body = NULL; | ||
108 | int body_len = 0; | ||
109 | uint8_t* name = NULL; | ||
110 | |||
111 | while (OBEX_ObjectGetNextHeader (handle, object, &hi, &hv, &hlen)) { | ||
112 | switch(hi) { | ||
113 | case OBEX_HDR_BODY: | ||
114 | body = hv.bs; | ||
115 | body_len = hlen; | ||
116 | break; | ||
117 | |||
118 | case OBEX_HDR_NAME: | ||
119 | name = new uint8_t[(hlen / 2) + 1]; | ||
120 | OBEX_UnicodeToChar(name, hv.bs, hlen); | ||
121 | break; | ||
122 | |||
123 | default: | ||
124 | break; | ||
125 | } | ||
126 | } | ||
127 | |||
128 | if (body) | ||
129 | err = file_received(name, body, body_len); | ||
130 | |||
131 | if (name) | ||
132 | delete[] name; | ||
133 | return err; | ||
134 | } | ||
135 | |||
136 | /** | ||
137 | * Function handles OBEX request | ||
138 | * @param handle OBEX connection handle | ||
139 | * @param object OBEX object itself | ||
140 | * @param mode | ||
141 | * @param event event code | ||
142 | * @param cmd OBEX command itself | ||
143 | */ | ||
144 | static void handle_request (obex_t* handle, obex_object_t* object, | ||
145 | int event, int cmd) | ||
146 | { | ||
147 | (void)event; | ||
148 | switch(cmd){ | ||
149 | case OBEX_CMD_SETPATH: | ||
150 | OBEX_ObjectSetRsp (object, OBEX_RSP_CONTINUE, OBEX_RSP_SUCCESS); | ||
151 | break; | ||
152 | case OBEX_CMD_PUT: | ||
153 | if (put_done (handle, object) < 0) | ||
154 | OBEX_ObjectSetRsp (object, OBEX_RSP_INTERNAL_SERVER_ERROR, | ||
155 | OBEX_RSP_INTERNAL_SERVER_ERROR); | ||
156 | else | ||
157 | OBEX_ObjectSetRsp (object, OBEX_RSP_CONTINUE, OBEX_RSP_SUCCESS); | ||
158 | break; | ||
159 | case OBEX_CMD_CONNECT: | ||
160 | OBEX_ObjectSetRsp (object, OBEX_RSP_SUCCESS, OBEX_RSP_SUCCESS); | ||
161 | break; | ||
162 | case OBEX_CMD_DISCONNECT: | ||
163 | OBEX_ObjectSetRsp (object, OBEX_RSP_SUCCESS, OBEX_RSP_SUCCESS); | ||
164 | break; | ||
165 | default: | ||
166 | printf("Denied %02x request\n", cmd); | ||
167 | fflush(stdout); | ||
168 | OBEX_ObjectSetRsp (object, OBEX_RSP_NOT_IMPLEMENTED, | ||
169 | OBEX_RSP_NOT_IMPLEMENTED); | ||
170 | break; | ||
171 | } | ||
172 | } | ||
173 | |||
174 | |||
175 | /** | ||
176 | * Function handles OBEX event when a client is connected to the server | ||
177 | * @param handle OBEX connection handle | ||
178 | * @param object OBEX object itself | ||
179 | * @param mode | ||
180 | * @param event event code | ||
181 | * @param obex_cmd OBEX command itself | ||
182 | * @param obex_rsp OBEX responce | ||
183 | */ | ||
184 | static void obex_conn_event (obex_t *handle, obex_object_t *object, | ||
185 | int mode, int event, int obex_cmd, int obex_rsp) | ||
186 | { | ||
187 | (void)mode; | ||
188 | (void)obex_rsp; | ||
189 | |||
190 | switch(event) { | ||
191 | case OBEX_EV_REQHINT: | ||
192 | switch(obex_cmd) { | ||
193 | case OBEX_CMD_PUT: | ||
194 | case OBEX_CMD_CONNECT: | ||
195 | case OBEX_CMD_DISCONNECT: | ||
196 | OBEX_ObjectSetRsp (object, OBEX_RSP_CONTINUE, OBEX_RSP_SUCCESS); | ||
197 | break; | ||
198 | default: | ||
199 | OBEX_ObjectSetRsp (object, OBEX_RSP_NOT_IMPLEMENTED, | ||
200 | OBEX_RSP_NOT_IMPLEMENTED); | ||
201 | break; | ||
202 | } | ||
203 | break; | ||
204 | |||
205 | case OBEX_EV_REQ: | ||
206 | /* Comes when a server-request has been received. */ | ||
207 | handle_request (handle, object, event, obex_cmd); | ||
208 | break; | ||
209 | |||
210 | case OBEX_EV_LINKERR: | ||
211 | break; | ||
212 | } | ||
213 | } | ||
214 | |||
215 | /** | ||
216 | * Function handles OBEX event | ||
217 | * @param handle OBEX connection handle | ||
218 | * @param object OBEX object itself | ||
219 | * @param mode | ||
220 | * @param event event code | ||
221 | * @param obex_cmd OBEX command itself | ||
222 | * @param obex_rsp OBEX responce | ||
223 | */ | ||
224 | static void obex_event (obex_t* handle, obex_object_t* object, int mode, | ||
225 | int event, int obex_cmd, int obex_rsp) | ||
226 | { | ||
227 | |||
228 | obex_t *obex; //OBEX connection handle | ||
229 | |||
230 | switch (event) { | ||
231 | case OBEX_EV_ACCEPTHINT: | ||
232 | obex = OBEX_ServerAccept (handle, obex_conn_event, NULL); | ||
233 | break; | ||
234 | |||
235 | default: | ||
236 | obex_conn_event(handle, object, mode, event, obex_cmd, obex_rsp); | ||
237 | } | ||
238 | } | ||
239 | |||
240 | /** | ||
241 | * Function registers OBEX push service on a specified channel | ||
242 | * Based on The same function from GPE. | ||
243 | * @param session SDP session | ||
244 | * @param chan channel to listen | ||
245 | * @name name to show | ||
246 | */ | ||
247 | sdp_session_t* ObexServer::addOpushSvc(uint8_t chan, const char* name) | ||
248 | { | ||
249 | sdp_list_t *svclass_id, *pfseq, *apseq, *root; | ||
250 | uuid_t root_uuid, opush_uuid, l2cap_uuid, rfcomm_uuid, obex_uuid; | ||
251 | sdp_profile_desc_t profile[1]; | ||
252 | sdp_list_t *aproto, *proto[3]; | ||
253 | sdp_record_t record; | ||
254 | sdp_data_t *channel; | ||
255 | uint8_t formats[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 }; | ||
256 | //uint8_t formats[] = { 0xff }; | ||
257 | void *dtds[sizeof(formats)], *values[sizeof(formats)]; | ||
258 | unsigned int i; | ||
259 | uint8_t dtd = SDP_UINT8; | ||
260 | sdp_data_t *sflist; | ||
261 | int err = 0; | ||
262 | sdp_session_t* lsession = 0; | ||
263 | |||
264 | memset((void *)&record, 0, sizeof(sdp_record_t)); | ||
265 | record.handle = 0xffffffff; | ||
266 | sdp_uuid16_create(&root_uuid, PUBLIC_BROWSE_GROUP); | ||
267 | root = sdp_list_append(0, &root_uuid); | ||
268 | sdp_set_browse_groups(&record, root); | ||
269 | |||
270 | sdp_uuid16_create(&opush_uuid, OBEX_OBJPUSH_SVCLASS_ID); | ||
271 | svclass_id = sdp_list_append(0, &opush_uuid); | ||
272 | sdp_set_service_classes(&record, svclass_id); | ||
273 | |||
274 | sdp_uuid16_create(&profile[0].uuid, OBEX_OBJPUSH_PROFILE_ID); | ||
275 | profile[0].version = 0x0100; | ||
276 | pfseq = sdp_list_append(0, profile); | ||
277 | sdp_set_profile_descs(&record, pfseq); | ||
278 | |||
279 | sdp_uuid16_create(&l2cap_uuid, L2CAP_UUID); | ||
280 | proto[0] = sdp_list_append(0, &l2cap_uuid); | ||
281 | apseq = sdp_list_append(0, proto[0]); | ||
282 | |||
283 | sdp_uuid16_create(&rfcomm_uuid, RFCOMM_UUID); | ||
284 | proto[1] = sdp_list_append(0, &rfcomm_uuid); | ||
285 | channel = sdp_data_alloc(SDP_UINT8, &chan); | ||
286 | proto[1] = sdp_list_append(proto[1], channel); | ||
287 | apseq = sdp_list_append(apseq, proto[1]); | ||
288 | |||
289 | sdp_uuid16_create(&obex_uuid, OBEX_UUID); | ||
290 | proto[2] = sdp_list_append(0, &obex_uuid); | ||
291 | apseq = sdp_list_append(apseq, proto[2]); | ||
292 | |||
293 | aproto = sdp_list_append(0, apseq); | ||
294 | sdp_set_access_protos(&record, aproto); | ||
295 | |||
296 | for (i = 0; i < sizeof(formats); i++) | ||
297 | { | ||
298 | dtds[i] = &dtd; | ||
299 | values[i] = &formats[i]; | ||
300 | } | ||
301 | sflist = sdp_seq_alloc(dtds, values, sizeof(formats)); | ||
302 | sdp_attr_add(&record, SDP_ATTR_SUPPORTED_FORMATS_LIST, sflist); | ||
303 | |||
304 | sdp_set_info_attr(&record, name, 0, 0); | ||
305 | |||
306 | // connect to the local SDP server, register the service record, and | ||
307 | // disconnect | ||
308 | lsession = sdp_connect(BDADDR_ANY, BDADDR_LOCAL, SDP_RETRY_IF_BUSY); | ||
309 | if (lsession == NULL) | ||
310 | goto errout; | ||
311 | err = sdp_record_register(lsession, &record, 0); | ||
312 | if (err) { | ||
313 | sdp_close(lsession); | ||
314 | lsession = NULL; | ||
315 | } | ||
316 | errout: | ||
317 | sdp_data_free(channel); | ||
318 | sdp_list_free(proto[0], 0); | ||
319 | sdp_list_free(proto[1], 0); | ||
320 | sdp_list_free(proto[2], 0); | ||
321 | sdp_list_free(apseq, 0); | ||
322 | sdp_list_free(aproto, 0); | ||
323 | |||
324 | return lsession; | ||
325 | } | ||
326 | |||
327 | int ObexServer::initObex(void) | ||
328 | { | ||
329 | int channel = 10; //Channel on which we do listen | ||
330 | if (m_obex) | ||
331 | return 0; | ||
332 | m_obex = ::OBEX_Init(OBEX_TRANS_BLUETOOTH, obex_event, 0); | ||
333 | if (!m_obex) { | ||
334 | printf("OBEX initialization error %d\n", errno); | ||
335 | return -1; | ||
336 | } | ||
337 | ::BtOBEX_ServerRegister(m_obex, NULL, channel); | ||
338 | m_session = addOpushSvc(channel, "OBEX push service"); | ||
339 | if (!m_session) { | ||
340 | printf("OBEX registration error %d\n", errno); | ||
341 | ::OBEX_Cleanup(m_obex); | ||
342 | m_obex = NULL; | ||
343 | return -1; | ||
344 | } | ||
345 | return 0; | ||
346 | } | ||
347 | |||
348 | bool ObexServer::start(RunMode runmode, Communication comm) | ||
349 | { | ||
350 | if ( runs ) | ||
351 | { | ||
352 | return false; // cannot start a process that is already running | ||
353 | // or if no executable has been assigned | ||
354 | } | ||
355 | run_mode = runmode; | ||
356 | status = 0; | ||
357 | |||
358 | if ( !setupCommunication( comm ) ) | ||
359 | qWarning( "Could not setup Communication!" ); | ||
360 | |||
361 | // We do this in the parent because if we do it in the child process | ||
362 | // gdb gets confused when the application runs from gdb. | ||
363 | uid_t uid = getuid(); | ||
364 | gid_t gid = getgid(); | ||
365 | #ifdef HAVE_INITGROUPS | ||
366 | |||
367 | struct passwd *pw = getpwuid( uid ); | ||
368 | #endif | ||
369 | |||
370 | int fd[ 2 ]; | ||
371 | if ( 0 > pipe( fd ) ) | ||
372 | { | ||
373 | fd[ 0 ] = fd[ 1 ] = 0; // Pipe failed.. continue | ||
374 | } | ||
375 | |||
376 | runs = true; | ||
377 | |||
378 | QApplication::flushX(); | ||
379 | |||
380 | // WABA: Note that we use fork() and not vfork() because | ||
381 | // vfork() has unclear semantics and is not standardized. | ||
382 | pid_ = fork(); | ||
383 | |||
384 | if ( 0 == pid_ ) | ||
385 | { | ||
386 | if ( fd[ 0 ] ) | ||
387 | close( fd[ 0 ] ); | ||
388 | if ( !runPrivileged() ) | ||
389 | { | ||
390 | setgid( gid ); | ||
391 | #if defined( HAVE_INITGROUPS) | ||
392 | |||
393 | if ( pw ) | ||
394 | initgroups( pw->pw_name, pw->pw_gid ); | ||
395 | #endif | ||
396 | |||
397 | setuid( uid ); | ||
398 | } | ||
399 | // The child process | ||
400 | if ( !commSetupDoneC() ) | ||
401 | qWarning( "Could not finish comm setup in child!" ); | ||
402 | |||
403 | setupEnvironment(); | ||
404 | |||
405 | // Matthias | ||
406 | if ( run_mode == DontCare ) | ||
407 | setpgid( 0, 0 ); | ||
408 | // restore default SIGPIPE handler (Harri) | ||
409 | struct sigaction act; | ||
410 | sigemptyset( &( act.sa_mask ) ); | ||
411 | sigaddset( &( act.sa_mask ), SIGPIPE ); | ||
412 | act.sa_handler = SIG_DFL; | ||
413 | act.sa_flags = 0; | ||
414 | sigaction( SIGPIPE, &act, 0L ); | ||
415 | |||
416 | // We set the close on exec flag. | ||
417 | // Closing of fd[1] indicates that the execvp succeeded! | ||
418 | if ( fd[ 1 ] ) | ||
419 | fcntl( fd[ 1 ], F_SETFD, FD_CLOEXEC ); | ||
420 | |||
421 | if (initObex() == 0) { | ||
422 | do { | ||
423 | int result; //Connection result | ||
424 | if ( fd[ 1 ] ) { | ||
425 | ::close(fd[1]); | ||
426 | fd[1] = 0; | ||
427 | } | ||
428 | if ((result = OBEX_HandleInput(m_obex, 60)) < 0) { | ||
429 | if (errno != ECONNRESET) { | ||
430 | printf("OBEX_HandleInput error %d\n", errno); | ||
431 | fflush(stdout); | ||
432 | _exit(-1); | ||
433 | } | ||
434 | else | ||
435 | _exit(0); | ||
436 | } | ||
437 | } while(1); | ||
438 | } | ||
439 | char resultByte = 1; | ||
440 | if ( fd[ 1 ] ) | ||
441 | write( fd[ 1 ], &resultByte, 1 ); | ||
442 | _exit( -1 ); | ||
443 | } | ||
444 | else if ( -1 == pid_ ) | ||
445 | { | ||
446 | // forking failed | ||
447 | |||
448 | runs = false; | ||
449 | return false; | ||
450 | } | ||
451 | else | ||
452 | { | ||
453 | if ( fd[ 1 ] ) | ||
454 | close( fd[ 1 ] ); | ||
455 | // the parent continues here | ||
456 | |||
457 | // Discard any data for stdin that might still be there | ||
458 | input_data = 0; | ||
459 | |||
460 | // Check whether client could be started. | ||
461 | if ( fd[ 0 ] ) | ||
462 | for ( ;; ) | ||
463 | { | ||
464 | char resultByte; | ||
465 | int n = ::read( fd[ 0 ], &resultByte, 1 ); | ||
466 | if ( n == 1 ) | ||
467 | { | ||
468 | // Error | ||
469 | runs = false; | ||
470 | close( fd[ 0 ] ); | ||
471 | pid_ = 0; | ||
472 | return false; | ||
473 | } | ||
474 | if ( n == -1 ) | ||
475 | { | ||
476 | if ( ( errno == ECHILD ) || ( errno == EINTR ) ) | ||
477 | continue; // Ignore | ||
478 | } | ||
479 | break; // success | ||
480 | } | ||
481 | if ( fd[ 0 ] ) | ||
482 | close( fd[ 0 ] ); | ||
483 | |||
484 | if ( !commSetupDoneP() ) // finish communication socket setup for the parent | ||
485 | qWarning( "Could not finish comm setup in parent!" ); | ||
486 | |||
487 | if ( run_mode == Block ) | ||
488 | { | ||
489 | commClose(); | ||
490 | |||
491 | // The SIGCHLD handler of the process controller will catch | ||
492 | // the exit and set the status | ||
493 | while ( runs ) | ||
494 | { | ||
495 | OProcessController::theOProcessController-> | ||
496 | slotDoHousekeeping( 0 ); | ||
497 | } | ||
498 | runs = FALSE; | ||
499 | emit processExited( this ); | ||
500 | } | ||
501 | } | ||
502 | return true; | ||
503 | } | ||
504 | |||
505 | /* | ||
506 | * Stop forwarding process | ||
507 | */ | ||
508 | int ObexServer::stop() | ||
509 | { | ||
510 | kill(SIGTERM); | ||
511 | return 0; | ||
512 | } | ||
513 | |||
514 | //eof | ||
diff --git a/core/obex/obexserver.h b/core/obex/obexserver.h new file mode 100644 index 0000000..8567105 --- a/dev/null +++ b/core/obex/obexserver.h | |||
@@ -0,0 +1,83 @@ | |||
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 OBEX server class declaration | ||
30 | * Based on OBEX server from GPE (thanks, guys) | ||
31 | */ | ||
32 | #ifndef ObexServer_H | ||
33 | #define ObexServer_H | ||
34 | |||
35 | #include <qobject.h> | ||
36 | #include <opie2/oprocess.h> | ||
37 | |||
38 | #include <bluetooth/sdp.h> | ||
39 | #include <bluetooth/sdp_lib.h> | ||
40 | |||
41 | #include <openobex/obex.h> | ||
42 | |||
43 | namespace Opie { | ||
44 | namespace Core { | ||
45 | class OProcess; | ||
46 | namespace Internal { | ||
47 | class OProcessController; | ||
48 | } | ||
49 | } | ||
50 | }; | ||
51 | |||
52 | namespace Opie {namespace Core {class OProcess;}} | ||
53 | namespace OpieObex { | ||
54 | class ObexServer : public Opie::Core::OProcess { | ||
55 | Q_OBJECT | ||
56 | public: | ||
57 | /** | ||
58 | * ObexServer constructor | ||
59 | */ | ||
60 | ObexServer(); | ||
61 | /** | ||
62 | * | ||
63 | */ | ||
64 | ~ObexServer(); | ||
65 | //Function starts the server process | ||
66 | virtual bool start( RunMode runmode = NotifyOnExit, | ||
67 | Communication comm = NoCommunication ); | ||
68 | //Stop the server process | ||
69 | int stop(); | ||
70 | protected: //variables | ||
71 | obex_t* m_obex; //Obex server handler | ||
72 | sdp_session_t* m_session; //SDP session handler; | ||
73 | protected: //functions | ||
74 | //Funtion initializes obex server return 0 on success and -1 on error | ||
75 | int initObex(void); | ||
76 | //Function registers an OBEX push service | ||
77 | sdp_session_t* addOpushSvc(uint8_t chan, const char* name); | ||
78 | signals: | ||
79 | protected slots: | ||
80 | }; | ||
81 | }; | ||
82 | |||
83 | #endif | ||
diff --git a/core/obex/receiver.cpp b/core/obex/receiver.cpp index 7d9a42a..e153152 100644 --- a/core/obex/receiver.cpp +++ b/core/obex/receiver.cpp | |||
@@ -1,7 +1,9 @@ | |||
1 | #include "obex.h" | 1 | #include "obex.h" |
2 | #include "btobex.h" | ||
3 | #include "obexbase.h" | ||
2 | #include "receiver.h" | 4 | #include "receiver.h" |
3 | using namespace OpieObex; | 5 | using namespace OpieObex; |
4 | 6 | ||
5 | /* OPIE */ | 7 | /* OPIE */ |
6 | #include <opie2/odebug.h> | 8 | #include <opie2/odebug.h> |
7 | #include <qpe/applnk.h> | 9 | #include <qpe/applnk.h> |
@@ -23,14 +25,17 @@ using namespace Opie::Core; | |||
23 | #include <stdlib.h> // int system | 25 | #include <stdlib.h> // int system |
24 | #include <unistd.h> | 26 | #include <unistd.h> |
25 | #include <fcntl.h> | 27 | #include <fcntl.h> |
26 | 28 | ||
27 | /* TRANSLATOR OpieObex::Receiver */ | 29 | /* TRANSLATOR OpieObex::Receiver */ |
28 | 30 | ||
29 | Receiver::Receiver() { | 31 | Receiver::Receiver(RecType type) { |
30 | m_obex = new Obex(this, "Receiver"); | 32 | if (type == REC_IRDA) |
33 | m_obex = new Obex(this, "Receiver"); | ||
34 | else | ||
35 | m_obex = new BtObex(this, "Receiver"); | ||
31 | connect(m_obex, SIGNAL(receivedFile(const QString&) ), | 36 | connect(m_obex, SIGNAL(receivedFile(const QString&) ), |
32 | this, SLOT(slotReceived(const QString&) ) ); | 37 | this, SLOT(slotReceived(const QString&) ) ); |
33 | m_obex->receive(); | 38 | m_obex->receive(); |
34 | } | 39 | } |
35 | Receiver::~Receiver() { | 40 | Receiver::~Receiver() { |
36 | m_obex->setReceiveEnabled( false ); | 41 | m_obex->setReceiveEnabled( false ); |
diff --git a/core/obex/receiver.h b/core/obex/receiver.h index e1d54df..a10ea13 100644 --- a/core/obex/receiver.h +++ b/core/obex/receiver.h | |||
@@ -2,22 +2,28 @@ | |||
2 | #define OPIE_OBEX_RECEIVER_H | 2 | #define OPIE_OBEX_RECEIVER_H |
3 | 3 | ||
4 | #include <qobject.h> | 4 | #include <qobject.h> |
5 | #include <qvbox.h> | 5 | #include <qvbox.h> |
6 | #include <qstring.h> | 6 | #include <qstring.h> |
7 | 7 | ||
8 | //Receiver type | ||
9 | typedef enum _RecType { | ||
10 | REC_IRDA = 0, | ||
11 | REC_BLUETOOTH = 1 | ||
12 | } RecType; | ||
13 | |||
8 | class QLabel; | 14 | class QLabel; |
9 | class QTextView; | 15 | class QTextView; |
10 | namespace OpieObex { | 16 | namespace OpieObex { |
11 | class Obex; | 17 | class ObexBase; |
12 | class OtherHandler; | 18 | class OtherHandler; |
13 | class Receiver : public QObject { | 19 | class Receiver : public QObject { |
14 | Q_OBJECT | 20 | Q_OBJECT |
15 | public: | 21 | public: |
16 | enum { Datebook , AddressBook, Other }; | 22 | enum { Datebook , AddressBook, Other }; |
17 | Receiver(); | 23 | Receiver(RecType type); |
18 | ~Receiver(); | 24 | ~Receiver(); |
19 | 25 | ||
20 | private: | 26 | private: |
21 | void handleAddr(const QString& ); | 27 | void handleAddr(const QString& ); |
22 | void handleDateTodo(const QString& ); | 28 | void handleDateTodo(const QString& ); |
23 | void handleOther(const QString& ); | 29 | void handleOther(const QString& ); |
@@ -29,13 +35,13 @@ namespace OpieObex { | |||
29 | void tidyUp( QString& file, const QString& ending ); | 35 | void tidyUp( QString& file, const QString& ending ); |
30 | 36 | ||
31 | private slots: | 37 | private slots: |
32 | void slotReceived( const QString& ); | 38 | void slotReceived( const QString& ); |
33 | 39 | ||
34 | private: | 40 | private: |
35 | Obex* m_obex; | 41 | ObexBase* m_obex; //IR obex |
36 | }; | 42 | }; |
37 | 43 | ||
38 | class OtherHandler : public QVBox { | 44 | class OtherHandler : public QVBox { |
39 | Q_OBJECT | 45 | Q_OBJECT |
40 | public: | 46 | public: |
41 | OtherHandler(); | 47 | OtherHandler(); |