author | zecke <zecke> | 2002-06-20 22:23:44 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-06-20 22:23:44 (UTC) |
commit | 7b4a1dfd56b64e588d3fe6c75a51490df13e9797 (patch) (unidiff) | |
tree | 43db3e094004ad478c43d93ddeafed044534035e | |
parent | c2eb66bc5c5ac4225edff8b369026bd208f8c148 (diff) | |
download | opie-7b4a1dfd56b64e588d3fe6c75a51490df13e9797.zip opie-7b4a1dfd56b64e588d3fe6c75a51490df13e9797.tar.gz opie-7b4a1dfd56b64e588d3fe6c75a51490df13e9797.tar.bz2 |
German politicians suck
-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,6 +1,9 @@ | |||
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 | ||
5 | 8 | ||
6 | using namespace OpieTooth; | 9 | using namespace OpieTooth; |
@@ -12,9 +15,9 @@ Manager::Manager( const QString& dev ) | |||
12 | m_device = dev; | 15 | m_device = dev; |
13 | m_hcitool = 0; | 16 | m_hcitool = 0; |
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 | { |
19 | m_hcitool = 0; | 22 | m_hcitool = 0; |
20 | m_sdp = 0; | 23 | m_sdp = 0; |
@@ -31,9 +34,9 @@ Manager::~Manager(){ | |||
31 | } | 34 | } |
32 | void Manager::setDevice( const QString& dev ){ | 35 | 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 | } |
38 | void Manager::isAvailable( const QString& device ){ | 41 | void Manager::isAvailable( const QString& device ){ |
39 | OProcess* l2ping = new OProcess(); | 42 | OProcess* l2ping = new OProcess(); |
@@ -46,9 +49,10 @@ void Manager::isAvailable( const QString& device ){ | |||
46 | delete l2ping; | 49 | delete l2ping; |
47 | } | 50 | } |
48 | 51 | ||
49 | } | 52 | } |
50 | void Manager::isAvailable( Device* dev ){ | 53 | |
54 | void Manager::isAvailable( Device* /*dev*/ ){ | ||
51 | 55 | ||
52 | 56 | ||
53 | } | 57 | } |
54 | void Manager::searchDevices( const QString& device ){ | 58 | void Manager::searchDevices( const QString& device ){ |
@@ -67,9 +71,9 @@ void Manager::searchDevices( const QString& device ){ | |||
67 | delete hcitool; | 71 | delete hcitool; |
68 | } | 72 | } |
69 | } | 73 | } |
70 | 74 | ||
71 | void Manager::searchDevices(Device* d ){ | 75 | void Manager::searchDevices(Device* /*d*/ ){ |
72 | 76 | ||
73 | 77 | ||
74 | } | 78 | } |
75 | void Manager::addService(const QString& name ){ | 79 | void Manager::addService(const QString& name ){ |
@@ -114,13 +118,13 @@ void Manager::searchServices( const QString& remDevice ){ | |||
114 | } | 118 | } |
115 | void Manager::searchServices( const RemoteDevice& dev){ | 119 | 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 ) { |
125 | bool conn= false; | 129 | bool conn= false; |
126 | if (proc->normalExit() && proc->exitStatus() == 0 ) | 130 | if (proc->normalExit() && proc->exitStatus() == 0 ) |
@@ -156,8 +160,10 @@ void Manager::slotSDPExited( OProcess* proc) | |||
156 | delete proc; | 160 | delete proc; |
157 | } | 161 | } |
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 | } |
162 | 168 | ||
163 | void Manager::slotHCIExited(OProcess* proc ) { | 169 | void Manager::slotHCIExited(OProcess* proc ) { |
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 | |||
@@ -4,8 +4,36 @@ | |||
4 | #include "parser.h" | 4 | #include "parser.h" |
5 | 5 | ||
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 ); |
10 | } | 38 | } |
11 | void Parser::setText(const QString& output) { | 39 | void Parser::setText(const QString& output) { |
@@ -27,8 +55,9 @@ void Parser::parse( const QString& string) { | |||
27 | if (m_complete ) { | 55 | if (m_complete ) { |
28 | m_list.append( m_item ); | 56 | m_list.append( m_item ); |
29 | Services serv; | 57 | Services serv; |
30 | m_item = serv; | 58 | m_item = serv; |
59 | m_complete = true; | ||
31 | continue; | 60 | continue; |
32 | } | 61 | } |
33 | } | 62 | } |
34 | if (parseName( (*it) ) ) ;//continue; | 63 | if (parseName( (*it) ) ) ;//continue; |
@@ -36,8 +65,12 @@ void Parser::parse( const QString& string) { | |||
36 | if (parseClassId( (*it) ) ) ;//continue; | 65 | if (parseClassId( (*it) ) ) ;//continue; |
37 | if (parseProtocol( (*it) ) ) ;//continue; | 66 | if (parseProtocol( (*it) ) ) ;//continue; |
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) { |
42 | if (str.startsWith("Service Name:") ) { | 75 | if (str.startsWith("Service Name:") ) { |
43 | m_item.setServiceName( str.mid(13).stripWhiteSpace() ); | 76 | m_item.setServiceName( str.mid(13).stripWhiteSpace() ); |
@@ -66,21 +99,20 @@ bool Parser::parseClassId( const QString& str) { | |||
66 | return true; | 99 | return true; |
67 | }else if ( m_classOver ) { // ok now are the informations in place | 100 | }else if ( m_classOver ) { // ok now are the informations in place |
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 |
85 | m_classOver = true; | 117 | m_classOver = true; |
86 | return false; | 118 | return false; |
@@ -90,24 +122,52 @@ bool Parser::parseProtocol( const QString& str) { | |||
90 | m_protocolOver = true; | 122 | m_protocolOver = true; |
91 | m_protocolAdded = false; | 123 | m_protocolAdded = false; |
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 ); |
98 | m_item.insertProtocolDescriptor( desc ); | 131 | m_item.insertProtocolDescriptor( desc ); |
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 ) { |
107 | m_protocolOver = false; | 150 | m_protocolOver = false; |
108 | } | 151 | } |
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 | |||
@@ -22,12 +22,15 @@ namespace OpieTooth { | |||
22 | bool parseProfile( const QString& ) ; | 22 | bool parseProfile( const QString& ) ; |
23 | bool m_complete:1; | 23 | bool m_complete:1; |
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 | }; |
32 | 35 | ||
33 | 36 | ||
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 | |||
@@ -104,65 +104,79 @@ bool operator==( const Services::ProtocolDescriptor &first, | |||
104 | Services::Services(){ | 104 | Services::Services(){ |
105 | 105 | ||
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 | |||
@@ -62,9 +62,9 @@ namespace OpieTooth { | |||
62 | ProfileDescriptor &operator=( const ProfileDescriptor& ); | 62 | ProfileDescriptor &operator=( const ProfileDescriptor& ); |
63 | /** | 63 | /** |
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; |
69 | int m_idInt; | 69 | int m_idInt; |
70 | int m_version; | 70 | int m_version; |
@@ -93,10 +93,10 @@ namespace OpieTooth { | |||
93 | void setId(int ); | 93 | void setId(int ); |
94 | int port()const; | 94 | int port()const; |
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; |
101 | int m_number; | 101 | int m_number; |
102 | int m_channel; | 102 | int m_channel; |
@@ -130,9 +130,14 @@ namespace OpieTooth { | |||
130 | void clearProfileDescriptorList(); | 130 | void clearProfileDescriptorList(); |
131 | void removeProfileDescriptor(const ProfileDescriptor& ); | 131 | void removeProfileDescriptor(const ProfileDescriptor& ); |
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 | }; |
138 | #endif | 143 | #endif |