gpii-windows
Version:
Components of the GPII personalization infrastructure for use on Microsoft's "Windows" ™
88 lines (79 loc) • 3.09 kB
JavaScript
/*
* Handles requests from Windows Service.
*
* Copyright 2018 Raising the Floor - International
*
* Licensed under the New BSD license. You may not use this file except in
* compliance with this License.
*
* The R&D leading to these results received funding from the
* Department of Education - Grant H421A150005 (GPII-APCP). However,
* these results do not necessarily represent the policy of the
* Department of Education, and you should not assume endorsement by the
* Federal Government.
*
* You may obtain a copy of the License at
* https://github.com/GPII/universal/blob/master/LICENSE.txt
*/
;
var fluid = require("gpii-universal");
var gpii = fluid.registerNamespace("gpii");
fluid.registerNamespace("gpii.windows.service.serviceHandler");
/**
* A request from the service.
* @typedef {Object} ServiceRequest
* @property {String} requestType The type of request to perform.
* @property {Mixed} [various] Zero or more additional fields specific to the request.
*/
// Handles requests from the service.
// handleRequest() is invoked when a ServiceRequest is received from the service. The requestType field of the
// ServiceRequest is used to determine which invoker to call, and the return value is returned.
fluid.defaults("gpii.windows.service.requestHandler", {
gradeNames: ["fluid.component" ],
invokers: {
// Called from the handleMessage callback of the message session when a request has been received.
handleRequest: {
funcName: "gpii.windows.service.handleRequest",
args: [ "{that}", "{arguments}.0" ] // ServiceRequest
},
// Dynamically called via handleRequest.
status: {
funcName: "gpii.windows.service.status",
args: [ "{that}" ]
},
shutdown: {
funcName: "gpii.windows.service.shutdown",
args: [ "{that}" ]
}
}
});
/**
* Handle a request from the service, by calling the relevant invoker of gpii.windows.service.requestHandler.
*
* @param {Component} that The gpii.serviceHandler instance.
* @param {ServiceRequest} request The request from the service.
* @return {Object|Promise} The return of the handler function.
*/
gpii.windows.service.handleRequest = function (that, request) {
fluid.log("Service: request", request);
var handler = that[request.requestType];
return typeof(handler) === "function" && handler(request);
};
/**
* Determines the status of GPII. Currently, this only determines if GPII is running and hasn't frozen, where if a
* response from this request hasn't been received in a timely manner then it can be assumed GPII has froze.
*
* @return {Object} an object containing the status.
*/
gpii.windows.service.status = function () {
return {
isRunning: true
};
};
/**
* Called by the service to shutdown GPII.
*/
gpii.windows.service.shutdown = function () {
fluid.log("Service requested shutdown");
gpii.windows.messages.sendMessage("gpii-message-window", gpii.windows.API_constants.WM_QUERYENDSESSION, 0, 0);
};