android: adjust for recent rpc changes

This commit is contained in:
Simon Fels 2016-08-23 09:51:14 +02:00
commit 1c9ebae83d
10 changed files with 50 additions and 42 deletions

View file

@ -34,9 +34,10 @@ LOCAL_SRC_FILES := \
android/service/platform_api_stub.cpp \ android/service/platform_api_stub.cpp \
src/anbox/common/fd.cpp \ src/anbox/common/fd.cpp \
src/anbox/common/wait_handle.cpp \ src/anbox/common/wait_handle.cpp \
src/anbox/bridge/message_processor.cpp \ src/anbox/rpc/message_processor.cpp \
src/anbox/bridge/pending_call_cache.cpp \ src/anbox/rpc/pending_call_cache.cpp \
src/anbox/bridge/rpc_channel.cpp \ src/anbox/rpc/channel.cpp \
src/anbox/protobuf/anbox_rpc.proto \
src/anbox/protobuf/anbox_bridge.proto src/anbox/protobuf/anbox_bridge.proto
proto_header_dir := $(call local-generated-sources-dir)/proto/$(LOCAL_PATH)/src/anbox/protobuf proto_header_dir := $(call local-generated-sources-dir)/proto/$(LOCAL_PATH)/src/anbox/protobuf
LOCAL_C_INCLUDES += \ LOCAL_C_INCLUDES += \

View file

