OLD | NEW |
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import mojom | 5 import mojom |
6 | 6 |
7 # mojom_data provides a mechanism to turn mojom Modules to dictionaries and | 7 # mojom_data provides a mechanism to turn mojom Modules to dictionaries and |
8 # back again. This can be used to persist a mojom Module created progromatically | 8 # back again. This can be used to persist a mojom Module created progromatically |
9 # or to read a dictionary from code or a file. | 9 # or to read a dictionary from code or a file. |
10 # Example: | 10 # Example: |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 method.name = data['name'] | 120 method.name = data['name'] |
121 method.ordinal = data.get('ordinal') | 121 method.ordinal = data.get('ordinal') |
122 method.default = data.get('default') | 122 method.default = data.get('default') |
123 method.parameters = map( | 123 method.parameters = map( |
124 lambda parameter: ParameterFromData(kinds, parameter), data['parameters']) | 124 lambda parameter: ParameterFromData(kinds, parameter), data['parameters']) |
125 return method | 125 return method |
126 | 126 |
127 def InterfaceToData(interface): | 127 def InterfaceToData(interface): |
128 return { | 128 return { |
129 istr(0, 'name'): interface.name, | 129 istr(0, 'name'): interface.name, |
130 istr(1, 'methods'): map(MethodToData, interface.methods) | 130 istr(1, 'peer'): interface.peer, |
| 131 istr(2, 'methods'): map(MethodToData, interface.methods) |
131 } | 132 } |
132 | 133 |
133 def InterfaceFromData(kinds, data): | 134 def InterfaceFromData(kinds, data): |
134 interface = mojom.Interface() | 135 interface = mojom.Interface() |
135 interface.name = data['name'] | 136 interface.name = data['name'] |
| 137 interface.peer = data['peer'] |
136 interface.methods = map( | 138 interface.methods = map( |
137 lambda method: MethodFromData(kinds, method), data['methods']) | 139 lambda method: MethodFromData(kinds, method), data['methods']) |
138 return interface | 140 return interface |
139 | 141 |
140 def ModuleToData(module): | 142 def ModuleToData(module): |
141 return { | 143 return { |
142 istr(0, 'name'): module.name, | 144 istr(0, 'name'): module.name, |
143 istr(1, 'namespace'): module.namespace, | 145 istr(1, 'namespace'): module.namespace, |
144 istr(2, 'structs'): map(StructToData, module.structs), | 146 istr(2, 'structs'): map(StructToData, module.structs), |
145 istr(3, 'interfaces'): map(InterfaceToData, module.interfaces) | 147 istr(3, 'interfaces'): map(InterfaceToData, module.interfaces) |
146 } | 148 } |
147 | 149 |
148 def ModuleFromData(data): | 150 def ModuleFromData(data): |
149 kinds = {} | 151 kinds = {} |
150 for kind in mojom.PRIMITIVES: | 152 for kind in mojom.PRIMITIVES: |
151 kinds[kind.spec] = kind | 153 kinds[kind.spec] = kind |
152 | 154 |
153 module = mojom.Module() | 155 module = mojom.Module() |
154 module.name = data['name'] | 156 module.name = data['name'] |
155 module.namespace = data['namespace'] | 157 module.namespace = data['namespace'] |
156 module.structs = map( | 158 module.structs = map( |
157 lambda struct: StructFromData(kinds, struct), data['structs']) | 159 lambda struct: StructFromData(kinds, struct), data['structs']) |
158 module.interfaces = map( | 160 module.interfaces = map( |
159 lambda interface: InterfaceFromData(kinds, interface), data['interfaces']) | 161 lambda interface: InterfaceFromData(kinds, interface), data['interfaces']) |
160 return module | 162 return module |
161 | 163 |
162 | 164 |
163 | 165 |
164 | 166 |
OLD | NEW |