Skip to content

Commit fe5fadb

Browse files
committed
Change DBus entry points to be static
The DBus class does not really have any usable instance data, so from an API perspective, it doesn't make much sense to create an instance of DBus just so that we can create an instance of Bus or Service. So instead, make `getBus` and `registerService` static methods that can be called directly, without instantiating a DBus instance first. This simplifies the calling code a little bit. That means that var dbus = new DBus(); var bus = dbus.getBus('session'); turns into var bus = DBus.getBus('session'); and var dbus = new DBus(); var service = dbus.registerService('session', 'service.name'); turns into var service = DBus.registerService('session', 'service.name'); Note that for backwards compatibility reasons, it's still possible to instantiate a new instance and call the methods on the instance.
1 parent 8409de5 commit fe5fadb

30 files changed

+138
-167
lines changed

README.md

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ Work your way through other examples to explore supported functionality.
5454

5555
## Note on systems without X11
5656
If no X server is running, the module fails when attempting to obtain a D-Bus
57-
connection at `dbus._dbus.getBus()`. This can be remedied by setting two
58-
environment variables manually (the actual bus address might be different):
57+
connection at `DBus.getBus()`. This can be remedied by setting two environment
58+
variables manually (the actual bus address might be different):
5959

6060
process.env.DISPLAY = ':0';
6161
process.env.DBUS_SESSION_BUS_ADDRESS = 'unix:path=/run/dbus/system_bus_socket';
@@ -68,16 +68,7 @@ environment variables manually (the actual bus address might be different):
6868

6969
The root object of this module.
7070

71-
#### `new DBus()`
72-
73-
Create a new DBus instance.
74-
75-
```
76-
var DBus = require('dbus')
77-
var dbus = new DBus()
78-
```
79-
80-
#### `DBus.prototype.getBus(busName)`
71+
#### `DBus.getBus(busName)`
8172

8273
* busName `<string>`
8374

@@ -87,10 +78,10 @@ bus or `"session"` to connect to the session bus.
8778
Returns a `Bus`.
8879

8980
```
90-
var bus = dbus.getBus('session');
81+
var bus = DBus.getBus('session');
9182
```
9283

93-
#### `DBus.prototype.registerService(busName, serviceName)`
84+
#### `DBus.registerService(busName, serviceName)`
9485

9586
* busName `<string>`
9687
* serviceName `<string>`
@@ -106,9 +97,26 @@ registered._
10697
Returns a `Service`.
10798

10899
```
109-
var service = dbus.registerService('session', 'com.example.Library');
100+
var service = DBus.registerService('session', 'com.example.Library');
101+
```
102+
103+
#### *DEPRECATED* `new DBus()`
104+
105+
Create a new DBus instance.
106+
107+
```
108+
var DBus = require('dbus')
109+
var dbus = new DBus()
110110
```
111111

112+
#### *DEPRECATED* `DBus.prototype.getBus(busName)`
113+
114+
Use `DBus.getBus(busName)`.
115+
116+
#### *DEPRECATED* `DBus.prototype.registerService(busName, serviceName)`
117+
118+
Use `DBus.registerService(busName, serviceName)`
119+
112120

113121
### Bus
114122

examples/error_handling.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
var DBus = require('../');
22

3-
var dbus = new DBus();
4-
5-
var bus = dbus.getBus('session');
3+
var bus = DBus.getBus('session');
64

75
bus.getInterface('nodejs.dbus.ExampleService', '/nodejs/dbus/ExampleService', 'nodejs.dbus.ExampleService.Interface1', function(err, iface) {
86

examples/get_property.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
var DBus = require('../');
22

3-
var dbus = new DBus();
4-
5-
var bus = dbus.getBus('session');
3+
var bus = DBus.getBus('session');
64

75
bus.getInterface('nodejs.dbus.ExampleService', '/nodejs/dbus/ExampleService', 'nodejs.dbus.ExampleService.Interface1', function(err, iface) {
86

examples/hello.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
var DBus = require('../');
22

3-
var dbus = new DBus();
4-
5-
var bus = dbus.getBus('session');
3+
var bus = DBus.getBus('session');
64

75
bus.getInterface('nodejs.dbus.ExampleService', '/nodejs/dbus/ExampleService', 'nodejs.dbus.ExampleService.Interface1', function(err, iface) {
86

examples/invalid_args.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
var DBus = require('../');
22

3-
var dbus = new DBus();
4-
5-
var bus = dbus.getBus('session');
3+
var bus = DBus.getBus('session');
64

75
bus.getInterface('nodejs.dbus.ExampleService', '/nodejs/dbus/ExampleService', 'nodejs.dbus.ExampleService.Interface1', function(err, iface) {
86
iface.Equal({ timeout: 1000 }, function(err, result) {

examples/method.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
var DBus = require('../');
22

3-
var dbus = new DBus();
4-
5-
var bus = dbus.getBus('session');
3+
var bus = DBus.getBus('session');
64

75
bus.getInterface('nodejs.dbus.ExampleService', '/nodejs/dbus/ExampleService', 'nodejs.dbus.ExampleService.Interface1', function(err, iface) {
86

examples/multi_connection.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
var DBus = require('../');
22

3-
var dbus = new DBus();
4-
5-
var bus1 = dbus.getBus('session');
3+
var bus1 = DBus.getBus('session');
64

75
bus1.getInterface('nodejs.dbus.ExampleService', '/nodejs/dbus/ExampleService', 'nodejs.dbus.ExampleService.Interface1', function(err, iface) {
86

@@ -12,7 +10,7 @@ bus1.getInterface('nodejs.dbus.ExampleService', '/nodejs/dbus/ExampleService', '
1210

1311
});
1412

15-
var bus2 = dbus.getBus('session');
13+
var bus2 = DBus.getBus('session');
1614

1715
bus2.getInterface('nodejs.dbus.ExampleService', '/nodejs/dbus/ExampleService', 'nodejs.dbus.ExampleService.Interface1', function(err, iface) {
1816

examples/service.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
var DBus = require('../');
22

3-
var dbus = new DBus();
4-
53
// Create a new service, object and interface
6-
var service = dbus.registerService('session', 'nodejs.dbus.ExampleService');
4+
var service = DBus.registerService('session', 'nodejs.dbus.ExampleService');
75
var obj = service.createObject('/nodejs/dbus/ExampleService');
86

97
// Create interface

examples/set_max_received_size.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
var DBus = require('../');
22

3-
var dbus = new DBus();
4-
5-
var bus = dbus.getBus('session');
3+
var bus = DBus.getBus('session');
64

75
bus.setMaxMessageSize(5000000);

examples/signal.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
var DBus = require('../');
22

3-
var dbus = new DBus();
4-
5-
var bus = dbus.getBus('session');
3+
var bus = DBus.getBus('session');
64

75
bus.getInterface('nodejs.dbus.ExampleService', '/nodejs/dbus/ExampleService', 'nodejs.dbus.ExampleService.Interface1', function(err, iface) {
86

0 commit comments

Comments
 (0)