/*! tether 0.6.5 */ (function(root, factory) { if (typeof define === 'function' && define.amd) { define(factory); } else if (typeof exports === 'object') { module.exports = factory(require,exports,module); } else { root.Tether = factory(); } }(this, function(require,exports,module) { (function() { var Evented, addClass, defer, deferred, extend, flush, getBounds, getOffsetParent, getOrigin, getScrollBarSize, getScrollParent, hasClass, node, removeClass, uniqueId, updateClasses, zeroPosCache, __hasProp = {}.hasOwnProperty, __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }, __slice = [].slice; if (this.Tether == null) { this.Tether = { modules: [] }; } getScrollParent = function(el) { var parent, position, scrollParent, style, _ref; position = getComputedStyle(el).position; if (position === 'fixed') { return el; } scrollParent = void 0; parent = el; while (parent = parent.parentNode) { try { style = getComputedStyle(parent); } catch (_error) {} if (style == null) { return parent; } if (/(auto|scroll)/.test(style['overflow'] + style['overflow-y'] + style['overflow-x'])) { if (position !== 'absolute' || ((_ref = style['position']) === 'relative' || _ref === 'absolute' || _ref === 'fixed')) { return parent; } } } return document.body; }; uniqueId = (function() { var id; id = 0; return function() { return id++; }; })(); zeroPosCache = {}; getOrigin = function(doc) { var id, k, node, v, _ref; node = doc._tetherZeroElement; if (node == null) { node = doc.createElement('div'); node.setAttribute('data-tether-id', uniqueId()); extend(node.style, { top: 0, left: 0, position: 'absolute' }); doc.body.appendChild(node); doc._tetherZeroElement = node; } id = node.getAttribute('data-tether-id'); if (zeroPosCache[id] == null) { zeroPosCache[id] = {}; _ref = node.getBoundingClientRect(); for (k in _ref) { v = _ref[k]; zeroPosCache[id][k] = v; } defer(function() { return zeroPosCache[id] = void 0; }); } return zeroPosCache[id]; }; node = null; getBounds = function(el) { var box, doc, docEl, k, origin, v, _ref; if (el === document) { doc = document; el = document.documentElement; } else { doc = el.ownerDocument; } docEl = doc.documentElement; box = {}; _ref = el.getBoundingClientRect(); for (k in _ref) { v = _ref[k]; box[k] = v; } origin = getOrigin(doc); box.top -= origin.top; box.left -= origin.left; if (box.width == null) { box.width = document.body.scrollWidth - box.left - box.right; } if (box.height == null) { box.height = document.body.scrollHeight - box.top - box.bottom; } box.top = box.top - docEl.clientTop; box.left = box.left - docEl.clientLeft; box.right = doc.body.clientWidth - box.width - box.left; box.bottom = doc.body.clientHeight - box.height - box.top; return box; }; getOffsetParent = function(el) { return el.offsetParent || document.documentElement; }; getScrollBarSize = function() { var inner, outer, width, widthContained, widthScroll; inner = document.createElement('div'); inner.style.width = '100%'; inner.style.height = '200px'; outer = document.createElement('div'); extend(outer.style, { position: 'absolute', top: 0, left: 0, pointerEvents: 'none', visibility: 'hidden', width: '200px', height: '150px', overflow: 'hidden' }); outer.appendChild(inner); document.body.appendChild(outer); widthContained = inner.offsetWidth; outer.style.overflow = 'scroll'; widthScroll = inner.offsetWidth; if (widthContained === widthScroll) { widthScroll = outer.clientWidth; } document.body.removeChild(outer); width = widthContained - widthScroll; return { width: width, height: width }; }; extend = function(out) { var args, key, obj, val, _i, _len, _ref; if (out == null) { out = {}; } args = []; Array.prototype.push.apply(args, arguments); _ref = args.slice(1); for (_i = 0, _len = _ref.length; _i < _len; _i++) { obj = _ref[_i]; if (obj) { for (key in obj) { if (!__hasProp.call(obj, key)) continue; val = obj[key]; out[key] = val; } } } return out; }; removeClass = function(el, name) { var cls, _i, _len, _ref, _results; if (el.classList != null) { _ref = name.split(' '); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { cls = _ref[_i]; if (cls.trim()) { _results.push(el.classList.remove(cls)); } } return _results; } else { return el.className = el.className.replace(new RegExp("(^| )" + (name.split(' ').join('|')) + "( |$)", 'gi'), ' '); } }; addClass = function(el, name) { var cls, _i, _len, _ref, _results; if (el.classList != null) { _ref = name.split(' '); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { cls = _ref[_i]; if (cls.trim()) { _results.push(el.classList.add(cls)); } } return _results; } else { removeClass(el, name); return el.className += " " + name; } }; hasClass = function(el, name) { if (el.classList != null) { return el.classList.contains(name); } else { return new RegExp("(^| )" + name + "( |$)", 'gi').test(el.className); } }; updateClasses = function(el, add, all) { var cls, _i, _j, _len, _len1, _results; for (_i = 0, _len = all.length; _i < _len; _i++) { cls = all[_i]; if (__indexOf.call(add, cls) < 0) { if (hasClass(el, cls)) { removeClass(el, cls); } } } _results = []; for (_j = 0, _len1 = add.length; _j < _len1; _j++) { cls = add[_j]; if (!hasClass(el, cls)) { _results.push(addClass(el, cls)); } else { _results.push(void 0); } } return _results; }; deferred = []; defer = function(fn) { return deferred.push(fn); }; flush = function() { var fn, _results; _results = []; while (fn = deferred.pop()) { _results.push(fn()); } return _results; }; Evented = (function() { function Evented() {} Evented.prototype.on = function(event, handler, ctx, once) { var _base; if (once == null) { once = false; } if (this.bindings == null) { this.bindings = {}; } if ((_base = this.bindings)[event] == null) { _base[event] = []; } return this.bindings[event].push({ handler: handler,
/*
* Copyright (C) 2015, 2016 "IoT.bzh"
* Author "Romain Forlot" <romain.forlot@iot.bzh>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "clientApp.hpp"
clientAppCtx::clientAppCtx(const char* uuid)
: uuid_(uuid)
{}
void clientAppCtx::update(Signal* sig)
{
json_object* sigJ = sig->toJSON();
if(afb_event_push(event_, sigJ) == 0)
{sig->delObserver(this);}
return;
}
void clientAppCtx::appendSignals(std::vector<Signal*>& sigV)
{
bool set = false;
// Clean up already subscribed signals to avoid duplicata
for (std::vector<Signal*>::const_iterator it = sigV.begin();
it != sigV.end(); ++it)
{
for (auto& ctxSig: subscribedSignals_)
{if(*it == ctxSig) {set = true;}}
if (set)
{
set = false;
sigV.erase(it);
continue;
}
Signal* sig = *it;
sig->addObserver(this);
}
subscribedSignals_.insert(subscribedSignals_.end(), sigV.begin(), sigV.end());
}
int clientAppCtx::makeSubscription(struct afb_req request)
{
event_ = afb_event_is_valid(event_) ?
event_ : afb_daemon_make_event(uuid_.c_str());
return afb_req_subscribe(request, event_);
}
int clientAppCtx::makeUnsubscription(struct afb_req request)
{
return afb_event_is_valid(event_) ?
afb_req_unsubscribe(request, event_) : -1;
}