summaryrefslogtreecommitdiff
authorharlekin <harlekin>2003-01-16 19:50:06 (UTC)
committer harlekin <harlekin>2003-01-16 19:50:06 (UTC)
commit7957a2f100eb687e63cd3593097c5914539c7406 (patch) (unidiff)
tree323aaf6d34669f523532d41385560c3894ed5c59
parenteac64456fb43afe2200e4e545e1e4be3b4eb1bc8 (diff)
downloadopie-7957a2f100eb687e63cd3593097c5914539c7406.zip
opie-7957a2f100eb687e63cd3593097c5914539c7406.tar.gz
opie-7957a2f100eb687e63cd3593097c5914539c7406.tar.bz2
lib a bit more flexible for hciattach arguments
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opietooth/lib/device.cc12
-rw-r--r--noncore/net/opietooth/lib/device.h9
2 files changed, 13 insertions, 8 deletions
diff --git a/noncore/net/opietooth/lib/device.cc b/noncore/net/opietooth/lib/device.cc
index 5edfc03..bae1c47 100644
--- a/noncore/net/opietooth/lib/device.cc
+++ b/noncore/net/opietooth/lib/device.cc
@@ -2,70 +2,72 @@
2#include <signal.h> 2#include <signal.h>
3 3
4#include <opie/oprocess.h> 4#include <opie/oprocess.h>
5 5
6#include "device.h" 6#include "device.h"
7 7
8using namespace OpieTooth; 8using namespace OpieTooth;
9 9
10namespace { 10namespace {
11 int parsePid( const QCString& par ){ 11 int parsePid( const QCString& par ){
12 int id=0; 12 int id=0;
13 QString string( par ); 13 QString string( par );
14 QStringList list = QStringList::split( '\n', string ); 14 QStringList list = QStringList::split( '\n', string );
15 for( QStringList::Iterator it = list.begin(); it != list.end(); ++it ){ 15 for( QStringList::Iterator it = list.begin(); it != list.end(); ++it ){
16 qWarning("parsePID: %s", (*it).latin1() ); 16 qWarning("parsePID: %s", (*it).latin1() );
17 if( !(*it).startsWith("CSR") ){ 17 if( !(*it).startsWith("CSR") ){
18 id = (*it).toInt(); 18 id = (*it).toInt();
19 break; 19 break;
20 } 20 }
21 } 21 }
22 return id; 22 return id;
23 } 23 }
24} 24}
25 25
26Device::Device(const QString &device, const QString &mode ) 26Device::Device(const QString &device, const QString &mode, const QString &speed )
27 : QObject(0, "device" ) { 27 : QObject(0, "device") {
28
28 qWarning("OpieTooth::Device create" ); 29 qWarning("OpieTooth::Device create" );
29 m_hci = 0; 30 m_hci = 0;
30 m_process = 0; 31 m_process = 0;
31 m_attached = false; 32 m_attached = false;
32 m_device = device; 33 m_device = device;
33 m_mode = mode; 34 m_mode = mode;
35 m_speed = speed;
34 attach(); 36 attach();
35} 37}
36Device::~Device(){ 38Device::~Device(){
37 detach(); 39 detach();
38} 40}
39void Device::attach(){ 41void Device::attach(){
40 qWarning("attaching %s %s", m_device.latin1(), m_mode.latin1() ); 42 qWarning("attaching %s %s %s", m_device.latin1(), m_mode.latin1(), m_speed.latin1() );
41 if(m_process == 0 ){ 43 if(m_process == 0 ){
42 m_output.resize(0); 44 m_output.resize(0);
43 qWarning("new process to create" ); 45 qWarning("new process to create" );
44 m_process = new OProcess(); 46 m_process = new OProcess();
45 *m_process << "hciattach"; 47 *m_process << "hciattach";
46 *m_process << "-p"; 48 *m_process << "-p";
47 *m_process << m_device << m_mode; 49 *m_process << m_device << m_mode << m_speed;
48 connect(m_process, SIGNAL( processExited(OProcess*) ), 50 connect(m_process, SIGNAL( processExited(OProcess*) ),
49 this, SLOT( slotExited(OProcess* ) ) ); 51 this, SLOT( slotExited(OProcess* ) ) );
50 connect(m_process, SIGNAL( receivedStdout(OProcess*, char*, int) ), 52 connect(m_process, SIGNAL( receivedStdout(OProcess*, char*, int) ),
51 this, SLOT(slotStdOut(OProcess*,char*,int ) ) ); 53 this, SLOT(slotStdOut(OProcess*,char*,int ) ) );
52 connect(m_process, SIGNAL(receivedStderr(OProcess*, char*, int ) ), 54 connect(m_process, SIGNAL(receivedStderr(OProcess*, char*, int ) ),
53 this, SLOT(slotStdErr(OProcess*,char*,int) ) ); 55 this, SLOT(slotStdErr(OProcess*,char*,int) ) );
54 if(!m_process->start(OProcess::NotifyOnExit, OProcess::AllOutput ) ){ 56 if(!m_process->start(OProcess::NotifyOnExit, OProcess::AllOutput ) ){
55 qWarning("Could not start" ); 57 qWarning("Could not start" );
56 delete m_process; 58 delete m_process;
57 m_process = 0; 59 m_process = 0;
58 } 60 }
59 }; 61 };
60} 62}
61void Device::detach(){ 63void Device::detach(){
62 delete m_hci; 64 delete m_hci;
63 delete m_process; 65 delete m_process;
64 // kill the pid we got 66 // kill the pid we got
65 if(m_attached ){ 67 if(m_attached ){
66 //kill the pid 68 //kill the pid
67 qWarning( "killing" ); 69 qWarning( "killing" );
68 kill(pid, 9); 70 kill(pid, 9);
69 } 71 }
70 qWarning("detached" ); 72 qWarning("detached" );
71} 73}
@@ -113,37 +115,37 @@ void Device::slotExited( OProcess* proc)
113 }else if(proc== m_hci ){ 115 }else if(proc== m_hci ){
114 qWarning("M HCI exited" ); 116 qWarning("M HCI exited" );
115 if( m_hci->normalExit() ){ 117 if( m_hci->normalExit() ){
116 qWarning("normal exit" ); 118 qWarning("normal exit" );
117 int ret = m_hci->exitStatus(); 119 int ret = m_hci->exitStatus();
118 if( ret == 0 ){ 120 if( ret == 0 ){
119 qWarning("attached really really attached" ); 121 qWarning("attached really really attached" );
120 m_attached = true; 122 m_attached = true;
121 emit device("hci0", true ); 123 emit device("hci0", true );
122 }else{ 124 }else{
123 qWarning( "failed" ); 125 qWarning( "failed" );
124 emit device("hci0", false ); 126 emit device("hci0", false );
125 m_attached = false; 127 m_attached = false;
126 } 128 }
127 }// normal exit 129 }// normal exit
128 delete m_hci; 130 delete m_hci;
129 m_hci = 0; 131 m_hci = 0;
130 } 132 }
131} 133}
132void Device::slotStdOut(OProcess* proc, char* chars, int len) 134void Device::slotStdOut(OProcess* proc, char* chars, int len)
133{ 135{
134 qWarning("std out" ); 136 qWarning("std out" );
135 if( len <1 ){ 137 if( len <1 ){
136 qWarning( "len < 1 " ); 138 qWarning( "len < 1 " );
137 return; 139 return;
138 } 140 }
139 if(proc == m_process ){ 141 if(proc == m_process ){
140 QCString string( chars, len+1 ); // \0 == +1 142 QCString string( chars, len+1 ); // \0 == +1
141 qWarning("output: %s", string.data() ); 143 qWarning("output: %s", string.data() );
142 m_output.append( string.data() ); 144 m_output.append( string.data() );
143 } 145 }
144} 146}
145void Device::slotStdErr(OProcess* proc, char* chars, int len) 147void Device::slotStdErr(OProcess* proc, char* chars, int len)
146{ 148{
147 qWarning("std err" ); 149 qWarning("std err" );
148 slotStdOut( proc, chars, len ); 150 slotStdOut( proc, chars, len );
149} 151}
diff --git a/noncore/net/opietooth/lib/device.h b/noncore/net/opietooth/lib/device.h
index c0e2658..ce7fccc 100644
--- a/noncore/net/opietooth/lib/device.h
+++ b/noncore/net/opietooth/lib/device.h
@@ -1,54 +1,56 @@
1 1
2#ifndef OpieToothDevice_H 2#ifndef OpieToothDevice_H
3#define OpieToothDevice_H 3#define OpieToothDevice_H
4 4
5#include <qobject.h> 5#include <qobject.h>
6#include <qstring.h> 6#include <qstring.h>
7#include <qvaluelist.h> 7#include <qvaluelist.h>
8 8
9#include <sys/types.h> 9#include <sys/types.h>
10 10
11class OProcess; 11class OProcess;
12namespace OpieTooth { 12namespace OpieTooth {
13 /** 13 /**
14 * Device takes care of attaching serial 14 * Device takes care of attaching serial
15 * devices to the blueZ stack. 15 * devices to the blueZ stack.
16 * After attaching it hciconfig ups it 16 * After attaching it hciconfig ups it
17 */ 17 */
18 class Device : public QObject { 18 class Device : public QObject {
19 Q_OBJECT 19
20 Q_OBJECT
20 21
21 public: 22 public:
22 23
23 /** 24 /**
24 * Brings up an device. 25 * Brings up an device.
25 * Usage example: new Device(/dev/ttySB0, csr) 26 * Usage example: new Device(/dev/ttySB0, csr)
26 * 27 *
27 * @param &device QString the device name 28 * @param &device QString the device name
28 * @param &mode QString the mode 29 * @param &mode QString the mode
30 * @param &speed QString the speed of the device, can be left blank
29 */ 31 */
30 Device(const QString &device, const QString& mode); 32 Device(const QString &device, const QString& mode, const QString& speed);
31 33
32 /** 34 /**
33 * unloads the device 35 * unloads the device
34 */ 36 */
35 ~Device(); 37 ~Device();
36 38
37 /** 39 /**
38 * attach the device 40 * attach the device
39 */ 41 */
40 void attach(); 42 void attach();
41 43
42 /** 44 /**
43 * detach the device 45 * detach the device
44 */ 46 */
45 void detach(); 47 void detach();
46 48
47 /** 49 /**
48 * Is the device loaded? 50 * Is the device loaded?
49 * @return bool, if the device is loaded 51 * @return bool, if the device is loaded
50 */ 52 */
51 bool isLoaded()const; 53 bool isLoaded()const;
52 54
53 /** 55 /**
54 * Returns the device name 56 * Returns the device name
@@ -56,30 +58,31 @@ namespace OpieTooth {
56 */ 58 */
57 QString devName()const ; // hci0 59 QString devName()const ; // hci0
58 60
59 signals: 61 signals:
60 62
61 /** 63 /**
62 * Signals devicename and up status 64 * Signals devicename and up status
63 * @return &device QString, Devicename 65 * @return &device QString, Devicename
64 * @return up bool, if the device is up or not. 66 * @return up bool, if the device is up or not.
65 */ 67 */
66 void device(const QString& device, bool up ); 68 void device(const QString& device, bool up );
67 private slots: 69 private slots:
68 virtual void slotExited( OProcess* ); 70 virtual void slotExited( OProcess* );
69 virtual void slotStdOut(OProcess*, char*, int ); 71 virtual void slotStdOut(OProcess*, char*, int );
70 virtual void slotStdErr(OProcess*, char*, int ); 72 virtual void slotStdErr(OProcess*, char*, int );
71 private: 73 private:
72 class Private; 74 class Private;
73 Private *d; 75 Private *d;
74 QString m_device; 76 QString m_device;
75 bool m_attached:1; 77 bool m_attached:1;
76 OProcess* m_hci; 78 OProcess* m_hci;
77 OProcess* m_process; 79 OProcess* m_process;
78 QString m_devId; 80 QString m_devId;
79 QString m_mode; 81 QString m_mode;
82 QString m_speed;
80 pid_t pid; 83 pid_t pid;
81 QCString m_output; 84 QCString m_output;
82 }; 85 };
83}; 86};
84 87
85#endif 88#endif