summaryrefslogtreecommitdiff
path: root/noncore/net/opietooth/lib/device.cc
Unidiff
Diffstat (limited to 'noncore/net/opietooth/lib/device.cc') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opietooth/lib/device.cc90
1 files changed, 84 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 @@
1 1
2#include "kprocess.h"
3
2#include "device.h" 4#include "device.h"
3 5
@@ -5,20 +7,96 @@ using 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}