Remove weave::Device::Start method Start code moved into weave::Device::Create() method. BUG:24267885 Change-Id: I311777dfebe4374491c9c13907d92c6574304bd9 Reviewed-on: https://weave-review.googlesource.com/1220 Reviewed-by: Vitaly Buka <vitalybuka@google.com>
diff --git a/libweave/examples/ubuntu/main.cc b/libweave/examples/ubuntu/main.cc index cdeae8b..43c13ec 100644 --- a/libweave/examples/ubuntu/main.cc +++ b/libweave/examples/ubuntu/main.cc
@@ -104,8 +104,7 @@ weave::examples::HttpServerImpl http_server{&task_runner}; weave::examples::BluetoothImpl bluetooth; - auto device = weave::Device::Create(); - device->Start( + auto device = weave::Device::Create( &config_store, &task_runner, &http_client, &network, &dns_sd, &http_server, weave::examples::NetworkImpl::HasWifiCapability() ? &network : nullptr,
diff --git a/libweave/include/weave/device.h b/libweave/include/weave/device.h index 260790f..57895b2 100644 --- a/libweave/include/weave/device.h +++ b/libweave/include/weave/device.h
@@ -35,15 +35,6 @@ public: virtual ~Device() = default; - virtual void Start(provider::ConfigStore* config_store, - provider::TaskRunner* task_runner, - provider::HttpClient* http_client, - provider::Network* network, - provider::DnsServiceDiscovery* dns_sd, - provider::HttpServer* http_server, - provider::Wifi* wifi, - provider::Bluetooth* bluetooth_provider) = 0; - // Returns reference the current settings. virtual const Settings& GetSettings() = 0; @@ -84,7 +75,15 @@ const PairingBeginCallback& begin_callback, const PairingEndCallback& end_callback) = 0; - LIBWEAVE_EXPORT static std::unique_ptr<Device> Create(); + LIBWEAVE_EXPORT static std::unique_ptr<Device> Create( + provider::ConfigStore* config_store, + provider::TaskRunner* task_runner, + provider::HttpClient* http_client, + provider::Network* network, + provider::DnsServiceDiscovery* dns_sd, + provider::HttpServer* http_server, + provider::Wifi* wifi, + provider::Bluetooth* bluetooth_provider); }; } // namespace weave
diff --git a/libweave/src/device_manager.cc b/libweave/src/device_manager.cc index 5a8e630..46d5de9 100644 --- a/libweave/src/device_manager.cc +++ b/libweave/src/device_manager.cc
@@ -25,18 +25,14 @@ } // namespace -DeviceManager::DeviceManager() {} - -DeviceManager::~DeviceManager() {} - -void DeviceManager::Start(provider::ConfigStore* config_store, - provider::TaskRunner* task_runner, - provider::HttpClient* http_client, - provider::Network* network, - provider::DnsServiceDiscovery* dns_sd, - provider::HttpServer* http_server, - provider::Wifi* wifi, - provider::Bluetooth* bluetooth) { +DeviceManager::DeviceManager(provider::ConfigStore* config_store, + provider::TaskRunner* task_runner, + provider::HttpClient* http_client, + provider::Network* network, + provider::DnsServiceDiscovery* dns_sd, + provider::HttpServer* http_server, + provider::Wifi* wifi, + provider::Bluetooth* bluetooth) { command_manager_ = std::make_shared<CommandManager>(); command_manager_->Startup(config_store); state_change_queue_.reset(new StateChangeQueue(kMaxStateChangeQueueSize)); @@ -63,6 +59,8 @@ } } +DeviceManager::~DeviceManager() {} + const Settings& DeviceManager::GetSettings() { return device_info_->GetSettings(); } @@ -117,8 +115,17 @@ privet_->AddOnPairingChangedCallbacks(begin_callback, end_callback); } -std::unique_ptr<Device> Device::Create() { - return std::unique_ptr<Device>{new DeviceManager}; +std::unique_ptr<Device> Device::Create(provider::ConfigStore* config_store, + provider::TaskRunner* task_runner, + provider::HttpClient* http_client, + provider::Network* network, + provider::DnsServiceDiscovery* dns_sd, + provider::HttpServer* http_server, + provider::Wifi* wifi, + provider::Bluetooth* bluetooth) { + return std::unique_ptr<Device>{ + new DeviceManager{config_store, task_runner, http_client, network, dns_sd, + http_server, wifi, bluetooth}}; } } // namespace weave
diff --git a/libweave/src/device_manager.h b/libweave/src/device_manager.h index 787a7be..d96ee9b 100644 --- a/libweave/src/device_manager.h +++ b/libweave/src/device_manager.h
@@ -23,25 +23,23 @@ class DeviceManager final : public Device { public: - DeviceManager(); + DeviceManager(provider::ConfigStore* config_store, + provider::TaskRunner* task_runner, + provider::HttpClient* http_client, + provider::Network* network, + provider::DnsServiceDiscovery* dns_sd, + provider::HttpServer* http_server, + provider::Wifi* wifi, + provider::Bluetooth* bluetooth); ~DeviceManager() override; // Device implementation. - void Start(provider::ConfigStore* config_store, - provider::TaskRunner* task_runner, - provider::HttpClient* http_client, - provider::Network* network, - provider::DnsServiceDiscovery* dns_sd, - provider::HttpServer* http_server, - provider::Wifi* wifi, - provider::Bluetooth* bluetooth) override; const Settings& GetSettings() override; void AddSettingsChangedCallback( const SettingsChangedCallback& callback) override; Commands* GetCommands() override; State* GetState() override; - std::string RegisterDevice(const std::string& ticket_id, - ErrorPtr* error) override; + std::string Register(const std::string& ticket_id, ErrorPtr* error) override; GcdState GetGcdState() const override; void AddGcdStateChangedCallback(
diff --git a/libweave/src/weave_unittest.cc b/libweave/src/weave_unittest.cc index e211392..8776ba6 100644 --- a/libweave/src/weave_unittest.cc +++ b/libweave/src/weave_unittest.cc
@@ -134,7 +134,7 @@ class WeaveTest : public ::testing::Test { protected: - void SetUp() override { device_ = weave::Device::Create(); } + void SetUp() override {} void ExpectRequest(const std::string& method, const std::string& url, @@ -235,8 +235,9 @@ } void StartDevice() { - device_->Start(&config_store_, &task_runner_, &http_client_, &network_, - &dns_sd_, &http_server_, &wifi_, &bluetooth_); + device_ = weave::Device::Create(&config_store_, &task_runner_, + &http_client_, &network_, &dns_sd_, + &http_server_, &wifi_, &bluetooth_); for (const auto& cb : http_server_changed_cb_) cb.Run(http_server_); @@ -270,14 +271,10 @@ std::unique_ptr<weave::Device> device_; }; -TEST_F(WeaveTest, Create) { - ASSERT_TRUE(device_.get()); -} - TEST_F(WeaveTest, StartMinimal) { InitConfigStore(); - device_->Start(&config_store_, &task_runner_, &http_client_, &network_, - nullptr, nullptr, &wifi_, nullptr); + device_ = weave::Device::Create(&config_store_, &task_runner_, &http_client_, + &network_, nullptr, nullptr, &wifi_, nullptr); } TEST_F(WeaveTest, StartNoWifi) { @@ -287,8 +284,9 @@ InitDnsSd(); InitDnsSdPublishing(false, "CB"); - device_->Start(&config_store_, &task_runner_, &http_client_, &network_, - &dns_sd_, &http_server_, nullptr, &bluetooth_); + device_ = weave::Device::Create(&config_store_, &task_runner_, &http_client_, + &network_, &dns_sd_, &http_server_, nullptr, + &bluetooth_); for (const auto& cb : http_server_changed_cb_) cb.Run(http_server_); @@ -336,7 +334,7 @@ InitDnsSdPublishing(true, "DB"); - EXPECT_EQ("CLOUD_ID", device_->RegisterDevice("TICKET_ID", nullptr)); + EXPECT_EQ("CLOUD_ID", device_->Register("TICKET_ID", nullptr)); } class WeaveWiFiSetupTest : public WeaveTest {