summaryrefslogtreecommitdiff
path: root/libopie2
authormickeyl <mickeyl>2004-01-03 18:33:43 (UTC)
committer mickeyl <mickeyl>2004-01-03 18:33:43 (UTC)
commit27b84ed363fd7fc52092e3c2d1e49dca079b7ffd (patch) (unidiff)
tree932806dc83d84720bcb259df8711d894932580e1 /libopie2
parent3889c8f853aa2d128f54389b17f08fc7b9150788 (diff)
downloadopie-27b84ed363fd7fc52092e3c2d1e49dca079b7ffd.zip
opie-27b84ed363fd7fc52092e3c2d1e49dca079b7ffd.tar.gz
opie-27b84ed363fd7fc52092e3c2d1e49dca079b7ffd.tar.bz2
slightly improve the speed reading the manufacturers list
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/omanufacturerdb.cpp13
-rwxr-xr-xlibopie2/tools/regen.py230
2 files changed, 214 insertions, 29 deletions
diff --git a/libopie2/opienet/omanufacturerdb.cpp b/libopie2/opienet/omanufacturerdb.cpp
index 595633d..f61270b 100644
--- a/libopie2/opienet/omanufacturerdb.cpp
+++ b/libopie2/opienet/omanufacturerdb.cpp
@@ -82,6 +82,9 @@ OManufacturerDB::OManufacturerDB()
82 QString addr; 82 QString addr;
83 QString manu; 83 QString manu;
84 QString extManu; 84 QString extManu;
85 #ifdef OPIE_IMPROVE_GUI_LATENCY
86 int counter = 0;
87 #endif
85 while (!s.atEnd()) 88 while (!s.atEnd())
86 { 89 {
87 s >> addr; 90 s >> addr;
@@ -90,11 +93,17 @@ OManufacturerDB::OManufacturerDB()
90 93
91 manufacturers.insert( addr, manu ); 94 manufacturers.insert( addr, manu );
92 manufacturersExt.insert( addr, extManu ); 95 manufacturersExt.insert( addr, extManu );
93 odebug << "OmanufacturerDB: parse '" << addr << "' as '" << manu << "' (" << extManu << ")" << oendl; 96 // odebug << "OmanufacturerDB: parse '" << addr << "' as '" << manu << "' (" << extManu << ")" << oendl;
94 #ifdef OPIE_IMPROVE_GUI_LATENCY 97 #ifdef OPIE_IMPROVE_GUI_LATENCY
95 if ( qApp ) qApp->processEvents(); 98 counter++;
99 if ( counter == 50 )
100 {
101 qApp->processEvents();
102 counter = 0;
103 }
96 #endif 104 #endif
97 } 105 }
106 odebug << "OManufacturerDB: manufacturer list completed." << oendl;
98 } 107 }
99} 108}
100 109
diff --git a/libopie2/tools/regen.py b/libopie2/tools/regen.py
index 3779896..89385e1 100755
--- a/libopie2/tools/regen.py
+++ b/libopie2/tools/regen.py
@@ -1,26 +1,31 @@
1#!/usr/bin/env python 1#!/usr/bin/env python
2 2
3# 3"""Regenerate C++ mapping classes"""
4# regenerate ioctl_table.h
5#
6 4
7import sys 5#---------------------------------------------------------------------------#
8import os 6# #
9result = os.popen( 'find /usr/include -name "*.h" |xargs grep -h SIOC|grep 0x' ).readlines() 7#---------------------------------------------------------------------------#
8
9def regenDebugMapper( basename ):
10 """
11 Debug Mapper - maps ioctl numbers to names, e.g. 0x4x5a -> SIOCGIWNAME
12 """
13
14 result = os.popen( 'find /usr/include -name "*.h" |xargs grep -h SIOC|grep 0x' ).readlines()
10 15
11try: 16 try:
12 tablehfile = file( sys.argv[1]+".h", "w" ) 17 tablehfile = file( basename+".h", "w" )
13except: 18 except:
14 tablehfile = sys.stdout 19 tablehfile = sys.stdout
15 20
16try: 21 try:
17 tablecfile = file( sys.argv[1]+".cpp", "w" ) 22 tablecfile = file( basename+".cpp", "w" )
18except: 23 except:
19 tablecfile = sys.stdout 24 tablecfile = sys.stdout
20 25
21print >>tablehfile,""" 26 print >>tablehfile,"""
22/* 27/*
23 * debug value mapper - generated by regen.py - (C) Michael 'Mickey' Lauer <mickey@vanille.de> 28 * debug value mapper - generated by %s - (C) Michael 'Mickey' Lauer <mickey@vanille.de>
24 */ 29 */
25 30
26#ifndef DEBUGMAPPER_H 31#ifndef DEBUGMAPPER_H
@@ -43,11 +48,11 @@ class DebugMapper
43}; 48};
44 49
45#endif 50#endif
46""" 51""" % sys.argv[0]
47 52
48print >>tablecfile,""" 53 print >>tablecfile,"""
49/* 54/*
50 * debug value mapper - generated by regen.py - (C) Michael 'Mickey' Lauer <mickey@vanille.de> 55 * debug value mapper - generated by %s - (C) Michael 'Mickey' Lauer <mickey@vanille.de>
51 */ 56 */
52 57
53#include <opie2/odebug.h> 58#include <opie2/odebug.h>
@@ -58,17 +63,17 @@ DebugMapper::DebugMapper()
58{ 63{
59 odebug << "DebugMapper::DebugMapper()" << oendl; 64 odebug << "DebugMapper::DebugMapper()" << oendl;
60 65
61""" % (tablehfile.name) 66""" % ( sys.argv[0], tablehfile.name )
62 67
63for line in result: 68 for line in result:
64 l = line.split() 69 l = line.split()
65 if not l[0].startswith( "#define" ) or not l[2].startswith( "0x" ): 70 if not l[0].startswith( "#define" ) or not l[2].startswith( "0x" ):
66 print >>sys.stderr, "can't parse line: %s" % l 71 print >>sys.stderr, "can't parse line: %s" % l
67 continue 72 continue
68 print >>tablecfile, " _map.insert( %s, new QString(\"%s\") );" % ( l[2], l[1] ) 73 print >>tablecfile, " _map.insert( %s, new QString(\"%s\") );" % ( l[2], l[1] )
69 74
70 75
71print >>tablecfile,""" 76 print >>tablecfile,"""
72}; 77};
73 78
74 79
@@ -94,3 +99,174 @@ const QString& DebugMapper::map( int value ) const
94} 99}
95 100
96""" 101"""
102
103#---------------------------------------------------------------------------#
104# #
105#---------------------------------------------------------------------------#
106
107def regenManufacturerDB( basename ):
108
109 try:
110 h = file( basename+".h", "w" )
111 except:
112 h = sys.stdout
113
114 try:
115 cpp = file( basename+".cpp", "w" )
116 except:
117 cpp = sys.stdout
118
119 print >>h,"""
120#ifndef OMANUFACTURERDB_H
121#define OMANUFACTURERDB_H
122
123#include <qmap.h>
124
125/**
126 * @brief A Ethernet card vendor database.
127 *
128 * This class encapsulates the lookup of Ethernet vendor given a
129 * certain Mac Address. Only the first three bytes define the vendor.
130 */
131class OManufacturerDB
132{
133 public:
134 /**
135 * @returns the one-and-only @ref OManufacturerDB instance.
136 */
137 static OManufacturerDB* instance();
138 /**
139 * @returns the short manufacturer string given a @a macaddr.
140 */
141 const QString& lookup( const QString& macaddr ) const;
142 /**
143 * @returns the enhanced manufacturer string given a @a macaddr.
144 */
145 const QString& lookupExt( const QString& macaddr ) const;
146
147 protected:
148 OManufacturerDB();
149 virtual ~OManufacturerDB();
150
151 private:
152 QMap<QString, QString> manufacturers;
153 QMap<QString, QString> manufacturersExt;
154 static OManufacturerDB* _instance;
155};
156
157#endif
158"""
159
160 print >>cpp,"""
161#include "%s.h"
162
163/* OPIE CORE */
164#include <opie2/odebug.h>
165
166/* QT */
167#include <qapplication.h>
168#include <qstring.h>
169
170#define OPIE_IMPROVE_GUI_LATENCY 1
171
172OManufacturerDB* OManufacturerDB::_instance = 0;
173
174OManufacturerDB* OManufacturerDB::instance()
175{
176 if ( !OManufacturerDB::_instance )
177 {
178 odebug << "OManufacturerDB::instance(): creating OManufacturerDB..." << oendl;
179 _instance = new OManufacturerDB();
180 }
181 return _instance;
182}
183
184
185OManufacturerDB::OManufacturerDB()
186{
187""" % basename
188
189 count = 0
190 for line in sys.stdin:
191 if line[0] == "#": # skip comments
192 continue
193 #print line.strip()
194 entries = line.strip().split()
195 #print "number of entries =", len( entries )
196 #print entries
197 if len( entries ) < 2:
198 continue
199 elif len( entries ) == 2:
200 count += 1
201 print "2-line detected."
202 print >>cpp, ' manufacturers.insert( "%s", "%s" );' % ( entries[0], entries[1] )
203 print >>cpp, ' manufacturersExt.insert( "%s", "%s" );' % ( entries[0], entries[1] )
204 elif len( entries ) > 2:
205 count += 1
206 print "3-line detected."
207 print >>cpp, ' manufacturers.insert( "%s", "%s" );' % ( entries[0], entries[1] )
208 print >>cpp, ' manufacturersExt.insert( "%s", "%s" );' % ( entries[0], "_".join( entries[3:] ) )
209 else:
210 assert( false )
211 if not (count % 1000):
212 print >>cpp,"""
213#ifdef OPIE_IMPROVE_GUI_LATENCY
214 if (qApp) qApp->processEvents();
215#endif
216"""
217 print "successfully parsed", count, "manufacturer lines"
218 print >>cpp,"""
219}
220
221
222OManufacturerDB::~OManufacturerDB()
223{
224}
225
226
227const QString& OManufacturerDB::lookup( const QString& macaddr ) const
228{
229 return manufacturers[macaddr.upper().left(8)];
230}
231
232
233const QString& OManufacturerDB::lookupExt( const QString& macaddr ) const
234{
235 QMap<QString,QString>::ConstIterator it = manufacturersExt.find( macaddr.upper().left(8) );
236 return it == manufacturersExt.end() ? lookup( macaddr ) : *it;
237}
238"""
239
240#---------------------------------------------------------------------------#
241# #
242#---------------------------------------------------------------------------#
243
244#---------------------------------------------------------------------------#
245# #
246#---------------------------------------------------------------------------#
247
248#---------------------------------------------------------------------------#
249# #
250#---------------------------------------------------------------------------#
251
252import sys
253import os
254import copy
255
256if __name__ == "__main__":
257 if len( sys.argv ) != 3:
258 print """
259Usage: %s <table> <basename>
260
261Available tables: %s
262""" % ( sys.argv[0], [ str(k)[5:] for k in copy.copy( locals() ) if k.startswith( "regen" ) ] )
263 sys.exit( -1 )
264
265 try:
266 func = locals()["regen%s" % sys.argv[1]]
267 except KeyError:
268 print "Table '%s' unknown." % sys.argv[1]
269 sys.exit( -1 )
270 else:
271 func( sys.argv[2] )
272 sys.exit( 0 ) \ No newline at end of file