From 2b4e10f4dcd668a1e0ba3b800672e1ba4e6909de Mon Sep 17 00:00:00 2001 From: "darin@chromium.org" <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> Date: Thu, 29 May 2014 19:00:36 +0000 Subject: Mojo: more idiomatic C++ bindings This change eliminates AllocationScope in favor of heap allocating the "wrapper" classes, which are now no longer wrappers in the true sense but rather deep copies of the archived structs. We still use the term "wrapper" in the code generator. With this design, the fact that structs are encoded as pointers (that may be null) is more apparent. For example, a Foo struct may be allocated and stored in a FooPtr. The FooPtr implements move-only semantics. This is because some of the members of Foo may be move-only (e.g., handles). Strings are now just thin wrappers around std::string that impose nullability and a more restrictive API. It is not possible to mutate the elements of a string after it has been created. String acts like a pointer to a possibly null array of characters, which is very similar to a char*. Arrays are now just thin wrappers around std::vector that impose nullability and a more restrictive API. Unlike String, Array does support mutation of its elements after creation, but there is no support for resizing an array. (We can add support for push_back and resize if needed.) BUG=365922 R=yzshen@chromium.org Review URL: https://codereview.chromium.org/294833002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@273527 0039d316-1c4b-4281-b951-d872f2087c98 --- mojo/examples/dbus_echo/dbus_echo_app.cc | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'mojo/examples/dbus_echo') diff --git a/mojo/examples/dbus_echo/dbus_echo_app.cc b/mojo/examples/dbus_echo/dbus_echo_app.cc index 0ccccc6..5a9b80f 100644 --- a/mojo/examples/dbus_echo/dbus_echo_app.cc +++ b/mojo/examples/dbus_echo/dbus_echo_app.cc @@ -8,7 +8,6 @@ #include "base/bind.h" #include "base/logging.h" #include "mojo/public/cpp/application/application.h" -#include "mojo/public/cpp/bindings/allocation_scope.h" #include "mojo/public/cpp/environment/environment.h" #include "mojo/public/cpp/system/core.h" #include "mojo/public/cpp/system/macros.h" @@ -27,14 +26,14 @@ class DBusEchoApp : public Application { ConnectTo("dbus:org.chromium.EchoService/org/chromium/MojoImpl", &echo_service_); - AllocationScope scope; - echo_service_->Echo("who", base::Bind(&DBusEchoApp::OnEcho, - base::Unretained(this))); + echo_service_->Echo( + String::From("who"), + base::Bind(&DBusEchoApp::OnEcho, base::Unretained(this))); } private: - void OnEcho(const String& echoed) { - LOG(INFO) << "echo'd " << echoed.To<std::string>(); + void OnEcho(String echoed) { + LOG(INFO) << "echo'd " << echoed; } EchoServicePtr echo_service_; -- cgit v1.1