Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// This file is part of ThingEngine
//
// Copyright 2015 Giovanni Campagna
//
// See COPYING for details
const Q = require('q');
const events = require('events');
const lang = require('lang');
// The abstract interface that all ObjectSets must conform to
//
// Some ObjectSets are read-only, in which case the mutator methods will fail
// XXX: This is really bad OOP, should we have two interfaces instead?
// CounterXXX: this is too much OOP!
const ObjectSet = new lang.Class({
Name: 'ObjectSet',
Extends: events.EventEmitter,
Abstract: true,
// events: object-added(object), object-removed(object)
_init: function() {
events.EventEmitter.call(this);
},
objectAdded: function(o) {
this.emit('object-added', o);
},
objectRemoved: function(o) {
this.emit('object-removed', o);
},
// This file is part of ThingEngine
//
// Copyright 2015 Giovanni Campagna
//
// See COPYING for details
const Q = require('q');
const events = require('events');
const lang = require('lang');
const adt = require('adt');
const ObjectSet = require('./object_set');
// A "view" of a set of devices (or their channels really), as a set of selectors matching
// in specific context (which must be an ObjectSet of Devices)
const DeviceView = new lang.Class({
Name: 'DeviceView',
Extends: events.EventEmitter,
_init: function(device, context, selectors, channelName, params, mode, openContext) {
events.EventEmitter.call(this);
this.device = device;
this.context = context;
if (selectors.length <= 0)
throw new Error('Selectors array must be non-empty');
this.selectors = selectors;
this.channelName = channelName;
this.params = params;
this.mode = mode;
this._subviews = [];
},
getCursor: function() {
throw new Error('Not Implemented');
},
getMembers: function() {
throw new Error('Not Implemented');
},
sendItem: function() {
throw new Error('Not Implemented');
},
});
module.exports = new lang.Class({
Name: 'Messaging',
Extends: events.EventEmitter,
// events: feed-added, feed-removed
Abstract: true,
$rpcMethods: ['get isAvailable', 'getOwnId', 'getUserById', 'getAccountById',
'getFeedMetas'],
_init: function() {
},
get isAvailable() {
return false;
},
startSync: function() {
throw new Error('Not Implemented');
// This file is part of ThingEngine
//
// Copyright 2015 Giovanni Campagna
//
// See COPYING for details
const lang = require('lang');
const Messaging = require('./lib/messaging');
const BaseDevice = require('./lib/base_device');
const BaseChannel = require('./lib/base_channel');
const UtilityDev = require('./lib/utility_devices');
const UtilityCh = require('./lib/utility_channels');
// a meta class for inheriting from BaseDevice, which avoids exposing
// lang.Class, and also has some utility for adding devices
const DeviceClass = new lang.Class({
Name: 'DeviceClass',
Extends: lang.Class,
_construct: function(params) {
if (!params.Extends)
params.Extends = BaseDevice;
return lang.Class.prototype._construct.call(this, params);
},
_init: function(params) {
var useOAuth2 = params.UseOAuth2;
var useDiscovery = params.UseDiscovery;
delete params.UseOAuth2;
delete params.UseDiscovery;
if (useDiscovery)
// -*- mode: js; indent-tabs-mode: nil; js-basic-offset: 4 -*-
//
// This file is part of ThingEngine
//
// Copyright 2015 Giovanni Campagna
//
// See COPYING for details
const lang = require('lang');
const Q = require('q');
const BaseDevice = require('../../base_device');
const Tier = require('../../tier_manager').Tier;
// A device that reacts to user input on the phone app
const UIDevice = new lang.Class({
Name: 'UIDevice',
Extends: BaseDevice,
_init: function(engine, state) {
this.parent(engine, state);
this.uniqueId = 'thingengine-system-ui';
this.name = "System UI";
this.description = "System UI collects the interaction with the ThingEngine Phone App";
},
get ownerTier() {
return Tier.PHONE;
},
//else if (analyzer.isQuestion)
// return true; // FIXME: handle question
//else if (analyzer.isRule)
// return this.switchTo(new RuleDialog(), analyzer);
else if (analyzer.isAction)
return this.switchTo(new ActionDialog(true), analyzer);
else
return false;
}
});
function capitalize(str) {
return str[0].toUpperCase() + str.substr(1).toLowerCase();
}
const ActionDialog = new lang.Class({
Name: 'ActionDialog',
Extends: Dialog,
_init: function(directExec) {
this.parent();
this.kind = null;
this.channelName = null;
this.devices = null;
this.resolving = null;
this.currentParam = null;
this.resolved_parameters = [];
this.directExec = directExec;
},
request.write(data);
request.end();
return defer.promise;
}
const GoogleDocsAPI = new lang.Class({
Name: 'GoogleDocsWebAPI',
_init: function(device) {
this._device = device;
},
// FINISHME implement something useful here
});
const PagedList = new lang.Class({
Name: 'PagedList',
_init: function(reply, key, baseurl, accessToken) {
var parsed = url.parse(baseurl);
this._baseurl = baseurl;
this._url = baseurl;
if (!parsed.search)
this._url += '?pageToken=';
else
this._url += '&pageToken=';
this._key = key;
this._accessToken = accessToken;
this.reply = reply;
var kinds = params.Kinds;
delete params.Kinds;
if (kinds && !params.hasKind) {
params.hasKind = function(kind) {
if (kinds.indexOf(kind) >= 0)
return true;
return this.parent(kind);
}
}
this.parent(params);
},
});
// same for BaseChannel, which also hides refcounted
const ChannelClass = new lang.Class({
Name: 'ChannelClass',
Extends: lang.Class,
_construct: function(params) {
if (!params.Extends)
params.Extends = BaseChannel;
return this.parent(params);
},
_init: function(params) {
var requiredCapabilities = params.RequiredCapabilities;
if (requiredCapabilities) {
delete params.RequiredCapabilities;
this.requiredCapabilities = requiredCapabilities;
} else {
this.requiredCapabilities = [];
case 'const':
return value;
case 'string':
return replaceInto(event, value);
case 'number':
// FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME
// FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME
// FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME
// FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME
return eval(replaceInto(event, value));
default:
throw new Error('Invalid output type ' + value);
}
}
const App = new lang.Class({
Name: 'App',
Extends: BaseApp,
_init: function(engine, serialized) {
this.parent(engine, serialized);
this._triggerChannel = null;
this._actionChannel = null;
// The serialized state contains:
// - A trigger, composed of:
// - a source channel ID and optionally a device
// - a list of filter expressions
// (parameter, op, maybe argument)
// - An action, composed of
// - a sink channel ID and optionally a device
const ThingTalk = require('thingtalk');
const Ast = ThingTalk.Ast;
// the device that owns/implements a builtin
const BuiltinOwner = {
'timer': 'thingengine-own-global',
'at': 'thingengine-own-global',
'input': 'thingengine-app',
'return': 'thingengine-app',
'notify': 'thingengine-app',
'logger': 'thingengine-pipe-system-writer'
};
// The named pipe system, wrapped as a device to appease DeviceView
// very evil, look away
const PipeSystemDevice = new lang.Class({
Name: 'PipeSystemDevice',
Extends: Tp.BaseDevice,
_init: function(engine, mode) {
this.parent(engine, { kind: 'thingengine-pipe-system' });
this.mode = mode;
// there is only one device in the context where this is put
// so there is no need for this to be unique
// but it has to be correct or DeviceView will not pick it
// (it's annoying but I don't want to touch DeviceView until
// we clear out what's the story with delegation)
this.uniqueId = 'thingengine-pipe-system-' + (mode === 'r' ? 'reader' : 'writer');
},
getTrigger: function(id, params) {