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; +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; @@ -22,3 +38,6 @@ 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(); @@ -34,2 +53,3 @@ void Device::attach(){ if(!m_process->start(KProcess::NotifyOnExit, KProcess::AllOutput ) ){ + qWarning("Could not start" ); delete m_process; @@ -43,6 +63,9 @@ void Device::detach(){ // 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{ @@ -55,2 +78,3 @@ void Device::slotExited( KProcess* proc) { + qWarning("prcess exited" ); if(proc== m_process ){ @@ -59,2 +83,6 @@ void Device::slotExited( KProcess* proc) 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) @@ -67,2 +95,7 @@ void Device::slotExited( KProcess* proc) this, SLOT( slotExited(KProcess* ) ) ); + if(!m_hci->start() ){ + qWarning("could not start" ); + m_attached = false; + emit device("hci0", false ); + } }else{ @@ -76,7 +109,12 @@ void Device::slotExited( KProcess* proc) }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 ); @@ -91,2 +129,3 @@ void Device::slotStdOut(KProcess* proc, char* chars, int len) { + qWarning("std out" ); if( len <1 ) @@ -94,6 +133,5 @@ void Device::slotStdOut(KProcess* proc, char* chars, int len) 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() ); } @@ -102,3 +140,3 @@ void Device::slotStdErr(KProcess*, char*, int ) { - + qWarning("std err" ); } |