cylon/lib/driver.js

63 lines
1.5 KiB
JavaScript
Raw Normal View History

2013-10-25 05:25:42 +08:00
/*
* driver
* cylonjs.com
*
* Copyright (c) 2013-2014 The Hybrid Group
2013-10-25 05:25:42 +08:00
* Licensed under the Apache 2.0 license.
*/
'use strict';
2013-10-25 05:25:42 +08:00
2014-05-14 10:44:40 +08:00
var Basestar = require('./basestar'),
Logger = require('./logger'),
Utils = require('./utils');
2014-04-25 06:31:47 +08:00
2014-02-28 06:42:33 +08:00
// 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.
2014-05-07 09:24:43 +08:00
var Driver;
2013-10-25 05:25:42 +08:00
2014-05-07 09:24:43 +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
module.exports = Driver = function Driver(opts) {
if (opts == null) {
opts = {};
}
2014-05-07 09:24:43 +08:00
this.self = this;
this.name = opts.name;
this.device = opts.device;
this.connection = this.device.connection;
};
Utils.subclass(Driver, Basestar);
Driver.prototype.commands = [];
// Public: Starts up the driver, and triggers the provided callback when done.
2014-05-07 09:24:43 +08:00
//
// callback - function to run when the driver is started
//
// Returns nothing
Driver.prototype.start = function(callback) {
Logger.info("Driver " + this.name + " started.");
2014-05-07 09:24:43 +08:00
callback(null);
return true;
};
2014-05-07 09:24:43 +08:00
// Public: Halts the driver
//
// callback - function to be triggered when the driver is halted
//
2014-05-07 09:24:43 +08:00
// Returns nothing
Driver.prototype.halt = function(callback) {
Logger.info("Driver " + this.name + " halted.");
this.removeAllListeners();
callback();
2014-05-07 09:24:43 +08:00
};