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

Side by Side Diff: mojo/examples/sample_app/sample_app.cc

Issue 72123002: Work in progress for end-to-end bindings (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use SimpleThread instead of Thread to avoid creating a MessageLoop Created 7 years, 1 month 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
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 #include <string> 6 #include <string>
7 7
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "mojo/common/bindings_support_impl.h" 9 #include "mojo/common/bindings_support_impl.h"
10 #include "mojo/examples/sample_app/hello_world_client_impl.h" 10 #include "mojo/examples/sample_app/hello_world_client_impl.h"
11 #include "mojo/public/bindings/lib/bindings_support.h" 11 #include "mojo/public/bindings/lib/bindings_support.h"
12 #include "mojo/public/system/core.h" 12 #include "mojo/public/system/core.h"
13 #include "mojo/public/system/macros.h" 13 #include "mojo/public/system/macros.h"
14 14
15 #if defined(WIN32) 15 #if defined(WIN32)
16 #if !defined(CDECL) 16 #if !defined(CDECL)
17 #define CDECL __cdecl 17 #define CDECL __cdecl
18 #endif 18 #endif
19 #define SAMPLE_APP_EXPORT __declspec(dllexport) 19 #define SAMPLE_APP_EXPORT __declspec(dllexport)
20 #else 20 #else
21 #define CDECL 21 #define CDECL
22 #define SAMPLE_APP_EXPORT __attribute__((visibility("default"))) 22 #define SAMPLE_APP_EXPORT __attribute__((visibility("default")))
23 #endif 23 #endif
24 24
25 namespace mojo { 25 namespace mojo {
26 namespace examples { 26 namespace examples {
27 27
28 static HelloWorldClientImpl* g_client = 0;
29
30 void SayHello(mojo::Handle pipe) { 28 void SayHello(mojo::Handle pipe) {
31 g_client = new HelloWorldClientImpl(pipe); 29 base::MessageLoop loop;
darin (slow to review) 2013/11/15 00:01:37 it would be rational for BindingsSupportImpl to as
DaveMoore 2013/11/15 00:11:33 Done.
32 30 // Send message out.
31 HelloWorldClientImpl client(pipe);
33 mojo::ScratchBuffer buf; 32 mojo::ScratchBuffer buf;
34 const std::string kGreeting("hello, world!"); 33 const std::string kGreeting("hello, world!");
35 mojo::String* greeting = mojo::String::NewCopyOf(&buf, kGreeting); 34 mojo::String* greeting = mojo::String::NewCopyOf(&buf, kGreeting);
35 client.service()->Greeting(greeting);
36 36
37 g_client->service()->Greeting(greeting); 37 // Run loop to receieve Ack. The client will quit the loop.
38 loop.Run();
38 } 39 }
39 40
40 } // examples 41 } // examples
41 } // mojo 42 } // mojo
42 43
43 extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain( 44 extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain(
44 mojo::Handle pipe) { 45 mojo::Handle pipe) {
45 // Create a message loop on this thread for processing incoming messages. 46 printf("here!\n");
abarth-chromium 2013/11/14 23:59:05 We probably want to remove this before landing. :
DaveMoore 2013/11/15 00:11:33 Done.
46 // This creates a dependency on base that we'll be removing soon.
47 base::MessageLoop loop;
48
49 // Set the global bindings support. 47 // Set the global bindings support.
50 mojo::common::BindingsSupportImpl bindings_support; 48 mojo::common::BindingsSupportImpl bindings_support;
51 mojo::BindingsSupport::Set(&bindings_support); 49 mojo::BindingsSupport::Set(&bindings_support);
52 50
53 // Send message out.
54 mojo::examples::SayHello(pipe); 51 mojo::examples::SayHello(pipe);
55 52
56 // Run loop to receieve Ack.
57 loop.Run();
58
59 mojo::BindingsSupport::Set(NULL); 53 mojo::BindingsSupport::Set(NULL);
60 return MOJO_RESULT_OK; 54 return MOJO_RESULT_OK;
61 } 55 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698