Inflating bounds for rotation should support min/max progress
[chromium-blink-merge.git] / mojo / shell / sample_app.cc
bloba3acbe3fa8ef19bfb5751ef2ee221644550ed763
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.
5 #include <stdio.h>
7 #include "base/basictypes.h"
8 #include "mojo/public/system/core.h"
9 #include "mojo/system/core_impl.h"
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
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);
31 if (result < MOJO_RESULT_OK) {
32 // Failure..
33 if (buf)
34 delete[] buf;
35 return NULL;
37 return buf;
40 class SampleMessageWaiter {
41 public:
42 explicit SampleMessageWaiter(mojo::Handle pipe) : pipe_(pipe) {}
43 ~SampleMessageWaiter() {}
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;
54 void WaitAndRead() {
55 MojoResult result = mojo::Wait(pipe_, MOJO_WAIT_FLAG_READABLE, 100);
56 if (result < MOJO_RESULT_OK) {
57 // Failure...
60 Read();
63 private:
65 mojo::Handle pipe_;
66 DISALLOW_COPY_AND_ASSIGN(SampleMessageWaiter);
69 extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain(
70 mojo::Handle pipe) {
71 SampleMessageWaiter(pipe).WaitAndRead();
72 return MOJO_RESULT_OK;