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) (unidiff)
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) (show 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 @@
7 7
8using namespace OpieTooth; 8using namespace OpieTooth;
9 9
10namespace {
11 int parsePid( const QCString& par ){
12 int id=0;
13 QString string( par );
14 QStringList list = QStringList::split( '\n', string );
15 for( QStringList::Iterator it = list.begin(); it != list.end(); ++it ){
16 if( !(*it).startsWith("CSR") ){
17 id = (*it).toInt();
18 break;
19 }
20 }
21 return id;
22 }
23}
24
10Device::Device(const QString &device, const QString &mode ) 25Device::Device(const QString &device, const QString &mode )
11 : QObject(0, "device" ) { 26 : QObject(0, "device" ) {
27 qWarning("OpieTooth::Device create" );
12 m_hci = 0; 28 m_hci = 0;
13 m_process = 0; 29 m_process = 0;
14 m_attached = false; 30 m_attached = false;
@@ -20,7 +36,10 @@ Device::~Device(){
20 detach(); 36 detach();
21} 37}
22void Device::attach(){ 38void Device::attach(){
23 if(m_process != 0 ){ 39 qWarning("attaching %s %s", m_device.latin1(), m_mode.latin1() );
40 if(m_process == 0 ){
41 m_output.resize(0);
42 qWarning("new process to create" );
24 m_process = new KProcess(); 43 m_process = new KProcess();
25 *m_process << "hciattach"; 44 *m_process << "hciattach";
26 *m_process << "-p"; 45 *m_process << "-p";
@@ -32,6 +51,7 @@ void Device::attach(){
32 connect(m_process, SIGNAL(receivedStderr(KProcess*, char*, int ) ), 51 connect(m_process, SIGNAL(receivedStderr(KProcess*, char*, int ) ),
33 this, SLOT(slotStdErr(KProcess*,char*,int) ) ); 52 this, SLOT(slotStdErr(KProcess*,char*,int) ) );
34 if(!m_process->start(KProcess::NotifyOnExit, KProcess::AllOutput ) ){ 53 if(!m_process->start(KProcess::NotifyOnExit, KProcess::AllOutput ) ){
54 qWarning("Could not start" );
35 delete m_process; 55 delete m_process;
36 m_process = 0; 56 m_process = 0;
37 } 57 }
@@ -41,10 +61,13 @@ void Device::detach(){
41 delete m_hci; 61 delete m_hci;
42 delete m_process; 62 delete m_process;
43 // kill the pid we got 63 // kill the pid we got
44 if(m_attached ) 64 if(m_attached ){
45 //kill the pid 65 //kill the pid
66 qWarning( "killing" );
46 kill(pid, 9); 67 kill(pid, 9);
47} 68}
69 qWarning("detached" );
70}
48bool Device::isLoaded()const{ 71bool Device::isLoaded()const{
49 return m_attached; 72 return m_attached;
50} 73}
@@ -53,10 +76,15 @@ QString Device::devName()const {
53}; 76};
54void Device::slotExited( KProcess* proc) 77void Device::slotExited( KProcess* proc)
55{ 78{
79 qWarning("prcess exited" );
56 if(proc== m_process ){ 80 if(proc== m_process ){
57 if( m_process->normalExit() ){ // normal exit 81 if( m_process->normalExit() ){ // normal exit
58 int ret = m_process->exitStatus(); 82 int ret = m_process->exitStatus();
59 if( ret == 0 ){ // attached 83 if( ret == 0 ){ // attached
84 qWarning("attached" );
85 qWarning("Output: %s", m_output.data() );
86 pid = parsePid( m_output );
87 qWarning("Pid = %d", pid );
60 // now hciconfig hci0 up ( determine hciX FIXME) 88 // now hciconfig hci0 up ( determine hciX FIXME)
61 // and call hciconfig hci0 up 89 // and call hciconfig hci0 up
62 // FIXME hardcoded to hci0 now :( 90 // FIXME hardcoded to hci0 now :(
@@ -65,6 +93,11 @@ void Device::slotExited( KProcess* proc)
65 *m_hci << "hci0 up"; 93 *m_hci << "hci0 up";
66 connect(m_hci, SIGNAL( processExited(KProcess*) ), 94 connect(m_hci, SIGNAL( processExited(KProcess*) ),
67 this, SLOT( slotExited(KProcess* ) ) ); 95 this, SLOT( slotExited(KProcess* ) ) );
96 if(!m_hci->start() ){
97 qWarning("could not start" );
98 m_attached = false;
99 emit device("hci0", false );
100 }
68 }else{ 101 }else{
69 m_attached = false; 102 m_attached = false;
70 emit device("hci0", false ); 103 emit device("hci0", false );
@@ -74,11 +107,16 @@ void Device::slotExited( KProcess* proc)
74 delete m_process; 107 delete m_process;
75 m_process = 0; 108 m_process = 0;
76 }else if(proc== m_hci ){ 109 }else if(proc== m_hci ){
110 qWarning("M HCI exited" );
77 if( m_hci->normalExit() ){ 111 if( m_hci->normalExit() ){
78 int ret = m_hci->normalExit(); 112 qWarning("normal exit" );
113 int ret = m_hci->exitStatus();
79 if( ret == 0 ){ 114 if( ret == 0 ){
115 qWarning("attached really really attached" );
116 m_attached = true;
80 emit device("hci0", true ); 117 emit device("hci0", true );
81 }else{ 118 }else{
119 qWarning( "failed" );
82 emit device("hci0", false ); 120 emit device("hci0", false );
83 m_attached = false; 121 m_attached = false;
84 } 122 }
@@ -89,16 +127,16 @@ void Device::slotExited( KProcess* proc)
89} 127}
90void Device::slotStdOut(KProcess* proc, char* chars, int len) 128void Device::slotStdOut(KProcess* proc, char* chars, int len)
91{ 129{
130 qWarning("std out" );
92 if( len <1 ) 131 if( len <1 )
93 return; 132 return;
94 if(proc == m_process ){ 133 if(proc == m_process ){
95 QCString string( chars, len+1 ); 134 QCString string( chars, len+1 ); // \0 == +1
96 if(string.left(3) != "CSR" ){ // it's the pid 135 qWarning("output: %s", string.data() );
97 pid = string.toInt(); 136 m_output.append( string.data() );
98 };
99 } 137 }
100} 138}
101void Device::slotStdErr(KProcess*, char*, int ) 139void Device::slotStdErr(KProcess*, char*, int )
102{ 140{
103 141 qWarning("std err" );
104} 142}