author | zecke <zecke> | 2002-06-15 21:37:42 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-06-15 21:37:42 (UTC) |
commit | 9d02762b3d2e07f6db24c21621a5d577ea6acda7 (patch) (unidiff) | |
tree | d3a6ffb032a55991e4ef989f911f000090e29b09 | |
parent | 6f9b901d1f8db793a0e4a42f99f14f802e96f62e (diff) | |
download | opie-9d02762b3d2e07f6db24c21621a5d577ea6acda7.zip opie-9d02762b3d2e07f6db24c21621a5d577ea6acda7.tar.gz opie-9d02762b3d2e07f6db24c21621a5d577ea6acda7.tar.bz2 |
Manager should work now
-rw-r--r-- | noncore/net/opietooth/lib/manager.cc | 64 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/manager.h | 7 |
2 files changed, 69 insertions, 2 deletions
diff --git a/noncore/net/opietooth/lib/manager.cc b/noncore/net/opietooth/lib/manager.cc index eeeab19..d65dbd4 100644 --- a/noncore/net/opietooth/lib/manager.cc +++ b/noncore/net/opietooth/lib/manager.cc | |||
@@ -6,129 +6,191 @@ | |||
6 | using namespace OpieTooth; | 6 | using namespace OpieTooth; |
7 | 7 | ||
8 | Manager::Manager( const QString& dev ) | 8 | Manager::Manager( const QString& dev ) |
9 | : QObject() | 9 | : QObject() |
10 | { | 10 | { |
11 | m_device = dev; | 11 | m_device = dev; |
12 | m_hcitool = 0; | 12 | m_hcitool = 0; |
13 | m_sdp = 0; | 13 | m_sdp = 0; |
14 | } | 14 | } |
15 | Manager::Manager( Device* dev ) | 15 | Manager::Manager( Device* dev ) |
16 | : QObject() | 16 | : QObject() |
17 | { | 17 | { |
18 | m_hcitool = 0; | 18 | m_hcitool = 0; |
19 | m_sdp = 0; | 19 | m_sdp = 0; |
20 | } | 20 | } |
21 | Manager::Manager() | 21 | Manager::Manager() |
22 | : QObject() | 22 | : QObject() |
23 | { | 23 | { |
24 | m_hcitool = 0; | 24 | m_hcitool = 0; |
25 | m_sdp = 0; | 25 | m_sdp = 0; |
26 | } | 26 | } |
27 | Manager::~Manager(){ | 27 | Manager::~Manager(){ |
28 | delete m_hcitool; | 28 | delete m_hcitool; |
29 | delete m_sdp; | 29 | delete m_sdp; |
30 | } | 30 | } |
31 | void Manager::setDevice( const QString& dev ){ | 31 | void Manager::setDevice( const QString& dev ){ |
32 | m_device = dev; | 32 | m_device = dev; |
33 | } | 33 | } |
34 | void Manager::setDevice( Device* dev ){ | 34 | void Manager::setDevice( Device* dev ){ |
35 | 35 | ||
36 | } | 36 | } |
37 | void Manager::isConnected( const QString& device ){ | 37 | void Manager::isConnected( const QString& device ){ |
38 | OProcess* l2ping = new OProcess(); | 38 | OProcess* l2ping = new OProcess(); |
39 | l2ping->setName( device.latin1() ); | 39 | l2ping->setName( device.latin1() ); |
40 | *l2ping << "l2ping" << "-c1" << device; | 40 | *l2ping << "l2ping" << "-c1" << device; |
41 | connect(l2ping, SIGNAL(processExited(OProcess* ) ), | 41 | connect(l2ping, SIGNAL(processExited(OProcess* ) ), |
42 | this, SLOT(slotProcessExited(OProcess*) ) ); | 42 | this, SLOT(slotProcessExited(OProcess*) ) ); |
43 | if (!l2ping->start() ) { | 43 | if (!l2ping->start() ) { |
44 | emit connected( device, false ); | 44 | emit connected( device, false ); |
45 | delete l2ping; | 45 | delete l2ping; |
46 | } | 46 | } |
47 | 47 | ||
48 | } | 48 | } |
49 | void Manager::isConnected( Device* dev ){ | 49 | void Manager::isConnected( Device* dev ){ |
50 | 50 | ||
51 | 51 | ||
52 | } | 52 | } |
53 | void Manager::searchDevices( const QString& device ){ | 53 | void Manager::searchDevices( const QString& device ){ |
54 | 54 | OProcess* hcitool = new OProcess(); | |
55 | hcitool->setName( device.latin1() ); | ||
56 | *hcitool << "hcitool" << "scan"; | ||
57 | connect( hcitool, SIGNAL(processExited(OProcess*) ) , | ||
58 | this, SLOT(slotHCIExited(OProcess* ) ) ); | ||
59 | connect( hcitool, SIGNAL(receivedStdout(OProcess*, char*, int ) ), | ||
60 | this, SLOT(slotHCIOut(OProcess*, char*, int ) ) ); | ||
61 | if (!hcitool->start() ) { | ||
62 | RemoteDevices::ValueList list; | ||
63 | emit foundDevices( device, list ); | ||
64 | delete hcitool; | ||
65 | } | ||
55 | } | 66 | } |
56 | 67 | ||
57 | void Manager::searchDevices(Device* d ){ | 68 | void Manager::searchDevices(Device* d ){ |
58 | 69 | ||
59 | 70 | ||
60 | } | 71 | } |
61 | void Manager::addService(const QString& name ){ | 72 | void Manager::addService(const QString& name ){ |
62 | OProcess proc; | 73 | OProcess proc; |
63 | proc << "sdptool" << "add" << name; | 74 | proc << "sdptool" << "add" << name; |
64 | bool bo = true; | 75 | bool bo = true; |
65 | if (!proc.start(OProcess::DontCare ) ) | 76 | if (!proc.start(OProcess::DontCare ) ) |
66 | bo = false; | 77 | bo = false; |
67 | emit addedService( name, bo ); | 78 | emit addedService( name, bo ); |
68 | } | 79 | } |
69 | void Manager::addServices(const QStringList& list){ | 80 | void Manager::addServices(const QStringList& list){ |
70 | QStringList::ConstIterator it; | 81 | QStringList::ConstIterator it; |
71 | for (it = list.begin(); it != list.end(); ++it ) | 82 | for (it = list.begin(); it != list.end(); ++it ) |
72 | addService( (*it) ); | 83 | addService( (*it) ); |
73 | } | 84 | } |
74 | void Manager::removeService( const QString& name ){ | 85 | void Manager::removeService( const QString& name ){ |
75 | OProcess prc; | 86 | OProcess prc; |
76 | prc << "sdptool" << "del" << name; | 87 | prc << "sdptool" << "del" << name; |
77 | bool bo = true; | 88 | bool bo = true; |
78 | if (!prc.start(OProcess::DontCare ) ) | 89 | if (!prc.start(OProcess::DontCare ) ) |
79 | bo = false; | 90 | bo = false; |
80 | emit removedService( name, bo ); | 91 | emit removedService( name, bo ); |
81 | } | 92 | } |
82 | void Manager::removeServices( const QStringList& list){ | 93 | void Manager::removeServices( const QStringList& list){ |
83 | QStringList::ConstIterator it; | 94 | QStringList::ConstIterator it; |
84 | for (it = list.begin(); it != list.end(); ++it ) | 95 | for (it = list.begin(); it != list.end(); ++it ) |
85 | removeService( (*it) ); | 96 | removeService( (*it) ); |
86 | } | 97 | } |
87 | void Manager::searchServices( const QString& remDevice ){ | 98 | void Manager::searchServices( const QString& remDevice ){ |
88 | OProcess *m_sdp =new OProcess(); | 99 | OProcess *m_sdp =new OProcess(); |
89 | *m_sdp << "sdptool" << "browse" << remDevice; | 100 | *m_sdp << "sdptool" << "browse" << remDevice; |
90 | m_sdp->setName( remDevice.latin1() ); | 101 | m_sdp->setName( remDevice.latin1() ); |
91 | connect(m_sdp, SIGNAL(processExited(OProcess*) ), | 102 | connect(m_sdp, SIGNAL(processExited(OProcess*) ), |
92 | this, SLOT(slotSDPExited(OProcess* ) ) ); | 103 | this, SLOT(slotSDPExited(OProcess* ) ) ); |
93 | connect(m_sdp, SIGNAL(receivedStdout(OProcess*, char*, int ) ), | 104 | connect(m_sdp, SIGNAL(receivedStdout(OProcess*, char*, int ) ), |
94 | this, SLOT(slotSDPOut(OProcess*, char*, int) ) ); | 105 | this, SLOT(slotSDPOut(OProcess*, char*, int) ) ); |
95 | if (!m_sdp->start() ) { | 106 | if (!m_sdp->start() ) { |
96 | delete m_sdp; | 107 | delete m_sdp; |
97 | Services::ValueList list; | 108 | Services::ValueList list; |
98 | emit foundServices( remDevice, list ); | 109 | emit foundServices( remDevice, list ); |
99 | } | 110 | } |
100 | } | 111 | } |
101 | void Manager::searchServices( const RemoteDevices& dev){ | 112 | void Manager::searchServices( const RemoteDevices& dev){ |
102 | searchServices( dev.mac() ); | 113 | searchServices( dev.mac() ); |
103 | } | 114 | } |
104 | QString Manager::toDevice( const QString& mac ){ | 115 | QString Manager::toDevice( const QString& mac ){ |
105 | 116 | ||
106 | } | 117 | } |
107 | QString Manager::toMac( const QString &device ){ | 118 | QString Manager::toMac( const QString &device ){ |
108 | 119 | ||
109 | } | 120 | } |
110 | void Manager::slotProcessExited(OProcess* proc ) { | 121 | void Manager::slotProcessExited(OProcess* proc ) { |
111 | bool conn= false; | 122 | bool conn= false; |
112 | if (proc->normalExit() && proc->exitStatus() == 0 ) | 123 | if (proc->normalExit() && proc->exitStatus() == 0 ) |
113 | conn = true; | 124 | conn = true; |
114 | 125 | ||
115 | QString name = QString::fromLatin1(proc->name() ); | 126 | QString name = QString::fromLatin1(proc->name() ); |
116 | emit connected( name, conn ); | 127 | emit connected( name, conn ); |
117 | delete proc; | 128 | delete proc; |
118 | } | 129 | } |
119 | void Manager::slotSDPOut(OProcess* proc, char* ch, int len) | 130 | void Manager::slotSDPOut(OProcess* proc, char* ch, int len) |
120 | { | 131 | { |
121 | QCString str(ch, len+1 ); | 132 | QCString str(ch, len+1 ); |
122 | QMap<QString, QString>::Iterator it; | 133 | QMap<QString, QString>::Iterator it; |
123 | it = m_out.find(proc->name() ); | 134 | it = m_out.find(proc->name() ); |
124 | if ( it != m_out.end() ) { | 135 | if ( it != m_out.end() ) { |
125 | QString string = it.data(); | 136 | QString string = it.data(); |
126 | string.append( str ); | 137 | string.append( str ); |
127 | m_out.replace( proc->name(), string ); | 138 | m_out.replace( proc->name(), string ); |
128 | } | 139 | } |
129 | 140 | ||
130 | } | 141 | } |
131 | void Manager::slotSDPExited( OProcess* proc) | 142 | void Manager::slotSDPExited( OProcess* proc) |
132 | { | 143 | { |
144 | Services::ValueList list; | ||
145 | if (proc->normalExit() ) { | ||
146 | QMap<QString, QString>::Iterator it = m_out.find( proc->name() ); | ||
147 | if ( it != m_out.end() ) { | ||
148 | list = parseSDPOutput( it.data() ); | ||
149 | m_out.remove( it ); | ||
150 | } | ||
151 | } | ||
152 | emit foundServices( proc->name(), list ); | ||
153 | delete proc; | ||
154 | } | ||
155 | Services::ValueList Manager::parseSDPOutput( const QString& out ) { | ||
156 | Services::ValueList list; | ||
157 | return list; | ||
158 | } | ||
159 | |||
160 | void Manager::slotHCIExited(OProcess* proc ) { | ||
161 | RemoteDevices::ValueList list; | ||
162 | if (proc->normalExit() ) { | ||
163 | QMap<QString, QString>::Iterator it = m_devices.find(proc->name() ); | ||
164 | if (it != m_devices.end() ) { | ||
165 | list = parseHCIOutput( it.data() ); | ||
166 | m_devices.remove( it ); | ||
167 | } | ||
168 | } | ||
169 | emit foundDevices( proc->name(), list ); | ||
133 | delete proc; | 170 | delete proc; |
134 | } | 171 | } |
172 | void Manager::slotHCIOut(OProcess* proc, char* ch, int len) { | ||
173 | QCString str( ch, len+1 ); | ||
174 | QMap<QString, QString>::Iterator it; | ||
175 | it = m_devices.find( proc->name() ); | ||
176 | if (it != m_devices.end() ) { | ||
177 | QString string = it.data(); | ||
178 | string.append( str ); | ||
179 | m_devices.replace( proc->name(), string ); | ||
180 | } | ||
181 | } | ||
182 | RemoteDevices::ValueList Manager::parseHCIOutput(const QString& output ) { | ||
183 | RemoteDevices::ValueList list; | ||
184 | QStringList strList = QStringList::split('\n', output ); | ||
185 | QStringList::Iterator it; | ||
186 | QString str; | ||
187 | for ( it = strList.begin(); it != strList.end(); ++it ) { | ||
188 | str = (*it).stripWhiteSpace(); | ||
189 | qWarning("OpieTooth %s", str.latin1() ); | ||
190 | QStringList split = QStringList::split(" ", str ); | ||
191 | qWarning("Left:%s Right:%s", split[0].latin1() , split[1].latin1() ); | ||
192 | RemoteDevices rem( split[0].latin1() , split[1].latin1() ); | ||
193 | list.append( rem ); | ||
194 | } | ||
195 | return list; | ||
196 | } | ||
diff --git a/noncore/net/opietooth/lib/manager.h b/noncore/net/opietooth/lib/manager.h index 03375c5..95e4306 100644 --- a/noncore/net/opietooth/lib/manager.h +++ b/noncore/net/opietooth/lib/manager.h | |||
@@ -65,62 +65,67 @@ Q_OBJECT | |||
65 | */ | 65 | */ |
66 | void searchDevices(const QString& device= QString::null ); | 66 | void searchDevices(const QString& device= QString::null ); |
67 | /** same as above | 67 | /** same as above |
68 | * | 68 | * |
69 | */ | 69 | */ |
70 | void searchDevices(Device *d ); | 70 | void searchDevices(Device *d ); |
71 | 71 | ||
72 | /** | 72 | /** |
73 | * This will add the service @param name | 73 | * This will add the service @param name |
74 | * to the sdpd daemon | 74 | * to the sdpd daemon |
75 | * It will start the daemon if necessary | 75 | * It will start the daemon if necessary |
76 | */ | 76 | */ |
77 | void addService(const QString &name ); | 77 | void addService(const QString &name ); |
78 | /** | 78 | /** |
79 | * This will add the services @param names | 79 | * This will add the services @param names |
80 | * to the sdpd daemon | 80 | * to the sdpd daemon |
81 | * It will start the daemon if necessary | 81 | * It will start the daemon if necessary |
82 | */ | 82 | */ |
83 | void addServices( const QStringList& names ); | 83 | void addServices( const QStringList& names ); |
84 | /** | 84 | /** |
85 | * This removes a service from the sdps | 85 | * This removes a service from the sdps |
86 | */ | 86 | */ |
87 | void removeService(const QString &name ); | 87 | void removeService(const QString &name ); |
88 | /** | 88 | /** |
89 | * Removes a list from the sdpd | 89 | * Removes a list from the sdpd |
90 | */ | 90 | */ |
91 | void removeServices(const QStringList& ); | 91 | void removeServices(const QStringList& ); |
92 | 92 | ||
93 | /** | 93 | /** |
94 | * search for services on a remote device | 94 | * search for services on a remote device |
95 | * | 95 | * |
96 | */ | 96 | */ |
97 | void searchServices( const QString& remDevice ); | 97 | void searchServices( const QString& remDevice ); |
98 | /** | 98 | /** |
99 | * search for services on a remote device | 99 | * search for services on a remote device |
100 | */ | 100 | */ |
101 | void searchServices( const RemoteDevices& ); | 101 | void searchServices( const RemoteDevices& ); |
102 | /*static*/ QString toDevice( const QString& mac ); | 102 | /*static*/ QString toDevice( const QString& mac ); |
103 | /*static*/ QString toMac( const QString &device ); | 103 | /*static*/ QString toMac( const QString &device ); |
104 | 104 | ||
105 | signals: | 105 | signals: |
106 | // device either mac or dev name | 106 | // device either mac or dev name |
107 | // the first device is the device which you access | 107 | // the first device is the device which you access |
108 | void connected( const QString& device, bool connected ); | 108 | void connected( const QString& device, bool connected ); |
109 | void addedService( const QString& service, bool added ); | 109 | void addedService( const QString& service, bool added ); |
110 | void removedService( const QString& service, bool removed ); | 110 | void removedService( const QString& service, bool removed ); |
111 | void foundServices( const QString& device, Services::ValueList ); | 111 | void foundServices( const QString& device, Services::ValueList ); |
112 | void foundDevices( const QString& device, RemoteDevices::ValueList ); | 112 | void foundDevices( const QString& device, RemoteDevices::ValueList ); |
113 | void foundNothing( const QString& device ); | 113 | |
114 | private slots: | 114 | private slots: |
115 | void slotProcessExited(OProcess* ); | 115 | void slotProcessExited(OProcess* ); |
116 | void slotSDPExited(OProcess*); | 116 | void slotSDPExited(OProcess*); |
117 | void slotSDPOut(OProcess*, char*, int); | 117 | void slotSDPOut(OProcess*, char*, int); |
118 | void slotHCIExited(OProcess* ); | ||
119 | void slotHCIOut(OProcess*, char*, int ); | ||
118 | private: | 120 | private: |
121 | Services::ValueList parseSDPOutput( const QString& ); | ||
122 | RemoteDevices::ValueList parseHCIOutput( const QString& ); | ||
119 | OProcess *m_hcitool; | 123 | OProcess *m_hcitool; |
120 | OProcess *m_sdp; // not only one | 124 | OProcess *m_sdp; // not only one |
121 | QString m_device; | 125 | QString m_device; |
122 | QMap<QString, QString> m_out; | 126 | QMap<QString, QString> m_out; |
127 | QMap<QString, QString> m_devices; | ||
123 | }; | 128 | }; |
124 | }; | 129 | }; |
125 | 130 | ||
126 | #endif | 131 | #endif |