summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opietooth/lib/parser.cc15
-rw-r--r--noncore/net/opietooth/lib/remotedevice.cc6
-rw-r--r--noncore/net/opietooth/lib/remotedevice.h4
3 files changed, 19 insertions, 6 deletions
diff --git a/noncore/net/opietooth/lib/parser.cc b/noncore/net/opietooth/lib/parser.cc
index 0699309..8baf284 100644
--- a/noncore/net/opietooth/lib/parser.cc
+++ b/noncore/net/opietooth/lib/parser.cc
@@ -1,194 +1,199 @@
1 1
2#include <qstringlist.h> 2#include <qstringlist.h>
3 3
4#include "parser.h" 4#include "parser.h"
5 5
6using namespace OpieTooth; 6using namespace OpieTooth;
7 7
8namespace { 8namespace {
9 9
10 10
11 // "Test Foo Bar" (0x3456) 11 // "Test Foo Bar" (0x3456)
12 // @param ret Test Foo Bar 12 // @param ret Test Foo Bar
13 // @eturn 13398 13 // @eturn 13398
14 // tactic find " ( 14 // tactic find " (
15int convert( const QString& line, QString& ret ) { 15int convert( const QString& line, QString& ret ) {
16// qWarning("called"); 16// qWarning("called");
17 ret = QString::null; 17 ret = QString::null;
18 int i = 0; 18 int i = 0;
19 int pos = line.findRev("\" ("); 19 int pos = line.findRev("\" (");
20 if ( pos > 0 ) { // it shouldn't be at pos 0 20 if ( pos > 0 ) { // it shouldn't be at pos 0
21 ret = line.left(pos ).stripWhiteSpace(); 21 ret = line.left(pos ).stripWhiteSpace();
22 // qWarning("ret: %s", ret.latin1() ); 22 // qWarning("ret: %s", ret.latin1() );
23 ret = ret.replace(QRegExp("[\"]"), ""); 23 ret = ret.replace(QRegExp("[\"]"), "");
24 //qWarning("ret: %s", ret.latin1() ); 24 //qWarning("ret: %s", ret.latin1() );
25 QString dummy = line.mid(pos + 5 ); 25 QString dummy = line.mid(pos + 5 );
26 //qWarning("dummy: %s", dummy.latin1() ); 26 //qWarning("dummy: %s", dummy.latin1() );
27 dummy = dummy.replace(QRegExp("[)]"), ""); 27 dummy = dummy.replace(QRegExp("[)]"), "");
28 //qWarning("dummy: %s", dummy.latin1() ); 28 //qWarning("dummy: %s", dummy.latin1() );
29// dummy = dummy.remove( dummy.length() -2, 1 ); // remove the ) 29// dummy = dummy.remove( dummy.length() -2, 1 ); // remove the )
30 bool ok; 30 bool ok;
31 i = dummy.toInt(&ok, 16 ); 31 i = dummy.toInt(&ok, 16 );
32 //if (ok ) { 32 //if (ok ) {
33 // qWarning("converted %d", i); 33 // qWarning("converted %d", i);
34 //}else qWarning("failed" ); 34 //}else qWarning("failed" );
35 //qWarning("exiting"); 35 //qWarning("exiting");
36 return i; 36 return i;
37 } 37 }
38 //qWarning("output %d", i ); 38 //qWarning("output %d", i );
39 return i; 39 return i;
40} 40}
41 41
42}; 42};
43 43
44 44
45Parser::Parser(const QString& output ) { 45Parser::Parser(const QString& output ) {
46 parse( output ); 46 parse( output );
47} 47}
48void Parser::setText(const QString& output) { 48void Parser::setText(const QString& output) {
49 parse( output ); 49 parse( output );
50} 50}
51Services::ValueList Parser::services() const { 51Services::ValueList Parser::services() const {
52 return m_list; 52 return m_list;
53} 53}
54void Parser::parse( const QString& string) { 54void Parser::parse( const QString& string) {
55 m_list.clear(); 55 m_list.clear();
56 m_complete = true; 56 m_complete = true;
57 QStringList list = QStringList::split('\n', string,TRUE ); 57 QStringList list = QStringList::split('\n', string,TRUE );
58 QStringList::Iterator it; 58 QStringList::Iterator it;
59 for (it = list.begin(); it != list.end(); ++it ) { 59 for (it = list.begin(); it != list.end(); ++it ) {
60 qWarning("line:%s:line", (*it).latin1() ); 60 //qWarning("line:%s:line", (*it).latin1() );
61 if ( (*it).startsWith("Browsing") ) continue; 61 if ( (*it).startsWith("Browsing") ) continue;
62 62
63 if ( (*it).stripWhiteSpace().isEmpty() ) { // line is empty because a new Service begins 63 if ( (*it).stripWhiteSpace().isEmpty() ) { // line is empty because a new Service begins
64 qWarning("could add"); 64 qWarning("could add");
65 // now see if complete and add 65 // now see if complete and add
66 if (m_complete ) { 66 if (m_complete ) {
67 if (!m_item.serviceName().isEmpty() ) 67 if (!m_item.serviceName().isEmpty() )
68 m_list.append( m_item ); 68 m_list.append( m_item );
69 Services serv; 69 Services serv;
70 m_item = serv; 70 m_item = serv;
71 m_complete = true; 71 m_complete = true;
72 continue; 72 continue;
73 } 73 }
74 } 74 }
75 if (parseName( (*it) ) ) ;//continue; 75 if (parseName( (*it) ) ) ;//continue;
76 if (parseRecHandle( (*it) ) ) ;//continue; 76 if (parseRecHandle( (*it) ) ) ;//continue;
77 if (parseClassId( (*it) ) ) ;//continue; 77 if (parseClassId( (*it) ) ) ;//continue;
78 if (parseProtocol( (*it) ) ) ;//continue; 78 if (parseProtocol( (*it) ) ) ;//continue;
79 if (parseProfile( (*it) ) ) ;//continue; 79 if (parseProfile( (*it) ) ) ;//continue;
80 } 80 }
81 // missed the last one 81 // missed the last one
82 if (m_complete) { 82 if (m_complete) {
83 qWarning("adding"); 83// qWarning("adding");
84 if (!m_item.serviceName().isEmpty() ) 84 if (!m_item.serviceName().isEmpty() )
85 m_list.append(m_item ); 85 m_list.append(m_item );
86 } 86 }
87 QValueList<Services>::Iterator it2; 87 QValueList<Services>::Iterator it2;
88 88
89 if (m_list.isEmpty() ) 89 if (m_list.isEmpty() )
90 qWarning("m_list is empty"); 90 qWarning("m_list is empty");
91 for (it2 = m_list.begin(); it2 != m_list.end(); ++it2 ) { 91 for (it2 = m_list.begin(); it2 != m_list.end(); ++it2 ) {
92 qWarning("name %s", (*it2).serviceName().latin1() ); 92 qWarning("name %s", (*it2).serviceName().latin1() );
93 } 93 }
94} 94}
95bool Parser::parseName( const QString& str) { 95bool Parser::parseName( const QString& str) {
96 if (str.startsWith("Service Name:") ) { 96 if (str.startsWith("Service Name:") ) {
97 m_item.setServiceName( str.mid(13).stripWhiteSpace() ); 97 m_item.setServiceName( str.mid(13).stripWhiteSpace() );
98 qWarning(m_item.serviceName() ); 98 qWarning(m_item.serviceName() );
99 return true; 99 return true;
100 } 100 }
101 return false; 101 return false;
102} 102}
103bool Parser::parseRecHandle( const QString& str) { 103bool Parser::parseRecHandle( const QString& str) {
104 if (str.startsWith("Service RecHandle:" ) ) { 104 if (str.startsWith("Service RecHandle:" ) ) {
105 QString out = str.mid(18 ).stripWhiteSpace(); 105 QString out = str.mid(18 ).stripWhiteSpace();
106 qWarning("out %s", out.latin1() ); 106 qWarning("out %s", out.latin1() );
107 int value = out.mid(2).toInt(&m_ok, 16 ); 107 int value = out.mid(2).toInt(&m_ok, 16 );
108 if (m_ok && (value != -1) ) 108 if (m_ok && (value != -1) )
109 m_complete = true; 109 m_complete = true;
110 else 110 else
111 m_complete = false; 111 m_complete = false;
112 qWarning("rec handle %d", value); 112 qWarning("rec handle %d", value);
113 m_item.setRecHandle( value ); 113 m_item.setRecHandle( value );
114 return true; 114 return true;
115 115
116 } 116 }
117 return false; 117 return false;
118} 118}
119bool Parser::parseClassId( const QString& str) { 119bool Parser::parseClassId( const QString& str) {
120 if (str.startsWith("Service Class ID List:") ) { 120 if (str.startsWith("Service Class ID List:") ) {
121 qWarning("found class id" );
122 qWarning("line:%s", str.latin1() );
121 m_classOver = true; 123 m_classOver = true;
122 return true; 124 return true;
123 }else if ( m_classOver && str.startsWith(" " ) ){ // ok now are the informations in place 125 }else if ( m_classOver && str.startsWith(" " ) ){ // ok now are the informations in place
124 126 qWarning("line with class id" );
127 qWarning("%s",str.latin1() );
125 128
126 // "Obex Object Push" (0x1105) 129 // "Obex Object Push" (0x1105)
127 // find backwards the " and the from 0 to pos and the mid pos+1 130 // find backwards the " and the from 0 to pos and the mid pos+1
128 // then stripWhiteSpace add name replace '"' with "" 131 // then stripWhiteSpace add name replace '"' with ""
129 // and then convert 0x1105 toInt() 132 // and then convert 0x1105 toInt()
130 QString classes; 133 QString classes;
131 int ids; 134 int ids;
132 ids = convert( str, classes ); 135 ids = convert( str, classes );
133 qWarning("ids %d", ids ); 136 qWarning("ids %d", ids );
134 m_item.insertClassId( ids, classes ); 137 m_item.insertClassId( ids, classes );
135 138
136 return true; 139 return true;
137 }else 140 }else{
141 qWarning("Else %d", m_classOver );
138 m_classOver = false; 142 m_classOver = false;
143 }
139 return false; 144 return false;
140} 145}
141bool Parser::parseProtocol( const QString& str) { 146bool Parser::parseProtocol( const QString& str) {
142 if (str.startsWith("Protocol Descriptor List:") ) { 147 if (str.startsWith("Protocol Descriptor List:") ) {
143 m_protocolOver = true; 148 m_protocolOver = true;
144 m_protocolAdded = false; 149 m_protocolAdded = false;
145 return true; 150 return true;
146 151
147 }else if (m_protocolOver && str.startsWith(" ") ) { // "L2CAP" (0x0100) 152 }else if (m_protocolOver && str.startsWith(" ") ) { // "L2CAP" (0x0100)
148 qWarning("double protocol filter"); 153 qWarning("double protocol filter");
149 154
150 if (!m_protocolAdded ) { // the protocol does neither supply a channel nor port so add it now 155 if (!m_protocolAdded ) { // the protocol does neither supply a channel nor port so add it now
151 Services::ProtocolDescriptor desc( m_protName, m_protId ); 156 Services::ProtocolDescriptor desc( m_protName, m_protId );
152 m_item.insertProtocolDescriptor( desc ); 157 m_item.insertProtocolDescriptor( desc );
153 } 158 }
154 m_protocolAdded = false; 159 m_protocolAdded = false;
155 { // the find function 160 { // the find function
156 m_protId = convert(str, m_protName ); 161 m_protId = convert(str, m_protName );
157 } 162 }
158 return true; 163 return true;
159 }else if (m_protocolOver && str.startsWith(" ") ) { 164 }else if (m_protocolOver && str.startsWith(" ") ) {
160 qWarning("tripple protocol filter"); 165 qWarning("tripple protocol filter");
161 m_protocolAdded = true; 166 m_protocolAdded = true;
162 QString dummy = str.stripWhiteSpace(); 167 QString dummy = str.stripWhiteSpace();
163 int pos = dummy.findRev(':'); 168 int pos = dummy.findRev(':');
164 if ( pos > -1 ) { 169 if ( pos > -1 ) {
165 int port = dummy.mid(pos+1 ).stripWhiteSpace().toInt(); 170 int port = dummy.mid(pos+1 ).stripWhiteSpace().toInt();
166 Services::ProtocolDescriptor desc( m_protName, m_protId, port ); 171 Services::ProtocolDescriptor desc( m_protName, m_protId, port );
167 m_item.insertProtocolDescriptor( desc ); 172 m_item.insertProtocolDescriptor( desc );
168 } 173 }
169 return true; 174 return true;
170 }else if (m_protocolOver ) { 175 }else if (m_protocolOver ) {
171 m_protocolOver = false; 176 m_protocolOver = false;
172 } 177 }
173 return false; 178 return false;
174} 179}
175bool Parser::parseProfile( const QString& str) { 180bool Parser::parseProfile( const QString& str) {
176 if (str.startsWith("Profile Descriptor List:") ) { 181 if (str.startsWith("Profile Descriptor List:") ) {
177 m_profOver = true; 182 m_profOver = true;
178 }else if ( m_profOver && str.startsWith(" ") ) { 183 }else if ( m_profOver && str.startsWith(" ") ) {
179 m_profId = convert( str, m_profName ); 184 m_profId = convert( str, m_profName );
180 }else if ( m_profOver && str.startsWith(" ") ) { 185 }else if ( m_profOver && str.startsWith(" ") ) {
181 // now find 186 // now find
182 int pos = str.findRev(':'); 187 int pos = str.findRev(':');
183 if ( pos > 0 ) { 188 if ( pos > 0 ) {
184 int dummy = str.mid(pos+1 ).stripWhiteSpace().toInt(); 189 int dummy = str.mid(pos+1 ).stripWhiteSpace().toInt();
185 qWarning("dummyInt:%d", dummy ); 190 qWarning("dummyInt:%d", dummy );
186 Services::ProfileDescriptor desc( m_profName, m_profId, dummy ); 191 Services::ProfileDescriptor desc( m_profName, m_profId, dummy );
187 m_item.insertProfileDescriptor(desc); 192 m_item.insertProfileDescriptor(desc);
188 } 193 }
189 }else 194 }else
190 m_profOver = false; 195 m_profOver = false;
191 196
192 197
193 return false; 198 return false;
194} 199}
diff --git a/noncore/net/opietooth/lib/remotedevice.cc b/noncore/net/opietooth/lib/remotedevice.cc
index 08fb397..9cf0cac 100644
--- a/noncore/net/opietooth/lib/remotedevice.cc
+++ b/noncore/net/opietooth/lib/remotedevice.cc
@@ -1,48 +1,54 @@
1 1
2#include "remotedevice.h" 2#include "remotedevice.h"
3 3
4using namespace OpieTooth; 4using namespace OpieTooth;
5 5
6bool operator==(const RemoteDevice& rem1, const RemoteDevice& rem2){ 6bool operator==(const RemoteDevice& rem1, const RemoteDevice& rem2){
7 if( ( rem1.mac() == rem2.mac() ) && (rem1.name() == rem2.name() ) ) 7 if( ( rem1.mac() == rem2.mac() ) && (rem1.name() == rem2.name() ) )
8 return true; 8 return true;
9 9
10 return false; 10 return false;
11} 11}
12 12
13RemoteDevice::RemoteDevice(){ 13RemoteDevice::RemoteDevice(){
14 14
15} 15}
16RemoteDevice::RemoteDevice(const RemoteDevice& ole ){ 16RemoteDevice::RemoteDevice(const RemoteDevice& ole ){
17 (*this) = ole; 17 (*this) = ole;
18} 18}
19RemoteDevice::RemoteDevice(const QString &mac, const QString& name ){ 19RemoteDevice::RemoteDevice(const QString &mac, const QString& name ){
20 m_mac = mac; 20 m_mac = mac;
21 m_name = name; 21 m_name = name;
22} 22}
23RemoteDevice::~RemoteDevice(){ 23RemoteDevice::~RemoteDevice(){
24 24
25} 25}
26bool RemoteDevice::isEmpty() const { 26bool RemoteDevice::isEmpty() const {
27 if( m_name.isEmpty() && m_mac.isEmpty() ) 27 if( m_name.isEmpty() && m_mac.isEmpty() )
28 return true; 28 return true;
29 return false; 29 return false;
30}; 30};
31RemoteDevice& RemoteDevice::operator=( const RemoteDevice& rem1){ 31RemoteDevice& RemoteDevice::operator=( const RemoteDevice& rem1){
32 m_name = rem1.m_name; 32 m_name = rem1.m_name;
33 m_mac = rem1.m_mac; 33 m_mac = rem1.m_mac;
34 return *this; 34 return *this;
35 35
36} 36}
37QString RemoteDevice::mac() const { 37QString RemoteDevice::mac() const {
38 return m_mac; 38 return m_mac;
39} 39}
40void RemoteDevice::setMac( const QString& mac ){ 40void RemoteDevice::setMac( const QString& mac ){
41 m_mac = mac; 41 m_mac = mac;
42} 42}
43QString RemoteDevice::name() const{ 43QString RemoteDevice::name() const{
44 return m_name; 44 return m_name;
45} 45}
46void RemoteDevice::setName( const QString& name ){ 46void RemoteDevice::setName( const QString& name ){
47 m_name = name; 47 m_name = name;
48} 48}
49bool RemoteDevice::equals( const RemoteDevice& dev ) const {
50 if ( m_mac == dev.m_mac && m_name == dev.m_name )
51 return true;
52 else
53 return false;
54};
diff --git a/noncore/net/opietooth/lib/remotedevice.h b/noncore/net/opietooth/lib/remotedevice.h
index 23f98bd..f268ccc 100644
--- a/noncore/net/opietooth/lib/remotedevice.h
+++ b/noncore/net/opietooth/lib/remotedevice.h
@@ -1,28 +1,30 @@
1 1
2#ifndef OpieToothRemoteDevice 2#ifndef OpieToothRemoteDevice
3#define OpieToothRemoteDevice 3#define OpieToothRemoteDevice
4 4
5#include <qvaluelist.h> 5#include <qvaluelist.h>
6 6
7namespace OpieTooth{ 7namespace OpieTooth{
8 class RemoteDevice { 8 class RemoteDevice {
9 public: 9 public:
10 typedef QValueList<RemoteDevice> ValueList; 10 typedef QValueList<RemoteDevice> ValueList;
11 RemoteDevice(); 11 RemoteDevice();
12 RemoteDevice(const RemoteDevice& ); 12 RemoteDevice(const RemoteDevice& );
13 RemoteDevice(const QString &mac, const QString &name ); 13 RemoteDevice(const QString &mac, const QString &name );
14 ~RemoteDevice(); 14 ~RemoteDevice();
15 friend bool operator==(const RemoteDevice&, const RemoteDevice&); 15// friend bool operator==(const RemoteDevice&, const RemoteDevice&);
16 RemoteDevice &operator=(const RemoteDevice& ); 16 RemoteDevice &operator=(const RemoteDevice& );
17 bool isEmpty()const; 17 bool isEmpty()const;
18 QString mac()const; 18 QString mac()const;
19 void setMac(const QString& mac ); 19 void setMac(const QString& mac );
20 QString name()const; 20 QString name()const;
21 void setName( const QString& name ); 21 void setName( const QString& name );
22 bool equals( const RemoteDevice& )const;
22 private: 23 private:
23 QString m_name; 24 QString m_name;
24 QString m_mac; 25 QString m_mac;
25 }; 26 };
27 bool operator==( const RemoteDevice&, const RemoteDevice& );
26}; 28};
27 29
28#endif 30#endif