Work in progress for end-to-end bindings
[chromium-blink-merge.git] / mojo / examples / sample_app / sample_app.cc
blobb071a4eaa769ae82fcfcd0ac2cd520d7a4b61a97
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
3 // found in the LICENSE file.
5 #include <stdio.h>
6 #include <string>
8 #include "base/message_loop/message_loop.h"
9 #include "mojo/common/bindings_support_impl.h"
10 #include "mojo/examples/sample_app/hello_world_client_impl.h"
11 #include "mojo/public/bindings/lib/bindings_support.h"
12 #include "mojo/public/system/core.h"
13 #include "mojo/public/system/macros.h"
15 #if defined(WIN32)
16 #if !defined(CDECL)
17 #define CDECL __cdecl
18 #endif
19 #define SAMPLE_APP_EXPORT __declspec(dllexport)
20 #else
21 #define CDECL
22 #define SAMPLE_APP_EXPORT __attribute__((visibility("default")))
23 #endif
25 namespace mojo {
26 namespace examples {
28 void SayHello(mojo::Handle pipe) {
29 // Send message out.
30 HelloWorldClientImpl client(pipe);
31 mojo::ScratchBuffer buf;
32 const std::string kGreeting("hello, world!");
33 mojo::String* greeting = mojo::String::NewCopyOf(&buf, kGreeting);
34 client.service()->Greeting(greeting);
36 // Run loop to receieve Ack. The client will quit the loop.
37 base::MessageLoop::current()->Run();
40 } // examples
41 } // mojo
43 extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain(
44 mojo::Handle pipe) {
45 base::MessageLoop loop;
46 // Set the global bindings support.
47 mojo::common::BindingsSupportImpl bindings_support;
48 mojo::BindingsSupport::Set(&bindings_support);
50 mojo::examples::SayHello(pipe);
52 mojo::BindingsSupport::Set(NULL);
53 return MOJO_RESULT_OK;