Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1326)

Unified Diff: examples/bank_app/customer.cc

Issue 1261403003: Initial skeletal implementation of the PrincipalService. Also, use the Login()/GetUserBlessing() (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: minor logging fixes Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: examples/bank_app/customer.cc
diff --git a/examples/bank_app/customer.cc b/examples/bank_app/customer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d6c34f151d723b102f1f412b7aed275fedff7bd4
--- /dev/null
+++ b/examples/bank_app/customer.cc
@@ -0,0 +1,70 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
jamesr 2015/08/17 21:38:21 2015
gautham 2015/08/18 01:54:21 Done.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <stdio.h>
+
+#include "examples/bank_app/bank.mojom.h"
+
+#include "mojo/public/c/system/main.h"
+#include "mojo/public/cpp/application/application_impl.h"
+#include "mojo/public/cpp/application/application_runner.h"
+#include "mojo/public/cpp/utility/run_loop.h"
+#include "mojo/services/vanadium/security/public/interfaces/principal.mojom.h"
+
+namespace mojo {
+namespace examples {
+
+class LoginHandler {
+ public:
+ void Run(const BlessingPtr& b) const {
+ std::string user;
+ 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.
+ 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.
+ 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.
+ 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.
+ }
+ }
+ if (user.length() > 0) {
jamesr 2015/08/17 21:38:21 !empty()
gautham 2015/08/18 01:54:21 Done.
+ MOJO_LOG(INFO) << "Welcome: " << user;
+ }
+ RunLoop::current()->Quit(); // All done!
+ }
+};
+
+class GetBalanceResponse {
+ public:
+ void Run(const int32_t& balance) const {
+ MOJO_LOG(INFO) << "Bank balance: " << balance;
+ }
+};
+
+class BankCustomer : public ApplicationDelegate {
+ public:
+ void Initialize(ApplicationImpl* app) override {
+ // Get user login credentials
+ app->ConnectToService("mojo:principal_service", &login_service_);
+ login_service_->Login(LoginHandler());
+ login_service_.WaitForIncomingResponse();
+
+ BankPtr bank;
+ app->ConnectToService("mojo:bank", &bank);
+ bank->Deposit(500/*usd*/);
+ bank->Withdraw(100/*usd*/);
+ 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.
+ bank.WaitForIncomingResponse();
+ }
+ void Quit() override {
+ login_service_->Logout();
+ }
+ private:
+ PrincipalServicePtr login_service_;
+};
+
+} // namespace examples
+} // namespace mojo
+
+MojoResult MojoMain(MojoHandle application_request) {
+ mojo::ApplicationRunner runner(new mojo::examples::BankCustomer);
+ return runner.Run(application_request);
+}

Powered by Google App Engine
This is Rietveld 408576698