-rw-r--r-- | noncore/net/opietooth/lib/manager.cc | 22 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/parser.cc | 90 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/parser.h | 3 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/services.cc | 66 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/services.h | 15 |
5 files changed, 142 insertions, 54 deletions
diff --git a/noncore/net/opietooth/lib/manager.cc b/noncore/net/opietooth/lib/manager.cc index fcd21f6..177c94e 100644 --- a/noncore/net/opietooth/lib/manager.cc +++ b/noncore/net/opietooth/lib/manager.cc | |||
@@ -1,4 +1,7 @@ | |||
1 | |||
2 | |||
1 | #include <opie/oprocess.h> | 3 | #include <opie/oprocess.h> |
2 | 4 | ||
5 | #include "parser.h" | ||
3 | #include "manager.h" | 6 | #include "manager.h" |
4 | 7 | ||
@@ -14,5 +17,5 @@ Manager::Manager( const QString& dev ) | |||
14 | m_sdp = 0; | 17 | m_sdp = 0; |
15 | } | 18 | } |
16 | Manager::Manager( Device* dev ) | 19 | Manager::Manager( Device* /*dev*/ ) |
17 | : QObject() | 20 | : QObject() |
18 | { | 21 | { |
@@ -33,5 +36,5 @@ void Manager::setDevice( const QString& dev ){ | |||
33 | m_device = dev; | 36 | m_device = dev; |
34 | } | 37 | } |
35 | void Manager::setDevice( Device* dev ){ | 38 | void Manager::setDevice( Device* /*dev*/ ){ |
36 | 39 | ||
37 | } | 40 | } |
@@ -48,5 +51,6 @@ void Manager::isAvailable( const QString& device ){ | |||
48 | 51 | ||
49 | } | 52 | } |
50 | void Manager::isAvailable( Device* dev ){ | 53 | |
54 | void Manager::isAvailable( Device* /*dev*/ ){ | ||
51 | 55 | ||
52 | 56 | ||
@@ -69,5 +73,5 @@ void Manager::searchDevices( const QString& device ){ | |||
69 | } | 73 | } |
70 | 74 | ||
71 | void Manager::searchDevices(Device* d ){ | 75 | void Manager::searchDevices(Device* /*d*/ ){ |
72 | 76 | ||
73 | 77 | ||
@@ -116,9 +120,9 @@ void Manager::searchServices( const RemoteDevice& dev){ | |||
116 | searchServices( dev.mac() ); | 120 | searchServices( dev.mac() ); |
117 | } | 121 | } |
118 | QString Manager::toDevice( const QString& mac ){ | 122 | QString Manager::toDevice( const QString& /*mac*/ ){ |
119 | 123 | return QString::null; | |
120 | } | 124 | } |
121 | QString Manager::toMac( const QString &device ){ | 125 | QString Manager::toMac( const QString &/*device*/ ){ |
122 | 126 | return QString::null; | |
123 | } | 127 | } |
124 | void Manager::slotProcessExited(OProcess* proc ) { | 128 | void Manager::slotProcessExited(OProcess* proc ) { |
@@ -158,4 +162,6 @@ void Manager::slotSDPExited( OProcess* proc) | |||
158 | Services::ValueList Manager::parseSDPOutput( const QString& out ) { | 162 | Services::ValueList Manager::parseSDPOutput( const QString& out ) { |
159 | Services::ValueList list; | 163 | Services::ValueList list; |
164 | Parser parser( out ); | ||
165 | list = parser.services(); | ||
160 | return list; | 166 | return list; |
161 | } | 167 | } |
diff --git a/noncore/net/opietooth/lib/parser.cc b/noncore/net/opietooth/lib/parser.cc index 452917b..18d534e 100644 --- a/noncore/net/opietooth/lib/parser.cc +++ b/noncore/net/opietooth/lib/parser.cc | |||
@@ -6,4 +6,32 @@ | |||
6 | using namespace OpieTooth; | 6 | using namespace OpieTooth; |
7 | 7 | ||
8 | namespace { | ||
9 | |||
10 | |||
11 | // "Test Foo Bar" (0x3456) | ||
12 | // @param ret Test Foo Bar | ||
13 | // @eturn 13398 | ||
14 | // tactic find " ( | ||
15 | int convert( const QString& line, QString& ret ) { | ||
16 | ret = QString::null; | ||
17 | int i = 0; | ||
18 | int pos = line.findRev("\" ("); | ||
19 | if ( pos > 0 ) { // it shouldn't be at pos 0 | ||
20 | ret = line.left(pos-1 ).stripWhiteSpace(); | ||
21 | qWarning("ret: %s", ret.latin1() ); | ||
22 | ret = ret.replace(QRegExp("[\"]"), ""); | ||
23 | qWarning("ret: %s", ret.latin1() ); | ||
24 | QString dummy = line.mid(pos + 4 ); | ||
25 | qWarning("dummy: %s", dummy.latin1() ); | ||
26 | dummy = dummy.remove( dummy.length() -1, 1 ); // remove the ( | ||
27 | bool ok; | ||
28 | i = dummy.toInt(&ok, 16 ); | ||
29 | } | ||
30 | return i; | ||
31 | } | ||
32 | |||
33 | }; | ||
34 | |||
35 | |||
8 | Parser::Parser(const QString& output ) { | 36 | Parser::Parser(const QString& output ) { |
9 | parse( output ); | 37 | parse( output ); |
@@ -29,4 +57,5 @@ void Parser::parse( const QString& string) { | |||
29 | Services serv; | 57 | Services serv; |
30 | m_item = serv; | 58 | m_item = serv; |
59 | m_complete = true; | ||
31 | continue; | 60 | continue; |
32 | } | 61 | } |
@@ -38,4 +67,8 @@ void Parser::parse( const QString& string) { | |||
38 | if (parseProfile( (*it) ) ) ;//continue; | 67 | if (parseProfile( (*it) ) ) ;//continue; |
39 | } | 68 | } |
69 | // missed the last one | ||
70 | if (m_complete) { | ||
71 | m_list.append(m_item ); | ||
72 | } | ||
40 | } | 73 | } |
41 | bool Parser::parseName( const QString& str) { | 74 | bool Parser::parseName( const QString& str) { |
@@ -68,17 +101,16 @@ bool Parser::parseClassId( const QString& str) { | |||
68 | 101 | ||
69 | m_classOver = false; | 102 | m_classOver = false; |
70 | QStringList list = QStringList::split('\n', str.stripWhiteSpace() ); | 103 | |
71 | 104 | // "Obex Object Push" (0x1105) | |
72 | if ( list.count() == 2 ) { | 105 | // find backwards the " and the from 0 to pos and the mid pos+1 |
73 | m_item.setClassIdList( list[0] ); | 106 | // then stripWhiteSpace add name replace '"' with "" |
74 | // now let's parse the number (0x1105) | 107 | // and then convert 0x1105 toInt() |
75 | QString classId= list[1]; | 108 | QString classes; |
76 | int classIdInt; | 109 | int ids; |
77 | qWarning("%s", list[1].latin1() ); | 110 | ids = convert( str, classes ); |
78 | classId = classId.remove(0, 3 ); | 111 | qWarning("ids %d", ids ); |
79 | classId = classId.remove( classId.length()-1, 1 ); | 112 | m_item.setClassIdList( classes ); |
80 | qWarning("%s", classId.latin1() ); | 113 | m_item.setClassIdList( ids ); |
81 | m_item.setClassIdList( classId.toInt(&m_ok, 16 ) ); | 114 | |
82 | } | ||
83 | return true; | 115 | return true; |
84 | }else | 116 | }else |
@@ -92,6 +124,7 @@ bool Parser::parseProtocol( const QString& str) { | |||
92 | return true; | 124 | return true; |
93 | 125 | ||
94 | }else if (m_protocolOver && str.startsWith(" ") ) { | 126 | }else if (m_protocolOver && str.startsWith(" ") ) { // "L2CAP" (0x0100) |
95 | qWarning("double protocol filter"); | 127 | qWarning("double protocol filter"); |
128 | |||
96 | if (!m_protocolAdded ) { // the protocol does neither supply a channel nor port so add it now | 129 | if (!m_protocolAdded ) { // the protocol does neither supply a channel nor port so add it now |
97 | Services::ProtocolDescriptor desc( m_protName, m_protId ); | 130 | Services::ProtocolDescriptor desc( m_protName, m_protId ); |
@@ -99,8 +132,18 @@ bool Parser::parseProtocol( const QString& str) { | |||
99 | } | 132 | } |
100 | m_protocolAdded = false; | 133 | m_protocolAdded = false; |
134 | { // the find function | ||
135 | m_protId = convert(str, m_protName ); | ||
136 | } | ||
101 | return true; | 137 | return true; |
102 | }else if (m_protocolOver && str.startsWith(" ") ) { | 138 | }else if (m_protocolOver && str.startsWith(" ") ) { |
103 | qWarning("tripple protocol filter"); | 139 | qWarning("tripple protocol filter"); |
104 | m_protocolAdded = true; | 140 | m_protocolAdded = true; |
141 | QString dummy = str.stripWhiteSpace(); | ||
142 | int pos = dummy.findRev(':'); | ||
143 | if ( pos > -1 ) { | ||
144 | int port = dummy.mid(pos+1 ).stripWhiteSpace().toInt(); | ||
145 | Services::ProtocolDescriptor desc( m_protName, m_protId, port ); | ||
146 | m_item.insertProtocolDescriptor( desc ); | ||
147 | } | ||
105 | return true; | 148 | return true; |
106 | }else if (m_protocolOver ) { | 149 | }else if (m_protocolOver ) { |
@@ -109,5 +152,22 @@ bool Parser::parseProtocol( const QString& str) { | |||
109 | return false; | 152 | return false; |
110 | } | 153 | } |
111 | bool Parser::parseProfile( const QString& ) { | 154 | bool Parser::parseProfile( const QString& str) { |
155 | if (str.startsWith("Profile Descriptor List:") ) { | ||
156 | m_profOver = true; | ||
157 | }else if ( m_profOver && str.startsWith(" ") ) { | ||
158 | m_profId = convert( str, m_profName ); | ||
159 | }else if ( m_profOver && str.startsWith(" ") ) { | ||
160 | // now find | ||
161 | int pos = str.findRev(':'); | ||
162 | if ( pos > 0 ) { | ||
163 | int dummy = str.mid(pos+1 ).stripWhiteSpace().toInt(); | ||
164 | qWarning("dummyInt:%d", dummy ); | ||
165 | Services::ProfileDescriptor desc( m_profName, m_profId, dummy ); | ||
166 | m_item.insertProfileDescriptor(desc); | ||
167 | } | ||
168 | }else | ||
169 | m_profOver = false; | ||
170 | |||
171 | |||
112 | return false; | 172 | return false; |
113 | } | 173 | } |
diff --git a/noncore/net/opietooth/lib/parser.h b/noncore/net/opietooth/lib/parser.h index 7642ac3..520a725 100644 --- a/noncore/net/opietooth/lib/parser.h +++ b/noncore/net/opietooth/lib/parser.h | |||
@@ -24,8 +24,11 @@ namespace OpieTooth { | |||
24 | bool m_ok; | 24 | bool m_ok; |
25 | bool m_classOver:1; | 25 | bool m_classOver:1; |
26 | bool m_profOver:1; | ||
26 | bool m_protocolOver:1; | 27 | bool m_protocolOver:1; |
27 | bool m_protocolAdded:1; | 28 | bool m_protocolAdded:1; |
28 | QString m_protName; | 29 | QString m_protName; |
29 | int m_protId; | 30 | int m_protId; |
31 | QString m_profName; | ||
32 | int m_profId; | ||
30 | }; | 33 | }; |
31 | }; | 34 | }; |
diff --git a/noncore/net/opietooth/lib/services.cc b/noncore/net/opietooth/lib/services.cc index d91e4a1..93ee70a 100644 --- a/noncore/net/opietooth/lib/services.cc +++ b/noncore/net/opietooth/lib/services.cc | |||
@@ -106,63 +106,77 @@ Services::Services(){ | |||
106 | } | 106 | } |
107 | Services::Services(const Services& service ){ | 107 | Services::Services(const Services& service ){ |
108 | 108 | (*this) = service; | |
109 | } | 109 | } |
110 | Services::~Services(){ | 110 | Services::~Services(){ |
111 | 111 | ||
112 | } | 112 | } |
113 | Services &Services::operator=( const Services& ){ | 113 | Services &Services::operator=( const Services& ser){ |
114 | m_name = ser.m_name; | ||
115 | m_recHandle = ser.m_recHandle; | ||
116 | m_classList = ser.m_classList; | ||
117 | m_classId = ser.m_classId; | ||
118 | m_protocols = ser.m_protocols; | ||
119 | m_profiles = ser.m_profiles; | ||
114 | return *this; | 120 | return *this; |
115 | } | 121 | } |
116 | bool operator==( const Services&, | 122 | bool operator==( const Services& one, |
117 | const Services& ){ | 123 | const Services& two){ |
124 | if ( ( one.recHandle() == two.recHandle() ) && | ||
125 | ( one.classIdListInt() == two.classIdListInt() ) && | ||
126 | ( one.serviceName() == two.serviceName() ) && | ||
127 | ( one.classIdList() == two.classIdList() ) && | ||
128 | ( one.protocolDescriptorList() == two.protocolDescriptorList() ) && | ||
129 | ( one.profileDescriptor() == two.profileDescriptor() ) ) | ||
130 | return true; | ||
118 | return false; | 131 | return false; |
119 | } | 132 | } |
120 | QString Services::serviceName() const{ | 133 | QString Services::serviceName() const{ |
121 | 134 | return m_name; | |
122 | } | 135 | } |
123 | void Services::setServiceName( const QString& service ){ | 136 | void Services::setServiceName( const QString& service ){ |
124 | 137 | m_name = service; | |
125 | } | 138 | } |
126 | int Services::recHandle() const{ | 139 | int Services::recHandle() const{ |
127 | 140 | return m_recHandle; | |
128 | } | 141 | } |
129 | void Services::setRecHandle( int ){ | 142 | void Services::setRecHandle( int handle){ |
130 | 143 | m_recHandle = handle; | |
131 | } | 144 | } |
132 | QString Services::classIdList() const{ | 145 | QString Services::classIdList() const{ |
133 | 146 | return m_classList; | |
134 | } | 147 | } |
135 | void Services::setClassIdList( const QString& ){ | 148 | void Services::setClassIdList( const QString& str){ |
136 | 149 | m_classList = str; | |
137 | } | 150 | } |
138 | int Services::classIdListInt() const{ | 151 | int Services::classIdListInt() const{ |
139 | 152 | return m_classId; | |
140 | } | 153 | } |
141 | void Services::setClassIdList(int ){ | 154 | void Services::setClassIdList(int id){ |
142 | 155 | m_classId = id; | |
143 | } | 156 | } |
144 | void Services::insertProtocolDescriptor( const ProtocolDescriptor& ){ | 157 | void Services::insertProtocolDescriptor( const ProtocolDescriptor& prot){ |
145 | 158 | m_protocols.append( prot ); | |
146 | } | 159 | } |
147 | void Services::clearProtocolDescriptorList(){ | 160 | void Services::clearProtocolDescriptorList(){ |
148 | 161 | m_protocols.clear(); | |
149 | } | 162 | } |
150 | void Services::removeProtocolDescriptor( const ProtocolDescriptor& ){ | 163 | void Services::removeProtocolDescriptor( const ProtocolDescriptor& prot){ |
151 | 164 | m_protocols.remove( prot ); | |
152 | } | 165 | } |
153 | Services::ProtocolDescriptor::ValueList Services::protocolDescriptorList()const{ | 166 | Services::ProtocolDescriptor::ValueList Services::protocolDescriptorList()const{ |
154 | 167 | return m_protocols; | |
155 | } | 168 | } |
156 | 169 | ||
157 | void Services::insertProfileDescriptor( const ProfileDescriptor& ){ | ||
158 | 170 | ||
171 | void Services::insertProfileDescriptor( const ProfileDescriptor& prof){ | ||
172 | m_profiles.append( prof ); | ||
159 | } | 173 | } |
160 | void Services::clearProfileDescriptorList(){ | 174 | void Services::clearProfileDescriptorList(){ |
161 | 175 | m_profiles.clear(); | |
162 | } | 176 | } |
163 | void Services::removeProfileDescriptor( const ProfileDescriptor& ){ | 177 | void Services::removeProfileDescriptor( const ProfileDescriptor& prof){ |
164 | 178 | m_profiles.remove(prof ); | |
165 | } | 179 | } |
166 | Services::ProfileDescriptor::ValueList Services::profileDescriptor() const{ | 180 | Services::ProfileDescriptor::ValueList Services::profileDescriptor() const{ |
167 | 181 | return m_profiles; | |
168 | } | 182 | } |
diff --git a/noncore/net/opietooth/lib/services.h b/noncore/net/opietooth/lib/services.h index 65de049..881d383 100644 --- a/noncore/net/opietooth/lib/services.h +++ b/noncore/net/opietooth/lib/services.h | |||
@@ -64,5 +64,5 @@ namespace OpieTooth { | |||
64 | * operator== | 64 | * operator== |
65 | */ | 65 | */ |
66 | friend bool operator==(const ProfileDescriptor&, const ProfileDescriptor& ); | 66 | // friend bool operator==(const ProfileDescriptor&, const ProfileDescriptor& ); |
67 | private: | 67 | private: |
68 | QString m_id; | 68 | QString m_id; |
@@ -95,6 +95,6 @@ namespace OpieTooth { | |||
95 | void setPort(int ); | 95 | void setPort(int ); |
96 | ProtocolDescriptor &operator=( const ProtocolDescriptor& ); | 96 | ProtocolDescriptor &operator=( const ProtocolDescriptor& ); |
97 | friend bool operator==( const ProtocolDescriptor&, | 97 | //friend bool operator==( const ProtocolDescriptor&, |
98 | const ProtocolDescriptor& ); | 98 | // const ProtocolDescriptor& ); |
99 | private: | 99 | private: |
100 | QString m_name; | 100 | QString m_name; |
@@ -132,6 +132,11 @@ namespace OpieTooth { | |||
132 | ProfileDescriptor::ValueList profileDescriptor()const; | 132 | ProfileDescriptor::ValueList profileDescriptor()const; |
133 | 133 | ||
134 | 134 | private: | |
135 | 135 | QString m_name; | |
136 | int m_recHandle; | ||
137 | QString m_classList; | ||
138 | int m_classId; | ||
139 | QValueList<ProfileDescriptor> m_profiles; | ||
140 | QValueList<ProtocolDescriptor> m_protocols; | ||
136 | }; | 141 | }; |
137 | }; | 142 | }; |