Remaining moves and refactoring for Adaptor/Driver base classes
This commit is contained in:
parent
0e874c52d5
commit
8f40826a34
|
@ -16,7 +16,9 @@
|
|||
namespace('Cylon.Adaptors', function() {
|
||||
return this.Adaptor = (function() {
|
||||
function Adaptor(opts) {
|
||||
this.self = this;
|
||||
this.name = opts.name;
|
||||
this.connection = opts.connection;
|
||||
}
|
||||
|
||||
Adaptor.prototype.commands = function() {
|
||||
|
@ -25,7 +27,8 @@
|
|||
|
||||
Adaptor.prototype.connect = function(callback) {
|
||||
Logger.info("Connecting to adaptor '" + this.name + "'...");
|
||||
return callback(null);
|
||||
callback(null);
|
||||
return this.connection.emit('connect');
|
||||
};
|
||||
|
||||
Adaptor.prototype.disconnect = function() {
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
function Driver(opts) {
|
||||
this.self = this;
|
||||
this.name = opts.name;
|
||||
this.device = opts.device;
|
||||
}
|
||||
|
||||
Driver.prototype.start = function() {
|
||||
|
|
|
@ -57,8 +57,8 @@
|
|||
this.adaptors = {};
|
||||
this.drivers = {};
|
||||
this.commands = [];
|
||||
this.registerAdaptor("./loopback", "loopback");
|
||||
this.registerDriver("./ping", "ping");
|
||||
this.registerAdaptor("./test/loopback", "loopback");
|
||||
this.registerDriver("./test/ping", "ping");
|
||||
this.initConnections(opts.connection || opts.connections);
|
||||
this.initDevices(opts.device || opts.devices);
|
||||
this.work = opts.work || function() {
|
||||
|
|
|
@ -29,24 +29,15 @@
|
|||
};
|
||||
|
||||
namespace('Cylon.Adaptors', function() {
|
||||
var _ref;
|
||||
return this.Loopback = (function(_super) {
|
||||
__extends(Loopback, _super);
|
||||
|
||||
function Loopback(opts) {
|
||||
this.self = this;
|
||||
this.name = opts.name;
|
||||
function Loopback() {
|
||||
_ref = Loopback.__super__.constructor.apply(this, arguments);
|
||||
return _ref;
|
||||
}
|
||||
|
||||
Loopback.prototype.connect = function(callback) {
|
||||
Logger.info("Connecting to adaptor '" + this.name + "'...");
|
||||
callback(null);
|
||||
return this.connection.emit('connect');
|
||||
};
|
||||
|
||||
Loopback.prototype.disconnect = function() {
|
||||
return Logger.info("Disconnecting from adaptor '" + this.name + "'...");
|
||||
};
|
||||
|
||||
Loopback.prototype.commands = function() {
|
||||
return ['ping'];
|
||||
};
|
|
@ -29,23 +29,19 @@
|
|||
};
|
||||
|
||||
namespace('Cylon.Drivers', function() {
|
||||
var _ref;
|
||||
return this.Ping = (function(_super) {
|
||||
__extends(Ping, _super);
|
||||
|
||||
function Ping(opts) {
|
||||
this.self = this;
|
||||
this.name = opts.name;
|
||||
function Ping() {
|
||||
_ref = Ping.__super__.constructor.apply(this, arguments);
|
||||
return _ref;
|
||||
}
|
||||
|
||||
Ping.prototype.commands = function() {
|
||||
return ['ping'];
|
||||
};
|
||||
|
||||
Ping.prototype.start = function(callback) {
|
||||
Logger.info("Starting driver '" + this.name + "'...");
|
||||
return callback(null);
|
||||
};
|
||||
|
||||
Ping.prototype.ping = function() {
|
||||
return "pong";
|
||||
};
|
|
@ -13,7 +13,9 @@ namespace = require 'node-namespace'
|
|||
namespace 'Cylon.Adaptors', ->
|
||||
class @Adaptor
|
||||
constructor: (opts) ->
|
||||
@self = this
|
||||
@name = opts.name
|
||||
@connection = opts.connection
|
||||
|
||||
commands: ->
|
||||
[]
|
||||
|
@ -21,6 +23,7 @@ namespace 'Cylon.Adaptors', ->
|
|||
connect: (callback) ->
|
||||
Logger.info "Connecting to adaptor '#{@name}'..."
|
||||
(callback)(null)
|
||||
@connection.emit 'connect'
|
||||
|
||||
disconnect: ->
|
||||
Logger.info "Disconnecting from adaptor '#{@name}'..."
|
||||
|
|
|
@ -15,6 +15,7 @@ namespace 'Cylon.Drivers', ->
|
|||
constructor: (opts) ->
|
||||
@self = this
|
||||
@name = opts.name
|
||||
@device = opts.device
|
||||
|
||||
start: ->
|
||||
Logger.info "Driver #{@name} started"
|
||||
|
|
|
@ -57,8 +57,8 @@ namespace 'Cylon', ->
|
|||
@drivers = {}
|
||||
@commands = []
|
||||
|
||||
@registerAdaptor "./loopback", "loopback"
|
||||
@registerDriver "./ping", "ping"
|
||||
@registerAdaptor "./test/loopback", "loopback"
|
||||
@registerDriver "./test/ping", "ping"
|
||||
|
||||
@initConnections(opts.connection or opts.connections)
|
||||
@initDevices(opts.device or opts.devices)
|
||||
|
|
|
@ -16,17 +16,5 @@ module.exports =
|
|||
|
||||
namespace 'Cylon.Adaptors', ->
|
||||
class @Loopback extends @Adaptor
|
||||
constructor: (opts) ->
|
||||
@self = this
|
||||
@name = opts.name
|
||||
|
||||
connect: (callback) ->
|
||||
Logger.info "Connecting to adaptor '#{@name}'..."
|
||||
(callback)(null)
|
||||
@connection.emit 'connect'
|
||||
|
||||
disconnect: ->
|
||||
Logger.info "Disconnecting from adaptor '#{@name}'..."
|
||||
|
||||
commands: ->
|
||||
['ping']
|
|
@ -16,16 +16,8 @@ module.exports =
|
|||
|
||||
namespace 'Cylon.Drivers', ->
|
||||
class @Ping extends @Driver
|
||||
constructor: (opts) ->
|
||||
@self = this
|
||||
@name = opts.name
|
||||
|
||||
commands: ->
|
||||
['ping']
|
||||
|
||||
start: (callback) ->
|
||||
Logger.info "Starting driver '#{@name}'..."
|
||||
(callback)(null)
|
||||
|
||||
ping: ->
|
||||
"pong"
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
source("robot");
|
||||
|
||||
source("loopback");
|
||||
source("test/loopback");
|
||||
|
||||
describe("Connection", function() {
|
||||
var adaptor, connection, initAdaptor, robot;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
source("driver");
|
||||
|
||||
source("ping");
|
||||
source("test/ping");
|
||||
|
||||
describe("Device", function() {
|
||||
var device, driver, initDriver, robot;
|
||||
|
@ -22,17 +22,29 @@
|
|||
driver: 'driving',
|
||||
robot: robot
|
||||
});
|
||||
it("should belong to a robot", function() {
|
||||
it("belongs to a robot", function() {
|
||||
return device.robot.name.should.be.equal('me');
|
||||
});
|
||||
it("should have a name", function() {
|
||||
it("has a name", function() {
|
||||
return device.name.should.be.equal('devisive');
|
||||
});
|
||||
it("should use default connection if none specified");
|
||||
it("should use connection if one is specified");
|
||||
return it("should init a driver", function() {
|
||||
it("can init a driver", function() {
|
||||
return initDriver.should.be.called;
|
||||
});
|
||||
it("can start a driver", function() {
|
||||
var driverStart;
|
||||
driverStart = sinon.stub(driver, 'start').returns(true);
|
||||
device.start();
|
||||
return driverStart.should.be.called;
|
||||
});
|
||||
it("can stop a driver", function() {
|
||||
var driverStop;
|
||||
driverStop = sinon.stub(driver, 'stop').returns(true);
|
||||
device.stop();
|
||||
return driverStop.should.be.called;
|
||||
});
|
||||
it("should use default connection if none specified");
|
||||
return it("should use connection if one is specified");
|
||||
});
|
||||
|
||||
}).call(this);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
source "connection"
|
||||
source "adaptor"
|
||||
source "robot"
|
||||
source "loopback"
|
||||
source "test/loopback"
|
||||
|
||||
describe "Connection", ->
|
||||
robot = new Cylon.Robot(name: 'me')
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
source "device"
|
||||
source "robot"
|
||||
source "driver"
|
||||
source "ping"
|
||||
source "test/ping"
|
||||
|
||||
describe "Device", ->
|
||||
robot = new Cylon.Robot(name: 'me')
|
||||
|
@ -11,14 +11,24 @@ describe "Device", ->
|
|||
initDriver = sinon.stub(robot, 'initDriver').returns(driver)
|
||||
device = new Cylon.Device(name: "devisive", driver: 'driving', robot: robot)
|
||||
|
||||
it "should belong to a robot", ->
|
||||
it "belongs to a robot", ->
|
||||
device.robot.name.should.be.equal 'me'
|
||||
|
||||
it "should have a name", ->
|
||||
it "has a name", ->
|
||||
device.name.should.be.equal 'devisive'
|
||||
|
||||
it "can init a driver", ->
|
||||
initDriver.should.be.called
|
||||
|
||||
it "can start a driver", ->
|
||||
driverStart = sinon.stub(driver, 'start').returns(true)
|
||||
device.start()
|
||||
driverStart.should.be.called
|
||||
|
||||
it "can stop a driver", ->
|
||||
driverStop = sinon.stub(driver, 'stop').returns(true)
|
||||
device.stop()
|
||||
driverStop.should.be.called
|
||||
|
||||
it "should use default connection if none specified"
|
||||
it "should use connection if one is specified"
|
||||
|
||||
it "should init a driver", ->
|
||||
initDriver.should.be.called
|
||||
|
|
Loading…
Reference in New Issue