aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Vakulenko <avakulenko@google.com>2016-01-08 22:05:22 +0000
committerandroid-build-merger <android-build-merger@google.com>2016-01-08 22:05:22 +0000
commitdd06bb84503437954920c9856b2602720e1bd569 (patch)
treee41392338a6e706e12ec15693607e783b080a52c
parentf091e982abdde48eb5940c9180f0e80865f24f3f (diff)
parentc984451a701ab88a14ff5d911939e686f09d16a8 (diff)
downloadweaved-dd06bb84503437954920c9856b2602720e1bd569.tar.gz
weaved: Split command and state property name into a trait and a name
am: c984451a70 * commit 'c984451a701ab88a14ff5d911939e686f09d16a8': weaved: Split command and state property name into a trait and a name
-rw-r--r--libweaved/service.cc18
-rw-r--r--libweaved/service.h12
2 files changed, 22 insertions, 8 deletions
diff --git a/libweaved/service.cc b/libweaved/service.cc
index 83a404d..037c037 100644
--- a/libweaved/service.cc
+++ b/libweaved/service.cc
@@ -18,6 +18,7 @@
#include <base/bind.h>
#include <base/memory/weak_ptr.h>
+#include <base/strings/stringprintf.h>
#include <binderwrapper/binder_wrapper.h>
#include <brillo/message_loops/message_loop.h>
@@ -163,13 +164,15 @@ class ServiceImpl : public std::enable_shared_from_this<ServiceImpl>,
const std::vector<std::string>& traits,
brillo::ErrorPtr* error) override;
void AddCommandHandler(const std::string& component,
+ const std::string& trait_name,
const std::string& command_name,
const CommandHandlerCallback& callback) override;
bool SetStateProperties(const std::string& component,
const brillo::VariantDictionary& dict,
brillo::ErrorPtr* error) override;
bool SetStateProperty(const std::string& component,
- const std::string& name,
+ const std::string& trait_name,
+ const std::string& property_name,
const brillo::Any& value,
brillo::ErrorPtr* error) override;
@@ -276,20 +279,24 @@ bool ServiceImpl::AddComponent(const std::string& component,
}
void ServiceImpl::AddCommandHandler(const std::string& component,
+ const std::string& trait_name,
const std::string& command_name,
const CommandHandlerCallback& callback) {
CHECK(!component.empty() && !command_name.empty());
CHECK(weave_service_.get());
+ std::string full_command_name =
+ base::StringPrintf("%s.%s", trait_name.c_str(), command_name.c_str());
+
CommandHandlerEntry entry;
entry.component = component;
- entry.command_name = command_name;
+ entry.command_name = full_command_name;
entry.callback = callback;
command_handlers_.push_back(std::move(entry));
auto status = weave_service_->registerCommandHandler(
android::String16{component.c_str()},
- android::String16{command_name.c_str()});
+ android::String16{full_command_name.c_str()});
CHECK(status.isOk());
}
@@ -307,9 +314,12 @@ bool ServiceImpl::SetStateProperties(const std::string& component,
}
bool ServiceImpl::SetStateProperty(const std::string& component,
- const std::string& name,
+ const std::string& trait_name,
+ const std::string& property_name,
const brillo::Any& value,
brillo::ErrorPtr* error) {
+ std::string name =
+ base::StringPrintf("%s.%s", trait_name.c_str(), property_name.c_str());
return SetStateProperties(component, brillo::VariantDictionary{{name, value}},
error);
}
diff --git a/libweaved/service.h b/libweaved/service.h
index 7ae6824..415b230 100644
--- a/libweaved/service.h
+++ b/libweaved/service.h
@@ -54,10 +54,11 @@ class LIBWEAVED_EXPORT Service {
brillo::ErrorPtr* error) = 0;
// Sets handler for new commands added to the queue for a given |component|.
- // |command_name| is the full name of the command to handle, including the
- // name of the trait, e.g. "base.reboot".
+ // |command_name| is the name of the command to handle (e.g. "reboot").
+ // |trait_name| is the name of a trait the command belongs to (e.g. "base").
// Each command can have no more than one handler.
virtual void AddCommandHandler(const std::string& component,
+ const std::string& trait_name,
const std::string& command_name,
const CommandHandlerCallback& callback) = 0;
@@ -68,9 +69,12 @@ class LIBWEAVED_EXPORT Service {
brillo::ErrorPtr* error) = 0;
// Sets value of the single property.
- // |name| is full property name, including trait name. e.g. "base.network".
+ // |component| is a path to the component to set the property value to.
+ // |trait_name| is the name of the trait this property is part of.
+ // |property_name| is the property name.
virtual bool SetStateProperty(const std::string& component,
- const std::string& name,
+ const std::string& trait_name,
+ const std::string& property_name,
const brillo::Any& value,
brillo::ErrorPtr* error) = 0;