summaryrefslogtreecommitdiff
path: root/noncore/net/opietooth/lib/device.cc
authorzecke <zecke>2002-06-03 20:14:29 (UTC)
committer zecke <zecke>2002-06-03 20:14:29 (UTC)
commit7080f9f10443d7a8e61d01b5a1c0e9c972f6baca (patch) (side-by-side diff)
tree36f8b2ab579028bba027c0432da2ae41f09b9b4d /noncore/net/opietooth/lib/device.cc
parent8d5f42d770abca69d490774f4b1fc8284e7a86be (diff)
downloadopie-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) (ignore whitespace changes)
-rw-r--r--noncore/net/opietooth/lib/device.cc54
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
@@ -7,8 +7,24 @@
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;
m_attached = false;
@@ -20,7 +36,10 @@ Device::~Device(){
detach();
}
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";
*m_process << "-p";
@@ -32,6 +51,7 @@ void Device::attach(){
connect(m_process, SIGNAL(receivedStderr(KProcess*, char*, int ) ),
this, SLOT(slotStdErr(KProcess*,char*,int) ) );
if(!m_process->start(KProcess::NotifyOnExit, KProcess::AllOutput ) ){
+ qWarning("Could not start" );
delete m_process;
m_process = 0;
}
@@ -41,9 +61,12 @@ void Device::detach(){
delete m_hci;
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;
@@ -53,10 +76,15 @@ 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
// FIXME hardcoded to hci0 now :(
@@ -65,6 +93,11 @@ void Device::slotExited( KProcess* proc)
*m_hci << "hci0 up";
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;
emit device("hci0", false );
@@ -74,11 +107,16 @@ void Device::slotExited( KProcess* proc)
delete m_process;
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;
}
@@ -89,16 +127,16 @@ 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" );
}