Move RPC implementation into its own namespace
This commit is contained in:
parent
70666da79b
commit
51e9cfa777
24 changed files with 187 additions and 165 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 <boost/filesystem.hpp>
|
||||
|
|
@ -35,7 +36,7 @@ AndroidApiStub::AndroidApiStub() {
|
|||
AndroidApiStub::~AndroidApiStub() {
|
||||
}
|
||||
|
||||
void AndroidApiStub::set_rpc_channel(const std::shared_ptr<RpcChannel> &channel) {
|
||||
void AndroidApiStub::set_rpc_channel(const std::shared_ptr<rpc::Channel> &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<Request<protobuf::bridge::Void>>();
|
||||
auto c = std::make_shared<Request<protobuf::rpc::Void>>();
|
||||
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<protobuf::bridge::Void> *request) {
|
||||
void AndroidApiStub::application_installed(Request<protobuf::rpc::Void> *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<Request<protobuf::bridge::Void>>();
|
||||
auto c = std::make_shared<Request<protobuf::rpc::Void>>();
|
||||
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<protobuf::bridge::Void> *request) {
|
||||
void AndroidApiStub::application_launched(Request<protobuf::rpc::Void> *request) {
|
||||
launch_wait_handle_.result_received();
|
||||
}
|
||||
|
||||
void AndroidApiStub::set_dns_servers(const std::string &domain, const std::vector<std::string> &servers) {
|
||||
ensure_rpc_channel();
|
||||
|
||||
auto c = std::make_shared<Request<protobuf::bridge::Void>>();
|
||||
auto c = std::make_shared<Request<protobuf::rpc::Void>>();
|
||||
|
||||
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<protobuf::bridge::Void> *request) {
|
||||
void AndroidApiStub::dns_servers_set(Request<protobuf::rpc::Void> *request) {
|
||||
set_dns_servers_wait_handle_.result_received();
|
||||
}
|
||||
} // namespace bridge
|
||||
|
|
|
|||
|
|
@ -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<RpcChannel> &channel);
|
||||
void set_rpc_channel(const std::shared_ptr<rpc::Channel> &channel);
|
||||
void reset_rpc_channel();
|
||||
|
||||
void install(const std::string &path) override;
|
||||
|
|
@ -55,12 +57,12 @@ private:
|
|||
bool success;
|
||||
};
|
||||
|
||||
void application_installed(Request<protobuf::bridge::Void> *request);
|
||||
void application_launched(Request<protobuf::bridge::Void> *request);
|
||||
void dns_servers_set(Request<protobuf::bridge::Void> *request);
|
||||
void application_installed(Request<protobuf::rpc::Void> *request);
|
||||
void application_launched(Request<protobuf::rpc::Void> *request);
|
||||
void dns_servers_set(Request<protobuf::rpc::Void> *request);
|
||||
|
||||
mutable std::mutex mutex_;
|
||||
std::shared_ptr<RpcChannel> channel_;
|
||||
std::shared_ptr<rpc::Channel> channel_;
|
||||
common::WaitHandle install_wait_handle_;
|
||||
common::WaitHandle launch_wait_handle_;
|
||||
common::WaitHandle set_dns_servers_wait_handle_;
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
namespace anbox {
|
||||
namespace bridge {
|
||||
PlatformApiSkeleton::PlatformApiSkeleton(const std::shared_ptr<PendingCallCache> &pending_calls) :
|
||||
PlatformApiSkeleton::PlatformApiSkeleton(const std::shared_ptr<rpc::PendingCallCache> &pending_calls) :
|
||||
pending_calls_(pending_calls) {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<PendingCallCache> &pending_calls);
|
||||
PlatformApiSkeleton(const std::shared_ptr<rpc::PendingCallCache> &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<PendingCallCache> pending_calls_;
|
||||
std::shared_ptr<rpc::PendingCallCache> pending_calls_;
|
||||
};
|
||||
} // namespace bridge
|
||||
} // namespace anbox
|
||||
|
|
|
|||
|
|
@ -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<network::MessageSender> &sender,
|
||||
const std::shared_ptr<PlatformApiSkeleton> &server,
|
||||
const std::shared_ptr<PendingCallCache> &pending_calls) :
|
||||
MessageProcessor(sender, pending_calls),
|
||||
const std::shared_ptr<rpc::PendingCallCache> &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")
|
||||
|
|
|
|||
|
|
@ -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<network::MessageSender> &sender,
|
||||
const std::shared_ptr<PlatformApiSkeleton> &server,
|
||||
const std::shared_ptr<PendingCallCache> &pending_calls);
|
||||
const std::shared_ptr<rpc::PendingCallCache> &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:
|
||||
|
|
|
|||
|
|
@ -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<network::PublishedSocketConnector>(
|
||||
utils::string_format("%s/anbox_bridge", config::socket_path()),
|
||||
rt,
|
||||
std::make_shared<bridge::ConnectionCreator>(rt,
|
||||
std::make_shared<rpc::ConnectionCreator>(rt,
|
||||
[&](const std::shared_ptr<network::MessageSender> &sender) {
|
||||
auto pending_calls = std::make_shared<bridge::PendingCallCache>();
|
||||
auto rpc_channel = std::make_shared<bridge::RpcChannel>(pending_calls, sender);
|
||||
auto pending_calls = std::make_shared<rpc::PendingCallCache>();
|
||||
auto rpc_channel = std::make_shared<rpc::Channel>(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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
25
src/anbox/protobuf/anbox_rpc.proto
Normal file
25
src/anbox/protobuf/anbox_rpc.proto
Normal file
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -17,42 +17,42 @@
|
|||
* Authored by: Alan Griffiths <alan@octopull.co.uk>
|
||||
*/
|
||||
|
||||
#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<PendingCallCache> &pending_calls,
|
||||
const std::shared_ptr<network::MessageSender> &sender) :
|
||||
namespace rpc {
|
||||
Channel::Channel(const std::shared_ptr<PendingCallCache> &pending_calls,
|
||||
const std::shared_ptr<network::MessageSender> &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<size_t>(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<unsigned char>((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
|
||||
|
|
@ -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 <memory>
|
||||
#include <atomic>
|
||||
|
|
@ -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<PendingCallCache> &pending_calls,
|
||||
Channel(const std::shared_ptr<PendingCallCache> &pending_calls,
|
||||
const std::shared_ptr<network::MessageSender> &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<network::MessageSender> sender_;
|
||||
std::mutex write_mutex_;
|
||||
};
|
||||
} // namespace bridge
|
||||
} // namespace rpc
|
||||
} // namespace anbox
|
||||
|
||||
#endif
|
||||
|
|
@ -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<Runtime> &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
|
||||
|
|
@ -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 <boost/asio.hpp>
|
||||
|
||||
|
|
@ -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<std::shared_ptr<network::MessageProcessor>(
|
||||
|
|
@ -51,7 +51,7 @@ private:
|
|||
std::shared_ptr<network::Connections<network::SocketConnection>> const connections_;
|
||||
MessageProcessorFactory message_processor_factory_;
|
||||
};
|
||||
} // namespace rpc
|
||||
} // namespace anbox
|
||||
} // namespace network
|
||||
|
||||
#endif
|
||||
|
|
@ -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
|
||||
|
|
@ -16,13 +16,13 @@
|
|||
* Authored by: Alberto Aguirre <alberto.aguirre@canonical.com>
|
||||
*/
|
||||
|
||||
#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 <memory>
|
||||
|
||||
namespace anbox {
|
||||
namespace bridge {
|
||||
namespace rpc {
|
||||
template <typename ProtobufType>
|
||||
auto make_protobuf_object() {
|
||||
return std::unique_ptr<ProtobufType>{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
|
||||
|
|
@ -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<std::uint8_t> &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<std::uint8_t> &data) {
|
|||
dispatch(Invocation(raw_invocation));
|
||||
}
|
||||
else if (message_type == MessageType::response) {
|
||||
auto result = make_protobuf_object<protobuf::bridge::Result>();
|
||||
auto result = make_protobuf_object<protobuf::rpc::Result>();
|
||||
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());
|
||||
|
||||
|
|
@ -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 <memory>
|
||||
|
||||
|
|
@ -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<std::uint8_t> buffer_;
|
||||
std::shared_ptr<PendingCallCache> pending_calls_;
|
||||
};
|
||||
} // namespace bridge
|
||||
} // namespace rpc
|
||||
} // namespace anbox
|
||||
|
||||
#endif
|
||||
|
|
@ -16,29 +16,29 @@
|
|||
* Authored by: Alan Griffiths <alan@octopull.co.uk>
|
||||
*/
|
||||
|
||||
#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<std::mutex> 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<void(google::protobuf::MessageLite*)> const& populator) {
|
||||
std::unique_lock<std::mutex> 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<std::mutex> lock(mutex_);
|
||||
return pending_calls_.empty();
|
||||
}
|
||||
} // namespace bridge
|
||||
} // namespace rpc
|
||||
} // namespace anbox
|
||||
|
|
@ -16,8 +16,8 @@
|
|||
* Authored by: Alan Griffiths <alan@octopull.co.uk>
|
||||
*/
|
||||
|
||||
#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 <functional>
|
||||
#include <mutex>
|
||||
|
|
@ -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<void(google::protobuf::MessageLite*)> 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<int, PendingCall> pending_calls_;
|
||||
};
|
||||
} // namespace bridge
|
||||
} // namespace rpc
|
||||
} // namespace anbox
|
||||
|
||||
#endif
|
||||
|
|
@ -16,17 +16,17 @@
|
|||
* Authored by: Alan Griffiths <alan@octopull.co.uk>
|
||||
*/
|
||||
|
||||
#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 <google/protobuf/stubs/common.h>
|
||||
|
||||
#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<typename ResultType> struct result_ptr_t
|
|||
template<class Self, class Bridge, class BridgeX, class ParameterMessage, class ResultMessage>
|
||||
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
|
||||
|
|
@ -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<bridge::PendingCallCache> &pending_calls) :
|
||||
PlatformApiSekeleton::PlatformApiSekeleton(const std::shared_ptr<rpc::PendingCallCache> &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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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<bridge::PendingCallCache> &pending_calls);
|
||||
PlatformApiSekeleton(const std::shared_ptr<rpc::PendingCallCache> &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<void()> &action);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue