Skip to content

Instantly share code, notes, and snippets.

@sgithens
Created June 29, 2014 15:35
Show Gist options
  • Select an option

  • Save sgithens/9bb2e970a84d66e969cd to your computer and use it in GitHub Desktop.

Select an option

Save sgithens/9bb2e970a84d66e969cd to your computer and use it in GitHub Desktop.
gpii.invokeGradedFunction = function (name, spec) {
var defaults = fluid.defaults(name);
if (!defaults.argumentMap || !fluid.hasGrade(defaults, "fluid.function")) {
fluid.fail("Cannot look up name " + name + " to a function with registered argumentMap - got defaults ", defaults);
}
var args = [];
fluid.each(defaults.argumentMap, function (value, key) {
args[value] = spec[key];
});
return fluid.invokeGlobalFunction(name, args);
};
gpii.handleDeviceGet = function (requestProxy, installedSolutionsDataSource, solutionsRegistryDataSource) {
if (installedSolutionsDataSource.options.url) {
installedSolutionsDataSource.get(null, function onSuccess(solutions) {
fireDeviceInformation(requestProxy, solutions);
});
} else {
var installedSolutions = [];
solutionsRegistryDataSource.get(null, function onSuccess(entries) {
entries.forEach( function (entry) {
if (!installedSolutions.some(function(s) { return s.id === entry.id; })) {
fluid.each(entry.contexts.deviceReporters, function (deviceReporter) {
if (!installedSolutions.some(function(s) { return s.id === entry.id; })) {
if (gpii.invokeGradedFunction(deviceReporter.type, deviceReporter)) {
installedSolutions.push({ "id": entry.id });
}
}
});
}
});
fireDeviceInformation(requestProxy, installedSolutions);
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment