| 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_manager.h" | 13 #include "dbus/object_manager.h" | 
| 14 #include "dbus/object_path.h" | 14 #include "dbus/object_path.h" | 
| 15 #include "dbus/property.h" | 15 #include "dbus/property.h" | 
| 16 | 16 | 
| 17 namespace { | 17 namespace { | 
| 18 | 18 | 
| 19 void EmptyCallback(bool /* success */) { | 19 void EmptyCallback(bool /* success */) { | 
| 20 } | 20 } | 
| 21 | 21 | 
| 22 }  // namespace | 22 }  // namespace | 
| 23 | 23 | 
| 24 namespace dbus { | 24 namespace dbus { | 
| 25 | 25 | 
| 26 // Echo, SlowEcho, AsyncEcho, BrokenMethod, GetAll, Get, Set, PerformAction, | 26 // Echo, SlowEcho, AsyncEcho, BrokenMethod, GetAll, Get, Set, PerformAction, | 
| 27 // GetManagedObjects. | 27 // GetManagedObjects. | 
| 28 const int TestService::kNumMethodsToExport = 9; | 28 const int TestService::kNumMethodsToExport = 9; | 
| 29 | 29 | 
| 30 TestService::Options::Options() { | 30 TestService::Options::Options() | 
|  | 31     : request_ownership_options(Bus::REQUIRE_PRIMARY) { | 
| 31 } | 32 } | 
| 32 | 33 | 
| 33 TestService::Options::~Options() { | 34 TestService::Options::~Options() { | 
| 34 } | 35 } | 
| 35 | 36 | 
| 36 TestService::TestService(const Options& options) | 37 TestService::TestService(const Options& options) | 
| 37     : base::Thread("TestService"), | 38     : base::Thread("TestService"), | 
|  | 39       request_ownership_options_(options.request_ownership_options), | 
| 38       dbus_task_runner_(options.dbus_task_runner), | 40       dbus_task_runner_(options.dbus_task_runner), | 
| 39       on_all_methods_exported_(false, false), | 41       on_all_methods_exported_(false, false), | 
| 40       num_exported_methods_(0) { | 42       num_exported_methods_(0) { | 
| 41 } | 43 } | 
| 42 | 44 | 
| 43 TestService::~TestService() { | 45 TestService::~TestService() { | 
| 44   Stop(); | 46   Stop(); | 
| 45 } | 47 } | 
| 46 | 48 | 
| 47 bool TestService::StartService() { | 49 bool TestService::StartService() { | 
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 96   writer.AppendString(message); | 98   writer.AppendString(message); | 
| 97   exported_object_->SendSignal(&signal); | 99   exported_object_->SendSignal(&signal); | 
| 98 } | 100 } | 
| 99 | 101 | 
| 100 void TestService::SendTestSignalFromRootInternal(const std::string& message) { | 102 void TestService::SendTestSignalFromRootInternal(const std::string& message) { | 
| 101   Signal signal("org.chromium.TestInterface", "Test"); | 103   Signal signal("org.chromium.TestInterface", "Test"); | 
| 102   MessageWriter writer(&signal); | 104   MessageWriter writer(&signal); | 
| 103   writer.AppendString(message); | 105   writer.AppendString(message); | 
| 104 | 106 | 
| 105   bus_->RequestOwnership("org.chromium.TestService", | 107   bus_->RequestOwnership("org.chromium.TestService", | 
|  | 108                          request_ownership_options_, | 
| 106                          base::Bind(&TestService::OnOwnership, | 109                          base::Bind(&TestService::OnOwnership, | 
| 107                                     base::Unretained(this), | 110                                     base::Unretained(this), | 
| 108                                     base::Bind(&EmptyCallback))); | 111                                     base::Bind(&EmptyCallback))); | 
| 109 | 112 | 
| 110   // Use "/" just like dbus-send does. | 113   // Use "/" just like dbus-send does. | 
| 111   ExportedObject* root_object = bus_->GetExportedObject(ObjectPath("/")); | 114   ExportedObject* root_object = bus_->GetExportedObject(ObjectPath("/")); | 
| 112   root_object->SendSignal(&signal); | 115   root_object->SendSignal(&signal); | 
| 113 } | 116 } | 
| 114 | 117 | 
| 115 void TestService::RequestOwnership(base::Callback<void(bool)> callback) { | 118 void TestService::RequestOwnership(base::Callback<void(bool)> callback) { | 
| 116   message_loop()->PostTask( | 119   message_loop()->PostTask( | 
| 117       FROM_HERE, | 120       FROM_HERE, | 
| 118       base::Bind(&TestService::RequestOwnershipInternal, | 121       base::Bind(&TestService::RequestOwnershipInternal, | 
| 119                  base::Unretained(this), | 122                  base::Unretained(this), | 
| 120                  callback)); | 123                  callback)); | 
| 121 } | 124 } | 
| 122 | 125 | 
| 123 void TestService::RequestOwnershipInternal( | 126 void TestService::RequestOwnershipInternal( | 
| 124     base::Callback<void(bool)> callback) { | 127     base::Callback<void(bool)> callback) { | 
| 125   bus_->RequestOwnership("org.chromium.TestService", | 128   bus_->RequestOwnership("org.chromium.TestService", | 
|  | 129                          request_ownership_options_, | 
| 126                          base::Bind(&TestService::OnOwnership, | 130                          base::Bind(&TestService::OnOwnership, | 
| 127                                     base::Unretained(this), | 131                                     base::Unretained(this), | 
| 128                                     callback)); | 132                                     callback)); | 
| 129 } | 133 } | 
| 130 | 134 | 
| 131 void TestService::OnOwnership(base::Callback<void(bool)> callback, | 135 void TestService::OnOwnership(base::Callback<void(bool)> callback, | 
| 132                               const std::string& service_name, | 136                               const std::string& service_name, | 
| 133                               bool success) { | 137                               bool success) { | 
| 134   has_ownership_ = success; | 138   has_ownership_ = success; | 
| 135   LOG_IF(ERROR, !success) << "Failed to own: " << service_name; | 139   LOG_IF(ERROR, !success) << "Failed to own: " << service_name; | 
| (...skipping 17 matching lines...) Expand all  Loading... | 
| 153 } | 157 } | 
| 154 | 158 | 
| 155 void TestService::Run(base::MessageLoop* message_loop) { | 159 void TestService::Run(base::MessageLoop* message_loop) { | 
| 156   Bus::Options bus_options; | 160   Bus::Options bus_options; | 
| 157   bus_options.bus_type = Bus::SESSION; | 161   bus_options.bus_type = Bus::SESSION; | 
| 158   bus_options.connection_type = Bus::PRIVATE; | 162   bus_options.connection_type = Bus::PRIVATE; | 
| 159   bus_options.dbus_task_runner = dbus_task_runner_; | 163   bus_options.dbus_task_runner = dbus_task_runner_; | 
| 160   bus_ = new Bus(bus_options); | 164   bus_ = new Bus(bus_options); | 
| 161 | 165 | 
| 162   bus_->RequestOwnership("org.chromium.TestService", | 166   bus_->RequestOwnership("org.chromium.TestService", | 
|  | 167                          request_ownership_options_, | 
| 163                          base::Bind(&TestService::OnOwnership, | 168                          base::Bind(&TestService::OnOwnership, | 
| 164                                     base::Unretained(this), | 169                                     base::Unretained(this), | 
| 165                                     base::Bind(&EmptyCallback))); | 170                                     base::Bind(&EmptyCallback))); | 
| 166 | 171 | 
| 167   exported_object_ = bus_->GetExportedObject( | 172   exported_object_ = bus_->GetExportedObject( | 
| 168       ObjectPath("/org/chromium/TestObject")); | 173       ObjectPath("/org/chromium/TestObject")); | 
| 169 | 174 | 
| 170   int num_methods = 0; | 175   int num_methods = 0; | 
| 171   exported_object_->ExportMethod( | 176   exported_object_->ExportMethod( | 
| 172       "org.chromium.TestInterface", | 177       "org.chromium.TestInterface", | 
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 602   array_writer.OpenDictEntry(&dict_entry_writer); | 607   array_writer.OpenDictEntry(&dict_entry_writer); | 
| 603   dict_entry_writer.AppendString("Name"); | 608   dict_entry_writer.AppendString("Name"); | 
| 604   dict_entry_writer.AppendVariantOfString(name); | 609   dict_entry_writer.AppendVariantOfString(name); | 
| 605   array_writer.CloseContainer(&dict_entry_writer); | 610   array_writer.CloseContainer(&dict_entry_writer); | 
| 606   writer.CloseContainer(&array_writer); | 611   writer.CloseContainer(&array_writer); | 
| 607 | 612 | 
| 608   exported_object_->SendSignal(&signal); | 613   exported_object_->SendSignal(&signal); | 
| 609 } | 614 } | 
| 610 | 615 | 
| 611 }  // namespace dbus | 616 }  // namespace dbus | 
| OLD | NEW | 
|---|