Debian Codegraph @

utils/qmidb/Entities.py

raw
1 # -*- Mode: python; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 #
3 # This program is free software; you can redistribute it and/or modify it under
4 # the terms of the GNU General Public License as published by the Free Software
5 # Foundation, version 2.
6 #
7 # This program is distributed in the hope that it will be useful, but WITHOUT
8 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
10 # details.
11 #
12 # You should have received a copy of the GNU General Public License along with
13 # this program; if not, write to the Free Software Foundation, Inc., 51
14 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15 #
16 # Copyright (C) 2011 - 2012 Red Hat, Inc.
17 #
18
19 import utils
20
21 class Entity:
22 def __init__(self, line):
23 # Each entity defines a TLV item in a QMI request or response. The
24 # entity's 'struct' field maps to the ID of a struct in Struct.txt,
25 # which describes the fields of that struct. For example:
26 #
27 # 33^"32,16"^"WDS/Start Network Interface Request/Primary DNS"^50021^-1
28 #
29 # The first field (33) indicates that this entity is valid for the QMI
30 # message eDB2_ET_QMI_WDS_REQ. The "32,16" is a tuple
31 # (eQMI_WDS_START_NET, 16), the first item of which (32) indicates the
32 # general QMI service the entity is associated with (WDS, CTL, NAS, etc)
33 # and the second item indicates the specific entity number (ie, the 'T'
34 # in TLV).
35 #
36 # The 'struct' field (50021) points to:
37 #
38 # Struct.txt:50021^0^0^50118^""^-1^1^"4"
39 #
40 # which indicates that the only member of this struct is field #50118:
41 #
42 # Field.txt:50118^"IP V4 Address"^8^0^2^0
43 #
44 # which should be pretty self-explanatory. Note that different entities
45 # can point to the same struct.
46
47
48 parts = line.split('^')
49 if len(parts) < 4:
50 raise Exception("Invalid entity line '%s'" % line)
51 self.uniqueid = parts[0] + '.' + parts[1].replace('"', '').replace(',', '.')
52 self.type = int(parts[0]) # eDB2EntityType
53
54 self.key = parts[1].replace('"','') # tuple of (eQMIMessageXXX, entity number)
55 self.cmdno = int(self.key.split(",")[0])
56 self.tlvno = int(self.key.split(",")[1])
57 self.name = parts[2].replace('"', '')
58 self.struct = int(parts[3])
59 self.format = None
60 self.internal = True
61 self.extformat = None
62 if len(parts) > 4:
63 self.format = int(parts[4])
64 if len(parts) > 5:
65 self.internal = int(parts[5]) != 0
66 if len(parts) > 6:
67 self.extformat = int(parts[6])
68
69 def validate(self, structs):
70 if not structs.has_child(self.struct):
71 raise Exception("Entity missing struct: %d" % self.struct)
72
73 def emit(self, fields, structs, enums):
74 if self.tlvno == 2 and self.name.find("/Result Code") > 0 and self.struct == 50000:
75 # ignore this entity if it's a standard QMI result code struct
76 return self.struct
77
78 # Tell the struct this value is for to emit itself
79 s = structs.get_child(self.struct)
80 s.emit_header(self.name, self.cmdno, self.tlvno)
81 s.emit(self.name, 0, 0, fields, structs, enums)
82 return self.struct
83
84
85 class Entities(utils.DbFile):
86 def __init__(self, path):
87 self.byid = {}
88 f = file(path + "Entity.txt")
89 for line in f:
90 ent = Entity(line)
91 self.byid[ent.uniqueid] = ent
92
93 def validate(self, structs):
94 for e in self.byid.values():
95 e.validate(structs)
96
97 def emit(self, fields, structs, enums):
98 # emit the standard status TLV struct
99 print "struct qmi_result_code { /* QMI Result Code TLV (0x0002) */"
100 print "\tgobi_qmi_results qmi_result; /* QMI Result */"
101 print "\tgobi_qmi_errors qmi_error; /* QMI Error */"
102 print "};"
103 print ""
104
105 structs_used = []
106 for e in self.byid.values():
107 sused = e.emit(fields, structs, enums)
108 structs_used.append(sused)
109 return structs_used
110