OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 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 # mojom's classes provide an interface to mojo modules. Modules are collections | 5 # mojom's classes provide an interface to mojo modules. Modules are collections |
6 # of interfaces and structs to be used by mojo ipc clients and servers. | 6 # of interfaces and structs to be used by mojo ipc clients and servers. |
7 # | 7 # |
8 # A simple interface would be created this way: | 8 # A simple interface would be created this way: |
9 # module = mojom.Module('Foo') | 9 # module = mojom.Module('Foo') |
10 # interface = module.AddInterface('Bar') | 10 # interface = module.AddInterface('Bar') |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 def __init__(self, name = None, kind = None, ordinal = None, default = None): | 62 def __init__(self, name = None, kind = None, ordinal = None, default = None): |
63 self.name = name | 63 self.name = name |
64 self.kind = kind | 64 self.kind = kind |
65 self.ordinal = ordinal | 65 self.ordinal = ordinal |
66 self.default = default | 66 self.default = default |
67 | 67 |
68 | 68 |
69 class Struct(Kind): | 69 class Struct(Kind): |
70 def __init__(self, name = None): | 70 def __init__(self, name = None): |
71 self.name = name | 71 self.name = name |
72 self.imported_from_namespace = None | 72 self.imported_from = None |
73 if name != None: | 73 if name != None: |
74 spec = 'x:' + name | 74 spec = 'x:' + name |
75 else: | 75 else: |
76 spec = None | 76 spec = None |
77 Kind.__init__(self, spec) | 77 Kind.__init__(self, spec) |
78 self.fields = [] | 78 self.fields = [] |
79 | 79 |
80 @classmethod | 80 @classmethod |
81 def CreateFromImport(cls, kind, import_namespace): | 81 def CreateFromImport(cls, kind, imported_from): |
82 """Used with 'import module' - clones the kind imported from the | 82 """Used with 'import module' - clones the kind imported from the |
83 given module's namespace.""" | 83 given module's namespace.""" |
84 kind = copy.deepcopy(kind) | 84 kind = copy.deepcopy(kind) |
85 kind.imported_from_namespace = import_namespace | 85 kind.imported_from = imported_from |
86 return kind | 86 return kind |
87 | 87 |
88 def AddField(self, name, kind, ordinal = None, default = None): | 88 def AddField(self, name, kind, ordinal = None, default = None): |
89 field = Field(name, kind, ordinal, default) | 89 field = Field(name, kind, ordinal, default) |
90 self.fields.append(field) | 90 self.fields.append(field) |
91 return field | 91 return field |
92 | 92 |
93 def GetFullName(self, separator): | 93 def GetFullName(self, separator): |
94 """Returns the fully qualified type name, including namespace prefix.""" | 94 """Returns the fully qualified type name, including namespace prefix.""" |
95 if self.imported_from_namespace: | 95 if self.imported_from: |
96 return separator.join([self.imported_from_namespace, self.name]) | 96 return separator.join([self.imported_from["namespace"], self.name]) |
97 return self.name | 97 return self.name |
98 | 98 |
99 def GetFullNameInternal(self, separator): | 99 def GetFullNameInternal(self, separator): |
100 """Returns the fully qualified type name for an internal data structure, | 100 """Returns the fully qualified type name for an internal data structure, |
101 including namespace prefix.""" | 101 including namespace prefix.""" |
102 if self.imported_from_namespace: | 102 if self.imported_from: |
103 return separator.join( | 103 return separator.join( |
104 [self.imported_from_namespace, "internal", self.name]) | 104 [self.imported_from["namespace"], "internal", self.name]) |
105 return self.name | 105 return self.name |
106 | 106 |
107 | 107 |
108 class Array(Kind): | 108 class Array(Kind): |
109 def __init__(self, kind = None): | 109 def __init__(self, kind = None): |
110 self.kind = kind | 110 self.kind = kind |
111 if kind != None: | 111 if kind != None: |
112 Kind.__init__(self, 'a:' + kind.spec) | 112 Kind.__init__(self, 'a:' + kind.spec) |
113 else: | 113 else: |
114 Kind.__init__(self) | 114 Kind.__init__(self) |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 | 172 |
173 def AddInterface(self, name): | 173 def AddInterface(self, name): |
174 interface = Interface(name); | 174 interface = Interface(name); |
175 self.interfaces.append(interface) | 175 self.interfaces.append(interface) |
176 return interface; | 176 return interface; |
177 | 177 |
178 def AddStruct(self, name): | 178 def AddStruct(self, name): |
179 struct = Struct(name) | 179 struct = Struct(name) |
180 self.structs.append(struct) | 180 self.structs.append(struct) |
181 return struct; | 181 return struct; |
OLD | NEW |