| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stdio.h> | 5 #include <stdio.h> |
| 6 | 6 |
| 7 #include "examples/echo/echo.mojom.h" | 7 #include "examples/echo/echo.mojom.h" |
| 8 #include "mojo/public/c/system/main.h" | 8 #include "mojo/public/c/system/main.h" |
| 9 #include "mojo/public/cpp/application/application_delegate.h" | 9 #include "mojo/public/cpp/application/application_delegate.h" |
| 10 #include "mojo/public/cpp/application/application_impl.h" | 10 #include "mojo/public/cpp/application/application_impl.h" |
| 11 #include "mojo/public/cpp/application/application_runner.h" | 11 #include "mojo/public/cpp/application/application_runner.h" |
| 12 #include "mojo/public/cpp/utility/run_loop.h" | 12 #include "mojo/public/cpp/utility/run_loop.h" |
| 13 #include "mojo/services/vanadium/security/public/interfaces/principal.mojom.h" |
| 13 | 14 |
| 14 namespace mojo { | 15 namespace mojo { |
| 15 namespace examples { | 16 namespace examples { |
| 16 | 17 |
| 17 class ResponsePrinter { | 18 class ResponsePrinter { |
| 18 public: | 19 public: |
| 19 void Run(const String& value) const { | 20 void Run(const String& value) const { |
| 20 printf("Response: \"%s\"\n", value.get().c_str()); | 21 printf("Response: \"%s\"\n", value.get().c_str()); |
| 21 | 22 |
| 22 RunLoop::current()->Quit(); // All done! | 23 RunLoop::current()->Quit(); // All done! |
| 23 } | 24 } |
| 24 }; | 25 }; |
| 25 | 26 |
| 26 class EchoClientDelegate : public ApplicationDelegate { | 27 class EchoClientDelegate : public ApplicationDelegate { |
| 27 public: | 28 public: |
| 28 void Initialize(ApplicationImpl* app) override { | 29 void Initialize(ApplicationImpl* app) override { |
| 30 // Get user login credentials |
| 31 app->ConnectToService("mojo:go_principal_service", &login_service_); |
| 32 login_service_->Login(Callback<void(const BlessingPtr)>()); |
| 33 |
| 29 app->ConnectToService("mojo:echo_server", &echo_); | 34 app->ConnectToService("mojo:echo_server", &echo_); |
| 35 echo_->EchoString("hello world", ResponsePrinter()); |
| 36 } |
| 30 | 37 |
| 31 echo_->EchoString("hello world", ResponsePrinter()); | 38 void Quit() override { |
| 39 login_service_->Logout(); |
| 32 } | 40 } |
| 33 | 41 |
| 34 private: | 42 private: |
| 35 EchoPtr echo_; | 43 EchoPtr echo_; |
| 44 PrincipalServicePtr login_service_; |
| 36 }; | 45 }; |
| 37 | 46 |
| 38 } // namespace examples | 47 } // namespace examples |
| 39 } // namespace mojo | 48 } // namespace mojo |
| 40 | 49 |
| 41 MojoResult MojoMain(MojoHandle application_request) { | 50 MojoResult MojoMain(MojoHandle application_request) { |
| 42 mojo::ApplicationRunner runner(new mojo::examples::EchoClientDelegate); | 51 mojo::ApplicationRunner runner(new mojo::examples::EchoClientDelegate); |
| 43 return runner.Run(application_request); | 52 return runner.Run(application_request); |
| 44 } | 53 } |
| OLD | NEW |