| 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 831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 842 // sample::mojom::Logger: | 842 // sample::mojom::Logger: |
| 843 void Log(const std::string& message) override { | 843 void Log(const std::string& message) override { |
| 844 LOG(ERROR) << "[Logger] " << message; | 844 LOG(ERROR) << "[Logger] " << message; |
| 845 } | 845 } |
| 846 | 846 |
| 847 private: | 847 private: |
| 848 // NOTE: This doesn't own any Binding object! | 848 // NOTE: This doesn't own any Binding object! |
| 849 }; | 849 }; |
| 850 | 850 |
| 851 db::mojom::LoggerPtr logger; | 851 db::mojom::LoggerPtr logger; |
| 852 mojo::MakeStrongBinding(base::MakeUnique<DatabaseImpl>(), | 852 mojo::MakeStrongBinding(base::MakeUnique<LoggerImpl>(), |
| 853 mojo::MakeRequest(&logger)); | 853 mojo::MakeRequest(&logger)); |
| 854 | 854 |
| 855 logger->Log("NOM NOM NOM MESSAGES"); | 855 logger->Log("NOM NOM NOM MESSAGES"); |
| 856 ``` | 856 ``` |
| 857 | 857 |
| 858 Now as long as `logger` remains open somewhere in the system, the bound | 858 Now as long as `logger` remains open somewhere in the system, the bound |
| 859 `DatabaseImpl` on the other end will remain alive. | 859 `LoggerImpl` on the other end will remain alive. |
| 860 | 860 |
| 861 ### Binding Sets | 861 ### Binding Sets |
| 862 | 862 |
| 863 Sometimes it's useful to share a single implementation instance with multiple | 863 Sometimes it's useful to share a single implementation instance with multiple |
| 864 clients. [**`BindingSet`**](https://cs.chromium.org/chromium/src/mojo/public/cpp
/bindings/binding_set.h) | 864 clients. [**`BindingSet`**](https://cs.chromium.org/chromium/src/mojo/public/cpp
/bindings/binding_set.h) |
| 865 makes this easy. Consider the Mojom: | 865 makes this easy. Consider the Mojom: |
| 866 | 866 |
| 867 ``` cpp | 867 ``` cpp |
| 868 module system.mojom; | 868 module system.mojom; |
| 869 | 869 |
| (...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1431 | 1431 |
| 1432 ```cpp | 1432 ```cpp |
| 1433 inline bool IsKnownEnumValue(Department value); | 1433 inline bool IsKnownEnumValue(Department value); |
| 1434 ``` | 1434 ``` |
| 1435 | 1435 |
| 1436 ### Additional Documentation | 1436 ### Additional Documentation |
| 1437 | 1437 |
| 1438 [Calling Mojo From Blink](https://www.chromium.org/developers/design-documents/m
ojo/calling-mojo-from-blink) | 1438 [Calling Mojo From Blink](https://www.chromium.org/developers/design-documents/m
ojo/calling-mojo-from-blink) |
| 1439 : A brief overview of what it looks like to use Mojom C++ bindings from | 1439 : A brief overview of what it looks like to use Mojom C++ bindings from |
| 1440 within Blink code. | 1440 within Blink code. |
| OLD | NEW |