author | zecke <zecke> | 2002-06-01 12:36:34 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-06-01 12:36:34 (UTC) |
commit | f386b95e1c9763bb9c5ea404c0824b45a744e151 (patch) (side-by-side diff) | |
tree | fb64a35e3824e3b50b93b1289a0feed50a1d3b5f | |
parent | 075f2ae74f328581ec0db05d633961f3baa5ed36 (diff) | |
download | opie-f386b95e1c9763bb9c5ea404c0824b45a744e151.zip opie-f386b95e1c9763bb9c5ea404c0824b45a744e151.tar.gz opie-f386b95e1c9763bb9c5ea404c0824b45a744e151.tar.bz2 |
attaching and detaching
-rw-r--r-- | noncore/net/opietooth/lib/device.cc | 90 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/device.h | 17 |
2 files changed, 101 insertions, 6 deletions
diff --git a/noncore/net/opietooth/lib/device.cc b/noncore/net/opietooth/lib/device.cc index b567e2b..0c552ea 100644 --- a/noncore/net/opietooth/lib/device.cc +++ b/noncore/net/opietooth/lib/device.cc @@ -1,3 +1,5 @@ +#include "kprocess.h" + #include "device.h" @@ -5,20 +7,96 @@ using namespace OpieTooth; Device::Device(const QString &device, const QString &mode ) - : QObject(0, "device" ){ - + : QObject(0, "device" ) { + m_hci = 0; + m_process = 0; + m_attached = false; + m_device = device; + m_mode = mode; + attach(); } Device::~Device(){ - + detach(); } void Device::attach(){ - + if(m_process != 0 ){ + m_process = new KProcess(); + *m_process << "hciattach"; + *m_process << "-p"; + *m_process << m_device << m_mode; + connect(m_process, SIGNAL( processExited(KProcess*) ), + this, SLOT( slotExited(KProcess* ) ) ); + connect(m_process, SIGNAL( receivedStdout(KProcess*, char*, int) ), + this, SLOT(slotStdOut(KProcess*,char*,int ) ) ); + connect(m_process, SIGNAL(receivedStderr(KProcess*, char*, int ) ), + this, SLOT(slotStdErr(KProcess*,char*,int) ) ); + if(!m_process->start(KProcess::NotifyOnExit, KProcess::AllOutput ) ){ + delete m_process; + m_process = 0; + } + }; } void Device::detach(){ - + delete m_hci; + delete m_process; + // kill the pid we got + if(m_attached ) + //kill the pid + ; } bool Device::isLoaded()const{ - return false; + return m_attached; } QString Device::devName()const { return QString::fromLatin1("hci0"); }; +void Device::slotExited( KProcess* proc) +{ + if(proc== m_process ){ + if( m_process->normalExit() ){ // normal exit + int ret = m_process->exitStatus(); + if( ret == 0 ){ // attached + // now hciconfig hci0 up ( determine hciX FIXME) + // and call hciconfig hci0 up + // FIXME hardcoded to hci0 now :( + m_hci = new KProcess( ); + *m_hci << "hciconfig"; + *m_hci << "hci0 up"; + connect(m_hci, SIGNAL( processExited(KProcess*) ), + this, SLOT( slotExited(KProcess* ) ) ); + }else{ + m_attached = false; + emit device("hci0", false ); + + } + } + delete m_process; + m_process = 0; + }else if(proc== m_hci ){ + if( m_hci->normalExit() ){ + int ret = m_hci->normalExit(); + if( ret == 0 ){ + emit device("hci0", true ); + }else{ + emit device("hci0", false ); + m_attached = false; + } + }// normal exit + delete m_hci; + m_hci = 0; + } +} +void Device::slotStdOut(KProcess* proc, char* chars, int len) +{ + if( len <1 ) + return; + if(proc == m_process ){ + QCString string( chars ); + if(string.left(3) != "CSR" ){ // it's the pid + pid = string.toInt(); + }; + } +} +void Device::slotStdErr(KProcess*, char*, int ) +{ + +} diff --git a/noncore/net/opietooth/lib/device.h b/noncore/net/opietooth/lib/device.h index d23f24c..010db40 100644 --- a/noncore/net/opietooth/lib/device.h +++ b/noncore/net/opietooth/lib/device.h @@ -7,4 +7,7 @@ #include <qvaluelist.h> +#include <sys/types.h> + +class KProcess; namespace OpieTooth { /** @@ -62,4 +65,18 @@ namespace OpieTooth { */ void device(const QString& device, bool up ); + private slots: + virtual void slotExited( KProcess* ); + virtual void slotStdOut(KProcess*, char*, int ); + virtual void slotStdErr(KProcess*, char*, int ); + private: + class Private; + Private *d; + QString m_device; + bool m_attached:1; + KProcess* m_hci; + KProcess* m_process; + QString m_devId; + QString m_mode; + pid_t pid; }; }; |