Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include <stdio.h> | 5 #include <stdio.h> |
| 6 | 6 |
| 7 #include "base/basictypes.h" | |
| 8 #include "mojo/public/system/core.h" | 7 #include "mojo/public/system/core.h" |
| 8 #include "mojo/public/system/macros.h" | |
|
Ben Goodger (Google)
2013/10/29 21:34:41
I noticed that this app need not depend on base at
| |
| 9 #include "mojo/system/core_impl.h" | 9 #include "mojo/system/core_impl.h" |
| 10 | 10 |
| 11 #if defined(OS_WIN) | 11 #if defined(OS_WIN) |
| 12 #if !defined(CDECL) | 12 #if !defined(CDECL) |
| 13 #define CDECL __cdecl | 13 #define CDECL __cdecl |
| 14 #endif | 14 #endif |
| 15 #define SAMPLE_APP_EXPORT __declspec(dllexport) | 15 #define SAMPLE_APP_EXPORT __declspec(dllexport) |
| 16 #else | 16 #else |
| 17 #define CDECL | 17 #define CDECL |
| 18 #define SAMPLE_APP_EXPORT __attribute__((visibility("default"))) | 18 #define SAMPLE_APP_EXPORT __attribute__((visibility("default"))) |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 32 // Failure.. | 32 // Failure.. |
| 33 if (buf) | 33 if (buf) |
| 34 delete[] buf; | 34 delete[] buf; |
| 35 return NULL; | 35 return NULL; |
| 36 } | 36 } |
| 37 return buf; | 37 return buf; |
| 38 } | 38 } |
| 39 | 39 |
| 40 class SampleMessageWaiter { | 40 class SampleMessageWaiter { |
| 41 public: | 41 public: |
| 42 explicit SampleMessageWaiter(mojo::Handle pipe) : pipe_(pipe) {} | 42 explicit SampleMessageWaiter(mojo::Handle pipe) |
| 43 : pipe_(pipe), running_(false) {} | |
| 43 ~SampleMessageWaiter() {} | 44 ~SampleMessageWaiter() {} |
| 44 | 45 |
| 45 void Read() { | 46 void Read() { |
| 46 char* string = ReadStringFromPipe(pipe_); | 47 char* string = ReadStringFromPipe(pipe_); |
| 47 if (string) { | 48 if (string) { |
| 48 printf("Read string from pipe: %s\n", string); | 49 printf("Read string from pipe: %s\n", string); |
| 49 delete[] string; | 50 delete[] string; |
| 50 string = NULL; | 51 string = NULL; |
| 51 } | 52 } |
| 52 } | 53 } |
| 53 | 54 |
| 54 void WaitAndRead() { | 55 void WaitAndRead() { |
| 55 MojoResult result = mojo::Wait(pipe_, MOJO_WAIT_FLAG_READABLE, 100); | 56 running_ = true; |
|
abarth-chromium
2013/10/29 21:48:44
Do we want to set running_ to false at some point?
| |
| 56 if (result < MOJO_RESULT_OK) { | 57 do { |
| 57 // Failure... | 58 MojoResult result = mojo::Wait(pipe_, MOJO_WAIT_FLAG_READABLE, 100); |
| 58 } | 59 if (result < MOJO_RESULT_OK) { |
| 59 | 60 // Failure... |
| 60 Read(); | 61 } |
| 62 Read(); | |
| 63 } while (running_); | |
| 64 // TODO: quit, etc. i.e. real MessageLoop. | |
| 61 } | 65 } |
| 62 | 66 |
| 63 private: | 67 private: |
| 64 | 68 |
| 65 mojo::Handle pipe_; | 69 mojo::Handle pipe_; |
| 66 DISALLOW_COPY_AND_ASSIGN(SampleMessageWaiter); | 70 bool running_; |
| 71 | |
| 72 MOJO_DISALLOW_COPY_AND_ASSIGN(SampleMessageWaiter); | |
| 67 }; | 73 }; |
| 68 | 74 |
| 69 extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain( | 75 extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain( |
| 70 mojo::Handle pipe) { | 76 mojo::Handle pipe) { |
| 71 SampleMessageWaiter(pipe).WaitAndRead(); | 77 SampleMessageWaiter(pipe).WaitAndRead(); |
| 72 return MOJO_RESULT_OK; | 78 return MOJO_RESULT_OK; |
| 73 } | 79 } |
| OLD | NEW |