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/exported_object.h" | 5 #include "dbus/exported_object.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 // ExportedObject. | 28 // ExportedObject. |
29 std::string GetAbsoluteMethodName( | 29 std::string GetAbsoluteMethodName( |
30 const std::string& interface_name, | 30 const std::string& interface_name, |
31 const std::string& method_name) { | 31 const std::string& method_name) { |
32 return interface_name + "." + method_name; | 32 return interface_name + "." + method_name; |
33 } | 33 } |
34 | 34 |
35 } // namespace | 35 } // namespace |
36 | 36 |
37 ExportedObject::ExportedObject(Bus* bus, | 37 ExportedObject::ExportedObject(Bus* bus, |
38 const std::string& service_name, | |
39 const ObjectPath& object_path) | 38 const ObjectPath& object_path) |
40 : bus_(bus), | 39 : bus_(bus), |
41 service_name_(service_name), | |
42 object_path_(object_path), | 40 object_path_(object_path), |
43 object_is_registered_(false) { | 41 object_is_registered_(false) { |
44 } | 42 } |
45 | 43 |
46 ExportedObject::~ExportedObject() { | 44 ExportedObject::~ExportedObject() { |
47 DCHECK(!object_is_registered_); | 45 DCHECK(!object_is_registered_); |
48 } | 46 } |
49 | 47 |
50 bool ExportedObject::ExportMethodAndBlock( | 48 bool ExportedObject::ExportMethodAndBlock( |
51 const std::string& interface_name, | 49 const std::string& interface_name, |
52 const std::string& method_name, | 50 const std::string& method_name, |
53 MethodCallCallback method_call_callback) { | 51 MethodCallCallback method_call_callback) { |
54 bus_->AssertOnDBusThread(); | 52 bus_->AssertOnDBusThread(); |
55 | 53 |
56 // Check if the method is already exported. | 54 // Check if the method is already exported. |
57 const std::string absolute_method_name = | 55 const std::string absolute_method_name = |
58 GetAbsoluteMethodName(interface_name, method_name); | 56 GetAbsoluteMethodName(interface_name, method_name); |
59 if (method_table_.find(absolute_method_name) != method_table_.end()) { | 57 if (method_table_.find(absolute_method_name) != method_table_.end()) { |
60 LOG(ERROR) << absolute_method_name << " is already exported"; | 58 LOG(ERROR) << absolute_method_name << " is already exported"; |
61 return false; | 59 return false; |
62 } | 60 } |
63 | 61 |
64 if (!bus_->Connect()) | 62 if (!bus_->Connect()) |
65 return false; | 63 return false; |
66 if (!bus_->SetUpAsyncOperations()) | 64 if (!bus_->SetUpAsyncOperations()) |
67 return false; | 65 return false; |
68 if (!bus_->RequestOwnership(service_name_)) | |
69 return false; | |
70 if (!Register()) | 66 if (!Register()) |
71 return false; | 67 return false; |
72 | 68 |
73 // Add the method callback to the method table. | 69 // Add the method callback to the method table. |
74 method_table_[absolute_method_name] = method_call_callback; | 70 method_table_[absolute_method_name] = method_call_callback; |
75 | 71 |
76 return true; | 72 return true; |
77 } | 73 } |
78 | 74 |
79 void ExportedObject::ExportMethod(const std::string& interface_name, | 75 void ExportedObject::ExportMethod(const std::string& interface_name, |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 return self->HandleMessage(connection, raw_message); | 309 return self->HandleMessage(connection, raw_message); |
314 } | 310 } |
315 | 311 |
316 void ExportedObject::OnUnregisteredThunk(DBusConnection *connection, | 312 void ExportedObject::OnUnregisteredThunk(DBusConnection *connection, |
317 void* user_data) { | 313 void* user_data) { |
318 ExportedObject* self = reinterpret_cast<ExportedObject*>(user_data); | 314 ExportedObject* self = reinterpret_cast<ExportedObject*>(user_data); |
319 return self->OnUnregistered(connection); | 315 return self->OnUnregistered(connection); |
320 } | 316 } |
321 | 317 |
322 } // namespace dbus | 318 } // namespace dbus |
OLD | NEW |