summaryrefslogtreecommitdiff
path: root/core/obex
Unidiff
Diffstat (limited to 'core/obex') (more/less context) (ignore whitespace changes)
-rw-r--r--core/obex/btobex.cpp2
-rw-r--r--core/obex/obex.cpp3
-rw-r--r--core/obex/obex.h3
-rw-r--r--core/obex/obexserver.cpp24
-rw-r--r--core/obex/obexserver.h4
5 files changed, 21 insertions, 15 deletions
diff --git a/core/obex/btobex.cpp b/core/obex/btobex.cpp
index 212a084..4e078b0 100644
--- a/core/obex/btobex.cpp
+++ b/core/obex/btobex.cpp
@@ -44,49 +44,49 @@
44#include <qmessagebox.h> 44#include <qmessagebox.h>
45 45
46using namespace OpieObex; 46using namespace OpieObex;
47 47
48using namespace Opie::Core; 48using namespace Opie::Core;
49/* TRANSLATOR OpieObex::Obex */ 49/* TRANSLATOR OpieObex::Obex */
50using namespace OpieTooth; 50using namespace OpieTooth;
51 51
52BtObex::BtObex( QObject *parent, const char* name ) 52BtObex::BtObex( QObject *parent, const char* name )
53 : ObexBase(parent, name ) 53 : ObexBase(parent, name )
54{ 54{
55 m_rec = 0; 55 m_rec = 0;
56 m_send=0; 56 m_send=0;
57 btManager = NULL; 57 btManager = NULL;
58}; 58};
59 59
60BtObex::~BtObex() { 60BtObex::~BtObex() {
61 delete btManager; 61 delete btManager;
62 delete m_rec; 62 delete m_rec;
63 delete m_send; 63 delete m_send;
64} 64}
65 65
66void BtObex::receive() { 66void BtObex::receive() {
67 ObexBase::receive(); 67 ObexBase::receive();
68 m_rec = new ObexServer(); 68 m_rec = new ObexServer(OBEX_TRANS_BLUETOOTH);
69 69
70 odebug << "BT OBEX do receive" << oendl; 70 odebug << "BT OBEX do receive" << oendl;
71 // 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.
72 // connect to the necessary slots 72 // connect to the necessary slots
73 connect(m_rec, SIGNAL(processExited(Opie::Core::OProcess*) ), 73 connect(m_rec, SIGNAL(processExited(Opie::Core::OProcess*) ),
74 this, SLOT(slotExited(Opie::Core::OProcess*) ) ); 74 this, SLOT(slotExited(Opie::Core::OProcess*) ) );
75 75
76 connect(m_rec, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ), 76 connect(m_rec, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ),
77 this, SLOT(slotStdOut(Opie::Core::OProcess*, char*, int) ) ); 77 this, SLOT(slotStdOut(Opie::Core::OProcess*, char*, int) ) );
78 78
79 if(!m_rec->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { 79 if(!m_rec->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) {
80 emit done( false ); 80 emit done( false );
81 delete m_rec; 81 delete m_rec;
82 m_rec = 0; 82 m_rec = 0;
83 } 83 }
84} 84}
85 85
86void BtObex::send( const QString& fileName, const QString& bdaddr) { 86void BtObex::send( const QString& fileName, const QString& bdaddr) {
87 ObexBase::send(fileName, bdaddr); 87 ObexBase::send(fileName, bdaddr);
88 // if currently receiving stop it send receive 88 // if currently receiving stop it send receive
89 if (m_send != 0) { 89 if (m_send != 0) {
90 if (m_send->isSending()) 90 if (m_send->isSending())
91 return; 91 return;
92 else { 92 else {
diff --git a/core/obex/obex.cpp b/core/obex/obex.cpp
index 95c561a..e4a3c31 100644
--- a/core/obex/obex.cpp
+++ b/core/obex/obex.cpp
@@ -36,50 +36,49 @@
36#include <opie2/odebug.h> 36#include <opie2/odebug.h>
37 37
38/* QT */ 38/* QT */
39#include <qfileinfo.h> 39#include <qfileinfo.h>
40 40
41 41
42 42
43using namespace OpieObex; 43using namespace OpieObex;
44 44
45using namespace Opie::Core; 45using namespace Opie::Core;
46/* TRANSLATOR OpieObex::Obex */ 46/* TRANSLATOR OpieObex::Obex */
47 47
48Obex::Obex( QObject *parent, const char* name ) 48Obex::Obex( QObject *parent, const char* name )
49 : ObexBase(parent, name ) 49 : ObexBase(parent, name )
50{ 50{
51 m_rec = 0; 51 m_rec = 0;
52 m_send=0; 52 m_send=0;
53}; 53};
54Obex::~Obex() { 54Obex::~Obex() {
55 delete m_rec; 55 delete m_rec;
56 delete m_send; 56 delete m_send;
57} 57}
58void Obex::receive() { 58void Obex::receive() {
59 ObexBase::receive(); 59 ObexBase::receive();
60 m_rec = new OProcess(); 60 m_rec = new ObexServer(OBEX_TRANS_IRDA);
61 *m_rec << "irobex_palm3";
62 // connect to the necessary slots 61 // connect to the necessary slots
63 connect(m_rec, SIGNAL(processExited(Opie::Core::OProcess*) ), 62 connect(m_rec, SIGNAL(processExited(Opie::Core::OProcess*) ),
64 this, SLOT(slotExited(Opie::Core::OProcess*) ) ); 63 this, SLOT(slotExited(Opie::Core::OProcess*) ) );
65 64
66 connect(m_rec, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ), 65 connect(m_rec, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ),
67 this, SLOT(slotStdOut(Opie::Core::OProcess*, char*, int) ) ); 66 this, SLOT(slotStdOut(Opie::Core::OProcess*, char*, int) ) );
68 67
69 if(!m_rec->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { 68 if(!m_rec->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) {
70 emit done( false ); 69 emit done( false );
71 delete m_rec; 70 delete m_rec;
72 m_rec = 0; 71 m_rec = 0;
73 } 72 }
74} 73}
75 74
76// if currently receiving stop it send receive 75// if currently receiving stop it send receive
77void Obex::send(const QString& fileName, const QString& addr) { 76void Obex::send(const QString& fileName, const QString& addr) {
78 ObexBase::send(fileName, addr); 77 ObexBase::send(fileName, addr);
79 if (m_rec != 0 ) { 78 if (m_rec != 0 ) {
80 if (m_rec->isRunning() ) { 79 if (m_rec->isRunning() ) {
81 emit error(-1 ); 80 emit error(-1 );
82 delete m_rec; 81 delete m_rec;
83 m_rec = 0; 82 m_rec = 0;
84 83
85 }else{ 84 }else{
diff --git a/core/obex/obex.h b/core/obex/obex.h
index 36ff29a..b948ce4 100644
--- a/core/obex/obex.h
+++ b/core/obex/obex.h
@@ -13,48 +13,49 @@
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of 14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=| MERCHANTABILITY or FITNESS FOR A 15    =_        +     =;=| MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>: PARTICULAR PURPOSE. See the GNU 16  _.=:.       :    :=>: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more 17..}^=.=       =       ; Library General Public License for more
18++=   -.     .     .: details. 18++=   -.     .     .: details.
19 :     =  ...= . :.=- 19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU 20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with 21  -_. . .   )=.  = Library General Public License along with
22   --        :-= this library; see the file COPYING.LIB. 22   --        :-= this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation, 23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330, 24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28/* 28/*
29 * The Infrared OBEX handling class declaration 29 * The Infrared OBEX handling class declaration
30 */ 30 */
31 31
32#ifndef OpieObex_H 32#ifndef OpieObex_H
33#define OpieObex_H 33#define OpieObex_H
34 34
35#include "obexbase.h" 35#include "obexbase.h"
36#include <qobject.h> 36#include <qobject.h>
37#include "obexserver.h"
37 38
38namespace Opie {namespace Core {class OProcess;}} 39namespace Opie {namespace Core {class OProcess;}}
39class QCopChannel; 40class QCopChannel;
40namespace OpieObex { 41namespace OpieObex {
41 class Obex : public ObexBase { 42 class Obex : public ObexBase {
42 Q_OBJECT 43 Q_OBJECT
43 public: 44 public:
44 /** 45 /**
45 * Obex c'tor look 46 * Obex c'tor look
46 */ 47 */
47 Obex( QObject *parent, const char* name); 48 Obex( QObject *parent, const char* name);
48 /** 49 /**
49 * d'tor 50 * d'tor
50 */ 51 */
51 ~Obex(); 52 ~Obex();
52 53
53 /** 54 /**
54 * Starting listening to irda after enabled by the applet 55 * Starting listening to irda after enabled by the applet
55 * a signal gets emitted when received a file 56 * a signal gets emitted when received a file
56 */ 57 */
57 virtual void receive(); 58 virtual void receive();
58 virtual void send(const QString& filename, const QString& addr); 59 virtual void send(const QString& filename, const QString& addr);
59 virtual void setReceiveEnabled( bool = false ); 60 virtual void setReceiveEnabled( bool = false );
60 signals: 61 signals:
@@ -63,49 +64,49 @@ namespace OpieObex {
63 * a signal 64 * a signal
64 * @param path The path to the received file 65 * @param path The path to the received file
65 */ 66 */
66 void receivedFile( const QString& path); 67 void receivedFile( const QString& path);
67 /** 68 /**
68 * error signal if the program couldn't be started or the 69 * error signal if the program couldn't be started or the
69 * the connection timed out 70 * the connection timed out
70 */ 71 */
71 void error( int ); 72 void error( int );
72 /** 73 /**
73 * The current try to receive data 74 * The current try to receive data
74 */ 75 */
75 void currentTry(unsigned int); 76 void currentTry(unsigned int);
76 /** 77 /**
77 * signal sent The file got beamed to the remote location 78 * signal sent The file got beamed to the remote location
78 */ 79 */
79 void sent(bool); 80 void sent(bool);
80 void done(bool); 81 void done(bool);
81 82
82 private: 83 private:
83 uint m_count; 84 uint m_count;
84 QString m_file; 85 QString m_file;
85 QString m_outp; 86 QString m_outp;
86 Opie::Core::OProcess *m_send; 87 Opie::Core::OProcess *m_send;
87 Opie::Core::OProcess *m_rec; 88 ObexServer* m_rec; //The OBEX server
88 bool m_receive : 1; 89 bool m_receive : 1;
89 void shutDownReceive(); 90 void shutDownReceive();
90 91
91private slots: 92private slots:
92 93
93 /** 94 /**
94 * send over palm obex 95 * send over palm obex
95 */ 96 */
96 97
97 //void send(const QString&); 98 //void send(const QString&);
98 99
99 // the process exited 100 // the process exited
100 void slotExited(Opie::Core::OProcess* proc) ; 101 void slotExited(Opie::Core::OProcess* proc) ;
101 void slotStdOut(Opie::Core::OProcess*, char*, int); 102 void slotStdOut(Opie::Core::OProcess*, char*, int);
102 virtual void slotError(); 103 virtual void slotError();
103 104
104 private: 105 private:
105 void sendNow(); 106 void sendNow();
106 QString parseOut(); 107 QString parseOut();
107 void received(); 108 void received();
108 void sendEnd(); 109 void sendEnd();
109 110
110 }; 111 };
111}; 112};
diff --git a/core/obex/obexserver.cpp b/core/obex/obexserver.cpp
index 95196de..25d8224 100644
--- a/core/obex/obexserver.cpp
+++ b/core/obex/obexserver.cpp
@@ -27,51 +27,52 @@
27*/ 27*/
28/* 28/*
29 * The OBEX server class implementation 29 * The OBEX server class implementation
30 * Based on OBEX server from GPE (thanks, guys) 30 * Based on OBEX server from GPE (thanks, guys)
31 */ 31 */
32 32
33#include "obexserver.h" 33#include "obexserver.h"
34#include <unistd.h> 34#include <unistd.h>
35#include <opie2/odebug.h> 35#include <opie2/odebug.h>
36#include <sys/types.h> 36#include <sys/types.h>
37#include <sys/wait.h> 37#include <sys/wait.h>
38#include <errno.h> 38#include <errno.h>
39#include <stdlib.h> 39#include <stdlib.h>
40#include <stdio.h> 40#include <stdio.h>
41#include <fcntl.h> 41#include <fcntl.h>
42#include <qapplication.h> 42#include <qapplication.h>
43#include <opie2/oprocctrl.h> 43#include <opie2/oprocctrl.h>
44#include <qstring.h> 44#include <qstring.h>
45#include <qfile.h> 45#include <qfile.h>
46 46
47using namespace Opie::Core; 47using namespace Opie::Core;
48using namespace Opie::Core::Internal; 48using namespace Opie::Core::Internal;
49using namespace OpieObex; 49using namespace OpieObex;
50 50
51ObexServer::ObexServer() : 51ObexServer::ObexServer(int trans) :
52 OProcess(tr("ObexServer"), 0, "ObexServer") 52 OProcess(tr("ObexServer"), 0, "ObexServer")
53{ 53{
54 transport = trans;
54 m_obex = NULL; 55 m_obex = NULL;
55} 56}
56 57
57ObexServer::~ObexServer() 58ObexServer::~ObexServer()
58{ 59{
59 stop(); 60 stop();
60} 61}
61 62
62/** 63/**
63 * Function handles the file received 64 * Function handles the file received
64 * @param name the file name 65 * @param name the file name
65 * @param data the file data 66 * @param data the file data
66 * @param data_len the data length 67 * @param data_len the data length
67 * @return 0 on success -1 on error 68 * @return 0 on success -1 on error
68 */ 69 */
69static int file_received(uint8_t* name, const uint8_t* data, size_t data_len) 70static int file_received(uint8_t* name, const uint8_t* data, size_t data_len)
70{ 71{
71 QString path("/tmp/"); 72 QString path("/tmp/");
72 path += (char*)name; 73 path += (char*)name;
73 QFile out(path); 74 QFile out(path);
74 int err = 0; 75 int err = 0;
75 76
76 if (!out.open(IO_Raw | IO_ReadWrite | IO_Truncate)) { 77 if (!out.open(IO_Raw | IO_ReadWrite | IO_Truncate)) {
77 printf("File %s open error %d\n", (const char*)path, errno); 78 printf("File %s open error %d\n", (const char*)path, errno);
@@ -308,61 +309,64 @@ sdp_session_t* ObexServer::addOpushSvc(uint8_t chan, const char* name)
308 lsession = sdp_connect(BDADDR_ANY, BDADDR_LOCAL, SDP_RETRY_IF_BUSY); 309 lsession = sdp_connect(BDADDR_ANY, BDADDR_LOCAL, SDP_RETRY_IF_BUSY);
309 if (lsession == NULL) 310 if (lsession == NULL)
310 goto errout; 311 goto errout;
311 err = sdp_record_register(lsession, &record, 0); 312 err = sdp_record_register(lsession, &record, 0);
312 if (err) { 313 if (err) {
313 sdp_close(lsession); 314 sdp_close(lsession);
314 lsession = NULL; 315 lsession = NULL;
315 } 316 }
316errout: 317errout:
317 sdp_data_free(channel); 318 sdp_data_free(channel);
318 sdp_list_free(proto[0], 0); 319 sdp_list_free(proto[0], 0);
319 sdp_list_free(proto[1], 0); 320 sdp_list_free(proto[1], 0);
320 sdp_list_free(proto[2], 0); 321 sdp_list_free(proto[2], 0);
321 sdp_list_free(apseq, 0); 322 sdp_list_free(apseq, 0);
322 sdp_list_free(aproto, 0); 323 sdp_list_free(aproto, 0);
323 324
324 return lsession; 325 return lsession;
325} 326}
326 327
327int ObexServer::initObex(void) 328int ObexServer::initObex(void)
328{ 329{
329 int channel = 10; //Channel on which we do listen 330 int channel = 10; //Channel on which we do listen
330 if (m_obex) 331 if (m_obex)
331 return 0; 332 return 0;
332 m_obex = ::OBEX_Init(OBEX_TRANS_BLUETOOTH, obex_event, 0); 333 m_obex = ::OBEX_Init(transport, obex_event, 0);
333 if (!m_obex) { 334 if (!m_obex) {
334 printf("OBEX initialization error %d\n", errno); 335 printf("OBEX initialization error %d\n", errno);
335 return -1; 336 return -1;
336 } 337 }
337 ::BtOBEX_ServerRegister(m_obex, NULL, channel); 338 if (transport == OBEX_TRANS_BLUETOOTH) {
338 m_session = addOpushSvc(channel, "OBEX push service"); 339 ::BtOBEX_ServerRegister(m_obex, NULL, channel);
339 if (!m_session) { 340 m_session = addOpushSvc(channel, "OBEX push service");
340 printf("OBEX registration error %d\n", errno); 341 if (!m_session) {
341 ::OBEX_Cleanup(m_obex); 342 printf("OBEX registration error %d\n", errno);
342 m_obex = NULL; 343 ::OBEX_Cleanup(m_obex);
343 return -1; 344 m_obex = NULL;
344 } 345 return -1;
346 }
347 } else if (transport == OBEX_TRANS_IRDA)
348 ::IrOBEX_ServerRegister(m_obex, "OBEX");
345 return 0; 349 return 0;
346} 350}
347 351
348bool ObexServer::start(RunMode runmode, Communication comm) 352bool ObexServer::start(RunMode runmode, Communication comm)
349{ 353{
350 if ( runs ) 354 if ( runs )
351 { 355 {
352 return false; // cannot start a process that is already running 356 return false; // cannot start a process that is already running
353 // or if no executable has been assigned 357 // or if no executable has been assigned
354 } 358 }
355 run_mode = runmode; 359 run_mode = runmode;
356 status = 0; 360 status = 0;
357 361
358 if ( !setupCommunication( comm ) ) 362 if ( !setupCommunication( comm ) )
359 qWarning( "Could not setup Communication!" ); 363 qWarning( "Could not setup Communication!" );
360 364
361 // We do this in the parent because if we do it in the child process 365 // 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. 366 // gdb gets confused when the application runs from gdb.
363 uid_t uid = getuid(); 367 uid_t uid = getuid();
364 gid_t gid = getgid(); 368 gid_t gid = getgid();
365#ifdef HAVE_INITGROUPS 369#ifdef HAVE_INITGROUPS
366 370
367 struct passwd *pw = getpwuid( uid ); 371 struct passwd *pw = getpwuid( uid );
368#endif 372#endif
diff --git a/core/obex/obexserver.h b/core/obex/obexserver.h
index 8567105..28577e2 100644
--- a/core/obex/obexserver.h
+++ b/core/obex/obexserver.h
@@ -32,52 +32,54 @@
32#ifndef ObexServer_H 32#ifndef ObexServer_H
33#define ObexServer_H 33#define ObexServer_H
34 34
35#include <qobject.h> 35#include <qobject.h>
36#include <opie2/oprocess.h> 36#include <opie2/oprocess.h>
37 37
38#include <bluetooth/sdp.h> 38#include <bluetooth/sdp.h>
39#include <bluetooth/sdp_lib.h> 39#include <bluetooth/sdp_lib.h>
40 40
41#include <openobex/obex.h> 41#include <openobex/obex.h>
42 42
43namespace Opie { 43namespace Opie {
44 namespace Core { 44 namespace Core {
45 class OProcess; 45 class OProcess;
46 namespace Internal { 46 namespace Internal {
47 class OProcessController; 47 class OProcessController;
48 } 48 }
49 } 49 }
50}; 50};
51 51
52namespace Opie {namespace Core {class OProcess;}} 52namespace Opie {namespace Core {class OProcess;}}
53namespace OpieObex { 53namespace OpieObex {
54 class ObexServer : public Opie::Core::OProcess { 54 class ObexServer : public Opie::Core::OProcess {
55 Q_OBJECT 55 Q_OBJECT
56 private:
57 int transport; //The OBEX transport type
56 public: 58 public:
57 /** 59 /**
58 * ObexServer constructor 60 * ObexServer constructor
59 */ 61 */
60 ObexServer(); 62 ObexServer(int trans);
61 /** 63 /**
62 * 64 *
63 */ 65 */
64 ~ObexServer(); 66 ~ObexServer();
65 //Function starts the server process 67 //Function starts the server process
66 virtual bool start( RunMode runmode = NotifyOnExit, 68 virtual bool start( RunMode runmode = NotifyOnExit,
67 Communication comm = NoCommunication ); 69 Communication comm = NoCommunication );
68 //Stop the server process 70 //Stop the server process
69 int stop(); 71 int stop();
70 protected: //variables 72 protected: //variables
71 obex_t* m_obex; //Obex server handler 73 obex_t* m_obex; //Obex server handler
72 sdp_session_t* m_session; //SDP session handler; 74 sdp_session_t* m_session; //SDP session handler;
73 protected: //functions 75 protected: //functions
74 //Funtion initializes obex server return 0 on success and -1 on error 76 //Funtion initializes obex server return 0 on success and -1 on error
75 int initObex(void); 77 int initObex(void);
76 //Function registers an OBEX push service 78 //Function registers an OBEX push service
77 sdp_session_t* addOpushSvc(uint8_t chan, const char* name); 79 sdp_session_t* addOpushSvc(uint8_t chan, const char* name);
78 signals: 80 signals:
79 protected slots: 81 protected slots:
80 }; 82 };
81}; 83};
82 84
83#endif 85#endif