X-Git-Url: https://gerrit.akraino.org/r/gitweb?a=blobdiff_plain;f=src%2Ftype3_AndroidCloud%2Fanbox-master%2Fsrc%2Fanbox%2Fcmds%2Fwait_ready.cpp;fp=src%2Ftype3_AndroidCloud%2Fanbox-master%2Fsrc%2Fanbox%2Fcmds%2Fwait_ready.cpp;h=9e62ce6e53633c95a0e4c67da4ce291e81e7fd5a;hb=e26c1ec581be598521517829adba8c8dd23a768f;hp=0000000000000000000000000000000000000000;hpb=6699c1aea74eeb0eb400e6299079f0c7576f716f;p=iec.git
diff --git a/src/type3_AndroidCloud/anbox-master/src/anbox/cmds/wait_ready.cpp b/src/type3_AndroidCloud/anbox-master/src/anbox/cmds/wait_ready.cpp
new file mode 100644
index 0000000..9e62ce6
--- /dev/null
+++ b/src/type3_AndroidCloud/anbox-master/src/anbox/cmds/wait_ready.cpp
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2016 Canonical, Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ *
+ * Authored by: Thomas VoÃ
+ *
+ */
+
+#include "anbox/cmds/wait_ready.h"
+#include "anbox/dbus/stub/application_manager.h"
+
+namespace {
+constexpr const unsigned int max_wait_attempts{30};
+}
+
+anbox::cmds::WaitReady::WaitReady()
+ : CommandWithFlagsAndAction{
+ cli::Name{"wait-ready"}, cli::Usage{"wait-ready"},
+ cli::Description{"Wait until the Android system has successfully booted"}} {
+
+ flag(cli::make_flag(cli::Name{"use-system-dbus"},
+ cli::Description{"Use system instead of session DBus"},
+ use_system_dbus_));
+
+ action([this](const cli::Command::Context&) {
+ auto bus_type = anbox::dbus::Bus::Type::Session;
+ if (use_system_dbus_)
+ bus_type = anbox::dbus::Bus::Type::System;
+ auto bus = std::make_shared(bus_type);
+
+ auto stub = dbus::stub::ApplicationManager::create_for_bus(bus);
+
+ unsigned int n = 0;
+ while (n < max_wait_attempts) {
+ stub->update_properties();
+ if (stub->ready().get())
+ return EXIT_SUCCESS;
+
+ std::this_thread::sleep_for(std::chrono::seconds{1});
+ n++;
+ }
+
+ return EXIT_FAILURE;
+ });
+}