X-Git-Url: https://gerrit.akraino.org/r/gitweb?a=blobdiff_plain;f=src%2Ftype3_AndroidCloud%2Fanbox-master%2Fandroid%2Fservice%2Fhost_connector.cpp;fp=src%2Ftype3_AndroidCloud%2Fanbox-master%2Fandroid%2Fservice%2Fhost_connector.cpp;h=4ff8da059db093ddc2571dec4db97e8fc5898126;hb=e26c1ec581be598521517829adba8c8dd23a768f;hp=0000000000000000000000000000000000000000;hpb=6699c1aea74eeb0eb400e6299079f0c7576f716f;p=iec.git diff --git a/src/type3_AndroidCloud/anbox-master/android/service/host_connector.cpp b/src/type3_AndroidCloud/anbox-master/android/service/host_connector.cpp new file mode 100644 index 0000000..4ff8da0 --- /dev/null +++ b/src/type3_AndroidCloud/anbox-master/android/service/host_connector.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2016 Simon Fels + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + */ + +#include "android/service/host_connector.h" +#include "android/service/local_socket_connection.h" +#include "android/service/message_processor.h" +#include "android/service/android_api_skeleton.h" +#include "android/service/platform_api_stub.h" + +#include "anbox/rpc/channel.h" + +#include +#include + +namespace anbox { +HostConnector::HostConnector() : + socket_(std::make_shared("/dev/anbox_bridge")), + pending_calls_(std::make_shared()), + android_api_skeleton_(std::make_shared()), + message_processor_(std::make_shared(socket_, pending_calls_, android_api_skeleton_)), + rpc_channel_(std::make_shared(pending_calls_, socket_)), + platform_api_stub_(std::make_shared(rpc_channel_)), + running_(false) { +} + +HostConnector::~HostConnector() { +} + +void HostConnector::start() { + if (running_) + return; + + running_.exchange(true); + thread_ = std::thread(std::bind(&HostConnector::main_loop, this)); +} + +void HostConnector::stop() { + if (!running_.exchange(false)) + return; + + thread_.join(); +} + +void HostConnector::main_loop() { + while (running_) { + std::array buffer; + const auto bytes_read = socket_->read_all(buffer.data(), buffer.size()); + if (bytes_read == 0) + break; + + // MessageProcessor wants an vector so give it what it wants until + // we refactor this. + std::vector data; + for (unsigned n = 0; n < bytes_read; n++) + data.push_back(buffer[n]); + + if (!message_processor_->process_data(data)) + break; + } +} + +std::shared_ptr HostConnector::platform_api_stub() const { + return platform_api_stub_; +} +} // namespace anbox