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.cc95
1 files changed, 50 insertions, 45 deletions
diff --git a/noncore/net/opietooth/lib/device.cc b/noncore/net/opietooth/lib/device.cc
index 04c50d9..f81066e 100644
--- a/noncore/net/opietooth/lib/device.cc
+++ b/noncore/net/opietooth/lib/device.cc
@@ -1,152 +1,157 @@
1 1
2#include <signal.h> 2#include "device.h"
3 3
4/* OPIE */
4#include <opie2/oprocess.h> 5#include <opie2/oprocess.h>
6#include <opie2/odebug.h>
7using namespace Opie::Core;
8
9/* STD */
10#include <signal.h>
5 11
6#include "device.h"
7 12
8using namespace OpieTooth; 13using namespace OpieTooth;
9 14
10using Opie::Core::OProcess; 15using Opie::Core::OProcess;
11namespace { 16namespace {
12 int parsePid( const QCString& par ){ 17 int parsePid( const QCString& par ){
13 int id=0; 18 int id=0;
14 QString string( par ); 19 QString string( par );
15 QStringList list = QStringList::split( '\n', string ); 20 QStringList list = QStringList::split( '\n', string );
16 for( QStringList::Iterator it = list.begin(); it != list.end(); ++it ){ 21 for( QStringList::Iterator it = list.begin(); it != list.end(); ++it ){
17 qWarning("parsePID: %s", (*it).latin1() ); 22 owarn << "parsePID: " << (*it).latin1() << oendl;
18 if( !(*it).startsWith("CSR") ){ 23 if( !(*it).startsWith("CSR") ){
19 id = (*it).toInt(); 24 id = (*it).toInt();
20 break; 25 break;
21 } 26 }
22 } 27 }
23 return id; 28 return id;
24 } 29 }
25} 30}
26 31
27Device::Device(const QString &device, const QString &mode, const QString &speed ) 32Device::Device(const QString &device, const QString &mode, const QString &speed )
28 : QObject(0, "device") { 33 : QObject(0, "device") {
29 34
30 qWarning("OpieTooth::Device create" ); 35 owarn << "OpieTooth::Device create" << oendl;
31 m_hci = 0; 36 m_hci = 0;
32 m_process = 0; 37 m_process = 0;
33 m_attached = false; 38 m_attached = false;
34 m_device = device; 39 m_device = device;
35 m_mode = mode; 40 m_mode = mode;
36 m_speed = speed; 41 m_speed = speed;
37 attach(); 42 attach();
38} 43}
39Device::~Device(){ 44Device::~Device(){
40 detach(); 45 detach();
41} 46}
42void Device::attach(){ 47void Device::attach(){
43 qWarning("attaching %s %s %s", m_device.latin1(), m_mode.latin1(), m_speed.latin1() ); 48 owarn << "attaching " << m_device.latin1() << " " << m_mode.latin1() << " " << m_speed.latin1() << oendl;
44 if(m_process == 0 ){ 49 if(m_process == 0 ){
45 m_output.resize(0); 50 m_output.resize(0);
46 qWarning("new process to create" ); 51 owarn << "new process to create" << oendl;
47 m_process = new OProcess(); 52 m_process = new OProcess();
48 *m_process << "hciattach"; 53 *m_process << "hciattach";
49 *m_process << "-p"; 54 *m_process << "-p";
50 *m_process << m_device << m_mode << m_speed; 55 *m_process << m_device << m_mode << m_speed;
51 connect(m_process, SIGNAL( processExited(Opie::Core::OProcess*) ), 56 connect(m_process, SIGNAL( processExited(Opie::Core::OProcess*) ),
52 this, SLOT( slotExited(Opie::Core::OProcess* ) ) ); 57 this, SLOT( slotExited(Opie::Core::OProcess* ) ) );
53 connect(m_process, SIGNAL( receivedStdout(Opie::Core::OProcess*, char*, int) ), 58 connect(m_process, SIGNAL( receivedStdout(Opie::Core::OProcess*, char*, int) ),
54 this, SLOT(slotStdOut(Opie::Core::OProcess*,char*,int ) ) ); 59 this, SLOT(slotStdOut(Opie::Core::OProcess*,char*,int ) ) );
55 connect(m_process, SIGNAL(receivedStderr(Opie::Core::OProcess*, char*, int ) ), 60 connect(m_process, SIGNAL(receivedStderr(Opie::Core::OProcess*, char*, int ) ),
56 this, SLOT(slotStdErr(Opie::Core::OProcess*,char*,int) ) ); 61 this, SLOT(slotStdErr(Opie::Core::OProcess*,char*,int) ) );
57 if(!m_process->start(OProcess::NotifyOnExit, OProcess::AllOutput ) ){ 62 if(!m_process->start(OProcess::NotifyOnExit, OProcess::AllOutput ) ){
58 qWarning("Could not start" ); 63 owarn << "Could not start" << oendl;
59 delete m_process; 64 delete m_process;
60 m_process = 0; 65 m_process = 0;
61 } 66 }
62 }; 67 };
63} 68}
64void Device::detach(){ 69void Device::detach(){
65 delete m_hci; 70 delete m_hci;
66 delete m_process; 71 delete m_process;
67 // kill the pid we got 72 // kill the pid we got
68 if(m_attached ){ 73 if(m_attached ){
69 //kill the pid 74 //kill the pid
70 qWarning( "killing" ); 75 warn << "killing" << oendl;
71 kill(pid, 9); 76 kill(pid, 9);
72 } 77 }
73 qWarning("detached" ); 78 owarn << "detached" << oendl;
74} 79}
75bool Device::isLoaded()const{ 80bool Device::isLoaded()const{
76 return m_attached; 81 return m_attached;
77} 82}
78QString Device::devName()const { 83QString Device::devName()const {
79 return QString::fromLatin1("hci0"); 84 return QString::fromLatin1("hci0");
80}; 85};
81void Device::slotExited( OProcess* proc) 86void Device::slotExited( OProcess* proc)
82{ 87{
83 qWarning("prcess exited" ); 88 owarn << "prcess exited" << oendl;
84 if(proc== m_process ){ 89 if(proc== m_process ){
85 qWarning("proc == m_process" ); 90 owarn << "proc == m_process" << oendl;
86 if( m_process->normalExit() ){ // normal exit 91 if( m_process->normalExit() ){ // normal exit
87 qWarning("normalExit" ); 92 owarn << "normalExit" << oendl;
88 int ret = m_process->exitStatus(); 93 int ret = m_process->exitStatus();
89 if( ret == 0 ){ // attached 94 if( ret == 0 ){ // attached
90 qWarning("attached" ); 95 owarn << "attached" << oendl;
91 qWarning("Output: %s", m_output.data() ); 96 owarn << "Output: " << m_output.data() << oendl;
92 pid = parsePid( m_output ); 97 pid = parsePid( m_output );
93 qWarning("Pid = %d", pid ); 98 owarn << "Pid = " << pid << oendl;
94 // now hciconfig hci0 up ( determine hciX FIXME) 99 // now hciconfig hci0 up ( determine hciX FIXME)
95 // and call hciconfig hci0 up 100 // and call hciconfig hci0 up
96 // FIXME hardcoded to hci0 now :( 101 // FIXME hardcoded to hci0 now :(
97 m_hci = new OProcess( ); 102 m_hci = new OProcess( );
98 *m_hci << "hciconfig"; 103 *m_hci << "hciconfig";
99 *m_hci << "hci0 up"; 104 *m_hci << "hci0 up";
100 connect(m_hci, SIGNAL( processExited(Opie::Core::OProcess*) ), 105 connect(m_hci, SIGNAL( processExited(Opie::Core::OProcess*) ),
101 this, SLOT( slotExited(Opie::Core::OProcess* ) ) ); 106 this, SLOT( slotExited(Opie::Core::OProcess* ) ) );
102 if(!m_hci->start() ){ 107 if(!m_hci->start() ){
103 qWarning("could not start" ); 108 owarn << "could not start" << oendl;
104 m_attached = false; 109 m_attached = false;
105 emit device("hci0", false ); 110 emit device("hci0", false );
106 } 111 }
107 }else{ 112 }else{
108 qWarning("crass" ); 113 owarn << "crass" << oendl;
109 m_attached = false; 114 m_attached = false;
110 emit device("hci0", false ); 115 emit device("hci0", false );
111 116
112 } 117 }
113 } 118 }
114 delete m_process; 119 delete m_process;
115 m_process = 0; 120 m_process = 0;
116 }else if(proc== m_hci ){ 121 }else if(proc== m_hci ){
117 qWarning("M HCI exited" ); 122 owarn << "M HCI exited" << oendl;
118 if( m_hci->normalExit() ){ 123 if( m_hci->normalExit() ){
119 qWarning("normal exit" ); 124 owarn << "normal exit" << oendl;
120 int ret = m_hci->exitStatus(); 125 int ret = m_hci->exitStatus();
121 if( ret == 0 ){ 126 if( ret == 0 ){
122 qWarning("attached really really attached" ); 127 owarn << "attached really really attached" << oendl;
123 m_attached = true; 128 m_attached = true;
124 emit device("hci0", true ); 129 emit device("hci0", true );
125 }else{ 130 }else{
126 qWarning( "failed" ); 131 owarn << "failed" << oendl;
127 emit device("hci0", false ); 132 emit device("hci0", false );
128 m_attached = false; 133 m_attached = false;
129 } 134 }
130 }// normal exit 135 }// normal exit
131 delete m_hci; 136 delete m_hci;
132 m_hci = 0; 137 m_hci = 0;
133 } 138 }
134} 139}
135void Device::slotStdOut(OProcess* proc, char* chars, int len) 140void Device::slotStdOut(OProcess* proc, char* chars, int len)
136{ 141{
137 qWarning("std out" ); 142 owarn << "std out" << oendl;
138 if( len <1 ){ 143 if( len <1 ){
139 qWarning( "len < 1 " ); 144 owarn << "len < 1 " << oendl;
140 return; 145 return;
141 } 146 }
142 if(proc == m_process ){ 147 if(proc == m_process ){
143 QCString string( chars, len+1 ); // \0 == +1 148 QCString string( chars, len+1 ); // \0 == +1
144 qWarning("output: %s", string.data() ); 149 owarn << "output: " << string.data() << oendl;
145 m_output.append( string.data() ); 150 m_output.append( string.data() );
146 } 151 }
147} 152}
148void Device::slotStdErr(OProcess* proc, char* chars, int len) 153void Device::slotStdErr(OProcess* proc, char* chars, int len)
149{ 154{
150 qWarning("std err" ); 155 owarn << "std err" << oendl;
151 slotStdOut( proc, chars, len ); 156 slotStdOut( proc, chars, len );
152} 157}