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/bindings/buffer.h> |
| 13 #include <mojo/bindings/message.h> |
12 #include <mojo/macros.h> | 14 #include <mojo/macros.h> |
13 #include <mojo/result.h> | 15 #include <mojo/result.h> |
14 #include <mojo/system/main.h> | 16 #include <mojo/system/main.h> |
15 #include <mojo/system/message_pipe.h> | 17 #include <mojo/system/message_pipe.h> |
16 #include <mojo/system/wait.h> | 18 #include <mojo/system/wait.h> |
17 #include <stdio.h> | 19 #include <stdio.h> |
18 #include <string.h> | 20 #include <string.h> |
19 | 21 |
20 #include "examples/echo/echo.mojom-c.h" | 22 #include "examples/echo/echo.mojom-c.h" |
21 #include "mojo/public/c/bindings/buffer.h" | |
22 #include "mojo/public/c/bindings/message.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 |
29 // using a MojomBuffer. | 29 // using a MojomBuffer. |
30 #define MESSAGE_MAX_BYTES 256 | 30 #define MESSAGE_MAX_BYTES 256 |
31 | 31 |
32 // Creates a message pipe; sets |client| to one end of the pipe, and returns | 32 // Creates a message pipe; sets |client| to one end of the pipe, and returns |
(...skipping 340 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 |