2013-10-30 01:43:11 +08:00
|
|
|
/*
|
|
|
|
* basestar
|
|
|
|
* cylonjs.com
|
|
|
|
*
|
2014-02-28 02:58:50 +08:00
|
|
|
* Copyright (c) 2013-2014 The Hybrid Group
|
2013-10-30 01:43:11 +08:00
|
|
|
* Licensed under the Apache 2.0 license.
|
|
|
|
*/
|
|
|
|
|
2014-02-28 02:58:50 +08:00
|
|
|
"use strict";
|
2013-10-30 01:43:11 +08:00
|
|
|
|
2014-02-28 02:58:50 +08:00
|
|
|
require('./utils');
|
|
|
|
var namespace = require('node-namespace');
|
|
|
|
var EventEmitter = require('events').EventEmitter;
|
2013-10-30 01:43:11 +08:00
|
|
|
|
2014-02-28 02:58:50 +08:00
|
|
|
namespace("Cylon", function() {
|
|
|
|
this.Basestar = (function(klass) {
|
|
|
|
subclass(Basestar, klass);
|
2013-11-05 03:41:51 +08:00
|
|
|
|
2014-02-28 02:58:50 +08:00
|
|
|
function Basestar(opts) {
|
|
|
|
this.self = this;
|
|
|
|
}
|
2013-10-30 01:43:11 +08:00
|
|
|
|
2014-02-28 02:58:50 +08:00
|
|
|
Basestar.prototype.proxyMethods = function(methods, target, source, force) {
|
|
|
|
if (force == null) {
|
|
|
|
force = false;
|
2013-10-30 01:43:11 +08:00
|
|
|
}
|
2014-02-28 02:58:50 +08:00
|
|
|
return proxyFunctionsToObject(methods, target, source, force);
|
|
|
|
};
|
2013-10-30 01:43:11 +08:00
|
|
|
|
2014-02-28 02:58:50 +08:00
|
|
|
Basestar.prototype.defineEvent = function(opts) {
|
|
|
|
var sendUpdate, targetEventName,
|
|
|
|
_this = this;
|
|
|
|
targetEventName = opts.targetEventName || opts.eventName;
|
|
|
|
sendUpdate = opts.sendUpdate || false;
|
|
|
|
opts.source.on(opts.eventName, function() {
|
|
|
|
var args, _ref, _ref1;
|
|
|
|
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
|
|
|
(_ref = opts.target).emit.apply(_ref, [targetEventName].concat(__slice.call(args)));
|
|
|
|
if (sendUpdate) {
|
|
|
|
return (_ref1 = opts.target).emit.apply(_ref1, ['update', targetEventName].concat(__slice.call(args)));
|
2013-11-01 06:15:23 +08:00
|
|
|
}
|
2014-02-28 02:58:50 +08:00
|
|
|
});
|
|
|
|
return opts.source;
|
|
|
|
};
|
2013-11-01 06:15:23 +08:00
|
|
|
|
2014-02-28 02:58:50 +08:00
|
|
|
Basestar.prototype.defineAdaptorEvent = function(opts) {
|
|
|
|
opts['source'] = this.connector;
|
|
|
|
opts['target'] = this.connection;
|
|
|
|
if (opts['sendUpdate'] == null) {
|
|
|
|
opts['sendUpdate'] = false;
|
|
|
|
}
|
|
|
|
return this.defineEvent(opts);
|
|
|
|
};
|
2013-11-01 06:15:23 +08:00
|
|
|
|
2014-02-28 02:58:50 +08:00
|
|
|
Basestar.prototype.defineDriverEvent = function(opts) {
|
|
|
|
opts['source'] = this.connection;
|
|
|
|
opts['target'] = this.device;
|
|
|
|
if (opts['sendUpdate'] == null) {
|
|
|
|
opts['sendUpdate'] = true;
|
|
|
|
}
|
|
|
|
return this.defineEvent(opts);
|
|
|
|
};
|
2013-10-30 01:43:11 +08:00
|
|
|
|
2014-02-28 02:58:50 +08:00
|
|
|
return Basestar;
|
2013-10-30 01:43:11 +08:00
|
|
|
|
2014-02-28 02:58:50 +08:00
|
|
|
})(EventEmitter);
|
|
|
|
});
|