This source file includes following definitions.
- CallMethodAndBlockInternal
- on_blocking_method_call_
- CallMethodAndBlock
#include "chromeos/dbus/blocking_method_caller.h"
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/location.h"
#include "base/task_runner.h"
#include "base/threading/thread_restrictions.h"
#include "dbus/bus.h"
#include "dbus/object_proxy.h"
namespace chromeos {
namespace {
void CallMethodAndBlockInternal(
scoped_ptr<dbus::Response>* response,
base::ScopedClosureRunner* signaler,
dbus::ObjectProxy* proxy,
dbus::MethodCall* method_call) {
*response = proxy->CallMethodAndBlock(
method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT);
}
}
BlockingMethodCaller::BlockingMethodCaller(dbus::Bus* bus,
dbus::ObjectProxy* proxy)
: bus_(bus),
proxy_(proxy),
on_blocking_method_call_(false ,
false ) {
}
BlockingMethodCaller::~BlockingMethodCaller() {
}
scoped_ptr<dbus::Response> BlockingMethodCaller::CallMethodAndBlock(
dbus::MethodCall* method_call) {
base::Closure signal_task(
base::Bind(&base::WaitableEvent::Signal,
base::Unretained(&on_blocking_method_call_)));
base::ScopedClosureRunner* signaler =
new base::ScopedClosureRunner(signal_task);
scoped_ptr<dbus::Response> response;
bus_->GetDBusTaskRunner()->PostTask(
FROM_HERE,
base::Bind(&CallMethodAndBlockInternal,
&response,
base::Owned(signaler),
base::Unretained(proxy_),
method_call));
base::ThreadRestrictions::ScopedAllowWait allow_wait;
on_blocking_method_call_.Wait();
return response.Pass();
}
}