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
3 # found in the LICENSE file.
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.
8 # A simple interface would be created this way:
9 # module = mojom.Module('Foo')
10 # interface = module.AddInterface('Bar')
11 # method = interface.AddMethod('Tat', 0)
12 # method.AddParameter('baz', 0, mojom.INT32)
15 def __init__(self
, spec
= None):
19 # Initialize the set of primitive types. These can be accessed by clients.
34 # Collection of all Primitive types
48 # TODO(davemoore): Add HANDLE.
53 def __init__(self
, name
= None, kind
= None, ordinal
= None, default
= None):
56 self
.ordinal
= ordinal
57 self
.default
= default
61 def __init__(self
, name
= None):
67 Kind
.__init
__(self
, spec
)
70 def AddField(self
, name
, kind
, ordinal
= None, default
= None):
71 field
= Field(name
, kind
, ordinal
, default
)
72 self
.fields
.append(field
)
77 def __init__(self
, kind
= None):
80 Kind
.__init
__(self
, 'a:' + kind
.spec
)
85 class Parameter(object):
86 def __init__(self
, name
= None, kind
= None, ordinal
= None, default
= None):
88 self
.ordinal
= ordinal
90 self
.default
= default
94 def __init__(self
, name
= None, ordinal
= None):
96 self
.ordinal
= ordinal
99 def AddParameter(self
, name
, kind
, ordinal
= None, default
= None):
100 parameter
= Parameter(name
, kind
, ordinal
, default
)
101 self
.parameters
.append(parameter
)
105 class Interface(object):
106 def __init__(self
, name
= None):
110 def AddMethod(self
, name
, ordinal
= None):
111 method
= Method(name
, ordinal
)
112 self
.methods
.append(method
)
116 class Module(object):
117 def __init__(self
, name
= None, namespace
= None):
119 self
.namespace
= namespace
123 def AddInterface(self
, name
):
124 interface
= Interface(name
);
125 self
.interfaces
.append(interface
)
128 def AddStruct(self
, name
):
129 struct
= Struct(name
)
130 self
.structs
.append(struct
)