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