author | zecke <zecke> | 2002-06-01 12:36:34 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-06-01 12:36:34 (UTC) |
commit | f386b95e1c9763bb9c5ea404c0824b45a744e151 (patch) (unidiff) | |
tree | fb64a35e3824e3b50b93b1289a0feed50a1d3b5f | |
parent | 075f2ae74f328581ec0db05d633961f3baa5ed36 (diff) | |
download | opie-f386b95e1c9763bb9c5ea404c0824b45a744e151.zip opie-f386b95e1c9763bb9c5ea404c0824b45a744e151.tar.gz opie-f386b95e1c9763bb9c5ea404c0824b45a744e151.tar.bz2 |
attaching and detaching
-rw-r--r-- | noncore/net/opietooth/lib/device.cc | 90 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/device.h | 17 |
2 files changed, 101 insertions, 6 deletions
diff --git a/noncore/net/opietooth/lib/device.cc b/noncore/net/opietooth/lib/device.cc index b567e2b..0c552ea 100644 --- a/noncore/net/opietooth/lib/device.cc +++ b/noncore/net/opietooth/lib/device.cc | |||
@@ -1,2 +1,4 @@ | |||
1 | 1 | ||
2 | #include "kprocess.h" | ||
3 | |||
2 | #include "device.h" | 4 | #include "device.h" |
@@ -6,16 +8,41 @@ using namespace OpieTooth; | |||
6 | Device::Device(const QString &device, const QString &mode ) | 8 | Device::Device(const QString &device, const QString &mode ) |
7 | : QObject(0, "device" ){ | 9 | : QObject(0, "device" ) { |
8 | 10 | m_hci = 0; | |
11 | m_process = 0; | ||
12 | m_attached = false; | ||
13 | m_device = device; | ||
14 | m_mode = mode; | ||
15 | attach(); | ||
9 | } | 16 | } |
10 | Device::~Device(){ | 17 | Device::~Device(){ |
11 | 18 | detach(); | |
12 | } | 19 | } |
13 | void Device::attach(){ | 20 | void Device::attach(){ |
14 | 21 | if(m_process != 0 ){ | |
22 | m_process = new KProcess(); | ||
23 | *m_process << "hciattach"; | ||
24 | *m_process << "-p"; | ||
25 | *m_process << m_device << m_mode; | ||
26 | connect(m_process, SIGNAL( processExited(KProcess*) ), | ||
27 | this, SLOT( slotExited(KProcess* ) ) ); | ||
28 | connect(m_process, SIGNAL( receivedStdout(KProcess*, char*, int) ), | ||
29 | this, SLOT(slotStdOut(KProcess*,char*,int ) ) ); | ||
30 | connect(m_process, SIGNAL(receivedStderr(KProcess*, char*, int ) ), | ||
31 | this, SLOT(slotStdErr(KProcess*,char*,int) ) ); | ||
32 | if(!m_process->start(KProcess::NotifyOnExit, KProcess::AllOutput ) ){ | ||
33 | delete m_process; | ||
34 | m_process = 0; | ||
35 | } | ||
36 | }; | ||
15 | } | 37 | } |
16 | void Device::detach(){ | 38 | void Device::detach(){ |
17 | 39 | delete m_hci; | |
40 | delete m_process; | ||
41 | // kill the pid we got | ||
42 | if(m_attached ) | ||
43 | //kill the pid | ||
44 | ; | ||
18 | } | 45 | } |
19 | bool Device::isLoaded()const{ | 46 | bool Device::isLoaded()const{ |
20 | return false; | 47 | return m_attached; |
21 | } | 48 | } |
@@ -24 +51,52 @@ QString Device::devName()const { | |||
24 | }; | 51 | }; |
52 | void Device::slotExited( KProcess* proc) | ||
53 | { | ||
54 | if(proc== m_process ){ | ||
55 | if( m_process->normalExit() ){ // normal exit | ||
56 | int ret = m_process->exitStatus(); | ||
57 | if( ret == 0 ){ // attached | ||
58 | // now hciconfig hci0 up ( determine hciX FIXME) | ||
59 | // and call hciconfig hci0 up | ||
60 | // FIXME hardcoded to hci0 now :( | ||
61 | m_hci = new KProcess( ); | ||
62 | *m_hci << "hciconfig"; | ||
63 | *m_hci << "hci0 up"; | ||
64 | connect(m_hci, SIGNAL( processExited(KProcess*) ), | ||
65 | this, SLOT( slotExited(KProcess* ) ) ); | ||
66 | }else{ | ||
67 | m_attached = false; | ||
68 | emit device("hci0", false ); | ||
69 | |||
70 | } | ||
71 | } | ||
72 | delete m_process; | ||
73 | m_process = 0; | ||
74 | }else if(proc== m_hci ){ | ||
75 | if( m_hci->normalExit() ){ | ||
76 | int ret = m_hci->normalExit(); | ||
77 | if( ret == 0 ){ | ||
78 | emit device("hci0", true ); | ||
79 | }else{ | ||
80 | emit device("hci0", false ); | ||
81 | m_attached = false; | ||
82 | } | ||
83 | }// normal exit | ||
84 | delete m_hci; | ||
85 | m_hci = 0; | ||
86 | } | ||
87 | } | ||
88 | void Device::slotStdOut(KProcess* proc, char* chars, int len) | ||
89 | { | ||
90 | if( len <1 ) | ||
91 | return; | ||
92 | if(proc == m_process ){ | ||
93 | QCString string( chars ); | ||
94 | if(string.left(3) != "CSR" ){ // it's the pid | ||
95 | pid = string.toInt(); | ||
96 | }; | ||
97 | } | ||
98 | } | ||
99 | void Device::slotStdErr(KProcess*, char*, int ) | ||
100 | { | ||
101 | |||
102 | } | ||
diff --git a/noncore/net/opietooth/lib/device.h b/noncore/net/opietooth/lib/device.h index d23f24c..010db40 100644 --- a/noncore/net/opietooth/lib/device.h +++ b/noncore/net/opietooth/lib/device.h | |||
@@ -8,2 +8,5 @@ | |||
8 | 8 | ||
9 | #include <sys/types.h> | ||
10 | |||
11 | class KProcess; | ||
9 | namespace OpieTooth { | 12 | namespace OpieTooth { |
@@ -63,2 +66,16 @@ namespace OpieTooth { | |||
63 | void device(const QString& device, bool up ); | 66 | void device(const QString& device, bool up ); |
67 | private slots: | ||
68 | virtual void slotExited( KProcess* ); | ||
69 | virtual void slotStdOut(KProcess*, char*, int ); | ||
70 | virtual void slotStdErr(KProcess*, char*, int ); | ||
71 | private: | ||
72 | class Private; | ||
73 | Private *d; | ||
74 | QString m_device; | ||
75 | bool m_attached:1; | ||
76 | KProcess* m_hci; | ||
77 | KProcess* m_process; | ||
78 | QString m_devId; | ||
79 | QString m_mode; | ||
80 | pid_t pid; | ||
64 | }; | 81 | }; |