| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 // Here is an example of the echo client using C bindings. This example avoids | 5 // Here is an example of the echo client using C bindings. This example avoids |
| 6 // making any dynamic allocations and uses the stack entirely by wildly | 6 // making any dynamic allocations and uses the stack entirely by wildly |
| 7 // reserving a stack buffer, and foregoing any size-computation and copying. | 7 // reserving a stack buffer, and foregoing any size-computation and copying. |
| 8 // Using it this way essentially requires the programmer to know the mojom | 8 // Using it this way essentially requires the programmer to know the mojom |
| 9 // encoding order and can be error-prone, but fast. | 9 // encoding order and can be error-prone, but fast. |
| 10 | 10 |
| 11 #include <assert.h> | 11 #include <assert.h> |
| 12 #include <mojo/macros.h> |
| 12 #include <stdio.h> | 13 #include <stdio.h> |
| 13 #include <string.h> | 14 #include <string.h> |
| 14 | 15 |
| 15 #include "examples/echo/echo.mojom-c.h" | 16 #include "examples/echo/echo.mojom-c.h" |
| 16 #include "mojo/public/c/bindings/buffer.h" | 17 #include "mojo/public/c/bindings/buffer.h" |
| 17 #include "mojo/public/c/bindings/message.h" | 18 #include "mojo/public/c/bindings/message.h" |
| 18 #include "mojo/public/c/system/macros.h" | |
| 19 #include "mojo/public/c/system/main.h" | 19 #include "mojo/public/c/system/main.h" |
| 20 #include "mojo/public/c/system/message_pipe.h" | 20 #include "mojo/public/c/system/message_pipe.h" |
| 21 #include "mojo/public/c/system/result.h" | 21 #include "mojo/public/c/system/result.h" |
| 22 #include "mojo/public/c/system/wait.h" | 22 #include "mojo/public/c/system/wait.h" |
| 23 #include "mojo/public/interfaces/application/application.mojom-c.h" | 23 #include "mojo/public/interfaces/application/application.mojom-c.h" |
| 24 #include "mojo/public/interfaces/application/application_connector.mojom-c.h" | 24 #include "mojo/public/interfaces/application/application_connector.mojom-c.h" |
| 25 #include "mojo/public/interfaces/application/shell.mojom-c.h" | 25 #include "mojo/public/interfaces/application/shell.mojom-c.h" |
| 26 | 26 |
| 27 // To avoid dynamic allocations, we reserve this much space as an upper-bound | 27 // To avoid dynamic allocations, we reserve this much space as an upper-bound |
| 28 // for allocating mojo messages on the stack. This space is meant to be consumed | 28 // for allocating mojo messages on the stack. This space is meant to be consumed |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 MojoHandle echo_service_h = | 373 MojoHandle echo_service_h = |
| 374 connect_to_service(echo_sp_h, mojo_examples_Echo__ServiceName, | 374 connect_to_service(echo_sp_h, mojo_examples_Echo__ServiceName, |
| 375 strlen(mojo_examples_Echo__ServiceName)); | 375 strlen(mojo_examples_Echo__ServiceName)); |
| 376 | 376 |
| 377 // 5) Call into the echo service. | 377 // 5) Call into the echo service. |
| 378 const char kEchoMsg[] = "Hello world!"; | 378 const char kEchoMsg[] = "Hello world!"; |
| 379 call_echo(echo_service_h, kEchoMsg, strlen(kEchoMsg)); | 379 call_echo(echo_service_h, kEchoMsg, strlen(kEchoMsg)); |
| 380 | 380 |
| 381 return MOJO_RESULT_OK; | 381 return MOJO_RESULT_OK; |
| 382 } | 382 } |
| OLD | NEW |