@@ -15,6 +15,12 @@ var Interface = module.exports = function(bus, serviceName, objectPath, interfac
15
15
16
16
util . inherits ( Interface , events . EventEmitter ) ;
17
17
18
+ Object . defineProperty ( Interface . prototype , 'connected' , {
19
+ get : function ( ) {
20
+ return this . bus . connected ;
21
+ }
22
+ } ) ;
23
+
18
24
Interface . prototype . init = function ( callback ) {
19
25
var self = this ;
20
26
@@ -48,6 +54,10 @@ Interface.prototype.init = function(callback) {
48
54
var error = this [ method ] . error || null
49
55
50
56
process . nextTick ( function ( ) {
57
+ if ( ! self . connected ) {
58
+ callback ( new Error ( 'Bus is no longer connected' ) ) ;
59
+ return ;
60
+ }
51
61
52
62
try {
53
63
self . bus . dbus . callMethod ( self . bus . connection ,
@@ -90,6 +100,13 @@ Interface.prototype.init = function(callback) {
90
100
Interface . prototype . setProperty = function ( propertyName , value , callback ) {
91
101
var self = this ;
92
102
103
+ if ( ! self . connected ) {
104
+ process . nextTick ( function ( ) {
105
+ callback ( new Error ( 'Bus is no longer connected' ) ) ;
106
+ } ) ;
107
+ return ;
108
+ }
109
+
93
110
self . bus . dbus . callMethod ( self . bus . connection ,
94
111
self . serviceName ,
95
112
self . objectPath ,
@@ -108,6 +125,13 @@ Interface.prototype.setProperty = function(propertyName, value, callback) {
108
125
Interface . prototype . getProperty = function ( propertyName , callback ) {
109
126
var self = this ;
110
127
128
+ if ( ! self . connected ) {
129
+ process . nextTick ( function ( ) {
130
+ callback ( new Error ( 'Bus is no longer connected' ) ) ;
131
+ } ) ;
132
+ return ;
133
+ }
134
+
111
135
self . bus . dbus . callMethod ( self . bus . connection ,
112
136
self . serviceName ,
113
137
self . objectPath ,
@@ -126,6 +150,13 @@ Interface.prototype.getProperty = function(propertyName, callback) {
126
150
Interface . prototype . getProperties = function ( callback ) {
127
151
var self = this ;
128
152
153
+ if ( ! self . connected ) {
154
+ process . nextTick ( function ( ) {
155
+ callback ( new Error ( 'Bus is no longer connected' ) ) ;
156
+ } ) ;
157
+ return ;
158
+ }
159
+
129
160
self . bus . dbus . callMethod ( self . bus . connection ,
130
161
self . serviceName ,
131
162
self . objectPath ,
0 commit comments