| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_OBJECT_PROXY_H_ | 5 #ifndef DBUS_OBJECT_PROXY_H_ |
| 6 #define DBUS_OBJECT_PROXY_H_ | 6 #define DBUS_OBJECT_PROXY_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 #include <dbus/dbus.h> | 12 #include <dbus/dbus.h> |
| 13 | 13 |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/time.h" |
| 16 | 17 |
| 17 class MessageLoop; | 18 class MessageLoop; |
| 18 | 19 |
| 19 namespace dbus { | 20 namespace dbus { |
| 20 | 21 |
| 21 class Bus; | 22 class Bus; |
| 22 class MethodCall; | 23 class MethodCall; |
| 23 class Response; | 24 class Response; |
| 24 class Signal; | 25 class Signal; |
| 25 | 26 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 // This is protected, so we can define sub classes. | 110 // This is protected, so we can define sub classes. |
| 110 virtual ~ObjectProxy(); | 111 virtual ~ObjectProxy(); |
| 111 | 112 |
| 112 private: | 113 private: |
| 113 friend class base::RefCountedThreadSafe<ObjectProxy>; | 114 friend class base::RefCountedThreadSafe<ObjectProxy>; |
| 114 | 115 |
| 115 // Struct of data we'll be passing from StartAsyncMethodCall() to | 116 // Struct of data we'll be passing from StartAsyncMethodCall() to |
| 116 // OnPendingCallIsCompleteThunk(). | 117 // OnPendingCallIsCompleteThunk(). |
| 117 struct OnPendingCallIsCompleteData { | 118 struct OnPendingCallIsCompleteData { |
| 118 OnPendingCallIsCompleteData(ObjectProxy* in_object_proxy, | 119 OnPendingCallIsCompleteData(ObjectProxy* in_object_proxy, |
| 119 ResponseCallback in_response_callback); | 120 ResponseCallback in_response_callback, |
| 121 base::TimeTicks start_time); |
| 120 ~OnPendingCallIsCompleteData(); | 122 ~OnPendingCallIsCompleteData(); |
| 121 | 123 |
| 122 ObjectProxy* object_proxy; | 124 ObjectProxy* object_proxy; |
| 123 ResponseCallback response_callback; | 125 ResponseCallback response_callback; |
| 126 base::TimeTicks start_time; |
| 124 }; | 127 }; |
| 125 | 128 |
| 126 // Starts the async method call. This is a helper function to implement | 129 // Starts the async method call. This is a helper function to implement |
| 127 // CallMethod(). | 130 // CallMethod(). |
| 128 void StartAsyncMethodCall(int timeout_ms, | 131 void StartAsyncMethodCall(int timeout_ms, |
| 129 void* request_message, | 132 void* request_message, |
| 130 ResponseCallback response_callback); | 133 ResponseCallback response_callback, |
| 134 base::TimeTicks start_time); |
| 131 | 135 |
| 132 // Called when the pending call is complete. | 136 // Called when the pending call is complete. |
| 133 void OnPendingCallIsComplete(DBusPendingCall* pending_call, | 137 void OnPendingCallIsComplete(DBusPendingCall* pending_call, |
| 134 ResponseCallback response_callback); | 138 ResponseCallback response_callback, |
| 139 base::TimeTicks start_time); |
| 135 | 140 |
| 136 // Runs the response callback with the given response object. | 141 // Runs the response callback with the given response object. |
| 137 void RunResponseCallback(ResponseCallback response_callback, | 142 void RunResponseCallback(ResponseCallback response_callback, |
| 143 base::TimeTicks start_time, |
| 138 void* response_message); | 144 void* response_message); |
| 139 | 145 |
| 140 // Redirects the function call to OnPendingCallIsComplete(). | 146 // Redirects the function call to OnPendingCallIsComplete(). |
| 141 static void OnPendingCallIsCompleteThunk(DBusPendingCall* pending_call, | 147 static void OnPendingCallIsCompleteThunk(DBusPendingCall* pending_call, |
| 142 void* user_data); | 148 void* user_data); |
| 143 | 149 |
| 144 // Helper function for ConnectToSignal(). | 150 // Helper function for ConnectToSignal(). |
| 145 void ConnectToSignalInternal( | 151 void ConnectToSignalInternal( |
| 146 const std::string& interface_name, | 152 const std::string& interface_name, |
| 147 const std::string& signal_name, | 153 const std::string& signal_name, |
| 148 SignalCallback signal_callback, | 154 SignalCallback signal_callback, |
| 149 OnConnectedCallback on_connected_callback); | 155 OnConnectedCallback on_connected_callback); |
| 150 | 156 |
| 151 // Called when the object proxy is connected to the signal, or failed. | 157 // Called when the object proxy is connected to the signal, or failed. |
| 152 void OnConnected(OnConnectedCallback on_connected_callback, | 158 void OnConnected(OnConnectedCallback on_connected_callback, |
| 153 const std::string& interface_name, | 159 const std::string& interface_name, |
| 154 const std::string& signal_name, | 160 const std::string& signal_name, |
| 155 bool success); | 161 bool success); |
| 156 | 162 |
| 157 // Handles the incoming request messages and dispatches to the signal | 163 // Handles the incoming request messages and dispatches to the signal |
| 158 // callbacks. | 164 // callbacks. |
| 159 DBusHandlerResult HandleMessage(DBusConnection* connection, | 165 DBusHandlerResult HandleMessage(DBusConnection* connection, |
| 160 DBusMessage* raw_message); | 166 DBusMessage* raw_message); |
| 161 | 167 |
| 162 // Runs the method. Helper function for HandleMessage(). | 168 // Runs the method. Helper function for HandleMessage(). |
| 163 void RunMethod(SignalCallback signal_callback, Signal* signal); | 169 void RunMethod(base::TimeTicks start_time, |
| 170 SignalCallback signal_callback, |
| 171 Signal* signal); |
| 164 | 172 |
| 165 // Redirects the function call to HandleMessage(). | 173 // Redirects the function call to HandleMessage(). |
| 166 static DBusHandlerResult HandleMessageThunk(DBusConnection* connection, | 174 static DBusHandlerResult HandleMessageThunk(DBusConnection* connection, |
| 167 DBusMessage* raw_message, | 175 DBusMessage* raw_message, |
| 168 void* user_data); | 176 void* user_data); |
| 169 | 177 |
| 170 Bus* bus_; | 178 Bus* bus_; |
| 171 std::string service_name_; | 179 std::string service_name_; |
| 172 std::string object_path_; | 180 std::string object_path_; |
| 173 | 181 |
| 174 // True if the message filter was added. | 182 // True if the message filter was added. |
| 175 bool filter_added_; | 183 bool filter_added_; |
| 176 | 184 |
| 177 // The method table where keys are absolute signal names (i.e. interface | 185 // The method table where keys are absolute signal names (i.e. interface |
| 178 // name + signal name), and values are the corresponding callbacks. | 186 // name + signal name), and values are the corresponding callbacks. |
| 179 typedef std::map<std::string, SignalCallback> MethodTable; | 187 typedef std::map<std::string, SignalCallback> MethodTable; |
| 180 MethodTable method_table_; | 188 MethodTable method_table_; |
| 181 | 189 |
| 182 std::vector<std::string> match_rules_; | 190 std::vector<std::string> match_rules_; |
| 183 | 191 |
| 184 DISALLOW_COPY_AND_ASSIGN(ObjectProxy); | 192 DISALLOW_COPY_AND_ASSIGN(ObjectProxy); |
| 185 }; | 193 }; |
| 186 | 194 |
| 187 } // namespace dbus | 195 } // namespace dbus |
| 188 | 196 |
| 189 #endif // DBUS_OBJECT_PROXY_H_ | 197 #endif // DBUS_OBJECT_PROXY_H_ |
| OLD | NEW |