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" | |
14 | 13 |
15 namespace dbus { | 14 namespace dbus { |
16 | 15 |
17 // Echo, SlowEcho, AsyncEcho, BrokenMethod. | 16 // Echo, SlowEcho, AsyncEcho, BrokenMethod. |
18 const int TestService::kNumMethodsToExport = 4; | 17 const int TestService::kNumMethodsToExport = 4; |
19 | 18 |
20 TestService::Options::Options() { | 19 TestService::Options::Options() { |
21 } | 20 } |
22 | 21 |
23 TestService::Options::~Options() { | 22 TestService::Options::~Options() { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 } | 89 } |
91 | 90 |
92 void TestService::SendTestSignalFromRootInternal(const std::string& message) { | 91 void TestService::SendTestSignalFromRootInternal(const std::string& message) { |
93 dbus::Signal signal("org.chromium.TestInterface", "Test"); | 92 dbus::Signal signal("org.chromium.TestInterface", "Test"); |
94 dbus::MessageWriter writer(&signal); | 93 dbus::MessageWriter writer(&signal); |
95 writer.AppendString(message); | 94 writer.AppendString(message); |
96 | 95 |
97 // Use "/" just like dbus-send does. | 96 // Use "/" just like dbus-send does. |
98 ExportedObject* root_object = | 97 ExportedObject* root_object = |
99 bus_->GetExportedObject("org.chromium.TestService", | 98 bus_->GetExportedObject("org.chromium.TestService", |
100 dbus::ObjectPath("/")); | 99 "/"); |
101 root_object->SendSignal(&signal); | 100 root_object->SendSignal(&signal); |
102 } | 101 } |
103 | 102 |
104 void TestService::OnExported(const std::string& interface_name, | 103 void TestService::OnExported(const std::string& interface_name, |
105 const std::string& method_name, | 104 const std::string& method_name, |
106 bool success) { | 105 bool success) { |
107 if (!success) { | 106 if (!success) { |
108 LOG(ERROR) << "Failed to export: " << interface_name << "." | 107 LOG(ERROR) << "Failed to export: " << interface_name << "." |
109 << method_name; | 108 << method_name; |
110 // Returning here will make WaitUntilServiceIsStarted() to time out | 109 // Returning here will make WaitUntilServiceIsStarted() to time out |
111 // and return false. | 110 // and return false. |
112 return; | 111 return; |
113 } | 112 } |
114 | 113 |
115 ++num_exported_methods_; | 114 ++num_exported_methods_; |
116 if (num_exported_methods_ == kNumMethodsToExport) | 115 if (num_exported_methods_ == kNumMethodsToExport) |
117 on_all_methods_exported_.Signal(); | 116 on_all_methods_exported_.Signal(); |
118 } | 117 } |
119 | 118 |
120 void TestService::Run(MessageLoop* message_loop) { | 119 void TestService::Run(MessageLoop* message_loop) { |
121 Bus::Options bus_options; | 120 Bus::Options bus_options; |
122 bus_options.bus_type = Bus::SESSION; | 121 bus_options.bus_type = Bus::SESSION; |
123 bus_options.connection_type = Bus::PRIVATE; | 122 bus_options.connection_type = Bus::PRIVATE; |
124 bus_options.dbus_thread_message_loop_proxy = dbus_thread_message_loop_proxy_; | 123 bus_options.dbus_thread_message_loop_proxy = dbus_thread_message_loop_proxy_; |
125 bus_ = new Bus(bus_options); | 124 bus_ = new Bus(bus_options); |
126 | 125 |
127 exported_object_ = bus_->GetExportedObject( | 126 exported_object_ = bus_->GetExportedObject( |
128 "org.chromium.TestService", | 127 "org.chromium.TestService", |
129 dbus::ObjectPath("/org/chromium/TestObject")); | 128 "/org/chromium/TestObject"); |
130 | 129 |
131 int num_methods = 0; | 130 int num_methods = 0; |
132 exported_object_->ExportMethod( | 131 exported_object_->ExportMethod( |
133 "org.chromium.TestInterface", | 132 "org.chromium.TestInterface", |
134 "Echo", | 133 "Echo", |
135 base::Bind(&TestService::Echo, | 134 base::Bind(&TestService::Echo, |
136 base::Unretained(this)), | 135 base::Unretained(this)), |
137 base::Bind(&TestService::OnExported, | 136 base::Bind(&TestService::OnExported, |
138 base::Unretained(this))); | 137 base::Unretained(this))); |
139 ++num_methods; | 138 ++num_methods; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 TestTimeouts::tiny_timeout_ms()); | 206 TestTimeouts::tiny_timeout_ms()); |
208 } | 207 } |
209 | 208 |
210 void TestService::BrokenMethod( | 209 void TestService::BrokenMethod( |
211 MethodCall* method_call, | 210 MethodCall* method_call, |
212 dbus::ExportedObject::ResponseSender response_sender) { | 211 dbus::ExportedObject::ResponseSender response_sender) { |
213 response_sender.Run(NULL); | 212 response_sender.Run(NULL); |
214 } | 213 } |
215 | 214 |
216 } // namespace dbus | 215 } // namespace dbus |
OLD | NEW |