Refactor adaptor & driver to pure JS style
This commit is contained in:
parent
74efee0809
commit
8b88e5dc10
|
@ -2,52 +2,44 @@
|
||||||
* adaptor
|
* adaptor
|
||||||
* cylonjs.com
|
* cylonjs.com
|
||||||
*
|
*
|
||||||
* Copyright (c) 2013 The Hybrid Group
|
* Copyright (c) 2013-2014 The Hybrid Group
|
||||||
* Licensed under the Apache 2.0 license.
|
* Licensed under the Apache 2.0 license.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
(function() {
|
require('./basestar');
|
||||||
'use strict';
|
var namespace = require('node-namespace');
|
||||||
var namespace,
|
|
||||||
__hasProp = {}.hasOwnProperty,
|
|
||||||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
||||||
|
|
||||||
namespace = require('node-namespace');
|
namespace("Cylon", function() {
|
||||||
|
this.Adaptor = (function(klass) {
|
||||||
|
subclass(Adaptor, klass);
|
||||||
|
|
||||||
require('./basestar');
|
function Adaptor(opts) {
|
||||||
|
if (opts == null) {
|
||||||
namespace('Cylon', function() {
|
opts = {};
|
||||||
return this.Adaptor = (function(_super) {
|
|
||||||
__extends(Adaptor, _super);
|
|
||||||
|
|
||||||
function Adaptor(opts) {
|
|
||||||
if (opts == null) {
|
|
||||||
opts = {};
|
|
||||||
}
|
|
||||||
this.self = this;
|
|
||||||
this.name = opts.name;
|
|
||||||
this.connection = opts.connection;
|
|
||||||
this.commandList = [];
|
|
||||||
}
|
}
|
||||||
|
this.self = this;
|
||||||
|
this.name = opts.name;
|
||||||
|
this.connection = opts.connection;
|
||||||
|
this.commandList = [];
|
||||||
|
}
|
||||||
|
|
||||||
Adaptor.prototype.commands = function() {
|
Adaptor.prototype.commands = function() {
|
||||||
return this.commandList;
|
return this.commandList;
|
||||||
};
|
};
|
||||||
|
|
||||||
Adaptor.prototype.connect = function(callback) {
|
Adaptor.prototype.connect = function(callback) {
|
||||||
Logger.info("Connecting to adaptor '" + this.name + "'...");
|
Logger.info("Connecting to adaptor '" + this.name + "'...");
|
||||||
callback(null);
|
callback(null);
|
||||||
return this.connection.emit('connect');
|
return this.connection.emit('connect');
|
||||||
};
|
};
|
||||||
|
|
||||||
Adaptor.prototype.disconnect = function() {
|
Adaptor.prototype.disconnect = function() {
|
||||||
return Logger.info("Disconnecting from adaptor '" + this.name + "'...");
|
return Logger.info("Disconnecting from adaptor '" + this.name + "'...");
|
||||||
};
|
};
|
||||||
|
|
||||||
return Adaptor;
|
return Adaptor;
|
||||||
|
|
||||||
})(Cylon.Basestar);
|
})(Cylon.Basestar);
|
||||||
});
|
});
|
||||||
|
|
||||||
}).call(this);
|
|
||||||
|
|
|
@ -2,54 +2,46 @@
|
||||||
* driver
|
* driver
|
||||||
* cylonjs.com
|
* cylonjs.com
|
||||||
*
|
*
|
||||||
* Copyright (c) 2013 The Hybrid Group
|
* Copyright (c) 2013-2014 The Hybrid Group
|
||||||
* Licensed under the Apache 2.0 license.
|
* Licensed under the Apache 2.0 license.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
(function() {
|
require('./basestar');
|
||||||
'use strict';
|
var namespace = require('node-namespace');
|
||||||
var namespace,
|
|
||||||
__hasProp = {}.hasOwnProperty,
|
|
||||||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
||||||
|
|
||||||
namespace = require('node-namespace');
|
namespace("Cylon", function() {
|
||||||
|
this.Driver = (function(klass) {
|
||||||
|
subclass(Driver, klass);
|
||||||
|
|
||||||
require('./basestar');
|
function Driver(opts) {
|
||||||
|
if (opts == null) {
|
||||||
namespace('Cylon', function() {
|
opts = {};
|
||||||
return this.Driver = (function(_super) {
|
|
||||||
__extends(Driver, _super);
|
|
||||||
|
|
||||||
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 = [];
|
|
||||||
}
|
}
|
||||||
|
this.self = this;
|
||||||
|
this.name = opts.name;
|
||||||
|
this.device = opts.device;
|
||||||
|
this.connection = this.device.connection;
|
||||||
|
this.commandList = [];
|
||||||
|
}
|
||||||
|
|
||||||
Driver.prototype.commands = function() {
|
Driver.prototype.commands = function() {
|
||||||
return this.commandList;
|
return this.commandList;
|
||||||
};
|
};
|
||||||
|
|
||||||
Driver.prototype.start = function(callback) {
|
Driver.prototype.start = function(callback) {
|
||||||
Logger.info("Driver " + this.name + " started");
|
Logger.info("Driver " + this.name + " started");
|
||||||
callback(null);
|
callback(null);
|
||||||
this.device.emit('start');
|
this.device.emit('start');
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
Driver.prototype.stop = function() {
|
Driver.prototype.stop = function() {
|
||||||
return Logger.info("Driver " + this.name + " stopped");
|
return Logger.info("Driver " + this.name + " stopped");
|
||||||
};
|
};
|
||||||
|
|
||||||
return Driver;
|
return Driver;
|
||||||
|
|
||||||
})(Cylon.Basestar);
|
})(Cylon.Basestar);
|
||||||
});
|
});
|
||||||
|
|
||||||
}).call(this);
|
|
||||||
|
|
Loading…
Reference in New Issue