Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(207)

Unified Diff: mojo/shell/sample_app.cc

Issue 25895002: Simple shell that loads a dll and calls an entrypoint function passing in a handle to a pipe create… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/shell/sample_app.cc
diff --git a/mojo/shell/sample_app.cc b/mojo/shell/sample_app.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1246852a428ea535826d22d81bd0c50c920926ae
--- /dev/null
+++ b/mojo/shell/sample_app.cc
@@ -0,0 +1,64 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <stdio.h>
+
+#include "base/basictypes.h"
+#include "mojo/public/system/core.h"
+#include "mojo/system/core_impl.h"
+
+typedef MojoResult (*MojoMainFunction)(MojoHandle pipe);
+
+char* ReadStringFromPipe(MojoHandle pipe) {
+ uint32_t len = 0;
+ char* buf = NULL;
+ MojoResult result = MojoReadMessage(pipe, buf, &len, NULL, NULL,
+ MOJO_READ_MESSAGE_FLAG_NONE);
+ if (result == MOJO_RESULT_RESOURCE_EXHAUSTED) {
+ buf = new char[len];
+ result = MojoReadMessage(pipe, buf, &len, NULL, NULL,
+ MOJO_READ_MESSAGE_FLAG_NONE);
+ }
+ if (result < MOJO_RESULT_OK) {
+ // Failure..
+ if (buf)
+ delete[] buf;
+ return NULL;
+ }
+ return buf;
+}
+
+class SampleMessageWaiter {
+ public:
+ explicit SampleMessageWaiter(MojoHandle pipe) : pipe_(pipe) {}
+ ~SampleMessageWaiter() {}
+
+ void Read() {
+ char* string = ReadStringFromPipe(pipe_);
+ if (string) {
+ printf("Read string from pipe: %s\n", string);
+ delete[] string;
+ string = NULL;
+ }
+ }
+
+ void WaitAndRead() {
+ MojoResult result = MojoWait(pipe_, MOJO_WAIT_FLAG_READABLE, 100);
+ if (result < MOJO_RESULT_OK) {
+ // Failure...
Ben Goodger (Google) 2013/10/03 17:45:18 a typical meme in this code. can we have a discuss
darin (slow to review) 2013/10/04 21:47:14 yeah, we should probably figure out a good canonic
+ }
+
+ Read();
+ }
+
+ private:
+
+ MojoHandle pipe_;
+ DISALLOW_COPY_AND_ASSIGN(SampleMessageWaiter);
+};
+
+extern "C" __declspec(dllexport) MojoResult __cdecl MojoMain(MojoHandle pipe) {
+ SampleMessageWaiter(pipe).WaitAndRead();
+ return MOJO_RESULT_NOT_FOUND;
+}

Powered by Google App Engine
This is Rietveld 408576698