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..5a7fa46a7dfec8728cf3378acef66fa5b005642d 100644 |
--- a/mojo/examples/sample_app/sample_app.cc |
+++ b/mojo/examples/sample_app/sample_app.cc |
@@ -3,7 +3,12 @@ |
// found in the LICENSE file. |
#include <stdio.h> |
+#include <string> |
+#include "base/message_loop/message_loop.h" |
+#include "mojo/common/bindings_support_impl.h" |
+#include "mojo/examples/sample_app/hello_world_client_impl.h" |
+#include "mojo/public/bindings/lib/bindings_support.h" |
#include "mojo/public/system/core.h" |
#include "mojo/public/system/macros.h" |
@@ -17,59 +22,33 @@ |
#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; |
darin (slow to review)
2013/11/14 00:05:34
nit: g_client?
|
- 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(); |
+ base::MessageLoop loop; |
darin (slow to review)
2013/11/14 00:05:34
since this is sample code, it might be nice to add
DaveMoore
2013/11/14 23:46:54
Done.
|
+ mojo::common::BindingsSupportImpl bindings_support; |
+ mojo::BindingsSupport::Set(&bindings_support); |
+ |
+ mojo::examples::SayHello(pipe); |
+ loop.Run(); |
+ |
+ mojo::BindingsSupport::Set(NULL); |
return MOJO_RESULT_OK; |
} |