diff options
author | Christopher Wiley <wiley@chromium.org> | 2015-03-12 16:02:22 -0700 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2015-03-15 02:41:42 +0000 |
commit | efe9df5bf7fd906c1dad13f0e00cfd27ad190dac (patch) | |
tree | bff82907f48b9655effb9147c76ead66ca768965 | |
parent | 1b6aa986ce3143dd2fe9c9ccc180f8ea9afba1e5 (diff) | |
download | dbus-binding-generator-efe9df5bf7fd906c1dad13f0e00cfd27ad190dac.tar.gz |
chromeos-dbus-bindings: Correct ObjectManager without service name
We need to store the passed in service name and pass it to proxies
we create when not configured with a service name in the dbus config.
BUG=brillo:581
TEST=leaderd changes which depend on this compile, unittests.
Change-Id: Id53f3a0c45ac64d477ba1d723952679cc3eb1b29
Reviewed-on: https://chromium-review.googlesource.com/260014
Tested-by: Christopher Wiley <wiley@chromium.org>
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Commit-Queue: Christopher Wiley <wiley@chromium.org>
-rw-r--r-- | chromeos-dbus-bindings/proxy_generator.cc | 15 | ||||
-rw-r--r-- | chromeos-dbus-bindings/proxy_generator.h | 6 | ||||
-rw-r--r-- | chromeos-dbus-bindings/proxy_generator_unittest.cc | 6 |
3 files changed, 21 insertions, 6 deletions
diff --git a/chromeos-dbus-bindings/proxy_generator.cc b/chromeos-dbus-bindings/proxy_generator.cc index 34d9e90..0921ae4 100644 --- a/chromeos-dbus-bindings/proxy_generator.cc +++ b/chromeos-dbus-bindings/proxy_generator.cc @@ -837,10 +837,10 @@ void ProxyGenerator::ObjectManager::GenerateProxy( text->AddLineWithOffset("private:", kScopeOffset); text->PushOffset(kBlockOffset); AddOnPropertyChanged(interfaces, text); - AddObjectAdded(interfaces, text); + AddObjectAdded(config, interfaces, text); AddObjectRemoved(interfaces, text); AddCreateProperties(interfaces, class_name, text); - AddDataMembers(interfaces, class_name, text); + AddDataMembers(config, interfaces, class_name, text); text->AddLine(StringPrintf("DISALLOW_COPY_AND_ASSIGN(%s);", class_name.c_str())); @@ -870,6 +870,9 @@ void ProxyGenerator::ObjectManager::AddConstructor( text->PushOffset(kLineContinuationOffset); text->AddLine(": bus_{bus},"); text->PushOffset(kBlockOffset); + if (config.service_name.empty()) { + text->AddLine("service_name_{service_name},"); + } text->AddLine("dbus_object_manager_{bus->GetObjectManager("); text->PushOffset(kLineContinuationOffset); if (config.service_name.empty()) { @@ -1037,6 +1040,7 @@ void ProxyGenerator::ObjectManager::AddOnPropertyChanged( } void ProxyGenerator::ObjectManager::AddObjectAdded( + const ServiceConfig& config, const std::vector<Interface>& interfaces, IndentedText* text) { text->AddLine("void ObjectAdded("); @@ -1068,6 +1072,9 @@ void ProxyGenerator::ObjectManager::AddObjectAdded( text->PushOffset(kBlockOffset); string new_instance = StringPrintf("new %s{bus_", itf_name.MakeProxyName(true).c_str()); + if (config.service_name.empty()) { + new_instance += ", service_name_"; + } if (itf.path.empty()) new_instance += ", object_path"; if (!itf.properties.empty()) @@ -1177,10 +1184,14 @@ void ProxyGenerator::ObjectManager::AddCreateProperties( } void ProxyGenerator::ObjectManager::AddDataMembers( + const ServiceConfig& config, const std::vector<Interface>& interfaces, const std::string& class_name, IndentedText* text) { text->AddLine("scoped_refptr<dbus::Bus> bus_;"); + if (config.service_name.empty()) { + text->AddLine("std::string service_name_;"); + } text->AddLine("dbus::ObjectManager* dbus_object_manager_;"); for (const auto& itf : interfaces) { NameParser itf_name{itf.name}; diff --git a/chromeos-dbus-bindings/proxy_generator.h b/chromeos-dbus-bindings/proxy_generator.h index aa9e89e..5dc04c9 100644 --- a/chromeos-dbus-bindings/proxy_generator.h +++ b/chromeos-dbus-bindings/proxy_generator.h @@ -146,7 +146,8 @@ class ProxyGenerator : public HeaderGenerator { IndentedText* text); // Generates ObjectAdded() method. - static void AddObjectAdded(const std::vector<Interface>& interfaces, + static void AddObjectAdded(const ServiceConfig& config, + const std::vector<Interface>& interfaces, IndentedText* text); // Generates ObjectRemoved() method. @@ -159,7 +160,8 @@ class ProxyGenerator : public HeaderGenerator { IndentedText* text); // Generates data members of the class. - static void AddDataMembers(const std::vector<Interface>& interfaces, + static void AddDataMembers(const ServiceConfig& config, + const std::vector<Interface>& interfaces, const std::string& class_name, IndentedText* text); }; diff --git a/chromeos-dbus-bindings/proxy_generator_unittest.cc b/chromeos-dbus-bindings/proxy_generator_unittest.cc index a157656..165d068 100644 --- a/chromeos-dbus-bindings/proxy_generator_unittest.cc +++ b/chromeos-dbus-bindings/proxy_generator_unittest.cc @@ -740,6 +740,7 @@ class ObjectManagerProxy : public dbus::ObjectManager::Interface { ObjectManagerProxy(const scoped_refptr<dbus::Bus>& bus, const std::string& service_name) : bus_{bus}, + service_name_{service_name}, dbus_object_manager_{bus->GetObjectManager( service_name, dbus::ObjectPath{"/org/chromium/Test"})} { @@ -821,7 +822,7 @@ class ObjectManagerProxy : public dbus::ObjectManager::Interface { static_cast<org::chromium::Itf1Proxy::PropertySet*>( dbus_object_manager_->GetProperties(object_path, interface_name)); std::unique_ptr<org::chromium::Itf1Proxy> itf1_proxy{ - new org::chromium::Itf1Proxy{bus_, property_set} + new org::chromium::Itf1Proxy{bus_, service_name_, property_set} }; auto p = itf1_instances_.emplace(object_path, std::move(itf1_proxy)); if (!on_itf1_added_.is_null()) @@ -830,7 +831,7 @@ class ObjectManagerProxy : public dbus::ObjectManager::Interface { } if (interface_name == "org.chromium.Itf2") { std::unique_ptr<org::chromium::Itf2Proxy> itf2_proxy{ - new org::chromium::Itf2Proxy{bus_, object_path} + new org::chromium::Itf2Proxy{bus_, service_name_, object_path} }; auto p = itf2_instances_.emplace(object_path, std::move(itf2_proxy)); if (!on_itf2_added_.is_null()) @@ -890,6 +891,7 @@ class ObjectManagerProxy : public dbus::ObjectManager::Interface { } scoped_refptr<dbus::Bus> bus_; + std::string service_name_; dbus::ObjectManager* dbus_object_manager_; std::map<dbus::ObjectPath, std::unique_ptr<org::chromium::Itf1Proxy>> itf1_instances_; |