-rw-r--r-- | noncore/net/opietooth/lib/device.cc | 55 |
1 files changed, 42 insertions, 13 deletions
diff --git a/noncore/net/opietooth/lib/device.cc b/noncore/net/opietooth/lib/device.cc index eea1178..40acbd2 100644 --- a/noncore/net/opietooth/lib/device.cc +++ b/noncore/net/opietooth/lib/device.cc | |||
@@ -1,79 +1,108 @@ | |||
1 | 1 | ||
2 | #include "device.h" | 2 | #include "device.h" |
3 | 3 | ||
4 | /* OPIE */ | 4 | /* OPIE */ |
5 | #include <opie2/oprocess.h> | 5 | #include <opie2/oprocess.h> |
6 | #include <opie2/odebug.h> | 6 | #include <opie2/odebug.h> |
7 | #include <opie2/odevice.h> | ||
8 | |||
7 | using namespace Opie::Core; | 9 | using namespace Opie::Core; |
8 | 10 | ||
9 | /* STD */ | 11 | /* STD */ |
10 | #include <signal.h> | 12 | #include <signal.h> |
11 | 13 | ||
12 | 14 | ||
13 | using namespace OpieTooth; | 15 | using namespace OpieTooth; |
14 | 16 | ||
15 | using Opie::Core::OProcess; | 17 | using Opie::Core::OProcess; |
16 | namespace { | 18 | namespace { |
17 | int parsePid( const QCString& par ){ | 19 | int parsePid( const QCString& par ) |
18 | int id=0; | 20 | { |
19 | QString string( par ); | 21 | int id=0; |
20 | QStringList list = QStringList::split( '\n', string ); | 22 | QString string( par ); |
21 | for( QStringList::Iterator it = list.begin(); it != list.end(); ++it ){ | 23 | QStringList list = QStringList::split( '\n', string ); |
22 | owarn << "parsePID: " << (*it).latin1() << oendl; | 24 | |
23 | if( !(*it).startsWith("CSR") ){ | 25 | for( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) |
24 | id = (*it).toInt(); | 26 | { |
25 | break; | 27 | owarn << "parsePID: " << (*it).latin1() << oendl; |
26 | } | 28 | |
29 | // FIXME mbhaynie: Surely there is a better way to skip | ||
30 | // verbosity (E.g. the TI device configuration | ||
31 | // script). Apparently the PID is always on a line by | ||
32 | // itself, or is at least the first word of a line. Does | ||
33 | // QString have somethine like startsWithRegex("[0-9]+")? | ||
34 | if( (*it).startsWith("#") ) continue; | ||
35 | if( (*it).startsWith("TI") ) continue; | ||
36 | if( (*it).startsWith("Loading") ) continue; | ||
37 | if( (*it).startsWith("BTS") ) continue; | ||
38 | if( !(*it).startsWith("CSR") ) | ||
39 | { | ||
40 | id = (*it).toInt(); | ||
41 | break; | ||
42 | } | ||
43 | } | ||
44 | return id; | ||
27 | } | 45 | } |
28 | return id; | ||
29 | } | ||
30 | } | 46 | } |
31 | 47 | ||
32 | Device::Device(const QString &device, const QString &mode, const QString &speed ) | 48 | Device::Device(const QString &device, const QString &mode, const QString &speed ) |
33 | : QObject(0, "device") { | 49 | : QObject(0, "device") { |
34 | 50 | ||
35 | owarn << "OpieTooth::Device create" << oendl; | 51 | owarn << "OpieTooth::Device create" << oendl; |
36 | m_hci = 0; | 52 | m_hci = 0; |
37 | m_process = 0; | 53 | m_process = 0; |
38 | m_attached = false; | 54 | m_attached = false; |
39 | m_device = device; | 55 | m_device = device; |
40 | m_mode = mode; | 56 | m_mode = mode; |
41 | m_speed = speed; | 57 | m_speed = speed; |
42 | attach(); | 58 | attach(); |
43 | } | 59 | } |
44 | Device::~Device(){ | 60 | Device::~Device(){ |
45 | detach(); | 61 | detach(); |
46 | } | 62 | } |
63 | |||
64 | // FIXME mbhaynie -- If BT is active, and opie is restarted, this | ||
65 | // applet thinks bt is down, and will fail to start it again. Not | ||
66 | // sure why. | ||
47 | void Device::attach(){ | 67 | void Device::attach(){ |
48 | owarn << "attaching " << m_device.latin1() << " " << m_mode.latin1() << " " << m_speed.latin1() << oendl; | 68 | owarn << "attaching " << m_device.latin1() << " " << m_mode.latin1() << " " << m_speed.latin1() << oendl; |
49 | if(m_process == 0 ){ | 69 | if(m_process == 0 ){ |
50 | m_output.resize(0); | 70 | m_output.resize(0); |
51 | owarn << "new process to create" << oendl; | 71 | owarn << "new process to create" << oendl; |
52 | m_process = new OProcess(); | 72 | m_process = new OProcess(); |
53 | *m_process << "hciattach"; | 73 | *m_process << "hciattach"; |
54 | *m_process << "-p"; | 74 | *m_process << "-p"; |
55 | *m_process << m_device << m_mode << m_speed; | 75 | |
76 | // FIXME -- this is a hack for an odd hciattach interface. | ||
77 | if ( ODevice::inst()->modelString() == "HX4700" ) | ||
78 | { | ||
79 | *m_process << "-S" << "/etc/bluetooth/TIInit_3.2.26.bts" << "/dev/ttyS1" << "texas"; | ||
80 | } | ||
81 | else | ||
82 | { | ||
83 | *m_process << m_device << m_mode << m_speed; | ||
84 | } | ||
56 | connect(m_process, SIGNAL( processExited(Opie::Core::OProcess*) ), | 85 | connect(m_process, SIGNAL( processExited(Opie::Core::OProcess*) ), |
57 | this, SLOT( slotExited(Opie::Core::OProcess* ) ) ); | 86 | this, SLOT( slotExited(Opie::Core::OProcess* ) ) ); |
58 | connect(m_process, SIGNAL( receivedStdout(Opie::Core::OProcess*, char*, int) ), | 87 | connect(m_process, SIGNAL( receivedStdout(Opie::Core::OProcess*, char*, int) ), |
59 | this, SLOT(slotStdOut(Opie::Core::OProcess*,char*,int ) ) ); | 88 | this, SLOT(slotStdOut(Opie::Core::OProcess*,char*,int ) ) ); |
60 | connect(m_process, SIGNAL(receivedStderr(Opie::Core::OProcess*, char*, int ) ), | 89 | connect(m_process, SIGNAL(receivedStderr(Opie::Core::OProcess*, char*, int ) ), |
61 | this, SLOT(slotStdErr(Opie::Core::OProcess*,char*,int) ) ); | 90 | this, SLOT(slotStdErr(Opie::Core::OProcess*,char*,int) ) ); |
62 | if(!m_process->start(OProcess::NotifyOnExit, OProcess::AllOutput ) ){ | 91 | if(!m_process->start(OProcess::NotifyOnExit, OProcess::AllOutput ) ){ |
63 | owarn << "Could not start" << oendl; | 92 | owarn << "Could not start" << oendl; |
64 | delete m_process; | 93 | delete m_process; |
65 | m_process = 0; | 94 | m_process = 0; |
66 | } | 95 | } |
67 | }; | 96 | }; |
68 | } | 97 | } |
69 | void Device::detach(){ | 98 | void Device::detach(){ |
70 | delete m_hci; | 99 | delete m_hci; |
71 | delete m_process; | 100 | delete m_process; |
72 | // kill the pid we got | 101 | // kill the pid we got |
73 | if(m_attached ){ | 102 | if(m_attached ){ |
74 | //kill the pid | 103 | //kill the pid |
75 | owarn << "killing" << oendl; | 104 | owarn << "killing" << oendl; |
76 | kill(pid, 9); | 105 | kill(pid, 9); |
77 | } | 106 | } |
78 | owarn << "detached" << oendl; | 107 | owarn << "detached" << oendl; |
79 | } | 108 | } |