cylon/lib/adaptor.js

68 lines
1.8 KiB
JavaScript
Raw Normal View History

2013-10-25 05:25:42 +08:00
/*
* adaptor
* 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
require('./basestar');
var namespace = require('node-namespace');
2013-10-25 05:25:42 +08:00
2014-02-28 03:45:09 +08:00
// The Adaptor class is a base class for Adaptor classes in external Cylon
// modules to use. It offers basic functions for connecting/disconnecting that
// descendant classes can use.
namespace("Cylon", function() {
this.Adaptor = (function(klass) {
subclass(Adaptor, klass);
2013-10-25 05:25:42 +08:00
2014-02-28 03:45:09 +08:00
// Public: Creates a new Adaptor
//
// opts - hash of acceptable params
// name - name of the Adaptor, used when printing to console
// connection - Connection the adaptor will use to proxy commands/events
//
2014-02-28 06:14:33 +08:00
// Returns a new Adaptor
function Adaptor(opts) {
if (opts == null) {
opts = {};
2013-11-12 00:28:37 +08:00
}
this.self = this;
this.name = opts.name;
this.connection = opts.connection;
this.commandList = [];
}
2014-02-28 03:45:09 +08:00
// Public: Exposes all commands the adaptor will respond to/proxy
//
// Returns an array of string method names
Adaptor.prototype.commands = function() {
return this.commandList;
};
2014-02-28 03:45:09 +08:00
// Public: Connects to the adaptor, and emits 'connect' from the @connection
// when done.
//
// callback - function to run when the adaptor is connected
//
// Returns nothing
Adaptor.prototype.connect = function(callback) {
Logger.info("Connecting to adaptor '" + this.name + "'...");
callback(null);
return this.connection.emit('connect');
};
2014-02-28 03:45:09 +08:00
// Public: Disconnects from the adaptor
//
// Returns nothing
Adaptor.prototype.disconnect = function() {
return Logger.info("Disconnecting from adaptor '" + this.name + "'...");
};
return Adaptor;
})(Cylon.Basestar);
});