cylon/lib/driver.js

71 lines
1.8 KiB
JavaScript

/*
* driver
* cylonjs.com
*
* Copyright (c) 2013-2014 The Hybrid Group
* Licensed under the Apache 2.0 license.
*/
'use strict';
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);
// 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: Exposes all commands the driver will respond to/proxy
//
// Returns an array of string method names
Driver.prototype.commands = function() {
return 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;
};
// Public: Halts the driver
//
// Returns nothing
Driver.prototype.halt = function() {
return Logger.info("Driver " + this.name + " halted");
};
return Driver;
})(Basestar);
});