Chromium Code Reviews| Index: mojo/examples/sample_app/sample_app.cc |
| diff --git a/mojo/examples/sample_app/sample_app.cc b/mojo/examples/sample_app/sample_app.cc |
| index abef1f3fffae10faf529e8ecb6381d9661e38582..856c540ecfb6bf09691ea72a5c6e056730a260c1 100644 |
| --- a/mojo/examples/sample_app/sample_app.cc |
| +++ b/mojo/examples/sample_app/sample_app.cc |
| @@ -3,9 +3,13 @@ |
| // found in the LICENSE file. |
| #include <stdio.h> |
| +#include <string> |
| +#include "mojo/examples/sample_app/hello_world_client_impl.h" |
| #include "mojo/public/system/core.h" |
| #include "mojo/public/system/macros.h" |
| +#include "mojo/public/bindings/common/bindings_support_impl.h" |
| +#include "mojo/public/bindings/lib/bindings_support.h" |
| #if defined(WIN32) |
| #if !defined(CDECL) |
| @@ -17,59 +21,32 @@ |
| #define SAMPLE_APP_EXPORT __attribute__((visibility("default"))) |
| #endif |
| -char* ReadStringFromPipe(mojo::Handle pipe) { |
| - uint32_t len = 0; |
| - char* buf = NULL; |
| - MojoResult result = mojo::ReadMessage(pipe, buf, &len, NULL, NULL, |
| - MOJO_READ_MESSAGE_FLAG_NONE); |
| - if (result == MOJO_RESULT_RESOURCE_EXHAUSTED) { |
| - buf = new char[len]; |
| - result = mojo::ReadMessage(pipe, buf, &len, NULL, NULL, |
| - MOJO_READ_MESSAGE_FLAG_NONE); |
| - } |
| - if (result < MOJO_RESULT_OK) { |
| - // Failure.. |
| - if (buf) |
| - delete[] buf; |
| - return NULL; |
| - } |
| - return buf; |
| -} |
| +namespace mojo { |
| +namespace examples { |
| -class SampleMessageWaiter { |
| - public: |
| - explicit SampleMessageWaiter(mojo::Handle pipe) : pipe_(pipe) {} |
| - ~SampleMessageWaiter() {} |
| +static HelloWorldClientImpl* client = 0; |
| - void Read() { |
| - char* string = ReadStringFromPipe(pipe_); |
| - if (string) { |
| - printf("Read string from pipe: %s\n", string); |
| - delete[] string; |
| - string = NULL; |
| - } |
| - } |
| +void SayHello(mojo::Handle pipe) { |
| + client = new HelloWorldClientImpl(pipe); |
| - void WaitAndRead() { |
| - for (int i = 0; i < 100;) { |
| - MojoResult result = mojo::Wait(pipe_, MOJO_WAIT_FLAG_READABLE, 100); |
| - if (result < MOJO_RESULT_OK) { |
| - // Failure... |
| - continue; |
| - } |
| - ++i; |
| - Read(); |
| - } |
| - } |
| + mojo::ScratchBuffer buf; |
| + const std::string kGreeting("hello, world!"); |
| + mojo::String* greeting = mojo::String::NewCopyOf(&buf, kGreeting); |
| - private: |
| - mojo::Handle pipe_; |
| + client->service()->Greeting(greeting); |
| +} |
| - MOJO_DISALLOW_COPY_AND_ASSIGN(SampleMessageWaiter); |
| -}; |
| +} // examples |
| +} // mojo |
| extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain( |
| mojo::Handle pipe) { |
| - SampleMessageWaiter(pipe).WaitAndRead(); |
| + common::BindingsSupportImpl bindings_support; |
|
darin (slow to review)
2013/11/13 22:57:49
note: using common::BindingsSupportImpl implies ha
|
| + mojo::BindingsSupport::Set(&bindings_support); |
| + |
| + mojo::examples::SayHello(pipe); |
| + |
| + |
| + BindingsSupport::Set(NULL); |
| return MOJO_RESULT_OK; |
| } |