OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <memory> | 5 #include <memory> |
6 | 6 |
7 #include "examples/bank_app/bank.mojom.h" | 7 #include "examples/bank_app/bank.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_impl.h" | 9 #include "mojo/public/cpp/application/application_impl.h" |
10 #include "mojo/public/cpp/application/application_runner.h" | 10 #include "mojo/public/cpp/application/application_runner.h" |
11 #include "mojo/public/cpp/utility/run_loop.h" | 11 #include "mojo/public/cpp/utility/run_loop.h" |
12 #include "mojo/services/vanadium/security/interfaces/principal.mojom.h" | 12 #include "mojo/services/vanadium/security/interfaces/principal.mojom.h" |
13 | 13 |
14 namespace examples { | 14 namespace examples { |
15 | 15 |
16 class LoginHandler { | 16 class LoginHandler { |
17 public: | 17 public: |
18 void Run(const vanadium::UserPtr& user) const { | 18 void Run(const vanadium::UserPtr& user) const { |
19 if (user) { | 19 if (user) { |
20 MOJO_LOG(INFO) << "User logged-in as " << user->email; | 20 MOJO_LOG(INFO) << "User logged-in as " << user->email; |
21 } | 21 } |
22 } | 22 } |
23 }; | 23 }; |
24 | 24 |
25 class BankCustomer : public mojo::ApplicationDelegate { | 25 class BankCustomer : public mojo::ApplicationDelegate { |
26 public: | 26 public: |
27 void Initialize(mojo::ApplicationImpl* app) override { | 27 void Initialize(mojo::ApplicationImpl* app) override { |
28 app->ConnectToService("mojo:principal_service", &login_service_); | 28 app->ConnectToServiceDeprecated("mojo:principal_service", &login_service_); |
29 | 29 |
30 // Login to the principal service to get a user identity. | 30 // Login to the principal service to get a user identity. |
31 login_service_->Login(LoginHandler()); | 31 login_service_->Login(LoginHandler()); |
32 // Check and see whether we got a valid user id. | 32 // Check and see whether we got a valid user id. |
33 if (!login_service_.WaitForIncomingResponse()) { | 33 if (!login_service_.WaitForIncomingResponse()) { |
34 MOJO_LOG(INFO) << "Login() to the principal service failed"; | 34 MOJO_LOG(INFO) << "Login() to the principal service failed"; |
35 } | 35 } |
36 | 36 |
37 BankPtr bank; | 37 BankPtr bank; |
38 app->ConnectToService("mojo:bank", &bank); | 38 app->ConnectToServiceDeprecated("mojo:bank", &bank); |
39 bank->Deposit(500/*usd*/); | 39 bank->Deposit(500/*usd*/); |
40 bank->Withdraw(100/*usd*/); | 40 bank->Withdraw(100/*usd*/); |
41 auto gb_callback = [](const int32_t& balance) { | 41 auto gb_callback = [](const int32_t& balance) { |
42 MOJO_LOG(INFO) << "Bank balance: " << balance; | 42 MOJO_LOG(INFO) << "Bank balance: " << balance; |
43 }; | 43 }; |
44 bank->GetBalance(mojo::Callback<void(const int32_t&)>(gb_callback)); | 44 bank->GetBalance(mojo::Callback<void(const int32_t&)>(gb_callback)); |
45 bank.WaitForIncomingResponse(); | 45 bank.WaitForIncomingResponse(); |
46 } | 46 } |
47 void Quit() override { | 47 void Quit() override { |
48 login_service_->Logout(); | 48 login_service_->Logout(); |
49 } | 49 } |
50 private: | 50 private: |
51 vanadium::PrincipalServicePtr login_service_; | 51 vanadium::PrincipalServicePtr login_service_; |
52 }; | 52 }; |
53 | 53 |
54 } // namespace examples | 54 } // namespace examples |
55 | 55 |
56 MojoResult MojoMain(MojoHandle application_request) { | 56 MojoResult MojoMain(MojoHandle application_request) { |
57 mojo::ApplicationRunner runner( | 57 mojo::ApplicationRunner runner( |
58 std::unique_ptr<examples::BankCustomer>(new examples::BankCustomer())); | 58 std::unique_ptr<examples::BankCustomer>(new examples::BankCustomer())); |
59 return runner.Run(application_request); | 59 return runner.Run(application_request); |
60 } | 60 } |
OLD | NEW |