author | zecke <zecke> | 2002-06-03 20:14:29 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-06-03 20:14:29 (UTC) |
commit | 7080f9f10443d7a8e61d01b5a1c0e9c972f6baca (patch) (unidiff) | |
tree | 36f8b2ab579028bba027c0432da2ae41f09b9b4d /noncore/net/opietooth/lib/device.cc | |
parent | 8d5f42d770abca69d490774f4b1fc8284e7a86be (diff) | |
download | opie-7080f9f10443d7a8e61d01b5a1c0e9c972f6baca.zip opie-7080f9f10443d7a8e61d01b5a1c0e9c972f6baca.tar.gz opie-7080f9f10443d7a8e61d01b5a1c0e9c972f6baca.tar.bz2 |
attaching and detaching is now working
Diffstat (limited to 'noncore/net/opietooth/lib/device.cc') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/net/opietooth/lib/device.cc | 54 |
1 files changed, 46 insertions, 8 deletions
diff --git a/noncore/net/opietooth/lib/device.cc b/noncore/net/opietooth/lib/device.cc index 468f191..e3d7f3b 100644 --- a/noncore/net/opietooth/lib/device.cc +++ b/noncore/net/opietooth/lib/device.cc | |||
@@ -9,4 +9,20 @@ using namespace OpieTooth; | |||
9 | 9 | ||
10 | namespace { | ||
11 | int parsePid( const QCString& par ){ | ||
12 | int id=0; | ||
13 | QString string( par ); | ||
14 | QStringList list = QStringList::split( '\n', string ); | ||
15 | for( QStringList::Iterator it = list.begin(); it != list.end(); ++it ){ | ||
16 | if( !(*it).startsWith("CSR") ){ | ||
17 | id = (*it).toInt(); | ||
18 | break; | ||
19 | } | ||
20 | } | ||
21 | return id; | ||
22 | } | ||
23 | } | ||
24 | |||
10 | Device::Device(const QString &device, const QString &mode ) | 25 | Device::Device(const QString &device, const QString &mode ) |
11 | : QObject(0, "device" ) { | 26 | : QObject(0, "device" ) { |
27 | qWarning("OpieTooth::Device create" ); | ||
12 | m_hci = 0; | 28 | m_hci = 0; |
@@ -22,3 +38,6 @@ Device::~Device(){ | |||
22 | void Device::attach(){ | 38 | void Device::attach(){ |
23 | if(m_process != 0 ){ | 39 | qWarning("attaching %s %s", m_device.latin1(), m_mode.latin1() ); |
40 | if(m_process == 0 ){ | ||
41 | m_output.resize(0); | ||
42 | qWarning("new process to create" ); | ||
24 | m_process = new KProcess(); | 43 | m_process = new KProcess(); |
@@ -34,2 +53,3 @@ void Device::attach(){ | |||
34 | if(!m_process->start(KProcess::NotifyOnExit, KProcess::AllOutput ) ){ | 53 | if(!m_process->start(KProcess::NotifyOnExit, KProcess::AllOutput ) ){ |
54 | qWarning("Could not start" ); | ||
35 | delete m_process; | 55 | delete m_process; |
@@ -43,6 +63,9 @@ void Device::detach(){ | |||
43 | // kill the pid we got | 63 | // kill the pid we got |
44 | if(m_attached ) | 64 | if(m_attached ){ |
45 | //kill the pid | 65 | //kill the pid |
66 | qWarning( "killing" ); | ||
46 | kill(pid, 9); | 67 | kill(pid, 9); |
47 | } | 68 | } |
69 | qWarning("detached" ); | ||
70 | } | ||
48 | bool Device::isLoaded()const{ | 71 | bool Device::isLoaded()const{ |
@@ -55,2 +78,3 @@ void Device::slotExited( KProcess* proc) | |||
55 | { | 78 | { |
79 | qWarning("prcess exited" ); | ||
56 | if(proc== m_process ){ | 80 | if(proc== m_process ){ |
@@ -59,2 +83,6 @@ void Device::slotExited( KProcess* proc) | |||
59 | if( ret == 0 ){ // attached | 83 | if( ret == 0 ){ // attached |
84 | qWarning("attached" ); | ||
85 | qWarning("Output: %s", m_output.data() ); | ||
86 | pid = parsePid( m_output ); | ||
87 | qWarning("Pid = %d", pid ); | ||
60 | // now hciconfig hci0 up ( determine hciX FIXME) | 88 | // now hciconfig hci0 up ( determine hciX FIXME) |
@@ -67,2 +95,7 @@ void Device::slotExited( KProcess* proc) | |||
67 | this, SLOT( slotExited(KProcess* ) ) ); | 95 | this, SLOT( slotExited(KProcess* ) ) ); |
96 | if(!m_hci->start() ){ | ||
97 | qWarning("could not start" ); | ||
98 | m_attached = false; | ||
99 | emit device("hci0", false ); | ||
100 | } | ||
68 | }else{ | 101 | }else{ |
@@ -76,7 +109,12 @@ void Device::slotExited( KProcess* proc) | |||
76 | }else if(proc== m_hci ){ | 109 | }else if(proc== m_hci ){ |
110 | qWarning("M HCI exited" ); | ||
77 | if( m_hci->normalExit() ){ | 111 | if( m_hci->normalExit() ){ |
78 | int ret = m_hci->normalExit(); | 112 | qWarning("normal exit" ); |
113 | int ret = m_hci->exitStatus(); | ||
79 | if( ret == 0 ){ | 114 | if( ret == 0 ){ |
115 | qWarning("attached really really attached" ); | ||
116 | m_attached = true; | ||
80 | emit device("hci0", true ); | 117 | emit device("hci0", true ); |
81 | }else{ | 118 | }else{ |
119 | qWarning( "failed" ); | ||
82 | emit device("hci0", false ); | 120 | emit device("hci0", false ); |
@@ -91,2 +129,3 @@ void Device::slotStdOut(KProcess* proc, char* chars, int len) | |||
91 | { | 129 | { |
130 | qWarning("std out" ); | ||
92 | if( len <1 ) | 131 | if( len <1 ) |
@@ -94,6 +133,5 @@ void Device::slotStdOut(KProcess* proc, char* chars, int len) | |||
94 | if(proc == m_process ){ | 133 | if(proc == m_process ){ |
95 | QCString string( chars, len+1 ); | 134 | QCString string( chars, len+1 ); // \0 == +1 |
96 | if(string.left(3) != "CSR" ){ // it's the pid | 135 | qWarning("output: %s", string.data() ); |
97 | pid = string.toInt(); | 136 | m_output.append( string.data() ); |
98 | }; | ||
99 | } | 137 | } |
@@ -102,3 +140,3 @@ void Device::slotStdErr(KProcess*, char*, int ) | |||
102 | { | 140 | { |
103 | 141 | qWarning("std err" ); | |
104 | } | 142 | } |