OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "dbus/test_service.h" | 5 #include "dbus/test_service.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/test/test_timeouts.h" | 8 #include "base/test/test_timeouts.h" |
9 #include "base/threading/platform_thread.h" | 9 #include "base/threading/platform_thread.h" |
10 #include "dbus/bus.h" | 10 #include "dbus/bus.h" |
11 #include "dbus/exported_object.h" | 11 #include "dbus/exported_object.h" |
12 #include "dbus/message.h" | 12 #include "dbus/message.h" |
| 13 #include "dbus/object_path.h" |
13 | 14 |
14 namespace dbus { | 15 namespace dbus { |
15 | 16 |
16 // Echo, SlowEcho, AsyncEcho, BrokenMethod. | 17 // Echo, SlowEcho, AsyncEcho, BrokenMethod. |
17 const int TestService::kNumMethodsToExport = 4; | 18 const int TestService::kNumMethodsToExport = 4; |
18 | 19 |
19 TestService::Options::Options() { | 20 TestService::Options::Options() { |
20 } | 21 } |
21 | 22 |
22 TestService::Options::~Options() { | 23 TestService::Options::~Options() { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 } | 90 } |
90 | 91 |
91 void TestService::SendTestSignalFromRootInternal(const std::string& message) { | 92 void TestService::SendTestSignalFromRootInternal(const std::string& message) { |
92 dbus::Signal signal("org.chromium.TestInterface", "Test"); | 93 dbus::Signal signal("org.chromium.TestInterface", "Test"); |
93 dbus::MessageWriter writer(&signal); | 94 dbus::MessageWriter writer(&signal); |
94 writer.AppendString(message); | 95 writer.AppendString(message); |
95 | 96 |
96 // Use "/" just like dbus-send does. | 97 // Use "/" just like dbus-send does. |
97 ExportedObject* root_object = | 98 ExportedObject* root_object = |
98 bus_->GetExportedObject("org.chromium.TestService", | 99 bus_->GetExportedObject("org.chromium.TestService", |
99 "/"); | 100 dbus::ObjectPath("/")); |
100 root_object->SendSignal(&signal); | 101 root_object->SendSignal(&signal); |
101 } | 102 } |
102 | 103 |
103 void TestService::OnExported(const std::string& interface_name, | 104 void TestService::OnExported(const std::string& interface_name, |
104 const std::string& method_name, | 105 const std::string& method_name, |
105 bool success) { | 106 bool success) { |
106 if (!success) { | 107 if (!success) { |
107 LOG(ERROR) << "Failed to export: " << interface_name << "." | 108 LOG(ERROR) << "Failed to export: " << interface_name << "." |
108 << method_name; | 109 << method_name; |
109 // Returning here will make WaitUntilServiceIsStarted() to time out | 110 // Returning here will make WaitUntilServiceIsStarted() to time out |
110 // and return false. | 111 // and return false. |
111 return; | 112 return; |
112 } | 113 } |
113 | 114 |
114 ++num_exported_methods_; | 115 ++num_exported_methods_; |
115 if (num_exported_methods_ == kNumMethodsToExport) | 116 if (num_exported_methods_ == kNumMethodsToExport) |
116 on_all_methods_exported_.Signal(); | 117 on_all_methods_exported_.Signal(); |
117 } | 118 } |
118 | 119 |
119 void TestService::Run(MessageLoop* message_loop) { | 120 void TestService::Run(MessageLoop* message_loop) { |
120 Bus::Options bus_options; | 121 Bus::Options bus_options; |
121 bus_options.bus_type = Bus::SESSION; | 122 bus_options.bus_type = Bus::SESSION; |
122 bus_options.connection_type = Bus::PRIVATE; | 123 bus_options.connection_type = Bus::PRIVATE; |
123 bus_options.dbus_thread_message_loop_proxy = dbus_thread_message_loop_proxy_; | 124 bus_options.dbus_thread_message_loop_proxy = dbus_thread_message_loop_proxy_; |
124 bus_ = new Bus(bus_options); | 125 bus_ = new Bus(bus_options); |
125 | 126 |
126 exported_object_ = bus_->GetExportedObject( | 127 exported_object_ = bus_->GetExportedObject( |
127 "org.chromium.TestService", | 128 "org.chromium.TestService", |
128 "/org/chromium/TestObject"); | 129 dbus::ObjectPath("/org/chromium/TestObject")); |
129 | 130 |
130 int num_methods = 0; | 131 int num_methods = 0; |
131 exported_object_->ExportMethod( | 132 exported_object_->ExportMethod( |
132 "org.chromium.TestInterface", | 133 "org.chromium.TestInterface", |
133 "Echo", | 134 "Echo", |
134 base::Bind(&TestService::Echo, | 135 base::Bind(&TestService::Echo, |
135 base::Unretained(this)), | 136 base::Unretained(this)), |
136 base::Bind(&TestService::OnExported, | 137 base::Bind(&TestService::OnExported, |
137 base::Unretained(this))); | 138 base::Unretained(this))); |
138 ++num_methods; | 139 ++num_methods; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 TestTimeouts::tiny_timeout_ms()); | 207 TestTimeouts::tiny_timeout_ms()); |
207 } | 208 } |
208 | 209 |
209 void TestService::BrokenMethod( | 210 void TestService::BrokenMethod( |
210 MethodCall* method_call, | 211 MethodCall* method_call, |
211 dbus::ExportedObject::ResponseSender response_sender) { | 212 dbus::ExportedObject::ResponseSender response_sender) { |
212 response_sender.Run(NULL); | 213 response_sender.Run(NULL); |
213 } | 214 } |
214 | 215 |
215 } // namespace dbus | 216 } // namespace dbus |
OLD | NEW |