@ -17,6 +17,7 @@
#include "android/service/android_api_skeleton.h" #include "android/service/android_api_skeleton.h"
#include "anbox_rpc.pb.h"
#include "anbox_bridge.pb.h" #include "anbox_bridge.pb.h"
#include <core/posix/exec.h> #include <core/posix/exec.h>
@ -37,7 +38,7 @@ AndroidApiSkeleton::~AndroidApiSkeleton() {
} }
void AndroidApiSkeleton::wait_for_process(core::posix::ChildProcess &process, void AndroidApiSkeleton::wait_for_process(core::posix::ChildProcess &process,
anbox::protobuf::bridge::Void *response) { anbox::protobuf::rpc::Void *response) {
const auto result = process.wait_for(core::posix::wait::Flags::untraced); const auto result = process.wait_for(core::posix::wait::Flags::untraced);
if (result.status != core::posix::wait::Result::Status::exited || if (result.status != core::posix::wait::Result::Status::exited ||
result.detail.if_exited.status != core::posix::exit::Status::success) { result.detail.if_exited.status != core::posix::exit::Status::success) {
@ -48,7 +49,7 @@ void AndroidApiSkeleton::wait_for_process(core::posix::ChildProcess &process,
} }
void AndroidApiSkeleton::install_application(anbox::protobuf::bridge::InstallApplication const *request, void AndroidApiSkeleton::install_application(anbox::protobuf::bridge::InstallApplication const *request,
anbox::protobuf::bridge::Void *response, anbox::protobuf::rpc::Void *response,
google::protobuf::Closure *done) { google::protobuf::Closure *done) {
(void) response; (void) response;
@ -65,7 +66,7 @@ void AndroidApiSkeleton::install_application(anbox::protobuf::bridge::InstallApp
} }
void AndroidApiSkeleton::launch_application(anbox::protobuf::bridge::LaunchApplication const *request, void AndroidApiSkeleton::launch_application(anbox::protobuf::bridge::LaunchApplication const *request,
anbox::protobuf::bridge::Void *response, anbox::protobuf::rpc::Void *response,
google::protobuf::Closure *done) { google::protobuf::Closure *done) {
(void) response; (void) response;
@ -86,7 +87,7 @@ void AndroidApiSkeleton::launch_application(anbox::protobuf::bridge::LaunchAppli
} }
void AndroidApiSkeleton::set_dns_servers(anbox::protobuf::bridge::SetDnsServers const *request, void AndroidApiSkeleton::set_dns_servers(anbox::protobuf::bridge::SetDnsServers const *request,
anbox::protobuf::bridge::Void *response, anbox::protobuf::rpc::Void *response,
google::protobuf::Closure *done) { google::protobuf::Closure *done) {
(void) response; (void) response;

View file

@ -36,8 +36,10 @@ namespace bridge {
class InstallApplication; class InstallApplication;
class LaunchApplication; class LaunchApplication;
class SetDnsServers; class SetDnsServers;
class Void;
} // namespace bridge } // namespace bridge
namespace rpc {
class Void;
} // namespace rpc
} // namespace protobuf } // namespace protobuf
class AndroidApiSkeleton { class AndroidApiSkeleton {
public: public:
@ -45,20 +47,20 @@ public:
~AndroidApiSkeleton(); ~AndroidApiSkeleton();
void install_application(anbox::protobuf::bridge::InstallApplication const *request, void install_application(anbox::protobuf::bridge::InstallApplication const *request,
anbox::protobuf::bridge::Void *response, anbox::protobuf::rpc::Void *response,
google::protobuf::Closure *done); google::protobuf::Closure *done);
void launch_application(anbox::protobuf::bridge::LaunchApplication const *request, void launch_application(anbox::protobuf::bridge::LaunchApplication const *request,
anbox::protobuf::bridge::Void *response, anbox::protobuf::rpc::Void *response,
google::protobuf::Closure *done); google::protobuf::Closure *done);
void set_dns_servers(anbox::protobuf::bridge::SetDnsServers const *request, void set_dns_servers(anbox::protobuf::bridge::SetDnsServers const *request,
anbox::protobuf::bridge::Void *response, anbox::protobuf::rpc::Void *response,
google::protobuf::Closure *done); google::protobuf::Closure *done);
private: private:
void wait_for_process(core::posix::ChildProcess &process, void wait_for_process(core::posix::ChildProcess &process,
anbox::protobuf::bridge::Void *response); anbox::protobuf::rpc::Void *response);
}; };
} // namespace anbox } // namespace anbox

View file

@ -21,7 +21,7 @@
#include "android/service/android_api_skeleton.h" #include "android/service/android_api_skeleton.h"
#include "android/service/platform_api_stub.h" #include "android/service/platform_api_stub.h"
#include "anbox/bridge/rpc_channel.h" #include "anbox/rpc/channel.h"
#include <functional> #include <functional>
#include <array> #include <array>
@ -29,10 +29,10 @@
namespace anbox { namespace anbox {
HostConnector::HostConnector() : HostConnector::HostConnector() :
socket_(std::make_shared<LocalSocketConnection>("/dev/anbox_bridge")), socket_(std::make_shared<LocalSocketConnection>("/dev/anbox_bridge")),
pending_calls_(std::make_shared<bridge::PendingCallCache>()), pending_calls_(std::make_shared<rpc::PendingCallCache>()),
android_api_skeleton_(std::make_shared<AndroidApiSkeleton>()), android_api_skeleton_(std::make_shared<AndroidApiSkeleton>()),
message_processor_(std::make_shared<MessageProcessor>(socket_, pending_calls_, android_api_skeleton_)), message_processor_(std::make_shared<MessageProcessor>(socket_, pending_calls_, android_api_skeleton_)),
rpc_channel_(std::make_shared<bridge::RpcChannel>(pending_calls_, socket_)), rpc_channel_(std::make_shared<rpc::Channel>(pending_calls_, socket_)),
platform_api_stub_(std::make_shared<PlatformApiStub>(rpc_channel_)), platform_api_stub_(std::make_shared<PlatformApiStub>(rpc_channel_)),
running_(false) { running_(false) {
} }

View file

@ -23,10 +23,10 @@
#include <atomic> #include <atomic>
namespace anbox { namespace anbox {
namespace bridge { namespace rpc {
class PendingCallCache; class PendingCallCache;
class RpcChannel; class Channel;
} // namespace bridge } // namespace rpc
class LocalSocketConnection; class LocalSocketConnection;
class MessageProcessor; class MessageProcessor;
class AndroidApiSkeleton; class AndroidApiSkeleton;
@ -45,10 +45,10 @@ private:
void main_loop(); void main_loop();
std::shared_ptr<LocalSocketConnection> socket_; std::shared_ptr<LocalSocketConnection> socket_;
std::shared_ptr<bridge::PendingCallCache> pending_calls_; std::shared_ptr<rpc::PendingCallCache> pending_calls_;
std::shared_ptr<AndroidApiSkeleton> android_api_skeleton_; std::shared_ptr<AndroidApiSkeleton> android_api_skeleton_;
std::shared_ptr<MessageProcessor> message_processor_; std::shared_ptr<MessageProcessor> message_processor_;
std::shared_ptr<bridge::RpcChannel> rpc_channel_; std::shared_ptr<rpc::Channel> rpc_channel_;
std::shared_ptr<anbox::PlatformApiStub> platform_api_stub_; std::shared_ptr<anbox::PlatformApiStub> platform_api_stub_;
std::thread thread_; std::thread thread_;
std::atomic<bool> running_; std::atomic<bool> running_;

View file

@ -18,20 +18,23 @@
#include "android/service/message_processor.h" #include "android/service/message_processor.h"
#include "android/service/android_api_skeleton.h" #include "android/service/android_api_skeleton.h"
#include "anbox/bridge/template_message_processor.h" #include "anbox/rpc/template_message_processor.h"
#include "anbox_rpc.pb.h"
#include "anbox_bridge.pb.h"
namespace anbox { namespace anbox {
MessageProcessor::MessageProcessor(const std::shared_ptr<network::MessageSender> &sender, MessageProcessor::MessageProcessor(const std::shared_ptr<network::MessageSender> &sender,
const std::shared_ptr<bridge::PendingCallCache> &pending_calls, const std::shared_ptr<rpc::PendingCallCache> &pending_calls,
const std::shared_ptr<AndroidApiSkeleton> &platform_api) : const std::shared_ptr<AndroidApiSkeleton> &platform_api) :
bridge::MessageProcessor(sender, pending_calls), rpc::MessageProcessor(sender, pending_calls),
platform_api_(platform_api) { platform_api_(platform_api) {
} }
MessageProcessor::~MessageProcessor() { MessageProcessor::~MessageProcessor() {
} }
void MessageProcessor::dispatch(bridge::Invocation const& invocation) { void MessageProcessor::dispatch(rpc::Invocation const& invocation) {
if (invocation.method_name() == "install_application") if (invocation.method_name() == "install_application")
invoke(this, platform_api_.get(), &AndroidApiSkeleton::install_application, invocation); invoke(this, platform_api_.get(), &AndroidApiSkeleton::install_application, invocation);
else if (invocation.method_name() == "launch_application") else if (invocation.method_name() == "launch_application")

View file

@ -18,18 +18,18 @@
#ifndef ANBOX_ANDROID_MESSAGE_PROCESSOR_H_ #ifndef ANBOX_ANDROID_MESSAGE_PROCESSOR_H_
#define ANBOX_ANDROID_MESSAGE_PROCESSOR_H_ #define ANBOX_ANDROID_MESSAGE_PROCESSOR_H_
#include "anbox/bridge/message_processor.h" #include "anbox/rpc/message_processor.h"
namespace anbox { namespace anbox {
class AndroidApiSkeleton; class AndroidApiSkeleton;
class MessageProcessor : public bridge::MessageProcessor { class MessageProcessor : public rpc::MessageProcessor {
public: public:
MessageProcessor(const std::shared_ptr<network::MessageSender> &sender, MessageProcessor(const std::shared_ptr<network::MessageSender> &sender,
const std::shared_ptr<bridge::PendingCallCache> &pending_calls, const std::shared_ptr<rpc::PendingCallCache> &pending_calls,
const std::shared_ptr<AndroidApiSkeleton> &platform_api); const std::shared_ptr<AndroidApiSkeleton> &platform_api);
~MessageProcessor(); ~MessageProcessor();
void dispatch(bridge::Invocation const& invocation) override; void dispatch(rpc::Invocation const& invocation) override;
void process_event_sequence(const std::string &event) override; void process_event_sequence(const std::string &event) override;
private: private:

View file

@ -16,20 +16,21 @@
*/ */
#include "android/service/platform_api_stub.h" #include "android/service/platform_api_stub.h"
#include "anbox/bridge/rpc_channel.h" #include "anbox/rpc/channel.h"
#include "anbox_rpc.pb.h"
#include "anbox_bridge.pb.h" #include "anbox_bridge.pb.h"
#define LOG_TAG "Anbox" #define LOG_TAG "Anbox"
#include <cutils/log.h> #include <cutils/log.h>
namespace anbox { namespace anbox {
PlatformApiStub::PlatformApiStub(const std::shared_ptr<bridge::RpcChannel> &rpc_channel) : PlatformApiStub::PlatformApiStub(const std::shared_ptr<rpc::Channel> &rpc_channel) :
rpc_channel_(rpc_channel) { rpc_channel_(rpc_channel) {
} }
void PlatformApiStub::boot_finished() { void PlatformApiStub::boot_finished() {
auto c = std::make_shared<Request<protobuf::bridge::Void>>(); auto c = std::make_shared<Request<protobuf::rpc::Void>>();
ALOGI("Boot finished"); ALOGI("Boot finished");
@ -38,7 +39,7 @@ void PlatformApiStub::boot_finished() {
boot_finished_wait_handle_.expect_result(); boot_finished_wait_handle_.expect_result();
} }
protobuf::bridge::Void message; protobuf::rpc::Void message;
rpc_channel_->call_method( rpc_channel_->call_method(
"boot_finished", "boot_finished",
@ -50,7 +51,7 @@ void PlatformApiStub::boot_finished() {
ALOGI("Boot finished sent successfully!"); ALOGI("Boot finished sent successfully!");
} }
void PlatformApiStub::handle_boot_finished_response(Request<protobuf::bridge::Void>*) { void PlatformApiStub::handle_boot_finished_response(Request<protobuf::rpc::Void>*) {
ALOGI("handle_boot_finished_response"); ALOGI("handle_boot_finished_response");
boot_finished_wait_handle_.result_received(); boot_finished_wait_handle_.result_received();
} }

View file

@ -24,16 +24,16 @@
namespace anbox { namespace anbox {
namespace protobuf { namespace protobuf {
namespace bridge { namespace rpc {
class Void; class Void;
} // namespace bridge } // namespace rpc
} // namespace protobuf } // namespace protobuf
namespace bridge { namespace rpc {
class RpcChannel; class Channel;
} // namespace bridge } // namespace rpc
class PlatformApiStub { class PlatformApiStub {
public: public:
PlatformApiStub(const std::shared_ptr<bridge::RpcChannel> &rpc_channel); PlatformApiStub(const std::shared_ptr<rpc::Channel> &rpc_channel);
void boot_finished(); void boot_finished();
@ -45,12 +45,12 @@ private:
bool success; bool success;
}; };
void handle_boot_finished_response(Request<protobuf::bridge::Void> *request); void handle_boot_finished_response(Request<protobuf::rpc::Void> *request);
mutable std::mutex mutex_; mutable std::mutex mutex_;
common::WaitHandle boot_finished_wait_handle_; common::WaitHandle boot_finished_wait_handle_;
std::shared_ptr<bridge::RpcChannel> rpc_channel_; std::shared_ptr<rpc::Channel> rpc_channel_;
}; };
} // namespace anbox } // namespace anbox

View file

@ -17,7 +17,7 @@
#include "android/service/platform_service.h" #include "android/service/platform_service.h"
#include "android/service/platform_api_stub.h" #include "android/service/platform_api_stub.h"
#include "anbox/bridge/rpc_channel.h" #include "anbox/rpc/channel.h"
#define LOG_TAG "Anboxd" #define LOG_TAG "Anboxd"
#include <cutils/log.h> #include <cutils/log.h>