Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(230)

Side by Side Diff: chromeos/dbus/dbus.h

Issue 2842019: Allowed to construct a dbus::BusConnection object with NULL g_connection (Closed) Base URL: ssh://git@gitrw.chromium.org//common.git
Patch Set: fixed Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chromeos/dbus/dbus.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 16 matching lines...) Expand all
27 // bus. 27 // bus.
28 // 28 //
29 // \models Copyable, Assignable 29 // \models Copyable, Assignable
30 // \related GetSystemBusConnection() 30 // \related GetSystemBusConnection()
31 31
32 class BusConnection { 32 class BusConnection {
33 public: 33 public:
34 typedef ::DBusGConnection* value_type; 34 typedef ::DBusGConnection* value_type;
35 35
36 BusConnection(const BusConnection& x) 36 BusConnection(const BusConnection& x)
37 : object_(dbus_g_connection_ref(x.object_)) { 37 : object_(x.object_) {
38 if (object_)
39 ::dbus_g_connection_ref(object_);
38 } 40 }
39 41
40 ~BusConnection() { 42 ~BusConnection() {
41 ::dbus_g_connection_unref(object_); 43 if (object_)
44 ::dbus_g_connection_unref(object_);
42 } 45 }
43 46
44 BusConnection& operator=(BusConnection x) { 47 BusConnection& operator=(BusConnection x) {
45 swap(*this, x); 48 swap(*this, x);
46 return *this; 49 return *this;
47 } 50 }
48 51
49 const value_type& g_connection() const { 52 const value_type& g_connection() const {
50 DCHECK(object_) << "referencing an empty connection"; 53 DCHECK(object_) << "referencing an empty connection";
51 return object_; 54 return object_;
52 } 55 }
53 56
57 operator bool() const {
58 return object_;
59 }
60
61 bool HasConnection() const {
62 return object_;
63 }
64
54 private: 65 private:
55 friend void swap(BusConnection& x, BusConnection& y); 66 friend void swap(BusConnection& x, BusConnection& y);
56 67
57 friend class Proxy; 68 friend class Proxy;
58 friend BusConnection GetSystemBusConnection(); 69 friend BusConnection GetSystemBusConnection();
59 friend BusConnection GetPrivateBusConnection(const char* address); 70 friend BusConnection GetPrivateBusConnection(const char* address);
60 71
61 // Constructor takes ownership 72 // Constructor takes ownership
62 explicit BusConnection(::DBusGConnection* x) 73 explicit BusConnection(::DBusGConnection* x)
63 : object_(x) { 74 : object_(x) {
64 DCHECK(object_) << "Constructing BusConnection with NULL object.";
65 } 75 }
66 76
67 value_type object_; 77 value_type object_;
68 }; 78 };
69 79
70 inline void swap(BusConnection& x, BusConnection& y) { 80 inline void swap(BusConnection& x, BusConnection& y) {
71 std::swap(x.object_, y.object_); 81 std::swap(x.object_, y.object_);
72 } 82 }
73 83
74 // \brief Proxy manages the ref-count for a ::DBusGProxy*. 84 // \brief Proxy manages the ref-count for a ::DBusGProxy*.
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 BusConnection GetSystemBusConnection(); 360 BusConnection GetSystemBusConnection();
351 361
352 // \brief Returns a private connection to a bus at |address|. 362 // \brief Returns a private connection to a bus at |address|.
353 363
354 BusConnection GetPrivateBusConnection(const char* address); 364 BusConnection GetPrivateBusConnection(const char* address);
355 365
356 } // namespace dbus 366 } // namespace dbus
357 } // namespace chromeos 367 } // namespace chromeos
358 368
359 #endif // CHROMEOS_DBUS_H_ 369 #endif // CHROMEOS_DBUS_H_
OLDNEW
« no previous file with comments | « no previous file | chromeos/dbus/dbus.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698