summaryrefslogtreecommitdiffstats
path: root/mojo/examples/sample_app/sample_app.cc
blob: 1229a5f8455ee31ab07fd3aa17e01664ed25e9fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 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 <string>

#include "base/message_loop/message_loop.h"
#include "mojo/common/bindings_support_impl.h"
#include "mojo/examples/sample_app/native_viewport_client_impl.h"
#include "mojo/public/bindings/lib/bindings_support.h"
#include "mojo/public/system/core.h"
#include "mojo/public/system/macros.h"

#if defined(WIN32)
#if !defined(CDECL)
#define CDECL __cdecl
#endif
#define SAMPLE_APP_EXPORT __declspec(dllexport)
#else
#define CDECL
#define SAMPLE_APP_EXPORT __attribute__((visibility("default")))
#endif

namespace mojo {
namespace examples {

void Start(ScopedMessagePipeHandle pipe) {
  printf("Starting sample app.\n");
  NativeViewportClientImpl client(pipe.Pass());
  printf("Opening native viewport.\n");
  client.service()->Open();

  base::MessageLoop::current()->Run();
}

}  // examples
}  // mojo

extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain(MojoHandle pipe) {
  base::MessageLoop loop;
  mojo::common::BindingsSupportImpl bindings_support;
  mojo::BindingsSupport::Set(&bindings_support);

  mojo::ScopedMessagePipeHandle scoped_handle;
  scoped_handle.reset(mojo::MessagePipeHandle(pipe));
  mojo::examples::Start(scoped_handle.Pass());

  mojo::BindingsSupport::Set(NULL);
  return MOJO_RESULT_OK;
}