-rw-r--r-- | noncore/net/opietooth/lib/device.cc | 16 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/lib.pro | 7 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/obexpush.cpp | 108 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/obexpush.h | 77 |
4 files changed, 196 insertions, 12 deletions
diff --git a/noncore/net/opietooth/lib/device.cc b/noncore/net/opietooth/lib/device.cc index 40acbd2..2f04d46 100644 --- a/noncore/net/opietooth/lib/device.cc +++ b/noncore/net/opietooth/lib/device.cc | |||
@@ -19,27 +19,25 @@ namespace { | |||
19 | int parsePid( const QCString& par ) | 19 | int parsePid( const QCString& par ) |
20 | { | 20 | { |
21 | int id=0; | 21 | int id=0; |
22 | QString string( par ); | 22 | QString string( par ); |
23 | QStringList list = QStringList::split( '\n', string ); | 23 | QStringList list = QStringList::split( '\n', string ); |
24 | 24 | ||
25 | for( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) | 25 | for( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { |
26 | { | ||
27 | owarn << "parsePID: " << (*it).latin1() << oendl; | 26 | owarn << "parsePID: " << (*it).latin1() << oendl; |
28 | 27 | ||
29 | // FIXME mbhaynie: Surely there is a better way to skip | 28 | // FIXME mbhaynie: Surely there is a better way to skip |
30 | // verbosity (E.g. the TI device configuration | 29 | // verbosity (E.g. the TI device configuration |
31 | // script). Apparently the PID is always on a line by | 30 | // script). Apparently the PID is always on a line by |
32 | // itself, or is at least the first word of a line. Does | 31 | // itself, or is at least the first word of a line. Does |
33 | // QString have somethine like startsWithRegex("[0-9]+")? | 32 | // QString have somethine like startsWithRegex("[0-9]+")? |
34 | if( (*it).startsWith("#") ) continue; | 33 | if( (*it).startsWith("#") ) continue; |
35 | if( (*it).startsWith("TI") ) continue; | 34 | if( (*it).startsWith("TI") ) continue; |
36 | if( (*it).startsWith("Loading") ) continue; | 35 | if( (*it).startsWith("Loading") ) continue; |
37 | if( (*it).startsWith("BTS") ) continue; | 36 | if( (*it).startsWith("BTS") ) continue; |
38 | if( !(*it).startsWith("CSR") ) | 37 | if( !(*it).startsWith("CSR") ) { |
39 | { | ||
40 | id = (*it).toInt(); | 38 | id = (*it).toInt(); |
41 | break; | 39 | break; |
42 | } | 40 | } |
43 | } | 41 | } |
44 | return id; | 42 | return id; |
45 | } | 43 | } |
@@ -72,40 +70,38 @@ void Device::attach(){ | |||
72 | m_process = new OProcess(); | 70 | m_process = new OProcess(); |
73 | *m_process << "hciattach"; | 71 | *m_process << "hciattach"; |
74 | *m_process << "-p"; | 72 | *m_process << "-p"; |
75 | 73 | ||
76 | // FIXME -- this is a hack for an odd hciattach interface. | 74 | // FIXME -- this is a hack for an odd hciattach interface. |
77 | if ( ODevice::inst()->modelString() == "HX4700" ) | 75 | if ( ODevice::inst()->modelString() == "HX4700" ) |
78 | { | ||
79 | *m_process << "-S" << "/etc/bluetooth/TIInit_3.2.26.bts" << "/dev/ttyS1" << "texas"; | 76 | *m_process << "-S" << "/etc/bluetooth/TIInit_3.2.26.bts" << "/dev/ttyS1" << "texas"; |
80 | } | ||
81 | else | 77 | else |
82 | { | ||
83 | *m_process << m_device << m_mode << m_speed; | 78 | *m_process << m_device << m_mode << m_speed; |
84 | } | ||
85 | connect(m_process, SIGNAL( processExited(Opie::Core::OProcess*) ), | 79 | connect(m_process, SIGNAL( processExited(Opie::Core::OProcess*) ), |
86 | this, SLOT( slotExited(Opie::Core::OProcess* ) ) ); | 80 | this, SLOT( slotExited(Opie::Core::OProcess* ) ) ); |
87 | connect(m_process, SIGNAL( receivedStdout(Opie::Core::OProcess*, char*, int) ), | 81 | connect(m_process, SIGNAL( receivedStdout(Opie::Core::OProcess*, char*, int) ), |
88 | this, SLOT(slotStdOut(Opie::Core::OProcess*,char*,int ) ) ); | 82 | this, SLOT(slotStdOut(Opie::Core::OProcess*,char*,int ) ) ); |
89 | connect(m_process, SIGNAL(receivedStderr(Opie::Core::OProcess*, char*, int ) ), | 83 | connect(m_process, SIGNAL(receivedStderr(Opie::Core::OProcess*, char*, int ) ), |
90 | this, SLOT(slotStdErr(Opie::Core::OProcess*,char*,int) ) ); | 84 | this, SLOT(slotStdErr(Opie::Core::OProcess*,char*,int) ) ); |
91 | if(!m_process->start(OProcess::NotifyOnExit, OProcess::AllOutput ) ){ | 85 | if(!m_process->start(OProcess::NotifyOnExit, OProcess::AllOutput ) ){ |
92 | owarn << "Could not start" << oendl; | 86 | owarn << "Could not start" << oendl; |
93 | delete m_process; | 87 | delete m_process; |
94 | m_process = 0; | 88 | m_process = 0; |
95 | } | 89 | } |
96 | }; | 90 | } |
97 | } | 91 | } |
98 | void Device::detach(){ | 92 | void Device::detach(){ |
99 | delete m_hci; | 93 | delete m_hci; |
94 | m_hci = 0; | ||
100 | delete m_process; | 95 | delete m_process; |
96 | m_process = 0; | ||
101 | // kill the pid we got | 97 | // kill the pid we got |
102 | if(m_attached ){ | 98 | if(m_attached ){ |
103 | //kill the pid | 99 | //kill the pid |
104 | owarn << "killing" << oendl; | 100 | owarn << "killing" << oendl; |
105 | kill(pid, 9); | 101 | ::kill(pid, 9); |
106 | } | 102 | } |
107 | owarn << "detached" << oendl; | 103 | owarn << "detached" << oendl; |
108 | } | 104 | } |
109 | bool Device::isLoaded()const{ | 105 | bool Device::isLoaded()const{ |
110 | return m_attached; | 106 | return m_attached; |
111 | } | 107 | } |
diff --git a/noncore/net/opietooth/lib/lib.pro b/noncore/net/opietooth/lib/lib.pro index 781bf15..e11af9a 100644 --- a/noncore/net/opietooth/lib/lib.pro +++ b/noncore/net/opietooth/lib/lib.pro | |||
@@ -1,12 +1,15 @@ | |||
1 | TEMPLATE = lib | 1 | TEMPLATE = lib |
2 | CONFIG += qte warn_on | 2 | CONFIG += qte warn_on |
3 | HEADERS = connection.h parser.h device.h manager.h remotedevice.h services.h \ | 3 | HEADERS = connection.h parser.h device.h manager.h remotedevice.h services.h \ |
4 | startpanconnection.h startdunconnection.h bt-serial.h forwarder.h | 4 | startpanconnection.h startdunconnection.h obexpush.h \ |
5 | bt-serial.h forwarder.h | ||
5 | SOURCES = connection.cpp parser.cc device.cc manager.cc remotedevice.cc services.cc \ | 6 | SOURCES = connection.cpp parser.cc device.cc manager.cc remotedevice.cc services.cc \ |
6 | startpanconnection.cpp startdunconnection.cpp bt-serial.c forwarder.cc | 7 | startpanconnection.cpp startdunconnection.cpp obexpush.cpp \ |
8 | bt-serial.c forwarder.cc | ||
9 | |||
7 | TARGET = opietooth1 | 10 | TARGET = opietooth1 |
8 | INCLUDEPATH += $(OPIEDIR)/include . | 11 | INCLUDEPATH += $(OPIEDIR)/include . |
9 | DESTDIR = $(OPIEDIR)/lib | 12 | DESTDIR = $(OPIEDIR)/lib |
10 | LIBS += -lopiecore2 | 13 | LIBS += -lopiecore2 |
11 | 14 | ||
12 | include( $(OPIEDIR)/include.pro ) | 15 | include( $(OPIEDIR)/include.pro ) |
diff --git a/noncore/net/opietooth/lib/obexpush.cpp b/noncore/net/opietooth/lib/obexpush.cpp new file mode 100644 index 0000000..e0a4bee --- a/dev/null +++ b/noncore/net/opietooth/lib/obexpush.cpp | |||
@@ -0,0 +1,108 @@ | |||
1 | /* $Id$ */ | ||
2 | /* OBEX push functions implementation */ | ||
3 | /*************************************************************************** | ||
4 | * * | ||
5 | * This program is free software; you can redistribute it and/or modify * | ||
6 | * it under the terms of the GNU General Public License as published by * | ||
7 | * the Free Software Foundation; either version 2 of the License, or * | ||
8 | * (at your option) any later version. * | ||
9 | * * | ||
10 | ***************************************************************************/ | ||
11 | #include "obexpush.h" | ||
12 | |||
13 | #include <qfileinfo.h> | ||
14 | #include <qfile.h> | ||
15 | |||
16 | #include <opie2/odebug.h> | ||
17 | #include <opie2/odebug.h> | ||
18 | |||
19 | using namespace Opie::Core; | ||
20 | using namespace OpieTooth; | ||
21 | |||
22 | ObexPush::ObexPush() | ||
23 | { | ||
24 | pushProc = new OProcess(); | ||
25 | connect(pushProc, SIGNAL(processExited(Opie::Core::OProcess*)), | ||
26 | this, SLOT(slotPushExited(Opie::Core::OProcess*))); | ||
27 | connect(pushProc, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int)), | ||
28 | this, SLOT(slotPushOut(Opie::Core::OProcess*, char*, int))); | ||
29 | connect(pushProc, SIGNAL(receivedStderr(Opie::Core::OProcess*, char*, int)), | ||
30 | this, SLOT(slotPushErr(Opie::Core::OProcess*, char*, int))); | ||
31 | |||
32 | } | ||
33 | |||
34 | ObexPush::~ObexPush() | ||
35 | { | ||
36 | if (pushProc->isRunning()) | ||
37 | pushProc->kill(); | ||
38 | delete pushProc; | ||
39 | pushProc = NULL; | ||
40 | } | ||
41 | |||
42 | /** | ||
43 | * Function that sends a file | ||
44 | * @param mac destination device MAC address | ||
45 | * @param port service port number | ||
46 | * @param src source file name | ||
47 | * @param dst destination file name | ||
48 | * @return 0 on success, -1 on error, 1 if sending process is running | ||
49 | */ | ||
50 | int ObexPush::send(QString& mac, int port, QString& src, QString& dst) | ||
51 | { | ||
52 | QString dev = mac; | ||
53 | QString execName = "ussp-push"; | ||
54 | if (pushProc->isRunning()) | ||
55 | return 1; | ||
56 | pushProc->clearArguments(); | ||
57 | dev += "@"; | ||
58 | dev += QString::number(port); | ||
59 | if (!dst.isEmpty()) | ||
60 | *pushProc << execName << "--timeo 30" << dev | ||
61 | << QFile::encodeName(src) << QFile::encodeName(dst); | ||
62 | else | ||
63 | *pushProc << execName << "--timeo 30" << dev | ||
64 | << QFile::encodeName(src) | ||
65 | << QFile::encodeName(QFileInfo(src).fileName()); | ||
66 | odebug << execName << " " << dev << " " << src << " " | ||
67 | << ((!dst.isEmpty())? dst: QFileInfo(src).fileName()) << oendl; | ||
68 | pushProc->setUseShell(true); | ||
69 | if (!pushProc->start(OProcess::NotifyOnExit, OProcess::All)) | ||
70 | return -1; | ||
71 | else | ||
72 | return 0; | ||
73 | } | ||
74 | |||
75 | void ObexPush::slotPushExited(Opie::Core::OProcess* proc) | ||
76 | { | ||
77 | if (pushProc != proc) | ||
78 | return; | ||
79 | odebug << "Process exited" << oendl; | ||
80 | if (pushProc->normalExit()) | ||
81 | emit sendComplete(pushProc->exitStatus()); | ||
82 | else | ||
83 | emit sendError(-1); | ||
84 | } | ||
85 | |||
86 | /** | ||
87 | * Function makes a notification from slotPushOut and slotPushErr | ||
88 | */ | ||
89 | void ObexPush::notifyInfo(Opie::Core::OProcess* proc, char* buf, int len) | ||
90 | { | ||
91 | if (proc != pushProc) | ||
92 | return; | ||
93 | QCString str(buf, len); | ||
94 | odebug << str << oendl; | ||
95 | emit status(str); | ||
96 | } | ||
97 | |||
98 | void ObexPush::slotPushOut(Opie::Core::OProcess* proc, char* buf, int len) | ||
99 | { | ||
100 | notifyInfo(proc, buf, len); | ||
101 | } | ||
102 | |||
103 | void ObexPush::slotPushErr(Opie::Core::OProcess* proc, char* buf, int len) | ||
104 | { | ||
105 | notifyInfo(proc, buf, len); | ||
106 | } | ||
107 | |||
108 | //eof | ||
diff --git a/noncore/net/opietooth/lib/obexpush.h b/noncore/net/opietooth/lib/obexpush.h new file mode 100644 index 0000000..8147643 --- a/dev/null +++ b/noncore/net/opietooth/lib/obexpush.h | |||
@@ -0,0 +1,77 @@ | |||
1 | /* $Id$ */ | ||
2 | /* OBEX push functions declarations */ | ||
3 | /*************************************************************************** | ||
4 | * * | ||
5 | * This program is free software; you can redistribute it and/or modify * | ||
6 | * it under the terms of the GNU General Public License as published by * | ||
7 | * the Free Software Foundation; either version 2 of the License, or * | ||
8 | * (at your option) any later version. * | ||
9 | * * | ||
10 | ***************************************************************************/ | ||
11 | #ifndef _OBEXPUSH_H_ | ||
12 | #define _OBEXPUSH_H_ | ||
13 | #include <qobject.h> | ||
14 | #include <qstring.h> | ||
15 | #include "services.h" | ||
16 | #include <opie2/oprocess.h> | ||
17 | namespace OpieTooth { | ||
18 | class ObexPush : public QObject { | ||
19 | Q_OBJECT | ||
20 | public: | ||
21 | /** | ||
22 | * Constructor which creates an object | ||
23 | */ | ||
24 | ObexPush(); | ||
25 | |||
26 | /** | ||
27 | * Public destructor | ||
28 | */ | ||
29 | ~ObexPush(); | ||
30 | |||
31 | /** | ||
32 | * Function that sends a file | ||
33 | * @param mac destination device MAC address | ||
34 | * @param port service port number | ||
35 | * @param src source file name | ||
36 | * @param dst destination file name | ||
37 | * @return 0 on success, -1 on error, 1 if sending process is running | ||
38 | */ | ||
39 | int send(QString& mac, int port, QString& src, QString& dst); | ||
40 | |||
41 | /** | ||
42 | * @return true if it's sending and false otherwise | ||
43 | */ | ||
44 | bool isSending() { return pushProc->isRunning(); } | ||
45 | signals: | ||
46 | /** | ||
47 | * Informs that the sending process has completed | ||
48 | * @param status the finish status | ||
49 | */ | ||
50 | void sendComplete(int); | ||
51 | |||
52 | /** | ||
53 | * Informs that the sending process has finished with error | ||
54 | * @param status the finish status | ||
55 | */ | ||
56 | void sendError(int); | ||
57 | |||
58 | /** | ||
59 | * Informs that we have a string status update | ||
60 | * @param str status string | ||
61 | */ | ||
62 | void status(QCString&); | ||
63 | protected slots: | ||
64 | void slotPushOut(Opie::Core::OProcess*, char*, int); | ||
65 | void slotPushErr(Opie::Core::OProcess*, char*, int); | ||
66 | void slotPushExited(Opie::Core::OProcess* proc); | ||
67 | protected: | ||
68 | /** | ||
69 | * Function makes a notification from slotPushOut and slotPushErr | ||
70 | */ | ||
71 | void notifyInfo(Opie::Core::OProcess*, char*, int); | ||
72 | protected: | ||
73 | Opie::Core::OProcess* pushProc; //The push process | ||
74 | }; | ||
75 | }; | ||
76 | #endif | ||
77 | //eof | ||