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

Side by Side 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: exports to template instantiations 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <stdio.h>
6
7 #include "base/basictypes.h"
8 #include "mojo/public/system/core.h"
9 #include "mojo/system/core_impl.h"
10
11 #if defined(OS_WIN)
12 #if !defined(CDECL)
13 #define CDECL __cdecl
14 #endif
15 #define SAMPLE_APP_EXPORT __declspec(dllexport)
16 #else
17 #define CDECL
18 #define SAMPLE_APP_EXPORT __attribute__((visibility("default")))
19 #endif
20
21 char* ReadStringFromPipe(mojo::Handle pipe) {
22 uint32_t len = 0;
23 char* buf = NULL;
24 MojoResult result = mojo::ReadMessage(pipe, buf, &len, NULL, NULL,
25 MOJO_READ_MESSAGE_FLAG_NONE);
26 if (result == MOJO_RESULT_RESOURCE_EXHAUSTED) {
27 buf = new char[len];
28 result = mojo::ReadMessage(pipe, buf, &len, NULL, NULL,
29 MOJO_READ_MESSAGE_FLAG_NONE);
30 }
31 if (result < MOJO_RESULT_OK) {
32 // Failure..
33 if (buf)
34 delete[] buf;
35 return NULL;
36 }
37 return buf;
38 }
39
40 class SampleMessageWaiter {
41 public:
42 explicit SampleMessageWaiter(mojo::Handle pipe) : pipe_(pipe) {}
43 ~SampleMessageWaiter() {}
44
45 void Read() {
46 char* string = ReadStringFromPipe(pipe_);
47 if (string) {
48 printf("Read string from pipe: %s\n", string);
49 delete[] string;
50 string = NULL;
51 }
52 }
53
54 void WaitAndRead() {
55 MojoResult result = mojo::Wait(pipe_, MOJO_WAIT_FLAG_READABLE, 100);
56 if (result < MOJO_RESULT_OK) {
57 // Failure...
58 }
59
60 Read();
61 }
62
63 private:
64
65 mojo::Handle pipe_;
66 DISALLOW_COPY_AND_ASSIGN(SampleMessageWaiter);
67 };
68
69 extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain(
70 mojo::Handle pipe) {
71 SampleMessageWaiter(pipe).WaitAndRead();
72 return MOJO_RESULT_OK;
73 }
OLDNEW
« build/all.gyp ('K') | « mojo/shell/app_container.cc ('k') | mojo/shell/shell.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698