summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/opietooth/lib/device.cc88
-rw-r--r--noncore/net/opietooth/lib/device.h17
2 files changed, 100 insertions, 5 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,24 +1,102 @@
1 1
2#include "kprocess.h"
3
2#include "device.h" 4#include "device.h"
3 5
4using namespace OpieTooth; 6using namespace OpieTooth;
5 7
6Device::Device(const QString &device, const QString &mode ) 8Device::Device(const QString &device, const QString &mode )
7 : QObject(0, "device" ){ 9 : QObject(0, "device" ){
8 10 m_hci = 0;
11 m_process = 0;
12 m_attached = false;
13 m_device = device;
14 m_mode = mode;
15 attach();
9} 16}
10Device::~Device(){ 17Device::~Device(){
11 18 detach();
12} 19}
13void Device::attach(){ 20void Device::attach(){
14 21 if(m_process != 0 ){
22 m_process = new KProcess();
23 *m_process << "hciattach";
24 *m_process << "-p";
25 *m_process << m_device << m_mode;
26 connect(m_process, SIGNAL( processExited(KProcess*) ),
27 this, SLOT( slotExited(KProcess* ) ) );
28 connect(m_process, SIGNAL( receivedStdout(KProcess*, char*, int) ),
29 this, SLOT(slotStdOut(KProcess*,char*,int ) ) );
30 connect(m_process, SIGNAL(receivedStderr(KProcess*, char*, int ) ),
31 this, SLOT(slotStdErr(KProcess*,char*,int) ) );
32 if(!m_process->start(KProcess::NotifyOnExit, KProcess::AllOutput ) ){
33 delete m_process;
34 m_process = 0;
35 }
36 };
15} 37}
16void Device::detach(){ 38void Device::detach(){
17 39 delete m_hci;
40 delete m_process;
41 // kill the pid we got
42 if(m_attached )
43 //kill the pid
44 ;
18} 45}
19bool Device::isLoaded()const{ 46bool Device::isLoaded()const{
20 return false; 47 return m_attached;
21} 48}
22QString Device::devName()const { 49QString Device::devName()const {
23 return QString::fromLatin1("hci0"); 50 return QString::fromLatin1("hci0");
24}; 51};
52void Device::slotExited( KProcess* proc)
53{
54 if(proc== m_process ){
55 if( m_process->normalExit() ){ // normal exit
56 int ret = m_process->exitStatus();
57 if( ret == 0 ){ // attached
58 // now hciconfig hci0 up ( determine hciX FIXME)
59 // and call hciconfig hci0 up
60 // FIXME hardcoded to hci0 now :(
61 m_hci = new KProcess( );
62 *m_hci << "hciconfig";
63 *m_hci << "hci0 up";
64 connect(m_hci, SIGNAL( processExited(KProcess*) ),
65 this, SLOT( slotExited(KProcess* ) ) );
66 }else{
67 m_attached = false;
68 emit device("hci0", false );
69
70 }
71 }
72 delete m_process;
73 m_process = 0;
74 }else if(proc== m_hci ){
75 if( m_hci->normalExit() ){
76 int ret = m_hci->normalExit();
77 if( ret == 0 ){
78 emit device("hci0", true );
79 }else{
80 emit device("hci0", false );
81 m_attached = false;
82 }
83 }// normal exit
84 delete m_hci;
85 m_hci = 0;
86 }
87}
88void Device::slotStdOut(KProcess* proc, char* chars, int len)
89{
90 if( len <1 )
91 return;
92 if(proc == m_process ){
93 QCString string( chars );
94 if(string.left(3) != "CSR" ){ // it's the pid
95 pid = string.toInt();
96 };
97 }
98}
99void Device::slotStdErr(KProcess*, char*, int )
100{
101
102}
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
@@ -6,6 +6,9 @@
6#include <qstring.h> 6#include <qstring.h>
7#include <qvaluelist.h> 7#include <qvaluelist.h>
8 8
9#include <sys/types.h>
10
11class KProcess;
9namespace OpieTooth { 12namespace OpieTooth {
10 /** 13 /**
11 * Device takes care of attaching serial 14 * Device takes care of attaching serial
@@ -61,6 +64,20 @@ namespace OpieTooth {
61 * @return up bool, if the device is up or not. 64 * @return up bool, if the device is up or not.
62 */ 65 */
63 void device(const QString& device, bool up ); 66 void device(const QString& device, bool up );
67 private slots:
68 virtual void slotExited( KProcess* );
69 virtual void slotStdOut(KProcess*, char*, int );
70 virtual void slotStdErr(KProcess*, char*, int );
71 private:
72 class Private;
73 Private *d;
74 QString m_device;
75 bool m_attached:1;
76 KProcess* m_hci;
77 KProcess* m_process;
78 QString m_devId;
79 QString m_mode;
80 pid_t pid;
64 }; 81 };
65}; 82};
66 83