2013-10-25 05:25:42 +08:00
|
|
|
/*
|
|
|
|
* adaptor
|
|
|
|
* 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-05-14 10:44:40 +08:00
|
|
|
var Basestar = require('./basestar'),
|
2014-06-06 03:11:37 +08:00
|
|
|
Logger = require('./logger'),
|
|
|
|
Utils = require('./utils');
|
2014-04-25 06:31:47 +08:00
|
|
|
|
2014-05-07 09:18:20 +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
|
|
|
|
//
|
|
|
|
// Returns a new Adaptor
|
2014-07-11 00:51:23 +08:00
|
|
|
var Adaptor = module.exports = function Adaptor(opts) {
|
|
|
|
opts = opts || {};
|
2014-05-07 09:18:20 +08:00
|
|
|
|
|
|
|
this.name = opts.name;
|
2014-11-11 07:56:25 +08:00
|
|
|
|
|
|
|
// the Robot the adaptor belongs to
|
|
|
|
this.robot = opts.robot;
|
|
|
|
|
|
|
|
// some default options
|
|
|
|
this.host = opts.host;
|
|
|
|
this.port = opts.port;
|
|
|
|
|
|
|
|
// misc. details provided in args hash
|
|
|
|
this.details = {};
|
|
|
|
|
|
|
|
for (var opt in opts) {
|
|
|
|
if (['robot', 'name', 'adaptor'].indexOf(opt) < 0) {
|
|
|
|
this.details[opt] = opts[opt];
|
|
|
|
}
|
|
|
|
}
|
2014-05-07 09:18:20 +08:00
|
|
|
};
|
|
|
|
|
2014-06-06 03:11:37 +08:00
|
|
|
Utils.subclass(Adaptor, Basestar);
|
2014-11-11 07:56:25 +08:00
|
|
|
|
|
|
|
// Public: Expresses the Connection in JSON format
|
|
|
|
//
|
|
|
|
// Returns an Object containing Connection data
|
|
|
|
Adaptor.prototype.toJSON = function() {
|
|
|
|
return {
|
|
|
|
name: this.name,
|
|
|
|
adaptor: this.constructor.name || this.name,
|
|
|
|
details: this.details
|
|
|
|
};
|
|
|
|
};
|