From 51e9cfa77759f7a932aeac8ade55c0501bd1d6df Mon Sep 17 00:00:00 2001 From: Simon Fels Date: Tue, 16 Aug 2016 11:58:03 +0200 Subject: [PATCH] Move RPC implementation into its own namespace --- android/CMakeLists.txt | 4 +- src/CMakeLists.txt | 21 ++++++---- src/anbox/bridge/android_api_stub.cpp | 17 +++++---- src/anbox/bridge/android_api_stub.h | 16 ++++---- src/anbox/bridge/platform_api_skeleton.cpp | 2 +- src/anbox/bridge/platform_api_skeleton.h | 18 +++++---- .../bridge/platform_message_processor.cpp | 8 ++-- src/anbox/bridge/platform_message_processor.h | 8 ++-- src/anbox/cmds/run.cpp | 10 ++--- src/anbox/protobuf/anbox_bridge.proto | 22 ----------- src/anbox/protobuf/anbox_rpc.proto | 25 ++++++++++++ .../rpc_channel.cpp => rpc/channel.cpp} | 38 +++++++++---------- .../{bridge/rpc_channel.h => rpc/channel.h} | 22 +++++------ .../{bridge => rpc}/connection_creator.cpp | 8 ++-- .../{bridge => rpc}/connection_creator.h | 8 ++-- src/anbox/{bridge => rpc}/constants.h | 8 ++-- .../{bridge => rpc}/make_protobuf_object.h | 8 ++-- .../{bridge => rpc}/message_processor.cpp | 18 ++++----- src/anbox/{bridge => rpc}/message_processor.h | 18 ++++----- .../{bridge => rpc}/pending_call_cache.cpp | 14 +++---- .../{bridge => rpc}/pending_call_cache.h | 18 ++++----- .../template_message_processor.h | 16 ++++---- src/anbox/ubuntu/platform_api_skeleton.cpp | 14 ++++--- src/anbox/ubuntu/platform_api_skeleton.h | 11 ++++-- 24 files changed, 187 insertions(+), 165 deletions(-) create mode 100644 src/anbox/protobuf/anbox_rpc.proto rename src/anbox/{bridge/rpc_channel.cpp => rpc/channel.cpp} (68%) rename src/anbox/{bridge/rpc_channel.h => rpc/channel.h} (81%) rename src/anbox/{bridge => rpc}/connection_creator.cpp (93%) rename src/anbox/{bridge => rpc}/connection_creator.h (93%) rename src/anbox/{bridge => rpc}/constants.h (89%) rename src/anbox/{bridge => rpc}/make_protobuf_object.h (89%) rename src/anbox/{bridge => rpc}/message_processor.cpp (89%) rename src/anbox/{bridge => rpc}/message_processor.h (84%) rename src/anbox/{bridge => rpc}/pending_call_cache.cpp (89%) rename src/anbox/{bridge => rpc}/pending_call_cache.h (82%) rename src/anbox/{bridge => rpc}/template_message_processor.h (90%) diff --git a/android/CMakeLists.txt b/android/CMakeLists.txt index 4f0abe8..1e872b6 100644 --- a/android/CMakeLists.txt +++ b/android/CMakeLists.txt @@ -4,8 +4,8 @@ include_directories( ${CMAKE_BINARY_DIR}/src) set(ANBOXD_SOURCES - ${CMAKE_SOURCE_DIR}/src/anbox/bridge/message_processor.cpp - ${CMAKE_SOURCE_DIR}/src/anbox/bridge/pending_call_cache.cpp + ${CMAKE_SOURCE_DIR}/src/anbox/rpc/message_processor.cpp + ${CMAKE_SOURCE_DIR}/src/anbox/rpc/pending_call_cache.cpp ${CMAKE_SOURCE_DIR}/src/anbox/common/fd.cpp service/platform_service.cpp service/platform_service_interface.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 24516d4..6ae7cf2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -15,6 +15,10 @@ include_directories( ${CMAKE_SOURCE_DIR}/external/android-emugl/host/include ) +protobuf_generate_cpp( + GENERATED_PROTOBUF_RPC_SRCS GENERATED_PROTOBUF_RPC_HDRS + anbox/protobuf/anbox_rpc.proto) + protobuf_generate_cpp( GENERATED_PROTOBUF_BRIDGE_SRCS GENERATED_PROTOBUF_BRIDGE_HDRS anbox/protobuf/anbox_bridge.proto) @@ -22,6 +26,8 @@ protobuf_generate_cpp( add_library(anbox-protobuf ${GENERATED_PROTOBUF_BRIDGE_SRCS} ${GENERATED_PROTOBUF_BRIDGE_HDRS} + ${GENERATED_PROTOBUF_RPC_SRCS} + ${GENERATED_PROTOBUF_RPC_HDRS} anbox/protobuf/google_protobuf_guard.cpp) target_link_libraries(anbox-protobuf ${PROTOBUF_LITE_LIBRARIES}) @@ -63,6 +69,14 @@ set(SOURCES anbox/network/local_socket_messenger.cpp anbox/network/socket_helper.cpp + anbox/rpc/channel.cpp + anbox/rpc/pending_call_cache.cpp + anbox/rpc/constants.h + anbox/rpc/connection_creator.cpp + anbox/rpc/message_processor.cpp + anbox/rpc/template_message_processor.h + anbox/rpc/make_protobuf_object.h + anbox/graphics/opengles_message_processor.cpp anbox/graphics/gl_renderer_server.cpp anbox/graphics/window_creator.cpp @@ -82,15 +96,8 @@ set(SOURCES anbox/qemu/at_parser.cpp anbox/qemu/bootanimation_message_processor.cpp - anbox/bridge/constants.h - anbox/bridge/connection_creator.cpp - anbox/bridge/message_processor.cpp - anbox/bridge/template_message_processor.h - anbox/bridge/pending_call_cache.cpp - anbox/bridge/make_protobuf_object.h anbox/bridge/platform_message_processor.cpp anbox/bridge/platform_api_skeleton.cpp - anbox/bridge/rpc_channel.cpp anbox/bridge/android_api_stub.cpp anbox/ubuntu/platform_api_skeleton.cpp diff --git a/src/anbox/bridge/android_api_stub.cpp b/src/anbox/bridge/android_api_stub.cpp index 9646fc5..e36ca8c 100644 --- a/src/anbox/bridge/android_api_stub.cpp +++ b/src/anbox/bridge/android_api_stub.cpp @@ -16,11 +16,12 @@ */ #include "anbox/bridge/android_api_stub.h" -#include "anbox/bridge/rpc_channel.h" +#include "anbox/rpc/channel.h" #include "anbox/utils.h" #include "anbox/config.h" #include "anbox/logger.h" +#include "anbox_rpc.pb.h" #include "anbox_bridge.pb.h" #include @@ -35,7 +36,7 @@ AndroidApiStub::AndroidApiStub() { AndroidApiStub::~AndroidApiStub() { } -void AndroidApiStub::set_rpc_channel(const std::shared_ptr &channel) { +void AndroidApiStub::set_rpc_channel(const std::shared_ptr &channel) { channel_ = channel; } @@ -62,7 +63,7 @@ void AndroidApiStub::install(const std::string &path) { const auto container_path = utils::string_format("%s/%s", config::container_android_share_path(), fs::path(path).filename().string()); - auto c = std::make_shared>(); + auto c = std::make_shared>(); protobuf::bridge::InstallApplication message; message.set_path(container_path); @@ -82,14 +83,14 @@ void AndroidApiStub::install(const std::string &path) { throw std::runtime_error(c->response->error()); } -void AndroidApiStub::application_installed(Request *request) { +void AndroidApiStub::application_installed(Request *request) { install_wait_handle_.result_received(); } void AndroidApiStub::launch(const std::string &package, const std::string &activity) { ensure_rpc_channel(); - auto c = std::make_shared>(); + auto c = std::make_shared>(); protobuf::bridge::LaunchApplication message; message.set_package_name(package); message.set_activity(activity); @@ -110,14 +111,14 @@ void AndroidApiStub::launch(const std::string &package, const std::string &activ throw std::runtime_error(c->response->error()); } -void AndroidApiStub::application_launched(Request *request) { +void AndroidApiStub::application_launched(Request *request) { launch_wait_handle_.result_received(); } void AndroidApiStub::set_dns_servers(const std::string &domain, const std::vector &servers) { ensure_rpc_channel(); - auto c = std::make_shared>(); + auto c = std::make_shared>(); protobuf::bridge::SetDnsServers message; message.set_domain(domain); @@ -143,7 +144,7 @@ void AndroidApiStub::set_dns_servers(const std::string &domain, const std::vecto throw std::runtime_error(c->response->error()); } -void AndroidApiStub::dns_servers_set(Request *request) { +void AndroidApiStub::dns_servers_set(Request *request) { set_dns_servers_wait_handle_.result_received(); } } // namespace bridge diff --git a/src/anbox/bridge/android_api_stub.h b/src/anbox/bridge/android_api_stub.h index 117fd13..58e1a92 100644 --- a/src/anbox/bridge/android_api_stub.h +++ b/src/anbox/bridge/android_api_stub.h @@ -26,18 +26,20 @@ namespace anbox { namespace protobuf { -namespace bridge { +namespace rpc { class Void; } // namespace bridge } // namespace protobuf +namespace rpc { +class Channel; +} // namespace rpc namespace bridge { -class RpcChannel; class AndroidApiStub : public anbox::ApplicationManager { public: AndroidApiStub(); ~AndroidApiStub(); - void set_rpc_channel(const std::shared_ptr &channel); + void set_rpc_channel(const std::shared_ptr &channel); void reset_rpc_channel(); void install(const std::string &path) override; @@ -55,12 +57,12 @@ private: bool success; }; - void application_installed(Request *request); - void application_launched(Request *request); - void dns_servers_set(Request *request); + void application_installed(Request *request); + void application_launched(Request *request); + void dns_servers_set(Request *request); mutable std::mutex mutex_; - std::shared_ptr channel_; + std::shared_ptr channel_; common::WaitHandle install_wait_handle_; common::WaitHandle launch_wait_handle_; common::WaitHandle set_dns_servers_wait_handle_; diff --git a/src/anbox/bridge/platform_api_skeleton.cpp b/src/anbox/bridge/platform_api_skeleton.cpp index fd3d245..e9e53e8 100644 --- a/src/anbox/bridge/platform_api_skeleton.cpp +++ b/src/anbox/bridge/platform_api_skeleton.cpp @@ -22,7 +22,7 @@ namespace anbox { namespace bridge { -PlatformApiSkeleton::PlatformApiSkeleton(const std::shared_ptr &pending_calls) : +PlatformApiSkeleton::PlatformApiSkeleton(const std::shared_ptr &pending_calls) : pending_calls_(pending_calls) { } diff --git a/src/anbox/bridge/platform_api_skeleton.h b/src/anbox/bridge/platform_api_skeleton.h index f0fe9e4..aafe417 100644 --- a/src/anbox/bridge/platform_api_skeleton.h +++ b/src/anbox/bridge/platform_api_skeleton.h @@ -28,28 +28,32 @@ class Closure; namespace anbox { namespace protobuf { +namespace rpc { +class Void; +} // namespace rpc namespace bridge { class Notification; -class Void; } // namespace bridge } // namespace protobuf -namespace bridge { +namespace rpc { class PendingCallCache; +} // namespace rpc +namespace bridge { class PlatformApiSkeleton { public: - PlatformApiSkeleton(const std::shared_ptr &pending_calls); + PlatformApiSkeleton(const std::shared_ptr &pending_calls); virtual ~PlatformApiSkeleton(); - virtual void boot_finished(anbox::protobuf::bridge::Void const *request, - anbox::protobuf::bridge::Void *response, + virtual void boot_finished(anbox::protobuf::rpc::Void const *request, + anbox::protobuf::rpc::Void *response, google::protobuf::Closure *done) = 0; virtual void handle_notification(anbox::protobuf::bridge::Notification const *request, - anbox::protobuf::bridge::Void *response, + anbox::protobuf::rpc::Void *response, google::protobuf::Closure *done) = 0; private: - std::shared_ptr pending_calls_; + std::shared_ptr pending_calls_; }; } // namespace bridge } // namespace anbox diff --git a/src/anbox/bridge/platform_message_processor.cpp b/src/anbox/bridge/platform_message_processor.cpp index d296dcf..599a3cb 100644 --- a/src/anbox/bridge/platform_message_processor.cpp +++ b/src/anbox/bridge/platform_message_processor.cpp @@ -17,7 +17,7 @@ #include "anbox/bridge/platform_message_processor.h" #include "anbox/bridge/platform_api_skeleton.h" -#include "anbox/bridge/template_message_processor.h" +#include "anbox/rpc/template_message_processor.h" #include "anbox_bridge.pb.h" @@ -25,15 +25,15 @@ namespace anbox { namespace bridge { PlatformMessageProcessor::PlatformMessageProcessor(const std::shared_ptr &sender, const std::shared_ptr &server, - const std::shared_ptr &pending_calls) : - MessageProcessor(sender, pending_calls), + const std::shared_ptr &pending_calls) : + rpc::MessageProcessor(sender, pending_calls), server_(server) { } PlatformMessageProcessor::~PlatformMessageProcessor() { } -void PlatformMessageProcessor::dispatch(Invocation const& invocation) { +void PlatformMessageProcessor::dispatch(rpc::Invocation const& invocation) { if (invocation.method_name() == "handle_notification") invoke(this, server_.get(), &PlatformApiSkeleton::handle_notification, invocation); else if (invocation.method_name() == "boot_finished") diff --git a/src/anbox/bridge/platform_message_processor.h b/src/anbox/bridge/platform_message_processor.h index 28085db..a956ea0 100644 --- a/src/anbox/bridge/platform_message_processor.h +++ b/src/anbox/bridge/platform_message_processor.h @@ -18,19 +18,19 @@ #ifndef ANBOX_BRIDGE_PLATFORM_MESSAGE_PROCESSOR_H_ #define ANBOX_BRIDGE_PLATFORM_MESSAGE_PROCESSOR_H_ -#include "anbox/bridge/message_processor.h" +#include "anbox/rpc/message_processor.h" namespace anbox { namespace bridge { class PlatformApiSkeleton; -class PlatformMessageProcessor : public MessageProcessor { +class PlatformMessageProcessor : public rpc::MessageProcessor { public: PlatformMessageProcessor(const std::shared_ptr &sender, const std::shared_ptr &server, - const std::shared_ptr &pending_calls); + const std::shared_ptr &pending_calls); ~PlatformMessageProcessor(); - void dispatch(Invocation const& invocation) override; + void dispatch(rpc::Invocation const& invocation) override; void process_event_sequence(const std::string &event) override; private: diff --git a/src/anbox/cmds/run.cpp b/src/anbox/cmds/run.cpp index 42a0e9a..b11a28f 100644 --- a/src/anbox/cmds/run.cpp +++ b/src/anbox/cmds/run.cpp @@ -28,9 +28,9 @@ #include "anbox/qemu/pipe_connection_creator.h" #include "anbox/graphics/gl_renderer_server.h" #include "anbox/input/manager.h" -#include "anbox/bridge/connection_creator.h" +#include "anbox/rpc/connection_creator.h" +#include "anbox/rpc/channel.h" #include "anbox/bridge/platform_message_processor.h" -#include "anbox/bridge/rpc_channel.h" #include "anbox/bridge/android_api_stub.h" #include "anbox/ubuntu/platform_api_skeleton.h" #include "anbox/ubuntu/window_creator.h" @@ -115,10 +115,10 @@ anbox::cmds::Run::Run(const BusFactory& bus_factory) auto bridge_connector = std::make_shared( utils::string_format("%s/anbox_bridge", config::socket_path()), rt, - std::make_shared(rt, + std::make_shared(rt, [&](const std::shared_ptr &sender) { - auto pending_calls = std::make_shared(); - auto rpc_channel = std::make_shared(pending_calls, sender); + auto pending_calls = std::make_shared(); + auto rpc_channel = std::make_shared(pending_calls, sender); // This is safe as long as we only support a single client. If we support // more than one one day we need proper dispatching to the right one. android_api_stub->set_rpc_channel(rpc_channel); diff --git a/src/anbox/protobuf/anbox_bridge.proto b/src/anbox/protobuf/anbox_bridge.proto index 9ded4f3..2102278 100644 --- a/src/anbox/protobuf/anbox_bridge.proto +++ b/src/anbox/protobuf/anbox_bridge.proto @@ -2,28 +2,6 @@ option optimize_for = LITE_RUNTIME; package anbox.protobuf.bridge; -message Invocation { - required uint32 id = 1; - required string method_name = 2; - required bytes parameters = 3; - required uint32 protocol_version = 4; -} - -message Result { - optional uint32 id = 1; - optional bytes response = 2; -} - -message StructuredError { - optional uint32 domain = 1; - optional uint32 code = 2; -} - -message Void { - optional string error = 127; - optional StructuredError structured_error = 128; -} - message Notification { required string package_name = 1; required string category = 2; diff --git a/src/anbox/protobuf/anbox_rpc.proto b/src/anbox/protobuf/anbox_rpc.proto new file mode 100644 index 0000000..dddbd41 --- /dev/null +++ b/src/anbox/protobuf/anbox_rpc.proto @@ -0,0 +1,25 @@ +option optimize_for = LITE_RUNTIME; + +package anbox.protobuf.rpc; + +message Invocation { + required uint32 id = 1; + required string method_name = 2; + required bytes parameters = 3; + required uint32 protocol_version = 4; +} + +message Result { + optional uint32 id = 1; + optional bytes response = 2; +} + +message StructuredError { + optional uint32 domain = 1; + optional uint32 code = 2; +} + +message Void { + optional string error = 127; + optional StructuredError structured_error = 128; +} diff --git a/src/anbox/bridge/rpc_channel.cpp b/src/anbox/rpc/channel.cpp similarity index 68% rename from src/anbox/bridge/rpc_channel.cpp rename to src/anbox/rpc/channel.cpp index 7d5d2d5..a99da5a 100644 --- a/src/anbox/bridge/rpc_channel.cpp +++ b/src/anbox/rpc/channel.cpp @@ -17,42 +17,42 @@ * Authored by: Alan Griffiths */ -#include "anbox/bridge/rpc_channel.h" -#include "anbox/bridge/pending_call_cache.h" -#include "anbox/bridge/constants.h" +#include "anbox/rpc/channel.h" +#include "anbox/rpc/pending_call_cache.h" +#include "anbox/rpc/constants.h" #include "anbox/common/variable_length_array.h" #include "anbox/network/message_sender.h" -#include "anbox_bridge.pb.h" +#include "anbox_rpc.pb.h" namespace anbox { -namespace bridge { -RpcChannel::RpcChannel(const std::shared_ptr &pending_calls, - const std::shared_ptr &sender) : +namespace rpc { +Channel::Channel(const std::shared_ptr &pending_calls, + const std::shared_ptr &sender) : pending_calls_(pending_calls), sender_(sender) { } -RpcChannel::~RpcChannel() { +Channel::~Channel() { } -void RpcChannel::call_method(std::string const& method_name, - google::protobuf::MessageLite const *parameters, - google::protobuf::MessageLite *response, - google::protobuf::Closure *complete) { +void Channel::call_method(std::string const& method_name, + google::protobuf::MessageLite const *parameters, + google::protobuf::MessageLite *response, + google::protobuf::Closure *complete) { auto const &invocation = invocation_for(method_name, parameters); pending_calls_->save_completion_details(invocation, response, complete); send_message(invocation); } -protobuf::bridge::Invocation RpcChannel::invocation_for(std::string const& method_name, - google::protobuf::MessageLite const* request) { +protobuf::rpc::Invocation Channel::invocation_for(std::string const& method_name, + google::protobuf::MessageLite const* request) { anbox::VariableLengthArray<2048> buffer{static_cast(request->ByteSize())}; request->SerializeWithCachedSizesToArray(buffer.data()); - anbox::protobuf::bridge::Invocation invoke; + anbox::protobuf::rpc::Invocation invoke; invoke.set_id(next_id()); invoke.set_method_name(method_name); @@ -62,7 +62,7 @@ protobuf::bridge::Invocation RpcChannel::invocation_for(std::string const& metho return invoke; } -void RpcChannel::send_message(anbox::protobuf::bridge::Invocation const& invocation) { +void Channel::send_message(anbox::protobuf::rpc::Invocation const& invocation) { const size_t size = invocation.ByteSize(); const unsigned char header_bytes[header_size] = { static_cast((size >> 8) & 0xff), @@ -84,12 +84,12 @@ void RpcChannel::send_message(anbox::protobuf::bridge::Invocation const& invocat } } -void RpcChannel::notify_disconnected() { +void Channel::notify_disconnected() { pending_calls_->force_completion(); } -int RpcChannel::next_id() { +int Channel::next_id() { return next_message_id_.fetch_add(1); } -} // namespace bridge +} // namespace rpc } // namespace anbox diff --git a/src/anbox/bridge/rpc_channel.h b/src/anbox/rpc/channel.h similarity index 81% rename from src/anbox/bridge/rpc_channel.h rename to src/anbox/rpc/channel.h index 0db3ee9..36a350b 100644 --- a/src/anbox/bridge/rpc_channel.h +++ b/src/anbox/rpc/channel.h @@ -15,8 +15,8 @@ * */ -#ifndef ANBOX_BRIDGE_RPC_CHANNEL_H_ -#define ANBOX_BRIDGE_RPC_CHANNEL_H_ +#ifndef ANBOX_RPC_CHANNEL_H_ +#define ANBOX_RPC_CHANNEL_H_ #include #include @@ -32,20 +32,20 @@ class MessageLite; namespace anbox { namespace protobuf { -namespace bridge { +namespace rpc { class Invocation; -} // namespace bridge +} // namespace rpc } // namespace protobuf namespace network { class MessageSender; } // namespace network -namespace bridge { +namespace rpc { class PendingCallCache; -class RpcChannel { +class Channel { public: - RpcChannel(const std::shared_ptr &pending_calls, + Channel(const std::shared_ptr &pending_calls, const std::shared_ptr &sender); - ~RpcChannel(); + ~Channel(); void call_method(std::string const& method_name, google::protobuf::MessageLite const *parameters, @@ -53,10 +53,10 @@ public: google::protobuf::Closure *complete); private: - protobuf::bridge::Invocation invocation_for( + protobuf::rpc::Invocation invocation_for( std::string const& method_name, google::protobuf::MessageLite const* request); - void send_message(anbox::protobuf::bridge::Invocation const& invocation); + void send_message(anbox::protobuf::rpc::Invocation const& invocation); int next_id(); void notify_disconnected(); @@ -65,7 +65,7 @@ private: std::shared_ptr sender_; std::mutex write_mutex_; }; -} // namespace bridge +} // namespace rpc } // namespace anbox #endif diff --git a/src/anbox/bridge/connection_creator.cpp b/src/anbox/rpc/connection_creator.cpp similarity index 93% rename from src/anbox/bridge/connection_creator.cpp rename to src/anbox/rpc/connection_creator.cpp index 05efb10..3c69967 100644 --- a/src/anbox/bridge/connection_creator.cpp +++ b/src/anbox/rpc/connection_creator.cpp @@ -16,8 +16,8 @@ */ -#include "anbox/bridge/connection_creator.h" -#include "anbox/bridge/message_processor.h" +#include "anbox/rpc/connection_creator.h" +#include "anbox/rpc/message_processor.h" #include "anbox/network/socket_messenger.h" #include "anbox/logger.h" @@ -26,7 +26,7 @@ namespace ba = boost::asio; namespace anbox { -namespace bridge { +namespace rpc { ConnectionCreator::ConnectionCreator(const std::shared_ptr &rt, const MessageProcessorFactory &factory) : runtime_(rt), next_connection_id_(0), @@ -61,5 +61,5 @@ int ConnectionCreator::next_id() return next_connection_id_.fetch_add(1); } +} // namespace rpc } // namespace anbox -} // namespace network diff --git a/src/anbox/bridge/connection_creator.h b/src/anbox/rpc/connection_creator.h similarity index 93% rename from src/anbox/bridge/connection_creator.h rename to src/anbox/rpc/connection_creator.h index 711a12e..79bd679 100644 --- a/src/anbox/bridge/connection_creator.h +++ b/src/anbox/rpc/connection_creator.h @@ -15,8 +15,8 @@ * */ -#ifndef ANBOX_BRIDGE_CONNECTION_CREATOR_H_ -#define ANBOX_BRIDGE_CONNECTION_CREATOR_H_ +#ifndef ANBOX_RPC_CONNECTION_CREATOR_H_ +#define ANBOX_RPC_CONNECTION_CREATOR_H_ #include @@ -30,7 +30,7 @@ #include "anbox/network/socket_messenger.h" namespace anbox { -namespace bridge { +namespace rpc { class ConnectionCreator : public network::ConnectionCreator { public: typedef std::function( @@ -51,7 +51,7 @@ private: std::shared_ptr> const connections_; MessageProcessorFactory message_processor_factory_; }; +} // namespace rpc } // namespace anbox -} // namespace network #endif diff --git a/src/anbox/bridge/constants.h b/src/anbox/rpc/constants.h similarity index 89% rename from src/anbox/bridge/constants.h rename to src/anbox/rpc/constants.h index a75d6e2..9c0621e 100644 --- a/src/anbox/bridge/constants.h +++ b/src/anbox/rpc/constants.h @@ -15,11 +15,11 @@ * */ -#ifndef ANBOX_BRIDGE_CONSTANTS_H_ -#define ANBOX_BRIDGE_CONSTANTS_H_ +#ifndef ANBOX_RPC_CONSTANTS_H_ +#define ANBOX_RPC_CONSTANTS_H_ namespace anbox { -namespace bridge { +namespace rpc { static constexpr const long header_size{3}; static constexpr unsigned int const serialization_buffer_size{2048}; @@ -27,7 +27,7 @@ enum MessageType { invocation = 0, response = 1, }; -} // namespace anbox +} // namespace rpc } // namespace network #endif diff --git a/src/anbox/bridge/make_protobuf_object.h b/src/anbox/rpc/make_protobuf_object.h similarity index 89% rename from src/anbox/bridge/make_protobuf_object.h rename to src/anbox/rpc/make_protobuf_object.h index 50b98ef..9e42b66 100644 --- a/src/anbox/bridge/make_protobuf_object.h +++ b/src/anbox/rpc/make_protobuf_object.h @@ -16,13 +16,13 @@ * Authored by: Alberto Aguirre */ -#ifndef ANBOX_BRIDGE_MAKE_PROTOBUF_OBJECT_H_ -#define ANBOX_BRIDGE_MAKE_PROTOBUF_OBJECT_H_ +#ifndef ANBOX_RPC_MAKE_PROTOBUF_OBJECT_H_ +#define ANBOX_RPC_MAKE_PROTOBUF_OBJECT_H_ #include namespace anbox { -namespace bridge { +namespace rpc { template auto make_protobuf_object() { return std::unique_ptr{ProtobufType::default_instance().New()}; @@ -34,7 +34,7 @@ auto make_protobuf_object(ProtobufType const& from) { object->CopyFrom(from); return object; } -} // namespace bridge +} // namespace rpc } // namespace anbox #endif diff --git a/src/anbox/bridge/message_processor.cpp b/src/anbox/rpc/message_processor.cpp similarity index 89% rename from src/anbox/bridge/message_processor.cpp rename to src/anbox/rpc/message_processor.cpp index e596092..e19066b 100644 --- a/src/anbox/bridge/message_processor.cpp +++ b/src/anbox/rpc/message_processor.cpp @@ -15,16 +15,16 @@ * */ -#include "anbox/bridge/message_processor.h" -#include "anbox/bridge/template_message_processor.h" -#include "anbox/bridge/make_protobuf_object.h" -#include "anbox/bridge/constants.h" +#include "anbox/rpc/message_processor.h" +#include "anbox/rpc/template_message_processor.h" +#include "anbox/rpc/make_protobuf_object.h" +#include "anbox/rpc/constants.h" #include "anbox/common/variable_length_array.h" -#include "anbox_bridge.pb.h" +#include "anbox_rpc.pb.h" namespace anbox { -namespace bridge { +namespace rpc { const ::std::string& Invocation::method_name() const { return invocation_.method_name(); } @@ -65,7 +65,7 @@ bool MessageProcessor::process_data(const std::vector &data) { buffer_.erase(buffer_.begin(), buffer_.begin() + header_size); if (message_type == MessageType::invocation) { - anbox::protobuf::bridge::Invocation raw_invocation; + anbox::protobuf::rpc::Invocation raw_invocation; raw_invocation.ParseFromArray(buffer_.data(), message_size); buffer_.erase(buffer_.begin(), buffer_.begin() + message_size); @@ -73,7 +73,7 @@ bool MessageProcessor::process_data(const std::vector &data) { dispatch(Invocation(raw_invocation)); } else if (message_type == MessageType::response) { - auto result = make_protobuf_object(); + auto result = make_protobuf_object(); result->ParseFromArray(buffer_.data(), message_size); buffer_.erase(buffer_.begin(), buffer_.begin() + message_size); @@ -90,7 +90,7 @@ void MessageProcessor::send_response(::google::protobuf::uint32 id, google::prot response->SerializeWithCachedSizesToArray(send_response_buffer.data()); - anbox::protobuf::bridge::Result send_response_result; + anbox::protobuf::rpc::Result send_response_result; send_response_result.set_id(id); send_response_result.set_response(send_response_buffer.data(), send_response_buffer.size()); diff --git a/src/anbox/bridge/message_processor.h b/src/anbox/rpc/message_processor.h similarity index 84% rename from src/anbox/bridge/message_processor.h rename to src/anbox/rpc/message_processor.h index c2c3c53..8a4de70 100644 --- a/src/anbox/bridge/message_processor.h +++ b/src/anbox/rpc/message_processor.h @@ -15,12 +15,12 @@ * */ -#ifndef ANBOX_BRIDGE_MESSAGE_PROCESSOR_H_ -#define ANBOX_BRIDGE_MESSAGE_PROCESSOR_H_ +#ifndef ANBOX_RPC_MESSAGE_PROCESSOR_H_ +#define ANBOX_RPC_MESSAGE_PROCESSOR_H_ #include "anbox/network/message_processor.h" #include "anbox/network/message_sender.h" -#include "anbox/bridge/pending_call_cache.h" +#include "anbox/rpc/pending_call_cache.h" #include @@ -29,22 +29,22 @@ namespace anbox { namespace protobuf { -namespace bridge { +namespace rpc { class Invocation; -} // namespace bridge +} // namespace rpc } // namespace protobuf -namespace bridge { +namespace rpc { class Invocation { public: - Invocation(anbox::protobuf::bridge::Invocation const& invocation) : + Invocation(anbox::protobuf::rpc::Invocation const& invocation) : invocation_(invocation) {} const ::std::string& method_name() const; const ::std::string& parameters() const; google::protobuf::uint32 id() const; private: - anbox::protobuf::bridge::Invocation const& invocation_; + anbox::protobuf::rpc::Invocation const& invocation_; }; class MessageProcessor : public network::MessageProcessor { @@ -65,7 +65,7 @@ private: std::vector buffer_; std::shared_ptr pending_calls_; }; -} // namespace bridge +} // namespace rpc } // namespace anbox #endif diff --git a/src/anbox/bridge/pending_call_cache.cpp b/src/anbox/rpc/pending_call_cache.cpp similarity index 89% rename from src/anbox/bridge/pending_call_cache.cpp rename to src/anbox/rpc/pending_call_cache.cpp index 577b4aa..b1ddfdd 100644 --- a/src/anbox/bridge/pending_call_cache.cpp +++ b/src/anbox/rpc/pending_call_cache.cpp @@ -16,29 +16,29 @@ * Authored by: Alan Griffiths */ -#include "anbox/bridge/pending_call_cache.h" +#include "anbox/rpc/pending_call_cache.h" -#include "anbox_bridge.pb.h" +#include "anbox_rpc.pb.h" namespace anbox { -namespace bridge { +namespace rpc { PendingCallCache::PendingCallCache() { } -void PendingCallCache::save_completion_details(anbox::protobuf::bridge::Invocation const &invocation, +void PendingCallCache::save_completion_details(anbox::protobuf::rpc::Invocation const &invocation, google::protobuf::MessageLite *response, google::protobuf::Closure *complete) { std::unique_lock lock(mutex_); pending_calls_[invocation.id()] = PendingCall(response, complete); } -void PendingCallCache::populate_message_for_result(anbox::protobuf::bridge::Result &result, +void PendingCallCache::populate_message_for_result(anbox::protobuf::rpc::Result &result, std::function const& populator) { std::unique_lock lock(mutex_); populator(pending_calls_.at(result.id()).response); } -void PendingCallCache::complete_response(anbox::protobuf::bridge::Result& result) { +void PendingCallCache::complete_response(anbox::protobuf::rpc::Result& result) { PendingCall completion; { @@ -68,5 +68,5 @@ bool PendingCallCache::empty() const { std::unique_lock lock(mutex_); return pending_calls_.empty(); } -} // namespace bridge +} // namespace rpc } // namespace anbox diff --git a/src/anbox/bridge/pending_call_cache.h b/src/anbox/rpc/pending_call_cache.h similarity index 82% rename from src/anbox/bridge/pending_call_cache.h rename to src/anbox/rpc/pending_call_cache.h index 4a1e30d..8ea9c78 100644 --- a/src/anbox/bridge/pending_call_cache.h +++ b/src/anbox/rpc/pending_call_cache.h @@ -16,8 +16,8 @@ * Authored by: Alan Griffiths */ -#ifndef ANBOX_BRIDGE_PENDING_CALL_CACHE_ -#define ANBOX_BRIDGE_PENDING_CALL_CACHE_ +#ifndef ANBOX_RPC_PENDING_CALL_CACHE_ +#define ANBOX_RPC_PENDING_CALL_CACHE_ #include #include @@ -32,22 +32,22 @@ class MessageLite; namespace anbox { namespace protobuf { -namespace bridge { +namespace rpc { class Invocation; class Result; -} // namespace bridge +} // namespace rpc } // namespace protobuf -namespace bridge { +namespace rpc { class PendingCallCache { public: PendingCallCache(); - void save_completion_details(anbox::protobuf::bridge::Invocation const &invocation, + void save_completion_details(anbox::protobuf::rpc::Invocation const &invocation, google::protobuf::MessageLite *response, google::protobuf::Closure *complete); - void populate_message_for_result(anbox::protobuf::bridge::Result &result, + void populate_message_for_result(anbox::protobuf::rpc::Result &result, std::function const& populator); - void complete_response(anbox::protobuf::bridge::Result& result); + void complete_response(anbox::protobuf::rpc::Result& result); void force_completion(); bool empty() const; @@ -71,7 +71,7 @@ private: std::mutex mutable mutex_; std::map pending_calls_; }; -} // namespace bridge +} // namespace rpc } // namespace anbox #endif diff --git a/src/anbox/bridge/template_message_processor.h b/src/anbox/rpc/template_message_processor.h similarity index 90% rename from src/anbox/bridge/template_message_processor.h rename to src/anbox/rpc/template_message_processor.h index fed6a04..b2fe7d0 100644 --- a/src/anbox/bridge/template_message_processor.h +++ b/src/anbox/rpc/template_message_processor.h @@ -16,17 +16,17 @@ * Authored by: Alan Griffiths */ -#ifndef ANBOX_BRIDGE_TEMPLATE_MESSAGE_PROCESSOR_H_ -#define ANBOX_BRIDGE_TEMPLATE_MESSAGE_PROCESSOR_H_ +#ifndef ANBOX_RPC_TEMPLATE_MESSAGE_PROCESSOR_H_ +#define ANBOX_RPC_TEMPLATE_MESSAGE_PROCESSOR_H_ #include -#include "anbox/bridge/message_processor.h" +#include "anbox/rpc/message_processor.h" -#include "anbox_bridge.pb.h" +#include "anbox_rpc.pb.h" namespace anbox { -namespace bridge { +namespace rpc { // Utility metafunction result_ptr_t<> allows invoke() to pick the right // send_response() overload. The base template resolves to the prototype // "send_response(::google::protobuf::uint32 id, ::google::protobuf::Message* response)" @@ -39,7 +39,7 @@ template struct result_ptr_t template void invoke( Self* self, - Bridge* bridge, + Bridge* rpc, void (BridgeX::*function)( ParameterMessage const* request, ResultMessage* response, @@ -63,7 +63,7 @@ void invoke( invocation.id(), &result_message)); - (bridge->*function)( + (rpc->*function)( ¶meter_message, &result_message, callback.get()); @@ -74,7 +74,7 @@ void invoke( self->send_response(invocation.id(), &result_message); } } -} // namespace bridge +} // namespace rpc } // namespace anbox #endif diff --git a/src/anbox/ubuntu/platform_api_skeleton.cpp b/src/anbox/ubuntu/platform_api_skeleton.cpp index 59ecb52..d7645cd 100644 --- a/src/anbox/ubuntu/platform_api_skeleton.cpp +++ b/src/anbox/ubuntu/platform_api_skeleton.cpp @@ -18,13 +18,15 @@ #include "anbox/ubuntu/platform_api_skeleton.h" #include "anbox/common/dispatcher.h" #include "anbox/bridge/android_api_stub.h" +#include "anbox/rpc/pending_call_cache.h" #include "anbox/logger.h" +#include "anbox_rpc.pb.h" #include "anbox_bridge.pb.h" namespace anbox { namespace ubuntu { -PlatformApiSekeleton::PlatformApiSekeleton(const std::shared_ptr &pending_calls) : +PlatformApiSekeleton::PlatformApiSekeleton(const std::shared_ptr &pending_calls) : bridge::PlatformApiSkeleton(pending_calls) { } @@ -32,17 +34,17 @@ PlatformApiSekeleton::~PlatformApiSekeleton() { } void PlatformApiSekeleton::handle_notification(anbox::protobuf::bridge::Notification const *request, - anbox::protobuf::bridge::Void *response, - google::protobuf::Closure *done) { + anbox::protobuf::rpc::Void *response, + google::protobuf::Closure *done) { (void) request; (void) response; DEBUG(""); done->Run(); } -void PlatformApiSekeleton::boot_finished(anbox::protobuf::bridge::Void const *request, - anbox::protobuf::bridge::Void *response, - google::protobuf::Closure *done) { +void PlatformApiSekeleton::boot_finished(anbox::protobuf::rpc::Void const *request, + anbox::protobuf::rpc::Void *response, + google::protobuf::Closure *done) { (void) request; (void) response; diff --git a/src/anbox/ubuntu/platform_api_skeleton.h b/src/anbox/ubuntu/platform_api_skeleton.h index c62b6fc..a00f391 100644 --- a/src/anbox/ubuntu/platform_api_skeleton.h +++ b/src/anbox/ubuntu/platform_api_skeleton.h @@ -27,18 +27,21 @@ class Dispatcher; namespace bridge { class AndroidApiStub; } // namespace bridge +namespace rpc { +class PendingCallCache; +} // namespace rpc; namespace ubuntu { class PlatformApiSekeleton : public bridge::PlatformApiSkeleton { public: - PlatformApiSekeleton(const std::shared_ptr &pending_calls); + PlatformApiSekeleton(const std::shared_ptr &pending_calls); virtual ~PlatformApiSekeleton(); void handle_notification(anbox::protobuf::bridge::Notification const *request, - anbox::protobuf::bridge::Void *response, + anbox::protobuf::rpc::Void *response, google::protobuf::Closure *done) override; - void boot_finished(anbox::protobuf::bridge::Void const *request, - anbox::protobuf::bridge::Void *response, + void boot_finished(anbox::protobuf::rpc::Void const *request, + anbox::protobuf::rpc::Void *response, google::protobuf::Closure *done) override; void on_boot_finished(const std::function &action);