OLD | NEW |
1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium OS 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 CHROMEOS_DBUS_H_ | 5 #ifndef CHROMEOS_DBUS_H_ |
6 #define CHROMEOS_DBUS_H_ | 6 #define CHROMEOS_DBUS_H_ |
7 | 7 |
8 #include <dbus/dbus-glib.h> | 8 #include <dbus/dbus-glib.h> |
9 #include <glib-object.h> | 9 #include <glib-object.h> |
10 | 10 |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 } | 240 } |
241 | 241 |
242 private: | 242 private: |
243 Proxy proxy_; | 243 Proxy proxy_; |
244 std::string name_; | 244 std::string name_; |
245 void (*monitor_)(void*, A1, A2); | 245 void (*monitor_)(void*, A1, A2); |
246 void* object_; | 246 void* object_; |
247 | 247 |
248 }; | 248 }; |
249 | 249 |
| 250 template <typename A1, typename A2, typename A3> |
| 251 class MonitorConnection<void (A1, A2, A3)> { |
| 252 public: |
| 253 MonitorConnection(const Proxy& proxy, const char* name, |
| 254 void (*monitor)(void*, A1, A2, A3), void* object) |
| 255 : proxy_(proxy), name_(name), monitor_(monitor), object_(object) { |
| 256 } |
| 257 |
| 258 static void Run(::DBusGProxy*, A1 x, A2 y, A3 z, MonitorConnection* self) { |
| 259 self->monitor_(self->object_, x, y, z); |
| 260 } |
| 261 const Proxy& proxy() const { |
| 262 return proxy_; |
| 263 } |
| 264 const std::string& name() const { |
| 265 return name_; |
| 266 } |
| 267 |
| 268 private: |
| 269 Proxy proxy_; |
| 270 std::string name_; |
| 271 void (*monitor_)(void*, A1, A2, A3); |
| 272 void* object_; |
| 273 |
| 274 }; |
| 275 |
250 template <typename A1> | 276 template <typename A1> |
251 MonitorConnection<void (A1)>* Monitor(const Proxy& proxy, const char* name, | 277 MonitorConnection<void (A1)>* Monitor(const Proxy& proxy, const char* name, |
252 void (*monitor)(void*, A1), | 278 void (*monitor)(void*, A1), |
253 void* object) { | 279 void* object) { |
254 typedef MonitorConnection<void (A1)> ConnectionType; | 280 typedef MonitorConnection<void (A1)> ConnectionType; |
255 | 281 |
256 ConnectionType* result = new ConnectionType(proxy, name, monitor, object); | 282 ConnectionType* result = new ConnectionType(proxy, name, monitor, object); |
257 | 283 |
258 ::dbus_g_proxy_add_signal(proxy.gproxy(), name, | 284 ::dbus_g_proxy_add_signal(proxy.gproxy(), name, |
259 glib::type_to_gtypeid<A1>(), G_TYPE_INVALID); | 285 glib::type_to_gtypeid<A1>(), G_TYPE_INVALID); |
(...skipping 14 matching lines...) Expand all Loading... |
274 ::dbus_g_proxy_add_signal(proxy.gproxy(), name, | 300 ::dbus_g_proxy_add_signal(proxy.gproxy(), name, |
275 glib::type_to_gtypeid<A1>(), | 301 glib::type_to_gtypeid<A1>(), |
276 glib::type_to_gtypeid<A2>(), | 302 glib::type_to_gtypeid<A2>(), |
277 G_TYPE_INVALID); | 303 G_TYPE_INVALID); |
278 ::dbus_g_proxy_connect_signal(proxy.gproxy(), name, | 304 ::dbus_g_proxy_connect_signal(proxy.gproxy(), name, |
279 G_CALLBACK(&ConnectionType::Run), | 305 G_CALLBACK(&ConnectionType::Run), |
280 result, NULL); | 306 result, NULL); |
281 return result; | 307 return result; |
282 } | 308 } |
283 | 309 |
| 310 template <typename A1, typename A2, typename A3> |
| 311 MonitorConnection<void (A1, A2, A3)>* Monitor(const Proxy& proxy, |
| 312 const char* name, |
| 313 void (*monitor)(void*, A1, A2, A3), |
| 314 void* object) { |
| 315 typedef MonitorConnection<void (A1, A2, A3)> ConnectionType; |
| 316 |
| 317 ConnectionType* result = new ConnectionType(proxy, name, monitor, object); |
| 318 |
| 319 ::dbus_g_proxy_add_signal(proxy.gproxy(), name, |
| 320 glib::type_to_gtypeid<A1>(), |
| 321 glib::type_to_gtypeid<A2>(), |
| 322 glib::type_to_gtypeid<A3>(), |
| 323 G_TYPE_INVALID); |
| 324 ::dbus_g_proxy_connect_signal(proxy.gproxy(), name, |
| 325 G_CALLBACK(&ConnectionType::Run), |
| 326 result, NULL); |
| 327 return result; |
| 328 } |
| 329 |
284 template <typename F> | 330 template <typename F> |
285 void Disconnect(MonitorConnection<F>* connection) { | 331 void Disconnect(MonitorConnection<F>* connection) { |
286 typedef MonitorConnection<F> ConnectionType; | 332 typedef MonitorConnection<F> ConnectionType; |
287 | 333 |
288 ::dbus_g_proxy_disconnect_signal(connection->proxy().gproxy(), | 334 ::dbus_g_proxy_disconnect_signal(connection->proxy().gproxy(), |
289 connection->name().c_str(), | 335 connection->name().c_str(), |
290 G_CALLBACK(&ConnectionType::Run), | 336 G_CALLBACK(&ConnectionType::Run), |
291 connection); | 337 connection); |
292 delete connection; | 338 delete connection; |
293 } | 339 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 BusConnection GetSystemBusConnection(); | 406 BusConnection GetSystemBusConnection(); |
361 | 407 |
362 // \brief Returns a private connection to a bus at |address|. | 408 // \brief Returns a private connection to a bus at |address|. |
363 | 409 |
364 BusConnection GetPrivateBusConnection(const char* address); | 410 BusConnection GetPrivateBusConnection(const char* address); |
365 | 411 |
366 } // namespace dbus | 412 } // namespace dbus |
367 } // namespace chromeos | 413 } // namespace chromeos |
368 | 414 |
369 #endif // CHROMEOS_DBUS_H_ | 415 #endif // CHROMEOS_DBUS_H_ |
OLD | NEW |