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 #ifndef DBUS_TEST_SERVICE_H_ | 5 #ifndef DBUS_TEST_SERVICE_H_ |
6 #define DBUS_TEST_SERVICE_H_ | 6 #define DBUS_TEST_SERVICE_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 bool HasDBusThread(); | 59 bool HasDBusThread(); |
60 | 60 |
61 // Sends "Test" signal with the given message from the exported object. | 61 // Sends "Test" signal with the given message from the exported object. |
62 void SendTestSignal(const std::string& message); | 62 void SendTestSignal(const std::string& message); |
63 | 63 |
64 // Sends "Test" signal with the given message from the root object ("/"). | 64 // Sends "Test" signal with the given message from the root object ("/"). |
65 // This function emulates dbus-send's behavior. | 65 // This function emulates dbus-send's behavior. |
66 void SendTestSignalFromRoot(const std::string& message); | 66 void SendTestSignalFromRoot(const std::string& message); |
67 | 67 |
68 // Request the ownership of a well-known name "TestService". | 68 // Request the ownership of a well-known name "TestService". |
69 void RequestOwnership(); | 69 // |callback| will be called with the result when an ownership request is |
| 70 // completed. |
| 71 void RequestOwnership(base::Callback<void(bool)> callback); |
| 72 |
| 73 // Returns whether this instance has the name ownership or not. |
| 74 bool has_ownership() const { return has_ownership_; } |
70 | 75 |
71 private: | 76 private: |
72 // Helper function for SendTestSignal(). | 77 // Helper function for SendTestSignal(). |
73 void SendTestSignalInternal(const std::string& message); | 78 void SendTestSignalInternal(const std::string& message); |
74 | 79 |
75 // Helper function for SendTestSignalFromRoot. | 80 // Helper function for SendTestSignalFromRoot. |
76 void SendTestSignalFromRootInternal(const std::string& message); | 81 void SendTestSignalFromRootInternal(const std::string& message); |
77 | 82 |
78 // Helper function for ShutdownAndBlock(). | 83 // Helper function for ShutdownAndBlock(). |
79 void ShutdownAndBlockInternal(); | 84 void ShutdownAndBlockInternal(); |
80 | 85 |
81 // Called when an ownership request is completed. | 86 // Called when an ownership request is completed. |
82 void OnOwnership(const std::string& service_name, | 87 // |callback| is the callback to be called with the result. |service_name| is |
| 88 // the requested well-known bus name. |callback| and |service_name| are bound |
| 89 // when the service requests the ownership. |success| is the result of the |
| 90 // completed request, and is propagated to |callback|. |
| 91 void OnOwnership(base::Callback<void(bool)> callback, |
| 92 const std::string& service_name, |
83 bool success); | 93 bool success); |
84 | 94 |
85 // Called when a method is exported. | 95 // Called when a method is exported. |
86 void OnExported(const std::string& interface_name, | 96 void OnExported(const std::string& interface_name, |
87 const std::string& method_name, | 97 const std::string& method_name, |
88 bool success); | 98 bool success); |
89 | 99 |
90 // base::Thread override. | 100 // base::Thread override. |
91 virtual void Run(MessageLoop* message_loop) OVERRIDE; | 101 virtual void Run(MessageLoop* message_loop) OVERRIDE; |
92 | 102 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 void SetProperty(MethodCall* method_call, | 134 void SetProperty(MethodCall* method_call, |
125 dbus::ExportedObject::ResponseSender response_sender); | 135 dbus::ExportedObject::ResponseSender response_sender); |
126 | 136 |
127 // Sends a property changed signal for the name property. | 137 // Sends a property changed signal for the name property. |
128 void SendPropertyChangedSignal(const std::string& name); | 138 void SendPropertyChangedSignal(const std::string& name); |
129 | 139 |
130 // Helper function for SendPropertyChangedSignal(). | 140 // Helper function for SendPropertyChangedSignal(). |
131 void SendPropertyChangedSignalInternal(const std::string& name); | 141 void SendPropertyChangedSignalInternal(const std::string& name); |
132 | 142 |
133 // Helper function for RequestOwnership(). | 143 // Helper function for RequestOwnership(). |
134 void RequestOwnershipInternal(); | 144 void RequestOwnershipInternal(base::Callback<void(bool)> callback); |
135 | 145 |
136 scoped_refptr<base::MessageLoopProxy> dbus_thread_message_loop_proxy_; | 146 scoped_refptr<base::MessageLoopProxy> dbus_thread_message_loop_proxy_; |
137 base::WaitableEvent on_all_methods_exported_; | 147 base::WaitableEvent on_all_methods_exported_; |
138 // The number of methods actually exported. | 148 // The number of methods actually exported. |
139 int num_exported_methods_; | 149 int num_exported_methods_; |
140 | 150 |
| 151 // True iff this instance has successfully acquired the name ownership. |
| 152 bool has_ownership_; |
| 153 |
141 scoped_refptr<Bus> bus_; | 154 scoped_refptr<Bus> bus_; |
142 ExportedObject* exported_object_; | 155 ExportedObject* exported_object_; |
143 }; | 156 }; |
144 | 157 |
145 } // namespace dbus | 158 } // namespace dbus |
146 | 159 |
147 #endif // DBUS_TEST_SERVICE_H_ | 160 #endif // DBUS_TEST_SERVICE_H_ |
OLD | NEW |