-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,24 +1,102 @@ | |||
1 | 1 | ||
2 | #include "kprocess.h" | ||
3 | |||
2 | #include "device.h" | 4 | #include "device.h" |
3 | 5 | ||
4 | using namespace OpieTooth; | 6 | using namespace OpieTooth; |
5 | 7 | ||
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 | } |
22 | QString Device::devName()const { | 49 | QString Device::devName()const { |
23 | return QString::fromLatin1("hci0"); | 50 | return QString::fromLatin1("hci0"); |
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 | |||
@@ -1,67 +1,84 @@ | |||
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> | ||
10 | |||
11 | class KProcess; | ||
9 | namespace OpieTooth { | 12 | namespace OpieTooth { |
10 | /** | 13 | /** |
11 | * Device takes care of attaching serial | 14 | * Device takes care of attaching serial |
12 | * devices to the blueZ stack. | 15 | * devices to the blueZ stack. |
13 | * After attaching it hciconfig ups it | 16 | * After attaching it hciconfig ups it |
14 | */ | 17 | */ |
15 | class Device : public QObject { | 18 | class Device : public QObject { |
16 | Q_OBJECT | 19 | Q_OBJECT |
17 | 20 | ||
18 | public: | 21 | public: |
19 | 22 | ||
20 | /** | 23 | /** |
21 | * Brings up an device. | 24 | * Brings up an device. |
22 | * Usage example: new Device(/dev/ttySB0, csr) | 25 | * Usage example: new Device(/dev/ttySB0, csr) |
23 | * | 26 | * |
24 | * @param &device QString the device name | 27 | * @param &device QString the device name |
25 | * @param &mode QString the mode | 28 | * @param &mode QString the mode |
26 | */ | 29 | */ |
27 | Device(const QString &device, const QString& mode); | 30 | Device(const QString &device, const QString& mode); |
28 | 31 | ||
29 | /** | 32 | /** |
30 | * unloads the device | 33 | * unloads the device |
31 | */ | 34 | */ |
32 | ~Device(); | 35 | ~Device(); |
33 | 36 | ||
34 | /** | 37 | /** |
35 | * attach the device | 38 | * attach the device |
36 | */ | 39 | */ |
37 | void attach(); | 40 | void attach(); |
38 | 41 | ||
39 | /** | 42 | /** |
40 | * detach the device | 43 | * detach the device |
41 | */ | 44 | */ |
42 | void detach(); | 45 | void detach(); |
43 | 46 | ||
44 | /** | 47 | /** |
45 | * Is the device loaded? | 48 | * Is the device loaded? |
46 | * @return bool, if the device is loaded | 49 | * @return bool, if the device is loaded |
47 | */ | 50 | */ |
48 | bool isLoaded()const; | 51 | bool isLoaded()const; |
49 | 52 | ||
50 | /** | 53 | /** |
51 | * Returns the device name | 54 | * Returns the device name |
52 | * @return QString, the device name | 55 | * @return QString, the device name |
53 | */ | 56 | */ |
54 | QString devName()const ; // hci0 | 57 | QString devName()const ; // hci0 |
55 | 58 | ||
56 | signals: | 59 | signals: |
57 | 60 | ||
58 | /** | 61 | /** |
59 | * Signals devicename and up status | 62 | * Signals devicename and up status |
60 | * @return &device QString, Devicename | 63 | * @return &device QString, Devicename |
61 | * @return up bool, if the device is up or not. | 64 | * @return up bool, if the device is up or not. |
62 | */ | 65 | */ |
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 | }; |
65 | }; | 82 | }; |
66 | 83 | ||
67 | #endif | 84 | #endif |