-rw-r--r-- | noncore/net/opietooth/lib/device.cc | 2 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/device.h | 2 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/manager.cc | 3 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/manager.h | 2 |
4 files changed, 4 insertions, 5 deletions
diff --git a/noncore/net/opietooth/lib/device.cc b/noncore/net/opietooth/lib/device.cc index 18d26e4..04c50d9 100644 --- a/noncore/net/opietooth/lib/device.cc +++ b/noncore/net/opietooth/lib/device.cc | |||
@@ -1,152 +1,152 @@ | |||
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 | ||
8 | using namespace OpieTooth; | 8 | using namespace OpieTooth; |
9 | 9 | ||
10 | using namespace Opie::Core; | 10 | using Opie::Core::OProcess; |
11 | namespace { | 11 | namespace { |
12 | int parsePid( const QCString& par ){ | 12 | int parsePid( const QCString& par ){ |
13 | int id=0; | 13 | int id=0; |
14 | QString string( par ); | 14 | QString string( par ); |
15 | QStringList list = QStringList::split( '\n', string ); | 15 | QStringList list = QStringList::split( '\n', string ); |
16 | for( QStringList::Iterator it = list.begin(); it != list.end(); ++it ){ | 16 | for( QStringList::Iterator it = list.begin(); it != list.end(); ++it ){ |
17 | qWarning("parsePID: %s", (*it).latin1() ); | 17 | qWarning("parsePID: %s", (*it).latin1() ); |
18 | if( !(*it).startsWith("CSR") ){ | 18 | if( !(*it).startsWith("CSR") ){ |
19 | id = (*it).toInt(); | 19 | id = (*it).toInt(); |
20 | break; | 20 | break; |
21 | } | 21 | } |
22 | } | 22 | } |
23 | return id; | 23 | return id; |
24 | } | 24 | } |
25 | } | 25 | } |
26 | 26 | ||
27 | Device::Device(const QString &device, const QString &mode, const QString &speed ) | 27 | Device::Device(const QString &device, const QString &mode, const QString &speed ) |
28 | : QObject(0, "device") { | 28 | : QObject(0, "device") { |
29 | 29 | ||
30 | qWarning("OpieTooth::Device create" ); | 30 | qWarning("OpieTooth::Device create" ); |
31 | m_hci = 0; | 31 | m_hci = 0; |
32 | m_process = 0; | 32 | m_process = 0; |
33 | m_attached = false; | 33 | m_attached = false; |
34 | m_device = device; | 34 | m_device = device; |
35 | m_mode = mode; | 35 | m_mode = mode; |
36 | m_speed = speed; | 36 | m_speed = speed; |
37 | attach(); | 37 | attach(); |
38 | } | 38 | } |
39 | Device::~Device(){ | 39 | Device::~Device(){ |
40 | detach(); | 40 | detach(); |
41 | } | 41 | } |
42 | void Device::attach(){ | 42 | void Device::attach(){ |
43 | 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() ); |
44 | if(m_process == 0 ){ | 44 | if(m_process == 0 ){ |
45 | m_output.resize(0); | 45 | m_output.resize(0); |
46 | qWarning("new process to create" ); | 46 | qWarning("new process to create" ); |
47 | m_process = new OProcess(); | 47 | m_process = new OProcess(); |
48 | *m_process << "hciattach"; | 48 | *m_process << "hciattach"; |
49 | *m_process << "-p"; | 49 | *m_process << "-p"; |
50 | *m_process << m_device << m_mode << m_speed; | 50 | *m_process << m_device << m_mode << m_speed; |
51 | connect(m_process, SIGNAL( processExited(Opie::Core::OProcess*) ), | 51 | connect(m_process, SIGNAL( processExited(Opie::Core::OProcess*) ), |
52 | this, SLOT( slotExited(Opie::Core::OProcess* ) ) ); | 52 | this, SLOT( slotExited(Opie::Core::OProcess* ) ) ); |
53 | connect(m_process, SIGNAL( receivedStdout(Opie::Core::OProcess*, char*, int) ), | 53 | connect(m_process, SIGNAL( receivedStdout(Opie::Core::OProcess*, char*, int) ), |
54 | this, SLOT(slotStdOut(Opie::Core::OProcess*,char*,int ) ) ); | 54 | this, SLOT(slotStdOut(Opie::Core::OProcess*,char*,int ) ) ); |
55 | connect(m_process, SIGNAL(receivedStderr(Opie::Core::OProcess*, char*, int ) ), | 55 | connect(m_process, SIGNAL(receivedStderr(Opie::Core::OProcess*, char*, int ) ), |
56 | this, SLOT(slotStdErr(Opie::Core::OProcess*,char*,int) ) ); | 56 | this, SLOT(slotStdErr(Opie::Core::OProcess*,char*,int) ) ); |
57 | if(!m_process->start(OProcess::NotifyOnExit, OProcess::AllOutput ) ){ | 57 | if(!m_process->start(OProcess::NotifyOnExit, OProcess::AllOutput ) ){ |
58 | qWarning("Could not start" ); | 58 | qWarning("Could not start" ); |
59 | delete m_process; | 59 | delete m_process; |
60 | m_process = 0; | 60 | m_process = 0; |
61 | } | 61 | } |
62 | }; | 62 | }; |
63 | } | 63 | } |
64 | void Device::detach(){ | 64 | void Device::detach(){ |
65 | delete m_hci; | 65 | delete m_hci; |
66 | delete m_process; | 66 | delete m_process; |
67 | // kill the pid we got | 67 | // kill the pid we got |
68 | if(m_attached ){ | 68 | if(m_attached ){ |
69 | //kill the pid | 69 | //kill the pid |
70 | qWarning( "killing" ); | 70 | qWarning( "killing" ); |
71 | kill(pid, 9); | 71 | kill(pid, 9); |
72 | } | 72 | } |
73 | qWarning("detached" ); | 73 | qWarning("detached" ); |
74 | } | 74 | } |
75 | bool Device::isLoaded()const{ | 75 | bool Device::isLoaded()const{ |
76 | return m_attached; | 76 | return m_attached; |
77 | } | 77 | } |
78 | QString Device::devName()const { | 78 | QString Device::devName()const { |
79 | return QString::fromLatin1("hci0"); | 79 | return QString::fromLatin1("hci0"); |
80 | }; | 80 | }; |
81 | void Device::slotExited( OProcess* proc) | 81 | void Device::slotExited( OProcess* proc) |
82 | { | 82 | { |
83 | qWarning("prcess exited" ); | 83 | qWarning("prcess exited" ); |
84 | if(proc== m_process ){ | 84 | if(proc== m_process ){ |
85 | qWarning("proc == m_process" ); | 85 | qWarning("proc == m_process" ); |
86 | if( m_process->normalExit() ){ // normal exit | 86 | if( m_process->normalExit() ){ // normal exit |
87 | qWarning("normalExit" ); | 87 | qWarning("normalExit" ); |
88 | int ret = m_process->exitStatus(); | 88 | int ret = m_process->exitStatus(); |
89 | if( ret == 0 ){ // attached | 89 | if( ret == 0 ){ // attached |
90 | qWarning("attached" ); | 90 | qWarning("attached" ); |
91 | qWarning("Output: %s", m_output.data() ); | 91 | qWarning("Output: %s", m_output.data() ); |
92 | pid = parsePid( m_output ); | 92 | pid = parsePid( m_output ); |
93 | qWarning("Pid = %d", pid ); | 93 | qWarning("Pid = %d", pid ); |
94 | // now hciconfig hci0 up ( determine hciX FIXME) | 94 | // now hciconfig hci0 up ( determine hciX FIXME) |
95 | // and call hciconfig hci0 up | 95 | // and call hciconfig hci0 up |
96 | // FIXME hardcoded to hci0 now :( | 96 | // FIXME hardcoded to hci0 now :( |
97 | m_hci = new OProcess( ); | 97 | m_hci = new OProcess( ); |
98 | *m_hci << "hciconfig"; | 98 | *m_hci << "hciconfig"; |
99 | *m_hci << "hci0 up"; | 99 | *m_hci << "hci0 up"; |
100 | connect(m_hci, SIGNAL( processExited(Opie::Core::OProcess*) ), | 100 | connect(m_hci, SIGNAL( processExited(Opie::Core::OProcess*) ), |
101 | this, SLOT( slotExited(Opie::Core::OProcess* ) ) ); | 101 | this, SLOT( slotExited(Opie::Core::OProcess* ) ) ); |
102 | if(!m_hci->start() ){ | 102 | if(!m_hci->start() ){ |
103 | qWarning("could not start" ); | 103 | qWarning("could not start" ); |
104 | m_attached = false; | 104 | m_attached = false; |
105 | emit device("hci0", false ); | 105 | emit device("hci0", false ); |
106 | } | 106 | } |
107 | }else{ | 107 | }else{ |
108 | qWarning("crass" ); | 108 | qWarning("crass" ); |
109 | m_attached = false; | 109 | m_attached = false; |
110 | emit device("hci0", false ); | 110 | emit device("hci0", false ); |
111 | 111 | ||
112 | } | 112 | } |
113 | } | 113 | } |
114 | delete m_process; | 114 | delete m_process; |
115 | m_process = 0; | 115 | m_process = 0; |
116 | }else if(proc== m_hci ){ | 116 | }else if(proc== m_hci ){ |
117 | qWarning("M HCI exited" ); | 117 | qWarning("M HCI exited" ); |
118 | if( m_hci->normalExit() ){ | 118 | if( m_hci->normalExit() ){ |
119 | qWarning("normal exit" ); | 119 | qWarning("normal exit" ); |
120 | int ret = m_hci->exitStatus(); | 120 | int ret = m_hci->exitStatus(); |
121 | if( ret == 0 ){ | 121 | if( ret == 0 ){ |
122 | qWarning("attached really really attached" ); | 122 | qWarning("attached really really attached" ); |
123 | m_attached = true; | 123 | m_attached = true; |
124 | emit device("hci0", true ); | 124 | emit device("hci0", true ); |
125 | }else{ | 125 | }else{ |
126 | qWarning( "failed" ); | 126 | qWarning( "failed" ); |
127 | emit device("hci0", false ); | 127 | emit device("hci0", false ); |
128 | m_attached = false; | 128 | m_attached = false; |
129 | } | 129 | } |
130 | }// normal exit | 130 | }// normal exit |
131 | delete m_hci; | 131 | delete m_hci; |
132 | m_hci = 0; | 132 | m_hci = 0; |
133 | } | 133 | } |
134 | } | 134 | } |
135 | void Device::slotStdOut(OProcess* proc, char* chars, int len) | 135 | void Device::slotStdOut(OProcess* proc, char* chars, int len) |
136 | { | 136 | { |
137 | qWarning("std out" ); | 137 | qWarning("std out" ); |
138 | if( len <1 ){ | 138 | if( len <1 ){ |
139 | qWarning( "len < 1 " ); | 139 | qWarning( "len < 1 " ); |
140 | return; | 140 | return; |
141 | } | 141 | } |
142 | if(proc == m_process ){ | 142 | if(proc == m_process ){ |
143 | QCString string( chars, len+1 ); // \0 == +1 | 143 | QCString string( chars, len+1 ); // \0 == +1 |
144 | qWarning("output: %s", string.data() ); | 144 | qWarning("output: %s", string.data() ); |
145 | m_output.append( string.data() ); | 145 | m_output.append( string.data() ); |
146 | } | 146 | } |
147 | } | 147 | } |
148 | void Device::slotStdErr(OProcess* proc, char* chars, int len) | 148 | void Device::slotStdErr(OProcess* proc, char* chars, int len) |
149 | { | 149 | { |
150 | qWarning("std err" ); | 150 | qWarning("std err" ); |
151 | slotStdOut( proc, chars, len ); | 151 | slotStdOut( proc, chars, len ); |
152 | } | 152 | } |
diff --git a/noncore/net/opietooth/lib/device.h b/noncore/net/opietooth/lib/device.h index f3339fc..3631c97 100644 --- a/noncore/net/opietooth/lib/device.h +++ b/noncore/net/opietooth/lib/device.h | |||
@@ -1,88 +1,88 @@ | |||
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 | ||
11 | namespace Opie {namespace Core {class Opie::Core::OProcess;}} | 11 | namespace Opie {namespace Core {class OProcess;}} |
12 | namespace OpieTooth { | 12 | namespace 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 | 19 | ||
20 | Q_OBJECT | 20 | Q_OBJECT |
21 | 21 | ||
22 | public: | 22 | public: |
23 | 23 | ||
24 | /** | 24 | /** |
25 | * Brings up an device. | 25 | * Brings up an device. |
26 | * Usage example: new Device(/dev/ttySB0, csr) | 26 | * Usage example: new Device(/dev/ttySB0, csr) |
27 | * | 27 | * |
28 | * @param &device QString the device name | 28 | * @param &device QString the device name |
29 | * @param &mode QString the mode | 29 | * @param &mode QString the mode |
30 | * @param &speed QString the speed of the device, can be left blank | 30 | * @param &speed QString the speed of the device, can be left blank |
31 | */ | 31 | */ |
32 | Device(const QString &device, const QString& mode, const QString& speed); | 32 | Device(const QString &device, const QString& mode, const QString& speed); |
33 | 33 | ||
34 | /** | 34 | /** |
35 | * unloads the device | 35 | * unloads the device |
36 | */ | 36 | */ |
37 | ~Device(); | 37 | ~Device(); |
38 | 38 | ||
39 | /** | 39 | /** |
40 | * attach the device | 40 | * attach the device |
41 | */ | 41 | */ |
42 | void attach(); | 42 | void attach(); |
43 | 43 | ||
44 | /** | 44 | /** |
45 | * detach the device | 45 | * detach the device |
46 | */ | 46 | */ |
47 | void detach(); | 47 | void detach(); |
48 | 48 | ||
49 | /** | 49 | /** |
50 | * Is the device loaded? | 50 | * Is the device loaded? |
51 | * @return bool, if the device is loaded | 51 | * @return bool, if the device is loaded |
52 | */ | 52 | */ |
53 | bool isLoaded()const; | 53 | bool isLoaded()const; |
54 | 54 | ||
55 | /** | 55 | /** |
56 | * Returns the device name | 56 | * Returns the device name |
57 | * @return QString, the device name | 57 | * @return QString, the device name |
58 | */ | 58 | */ |
59 | QString devName()const ; // hci0 | 59 | QString devName()const ; // hci0 |
60 | 60 | ||
61 | signals: | 61 | signals: |
62 | 62 | ||
63 | /** | 63 | /** |
64 | * Signals devicename and up status | 64 | * Signals devicename and up status |
65 | * @return &device QString, Devicename | 65 | * @return &device QString, Devicename |
66 | * @return up bool, if the device is up or not. | 66 | * @return up bool, if the device is up or not. |
67 | */ | 67 | */ |
68 | void device(const QString& device, bool up ); | 68 | void device(const QString& device, bool up ); |
69 | private slots: | 69 | private slots: |
70 | virtual void slotExited( Opie::Core::OProcess* ); | 70 | virtual void slotExited( Opie::Core::OProcess* ); |
71 | virtual void slotStdOut(Opie::Core::OProcess*, char*, int ); | 71 | virtual void slotStdOut(Opie::Core::OProcess*, char*, int ); |
72 | virtual void slotStdErr(Opie::Core::OProcess*, char*, int ); | 72 | virtual void slotStdErr(Opie::Core::OProcess*, char*, int ); |
73 | private: | 73 | private: |
74 | class Private; | 74 | class Private; |
75 | Private *d; | 75 | Private *d; |
76 | QString m_device; | 76 | QString m_device; |
77 | bool m_attached:1; | 77 | bool m_attached:1; |
78 | Opie::Core::OProcess* m_hci; | 78 | Opie::Core::OProcess* m_hci; |
79 | Opie::Core::OProcess* m_process; | 79 | Opie::Core::OProcess* m_process; |
80 | QString m_devId; | 80 | QString m_devId; |
81 | QString m_mode; | 81 | QString m_mode; |
82 | QString m_speed; | 82 | QString m_speed; |
83 | pid_t pid; | 83 | pid_t pid; |
84 | QCString m_output; | 84 | QCString m_output; |
85 | }; | 85 | }; |
86 | }; | 86 | }; |
87 | 87 | ||
88 | #endif | 88 | #endif |
diff --git a/noncore/net/opietooth/lib/manager.cc b/noncore/net/opietooth/lib/manager.cc index 7c9ea5b..18e1df9 100644 --- a/noncore/net/opietooth/lib/manager.cc +++ b/noncore/net/opietooth/lib/manager.cc | |||
@@ -1,204 +1,203 @@ | |||
1 | 1 | ||
2 | 2 | ||
3 | #include <opie2/oprocess.h> | 3 | #include <opie2/oprocess.h> |
4 | 4 | ||
5 | #include "parser.h" | 5 | #include "parser.h" |
6 | #include "manager.h" | 6 | #include "manager.h" |
7 | 7 | ||
8 | 8 | ||
9 | using namespace OpieTooth; | 9 | using namespace OpieTooth; |
10 | 10 | ||
11 | using namespace Opie::Core; | 11 | using Opie::Core::OProcess; |
12 | using namespace Opie::Core; | ||
13 | Manager::Manager( const QString& dev ) | 12 | Manager::Manager( const QString& dev ) |
14 | : QObject() | 13 | : QObject() |
15 | { | 14 | { |
16 | qWarning("created"); | 15 | qWarning("created"); |
17 | m_device = dev; | 16 | m_device = dev; |
18 | m_hcitool = 0; | 17 | m_hcitool = 0; |
19 | m_sdp = 0; | 18 | m_sdp = 0; |
20 | } | 19 | } |
21 | Manager::Manager( Device* /*dev*/ ) | 20 | Manager::Manager( Device* /*dev*/ ) |
22 | : QObject() | 21 | : QObject() |
23 | { | 22 | { |
24 | m_hcitool = 0; | 23 | m_hcitool = 0; |
25 | m_sdp = 0; | 24 | m_sdp = 0; |
26 | } | 25 | } |
27 | Manager::Manager() | 26 | Manager::Manager() |
28 | : QObject() | 27 | : QObject() |
29 | { | 28 | { |
30 | m_hcitool = 0; | 29 | m_hcitool = 0; |
31 | m_sdp = 0; | 30 | m_sdp = 0; |
32 | } | 31 | } |
33 | Manager::~Manager(){ | 32 | Manager::~Manager(){ |
34 | delete m_hcitool; | 33 | delete m_hcitool; |
35 | delete m_sdp; | 34 | delete m_sdp; |
36 | } | 35 | } |
37 | void Manager::setDevice( const QString& dev ){ | 36 | void Manager::setDevice( const QString& dev ){ |
38 | m_device = dev; | 37 | m_device = dev; |
39 | } | 38 | } |
40 | void Manager::setDevice( Device* /*dev*/ ){ | 39 | void Manager::setDevice( Device* /*dev*/ ){ |
41 | 40 | ||
42 | } | 41 | } |
43 | void Manager::isAvailable( const QString& device ){ | 42 | void Manager::isAvailable( const QString& device ){ |
44 | OProcess* l2ping = new OProcess(); | 43 | OProcess* l2ping = new OProcess(); |
45 | l2ping->setName( device.latin1() ); | 44 | l2ping->setName( device.latin1() ); |
46 | *l2ping << "l2ping" << "-c1" << device; | 45 | *l2ping << "l2ping" << "-c1" << device; |
47 | connect(l2ping, SIGNAL(processExited(Opie::Core::OProcess* ) ), | 46 | connect(l2ping, SIGNAL(processExited(Opie::Core::OProcess* ) ), |
48 | this, SLOT(slotProcessExited(Opie::Core::OProcess*) ) ); | 47 | this, SLOT(slotProcessExited(Opie::Core::OProcess*) ) ); |
49 | if (!l2ping->start() ) { | 48 | if (!l2ping->start() ) { |
50 | emit available( device, false ); | 49 | emit available( device, false ); |
51 | delete l2ping; | 50 | delete l2ping; |
52 | } | 51 | } |
53 | 52 | ||
54 | } | 53 | } |
55 | 54 | ||
56 | void Manager::isAvailable( Device* /*dev*/ ){ | 55 | void Manager::isAvailable( Device* /*dev*/ ){ |
57 | 56 | ||
58 | 57 | ||
59 | } | 58 | } |
60 | void Manager::searchDevices( const QString& device ){ | 59 | void Manager::searchDevices( const QString& device ){ |
61 | qWarning("search devices"); | 60 | qWarning("search devices"); |
62 | OProcess* hcitool = new OProcess(); | 61 | OProcess* hcitool = new OProcess(); |
63 | hcitool->setName( device.isEmpty() ? "hci0" : device.latin1() ); | 62 | hcitool->setName( device.isEmpty() ? "hci0" : device.latin1() ); |
64 | *hcitool << "hcitool" << "scan"; | 63 | *hcitool << "hcitool" << "scan"; |
65 | connect( hcitool, SIGNAL(processExited(Opie::Core::OProcess*) ) , | 64 | connect( hcitool, SIGNAL(processExited(Opie::Core::OProcess*) ) , |
66 | this, SLOT(slotHCIExited(Opie::Core::OProcess* ) ) ); | 65 | this, SLOT(slotHCIExited(Opie::Core::OProcess* ) ) ); |
67 | connect( hcitool, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ), | 66 | connect( hcitool, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ), |
68 | this, SLOT(slotHCIOut(Opie::Core::OProcess*, char*, int ) ) ); | 67 | this, SLOT(slotHCIOut(Opie::Core::OProcess*, char*, int ) ) ); |
69 | if (!hcitool->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { | 68 | if (!hcitool->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { |
70 | qWarning("could not start"); | 69 | qWarning("could not start"); |
71 | RemoteDevice::ValueList list; | 70 | RemoteDevice::ValueList list; |
72 | emit foundDevices( device, list ); | 71 | emit foundDevices( device, list ); |
73 | delete hcitool; | 72 | delete hcitool; |
74 | } | 73 | } |
75 | } | 74 | } |
76 | 75 | ||
77 | void Manager::searchDevices(Device* /*d*/ ){ | 76 | void Manager::searchDevices(Device* /*d*/ ){ |
78 | 77 | ||
79 | 78 | ||
80 | } | 79 | } |
81 | void Manager::addService(const QString& name ){ | 80 | void Manager::addService(const QString& name ){ |
82 | OProcess proc; | 81 | OProcess proc; |
83 | proc << "sdptool" << "add" << name; | 82 | proc << "sdptool" << "add" << name; |
84 | bool bo = true; | 83 | bool bo = true; |
85 | if (!proc.start(OProcess::DontCare ) ) | 84 | if (!proc.start(OProcess::DontCare ) ) |
86 | bo = false; | 85 | bo = false; |
87 | emit addedService( name, bo ); | 86 | emit addedService( name, bo ); |
88 | } | 87 | } |
89 | void Manager::addServices(const QStringList& list){ | 88 | void Manager::addServices(const QStringList& list){ |
90 | QStringList::ConstIterator it; | 89 | QStringList::ConstIterator it; |
91 | for (it = list.begin(); it != list.end(); ++it ) | 90 | for (it = list.begin(); it != list.end(); ++it ) |
92 | addService( (*it) ); | 91 | addService( (*it) ); |
93 | } | 92 | } |
94 | void Manager::removeService( const QString& name ){ | 93 | void Manager::removeService( const QString& name ){ |
95 | OProcess prc; | 94 | OProcess prc; |
96 | prc << "sdptool" << "del" << name; | 95 | prc << "sdptool" << "del" << name; |
97 | bool bo = true; | 96 | bool bo = true; |
98 | if (!prc.start(OProcess::DontCare ) ) | 97 | if (!prc.start(OProcess::DontCare ) ) |
99 | bo = false; | 98 | bo = false; |
100 | emit removedService( name, bo ); | 99 | emit removedService( name, bo ); |
101 | } | 100 | } |
102 | void Manager::removeServices( const QStringList& list){ | 101 | void Manager::removeServices( const QStringList& list){ |
103 | QStringList::ConstIterator it; | 102 | QStringList::ConstIterator it; |
104 | for (it = list.begin(); it != list.end(); ++it ) | 103 | for (it = list.begin(); it != list.end(); ++it ) |
105 | removeService( (*it) ); | 104 | removeService( (*it) ); |
106 | } | 105 | } |
107 | void Manager::searchServices( const QString& remDevice ){ | 106 | void Manager::searchServices( const QString& remDevice ){ |
108 | OProcess *m_sdp =new OProcess(); | 107 | OProcess *m_sdp =new OProcess(); |
109 | *m_sdp << "sdptool" << "browse" << remDevice; | 108 | *m_sdp << "sdptool" << "browse" << remDevice; |
110 | m_sdp->setName( remDevice.latin1() ); | 109 | m_sdp->setName( remDevice.latin1() ); |
111 | qWarning("search Services for %s", remDevice.latin1() ); | 110 | qWarning("search Services for %s", remDevice.latin1() ); |
112 | connect(m_sdp, SIGNAL(processExited(Opie::Core::OProcess*) ), | 111 | connect(m_sdp, SIGNAL(processExited(Opie::Core::OProcess*) ), |
113 | this, SLOT(slotSDPExited(Opie::Core::OProcess* ) ) ); | 112 | this, SLOT(slotSDPExited(Opie::Core::OProcess* ) ) ); |
114 | connect(m_sdp, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ), | 113 | connect(m_sdp, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ), |
115 | this, SLOT(slotSDPOut(Opie::Core::OProcess*, char*, int) ) ); | 114 | this, SLOT(slotSDPOut(Opie::Core::OProcess*, char*, int) ) ); |
116 | if (!m_sdp->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { | 115 | if (!m_sdp->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { |
117 | qWarning("could not start sdptool" ); | 116 | qWarning("could not start sdptool" ); |
118 | delete m_sdp; | 117 | delete m_sdp; |
119 | Services::ValueList list; | 118 | Services::ValueList list; |
120 | emit foundServices( remDevice, list ); | 119 | emit foundServices( remDevice, list ); |
121 | } | 120 | } |
122 | } | 121 | } |
123 | void Manager::searchServices( const RemoteDevice& dev){ | 122 | void Manager::searchServices( const RemoteDevice& dev){ |
124 | searchServices( dev.mac() ); | 123 | searchServices( dev.mac() ); |
125 | } | 124 | } |
126 | QString Manager::toDevice( const QString& /*mac*/ ){ | 125 | QString Manager::toDevice( const QString& /*mac*/ ){ |
127 | return QString::null; | 126 | return QString::null; |
128 | } | 127 | } |
129 | QString Manager::toMac( const QString &/*device*/ ){ | 128 | QString Manager::toMac( const QString &/*device*/ ){ |
130 | return QString::null; | 129 | return QString::null; |
131 | } | 130 | } |
132 | void Manager::slotProcessExited(OProcess* proc ) { | 131 | void Manager::slotProcessExited(OProcess* proc ) { |
133 | bool conn= false; | 132 | bool conn= false; |
134 | if (proc->normalExit() && proc->exitStatus() == 0 ) | 133 | if (proc->normalExit() && proc->exitStatus() == 0 ) |
135 | conn = true; | 134 | conn = true; |
136 | 135 | ||
137 | QString name = QString::fromLatin1(proc->name() ); | 136 | QString name = QString::fromLatin1(proc->name() ); |
138 | emit available( name, conn ); | 137 | emit available( name, conn ); |
139 | delete proc; | 138 | delete proc; |
140 | } | 139 | } |
141 | void Manager::slotSDPOut(OProcess* proc, char* ch, int len) | 140 | void Manager::slotSDPOut(OProcess* proc, char* ch, int len) |
142 | { | 141 | { |
143 | QCString str(ch, len+1 ); | 142 | QCString str(ch, len+1 ); |
144 | qWarning("SDP:%s", str.data() ); | 143 | qWarning("SDP:%s", str.data() ); |
145 | QMap<QString, QString>::Iterator it; | 144 | QMap<QString, QString>::Iterator it; |
146 | it = m_out.find(proc->name() ); | 145 | it = m_out.find(proc->name() ); |
147 | QString string; | 146 | QString string; |
148 | if ( it != m_out.end() ) { | 147 | if ( it != m_out.end() ) { |
149 | string = it.data(); | 148 | string = it.data(); |
150 | } | 149 | } |
151 | string.append( str ); | 150 | string.append( str ); |
152 | m_out.replace( proc->name(), string ); | 151 | m_out.replace( proc->name(), string ); |
153 | 152 | ||
154 | } | 153 | } |
155 | void Manager::slotSDPExited( OProcess* proc) | 154 | void Manager::slotSDPExited( OProcess* proc) |
156 | { | 155 | { |
157 | qWarning("proc name %s", proc->name() ); | 156 | qWarning("proc name %s", proc->name() ); |
158 | Services::ValueList list; | 157 | Services::ValueList list; |
159 | if (proc->normalExit() ) { | 158 | if (proc->normalExit() ) { |
160 | QMap<QString, QString>::Iterator it = m_out.find( proc->name() ); | 159 | QMap<QString, QString>::Iterator it = m_out.find( proc->name() ); |
161 | if ( it != m_out.end() ) { | 160 | if ( it != m_out.end() ) { |
162 | qWarning("found process" ); | 161 | qWarning("found process" ); |
163 | list = parseSDPOutput( it.data() ); | 162 | list = parseSDPOutput( it.data() ); |
164 | m_out.remove( it ); | 163 | m_out.remove( it ); |
165 | } | 164 | } |
166 | } | 165 | } |
167 | emit foundServices( proc->name(), list ); | 166 | emit foundServices( proc->name(), list ); |
168 | delete proc; | 167 | delete proc; |
169 | } | 168 | } |
170 | Services::ValueList Manager::parseSDPOutput( const QString& out ) { | 169 | Services::ValueList Manager::parseSDPOutput( const QString& out ) { |
171 | Services::ValueList list; | 170 | Services::ValueList list; |
172 | qWarning("parsing output" ); | 171 | qWarning("parsing output" ); |
173 | Parser parser( out ); | 172 | Parser parser( out ); |
174 | list = parser.services(); | 173 | list = parser.services(); |
175 | return list; | 174 | return list; |
176 | } | 175 | } |
177 | 176 | ||
178 | void Manager::slotHCIExited(OProcess* proc ) { | 177 | void Manager::slotHCIExited(OProcess* proc ) { |
179 | qWarning("process exited"); | 178 | qWarning("process exited"); |
180 | RemoteDevice::ValueList list; | 179 | RemoteDevice::ValueList list; |
181 | if (proc->normalExit() ) { | 180 | if (proc->normalExit() ) { |
182 | qWarning("normalExit %s", proc->name() ); | 181 | qWarning("normalExit %s", proc->name() ); |
183 | QMap<QString, QString>::Iterator it = m_devices.find(proc->name() ); | 182 | QMap<QString, QString>::Iterator it = m_devices.find(proc->name() ); |
184 | if (it != m_devices.end() ) { | 183 | if (it != m_devices.end() ) { |
185 | qWarning("!= end ;)"); | 184 | qWarning("!= end ;)"); |
186 | list = parseHCIOutput( it.data() ); | 185 | list = parseHCIOutput( it.data() ); |
187 | m_devices.remove( it ); | 186 | m_devices.remove( it ); |
188 | } | 187 | } |
189 | } | 188 | } |
190 | emit foundDevices( proc->name(), list ); | 189 | emit foundDevices( proc->name(), list ); |
191 | delete proc; | 190 | delete proc; |
192 | } | 191 | } |
193 | void Manager::slotHCIOut(OProcess* proc, char* ch, int len) { | 192 | void Manager::slotHCIOut(OProcess* proc, char* ch, int len) { |
194 | QCString str( ch, len+1 ); | 193 | QCString str( ch, len+1 ); |
195 | qWarning("hci: %s", str.data() ); | 194 | qWarning("hci: %s", str.data() ); |
196 | QMap<QString, QString>::Iterator it; | 195 | QMap<QString, QString>::Iterator it; |
197 | it = m_devices.find( proc->name() ); | 196 | it = m_devices.find( proc->name() ); |
198 | qWarning("proc->name %s", proc->name() ); | 197 | qWarning("proc->name %s", proc->name() ); |
199 | QString string; | 198 | QString string; |
200 | if (it != m_devices.end() ) { | 199 | if (it != m_devices.end() ) { |
201 | qWarning("slotHCIOut "); | 200 | qWarning("slotHCIOut "); |
202 | string = it.data(); | 201 | string = it.data(); |
203 | } | 202 | } |
204 | string.append( str ); | 203 | string.append( str ); |
diff --git a/noncore/net/opietooth/lib/manager.h b/noncore/net/opietooth/lib/manager.h index 9b1c714..930eb56 100644 --- a/noncore/net/opietooth/lib/manager.h +++ b/noncore/net/opietooth/lib/manager.h | |||
@@ -1,173 +1,173 @@ | |||
1 | 1 | ||
2 | #ifndef OpieToothManager_H | 2 | #ifndef OpieToothManager_H |
3 | #define OpieToothManager_H | 3 | #define OpieToothManager_H |
4 | 4 | ||
5 | #include <qobject.h> | 5 | #include <qobject.h> |
6 | #include <qstring.h> | 6 | #include <qstring.h> |
7 | #include <qmap.h> | 7 | #include <qmap.h> |
8 | #include <qvaluelist.h> | 8 | #include <qvaluelist.h> |
9 | 9 | ||
10 | #include "connection.h" | 10 | #include "connection.h" |
11 | #include "remotedevice.h" | 11 | #include "remotedevice.h" |
12 | #include "services.h" | 12 | #include "services.h" |
13 | 13 | ||
14 | namespace Opie {namespace Core {class Opie::Core::OProcess;}} | 14 | namespace Opie {namespace Core {class OProcess;}} |
15 | namespace OpieTooth { | 15 | namespace OpieTooth { |
16 | class Device; | 16 | class Device; |
17 | /** Manager manages a blueZ device (hci0 for example) | 17 | /** Manager manages a blueZ device (hci0 for example) |
18 | * without Manager you can control the things you | 18 | * without Manager you can control the things you |
19 | * could do from command line in a OO and asynchronus | 19 | * could do from command line in a OO and asynchronus |
20 | * way. | 20 | * way. |
21 | */ | 21 | */ |
22 | class Manager : public QObject { | 22 | class Manager : public QObject { |
23 | Q_OBJECT | 23 | Q_OBJECT |
24 | public: | 24 | public: |
25 | /** c'tor whichs create a new Manager | 25 | /** c'tor whichs create a new Manager |
26 | * @param device is the device to use. Either a mac or blueZ device name | 26 | * @param device is the device to use. Either a mac or blueZ device name |
27 | * | 27 | * |
28 | */ | 28 | */ |
29 | Manager( const QString &device ); | 29 | Manager( const QString &device ); |
30 | 30 | ||
31 | /** c'tor | 31 | /** c'tor |
32 | * @param dev The Device to be managed | 32 | * @param dev The Device to be managed |
33 | * We don't care of Device so you need to delete it | 33 | * We don't care of Device so you need to delete it |
34 | */ | 34 | */ |
35 | Manager( Device* dev ); | 35 | Manager( Device* dev ); |
36 | 36 | ||
37 | /** | 37 | /** |
38 | * c'tor | 38 | * c'tor |
39 | */ | 39 | */ |
40 | Manager(); | 40 | Manager(); |
41 | 41 | ||
42 | ~Manager(); | 42 | ~Manager(); |
43 | 43 | ||
44 | /** Set the manager to control a new device | 44 | /** Set the manager to control a new device |
45 | * @param device the new device to control (hci0 ) | 45 | * @param device the new device to control (hci0 ) |
46 | */ | 46 | */ |
47 | void setDevice( const QString& device ); | 47 | void setDevice( const QString& device ); |
48 | 48 | ||
49 | /** | 49 | /** |
50 | * Convience functions for setting a new device | 50 | * Convience functions for setting a new device |
51 | */ | 51 | */ |
52 | void setDevice( Device *dev ); | 52 | void setDevice( Device *dev ); |
53 | 53 | ||
54 | /** | 54 | /** |
55 | * Wether or not a device is connected. The function | 55 | * Wether or not a device is connected. The function |
56 | * is asynchron | 56 | * is asynchron |
57 | * If device is empty it will take the currently managed | 57 | * If device is empty it will take the currently managed |
58 | * device and see if it's up | 58 | * device and see if it's up |
59 | * for Remote devices it will ping and see. | 59 | * for Remote devices it will ping and see. |
60 | * @param either mac or hciX | 60 | * @param either mac or hciX |
61 | */ | 61 | */ |
62 | void isAvailable(const QString& device= QString::null ); | 62 | void isAvailable(const QString& device= QString::null ); |
63 | 63 | ||
64 | /** | 64 | /** |
65 | * same as above | 65 | * same as above |
66 | */ | 66 | */ |
67 | void isAvailable(Device *dev ); | 67 | void isAvailable(Device *dev ); |
68 | 68 | ||
69 | /** this searchs for devices reachable from the | 69 | /** this searchs for devices reachable from the |
70 | * currently managed device | 70 | * currently managed device |
71 | * or from device if @param device is not empty | 71 | * or from device if @param device is not empty |
72 | */ | 72 | */ |
73 | void searchDevices(const QString& device= QString::null ); | 73 | void searchDevices(const QString& device= QString::null ); |
74 | /** same as above | 74 | /** same as above |
75 | * | 75 | * |
76 | */ | 76 | */ |
77 | void searchDevices(Device *d ); | 77 | void searchDevices(Device *d ); |
78 | 78 | ||
79 | /** | 79 | /** |
80 | * This will add the service @param name | 80 | * This will add the service @param name |
81 | * to the sdpd daemon | 81 | * to the sdpd daemon |
82 | * It will start the daemon if necessary | 82 | * It will start the daemon if necessary |
83 | */ | 83 | */ |
84 | void addService(const QString &name ); | 84 | void addService(const QString &name ); |
85 | 85 | ||
86 | /** | 86 | /** |
87 | * This will add the services @param names | 87 | * This will add the services @param names |
88 | * to the sdpd daemon | 88 | * to the sdpd daemon |
89 | * It will start the daemon if necessary | 89 | * It will start the daemon if necessary |
90 | */ | 90 | */ |
91 | void addServices( const QStringList& names ); | 91 | void addServices( const QStringList& names ); |
92 | 92 | ||
93 | /** | 93 | /** |
94 | * This removes a service from the sdps | 94 | * This removes a service from the sdps |
95 | */ | 95 | */ |
96 | void removeService(const QString &name ); | 96 | void removeService(const QString &name ); |
97 | 97 | ||
98 | /** | 98 | /** |
99 | * Removes a list from the sdpd | 99 | * Removes a list from the sdpd |
100 | */ | 100 | */ |
101 | void removeServices(const QStringList& ); | 101 | void removeServices(const QStringList& ); |
102 | 102 | ||
103 | /** | 103 | /** |
104 | * search for services on a remote device | 104 | * search for services on a remote device |
105 | * | 105 | * |
106 | */ | 106 | */ |
107 | void searchServices( const QString& remDevice ); | 107 | void searchServices( const QString& remDevice ); |
108 | 108 | ||
109 | /** | 109 | /** |
110 | * search for services on a remote device | 110 | * search for services on a remote device |
111 | */ | 111 | */ |
112 | void searchServices( const RemoteDevice& ); | 112 | void searchServices( const RemoteDevice& ); |
113 | 113 | ||
114 | /** | 114 | /** |
115 | * Starts to connect to the device | 115 | * Starts to connect to the device |
116 | * in @param | 116 | * in @param |
117 | */ | 117 | */ |
118 | void connectTo(const QString& ); | 118 | void connectTo(const QString& ); |
119 | 119 | ||
120 | /** | 120 | /** |
121 | * Searches for active connections | 121 | * Searches for active connections |
122 | * the result is emitted with the | 122 | * the result is emitted with the |
123 | * connections signal | 123 | * connections signal |
124 | */ | 124 | */ |
125 | void searchConnections(); | 125 | void searchConnections(); |
126 | 126 | ||
127 | void signalStrength( const QString &mac ); | 127 | void signalStrength( const QString &mac ); |
128 | //// not implemented yet | 128 | //// not implemented yet |
129 | /*static*/ QString toDevice( const QString& mac ); | 129 | /*static*/ QString toDevice( const QString& mac ); |
130 | /*static*/ QString toMac( const QString &device ); | 130 | /*static*/ QString toMac( const QString &device ); |
131 | //// not implemented yet over | 131 | //// not implemented yet over |
132 | 132 | ||
133 | signals: | 133 | signals: |
134 | // device either mac or dev name | 134 | // device either mac or dev name |
135 | // the first device is the device which you access | 135 | // the first device is the device which you access |
136 | void available( const QString& device, bool connected ); | 136 | void available( const QString& device, bool connected ); |
137 | void addedService( const QString& service, bool added ); | 137 | void addedService( const QString& service, bool added ); |
138 | void removedService( const QString& service, bool removed ); | 138 | void removedService( const QString& service, bool removed ); |
139 | void foundServices( const QString& device, Services::ValueList ); | 139 | void foundServices( const QString& device, Services::ValueList ); |
140 | void foundDevices( const QString& device, RemoteDevice::ValueList ); | 140 | void foundDevices( const QString& device, RemoteDevice::ValueList ); |
141 | void connections( ConnectionState::ValueList ); | 141 | void connections( ConnectionState::ValueList ); |
142 | void signalStrength( const QString& mac, const QString& strengh ); | 142 | void signalStrength( const QString& mac, const QString& strengh ); |
143 | 143 | ||
144 | private slots: | 144 | private slots: |
145 | void slotProcessExited(Opie::Core::OProcess* ); | 145 | void slotProcessExited(Opie::Core::OProcess* ); |
146 | 146 | ||
147 | void slotSDPExited(Opie::Core::OProcess*); | 147 | void slotSDPExited(Opie::Core::OProcess*); |
148 | void slotSDPOut(Opie::Core::OProcess*, char*, int); | 148 | void slotSDPOut(Opie::Core::OProcess*, char*, int); |
149 | 149 | ||
150 | void slotHCIExited(Opie::Core::OProcess* ); | 150 | void slotHCIExited(Opie::Core::OProcess* ); |
151 | void slotHCIOut(Opie::Core::OProcess*, char*, int ); | 151 | void slotHCIOut(Opie::Core::OProcess*, char*, int ); |
152 | 152 | ||
153 | void slotConnectionExited(Opie::Core::OProcess* ); | 153 | void slotConnectionExited(Opie::Core::OProcess* ); |
154 | void slotConnectionOutput(Opie::Core::OProcess*, char*, int ); | 154 | void slotConnectionOutput(Opie::Core::OProcess*, char*, int ); |
155 | 155 | ||
156 | void slotSignalStrengthOutput( Opie::Core::OProcess*, char*, int ); | 156 | void slotSignalStrengthOutput( Opie::Core::OProcess*, char*, int ); |
157 | void slotSignalStrengthExited( Opie::Core::OProcess* ); | 157 | void slotSignalStrengthExited( Opie::Core::OProcess* ); |
158 | private: | 158 | private: |
159 | Services::ValueList parseSDPOutput( const QString& ); | 159 | Services::ValueList parseSDPOutput( const QString& ); |
160 | RemoteDevice::ValueList parseHCIOutput( const QString& ); | 160 | RemoteDevice::ValueList parseHCIOutput( const QString& ); |
161 | ConnectionState::ValueList parseConnections( const QString& ); | 161 | ConnectionState::ValueList parseConnections( const QString& ); |
162 | Opie::Core::OProcess *m_hcitool; | 162 | Opie::Core::OProcess *m_hcitool; |
163 | Opie::Core::OProcess *m_sdp; // not only one | 163 | Opie::Core::OProcess *m_sdp; // not only one |
164 | QString m_device; | 164 | QString m_device; |
165 | QMap<QString, int> m_signalStrength; | 165 | QMap<QString, int> m_signalStrength; |
166 | QMap<QString, QString> m_out; | 166 | QMap<QString, QString> m_out; |
167 | QMap<QString, QString> m_devices; | 167 | QMap<QString, QString> m_devices; |
168 | QMap<Opie::Core::OProcess*, QString> m_signalMac; | 168 | QMap<Opie::Core::OProcess*, QString> m_signalMac; |
169 | QString m_hcitoolCon; | 169 | QString m_hcitoolCon; |
170 | }; | 170 | }; |
171 | }; | 171 | }; |
172 | 172 | ||
173 | #endif | 173 | #endif |