Remove node-namespace from Driver

This commit is contained in:
Andrew Stewart 2014-05-06 18:24:43 -07:00
parent 637bce0e6d
commit c8cb7f0e40
4 changed files with 52 additions and 53 deletions

View File

@ -10,61 +10,55 @@
var Basestar = require('./basestar');
var namespace = require('node-namespace');
// The Driver class is a base class for Driver classes in external Cylon
// modules to use. It offers basic functions for starting/halting that
// descendant classes can use.
namespace("Cylon", function() {
this.Driver = (function(klass) {
subclass(Driver, klass);
var Driver;
// Public: Creates a new Driver
//
// opts - hash of acceptable params
// name - name of the Driver, used when printing to console
// device - Device the driver will use to proxy commands/events
//
// Returns a new Driver
function Driver(opts) {
if (opts == null) {
opts = {};
}
this.self = this;
this.name = opts.name;
this.device = opts.device;
this.connection = this.device.connection;
this.commandList = [];
}
// Public: Creates a new Driver
//
// opts - hash of acceptable params
// name - name of the Driver, used when printing to console
// device - Device the driver will use to proxy commands/events
//
// Returns a new Driver
module.exports = Driver = function Driver(opts) {
if (opts == null) {
opts = {};
}
// Public: Exposes all commands the driver will respond to/proxy
//
// Returns an array of string method names
Driver.prototype.commands = function() {
return this.commandList;
};
this.self = this;
this.name = opts.name;
this.device = opts.device;
this.connection = this.device.connection;
this.commandList = [];
};
// Public: Starts up the driver, and emits 'connect' from the @device
// when done.
//
// callback - function to run when the driver is started
//
// Returns nothing
Driver.prototype.start = function(callback) {
Logger.info("Driver " + this.name + " started");
callback(null);
this.device.emit('start');
return true;
};
subclass(Driver, Basestar);
// Public: Halts the driver
//
// Returns nothing
Driver.prototype.halt = function() {
return Logger.info("Driver " + this.name + " halted");
};
// Public: Exposes all commands the driver will respond to/proxy
//
// Returns an array of string method names
Driver.prototype.commands = function() {
return this.commandList;
};
return Driver;
// Public: Starts up the driver, and emits 'connect' from the @device
// when done.
//
// callback - function to run when the driver is started
//
// Returns nothing
Driver.prototype.start = function(callback) {
Logger.info("Driver " + this.name + " started");
callback(null);
this.device.emit('start');
return true;
};
})(Basestar);
});
// Public: Halts the driver
//
// Returns nothing
Driver.prototype.halt = function() {
return Logger.info("Driver " + this.name + " halted");
};

View File

@ -10,6 +10,8 @@
var namespace = require('node-namespace');
var Driver = require('../driver');
module.exports = {
driver: function(opts) {
return new Cylon.Drivers.Ping(opts);
@ -35,5 +37,5 @@ namespace("Cylon.Drivers", function() {
return Ping;
})(Cylon.Driver);
})(Driver);
});

View File

@ -10,6 +10,8 @@
var namespace = require('node-namespace');
var Driver = require('../driver');
module.exports = {
driver: function(opts) {
return new Cylon.Drivers.TestDriver(opts);
@ -29,5 +31,5 @@ namespace("Cylon.Drivers", function() {
return TestDriver;
})(Cylon.Driver);
})(Driver);
});

View File

@ -2,14 +2,15 @@
var EventEmitter = require('events').EventEmitter;
source("driver");
var Driver = source("driver");
describe("Driver", function() {
var device = {
connection: {},
emit: spy()
};
var driver = new Cylon.Driver({
var driver = new Driver({
name: 'driver',
device: device
});