2013-10-25 05:25:42 +08:00
|
|
|
/*
|
|
|
|
* driver
|
|
|
|
* cylonjs.com
|
|
|
|
*
|
2014-02-28 01:38:38 +08:00
|
|
|
* Copyright (c) 2013-2014 The Hybrid Group
|
2013-10-25 05:25:42 +08:00
|
|
|
* Licensed under the Apache 2.0 license.
|
|
|
|
*/
|
|
|
|
|
2014-02-28 01:38:38 +08:00
|
|
|
'use strict';
|
2013-10-25 05:25:42 +08:00
|
|
|
|
2014-02-28 01:38:38 +08:00
|
|
|
require('./basestar');
|
|
|
|
var namespace = require('node-namespace');
|
2013-10-25 05:25:42 +08:00
|
|
|
|
2014-02-28 06:42:33 +08:00
|
|
|
// The Driver class is a base class for Driver classes in external Cylon
|
2014-03-12 01:44:11 +08:00
|
|
|
// modules to use. It offers basic functions for starting/halting that
|
|
|
|
// descendant classes can use.
|
2014-02-28 01:38:38 +08:00
|
|
|
namespace("Cylon", function() {
|
|
|
|
this.Driver = (function(klass) {
|
|
|
|
subclass(Driver, klass);
|
2013-10-25 05:25:42 +08:00
|
|
|
|
2014-02-28 06:42:33 +08:00
|
|
|
// 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
|
2014-02-28 01:38:38 +08:00
|
|
|
function Driver(opts) {
|
|
|
|
if (opts == null) {
|
|
|
|
opts = {};
|
2013-11-12 00:28:37 +08:00
|
|
|
}
|
2014-02-28 01:38:38 +08:00
|
|
|
this.self = this;
|
|
|
|
this.name = opts.name;
|
|
|
|
this.device = opts.device;
|
|
|
|
this.connection = this.device.connection;
|
|
|
|
this.commandList = [];
|
|
|
|
}
|
|
|
|
|
2014-02-28 06:42:33 +08:00
|
|
|
// Public: Exposes all commands the driver will respond to/proxy
|
|
|
|
//
|
|
|
|
// Returns an array of string method names
|
2014-02-28 01:38:38 +08:00
|
|
|
Driver.prototype.commands = function() {
|
|
|
|
return this.commandList;
|
|
|
|
};
|
|
|
|
|
2014-02-28 06:42:33 +08:00
|
|
|
// Public: Starts up the driver, and emits 'connect' from the @device
|
|
|
|
// when done.
|
|
|
|
//
|
|
|
|
// callback - function to run when the driver is started
|
|
|
|
//
|
|
|
|
// Returns nothing
|
2014-02-28 01:38:38 +08:00
|
|
|
Driver.prototype.start = function(callback) {
|
|
|
|
Logger.info("Driver " + this.name + " started");
|
|
|
|
callback(null);
|
|
|
|
this.device.emit('start');
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2014-03-12 01:44:11 +08:00
|
|
|
// Public: Halts the driver
|
2014-02-28 06:42:33 +08:00
|
|
|
//
|
|
|
|
// Returns nothing
|
2014-03-12 01:44:11 +08:00
|
|
|
Driver.prototype.halt = function() {
|
|
|
|
return Logger.info("Driver " + this.name + " halted");
|
2014-02-28 01:38:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
return Driver;
|
|
|
|
|
|
|
|
})(Cylon.Basestar);
|
|
|
|
});
|