diff options
-rw-r--r-- | mojo/examples/hello_world_service/hello_world_service.mojom | 17 | ||||
-rw-r--r-- | mojo/examples/hello_world_service/hello_world_service_impl.cc | 26 | ||||
-rw-r--r-- | mojo/examples/hello_world_service/hello_world_service_impl.h | 27 | ||||
-rw-r--r-- | mojo/examples/sample_app/hello_world_client_impl.cc | 24 | ||||
-rw-r--r-- | mojo/examples/sample_app/hello_world_client_impl.h | 32 | ||||
-rw-r--r-- | mojo/examples/sample_app/sample_app.cc | 78 | ||||
-rw-r--r-- | mojo/mojo.gyp | 36 | ||||
-rw-r--r-- | mojo/public/bindings/mojom_bindings_generator.gypi | 6 | ||||
-rw-r--r-- | mojo/shell/app_container.cc | 23 | ||||
-rw-r--r-- | mojo/shell/app_container.h | 5 |
10 files changed, 62 insertions, 212 deletions
diff --git a/mojo/examples/hello_world_service/hello_world_service.mojom b/mojo/examples/hello_world_service/hello_world_service.mojom deleted file mode 100644 index 5f03d69..0000000 --- a/mojo/examples/hello_world_service/hello_world_service.mojom +++ /dev/null @@ -1,17 +0,0 @@ -// 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. - -module mojo { - -[Peer=HelloWorldClient] -interface HelloWorldService { - void Greeting(string greeting); -}; - -[Peer=HelloWorldService] -interface HelloWorldClient { - void DidReceiveGreeting(int32 result); -}; - -} diff --git a/mojo/examples/hello_world_service/hello_world_service_impl.cc b/mojo/examples/hello_world_service/hello_world_service_impl.cc deleted file mode 100644 index d1060cb..0000000 --- a/mojo/examples/hello_world_service/hello_world_service_impl.cc +++ /dev/null @@ -1,26 +0,0 @@ -// 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 "mojo/examples/hello_world_service/hello_world_service_impl.h" - -#include <string> -#include "base/logging.h" - -namespace mojo { -namespace examples { - -HelloWorldServiceImpl::HelloWorldServiceImpl(mojo::Handle pipe) - : client_(pipe) { - client_.SetPeer(this); -} - -void HelloWorldServiceImpl::Greeting(const mojo::String* greeting) { - LOG(INFO) << greeting->To<std::string>(); - client_->DidReceiveGreeting(42); -} - -HelloWorldServiceImpl::~HelloWorldServiceImpl() {} - -} // examples -} // mojo diff --git a/mojo/examples/hello_world_service/hello_world_service_impl.h b/mojo/examples/hello_world_service/hello_world_service_impl.h deleted file mode 100644 index 6382617..0000000 --- a/mojo/examples/hello_world_service/hello_world_service_impl.h +++ /dev/null @@ -1,27 +0,0 @@ -// 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. - -#ifndef MOJO_EXAMPLES_HELLO_WORLD_SERVICE_HELLO_WORLD_SERVICE_IMPL_H_ -#define MOJO_EXAMPLES_HELLO_WORLD_SERVICE_HELLO_WORLD_SERVICE_IMPL_H_ - -#include "mojo/public/bindings/lib/remote_ptr.h" -#include "mojom/hello_world_service.h" - -namespace mojo { -namespace examples { - -class HelloWorldServiceImpl : public HelloWorldServiceStub { - public: - explicit HelloWorldServiceImpl(mojo::Handle pipe); - virtual ~HelloWorldServiceImpl(); - virtual void Greeting(const mojo::String* greeting) MOJO_OVERRIDE; - - private: - mojo::RemotePtr<HelloWorldClient> client_; -}; - -} // examples -} // mojo - -#endif // MOJO_EXAMPLES_HELLO_WORLD_SERVICE_HELLO_WORLD_SERVICE_IMPL_H_ diff --git a/mojo/examples/sample_app/hello_world_client_impl.cc b/mojo/examples/sample_app/hello_world_client_impl.cc deleted file mode 100644 index c1233fc..0000000 --- a/mojo/examples/sample_app/hello_world_client_impl.cc +++ /dev/null @@ -1,24 +0,0 @@ -// 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 "mojo/examples/sample_app/hello_world_client_impl.h" - -#include <stdio.h> - -namespace mojo { -namespace examples { - -HelloWorldClientImpl::HelloWorldClientImpl(mojo::Handle pipe) - : service_(pipe) { - service_.SetPeer(this); -} - -void HelloWorldClientImpl::DidReceiveGreeting(int32_t result) { - printf("DidReceiveGreeting from pipe: %d\n", result); -} - -HelloWorldClientImpl::~HelloWorldClientImpl() {} - -} // examples -} // mojo diff --git a/mojo/examples/sample_app/hello_world_client_impl.h b/mojo/examples/sample_app/hello_world_client_impl.h deleted file mode 100644 index 4995406..0000000 --- a/mojo/examples/sample_app/hello_world_client_impl.h +++ /dev/null @@ -1,32 +0,0 @@ -// 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. - -#ifndef MOJO_EXAMPLES_SAMPLE_APP_HELLO_WORLD_CLIENT_IMPL_H_ -#define MOJO_EXAMPLES_SAMPLE_APP_HELLO_WORLD_CLIENT_IMPL_H_ - -#include "mojo/public/bindings/lib/remote_ptr.h" -#include "mojom/hello_world_service.h" - -namespace mojo { -namespace examples { - -class HelloWorldClientImpl : public HelloWorldClientStub { - public: - explicit HelloWorldClientImpl(mojo::Handle pipe); - virtual ~HelloWorldClientImpl(); - - virtual void DidReceiveGreeting(int32_t result) MOJO_OVERRIDE; - - HelloWorldService* service() { - return service_.get(); - } - - private: - mojo::RemotePtr<HelloWorldService> service_; -}; - -} // examples -} // mojo - -#endif // MOJO_EXAMPLES_SAMPLE_APP_HELLO_WORLD_CLIENT_IMPL_H_ diff --git a/mojo/examples/sample_app/sample_app.cc b/mojo/examples/sample_app/sample_app.cc index 5bc67dc..abef1f3 100644 --- a/mojo/examples/sample_app/sample_app.cc +++ b/mojo/examples/sample_app/sample_app.cc @@ -3,12 +3,7 @@ // 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/hello_world_client_impl.h" -#include "mojo/public/bindings/lib/bindings_support.h" #include "mojo/public/system/core.h" #include "mojo/public/system/macros.h" @@ -22,40 +17,59 @@ #define SAMPLE_APP_EXPORT __attribute__((visibility("default"))) #endif -namespace mojo { -namespace examples { +char* ReadStringFromPipe(mojo::Handle pipe) { + uint32_t len = 0; + char* buf = NULL; + MojoResult result = mojo::ReadMessage(pipe, buf, &len, NULL, NULL, + MOJO_READ_MESSAGE_FLAG_NONE); + if (result == MOJO_RESULT_RESOURCE_EXHAUSTED) { + buf = new char[len]; + result = mojo::ReadMessage(pipe, buf, &len, NULL, NULL, + MOJO_READ_MESSAGE_FLAG_NONE); + } + if (result < MOJO_RESULT_OK) { + // Failure.. + if (buf) + delete[] buf; + return NULL; + } + return buf; +} -static HelloWorldClientImpl* g_client = 0; +class SampleMessageWaiter { + public: + explicit SampleMessageWaiter(mojo::Handle pipe) : pipe_(pipe) {} + ~SampleMessageWaiter() {} -void SayHello(mojo::Handle pipe) { - g_client = new HelloWorldClientImpl(pipe); + void Read() { + char* string = ReadStringFromPipe(pipe_); + if (string) { + printf("Read string from pipe: %s\n", string); + delete[] string; + string = NULL; + } + } - mojo::ScratchBuffer buf; - const std::string kGreeting("hello, world!"); - mojo::String* greeting = mojo::String::NewCopyOf(&buf, kGreeting); + void WaitAndRead() { + for (int i = 0; i < 100;) { + MojoResult result = mojo::Wait(pipe_, MOJO_WAIT_FLAG_READABLE, 100); + if (result < MOJO_RESULT_OK) { + // Failure... + continue; + } + ++i; + Read(); + } + } - g_client->service()->Greeting(greeting); -} + private: + mojo::Handle pipe_; -} // examples -} // mojo + MOJO_DISALLOW_COPY_AND_ASSIGN(SampleMessageWaiter); +}; extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain( mojo::Handle pipe) { - // Create a message loop on this thread for processing incoming messages. - // This creates a dependency on base that we'll be removing soon. - base::MessageLoop loop; - - // Set the global bindings support. - mojo::common::BindingsSupportImpl bindings_support; - mojo::BindingsSupport::Set(&bindings_support); - - // Send message out. - mojo::examples::SayHello(pipe); - - // Run loop to receieve Ack. - loop.Run(); - - mojo::BindingsSupport::Set(NULL); + SampleMessageWaiter(pipe).WaitAndRead(); return MOJO_RESULT_OK; } diff --git a/mojo/mojo.gyp b/mojo/mojo.gyp index 3e05b33..e7cc056 100644 --- a/mojo/mojo.gyp +++ b/mojo/mojo.gyp @@ -233,7 +233,6 @@ 'mojo_system', 'mojo_utility', 'native_viewport', - 'hello_world_service_impl', ], 'sources': [ 'shell/app_container.cc', @@ -316,50 +315,15 @@ 'type': 'shared_library', 'dependencies': [ '../ui/gl/gl.gyp:gl', - 'hello_world_service', - 'mojo_common_lib', 'mojo_system', ], 'sources': [ - 'examples/sample_app/hello_world_client_impl.cc', - 'examples/sample_app/hello_world_client_impl.h', 'examples/sample_app/sample_app.cc', 'examples/sample_app/spinning_cube.cc', 'examples/sample_app/spinning_cube.h', ], }, { - 'target_name': 'hello_world_service', - 'type': 'static_library', - 'dependencies': [ - 'mojo_bindings', - 'mojo_system', - ], - 'export_dependent_settings': [ - 'mojo_bindings', - 'mojo_system', - ], - 'sources': [ - 'examples/hello_world_service/hello_world_service.mojom', - ], - 'includes': [ 'public/bindings/mojom_bindings_generator.gypi' ], - }, - { - 'target_name': 'hello_world_service_impl', - 'type': 'static_library', - 'sources': [ - 'examples/hello_world_service/hello_world_service_impl.cc', - 'examples/hello_world_service/hello_world_service_impl.h', - ], - 'export_dependent_settings': [ - 'hello_world_service', - ], - 'dependencies': [ - '../base/base.gyp:base', - 'hello_world_service', - ], - }, - { 'target_name': 'mojo_bindings', 'type': 'static_library', 'include_dirs': [ diff --git a/mojo/public/bindings/mojom_bindings_generator.gypi b/mojo/public/bindings/mojom_bindings_generator.gypi index 099e3eb7..17b4d31 100644 --- a/mojo/public/bindings/mojom_bindings_generator.gypi +++ b/mojo/public/bindings/mojom_bindings_generator.gypi @@ -42,11 +42,5 @@ '<(DEPTH)', '<(SHARED_INTERMEDIATE_DIR)', ], - 'direct_dependent_settings': { - 'include_dirs': [ - '<(DEPTH)', - '<(SHARED_INTERMEDIATE_DIR)', - ], - }, 'hard_dependency': 1, } diff --git a/mojo/shell/app_container.cc b/mojo/shell/app_container.cc index 07346a6..221c871 100644 --- a/mojo/shell/app_container.cc +++ b/mojo/shell/app_container.cc @@ -67,16 +67,12 @@ void AppContainer::Load(const GURL& app_url) { void AppContainer::DidCompleteLoad(const GURL& app_url, const base::FilePath& app_path) { - Handle shell_handle; Handle app_handle; - MojoResult result = CreateMessagePipe(&shell_handle, &app_handle); + MojoResult result = CreateMessagePipe(&shell_handle_, &app_handle); if (result < MOJO_RESULT_OK) { // Failure.. } - hello_world_service_.reset( - new examples::HelloWorldServiceImpl(shell_handle)); - // Launch the app on its own thread. // TODO(beng): Create a unique thread name. thread_.reset(new base::Thread("app_thread")); @@ -86,18 +82,25 @@ void AppContainer::DidCompleteLoad(const GURL& app_url, base::Bind(&LaunchAppOnThread, app_path, app_handle), base::Bind(&AppContainer::AppCompleted, weak_factory_.GetWeakPtr())); + const char* hello_msg = "Hello"; + result = WriteMessage(shell_handle_, hello_msg, + static_cast<uint32_t>(strlen(hello_msg)+1), + NULL, 0, MOJO_WRITE_MESSAGE_FLAG_NONE); + if (result < MOJO_RESULT_OK) { + // Failure.. + } + // TODO(beng): This should be created on demand by the NativeViewportService // when it is retrieved by the app. - // native_viewport_controller_.reset( - // new services::NativeViewportController(context_, shell_handle_)); + native_viewport_controller_.reset( + new services::NativeViewportController(context_, shell_handle_)); } void AppContainer::AppCompleted() { - hello_world_service_.reset(); - // TODO(aa): This code gets replaced once we have a service manager. - // native_viewport_controller_->Close(); + native_viewport_controller_->Close(); thread_.reset(); + Close(shell_handle_); } } // namespace shell diff --git a/mojo/shell/app_container.h b/mojo/shell/app_container.h index 5a55ada..ae6e277 100644 --- a/mojo/shell/app_container.h +++ b/mojo/shell/app_container.h @@ -8,7 +8,6 @@ #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" -#include "mojo/examples/hello_world_service/hello_world_service_impl.h" #include "mojo/public/system/core.h" #include "mojo/shell/loader.h" @@ -43,9 +42,11 @@ class AppContainer : public Loader::Delegate { Context* context_; scoped_ptr<Loader::Job> request_; scoped_ptr<base::Thread> thread_; - scoped_ptr<examples::HelloWorldServiceImpl> hello_world_service_; scoped_ptr<services::NativeViewportController> native_viewport_controller_; + // Following members are valid only on app thread. + Handle shell_handle_; + base::WeakPtrFactory<AppContainer> weak_factory_; DISALLOW_COPY_AND_ASSIGN(AppContainer); |