diff options
author | Casey Dahlin <sadmac@google.com> | 2016-03-11 15:15:04 -0800 |
---|---|---|
committer | Casey Dahlin <sadmac@google.com> | 2016-03-16 15:26:50 -0700 |
commit | aa436b16e8d3425302eed56ffb92ecef4bc8e909 (patch) | |
tree | c1bed331c7d4b243133b9c2824552b4bdbfa1477 | |
parent | 64ee4ff6a863ced08c98e36dd05a93221917c0a0 (diff) | |
download | weaved-aa436b16e8d3425302eed56ffb92ecef4bc8e909.tar.gz |
Port weaved to binder webservd interface
Change-Id: I94085e4cd6acbbf604fec221f35f84878ecfd778
Test: Can successfully connect to webservd
Bug: 27204884
-rw-r--r-- | Android.mk | 1 | ||||
-rw-r--r-- | buffet/dbus_constants.cc | 26 | ||||
-rw-r--r-- | buffet/dbus_constants.h | 32 | ||||
-rw-r--r-- | buffet/main.cc | 22 | ||||
-rw-r--r-- | buffet/manager.cc | 8 | ||||
-rw-r--r-- | buffet/manager.h | 4 | ||||
-rw-r--r-- | buffet/webserv_client.cc | 11 | ||||
-rw-r--r-- | buffet/webserv_client.h | 14 |
8 files changed, 24 insertions, 94 deletions
@@ -103,7 +103,6 @@ LOCAL_SRC_FILES := \ buffet/binder_command_proxy.cc \ buffet/binder_weave_service.cc \ buffet/buffet_config.cc \ - buffet/dbus_constants.cc \ buffet/flouride_socket_bluetooth_client.cc \ buffet/http_transport_client.cc \ buffet/manager.cc \ diff --git a/buffet/dbus_constants.cc b/buffet/dbus_constants.cc deleted file mode 100644 index 61eaf5c..0000000 --- a/buffet/dbus_constants.cc +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2015 The Android Open Source Project -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "buffet/dbus_constants.h" - -namespace buffet { - -namespace dbus_constants { - -const char kServiceName[] = "com.android.Weave"; -const char kRootServicePath[] = "/com/android/Weave"; - -} // namespace dbus constants - -} // namespace buffet diff --git a/buffet/dbus_constants.h b/buffet/dbus_constants.h deleted file mode 100644 index ae91891..0000000 --- a/buffet/dbus_constants.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2015 The Android Open Source Project -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef BUFFET_DBUS_CONSTANTS_H_ -#define BUFFET_DBUS_CONSTANTS_H_ - -namespace buffet { - -namespace dbus_constants { - -// The service name claimed by the Buffet daemon. -extern const char kServiceName[]; - -// The object at this path implements the ObjectManager interface. -extern const char kRootServicePath[]; - -} // namespace dbus_constants - -} // namespace buffet - -#endif // BUFFET_DBUS_CONSTANTS_H_ diff --git a/buffet/main.cc b/buffet/main.cc index 0120d75..6555d82 100644 --- a/buffet/main.cc +++ b/buffet/main.cc @@ -28,37 +28,37 @@ #include <brillo/syslog_logging.h> #include "buffet/buffet_config.h" -#include "buffet/dbus_constants.h" #include "buffet/manager.h" #include "common/binder_constants.h" using brillo::dbus_utils::AsyncEventSequencer; -using brillo::DBusServiceDaemon; -using buffet::dbus_constants::kServiceName; -using buffet::dbus_constants::kRootServicePath; +using brillo::DBusDaemon; namespace buffet { -class Daemon final : public DBusServiceDaemon { +class Daemon final : public DBusDaemon { public: explicit Daemon(const Manager::Options& options) - : DBusServiceDaemon(kServiceName, kRootServicePath), options_{options} {} + : options_{options} {} protected: int OnInit() override { + int err = brillo::DBusDaemon::OnInit(); + if (err != EX_OK) { + return err; + } + android::BinderWrapper::Create(); if (!binder_watcher_.Init()) return EX_OSERR; - return brillo::DBusServiceDaemon::OnInit(); - } - - void RegisterDBusObjectsAsync(AsyncEventSequencer* sequencer) override { manager_ = new Manager{options_, bus_}; android::BinderWrapper::Get()->RegisterService( weaved::binder::kWeaveServiceName, android::IInterface::asBinder(manager_)); - manager_->Start(sequencer); + manager_->Start(); + + return EX_OK; } void OnShutdown(int* /*return_code*/) override { manager_->Stop(); } diff --git a/buffet/manager.cc b/buffet/manager.cc index cbb1add..ef18adc 100644 --- a/buffet/manager.cc +++ b/buffet/manager.cc @@ -134,12 +134,12 @@ Manager::~Manager() { } } -void Manager::Start(AsyncEventSequencer* sequencer) { +void Manager::Start() { power_manager_client_.Init(); - RestartWeave(sequencer); + RestartWeave(); } -void Manager::RestartWeave(AsyncEventSequencer* sequencer) { +void Manager::RestartWeave() { Stop(); task_runner_.reset(new TaskRunner{}); @@ -153,7 +153,7 @@ void Manager::RestartWeave(AsyncEventSequencer* sequencer) { if (!options_.disable_privet) { mdns_client_ = MdnsClient::CreateInstance(); web_serv_client_.reset(new WebServClient{ - bus_, sequencer, + brillo::MessageLoop::current(), base::Bind(&Manager::CreateDevice, weak_ptr_factory_.GetWeakPtr())}); bluetooth_client_ = BluetoothClient::CreateInstance(); http_server = web_serv_client_.get(); diff --git a/buffet/manager.h b/buffet/manager.h index e152e40..1bb638e 100644 --- a/buffet/manager.h +++ b/buffet/manager.h @@ -58,11 +58,11 @@ class Manager final : public android::weave::BnWeaveServiceManager { Manager(const Options& options, const scoped_refptr<dbus::Bus>& bus); ~Manager() override; - void Start(brillo::dbus_utils::AsyncEventSequencer* sequencer); + void Start(); void Stop(); private: - void RestartWeave(brillo::dbus_utils::AsyncEventSequencer* sequencer); + void RestartWeave(); void CreateDevice(); // Binder methods for IWeaveServiceManager: diff --git a/buffet/webserv_client.cc b/buffet/webserv_client.cc index 4a67d75..030ae59 100644 --- a/buffet/webserv_client.cc +++ b/buffet/webserv_client.cc @@ -22,7 +22,8 @@ #include <libwebserv/response.h> #include <libwebserv/server.h> -#include "buffet/dbus_constants.h" +#include <base/bind.h> + #include "buffet/socket_stream.h" namespace buffet { @@ -89,13 +90,11 @@ class RequestImpl : public HttpServer::Request { } // namespace WebServClient::WebServClient( - const scoped_refptr<dbus::Bus>& bus, - brillo::dbus_utils::AsyncEventSequencer* sequencer, + brillo::MessageLoop* message_loop, const base::Closure& server_available_callback) : server_available_callback_{server_available_callback} { - web_server_ = libwebserv::Server::ConnectToServerViaDBus( - bus, buffet::dbus_constants::kServiceName, - sequencer->GetHandler("Server::Connect failed.", true), + web_server_ = libwebserv::Server::ConnectToServerViaBinder( + message_loop, base::Bind(&base::DoNothing), base::Bind(&base::DoNothing)); web_server_->OnProtocolHandlerConnected( diff --git a/buffet/webserv_client.h b/buffet/webserv_client.h index 1c0d44c..8a12936 100644 --- a/buffet/webserv_client.h +++ b/buffet/webserv_client.h @@ -20,18 +20,9 @@ #include <vector> #include <base/memory/weak_ptr.h> +#include <brillo/message_loops/message_loop.h> #include <weave/provider/http_server.h> -namespace dbus { -class Bus; -} - -namespace brillo { -namespace dbus_utils { -class AsyncEventSequencer; -} -} - namespace libwebserv { class ProtocolHandler; class Request; @@ -44,8 +35,7 @@ namespace buffet { // Wrapper around libwebserv that implements HttpServer interface. class WebServClient : public weave::provider::HttpServer { public: - WebServClient(const scoped_refptr<dbus::Bus>& bus, - brillo::dbus_utils::AsyncEventSequencer* sequencer, + WebServClient(brillo::MessageLoop* message_loop, const base::Closure& server_available_callback); ~WebServClient() override; |