Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
|
jamesr
2015/08/17 21:38:21
2015
gautham
2015/08/18 01:54:21
Done.
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <stdio.h> | |
| 6 | |
| 7 #include "examples/bank_app/bank.mojom.h" | |
| 8 | |
| 9 #include "mojo/public/c/system/main.h" | |
| 10 #include "mojo/public/cpp/application/application_impl.h" | |
| 11 #include "mojo/public/cpp/application/application_runner.h" | |
| 12 #include "mojo/public/cpp/utility/run_loop.h" | |
| 13 #include "mojo/services/vanadium/security/public/interfaces/principal.mojom.h" | |
| 14 | |
| 15 namespace mojo { | |
| 16 namespace examples { | |
| 17 | |
| 18 class LoginHandler { | |
| 19 public: | |
| 20 void Run(const BlessingPtr& b) const { | |
| 21 std::string user; | |
| 22 if (b.get()) { | |
|
jamesr
2015/08/17 21:38:21
StructPtr<> (and the rest of our ptr wrapper types
gautham
2015/08/18 01:54:21
Done.
| |
| 23 for (size_t i = 0; i < b.get()->chain.size(); i++) { | |
|
jamesr
2015/08/17 21:38:21
b defines operator->, so you can just say
b->chai
gautham
2015/08/18 01:54:21
Done.
| |
| 24 user += "/"; | |
|
jamesr
2015/08/17 21:38:21
this is a pretty inefficient way to build a string
gautham
2015/08/18 01:54:21
Acknowledged.
| |
| 25 user += b.get()->chain[i].get()->extension; | |
|
jamesr
2015/08/17 21:38:21
same for chain[i]
gautham
2015/08/18 01:54:21
Done.
| |
| 26 } | |
| 27 } | |
| 28 if (user.length() > 0) { | |
|
jamesr
2015/08/17 21:38:21
!empty()
gautham
2015/08/18 01:54:21
Done.
| |
| 29 MOJO_LOG(INFO) << "Welcome: " << user; | |
| 30 } | |
| 31 RunLoop::current()->Quit(); // All done! | |
| 32 } | |
| 33 }; | |
| 34 | |
| 35 class GetBalanceResponse { | |
| 36 public: | |
| 37 void Run(const int32_t& balance) const { | |
| 38 MOJO_LOG(INFO) << "Bank balance: " << balance; | |
| 39 } | |
| 40 }; | |
| 41 | |
| 42 class BankCustomer : public ApplicationDelegate { | |
| 43 public: | |
| 44 void Initialize(ApplicationImpl* app) override { | |
| 45 // Get user login credentials | |
| 46 app->ConnectToService("mojo:principal_service", &login_service_); | |
| 47 login_service_->Login(LoginHandler()); | |
| 48 login_service_.WaitForIncomingResponse(); | |
| 49 | |
| 50 BankPtr bank; | |
| 51 app->ConnectToService("mojo:bank", &bank); | |
| 52 bank->Deposit(500/*usd*/); | |
| 53 bank->Withdraw(100/*usd*/); | |
| 54 bank->GetBalance(GetBalanceResponse()); | |
|
jamesr
2015/08/17 21:38:21
seems like a good place to use a lambda instead of
gautham
2015/08/18 01:54:21
Done.
| |
| 55 bank.WaitForIncomingResponse(); | |
| 56 } | |
| 57 void Quit() override { | |
| 58 login_service_->Logout(); | |
| 59 } | |
| 60 private: | |
| 61 PrincipalServicePtr login_service_; | |
| 62 }; | |
| 63 | |
| 64 } // namespace examples | |
| 65 } // namespace mojo | |
| 66 | |
| 67 MojoResult MojoMain(MojoHandle application_request) { | |
| 68 mojo::ApplicationRunner runner(new mojo::examples::BankCustomer); | |
| 69 return runner.Run(application_request); | |
| 70 } | |
| OLD | NEW |