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