author | korovkin <korovkin> | 2006-05-10 13:32:46 (UTC) |
---|---|---|
committer | korovkin <korovkin> | 2006-05-10 13:32:46 (UTC) |
commit | 5521b2c0508cf6e6a390bd4796e8c9f2c7a6d05f (patch) (unidiff) | |
tree | e9ea63a2fe15982e98886af727649dc6a513faac /noncore/net/opietooth/lib/device.cc | |
parent | 620d55ae3b94fa8d2fa696b6626893e4520c3a02 (diff) | |
download | opie-5521b2c0508cf6e6a390bd4796e8c9f2c7a6d05f.zip opie-5521b2c0508cf6e6a390bd4796e8c9f2c7a6d05f.tar.gz opie-5521b2c0508cf6e6a390bd4796e8c9f2c7a6d05f.tar.bz2 |
OBEX push functionality moved to libbluetooth1.
Made some reformatting in device.cc
In bluezapplet.cpp /etc/init.d/bluetooth is started synchronously if it's called from QCopMessage.
Diffstat (limited to 'noncore/net/opietooth/lib/device.cc') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/opietooth/lib/device.cc | 108 |
1 files changed, 52 insertions, 56 deletions
diff --git a/noncore/net/opietooth/lib/device.cc b/noncore/net/opietooth/lib/device.cc index 40acbd2..2f04d46 100644 --- a/noncore/net/opietooth/lib/device.cc +++ b/noncore/net/opietooth/lib/device.cc | |||
@@ -1,186 +1,182 @@ | |||
1 | 1 | ||
2 | #include "device.h" | 2 | #include "device.h" |
3 | 3 | ||
4 | /* OPIE */ | 4 | /* OPIE */ |
5 | #include <opie2/oprocess.h> | 5 | #include <opie2/oprocess.h> |
6 | #include <opie2/odebug.h> | 6 | #include <opie2/odebug.h> |
7 | #include <opie2/odevice.h> | 7 | #include <opie2/odevice.h> |
8 | 8 | ||
9 | using namespace Opie::Core; | 9 | using namespace Opie::Core; |
10 | 10 | ||
11 | /* STD */ | 11 | /* STD */ |
12 | #include <signal.h> | 12 | #include <signal.h> |
13 | 13 | ||
14 | 14 | ||
15 | using namespace OpieTooth; | 15 | using namespace OpieTooth; |
16 | 16 | ||
17 | using Opie::Core::OProcess; | 17 | using Opie::Core::OProcess; |
18 | namespace { | 18 | namespace { |
19 | int parsePid( const QCString& par ) | 19 | int parsePid( const QCString& par ) |
20 | { | 20 | { |
21 | int id=0; | 21 | int id = 0; |
22 | QString string( par ); | 22 | QString string( par ); |
23 | QStringList list = QStringList::split( '\n', string ); | 23 | QStringList list = QStringList::split( '\n', string ); |
24 | 24 | ||
25 | for( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) | 25 | for( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { |
26 | { | 26 | owarn << "parsePID: " << (*it).latin1() << oendl; |
27 | owarn << "parsePID: " << (*it).latin1() << oendl; | ||
28 | 27 | ||
29 | // FIXME mbhaynie: Surely there is a better way to skip | 28 | // FIXME mbhaynie: Surely there is a better way to skip |
30 | // verbosity (E.g. the TI device configuration | 29 | // verbosity (E.g. the TI device configuration |
31 | // script). Apparently the PID is always on a line by | 30 | // script). Apparently the PID is always on a line by |
32 | // itself, or is at least the first word of a line. Does | 31 | // itself, or is at least the first word of a line. Does |
33 | // QString have somethine like startsWithRegex("[0-9]+")? | 32 | // QString have somethine like startsWithRegex("[0-9]+")? |
34 | if( (*it).startsWith("#") ) continue; | 33 | if( (*it).startsWith("#") ) continue; |
35 | if( (*it).startsWith("TI") ) continue; | 34 | if( (*it).startsWith("TI") ) continue; |
36 | if( (*it).startsWith("Loading") ) continue; | 35 | if( (*it).startsWith("Loading") ) continue; |
37 | if( (*it).startsWith("BTS") ) continue; | 36 | if( (*it).startsWith("BTS") ) continue; |
38 | if( !(*it).startsWith("CSR") ) | 37 | if( !(*it).startsWith("CSR") ) { |
39 | { | 38 | id = (*it).toInt(); |
40 | id = (*it).toInt(); | 39 | break; |
41 | break; | 40 | } |
42 | } | ||
43 | } | ||
44 | return id; | ||
45 | } | 41 | } |
42 | return id; | ||
43 | } | ||
46 | } | 44 | } |
47 | 45 | ||
48 | Device::Device(const QString &device, const QString &mode, const QString &speed ) | 46 | Device::Device(const QString &device, const QString &mode, const QString &speed ) |
49 | : QObject(0, "device") { | 47 | : QObject(0, "device") { |
50 | 48 | ||
51 | owarn << "OpieTooth::Device create" << oendl; | 49 | owarn << "OpieTooth::Device create" << oendl; |
52 | m_hci = 0; | 50 | m_hci = 0; |
53 | m_process = 0; | 51 | m_process = 0; |
54 | m_attached = false; | 52 | m_attached = false; |
55 | m_device = device; | 53 | m_device = device; |
56 | m_mode = mode; | 54 | m_mode = mode; |
57 | m_speed = speed; | 55 | m_speed = speed; |
58 | attach(); | 56 | attach(); |
59 | } | 57 | } |
60 | Device::~Device(){ | 58 | Device::~Device(){ |
61 | detach(); | 59 | detach(); |
62 | } | 60 | } |
63 | 61 | ||
64 | // FIXME mbhaynie -- If BT is active, and opie is restarted, this | 62 | // FIXME mbhaynie -- If BT is active, and opie is restarted, this |
65 | // applet thinks bt is down, and will fail to start it again. Not | 63 | // applet thinks bt is down, and will fail to start it again. Not |
66 | // sure why. | 64 | // sure why. |
67 | void Device::attach(){ | 65 | void Device::attach(){ |
68 | owarn << "attaching " << m_device.latin1() << " " << m_mode.latin1() << " " << m_speed.latin1() << oendl; | 66 | owarn << "attaching " << m_device.latin1() << " " << m_mode.latin1() << " " << m_speed.latin1() << oendl; |
69 | if(m_process == 0 ){ | 67 | if(m_process == 0 ){ |
70 | m_output.resize(0); | 68 | m_output.resize(0); |
71 | owarn << "new process to create" << oendl; | 69 | owarn << "new process to create" << oendl; |
72 | m_process = new OProcess(); | 70 | m_process = new OProcess(); |
73 | *m_process << "hciattach"; | 71 | *m_process << "hciattach"; |
74 | *m_process << "-p"; | 72 | *m_process << "-p"; |
75 | 73 | ||
76 | // FIXME -- this is a hack for an odd hciattach interface. | 74 | // FIXME -- this is a hack for an odd hciattach interface. |
77 | if ( ODevice::inst()->modelString() == "HX4700" ) | 75 | if ( ODevice::inst()->modelString() == "HX4700" ) |
78 | { | 76 | *m_process << "-S" << "/etc/bluetooth/TIInit_3.2.26.bts" << "/dev/ttyS1" << "texas"; |
79 | *m_process << "-S" << "/etc/bluetooth/TIInit_3.2.26.bts" << "/dev/ttyS1" << "texas"; | ||
80 | } | ||
81 | else | 77 | else |
82 | { | 78 | *m_process << m_device << m_mode << m_speed; |
83 | *m_process << m_device << m_mode << m_speed; | ||
84 | } | ||
85 | connect(m_process, SIGNAL( processExited(Opie::Core::OProcess*) ), | 79 | connect(m_process, SIGNAL( processExited(Opie::Core::OProcess*) ), |
86 | this, SLOT( slotExited(Opie::Core::OProcess* ) ) ); | 80 | this, SLOT( slotExited(Opie::Core::OProcess* ) ) ); |
87 | connect(m_process, SIGNAL( receivedStdout(Opie::Core::OProcess*, char*, int) ), | 81 | connect(m_process, SIGNAL( receivedStdout(Opie::Core::OProcess*, char*, int) ), |
88 | this, SLOT(slotStdOut(Opie::Core::OProcess*,char*,int ) ) ); | 82 | this, SLOT(slotStdOut(Opie::Core::OProcess*,char*,int ) ) ); |
89 | connect(m_process, SIGNAL(receivedStderr(Opie::Core::OProcess*, char*, int ) ), | 83 | connect(m_process, SIGNAL(receivedStderr(Opie::Core::OProcess*, char*, int ) ), |
90 | this, SLOT(slotStdErr(Opie::Core::OProcess*,char*,int) ) ); | 84 | this, SLOT(slotStdErr(Opie::Core::OProcess*,char*,int) ) ); |
91 | if(!m_process->start(OProcess::NotifyOnExit, OProcess::AllOutput ) ){ | 85 | if(!m_process->start(OProcess::NotifyOnExit, OProcess::AllOutput ) ){ |
92 | owarn << "Could not start" << oendl; | 86 | owarn << "Could not start" << oendl; |
93 | delete m_process; | 87 | delete m_process; |
94 | m_process = 0; | 88 | m_process = 0; |
95 | } | 89 | } |
96 | }; | 90 | } |
97 | } | 91 | } |
98 | void Device::detach(){ | 92 | void Device::detach(){ |
99 | delete m_hci; | 93 | delete m_hci; |
94 | m_hci = 0; | ||
100 | delete m_process; | 95 | delete m_process; |
96 | m_process = 0; | ||
101 | // kill the pid we got | 97 | // kill the pid we got |
102 | if(m_attached ){ | 98 | if(m_attached ){ |
103 | //kill the pid | 99 | //kill the pid |
104 | owarn << "killing" << oendl; | 100 | owarn << "killing" << oendl; |
105 | kill(pid, 9); | 101 | ::kill(pid, 9); |
106 | } | 102 | } |
107 | owarn << "detached" << oendl; | 103 | owarn << "detached" << oendl; |
108 | } | 104 | } |
109 | bool Device::isLoaded()const{ | 105 | bool Device::isLoaded()const{ |
110 | return m_attached; | 106 | return m_attached; |
111 | } | 107 | } |
112 | QString Device::devName()const { | 108 | QString Device::devName()const { |
113 | return QString::fromLatin1("hci0"); | 109 | return QString::fromLatin1("hci0"); |
114 | }; | 110 | }; |
115 | void Device::slotExited( OProcess* proc) | 111 | void Device::slotExited( OProcess* proc) |
116 | { | 112 | { |
117 | owarn << "prcess exited" << oendl; | 113 | owarn << "prcess exited" << oendl; |
118 | if(proc== m_process ){ | 114 | if(proc== m_process ){ |
119 | owarn << "proc == m_process" << oendl; | 115 | owarn << "proc == m_process" << oendl; |
120 | if( m_process->normalExit() ){ // normal exit | 116 | if( m_process->normalExit() ){ // normal exit |
121 | owarn << "normalExit" << oendl; | 117 | owarn << "normalExit" << oendl; |
122 | int ret = m_process->exitStatus(); | 118 | int ret = m_process->exitStatus(); |
123 | if( ret == 0 ){ // attached | 119 | if( ret == 0 ){ // attached |
124 | owarn << "attached" << oendl; | 120 | owarn << "attached" << oendl; |
125 | owarn << "Output: " << m_output.data() << oendl; | 121 | owarn << "Output: " << m_output.data() << oendl; |
126 | pid = parsePid( m_output ); | 122 | pid = parsePid( m_output ); |
127 | owarn << "Pid = " << pid << oendl; | 123 | owarn << "Pid = " << pid << oendl; |
128 | // now hciconfig hci0 up ( determine hciX FIXME) | 124 | // now hciconfig hci0 up ( determine hciX FIXME) |
129 | // and call hciconfig hci0 up | 125 | // and call hciconfig hci0 up |
130 | // FIXME hardcoded to hci0 now :( | 126 | // FIXME hardcoded to hci0 now :( |
131 | m_hci = new OProcess( ); | 127 | m_hci = new OProcess( ); |
132 | *m_hci << "hciconfig"; | 128 | *m_hci << "hciconfig"; |
133 | *m_hci << "hci0 up"; | 129 | *m_hci << "hci0 up"; |
134 | connect(m_hci, SIGNAL( processExited(Opie::Core::OProcess*) ), | 130 | connect(m_hci, SIGNAL( processExited(Opie::Core::OProcess*) ), |
135 | this, SLOT( slotExited(Opie::Core::OProcess* ) ) ); | 131 | this, SLOT( slotExited(Opie::Core::OProcess* ) ) ); |
136 | if(!m_hci->start() ){ | 132 | if(!m_hci->start() ){ |
137 | owarn << "could not start" << oendl; | 133 | owarn << "could not start" << oendl; |
138 | m_attached = false; | 134 | m_attached = false; |
139 | emit device("hci0", false ); | 135 | emit device("hci0", false ); |
140 | } | 136 | } |
141 | }else{ | 137 | }else{ |
142 | owarn << "crass" << oendl; | 138 | owarn << "crass" << oendl; |
143 | m_attached = false; | 139 | m_attached = false; |
144 | emit device("hci0", false ); | 140 | emit device("hci0", false ); |
145 | 141 | ||
146 | } | 142 | } |
147 | } | 143 | } |
148 | delete m_process; | 144 | delete m_process; |
149 | m_process = 0; | 145 | m_process = 0; |
150 | }else if(proc== m_hci ){ | 146 | }else if(proc== m_hci ){ |
151 | owarn << "M HCI exited" << oendl; | 147 | owarn << "M HCI exited" << oendl; |
152 | if( m_hci->normalExit() ){ | 148 | if( m_hci->normalExit() ){ |
153 | owarn << "normal exit" << oendl; | 149 | owarn << "normal exit" << oendl; |
154 | int ret = m_hci->exitStatus(); | 150 | int ret = m_hci->exitStatus(); |
155 | if( ret == 0 ){ | 151 | if( ret == 0 ){ |
156 | owarn << "attached really really attached" << oendl; | 152 | owarn << "attached really really attached" << oendl; |
157 | m_attached = true; | 153 | m_attached = true; |
158 | emit device("hci0", true ); | 154 | emit device("hci0", true ); |
159 | }else{ | 155 | }else{ |
160 | owarn << "failed" << oendl; | 156 | owarn << "failed" << oendl; |
161 | emit device("hci0", false ); | 157 | emit device("hci0", false ); |
162 | m_attached = false; | 158 | m_attached = false; |
163 | } | 159 | } |
164 | }// normal exit | 160 | }// normal exit |
165 | delete m_hci; | 161 | delete m_hci; |
166 | m_hci = 0; | 162 | m_hci = 0; |
167 | } | 163 | } |
168 | } | 164 | } |
169 | void Device::slotStdOut(OProcess* proc, char* chars, int len) | 165 | void Device::slotStdOut(OProcess* proc, char* chars, int len) |
170 | { | 166 | { |
171 | owarn << "std out" << oendl; | 167 | owarn << "std out" << oendl; |
172 | if( len <1 ){ | 168 | if( len <1 ){ |
173 | owarn << "len < 1 " << oendl; | 169 | owarn << "len < 1 " << oendl; |
174 | return; | 170 | return; |
175 | } | 171 | } |
176 | if(proc == m_process ){ | 172 | if(proc == m_process ){ |
177 | QCString string( chars, len+1 ); // \0 == +1 | 173 | QCString string( chars, len+1 ); // \0 == +1 |
178 | owarn << "output: " << string.data() << oendl; | 174 | owarn << "output: " << string.data() << oendl; |
179 | m_output.append( string.data() ); | 175 | m_output.append( string.data() ); |
180 | } | 176 | } |
181 | } | 177 | } |
182 | void Device::slotStdErr(OProcess* proc, char* chars, int len) | 178 | void Device::slotStdErr(OProcess* proc, char* chars, int len) |
183 | { | 179 | { |
184 | owarn << "std err" << oendl; | 180 | owarn << "std err" << oendl; |
185 | slotStdOut( proc, chars, len ); | 181 | slotStdOut( proc, chars, len ); |
186 | } | 182 | } |