author | zecke <zecke> | 2002-06-03 20:14:29 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-06-03 20:14:29 (UTC) |
commit | 7080f9f10443d7a8e61d01b5a1c0e9c972f6baca (patch) (side-by-side diff) | |
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 @@ -8,6 +8,22 @@ using namespace OpieTooth; +namespace { + int parsePid( const QCString& par ){ + int id=0; + QString string( par ); + QStringList list = QStringList::split( '\n', string ); + for( QStringList::Iterator it = list.begin(); it != list.end(); ++it ){ + if( !(*it).startsWith("CSR") ){ + id = (*it).toInt(); + break; + } + } + return id; + } +} + Device::Device(const QString &device, const QString &mode ) : QObject(0, "device" ) { + qWarning("OpieTooth::Device create" ); m_hci = 0; m_process = 0; @@ -21,5 +37,8 @@ Device::~Device(){ } void Device::attach(){ - if(m_process != 0 ){ + qWarning("attaching %s %s", m_device.latin1(), m_mode.latin1() ); + if(m_process == 0 ){ + m_output.resize(0); + qWarning("new process to create" ); m_process = new KProcess(); *m_process << "hciattach"; @@ -33,4 +52,5 @@ void Device::attach(){ this, SLOT(slotStdErr(KProcess*,char*,int) ) ); if(!m_process->start(KProcess::NotifyOnExit, KProcess::AllOutput ) ){ + qWarning("Could not start" ); delete m_process; m_process = 0; @@ -42,8 +62,11 @@ void Device::detach(){ delete m_process; // kill the pid we got - if(m_attached ) + if(m_attached ){ //kill the pid + qWarning( "killing" ); kill(pid, 9); } + qWarning("detached" ); +} bool Device::isLoaded()const{ return m_attached; @@ -54,8 +77,13 @@ QString Device::devName()const { void Device::slotExited( KProcess* proc) { + qWarning("prcess exited" ); if(proc== m_process ){ if( m_process->normalExit() ){ // normal exit int ret = m_process->exitStatus(); if( ret == 0 ){ // attached + qWarning("attached" ); + qWarning("Output: %s", m_output.data() ); + pid = parsePid( m_output ); + qWarning("Pid = %d", pid ); // now hciconfig hci0 up ( determine hciX FIXME) // and call hciconfig hci0 up @@ -66,4 +94,9 @@ void Device::slotExited( KProcess* proc) connect(m_hci, SIGNAL( processExited(KProcess*) ), this, SLOT( slotExited(KProcess* ) ) ); + if(!m_hci->start() ){ + qWarning("could not start" ); + m_attached = false; + emit device("hci0", false ); + } }else{ m_attached = false; @@ -75,9 +108,14 @@ void Device::slotExited( KProcess* proc) m_process = 0; }else if(proc== m_hci ){ + qWarning("M HCI exited" ); if( m_hci->normalExit() ){ - int ret = m_hci->normalExit(); + qWarning("normal exit" ); + int ret = m_hci->exitStatus(); if( ret == 0 ){ + qWarning("attached really really attached" ); + m_attached = true; emit device("hci0", true ); }else{ + qWarning( "failed" ); emit device("hci0", false ); m_attached = false; @@ -90,15 +128,15 @@ void Device::slotExited( KProcess* proc) void Device::slotStdOut(KProcess* proc, char* chars, int len) { + qWarning("std out" ); if( len <1 ) return; if(proc == m_process ){ - QCString string( chars, len+1 ); - if(string.left(3) != "CSR" ){ // it's the pid - pid = string.toInt(); - }; + QCString string( chars, len+1 ); // \0 == +1 + qWarning("output: %s", string.data() ); + m_output.append( string.data() ); } } void Device::slotStdErr(KProcess*, char*, int ) { - + qWarning("std err" ); } |