OLD | NEW |
1 # Mojo C++ Bindings API | 1 # Mojo C++ Bindings API |
2 This document is a subset of the [Mojo documentation](/mojo). | 2 This document is a subset of the [Mojo documentation](/mojo). |
3 | 3 |
4 [TOC] | 4 [TOC] |
5 | 5 |
6 ## Overview | 6 ## Overview |
7 The Mojo C++ Bindings API leverages the | 7 The Mojo C++ Bindings API leverages the |
8 [C++ System API](/mojo/public/cpp/system) to provide a more natural set of | 8 [C++ System API](/mojo/public/cpp/system) to provide a more natural set of |
9 primitives for communicating over Mojo message pipes. Combined with generated | 9 primitives for communicating over Mojo message pipes. Combined with generated |
10 code from the [Mojom IDL and bindings generator](/mojo/public/tools/bindings), | 10 code from the [Mojom IDL and bindings generator](/mojo/public/tools/bindings), |
(...skipping 990 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1001 The correct answer is, "Yes! That would be nice!" And fortunately, it can! | 1001 The correct answer is, "Yes! That would be nice!" And fortunately, it can! |
1002 | 1002 |
1003 ### Global Configuration | 1003 ### Global Configuration |
1004 | 1004 |
1005 While this feature is quite powerful, it introduces some unavoidable complexity | 1005 While this feature is quite powerful, it introduces some unavoidable complexity |
1006 into build system. This stems from the fact that type-mapping is an inherently | 1006 into build system. This stems from the fact that type-mapping is an inherently |
1007 viral concept: if `gfx::mojom::Rect` is mapped to `gfx::Rect` anywhere, the | 1007 viral concept: if `gfx::mojom::Rect` is mapped to `gfx::Rect` anywhere, the |
1008 mapping needs to apply *everywhere*. | 1008 mapping needs to apply *everywhere*. |
1009 | 1009 |
1010 For this reason we have a few global typemap configurations defined in | 1010 For this reason we have a few global typemap configurations defined in |
1011 [chromium_bindings_configuration.gni](https://cs.chromium.com/chromium/src/mojo/
public/tools/bindings/chromium_bindings_configuration.gni) | 1011 [chromium_bindings_configuration.gni](https://cs.chromium.org/chromium/src/mojo/
public/tools/bindings/chromium_bindings_configuration.gni) |
1012 and | 1012 and |
1013 [blink_bindings_configuration.gni](https://cs.chromium.com/chromium/src/mojo/pub
lic/tools/bindings/blink_bindings_configuration.gni). These configure the two su
pported [variants](#Variants) of Mojom generated | 1013 [blink_bindings_configuration.gni](https://cs.chromium.org/chromium/src/mojo/pub
lic/tools/bindings/blink_bindings_configuration.gni). These configure the two su
pported [variants](#Variants) of Mojom generated |
1014 bindings in the repository. Read more on this in the sections that follow. | 1014 bindings in the repository. Read more on this in the sections that follow. |
1015 | 1015 |
1016 For now, let's take a look at how to express the mapping from `gfx::mojom::Rect` | 1016 For now, let's take a look at how to express the mapping from `gfx::mojom::Rect` |
1017 to `gfx::Rect`. | 1017 to `gfx::Rect`. |
1018 | 1018 |
1019 ### Defining `StructTraits` | 1019 ### Defining `StructTraits` |
1020 | 1020 |
1021 In order to teach generated bindings code how to serialize an arbitrary native | 1021 In order to teach generated bindings code how to serialize an arbitrary native |
1022 type `T` as an arbitrary Mojom type `mojom::U`, we need to define an appropriate | 1022 type `T` as an arbitrary Mojom type `mojom::U`, we need to define an appropriate |
1023 specialization of the | 1023 specialization of the |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1159 `//ui/gfx/typemaps.gni` file with the following contents: | 1159 `//ui/gfx/typemaps.gni` file with the following contents: |
1160 | 1160 |
1161 ``` | 1161 ``` |
1162 typemaps = [ | 1162 typemaps = [ |
1163 "//ui/gfx/geometry/mojo/geometry.typemap", | 1163 "//ui/gfx/geometry/mojo/geometry.typemap", |
1164 ] | 1164 ] |
1165 ``` | 1165 ``` |
1166 | 1166 |
1167 And finally we can reference this file in the global default (Chromium) bindings | 1167 And finally we can reference this file in the global default (Chromium) bindings |
1168 configuration by adding it to `_typemap_imports` in | 1168 configuration by adding it to `_typemap_imports` in |
1169 [chromium_bindings_configuration.gni](https://cs.chromium.com/chromium/src/mojo/
public/tools/bindings/chromium_bindings_configuration.gni): | 1169 [chromium_bindings_configuration.gni](https://cs.chromium.org/chromium/src/mojo/
public/tools/bindings/chromium_bindings_configuration.gni): |
1170 | 1170 |
1171 ``` | 1171 ``` |
1172 _typemap_imports = [ | 1172 _typemap_imports = [ |
1173 ..., | 1173 ..., |
1174 "//ui/gfx/typemaps.gni", | 1174 "//ui/gfx/typemaps.gni", |
1175 ..., | 1175 ..., |
1176 ] | 1176 ] |
1177 ``` | 1177 ``` |
1178 | 1178 |
1179 ### StructTraits Reference | 1179 ### StructTraits Reference |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1422 | 1422 |
1423 ```cpp | 1423 ```cpp |
1424 inline bool IsKnownEnumValue(Department value); | 1424 inline bool IsKnownEnumValue(Department value); |
1425 ``` | 1425 ``` |
1426 | 1426 |
1427 ### Additional Documentation | 1427 ### Additional Documentation |
1428 | 1428 |
1429 [Calling Mojo From Blink](https://www.chromium.org/developers/design-documents/m
ojo/calling-mojo-from-blink) | 1429 [Calling Mojo From Blink](https://www.chromium.org/developers/design-documents/m
ojo/calling-mojo-from-blink) |
1430 : A brief overview of what it looks like to use Mojom C++ bindings from | 1430 : A brief overview of what it looks like to use Mojom C++ bindings from |
1431 within Blink code. | 1431 within Blink code. |
OLD | NEW |