From dc139c1a9024bc6996243eecb998a5d29363dbd5 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Wed, 10 Sep 2014 11:37:13 -0400 Subject: [PATCH 01/78] First commit of node.js "nodeprocesses" add-on for acquiring information about what is running. --- gpii/node_modules/processes/README.md | 48 ++++++ .../processes/nodeprocesses/binding.gyp | 11 ++ .../processes/nodeprocesses/nodeprocesses.cc | 149 ++++++++++++++++++ .../nodeprocesses/nodeprocesses_test.js | 79 ++++++++++ gpii/node_modules/processes/package.json | 19 +++ 5 files changed, 306 insertions(+) create mode 100644 gpii/node_modules/processes/README.md create mode 100644 gpii/node_modules/processes/nodeprocesses/binding.gyp create mode 100644 gpii/node_modules/processes/nodeprocesses/nodeprocesses.cc create mode 100644 gpii/node_modules/processes/nodeprocesses/nodeprocesses_test.js create mode 100644 gpii/node_modules/processes/package.json diff --git a/gpii/node_modules/processes/README.md b/gpii/node_modules/processes/README.md new file mode 100644 index 0000000..b3ed10f --- /dev/null +++ b/gpii/node_modules/processes/README.md @@ -0,0 +1,48 @@ +GPII Node.js Processes Bridge +----------------------------- + +The GPII prcoesses bridge is a Node.js bridge to GNOME/Linux's native libraries +to acquire information about running processes, written in C++. + +To compile the module: + +* Run build.sh at the top of this repository (TBD -- use Gruntfile.js?). + +Or, by hand: + +* cd nodeprocesses +* node-gyp configure build +* node nodeprocesses_tests.js # Run the tests + + +Notes +----- + +var procArray = nodeprocess.getProcesses(); + + +var commandName = "orca"; +var orcaProc = fluid.find (procArray, function (procInfo) { + if (procInfo.command === commandName) { + return procInfo; + } + }, null); + +A proccess is represented by the following structure (using orca as an example): + +{ + pid: 3911, + uid: 1000, + gid: 1000, + command: 'orca', + fullPath: '/usr/bin/python3', + argv: [ '/usr/bin/python3', '/usr/bin/orca' ], + state: 'Sleeping' +} + +The state member can be one of: +* Running +* Stopped +* Zombie +* Uninterruptible +* Sleeping diff --git a/gpii/node_modules/processes/nodeprocesses/binding.gyp b/gpii/node_modules/processes/nodeprocesses/binding.gyp new file mode 100644 index 0000000..051d2dc --- /dev/null +++ b/gpii/node_modules/processes/nodeprocesses/binding.gyp @@ -0,0 +1,11 @@ +{ + "targets": [ + { + "target_name": "nodeprocesses", + "sources": ["nodeprocesses.cc"], + "libraries": [" +#include +#include +#include +#include +#include +#include +#include +//#include + +using namespace v8; + +static glibtop* glibtopPtr = NULL; + +// static std::basic_string +// utf8StringFromValue(v8::Handle value) +// { +// v8::Local string = value->ToString(); +// gchar *buffer = g_new(gchar, string->Utf8Length()); +// string->WriteUtf8(buffer); +// return buffer; +// } + +v8::Local +format_process_state (guint state) +{ + v8::Local status; + + switch (state) + { + case GLIBTOP_PROCESS_RUNNING: + status = String::New ("Running"); + break; + + case GLIBTOP_PROCESS_STOPPED: + status = String::New ("Stopped"); + break; + + case GLIBTOP_PROCESS_ZOMBIE: + status = String::New ("Zombie"); + break; + + case GLIBTOP_PROCESS_UNINTERRUPTIBLE: + status = String::New ("Uninterruptible"); + break; + + default: + status = String::New ("Sleeping"); + break; + } + return status; +} + + +static v8::Handle +makeProcInfo (pid_t pid, glibtop_proclist* procList) { + glibtop_proc_state procstate; + glibtop_proc_args procargs; + glibtop_proc_uid procuid; + char** argv = NULL; + + v8::Local fullPath = String::Empty(); + v8::Handle arguments = v8::Array::New(); + + glibtop_get_proc_state (&procstate, pid); + glibtop_get_proc_uid (&procuid, pid); + + argv = glibtop_get_proc_argv (&procargs, pid, 0); + if (argv != NULL) { + if (argv[0] != NULL) + fullPath = String::New (argv[0]); + + for (int i = 0; argv[i]; i++) { + arguments->Set (i, String::New(argv[i])); + } + } + + v8::Handle procInfo = v8::Object::New(); + procInfo->Set(String::New("pid"), Integer::New(pid)); + procInfo->Set(String::New("uid"), Integer::New(procuid.uid)); + procInfo->Set(String::New("gid"), Integer::New(procuid.gid)); + procInfo->Set(String::New("command"), String::New (procstate.cmd)); + procInfo->Set(String::New("fullPath"), fullPath); + procInfo->Set(String::New("argv"), arguments); + procInfo->Set(String::New("state"), format_process_state (procstate.state)); + + if (argv != NULL) + g_strfreev (argv); + + return (procInfo); +} + +/** + * getProcesses: + * + * Returns: Array of currently running processes. + * FIXME: make "Returns:" more explicit. + */ +Handle getProcesses (const Arguments& args) { + HandleScope scope; + pid_t* pidArray = NULL; + glibtop_proclist procList; +// GPtrArray *array; + GError *err = NULL; + v8::Handle procInfo; + v8::Handle result = v8::Array::New(); + + // FIXME (JS): maybe make use of Arguments &args to shape the process list. + // Possible values for which = all vs. user vs. group + // Possible values for arg = 0 vs. user id vs. group id + // + gint64 which = GLIBTOP_KERN_PROC_ALL; + gint64 arg = 0; + + pidArray = glibtop_get_proclist (&procList, which, arg); + + for (unsigned int i=0; iSet (i, procInfo); + } + if (pidArray != NULL) + g_free (pidArray); + + return scope.Close (result); +} + +void init(Handle target) { + // Safe to call glibtop_init() since it does nothing if already initialized, + // and it returns a pointer to the glibtop structure. + glibtopPtr = glibtop_init(); + + target->Set(String::NewSymbol("getProcesses"), + FunctionTemplate::New(getProcesses)->GetFunction()); +} + +NODE_MODULE(nodeprocesses, init) + diff --git a/gpii/node_modules/processes/nodeprocesses/nodeprocesses_test.js b/gpii/node_modules/processes/nodeprocesses/nodeprocesses_test.js new file mode 100644 index 0000000..bf1cbe8 --- /dev/null +++ b/gpii/node_modules/processes/nodeprocesses/nodeprocesses_test.js @@ -0,0 +1,79 @@ +/*! +GPII Node.js Processes Bridge + +Copyright 2014 Inclusive Design Research Centre, OCAD University + +Licensed under the New BSD license. You may not use this file except in +compliance with this License. + +You may obtain a copy of the License at +https://github.com/gpii/universal/LICENSE.txt +*/ + +/*global require*/ + +var fluid = require ("universal"), + jqUnit = fluid.require ("jqUnit"), + processes = require ("./build/Release/nodeprocesses.node"); + +(function() { + "use strict"; + + var procTests = fluid.registerNamespace ("gpii.tests.processes"); + + // Return the process info object that matches the given command string. + procTests.matchProcByCommand = function (commandName, procArray) { + return fluid.find (procArray, function (procInfo) { + if (procInfo.command === commandName) { + return procInfo; + } + }, null); + }; + + jqUnit.module ("Processes Bridge node add-on module"); + + jqUnit.test ( + "Test getProceses() with 'node' (has to be a running process)", + function() { + var procInfos = processes.getProcesses(); + jqUnit.assertNotEquals ( + "Getting all processes", 0, procInfos.length + ); + // Check for the presence of "node" processs itself -- it must be in + // the process list since this code is running inside the node + // process. + var found = procTests.matchProcByCommand ("node", procInfos); + jqUnit.assertTrue ("Searching for 'node' process", found); + }); + + jqUnit.test ( + "Test getProceses() against nodejs's own global process object.", + function() { + var procInfos = processes.getProcesses(); + var nodeProcInfo = procTests.matchProcByCommand ("node", procInfos); + jqUnit.assertEquals ("Node process 'pid'", + process.pid, nodeProcInfo.pid); + + jqUnit.assertEquals ("Node process 'uid'", + process.getuid(), nodeProcInfo.uid); + + jqUnit.assertEquals ("Node process 'gid'", + process.getgid(), nodeProcInfo.gid); + + jqUnit.assertEquals ("Node process 'name'", + process.title, nodeProcInfo.command); + + jqUnit.assertEquals ("Node process 'argv' length'", + process.argv.length, nodeProcInfo.argv.length); + + jqUnit.assertEquals ("Node process status", + "Running", nodeProcInfo.state); + + // Loop to compare nodejs argument vector against the one found by + // by procTests.getProcesses(). + for (var i = 0; i < process.argv.length; i++) { + jqUnit.assertEquals ("Node process 'argv[" + i + "]'", + process.argv[i], nodeProcInfo.argv[i]); + } + }); +}()); \ No newline at end of file diff --git a/gpii/node_modules/processes/package.json b/gpii/node_modules/processes/package.json new file mode 100644 index 0000000..439888a --- /dev/null +++ b/gpii/node_modules/processes/package.json @@ -0,0 +1,19 @@ +{ + "name": "processesBridge", + "description": "The processesBridge is a Node.js add-on using Libgtop.", + "version": "0.1.0", + "author": "Joseph Scheuhammer", + "bugs": "http://wiki.gpii.net/index.php/Main_Page", + "homepage": "http://gpii.net/", + "dependencies": {}, + "licenses": [ + { + "type": "BSD-3-Clause", + "url": "http://www.opensource.org/licenses/BSD-3-Clause" + } + ], + "keywords": ["gpii", "accessibility", "processes", "fluid", "linux"], + "repository": "git://github.com:GPII/linux.git", + "main": "./index.js", + "engines": { "node" : ">=0.8" } +} From 8cad47667c5b7965b78c8f6dd5f3effb02108971 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Wed, 10 Sep 2014 11:45:47 -0400 Subject: [PATCH 02/78] GPII-442: Updated README.md Fixed code blocks to display with newlines. --- gpii/node_modules/processes/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gpii/node_modules/processes/README.md b/gpii/node_modules/processes/README.md index b3ed10f..b100277 100644 --- a/gpii/node_modules/processes/README.md +++ b/gpii/node_modules/processes/README.md @@ -17,7 +17,7 @@ Or, by hand: Notes ----- - +``` var procArray = nodeprocess.getProcesses(); @@ -39,7 +39,7 @@ A proccess is represented by the following structure (using orca as an example): argv: [ '/usr/bin/python3', '/usr/bin/orca' ], state: 'Sleeping' } - +``` The state member can be one of: * Running * Stopped From 9e34eb5d5ba0dbfc2e95d2ff871ed01ea419a479 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Mon, 22 Sep 2014 12:13:07 -0400 Subject: [PATCH 03/78] GPII-442: Detect running solutions. Firmed up the c++ code for the 'nodeprocesse' add-on: simply a bridge to gnome/linux library to generate a list of processes and information about each. Added numerous unit tests for the above, where most of the tests use an object that provides an API for processes. Next step: carve out the relevant functions into a non-test object that provides the same API. --- .../processes/nodeprocesses/nodeprocesses.cc | 40 ++--- .../nodeprocesses/nodeprocesses_test.js | 154 ++++++++++++++++-- 2 files changed, 154 insertions(+), 40 deletions(-) diff --git a/gpii/node_modules/processes/nodeprocesses/nodeprocesses.cc b/gpii/node_modules/processes/nodeprocesses/nodeprocesses.cc index 0b51dc9..587c5e1 100644 --- a/gpii/node_modules/processes/nodeprocesses/nodeprocesses.cc +++ b/gpii/node_modules/processes/nodeprocesses/nodeprocesses.cc @@ -18,22 +18,19 @@ You may obtain a copy of the License at #include #include #include -//#include +#include using namespace v8; static glibtop* glibtopPtr = NULL; -// static std::basic_string -// utf8StringFromValue(v8::Handle value) -// { -// v8::Local string = value->ToString(); -// gchar *buffer = g_new(gchar, string->Utf8Length()); -// string->WriteUtf8(buffer); -// return buffer; -// } +const char* STATE_RUNNING = "Running"; +const char* STATE_STOPPED = "Stopped"; +const char* STATE_ZOMBIE = "Zombie"; +const char* STATE_UNINTERRUPTIBLE = "Uninterruptible"; +const char* STATE_SLEEPING = "Sleeping"; -v8::Local +static v8::Local format_process_state (guint state) { v8::Local status; @@ -41,23 +38,23 @@ format_process_state (guint state) switch (state) { case GLIBTOP_PROCESS_RUNNING: - status = String::New ("Running"); + status = String::New (STATE_RUNNING); break; case GLIBTOP_PROCESS_STOPPED: - status = String::New ("Stopped"); + status = String::New (STATE_STOPPED); break; case GLIBTOP_PROCESS_ZOMBIE: - status = String::New ("Zombie"); + status = String::New (STATE_ZOMBIE); break; case GLIBTOP_PROCESS_UNINTERRUPTIBLE: - status = String::New ("Uninterruptible"); + status = String::New (STATE_UNINTERRUPTIBLE); break; default: - status = String::New ("Sleeping"); + status = String::New (STATE_SLEEPING); break; } return status; @@ -88,10 +85,11 @@ makeProcInfo (pid_t pid, glibtop_proclist* procList) { } v8::Handle procInfo = v8::Object::New(); - procInfo->Set(String::New("pid"), Integer::New(pid)); - procInfo->Set(String::New("uid"), Integer::New(procuid.uid)); - procInfo->Set(String::New("gid"), Integer::New(procuid.gid)); procInfo->Set(String::New("command"), String::New (procstate.cmd)); + procInfo->Set(String::New("pid"), Integer::New (pid)); + procInfo->Set(String::New("ppid"), Integer::New (procuid.ppid)); + procInfo->Set(String::New("uid"), Integer::New (procuid.uid)); + procInfo->Set(String::New("gid"), Integer::New (procuid.gid)); procInfo->Set(String::New("fullPath"), fullPath); procInfo->Set(String::New("argv"), arguments); procInfo->Set(String::New("state"), format_process_state (procstate.state)); @@ -112,15 +110,9 @@ Handle getProcesses (const Arguments& args) { HandleScope scope; pid_t* pidArray = NULL; glibtop_proclist procList; -// GPtrArray *array; - GError *err = NULL; v8::Handle procInfo; v8::Handle result = v8::Array::New(); - // FIXME (JS): maybe make use of Arguments &args to shape the process list. - // Possible values for which = all vs. user vs. group - // Possible values for arg = 0 vs. user id vs. group id - // gint64 which = GLIBTOP_KERN_PROC_ALL; gint64 arg = 0; diff --git a/gpii/node_modules/processes/nodeprocesses/nodeprocesses_test.js b/gpii/node_modules/processes/nodeprocesses/nodeprocesses_test.js index bf1cbe8..eac7808 100644 --- a/gpii/node_modules/processes/nodeprocesses/nodeprocesses_test.js +++ b/gpii/node_modules/processes/nodeprocesses/nodeprocesses_test.js @@ -13,44 +13,121 @@ https://github.com/gpii/universal/LICENSE.txt /*global require*/ var fluid = require ("universal"), + gpii = fluid.registerNamespace ("gpii"), jqUnit = fluid.require ("jqUnit"), processes = require ("./build/Release/nodeprocesses.node"); + // TODO: Must be a better way to get node gsettings add-on. + // something like 'fluid.require ("gsettingsBridge", require);' + var nodeGSettings = require("../../gsettingsBridge//nodegsettings/build/Release/nodegsettings.node"); + (function() { "use strict"; var procTests = fluid.registerNamespace ("gpii.tests.processes"); // Return the process info object that matches the given command string. + // Note that it can return "null" meaning there is no such process running. procTests.matchProcByCommand = function (commandName, procArray) { - return fluid.find (procArray, function (procInfo) { - if (procInfo.command === commandName) { - return procInfo; - } - }, null); + if (!procArray) { + procArray = processes.getProcesses(); + } + return fluid.find (procArray, function (procInfo) { + if (procInfo.command === commandName) { + return procInfo; + } + }, null); + }; + + // Return the process info object that matches the given process id. + // Note that it can return "null" meaning there is no such process running. + procTests.matchProcByPid = function (pid, procArray) { + if (!procArray) { + procArray = processes.getProcesses(); + } + return fluid.find (procArray, function (procInfo) { + if (procInfo.pid === pid) { + return procInfo; + } + }, null); + }; + + // TODO: (JS, 16-Sep-2014) Consider creating a standalone "process" object + // (fluid component ?) to encapsulate these procTests methods. + + // Determine if the state of the given process has changed. Return truthy: + // - if the state has not changed, return false. + // - if the state has changed, return the new state. Special case: a + // process that has been killed isn't in the list; return "NoSuchProcess". + procTests.hasStateChanged = function (procInfo) { + if (!procInfo) { + console.log ("hasStateChanged() called on null procinfo"); + return false; // ? nothing sought === nothing changed. + } + console.log ("hasStateChanged() called on " + procInfo.command + ", given state is " + procInfo.state); + var procArray = processes.getProcesses(); + var theProc = procTests.matchProcByPid (procInfo.pid, procArray); + + // Case: process not in the current list, implies state changed. but... + if (theProc === null) { + if (procInfo.state === "NoSuchProcess") { + console.log ("CASE 1A"); + return false; + } + else { + console.log ("CASE 1B"); + return "NoSuchProcess"; + } + } + + // Case: Process is (still) in the list and has the same state. + else if (theProc.state === procInfo.state) { + console.log ("CASE 2"); + return false; + } + + // Case: Process is (still) in the list, but has a different state. + else { + console.log ("CASE 3"); + return theProc.state; + } + } + + // Delay 10 seconds. + procTests.wait10sec = function() { + var t0 = Date.now(); + var longEnough = false; + while (!longEnough) { + longEnough = ((Date.now() - t0) > 10000); + } }; jqUnit.module ("Processes Bridge node add-on module"); jqUnit.test ( - "Test getProceses() with 'node' (has to be a running process)", + "Test getProceses() with 'node' (the nodejs process itself)", function() { var procInfos = processes.getProcesses(); jqUnit.assertNotEquals ( "Getting all processes", 0, procInfos.length ); - // Check for the presence of "node" processs itself -- it must be in - // the process list since this code is running inside the node + + // Check for the presence of this nodejs processs itself -- it must + // be in the process list since this code is running inside that // process. - var found = procTests.matchProcByCommand ("node", procInfos); - jqUnit.assertTrue ("Searching for 'node' process", found); + var nodeProc = procTests.matchProcByPid (process.pid, procInfos); + jqUnit.assertNotNull ("Searching for 'node' process", nodeProc); }); jqUnit.test ( - "Test getProceses() against nodejs's own global process object.", + "Test getProceses() against nodejs's own process object.", function() { var procInfos = processes.getProcesses(); - var nodeProcInfo = procTests.matchProcByCommand ("node", procInfos); + var nodeProcInfo = procTests.matchProcByPid (process.pid, procInfos); + jqUnit.assertEquals ("Node process 'name'", + process.title, nodeProcInfo.command); + + // TODO: Mildly redundant? This is how it was found. jqUnit.assertEquals ("Node process 'pid'", process.pid, nodeProcInfo.pid); @@ -60,9 +137,6 @@ var fluid = require ("universal"), jqUnit.assertEquals ("Node process 'gid'", process.getgid(), nodeProcInfo.gid); - jqUnit.assertEquals ("Node process 'name'", - process.title, nodeProcInfo.command); - jqUnit.assertEquals ("Node process 'argv' length'", process.argv.length, nodeProcInfo.argv.length); @@ -72,8 +146,56 @@ var fluid = require ("universal"), // Loop to compare nodejs argument vector against the one found by // by procTests.getProcesses(). for (var i = 0; i < process.argv.length; i++) { + if (i != 1) { jqUnit.assertEquals ("Node process 'argv[" + i + "]'", process.argv[i], nodeProcInfo.argv[i]); + } + } + }); + + // TODO: (JS, 16-Sep-2014) Not really a test, but the beginnings of how + // to actually use a "process" object to monitor the state of the + // processes-of-interest. + // TODO: This test assumes orca is running at the start. Need to launch + // it here first as necessary. + jqUnit.test ( + "Test getProceses() against launching orca.", + function() { + var wasRunning = true; + var orcaProc = procTests.matchProcByCommand ("orca"); + if (orcaProc == null) { + wasRunning = false; + var status = nodeGSettings.set_gsetting ( + "org.gnome.desktop.a11y.applications", + "screen-reader-enabled", true); + + // Give orca some time to start an initialize itself. Then look for + // the 'orca' process. + procTests.wait10sec(); + orcaProc = procTests.matchProcByCommand ("orca"); } + jqUnit.assertNotNull ("Orca is running", orcaProc); + + // Shutting orca down will change the state. + // Need to wait, say one second, for orca to shut down. + status = nodeGSettings.set_gsetting ( + "org.gnome.desktop.a11y.applications", + "screen-reader-enabled", false); + + // Give orca some time to shut itself down. Then look for + // the process whose id matches the running 'orca' process from + // above. + procTests.wait10sec(); + var orcaProcNewState = procTests.matchProcByPid (orcaProc.id); + jqUnit.assertNull ("Orca no longer running", orcaProcNewState); + + var newState = procTests.hasStateChanged (orcaProc); + jqUnit.assertEquals ("Orca process changed state", "NoSuchProcess", newState); + + // Clean up. + if (wasRunning) + nodeGSettings.set_gsetting ("org.gnome.desktop.a11y.applications", + "screen-reader-enabled", true); }); -}()); \ No newline at end of file + +}()); From e129e6684628a27adfb477ae9f0d53775fff9685 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Mon, 22 Sep 2014 15:16:39 -0400 Subject: [PATCH 04/78] GPII-442: Detect running solutions Using nodejs path.basename() for one of the tests. Linting nodeprocesses_test.js --- .../nodeprocesses/nodeprocesses_test.js | 74 ++++++++----------- 1 file changed, 31 insertions(+), 43 deletions(-) diff --git a/gpii/node_modules/processes/nodeprocesses/nodeprocesses_test.js b/gpii/node_modules/processes/nodeprocesses/nodeprocesses_test.js index eac7808..8caef86 100644 --- a/gpii/node_modules/processes/nodeprocesses/nodeprocesses_test.js +++ b/gpii/node_modules/processes/nodeprocesses/nodeprocesses_test.js @@ -12,8 +12,8 @@ https://github.com/gpii/universal/LICENSE.txt /*global require*/ -var fluid = require ("universal"), - gpii = fluid.registerNamespace ("gpii"), +var path = require ("path"), + fluid = require ("universal"), jqUnit = fluid.require ("jqUnit"), processes = require ("./build/Release/nodeprocesses.node"); @@ -61,37 +61,26 @@ var fluid = require ("universal"), // process that has been killed isn't in the list; return "NoSuchProcess". procTests.hasStateChanged = function (procInfo) { if (!procInfo) { - console.log ("hasStateChanged() called on null procinfo"); - return false; // ? nothing sought === nothing changed. + return false; // nothing sought === nothing changed. } - console.log ("hasStateChanged() called on " + procInfo.command + ", given state is " + procInfo.state); var procArray = processes.getProcesses(); var theProc = procTests.matchProcByPid (procInfo.pid, procArray); - // Case: process not in the current list, implies state changed. but... + // Case: process not in the current list, implies no longer running. if (theProc === null) { - if (procInfo.state === "NoSuchProcess") { - console.log ("CASE 1A"); - return false; - } - else { - console.log ("CASE 1B"); - return "NoSuchProcess"; - } + return "NoSuchProcess"; } // Case: Process is (still) in the list and has the same state. else if (theProc.state === procInfo.state) { - console.log ("CASE 2"); return false; } // Case: Process is (still) in the list, but has a different state. else { - console.log ("CASE 3"); return theProc.state; } - } + }; // Delay 10 seconds. procTests.wait10sec = function() { @@ -127,7 +116,7 @@ var fluid = require ("universal"), jqUnit.assertEquals ("Node process 'name'", process.title, nodeProcInfo.command); - // TODO: Mildly redundant? This is how it was found. + // TODO: Redundant? This is how it was found. jqUnit.assertEquals ("Node process 'pid'", process.pid, nodeProcInfo.pid); @@ -144,58 +133,57 @@ var fluid = require ("universal"), "Running", nodeProcInfo.state); // Loop to compare nodejs argument vector against the one found by - // by procTests.getProcesses(). + // by procTests.getProcesses(). Note that the linux add-on (libgtop) + // returns only the basename for argv[1], whereas node has the full + // path. Compare using Path.basename(). for (var i = 0; i < process.argv.length; i++) { - if (i != 1) { - jqUnit.assertEquals ("Node process 'argv[" + i + "]'", - process.argv[i], nodeProcInfo.argv[i]); + var processArg = process.argv[i]; + if (i === 1) { + processArg = path.basename (processArg); } + jqUnit.assertEquals ("Node process 'argv[" + i + "]'", + processArg, nodeProcInfo.argv[i]); } }); // TODO: (JS, 16-Sep-2014) Not really a test, but the beginnings of how // to actually use a "process" object to monitor the state of the // processes-of-interest. - // TODO: This test assumes orca is running at the start. Need to launch - // it here first as necessary. jqUnit.test ( "Test getProceses() against launching orca.", function() { var wasRunning = true; var orcaProc = procTests.matchProcByCommand ("orca"); - if (orcaProc == null) { + if (orcaProc === null) { wasRunning = false; - var status = nodeGSettings.set_gsetting ( - "org.gnome.desktop.a11y.applications", - "screen-reader-enabled", true); - // Give orca some time to start an initialize itself. Then look for - // the 'orca' process. + // Start orca + nodeGSettings.set_gsetting ( "org.gnome.desktop.a11y.applications", + "screen-reader-enabled", true ); + // Give orca some time to start and initialize itself. Then look + // for the 'orca' process. procTests.wait10sec(); - orcaProc = procTests.matchProcByCommand ("orca"); + orcaProc = procTests.matchProcByCommand ("orca"); } jqUnit.assertNotNull ("Orca is running", orcaProc); - // Shutting orca down will change the state. - // Need to wait, say one second, for orca to shut down. - status = nodeGSettings.set_gsetting ( - "org.gnome.desktop.a11y.applications", - "screen-reader-enabled", false); - - // Give orca some time to shut itself down. Then look for - // the process whose id matches the running 'orca' process from - // above. + // Quit orca. + nodeGSettings.set_gsetting ( "org.gnome.desktop.a11y.applications", + "screen-reader-enabled", false ); + // Give orca some time to quit itself. Then look for the process + // whose id matches the running 'orca' process from above. procTests.wait10sec(); var orcaProcNewState = procTests.matchProcByPid (orcaProc.id); jqUnit.assertNull ("Orca no longer running", orcaProcNewState); var newState = procTests.hasStateChanged (orcaProc); - jqUnit.assertEquals ("Orca process changed state", "NoSuchProcess", newState); + jqUnit.assertEquals ("Orca process changed state", + "NoSuchProcess", newState); // Clean up. - if (wasRunning) + if (wasRunning) { nodeGSettings.set_gsetting ("org.gnome.desktop.a11y.applications", "screen-reader-enabled", true); + } }); - }()); From 9bbdd0f3bcdb0d3c10044424817d5be0d6ff1366 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Tue, 23 Sep 2014 13:46:38 -0400 Subject: [PATCH 05/78] GPII-442: Detect running solutions First checkin of processes object for querying running processes, checking their state, and reporting changes. --- gpii/node_modules/processes/processes.js | 120 +++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 gpii/node_modules/processes/processes.js diff --git a/gpii/node_modules/processes/processes.js b/gpii/node_modules/processes/processes.js new file mode 100644 index 0000000..51ae878 --- /dev/null +++ b/gpii/node_modules/processes/processes.js @@ -0,0 +1,120 @@ +/*! +GPII Processes Bridge -- gpii.processes. + +Copyright 2014 Inclusive Design Research Centre, OCAD University + +Licensed under the New BSD license. You may not use this file except in +compliance with this License. + +You may obtain a copy of the License at +https://github.com/gpii/universal/LICENSE.txt +*/ + +/*global require */ + +(function() { + "use strict"; + + var fluid = require ("universal"); + var gpii = fluid.registerNamespace ("gpii"); + var nodeProcesses = require ("./nodeprocesses/build/Release/nodeprocesses.node"); + + var processes = fluid.registerNamespace ("gpii.processes"); + + // Return a list of processes -- a snapshot of the current processes. + processes.getProcesses = function() { + return nodeProcesses.getProcesses(); + }; + + // Return THE process info object that matches the given process id. + // Note that it can return "null" meaning there is no such process. + processes.findProcessByPid = function (pid, procArray) { + if (!procArray) { + procArray = processes.getProcesses(); + } + return fluid.find (procArray, function (procInfo) { + if (procInfo.pid === pid) { + return procInfo; + } + }, null); + }; + + // Return an an array of process information objects that match the given + // command name string. Note that it can return an empty array, meaning + // there is no such process. + processes.findProcessesByCommand = function (commandName, procArray) { + if (!procArray) { + procArray = processes.getProcesses(); + } + return fluid.accumulate (procArray, function (aProcInfo, matchingProcs) { + if (aProcInfo.command === commandName) { + matchingProcs.push (aProcInfo); + } + return matchingProcs; + }, []); + }; + + // Determine if the state of the given process has changed. Return truthy: + // - if the state has not changed, return false. + // - if the state has changed, return the new state. Special case: a + // process that has been killed isn't in the processes list; return + // "NoSuchProcess". + processes.hasStateChanged = function (procInfo) { + if (!procInfo) { + console.log ("hasStateChanged() called on null procinfo"); + return false; // nothing sought === nothing changed. + } + console.log ("hasStateChanged() called on " + procInfo.command + ", given state is " + procInfo.state); + var procArray = processes.getProcesses(); + var theProc = processes.findProcessByPid (procInfo.pid, procArray); + + // Case: process not in the current list, implies state changed to being + // quit or killed. + if (theProc === null) { + return "NoSuchProcess"; + } + + // Case: Process is (still) in the list and has the same state. + else if (theProc.state === procInfo.state) { + return false; + } + + else { + return theProc.state; + } + }; + + // Renew the information on a proces, or create a new one. Returns null if + // no such process is running. + processes.refreshProcInfo = function (pid) { + var procArray = processes.getProcesses(); + return processes.findProcessByPid (pid, procArray); + }; + + // Create a monitor object for passing to a setInterval() to periodically + // check for chanages in the status of a process. + processes.initMonitor = function() { + var monitor = {}; + monitor.intervalID = -1; + monitor.stateChanged = false; + monitor.newState = false; + + return monitor; + }; + + // Callback to pass to setInterval() to periodically check the state of a + // process. + processes.monitorChanged = function (procInfo, monitor) { + var newState = processes.hasStateChanged (procInfo); + console.log ("processes.monitorChanged(): is " + newState); + if (newState) { + monitor.stateChanged = true; + monitor.newState = newState; + console.log ("NEW STATE! ==> " + monitor.newState); + + clearInterval (monitor.intervalID); // Here? + } + }; + + return processes; +}()); \ No newline at end of file From cd99c1380e81c87d7fd625c257a94f04686df625 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Tue, 23 Sep 2014 13:55:30 -0400 Subject: [PATCH 06/78] GPII-442: Detect running solutions Modified processes.js to use full gpii.processes name. Added procDemo.js to show how to detect a change in state for orca. --- gpii/node_modules/processes/procDemo.js | 36 ++++++++++++++++++++++++ gpii/node_modules/processes/processes.js | 34 +++++++++++----------- 2 files changed, 53 insertions(+), 17 deletions(-) create mode 100644 gpii/node_modules/processes/procDemo.js diff --git a/gpii/node_modules/processes/procDemo.js b/gpii/node_modules/processes/procDemo.js new file mode 100644 index 0000000..52d26c1 --- /dev/null +++ b/gpii/node_modules/processes/procDemo.js @@ -0,0 +1,36 @@ +/*! +GPII Prcoess Bridge Demo. + +Copyright 2014 Inclusive Design Research Centre, OCAD University + +Licensed under the New BSD license. You may not use this file except in +compliance with this License. + +You may obtain a copy of the License at +https://github.com/gpii/universal/LICENSE.txt +*/ + +/*global require */ +"use strict"; + +var fluid = require("universal"); +require ("./processes.js"); + +var processes = fluid.registerNamespace ("gpii.processes"); + +// Start up orca BEFORE running this demo. + +// This result is an array, but interested only in the first one. +var orcaProcs = processes.findProcessesByCommand ("orca"); +if (orcaProcs.length > 0) { + var orcaProc = orcaProcs[0]; + + var orcaMonitor = processes.initMonitor(); + + // Periodically check if Orca has quit. + orcaMonitor.intervalID = setInterval (function() { + processes.monitorChanged (orcaProc, orcaMonitor); + }); +} +console.log ("processes = " + processes); +console.log ("Waiting..."); diff --git a/gpii/node_modules/processes/processes.js b/gpii/node_modules/processes/processes.js index 51ae878..f44b9e6 100644 --- a/gpii/node_modules/processes/processes.js +++ b/gpii/node_modules/processes/processes.js @@ -19,18 +19,18 @@ https://github.com/gpii/universal/LICENSE.txt var gpii = fluid.registerNamespace ("gpii"); var nodeProcesses = require ("./nodeprocesses/build/Release/nodeprocesses.node"); - var processes = fluid.registerNamespace ("gpii.processes"); + gpii.processes = fluid.registerNamespace ("gpii.processes"); // Return a list of processes -- a snapshot of the current processes. - processes.getProcesses = function() { + gpii.processes.getProcesses = function() { return nodeProcesses.getProcesses(); }; // Return THE process info object that matches the given process id. // Note that it can return "null" meaning there is no such process. - processes.findProcessByPid = function (pid, procArray) { + gpii.processes.findProcessByPid = function (pid, procArray) { if (!procArray) { - procArray = processes.getProcesses(); + procArray = gpii.processes.getProcesses(); } return fluid.find (procArray, function (procInfo) { if (procInfo.pid === pid) { @@ -42,9 +42,9 @@ https://github.com/gpii/universal/LICENSE.txt // Return an an array of process information objects that match the given // command name string. Note that it can return an empty array, meaning // there is no such process. - processes.findProcessesByCommand = function (commandName, procArray) { + gpii.processes.findProcessesByCommand = function (commandName, procArray) { if (!procArray) { - procArray = processes.getProcesses(); + procArray = gpii.processes.getProcesses(); } return fluid.accumulate (procArray, function (aProcInfo, matchingProcs) { if (aProcInfo.command === commandName) { @@ -59,14 +59,14 @@ https://github.com/gpii/universal/LICENSE.txt // - if the state has changed, return the new state. Special case: a // process that has been killed isn't in the processes list; return // "NoSuchProcess". - processes.hasStateChanged = function (procInfo) { + gpii.processes.hasStateChanged = function (procInfo) { if (!procInfo) { console.log ("hasStateChanged() called on null procinfo"); return false; // nothing sought === nothing changed. } console.log ("hasStateChanged() called on " + procInfo.command + ", given state is " + procInfo.state); - var procArray = processes.getProcesses(); - var theProc = processes.findProcessByPid (procInfo.pid, procArray); + var procArray = gpii.processes.getProcesses(); + var theProc = gpii.processes.findProcessByPid (procInfo.pid, procArray); // Case: process not in the current list, implies state changed to being // quit or killed. @@ -86,14 +86,14 @@ https://github.com/gpii/universal/LICENSE.txt // Renew the information on a proces, or create a new one. Returns null if // no such process is running. - processes.refreshProcInfo = function (pid) { - var procArray = processes.getProcesses(); - return processes.findProcessByPid (pid, procArray); + gpii.processes.refreshProcInfo = function (pid) { + var procArray = gpii.processes.getProcesses(); + return gpii.processes.findProcessByPid (pid, procArray); }; // Create a monitor object for passing to a setInterval() to periodically // check for chanages in the status of a process. - processes.initMonitor = function() { + gpii.processes.initMonitor = function() { var monitor = {}; monitor.intervalID = -1; monitor.stateChanged = false; @@ -104,9 +104,9 @@ https://github.com/gpii/universal/LICENSE.txt // Callback to pass to setInterval() to periodically check the state of a // process. - processes.monitorChanged = function (procInfo, monitor) { - var newState = processes.hasStateChanged (procInfo); - console.log ("processes.monitorChanged(): is " + newState); + gpii.processes.monitorChanged = function (procInfo, monitor) { + var newState = gpii.processes.hasStateChanged (procInfo); + console.log ("gpii.processes.monitorChanged(): is " + newState); if (newState) { monitor.stateChanged = true; monitor.newState = newState; @@ -116,5 +116,5 @@ https://github.com/gpii/universal/LICENSE.txt } }; - return processes; + return gpii.processes; }()); \ No newline at end of file From 63f909625b5ebb6de7a728f8605b7098c48f0967 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Wed, 24 Sep 2014 11:26:47 -0400 Subject: [PATCH 07/78] GPII-442: Detect running solutions. Added ability to start with a non-running process, and detect when it launches. --- gpii/node_modules/processes/procDemo.js | 15 ++++----- gpii/node_modules/processes/processes.js | 39 ++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/gpii/node_modules/processes/procDemo.js b/gpii/node_modules/processes/procDemo.js index 52d26c1..7a872dd 100644 --- a/gpii/node_modules/processes/procDemo.js +++ b/gpii/node_modules/processes/procDemo.js @@ -21,16 +21,17 @@ var processes = fluid.registerNamespace ("gpii.processes"); // Start up orca BEFORE running this demo. // This result is an array, but interested only in the first one. +var orcaProc = processes.initNotRunning ("orca"); var orcaProcs = processes.findProcessesByCommand ("orca"); if (orcaProcs.length > 0) { - var orcaProc = orcaProcs[0]; + orcaProc = orcaProcs[0]; +} +var orcaMonitor = processes.initMonitor(); - var orcaMonitor = processes.initMonitor(); +// Periodically check if Orca has quit. +orcaMonitor.intervalID = setInterval (function() { + processes.monitorChanged (orcaProc, orcaMonitor); +}); - // Periodically check if Orca has quit. - orcaMonitor.intervalID = setInterval (function() { - processes.monitorChanged (orcaProc, orcaMonitor); - }); -} console.log ("processes = " + processes); console.log ("Waiting..."); diff --git a/gpii/node_modules/processes/processes.js b/gpii/node_modules/processes/processes.js index f44b9e6..e21cb02 100644 --- a/gpii/node_modules/processes/processes.js +++ b/gpii/node_modules/processes/processes.js @@ -66,12 +66,30 @@ https://github.com/gpii/universal/LICENSE.txt } console.log ("hasStateChanged() called on " + procInfo.command + ", given state is " + procInfo.state); var procArray = gpii.processes.getProcesses(); - var theProc = gpii.processes.findProcessByPid (procInfo.pid, procArray); + + var theProc = null; + if (procInfo.state === "NoSuchProcess") { + var running = gpii.processes.findProcessesByCommand (procInfo.command); + if (running.length > 0) { + theProc = running[0]; + } + } + else { + theProc = gpii.processes.findProcessByPid (procInfo.pid, procArray); + } - // Case: process not in the current list, implies state changed to being - // quit or killed. + // Case: process not in the current list ... + // - if procInfo.state is anything but "NoSuchProcess", then new state is + // no longer running (it quit). + // - if procInfo.state is "NoSuchProcess", then the process has not + // started -- no change in state. if (theProc === null) { + if (procInfo.state === "NoSuchProcess") { + return false; + } + else { return "NoSuchProcess"; + } } // Case: Process is (still) in the list and has the same state. @@ -91,6 +109,21 @@ https://github.com/gpii/universal/LICENSE.txt return gpii.processes.findProcessByPid (pid, procArray); }; + // Create information on a non-running process, to use to detect when the + // process starts. + gpii.processes.initNotRunning = function (command) { + var process = {}; + process.command = command; + process.pid = -1; + process.ppid = -1; + process.uid = -1; + process.gid = -1; + process.fullPath = ""; + process.argv = ""; + process.state = "NoSuchProcess"; + return process; + }; + // Create a monitor object for passing to a setInterval() to periodically // check for chanages in the status of a process. gpii.processes.initMonitor = function() { From 16c0591900cd8d42a2e3e79a8aa8206ee373b3b9 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Wed, 24 Sep 2014 11:35:57 -0400 Subject: [PATCH 08/78] GPII-442: Detect running solutions. Whitespace cleanup and other tidying. --- gpii/node_modules/processes/processes.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/gpii/node_modules/processes/processes.js b/gpii/node_modules/processes/processes.js index e21cb02..32536bd 100644 --- a/gpii/node_modules/processes/processes.js +++ b/gpii/node_modules/processes/processes.js @@ -57,16 +57,15 @@ https://github.com/gpii/universal/LICENSE.txt // Determine if the state of the given process has changed. Return truthy: // - if the state has not changed, return false. // - if the state has changed, return the new state. Special case: a - // process that has been killed isn't in the processes list; return + // process that has quit isn't in the processes list; return // "NoSuchProcess". gpii.processes.hasStateChanged = function (procInfo) { if (!procInfo) { console.log ("hasStateChanged() called on null procinfo"); return false; // nothing sought === nothing changed. } - console.log ("hasStateChanged() called on " + procInfo.command + ", given state is " + procInfo.state); var procArray = gpii.processes.getProcesses(); - + var theProc = null; if (procInfo.state === "NoSuchProcess") { var running = gpii.processes.findProcessesByCommand (procInfo.command); @@ -77,7 +76,6 @@ https://github.com/gpii/universal/LICENSE.txt else { theProc = gpii.processes.findProcessByPid (procInfo.pid, procArray); } - // Case: process not in the current list ... // - if procInfo.state is anything but "NoSuchProcess", then new state is // no longer running (it quit). @@ -91,12 +89,11 @@ https://github.com/gpii/universal/LICENSE.txt return "NoSuchProcess"; } } - // Case: Process is (still) in the list and has the same state. else if (theProc.state === procInfo.state) { return false; } - + // Case: Process is (still) in the list and has a new state. else { return theProc.state; } @@ -124,14 +121,13 @@ https://github.com/gpii/universal/LICENSE.txt return process; }; - // Create a monitor object for passing to a setInterval() to periodically - // check for chanages in the status of a process. + // Create a monitor object for passing to a functiona that periodically + // checks for chanages in the state of a process. gpii.processes.initMonitor = function() { var monitor = {}; monitor.intervalID = -1; monitor.stateChanged = false; monitor.newState = false; - return monitor; }; From 28edabfcbea6b1b99142ec3f7488d0b05c6be656 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Fri, 26 Sep 2014 16:49:07 -0400 Subject: [PATCH 09/78] GPII-442: Detect running solutions. Added ability to continuously check the state of a process and report when it changes from "running" to "not running" OR from "not running" to "running". --- gpii/node_modules/processes/procDemo.js | 36 ++++++-- gpii/node_modules/processes/processes.js | 106 +++++++++++++++++++++-- 2 files changed, 127 insertions(+), 15 deletions(-) diff --git a/gpii/node_modules/processes/procDemo.js b/gpii/node_modules/processes/procDemo.js index 7a872dd..f607de1 100644 --- a/gpii/node_modules/processes/procDemo.js +++ b/gpii/node_modules/processes/procDemo.js @@ -13,25 +13,47 @@ https://github.com/gpii/universal/LICENSE.txt /*global require */ "use strict"; +var readline = require ("readline"); var fluid = require("universal"); require ("./processes.js"); -var processes = fluid.registerNamespace ("gpii.processes"); +var jobs = fluid.registerNamespace ("gpii.processes"); -// Start up orca BEFORE running this demo. +var seekInput = readline.createInterface ({ + input: process.stdin, + output: process.stdout +}); // This result is an array, but interested only in the first one. -var orcaProc = processes.initNotRunning ("orca"); -var orcaProcs = processes.findProcessesByCommand ("orca"); +var orcaProc = jobs.initNotRunning ("orca"); +var orcaProcs = jobs.findProcessesByCommand ("orca"); if (orcaProcs.length > 0) { orcaProc = orcaProcs[0]; } -var orcaMonitor = processes.initMonitor(); +var orcaMonitor = jobs.initMonitor (orcaProc); // Periodically check if Orca has quit. +// orcaMonitor.intervalID = setInterval (function() { +// jobs.monitorChanged (orcaProc, orcaMonitor); +// }); + +// Periodically check if Orca has changed state. orcaMonitor.intervalID = setInterval (function() { - processes.monitorChanged (orcaProc, orcaMonitor); + jobs.monitorRunningChanged (orcaMonitor); }); -console.log ("processes = " + processes); +console.log ("jobs = " + jobs); +console.log ("periodical: " + orcaMonitor.intervalID); console.log ("Waiting..."); + +seekInput.question ("Stop? ", function (answer) { + console.log ("You said " + answer); + if (answer === "yes") { + console.log ("Okay, stopping"); + clearInterval (orcaMonitor.intervalID); + seekInput.close(); + } + else { + console.log ("Okay, continuing"); + } +}); diff --git a/gpii/node_modules/processes/processes.js b/gpii/node_modules/processes/processes.js index 32536bd..666c2b3 100644 --- a/gpii/node_modules/processes/processes.js +++ b/gpii/node_modules/processes/processes.js @@ -39,7 +39,7 @@ https://github.com/gpii/universal/LICENSE.txt }, null); }; - // Return an an array of process information objects that match the given + // Return an array of process information objects that match the given // command name string. Note that it can return an empty array, meaning // there is no such process. gpii.processes.findProcessesByCommand = function (commandName, procArray) { @@ -54,6 +54,19 @@ https://github.com/gpii/universal/LICENSE.txt }, []); }; + // Return the first process of an array of processes all with the same + // command name string. If there are no matching processes, return null. + gpii.processes.findFirstProcessByCommand = + function (commandName, procArray) { + var commands = gpii.processes.findProcessesByCommand (commandName, procArray); + if (commands.length > 0) { + return commands[0]; + } + else { + return null; + } + }; + // Determine if the state of the given process has changed. Return truthy: // - if the state has not changed, return false. // - if the state has changed, return the new state. Special case: a @@ -99,11 +112,67 @@ https://github.com/gpii/universal/LICENSE.txt } }; - // Renew the information on a proces, or create a new one. Returns null if - // no such process is running. - gpii.processes.refreshProcInfo = function (pid) { - var procArray = gpii.processes.getProcesses(); - return gpii.processes.findProcessByPid (pid, procArray); + // Utility function to conflate process state values into "Running" + // (= true) vs. "Not Running" (= false). Returns boolean. + gpii.processes.isRunning = function (state) { + var result; + switch (state) { + case "Running": + case "Uninterruptible": + case "Sleeping": + case "Stopped": + result = true; + break; + + case "Zombie": + case "NoSuchProcess": + default: + result = false; + } + return result; + }; + + // Determine if the state of the given process has changed from + // "not running" to "running" OR from "running" to "not running". + // Return an object { switched, newProcInfo }. + // - if the state has not changed, switch = false. + // - if the state has changed, switch = true. Special case: a + // process that has quit isn't in the processes list; return + // "NoSuchProcess". + gpii.processes.hasSwitchedRunState = function (monitor) { + if (!monitor.procInfo) { + // nothing sought === nothing changed. +// return { runStateChanged: false, newProcInfo: null }; + return false; + } + var newInfo = null; + if (monitor.procInfo.state === "NoSuchProcess") { + newInfo = gpii.processes.findFirstProcessByCommand (monitor.procInfo.command); + } + else { + newInfo = gpii.processes.findProcessByPid (monitor.procInfo.pid); + } + var wasRunning = gpii.processes.isRunning (monitor.procInfo.state); + var isRunning = ( newInfo !== null ? + gpii.processes.isRunning (newInfo.state) : + false ); + monitor.newProcInfo = newInfo; + return (isRunning !== wasRunning); + }; + + // Renew the information on a process, or create a new "NoSuchProcces". + gpii.processes.refreshProcInfo = function (procInfo) { + var newProcInfo = null; + if (procInfo.state === "NoSuchProcess") { + newProcInfo = gpii.processes.findFirstProcessByCommand (procInfo.command); + } + else { + newProcInfo = gpii.processes.findProcessByPid (procInfo.pid); + } + if (newProcInfo === null) { + newProcInfo = gpii.processes.initNotRunning (procInfo.command); + } + return newProcInfo; }; // Create information on a non-running process, to use to detect when the @@ -123,11 +192,13 @@ https://github.com/gpii/universal/LICENSE.txt // Create a monitor object for passing to a functiona that periodically // checks for chanages in the state of a process. - gpii.processes.initMonitor = function() { + gpii.processes.initMonitor = function (procInfo) { var monitor = {}; monitor.intervalID = -1; monitor.stateChanged = false; monitor.newState = false; + monitor.procInfo = procInfo; + monitor.newProcInfo = null; return monitor; }; @@ -145,5 +216,24 @@ https://github.com/gpii/universal/LICENSE.txt } }; - return gpii.processes; + // Callback to pass to setInterval() to periodically check when the state + // changes from "running" to "not running" and vice versa. + gpii.processes.monitorRunningChanged = function (monitor) { + + // Check for switch in running state. If changed, refresh the processs + // information. + if (gpii.processes.hasSwitchedRunState (monitor)) { + var oldState = monitor.procInfo.state; + if (monitor.newProcInfo === null) { + monitor.procInfo = gpii.processes.initNotRunning (monitor.procInfo.command); + } + else { + monitor.procInfo = monitor.newProcInfo; + } + monitor.stateChanged = true; + monitor.newState = monitor.procInfo.state; + console.log ("SWITCHED from " + oldState + " to " + monitor.newState); + console.log (""); + } + }; }()); \ No newline at end of file From 23189c5870ca8e4d2f58928cc79be6a74dc954c1 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Fri, 26 Sep 2014 16:57:27 -0400 Subject: [PATCH 10/78] GPII-442: Detect running solutions. Cleaned up comments. --- gpii/node_modules/processes/processes.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/gpii/node_modules/processes/processes.js b/gpii/node_modules/processes/processes.js index 666c2b3..b3c247e 100644 --- a/gpii/node_modules/processes/processes.js +++ b/gpii/node_modules/processes/processes.js @@ -134,15 +134,10 @@ https://github.com/gpii/universal/LICENSE.txt // Determine if the state of the given process has changed from // "not running" to "running" OR from "running" to "not running". - // Return an object { switched, newProcInfo }. - // - if the state has not changed, switch = false. - // - if the state has changed, switch = true. Special case: a - // process that has quit isn't in the processes list; return - // "NoSuchProcess". + // Return boolean. gpii.processes.hasSwitchedRunState = function (monitor) { if (!monitor.procInfo) { // nothing sought === nothing changed. -// return { runStateChanged: false, newProcInfo: null }; return false; } var newInfo = null; From 21b2720855b5af9a035c86a090e4cd621c88a1e7 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Tue, 30 Sep 2014 12:36:26 -0400 Subject: [PATCH 11/78] GPII-442: Detect running solutions -- Nodejs events. First pass at integrate node's event systme to fire an event when the process switches between running and not running, and vice versa. --- gpii/node_modules/processes/procDemo.js | 12 +++++++- gpii/node_modules/processes/processes.js | 36 +++++++++++++++--------- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/gpii/node_modules/processes/procDemo.js b/gpii/node_modules/processes/procDemo.js index f607de1..a38b0cf 100644 --- a/gpii/node_modules/processes/procDemo.js +++ b/gpii/node_modules/processes/procDemo.js @@ -24,13 +24,21 @@ var seekInput = readline.createInterface ({ output: process.stdout }); +var stateChangeHandler = function (procInfo) { + console.log (procInfo.command + ": run state switched to " + procInfo.state + + " (" + + ( jobs.isRunning (procInfo.state) ? "Running" : "Stopped" ) + + ")"); +}; + // This result is an array, but interested only in the first one. var orcaProc = jobs.initNotRunning ("orca"); var orcaProcs = jobs.findProcessesByCommand ("orca"); if (orcaProcs.length > 0) { orcaProc = orcaProcs[0]; } -var orcaMonitor = jobs.initMonitor (orcaProc); +jobs.trackRunState (stateChangeHandler); + // Periodically check if Orca has quit. // orcaMonitor.intervalID = setInterval (function() { @@ -38,6 +46,7 @@ var orcaMonitor = jobs.initMonitor (orcaProc); // }); // Periodically check if Orca has changed state. +var orcaMonitor = jobs.initMonitor (orcaProc); orcaMonitor.intervalID = setInterval (function() { jobs.monitorRunningChanged (orcaMonitor); }); @@ -51,6 +60,7 @@ seekInput.question ("Stop? ", function (answer) { if (answer === "yes") { console.log ("Okay, stopping"); clearInterval (orcaMonitor.intervalID); + jobs.stopTrackingRunState (stateChangeHandler); seekInput.close(); } else { diff --git a/gpii/node_modules/processes/processes.js b/gpii/node_modules/processes/processes.js index b3c247e..b2695b3 100644 --- a/gpii/node_modules/processes/processes.js +++ b/gpii/node_modules/processes/processes.js @@ -15,11 +15,13 @@ https://github.com/gpii/universal/LICENSE.txt (function() { "use strict"; + var events = require ("events"); var fluid = require ("universal"); var gpii = fluid.registerNamespace ("gpii"); var nodeProcesses = require ("./nodeprocesses/build/Release/nodeprocesses.node"); gpii.processes = fluid.registerNamespace ("gpii.processes"); + var startStopNotify = new events.EventEmitter(); // Return a list of processes -- a snapshot of the current processes. gpii.processes.getProcesses = function() { @@ -58,7 +60,8 @@ https://github.com/gpii/universal/LICENSE.txt // command name string. If there are no matching processes, return null. gpii.processes.findFirstProcessByCommand = function (commandName, procArray) { - var commands = gpii.processes.findProcessesByCommand (commandName, procArray); + var commands = + gpii.processes.findProcessesByCommand (commandName, procArray); if (commands.length > 0) { return commands[0]; } @@ -74,7 +77,6 @@ https://github.com/gpii/universal/LICENSE.txt // "NoSuchProcess". gpii.processes.hasStateChanged = function (procInfo) { if (!procInfo) { - console.log ("hasStateChanged() called on null procinfo"); return false; // nothing sought === nothing changed. } var procArray = gpii.processes.getProcesses(); @@ -124,10 +126,11 @@ https://github.com/gpii/universal/LICENSE.txt result = true; break; + default: case "Zombie": case "NoSuchProcess": - default: result = false; + break; } return result; }; @@ -190,7 +193,6 @@ https://github.com/gpii/universal/LICENSE.txt gpii.processes.initMonitor = function (procInfo) { var monitor = {}; monitor.intervalID = -1; - monitor.stateChanged = false; monitor.newState = false; monitor.procInfo = procInfo; monitor.newProcInfo = null; @@ -201,12 +203,8 @@ https://github.com/gpii/universal/LICENSE.txt // process. gpii.processes.monitorChanged = function (procInfo, monitor) { var newState = gpii.processes.hasStateChanged (procInfo); - console.log ("gpii.processes.monitorChanged(): is " + newState); if (newState) { - monitor.stateChanged = true; monitor.newState = newState; - console.log ("NEW STATE! ==> " + monitor.newState); - clearInterval (monitor.intervalID); // Here? } }; @@ -218,17 +216,29 @@ https://github.com/gpii/universal/LICENSE.txt // Check for switch in running state. If changed, refresh the processs // information. if (gpii.processes.hasSwitchedRunState (monitor)) { - var oldState = monitor.procInfo.state; if (monitor.newProcInfo === null) { monitor.procInfo = gpii.processes.initNotRunning (monitor.procInfo.command); } else { monitor.procInfo = monitor.newProcInfo; } - monitor.stateChanged = true; monitor.newState = monitor.procInfo.state; - console.log ("SWITCHED from " + oldState + " to " + monitor.newState); - console.log (""); + startStopNotify.emit ("switchedRunState", monitor.procInfo); } }; -}()); \ No newline at end of file + + // ======================= + // Nodejs event processing + // ======================= + + // Provide a way for the outside world to pass in a handler for the + // "switchedRunState", and to cancel. + gpii.processes.trackRunState = function (handler) { + startStopNotify.on ("switchedRunState", handler); + }; + + gpii.processes.stopTrackingRunState = function (handler) { + startStopNotify.removeListener ("switchedRunState", handler); + }; + +}()); From 48ef1d03754e2dfa4ce01cfb33f1c4b805e720ec Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Tue, 30 Sep 2014 12:48:28 -0400 Subject: [PATCH 12/78] GPII-442: Detect running solutions. Renamed gpii.processes.refreshPrcoInfo() to gpii.processes.updateProcInfo(), and made use of it. --- gpii/node_modules/processes/processes.js | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/gpii/node_modules/processes/processes.js b/gpii/node_modules/processes/processes.js index b2695b3..77861ce 100644 --- a/gpii/node_modules/processes/processes.js +++ b/gpii/node_modules/processes/processes.js @@ -143,23 +143,15 @@ https://github.com/gpii/universal/LICENSE.txt // nothing sought === nothing changed. return false; } - var newInfo = null; - if (monitor.procInfo.state === "NoSuchProcess") { - newInfo = gpii.processes.findFirstProcessByCommand (monitor.procInfo.command); - } - else { - newInfo = gpii.processes.findProcessByPid (monitor.procInfo.pid); - } + monitor.newProcInfo = gpii.processes.updateProcInfo (monitor.procInfo); var wasRunning = gpii.processes.isRunning (monitor.procInfo.state); - var isRunning = ( newInfo !== null ? - gpii.processes.isRunning (newInfo.state) : - false ); - monitor.newProcInfo = newInfo; + var isRunning = gpii.processes.isRunning (monitor.newProcInfo.state); return (isRunning !== wasRunning); }; // Renew the information on a process, or create a new "NoSuchProcces". - gpii.processes.refreshProcInfo = function (procInfo) { + // Returns a new procInfo structure. + gpii.processes.updateProcInfo = function (procInfo) { var newProcInfo = null; if (procInfo.state === "NoSuchProcess") { newProcInfo = gpii.processes.findFirstProcessByCommand (procInfo.command); From 477687fc23259833cdfa14c5d92fd8cd279cff96 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Tue, 30 Sep 2014 16:51:08 -0400 Subject: [PATCH 13/78] GPII-442: Detect running solutions -- simplify interface. Simplify the interface for setting up monitoring a process and responding to events. --- gpii/node_modules/processes/procDemo.js | 18 +++-------------- gpii/node_modules/processes/processes.js | 25 ++++++++++++++++++++---- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/gpii/node_modules/processes/procDemo.js b/gpii/node_modules/processes/procDemo.js index a38b0cf..09e2dc7 100644 --- a/gpii/node_modules/processes/procDemo.js +++ b/gpii/node_modules/processes/procDemo.js @@ -37,30 +37,18 @@ var orcaProcs = jobs.findProcessesByCommand ("orca"); if (orcaProcs.length > 0) { orcaProc = orcaProcs[0]; } -jobs.trackRunState (stateChangeHandler); - - -// Periodically check if Orca has quit. -// orcaMonitor.intervalID = setInterval (function() { -// jobs.monitorChanged (orcaProc, orcaMonitor); -// }); - -// Periodically check if Orca has changed state. -var orcaMonitor = jobs.initMonitor (orcaProc); -orcaMonitor.intervalID = setInterval (function() { - jobs.monitorRunningChanged (orcaMonitor); -}); +var intervalID = jobs.trackRunState (orcaProc, stateChangeHandler); console.log ("jobs = " + jobs); -console.log ("periodical: " + orcaMonitor.intervalID); +console.log ("periodical: " + intervalID); console.log ("Waiting..."); seekInput.question ("Stop? ", function (answer) { console.log ("You said " + answer); if (answer === "yes") { console.log ("Okay, stopping"); - clearInterval (orcaMonitor.intervalID); jobs.stopTrackingRunState (stateChangeHandler); + clearInterval (intervalID); seekInput.close(); } else { diff --git a/gpii/node_modules/processes/processes.js b/gpii/node_modules/processes/processes.js index 77861ce..e0833cc 100644 --- a/gpii/node_modules/processes/processes.js +++ b/gpii/node_modules/processes/processes.js @@ -180,7 +180,7 @@ https://github.com/gpii/universal/LICENSE.txt return process; }; - // Create a monitor object for passing to a functiona that periodically + // Create a monitor object for passing to a function that periodically // checks for chanages in the state of a process. gpii.processes.initMonitor = function (procInfo) { var monitor = {}; @@ -204,9 +204,21 @@ https://github.com/gpii/universal/LICENSE.txt // Callback to pass to setInterval() to periodically check when the state // changes from "running" to "not running" and vice versa. gpii.processes.monitorRunningChanged = function (monitor) { + if (gpii.processes.hasSwitchedRunState (monitor)) { + if (monitor.newProcInfo === null) { + monitor.procInfo = gpii.processes.initNotRunning (monitor.procInfo.command); + } + else { + monitor.procInfo = monitor.newProcInfo; + } + monitor.newState = monitor.procInfo.state; + startStopNotify.emit ("switchedRunState", monitor.procInfo); + } + }; - // Check for switch in running state. If changed, refresh the processs - // information. + // Callback to pass to setInterval() to periodically check when the state + // changes from "running" to "not running" and vice versa. + gpii.processes.monitorRunningChanged = function (monitor) { if (gpii.processes.hasSwitchedRunState (monitor)) { if (monitor.newProcInfo === null) { monitor.procInfo = gpii.processes.initNotRunning (monitor.procInfo.command); @@ -225,8 +237,13 @@ https://github.com/gpii/universal/LICENSE.txt // Provide a way for the outside world to pass in a handler for the // "switchedRunState", and to cancel. - gpii.processes.trackRunState = function (handler) { + gpii.processes.trackRunState = function (procInfo, handler) { + var monitor = gpii.processes.initMonitor (procInfo); + monitor.intervalID = setInterval (function() { + gpii.processes.monitorRunningChanged (monitor); + }); startStopNotify.on ("switchedRunState", handler); + return monitor.intervalID; }; gpii.processes.stopTrackingRunState = function (handler) { From 57fadc62ce6d9ca6ef5dbc644d24c6f2fd15afde Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Thu, 2 Oct 2014 16:23:01 -0400 Subject: [PATCH 14/78] GPII-442: New processes.js object; moved and improved unit tests. Moved most of the unit tests that were in nodeprocesses_test.js for the nodeprocesses add-on to a processes_test.js to test the new processes.js. The latter contains the machinery for inspecting processes, and, specifically, their state. --- .../nodeprocesses/nodeprocesses_test.js | 111 +------- gpii/node_modules/processes/procDemo.js | 38 ++- gpii/node_modules/processes/processes.js | 25 +- gpii/node_modules/processes/processes_test.js | 262 ++++++++++++++++++ 4 files changed, 295 insertions(+), 141 deletions(-) create mode 100644 gpii/node_modules/processes/processes_test.js diff --git a/gpii/node_modules/processes/nodeprocesses/nodeprocesses_test.js b/gpii/node_modules/processes/nodeprocesses/nodeprocesses_test.js index 8caef86..664eef2 100644 --- a/gpii/node_modules/processes/nodeprocesses/nodeprocesses_test.js +++ b/gpii/node_modules/processes/nodeprocesses/nodeprocesses_test.js @@ -12,33 +12,16 @@ https://github.com/gpii/universal/LICENSE.txt /*global require*/ +(function() { + "use strict"; + var path = require ("path"), fluid = require ("universal"), jqUnit = fluid.require ("jqUnit"), processes = require ("./build/Release/nodeprocesses.node"); - // TODO: Must be a better way to get node gsettings add-on. - // something like 'fluid.require ("gsettingsBridge", require);' - var nodeGSettings = require("../../gsettingsBridge//nodegsettings/build/Release/nodegsettings.node"); - -(function() { - "use strict"; - var procTests = fluid.registerNamespace ("gpii.tests.processes"); - // Return the process info object that matches the given command string. - // Note that it can return "null" meaning there is no such process running. - procTests.matchProcByCommand = function (commandName, procArray) { - if (!procArray) { - procArray = processes.getProcesses(); - } - return fluid.find (procArray, function (procInfo) { - if (procInfo.command === commandName) { - return procInfo; - } - }, null); - }; - // Return the process info object that matches the given process id. // Note that it can return "null" meaning there is no such process running. procTests.matchProcByPid = function (pid, procArray) { @@ -52,45 +35,6 @@ var path = require ("path"), }, null); }; - // TODO: (JS, 16-Sep-2014) Consider creating a standalone "process" object - // (fluid component ?) to encapsulate these procTests methods. - - // Determine if the state of the given process has changed. Return truthy: - // - if the state has not changed, return false. - // - if the state has changed, return the new state. Special case: a - // process that has been killed isn't in the list; return "NoSuchProcess". - procTests.hasStateChanged = function (procInfo) { - if (!procInfo) { - return false; // nothing sought === nothing changed. - } - var procArray = processes.getProcesses(); - var theProc = procTests.matchProcByPid (procInfo.pid, procArray); - - // Case: process not in the current list, implies no longer running. - if (theProc === null) { - return "NoSuchProcess"; - } - - // Case: Process is (still) in the list and has the same state. - else if (theProc.state === procInfo.state) { - return false; - } - - // Case: Process is (still) in the list, but has a different state. - else { - return theProc.state; - } - }; - - // Delay 10 seconds. - procTests.wait10sec = function() { - var t0 = Date.now(); - var longEnough = false; - while (!longEnough) { - longEnough = ((Date.now() - t0) > 10000); - } - }; - jqUnit.module ("Processes Bridge node add-on module"); jqUnit.test ( @@ -104,15 +48,8 @@ var path = require ("path"), // Check for the presence of this nodejs processs itself -- it must // be in the process list since this code is running inside that // process. - var nodeProc = procTests.matchProcByPid (process.pid, procInfos); - jqUnit.assertNotNull ("Searching for 'node' process", nodeProc); - }); - - jqUnit.test ( - "Test getProceses() against nodejs's own process object.", - function() { - var procInfos = processes.getProcesses(); var nodeProcInfo = procTests.matchProcByPid (process.pid, procInfos); + jqUnit.assertNotNull ("Searching for 'node' process", nodeProcInfo); jqUnit.assertEquals ("Node process 'name'", process.title, nodeProcInfo.command); @@ -146,44 +83,4 @@ var path = require ("path"), } }); - // TODO: (JS, 16-Sep-2014) Not really a test, but the beginnings of how - // to actually use a "process" object to monitor the state of the - // processes-of-interest. - jqUnit.test ( - "Test getProceses() against launching orca.", - function() { - var wasRunning = true; - var orcaProc = procTests.matchProcByCommand ("orca"); - if (orcaProc === null) { - wasRunning = false; - - // Start orca - nodeGSettings.set_gsetting ( "org.gnome.desktop.a11y.applications", - "screen-reader-enabled", true ); - // Give orca some time to start and initialize itself. Then look - // for the 'orca' process. - procTests.wait10sec(); - orcaProc = procTests.matchProcByCommand ("orca"); - } - jqUnit.assertNotNull ("Orca is running", orcaProc); - - // Quit orca. - nodeGSettings.set_gsetting ( "org.gnome.desktop.a11y.applications", - "screen-reader-enabled", false ); - // Give orca some time to quit itself. Then look for the process - // whose id matches the running 'orca' process from above. - procTests.wait10sec(); - var orcaProcNewState = procTests.matchProcByPid (orcaProc.id); - jqUnit.assertNull ("Orca no longer running", orcaProcNewState); - - var newState = procTests.hasStateChanged (orcaProc); - jqUnit.assertEquals ("Orca process changed state", - "NoSuchProcess", newState); - - // Clean up. - if (wasRunning) { - nodeGSettings.set_gsetting ("org.gnome.desktop.a11y.applications", - "screen-reader-enabled", true); - } - }); }()); diff --git a/gpii/node_modules/processes/procDemo.js b/gpii/node_modules/processes/procDemo.js index 09e2dc7..761b639 100644 --- a/gpii/node_modules/processes/procDemo.js +++ b/gpii/node_modules/processes/procDemo.js @@ -17,37 +17,47 @@ var readline = require ("readline"); var fluid = require("universal"); require ("./processes.js"); -var jobs = fluid.registerNamespace ("gpii.processes"); +var processes = fluid.registerNamespace ("gpii.processes"); var seekInput = readline.createInterface ({ input: process.stdin, output: process.stdout }); +// Handler for processes to use to detect change from "not running" to "running" +// or "running" to "not running". For this demo, just print the new run state +// on the console. var stateChangeHandler = function (procInfo) { - console.log (procInfo.command + ": run state switched to " + procInfo.state + - " (" + - ( jobs.isRunning (procInfo.state) ? "Running" : "Stopped" ) + - ")"); + console.log ( + procInfo.command + ": run state switched to " + procInfo.state + + " (" + + ( processes.isRunning (procInfo.state) ? "Running" : "Stopped" ) + + ")" + ); }; -// This result is an array, but interested only in the first one. -var orcaProc = jobs.initNotRunning ("orca"); -var orcaProcs = jobs.findProcessesByCommand ("orca"); -if (orcaProcs.length > 0) { - orcaProc = orcaProcs[0]; +// Initial assumption: not running. Then look for any running orca process. +var orcaProcInfo = processes.initNotRunning ("orca"); +var orcaProcInfos = processes.findProcessesByCommand ("orca"); +if (orcaProcInfos.length > 0) { + orcaProcInfo = orcaProcInfos[0]; } -var intervalID = jobs.trackRunState (orcaProc, stateChangeHandler); -console.log ("jobs = " + jobs); -console.log ("periodical: " + intervalID); +// Start the periodic check of the change in run-state for orca. +// To see any changes, state/stop orca using, say, the accessibility menu, or +// the command line: +// gsettings set org.gnome.desktop.a11y.applications screen-reader-enabled true/false +var intervalID = processes.trackRunState (orcaProcInfo, stateChangeHandler); + console.log ("Waiting..."); seekInput.question ("Stop? ", function (answer) { console.log ("You said " + answer); if (answer === "yes") { console.log ("Okay, stopping"); - jobs.stopTrackingRunState (stateChangeHandler); + + // Cease periodic check of orca's run-state. + processes.stopTrackingRunState (stateChangeHandler, intervalID); clearInterval (intervalID); seekInput.close(); } diff --git a/gpii/node_modules/processes/processes.js b/gpii/node_modules/processes/processes.js index e0833cc..439e75d 100644 --- a/gpii/node_modules/processes/processes.js +++ b/gpii/node_modules/processes/processes.js @@ -139,7 +139,7 @@ https://github.com/gpii/universal/LICENSE.txt // "not running" to "running" OR from "running" to "not running". // Return boolean. gpii.processes.hasSwitchedRunState = function (monitor) { - if (!monitor.procInfo) { + if (!monitor || !monitor.procInfo) { // nothing sought === nothing changed. return false; } @@ -191,28 +191,12 @@ https://github.com/gpii/universal/LICENSE.txt return monitor; }; - // Callback to pass to setInterval() to periodically check the state of a - // process. + // Callback to pass to, e.g., setInterval() to periodically check the state + // of a process. gpii.processes.monitorChanged = function (procInfo, monitor) { var newState = gpii.processes.hasStateChanged (procInfo); if (newState) { monitor.newState = newState; - clearInterval (monitor.intervalID); // Here? - } - }; - - // Callback to pass to setInterval() to periodically check when the state - // changes from "running" to "not running" and vice versa. - gpii.processes.monitorRunningChanged = function (monitor) { - if (gpii.processes.hasSwitchedRunState (monitor)) { - if (monitor.newProcInfo === null) { - monitor.procInfo = gpii.processes.initNotRunning (monitor.procInfo.command); - } - else { - monitor.procInfo = monitor.newProcInfo; - } - monitor.newState = monitor.procInfo.state; - startStopNotify.emit ("switchedRunState", monitor.procInfo); } }; @@ -246,8 +230,9 @@ https://github.com/gpii/universal/LICENSE.txt return monitor.intervalID; }; - gpii.processes.stopTrackingRunState = function (handler) { + gpii.processes.stopTrackingRunState = function (handler, intervalID) { startStopNotify.removeListener ("switchedRunState", handler); + clearInterval (intervalID); }; }()); diff --git a/gpii/node_modules/processes/processes_test.js b/gpii/node_modules/processes/processes_test.js new file mode 100644 index 0000000..7122937 --- /dev/null +++ b/gpii/node_modules/processes/processes_test.js @@ -0,0 +1,262 @@ +/*! +GPII Node.js Processes Bridge + +Copyright 2014 Inclusive Design Research Centre, OCAD University + +Licensed under the New BSD license. You may not use this file except in +compliance with this License. + +You may obtain a copy of the License at +https://github.com/gpii/universal/LICENSE.txt +*/ + +/*global require*/ + +(function() { + "use strict"; + + var path = require ("path"), + spawn = require("child_process").spawn, + fluid = require ("universal"), + jqUnit = fluid.require ("jqUnit"), + + // TODO: Must be a better way to get node gsettings add-on. + nodeGSettings = require ("../gsettingsBridge/nodegsettings/build/Release/nodegsettings.node"); + require ("./processes.js"); + + var processes = fluid.registerNamespace ("gpii.processes"); + var procTests = fluid.registerNamespace ("gpii.tests.processes"); + + // Delay 5 seconds. + procTests.wait5sec = function() { + var t0 = Date.now(); + var longEnough = false; + while (!longEnough) { + longEnough = ((Date.now() - t0) > 5000); + } + }; + + jqUnit.module ("Processes Bridge node add-on module"); + jqUnit.test ( + "Test getProceses()/findProcessByPid() with the nodejs process itself", + function() { + var procInfos = processes.getProcesses(); + jqUnit.assertNotEquals ( + "Listing all processes", 0, procInfos.length + ); + + // Check for the presence of this nodejs processs itself -- it must + // be in the process list since this code is running inside that + // process. + var nodeProc = processes.findProcessByPid (process.pid, procInfos); + jqUnit.assertNotNull ("Searching for 'node' process", nodeProc); + }); + + jqUnit.test ( + "Test findProcessByPid() with non-running process id", + function() { + jqUnit.assertNull ( + "Search negative process id value", processes.findProcessByPid (-1) + ); + }); + + jqUnit.test ( + "Test findProcessByPid() against nodejs's own process object.", + function() { + var nodeProcInfo = processes.findProcessByPid (process.pid); + jqUnit.assertEquals ("Node process 'name'", + process.title, nodeProcInfo.command); + + // Redundant? This is how it was found. + jqUnit.assertEquals ("Node process 'pid'", + process.pid, nodeProcInfo.pid); + + jqUnit.assertEquals ("Node process 'uid'", + process.getuid(), nodeProcInfo.uid); + + jqUnit.assertEquals ("Node process 'gid'", + process.getgid(), nodeProcInfo.gid); + + jqUnit.assertEquals ("Node process 'argv' length'", + process.argv.length, nodeProcInfo.argv.length); + + jqUnit.assertEquals ("Node process status", + "Running", nodeProcInfo.state); + + // Loop to compare nodejs argument vector against the one found by + // by procTests.getProcesses(). Note that the linux's libgtop + // returns only the basename for argv[1], whereas node has the full + // path. Compare using Path.basename(). + for (var i = 0; i < process.argv.length; i++) { + var processArg = process.argv[i]; + if (i === 1) { + processArg = path.basename (processArg); + } + jqUnit.assertEquals ("Node process 'argv[" + i + "]'", + processArg, nodeProcInfo.argv[i]); + } + }); + + jqUnit.test ( + "Test findProcessesByCmd()/findFirstProcessByCmd() with nodejs itself", + function() { + var nodeProcInfos = processes.findProcessesByCommand ("node"); + jqUnit.assertNotEquals ( + "Getting all 'node' processes", 0, nodeProcInfos.length + ); + nodeProcInfos.forEach (function (aProcInfo) { + jqUnit.assertEquals ( + "Node commmand name", "node", aProcInfo.command + ); + }); + var procInfo = processes.findFirstProcessByCommand ("node"); + jqUnit.assertNotNull ("Looking for first 'node' processes", procInfo); + jqUnit.assertEquals ("Node commmand name", "node", procInfo.command); + }); + + jqUnit.test ( + "Test initNotRunning()", + function() { + var notRunning = processes.initNotRunning ("grep"); + jqUnit.assertEquals ("Command name", notRunning.command, "grep"); + jqUnit.assertEquals ("Negative process id", notRunning.pid, -1); + jqUnit.assertEquals ( + "'NoSuchProcess' state", notRunning.state, "NoSuchProcess" + ); + jqUnit.assertNull ( + "Search negative process id value", + processes.findProcessByPid (notRunning.pid) + ); + }); + + jqUnit.test ( + "Test isRunning() with nodejs itself, and nonexistent process", + function() { + var procInfo = processes.findProcessByPid (process.pid); + jqUnit.assertNotNull ("Searching for 'node' process", procInfo); + jqUnit.assertTrue ( + "Check nodejs is running", processes.isRunning (procInfo.state) + ); + procInfo = processes.initNotRunning ("grep"); + jqUnit.assertFalse ( + "Check nonexistent process running", processes.isRunning (procInfo) + ); + }); + + jqUnit.test ( + "Test updateProcInfo() against non-changing process", + function() { + var procInfo = processes.findProcessByPid (process.pid); + jqUnit.assertNotNull ("Looking for 'node' processes", procInfo); + var newProcInfo = processes.updateProcInfo (procInfo); + jqUnit.assertDeepEq ( + "Check change in process info", procInfo, newProcInfo + ); + }); + + jqUnit.test ( + "Test updateProcInfo() against changing process", + function() { + var grep = spawn ("grep", ["ssh"]); + var grepInfo = processes.findProcessByPid (grep.pid); + jqUnit.assertNotNull ("Search 'grep' process", grepInfo); + jqUnit.assertTrue ("Stop grep", grep.kill ("SIGHUP")); + var newGrepInfo = processes.updateProcInfo (grepInfo); + jqUnit.assertNotEquals ( + "Update process state", newGrepInfo.state, grepInfo.state + ); + }); + + jqUnit.test ( + "Test hasStateChanged()", + function() { + jqUnit.assertFalse ( + "Check null process", processes.hasStateChanged (null) + ); + var catProcInfo = processes.initNotRunning ("cat"); + var stateChanged = processes.hasStateChanged (catProcInfo); + jqUnit.assertFalse ("Check non-running process", stateChanged); + + var cat = spawn ("cat"); + stateChanged = processes.hasStateChanged (catProcInfo); + jqUnit.assertTrue ("Check running process", stateChanged !== false); + + // Get the running process info, kill cat, and check again. + catProcInfo = processes.findProcessByPid (cat.pid); + cat.kill ("SIGHUP"); + stateChanged = processes.hasStateChanged (catProcInfo); + jqUnit.assertTrue ("Check stopped process", stateChanged !== false); + }); + + jqUnit.test ( + "Test hasSwitchedRunState()", + function() { + jqUnit.assertFalse ( + "Check null monitor", processes.hasSwitchedRunState (null) + ); + var grepProcMonitor = processes.initMonitor (null); + jqUnit.assertFalse ( + "Check null process", processes.hasSwitchedRunState (grepProcMonitor) + ); + var grep = spawn ("grep", ["ssh"]); + var grepProcInfo = processes.findProcessByPid (grep.pid); + grepProcMonitor = processes.initMonitor (grepProcInfo); + var switched = processes.hasSwitchedRunState (grepProcMonitor); + jqUnit.assertFalse ("Check running process", switched); + jqUnit.assertEquals ( + "Process state change", + grepProcInfo.state, grepProcMonitor.newProcInfo.state + ); + // Kill grep, and check again. + grep.kill ("SIGHUP"); + switched = processes.hasSwitchedRunState (grepProcMonitor); + jqUnit.assertTrue ("Check stopped process", switched); + jqUnit.assertNotEquals ( + "Process state change", + grepProcInfo.state, grepProcMonitor.newProcInfo.state + ); + }); + + // Test real life scenario: Use the GPII's gsettings bridge to launch + // and shut down orca, and track the changes in state. + jqUnit.test ( + "Test getProceses() against launching orca.", + function() { + var orcaProcInfo = processes.findFirstProcessByCommand ("orca"); + var wasRunning = (orcaProcInfo !== null); + // Start orca -- does nothing if orca is already running. + nodeGSettings.set_gsetting ( + "org.gnome.desktop.a11y.applications","screen-reader-enabled", true + ); + // Give orca some time to start and initialize itself. Then look + // for the 'orca' process. + procTests.wait5sec(); + orcaProcInfo = processes.findFirstProcessByCommand ("orca"); + jqUnit.assertNotNull ("Orca is running", orcaProcInfo); + + // Quit orca, giving it some time to quit itself. Then look for the + // process whose id matches the formerly running 'orca' process. + nodeGSettings.set_gsetting ( + "org.gnome.desktop.a11y.applications", "screen-reader-enabled", false + ); + procTests.wait5sec(); + var orcaProcNewState = processes.findProcessByPid (orcaProcInfo.pid); + jqUnit.assertNull ("Orca no longer running", orcaProcNewState); + var newState = processes.hasStateChanged (orcaProcInfo); + jqUnit.assertEquals ( + "Orca process changed state", "NoSuchProcess", newState + ); + // Clean up. + if (wasRunning) { + nodeGSettings.set_gsetting ( + "org.gnome.desktop.a11y.applications", + "screen-reader-enabled", true + ); + } + }); + +}()); + + + + From 2ec341230dd064ba6fcb6708e8560507f09aac8d Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Tue, 7 Oct 2014 12:24:24 -0400 Subject: [PATCH 15/78] GPII-442: Use fluid event system. Replaced Nodejs event emitter object with fluid event firer. Tweaked some of the function names. --- gpii/node_modules/processes/processes.js | 34 +++++++++---------- gpii/node_modules/processes/processes_test.js | 8 ++--- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/gpii/node_modules/processes/processes.js b/gpii/node_modules/processes/processes.js index 439e75d..e0e4814 100644 --- a/gpii/node_modules/processes/processes.js +++ b/gpii/node_modules/processes/processes.js @@ -15,13 +15,12 @@ https://github.com/gpii/universal/LICENSE.txt (function() { "use strict"; - var events = require ("events"); var fluid = require ("universal"); var gpii = fluid.registerNamespace ("gpii"); var nodeProcesses = require ("./nodeprocesses/build/Release/nodeprocesses.node"); gpii.processes = fluid.registerNamespace ("gpii.processes"); - var startStopNotify = new events.EventEmitter(); + var startStopNotify = fluid.makeEventFirer(); // Return a list of processes -- a snapshot of the current processes. gpii.processes.getProcesses = function() { @@ -58,7 +57,7 @@ https://github.com/gpii/universal/LICENSE.txt // Return the first process of an array of processes all with the same // command name string. If there are no matching processes, return null. - gpii.processes.findFirstProcessByCommand = + gpii.processes.findFirstProcessByCommand = function (commandName, procArray) { var commands = gpii.processes.findProcessesByCommand (commandName, procArray); @@ -160,14 +159,14 @@ https://github.com/gpii/universal/LICENSE.txt newProcInfo = gpii.processes.findProcessByPid (procInfo.pid); } if (newProcInfo === null) { - newProcInfo = gpii.processes.initNotRunning (procInfo.command); + newProcInfo = gpii.processes.initProcInfoNotRunning (procInfo.command); } return newProcInfo; }; // Create information on a non-running process, to use to detect when the // process starts. - gpii.processes.initNotRunning = function (command) { + gpii.processes.initProcInfoNotRunning = function (command) { var process = {}; process.command = command; process.pid = -1; @@ -193,8 +192,8 @@ https://github.com/gpii/universal/LICENSE.txt // Callback to pass to, e.g., setInterval() to periodically check the state // of a process. - gpii.processes.monitorChanged = function (procInfo, monitor) { - var newState = gpii.processes.hasStateChanged (procInfo); + gpii.processes.monitorStateChange = function (monitor) { + var newState = gpii.processes.hasStateChanged (monitor.procInfo); if (newState) { monitor.newState = newState; } @@ -202,37 +201,38 @@ https://github.com/gpii/universal/LICENSE.txt // Callback to pass to setInterval() to periodically check when the state // changes from "running" to "not running" and vice versa. - gpii.processes.monitorRunningChanged = function (monitor) { + gpii.processes.monitorRunStateChanged = function (monitor) { if (gpii.processes.hasSwitchedRunState (monitor)) { if (monitor.newProcInfo === null) { - monitor.procInfo = gpii.processes.initNotRunning (monitor.procInfo.command); + monitor.procInfo = + gpii.processes.initProcInfoNotRunning (monitor.procInfo.command); } else { monitor.procInfo = monitor.newProcInfo; } monitor.newState = monitor.procInfo.state; - startStopNotify.emit ("switchedRunState", monitor.procInfo); + startStopNotify.fire (monitor.procInfo); } }; - // ======================= - // Nodejs event processing - // ======================= + // ============== + // Event handling + // ============== // Provide a way for the outside world to pass in a handler for the // "switchedRunState", and to cancel. gpii.processes.trackRunState = function (procInfo, handler) { var monitor = gpii.processes.initMonitor (procInfo); + startStopNotify.addListener (handler); monitor.intervalID = setInterval (function() { - gpii.processes.monitorRunningChanged (monitor); + gpii.processes.monitorRunStateChanged (monitor); }); - startStopNotify.on ("switchedRunState", handler); return monitor.intervalID; }; gpii.processes.stopTrackingRunState = function (handler, intervalID) { - startStopNotify.removeListener ("switchedRunState", handler); + startStopNotify.removeListener (handler); clearInterval (intervalID); - }; + }; }()); diff --git a/gpii/node_modules/processes/processes_test.js b/gpii/node_modules/processes/processes_test.js index 7122937..68da84e 100644 --- a/gpii/node_modules/processes/processes_test.js +++ b/gpii/node_modules/processes/processes_test.js @@ -115,9 +115,9 @@ https://github.com/gpii/universal/LICENSE.txt }); jqUnit.test ( - "Test initNotRunning()", + "Test initProcInfoNotRunning()", function() { - var notRunning = processes.initNotRunning ("grep"); + var notRunning = processes.initProcInfoNotRunning ("grep"); jqUnit.assertEquals ("Command name", notRunning.command, "grep"); jqUnit.assertEquals ("Negative process id", notRunning.pid, -1); jqUnit.assertEquals ( @@ -137,7 +137,7 @@ https://github.com/gpii/universal/LICENSE.txt jqUnit.assertTrue ( "Check nodejs is running", processes.isRunning (procInfo.state) ); - procInfo = processes.initNotRunning ("grep"); + procInfo = processes.initProcInfoNotRunning ("grep"); jqUnit.assertFalse ( "Check nonexistent process running", processes.isRunning (procInfo) ); @@ -173,7 +173,7 @@ https://github.com/gpii/universal/LICENSE.txt jqUnit.assertFalse ( "Check null process", processes.hasStateChanged (null) ); - var catProcInfo = processes.initNotRunning ("cat"); + var catProcInfo = processes.initProcInfoNotRunning ("cat"); var stateChanged = processes.hasStateChanged (catProcInfo); jqUnit.assertFalse ("Check non-running process", stateChanged); From 602f963f097cf16442ffb370683a7498174142f6 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Wed, 8 Oct 2014 11:07:19 -0400 Subject: [PATCH 16/78] GPII-442: Use fluid "eventedComponent" for event handling. Reconfigured the processes.js to declare fluid.defaults for and evented component, and updated the demo as appropriate. --- gpii/node_modules/processes/procDemo.js | 6 +- gpii/node_modules/processes/processes.js | 80 +++++++++++++++++++++--- 2 files changed, 76 insertions(+), 10 deletions(-) diff --git a/gpii/node_modules/processes/procDemo.js b/gpii/node_modules/processes/procDemo.js index 761b639..69e5a6f 100644 --- a/gpii/node_modules/processes/procDemo.js +++ b/gpii/node_modules/processes/procDemo.js @@ -17,7 +17,9 @@ var readline = require ("readline"); var fluid = require("universal"); require ("./processes.js"); -var processes = fluid.registerNamespace ("gpii.processes"); +var gpii = fluid.registerNamespace ("gpii"); +gpii.processes = fluid.registerNamespace ("gpii.processes"); +var processes = gpii.processes(); var seekInput = readline.createInterface ({ input: process.stdin, @@ -37,7 +39,7 @@ var stateChangeHandler = function (procInfo) { }; // Initial assumption: not running. Then look for any running orca process. -var orcaProcInfo = processes.initNotRunning ("orca"); +var orcaProcInfo = processes.initProcInfoNotRunning ("orca"); var orcaProcInfos = processes.findProcessesByCommand ("orca"); if (orcaProcInfos.length > 0) { orcaProcInfo = orcaProcInfos[0]; diff --git a/gpii/node_modules/processes/processes.js b/gpii/node_modules/processes/processes.js index e0e4814..09d7157 100644 --- a/gpii/node_modules/processes/processes.js +++ b/gpii/node_modules/processes/processes.js @@ -20,7 +20,71 @@ https://github.com/gpii/universal/LICENSE.txt var nodeProcesses = require ("./nodeprocesses/build/Release/nodeprocesses.node"); gpii.processes = fluid.registerNamespace ("gpii.processes"); - var startStopNotify = fluid.makeEventFirer(); + + fluid.defaults ("gpii.processes", { + gradeNames: ["fluid.eventedComponent", "autoInit"], + events: { + onRunStateChange: null + }, + invokers: { + getProcesses: { + funcName: "gpii.processes.getProcesses", + args: [] + }, + findProcessByPid: { + funcName: "gpii.processes.findProcessByPid", + args: ["{arguments}.0", "{arguments}.1"] // pid, procArray (optional) + }, + findProcessesByCommand: { + funcName: "gpii.processes.findProcessesByCommand", + args: ["{arguments}.0", "{arguments}.1"] // command, procArray (optional) + }, + findFirstProcessByCmd: { + funcName: "gpii.processes.findFirstProcessByCmd", + args: ["{arguments}.0", "{arguments}.1"] // command, procArray (optional) + }, + hasStateChanged: { + funcName: "gpii.processes.hasStateChanged", + args: ["{arguments}.0"] // process info structure + }, + isRunning: { + funcName: "gpii.processes.isRunning", + args: ["{arguments}.0"] // state (string) + }, + hasSwitchRunState: { + funcName: "gpii.processes.hasSwitchedRunState", + args: ["{arguments}.0"] // monitor info structure + }, + updateProcInfo: { + funcName: "gpii.processes.updateProcInfo", + args: ["{arguments}.0"] // process info structure + }, + initProcInfoNotRunning: { + funcName: "gpii.processes.initProcInfoNotRunning", + args: ["{arguments}.0"] // command name (string) + }, + initMonitor: { + funcName: "gpii.processes.initMonitor", + args: ["{arguments}.0"] // process info structure + }, + monitorStateChange: { + funcName: "gpii.processes.monitorStateChange", + args: ["{arguments}.0"] // monitor info structure + }, + monitorRunStateChanged: { + funcName: "gpii.processes.monitorRunStateChanged", + args: ["{that}", "{arguments}.0"] // monitor info structure + }, + trackRunState: { + funcName: "gpii.processes.trackRunState", + args: ["{that}", "{arguments}.0", "{arguments}.1"] // process info, handler + }, + stopTrackingRunState: { + funcName: "gpii.processes.stopTrackingRunState", + args: ["{that}", "{arguments}.0", "{arguments}.1"] // handler, intervalID + } + } + }); // Return a list of processes -- a snapshot of the current processes. gpii.processes.getProcesses = function() { @@ -201,7 +265,7 @@ https://github.com/gpii/universal/LICENSE.txt // Callback to pass to setInterval() to periodically check when the state // changes from "running" to "not running" and vice versa. - gpii.processes.monitorRunStateChanged = function (monitor) { + gpii.processes.monitorRunStateChanged = function (that, monitor) { if (gpii.processes.hasSwitchedRunState (monitor)) { if (monitor.newProcInfo === null) { monitor.procInfo = @@ -211,7 +275,7 @@ https://github.com/gpii/universal/LICENSE.txt monitor.procInfo = monitor.newProcInfo; } monitor.newState = monitor.procInfo.state; - startStopNotify.fire (monitor.procInfo); + that.events.onRunStateChange.fire (monitor.procInfo); } }; @@ -221,17 +285,17 @@ https://github.com/gpii/universal/LICENSE.txt // Provide a way for the outside world to pass in a handler for the // "switchedRunState", and to cancel. - gpii.processes.trackRunState = function (procInfo, handler) { + gpii.processes.trackRunState = function (that, procInfo, handler) { var monitor = gpii.processes.initMonitor (procInfo); - startStopNotify.addListener (handler); + that.events.onRunStateChange.addListener (handler); monitor.intervalID = setInterval (function() { - gpii.processes.monitorRunStateChanged (monitor); + gpii.processes.monitorRunStateChanged (that, monitor); }); return monitor.intervalID; }; - gpii.processes.stopTrackingRunState = function (handler, intervalID) { - startStopNotify.removeListener (handler); + gpii.processes.stopTrackingRunState = function (that, handler, intervalID) { + that.events.onRunStateChange.removeListener (handler); clearInterval (intervalID); }; From 6c4b685bce2923fb8436596dd450f03bfdc296b4 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Fri, 10 Oct 2014 15:48:08 -0400 Subject: [PATCH 17/78] GPII-442: Added new event: "onStateChange". Added "onStateChange" event to notify of any change in a process' state, and functions to tap into this event. Also, simplified hasStateChanged(), monitorStateChange() functions. --- gpii/node_modules/processes/procDemo.js | 21 +++- gpii/node_modules/processes/processes.js | 97 +++++++++---------- gpii/node_modules/processes/processes_test.js | 25 +++-- 3 files changed, 80 insertions(+), 63 deletions(-) diff --git a/gpii/node_modules/processes/procDemo.js b/gpii/node_modules/processes/procDemo.js index 69e5a6f..0d527a4 100644 --- a/gpii/node_modules/processes/procDemo.js +++ b/gpii/node_modules/processes/procDemo.js @@ -29,7 +29,7 @@ var seekInput = readline.createInterface ({ // Handler for processes to use to detect change from "not running" to "running" // or "running" to "not running". For this demo, just print the new run state // on the console. -var stateChangeHandler = function (procInfo) { +var runStateChangeHandler = function (procInfo) { console.log ( procInfo.command + ": run state switched to " + procInfo.state + " (" + @@ -38,6 +38,15 @@ var stateChangeHandler = function (procInfo) { ); }; +// Handler to use to detect any change in state, and print to console. +var stateChangeHandler = function (oldProcInfo, newProcInfo) { + console.log ( + oldProcInfo.command + " process state switched from " + + oldProcInfo.state + " to " + newProcInfo.state + ); +}; + + // Initial assumption: not running. Then look for any running orca process. var orcaProcInfo = processes.initProcInfoNotRunning ("orca"); var orcaProcInfos = processes.findProcessesByCommand ("orca"); @@ -49,7 +58,9 @@ if (orcaProcInfos.length > 0) { // To see any changes, state/stop orca using, say, the accessibility menu, or // the command line: // gsettings set org.gnome.desktop.a11y.applications screen-reader-enabled true/false -var intervalID = processes.trackRunState (orcaProcInfo, stateChangeHandler); +var states = {}; +states.trackRunState = processes.trackRunState (orcaProcInfo, runStateChangeHandler); +states.trackState = processes.trackState (orcaProcInfo, stateChangeHandler); console.log ("Waiting..."); @@ -58,9 +69,9 @@ seekInput.question ("Stop? ", function (answer) { if (answer === "yes") { console.log ("Okay, stopping"); - // Cease periodic check of orca's run-state. - processes.stopTrackingRunState (stateChangeHandler, intervalID); - clearInterval (intervalID); + // Cease periodic check of orca's state. + processes.stopTrackingRunState (runStateChangeHandler, states.trackRunState); + processes.stopTrackingState (stateChangeHandler, states.trackState); seekInput.close(); } else { diff --git a/gpii/node_modules/processes/processes.js b/gpii/node_modules/processes/processes.js index 09d7157..36cdd97 100644 --- a/gpii/node_modules/processes/processes.js +++ b/gpii/node_modules/processes/processes.js @@ -24,7 +24,8 @@ https://github.com/gpii/universal/LICENSE.txt fluid.defaults ("gpii.processes", { gradeNames: ["fluid.eventedComponent", "autoInit"], events: { - onRunStateChange: null + onRunStateChange: null, + onStateChange: null }, invokers: { getProcesses: { @@ -39,7 +40,7 @@ https://github.com/gpii/universal/LICENSE.txt funcName: "gpii.processes.findProcessesByCommand", args: ["{arguments}.0", "{arguments}.1"] // command, procArray (optional) }, - findFirstProcessByCmd: { + findFirstProcessByCommand: { funcName: "gpii.processes.findFirstProcessByCmd", args: ["{arguments}.0", "{arguments}.1"] // command, procArray (optional) }, @@ -69,7 +70,7 @@ https://github.com/gpii/universal/LICENSE.txt }, monitorStateChange: { funcName: "gpii.processes.monitorStateChange", - args: ["{arguments}.0"] // monitor info structure + args: ["{that}", "{arguments}.0"] // monitor info structure }, monitorRunStateChanged: { funcName: "gpii.processes.monitorRunStateChanged", @@ -82,6 +83,15 @@ https://github.com/gpii/universal/LICENSE.txt stopTrackingRunState: { funcName: "gpii.processes.stopTrackingRunState", args: ["{that}", "{arguments}.0", "{arguments}.1"] // handler, intervalID + }, + // Tracking *any* state change. + trackState: { + funcName: "gpii.processes.trackState", + args: ["{that}", "{arguments}.0", "{arguments}.1"] // process info, handler + }, + stopTrackingState: { + funcName: "gpii.processes.stopTrackingState", + args: ["{that}", "{arguments}.0", "{arguments}.1"] // handler, intervalID } } }); @@ -133,48 +143,14 @@ https://github.com/gpii/universal/LICENSE.txt } }; - // Determine if the state of the given process has changed. Return truthy: - // - if the state has not changed, return false. - // - if the state has changed, return the new state. Special case: a - // process that has quit isn't in the processes list; return - // "NoSuchProcess". - gpii.processes.hasStateChanged = function (procInfo) { - if (!procInfo) { + // Determine if the state of the given process has changed. Record the + // new process information in the monitor. Return boolean. + gpii.processes.hasStateChanged = function (monitor) { + if (!monitor ||!monitor.procInfo) { return false; // nothing sought === nothing changed. } - var procArray = gpii.processes.getProcesses(); - - var theProc = null; - if (procInfo.state === "NoSuchProcess") { - var running = gpii.processes.findProcessesByCommand (procInfo.command); - if (running.length > 0) { - theProc = running[0]; - } - } - else { - theProc = gpii.processes.findProcessByPid (procInfo.pid, procArray); - } - // Case: process not in the current list ... - // - if procInfo.state is anything but "NoSuchProcess", then new state is - // no longer running (it quit). - // - if procInfo.state is "NoSuchProcess", then the process has not - // started -- no change in state. - if (theProc === null) { - if (procInfo.state === "NoSuchProcess") { - return false; - } - else { - return "NoSuchProcess"; - } - } - // Case: Process is (still) in the list and has the same state. - else if (theProc.state === procInfo.state) { - return false; - } - // Case: Process is (still) in the list and has a new state. - else { - return theProc.state; - } + monitor.newProcInfo = gpii.processes.updateProcInfo (monitor.procInfo); + return (monitor.procInfo.state !== monitor.newProcInfo.state); }; // Utility function to conflate process state values into "Running" @@ -248,7 +224,6 @@ https://github.com/gpii/universal/LICENSE.txt gpii.processes.initMonitor = function (procInfo) { var monitor = {}; monitor.intervalID = -1; - monitor.newState = false; monitor.procInfo = procInfo; monitor.newProcInfo = null; return monitor; @@ -256,10 +231,17 @@ https://github.com/gpii/universal/LICENSE.txt // Callback to pass to, e.g., setInterval() to periodically check the state // of a process. - gpii.processes.monitorStateChange = function (monitor) { - var newState = gpii.processes.hasStateChanged (monitor.procInfo); - if (newState) { - monitor.newState = newState; + gpii.processes.monitorStateChange = function (that, monitor) { + if (gpii.processes.hasStateChanged (monitor)) { + var oldProcInfo = monitor.procInfo; + if (monitor.newProcInfo === null) { + monitor.procInfo = + gpii.processes.initProcInfoNotRunning (monitor.procInfo.command); + } + else { + monitor.procInfo = monitor.newProcInfo; + } + that.events.onStateChange.fire (oldProcInfo, monitor.newProcInfo); } }; @@ -274,7 +256,6 @@ https://github.com/gpii/universal/LICENSE.txt else { monitor.procInfo = monitor.newProcInfo; } - monitor.newState = monitor.procInfo.state; that.events.onRunStateChange.fire (monitor.procInfo); } }; @@ -284,7 +265,7 @@ https://github.com/gpii/universal/LICENSE.txt // ============== // Provide a way for the outside world to pass in a handler for the - // "switchedRunState", and to cancel. + // "onRunStateChange" event, and to cancel. gpii.processes.trackRunState = function (that, procInfo, handler) { var monitor = gpii.processes.initMonitor (procInfo); that.events.onRunStateChange.addListener (handler); @@ -299,4 +280,20 @@ https://github.com/gpii/universal/LICENSE.txt clearInterval (intervalID); }; + // Provide a way for the outside world to pass in a handler for the + // "onStateChange" event, and to cancel. + gpii.processes.trackState = function (that, procInfo, handler) { + var monitor = gpii.processes.initMonitor (procInfo); + that.events.onStateChange.addListener (handler); + monitor.intervalID = setInterval (function() { + gpii.processes.monitorStateChange (that, monitor); + }); + return monitor.intervalID; + }; + + gpii.processes.stopTrackingState = function (that, handler, intervalID) { + that.events.onStateChange.removeListener (handler); + clearInterval (intervalID); + }; + }()); diff --git a/gpii/node_modules/processes/processes_test.js b/gpii/node_modules/processes/processes_test.js index 68da84e..ef97b7b 100644 --- a/gpii/node_modules/processes/processes_test.js +++ b/gpii/node_modules/processes/processes_test.js @@ -171,21 +171,28 @@ https://github.com/gpii/universal/LICENSE.txt "Test hasStateChanged()", function() { jqUnit.assertFalse ( - "Check null process", processes.hasStateChanged (null) + "Check null monitor", processes.hasStateChanged (null) + ); + var catMonitor = processes.initMonitor (null); + jqUnit.assertFalse ( + "Check null process", processes.hasStateChanged (catMonitor) ); var catProcInfo = processes.initProcInfoNotRunning ("cat"); - var stateChanged = processes.hasStateChanged (catProcInfo); + catMonitor = processes.initMonitor (catProcInfo); + var stateChanged = processes.hasStateChanged (catMonitor); jqUnit.assertFalse ("Check non-running process", stateChanged); var cat = spawn ("cat"); - stateChanged = processes.hasStateChanged (catProcInfo); - jqUnit.assertTrue ("Check running process", stateChanged !== false); + catMonitor = processes.initMonitor (catProcInfo); + stateChanged = processes.hasStateChanged (catMonitor); + jqUnit.assertTrue ("Check running process", stateChanged); // Get the running process info, kill cat, and check again. catProcInfo = processes.findProcessByPid (cat.pid); + catMonitor = processes.initMonitor (catProcInfo); cat.kill ("SIGHUP"); - stateChanged = processes.hasStateChanged (catProcInfo); - jqUnit.assertTrue ("Check stopped process", stateChanged !== false); + stateChanged = processes.hasStateChanged (catMonitor); + jqUnit.assertTrue ("Check stopped process", stateChanged); }); jqUnit.test ( @@ -242,9 +249,11 @@ https://github.com/gpii/universal/LICENSE.txt procTests.wait5sec(); var orcaProcNewState = processes.findProcessByPid (orcaProcInfo.pid); jqUnit.assertNull ("Orca no longer running", orcaProcNewState); - var newState = processes.hasStateChanged (orcaProcInfo); + var orcaMonitor = processes.initMonitor (orcaProcInfo); + processes.hasStateChanged (orcaMonitor); jqUnit.assertEquals ( - "Orca process changed state", "NoSuchProcess", newState + "Orca process changed state", "NoSuchProcess", + orcaMonitor.newProcInfo.state ); // Clean up. if (wasRunning) { From 908379b96b7287014088bd120897d95a7d98c89e Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Tue, 14 Oct 2014 16:41:19 -0400 Subject: [PATCH 18/78] GPII-442: Added ability to search for lists of solutions. Added invokers findSolutionsByCommands() and findSolutionsByPids() that take lists of command names, or process ids, respectively, and search the live process list to find and return a list of process information structures that match. --- gpii/node_modules/processes/processes.js | 40 +++++++++++++++++++ gpii/node_modules/processes/processes_test.js | 34 +++++++++++++++- 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/gpii/node_modules/processes/processes.js b/gpii/node_modules/processes/processes.js index 36cdd97..4c37e9e 100644 --- a/gpii/node_modules/processes/processes.js +++ b/gpii/node_modules/processes/processes.js @@ -28,6 +28,14 @@ https://github.com/gpii/universal/LICENSE.txt onStateChange: null }, invokers: { + findSolutionsByCommands: { + funcName: "gpii.processes.findSolutionsByCommands", + args: ["{arguments}.0"] // array of command names + }, + findSolutionsByPids: { + funcName: "gpii.processes.findSolutionsByPids", + args: ["{arguments}.0"] // array of pid (process ids) + }, getProcesses: { funcName: "gpii.processes.getProcesses", args: [] @@ -96,6 +104,38 @@ https://github.com/gpii/universal/LICENSE.txt } }); + // Return an list of process information structures corresponding to the + // names of each of the passed in commands. + gpii.processes.findSolutionsByCommands = function (commandNames) { + if (!!commandNames) { + return fluid.accumulate (commandNames, function (aCommand, matches) { + var procInfos = gpii.processes.findProcessesByCommand (aCommand); + matches = matches.concat (procInfos); + return matches; + }, []); + } + else { + return []; + } + }, + + // Return an list of process information structures corresponding to the + // pids pass in. + gpii.processes.findSolutionsByPids = function (pids) { + if (!!pids) { + return fluid.accumulate (pids, function (aPid, matches) { + var found = gpii.processes.findProcessByPid (aPid); + if (found !== null) { + matches.push (found); + } + return matches; + }, []); + } + else { + return []; + } + }, + // Return a list of processes -- a snapshot of the current processes. gpii.processes.getProcesses = function() { return nodeProcesses.getProcesses(); diff --git a/gpii/node_modules/processes/processes_test.js b/gpii/node_modules/processes/processes_test.js index ef97b7b..7e23620 100644 --- a/gpii/node_modules/processes/processes_test.js +++ b/gpii/node_modules/processes/processes_test.js @@ -224,10 +224,42 @@ https://github.com/gpii/universal/LICENSE.txt ); }); + jqUnit.test ( + "Test findSolutionsByCommands()", + function() { + // Node is running. Add a running cat process. No such command as why. + var cat = spawn ("cat"); + var solutions = ["node", "cat", "why"]; + var procInfos = processes.findSolutionsByCommands (solutions); + jqUnit.assertTrue ("Node and cat processes", procInfos.length >= 2); + procInfos.forEach (function (item) { + var isNode = item.command === "node"; + var isCat = item.command === "cat"; + jqUnit.assertTrue ("Process name node nor cat", isNode || isCat); + }); + cat.kill ("SIGHUP"); + }); + + jqUnit.test ( + "Test findSolutionsByPids()", + function() { + // Node is running. Add a running cat process. + var cat = spawn ("cat"); + var pids = [process.pid, cat.pid]; + var procInfos = processes.findSolutionsByPids (pids); + jqUnit.assertEquals ("Node and cat processes", 2, procInfos.length); + procInfos.forEach (function (item) { + var isNode = item.pid === process.pid; + var isCat = item.pid === cat.pid; + jqUnit.assertTrue ("Process pid node nor cat", isNode || isCat); + }); + cat.kill ("SIGHUP"); + }); + // Test real life scenario: Use the GPII's gsettings bridge to launch // and shut down orca, and track the changes in state. jqUnit.test ( - "Test getProceses() against launching orca.", + "Test gpii.processes against launching orca.", function() { var orcaProcInfo = processes.findFirstProcessByCommand ("orca"); var wasRunning = (orcaProcInfo !== null); From 642bce944d84b5f0e5755f3a210b78d03adffd8b Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Thu, 16 Oct 2014 11:36:13 -0400 Subject: [PATCH 19/78] GPII-442: Renamed to processReporter (part I). Renamed the main folder from "processes" to "processReporter". --- gpii/node_modules/{processes => processReporter}/README.md | 0 .../{processes => processReporter}/nodeprocesses/binding.gyp | 0 .../{processes => processReporter}/nodeprocesses/nodeprocesses.cc | 0 .../nodeprocesses/nodeprocesses_test.js | 0 gpii/node_modules/{processes => processReporter}/package.json | 0 gpii/node_modules/{processes => processReporter}/procDemo.js | 0 gpii/node_modules/{processes => processReporter}/processes.js | 0 .../node_modules/{processes => processReporter}/processes_test.js | 0 8 files changed, 0 insertions(+), 0 deletions(-) rename gpii/node_modules/{processes => processReporter}/README.md (100%) rename gpii/node_modules/{processes => processReporter}/nodeprocesses/binding.gyp (100%) rename gpii/node_modules/{processes => processReporter}/nodeprocesses/nodeprocesses.cc (100%) rename gpii/node_modules/{processes => processReporter}/nodeprocesses/nodeprocesses_test.js (100%) rename gpii/node_modules/{processes => processReporter}/package.json (100%) rename gpii/node_modules/{processes => processReporter}/procDemo.js (100%) rename gpii/node_modules/{processes => processReporter}/processes.js (100%) rename gpii/node_modules/{processes => processReporter}/processes_test.js (100%) diff --git a/gpii/node_modules/processes/README.md b/gpii/node_modules/processReporter/README.md similarity index 100% rename from gpii/node_modules/processes/README.md rename to gpii/node_modules/processReporter/README.md diff --git a/gpii/node_modules/processes/nodeprocesses/binding.gyp b/gpii/node_modules/processReporter/nodeprocesses/binding.gyp similarity index 100% rename from gpii/node_modules/processes/nodeprocesses/binding.gyp rename to gpii/node_modules/processReporter/nodeprocesses/binding.gyp diff --git a/gpii/node_modules/processes/nodeprocesses/nodeprocesses.cc b/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses.cc similarity index 100% rename from gpii/node_modules/processes/nodeprocesses/nodeprocesses.cc rename to gpii/node_modules/processReporter/nodeprocesses/nodeprocesses.cc diff --git a/gpii/node_modules/processes/nodeprocesses/nodeprocesses_test.js b/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses_test.js similarity index 100% rename from gpii/node_modules/processes/nodeprocesses/nodeprocesses_test.js rename to gpii/node_modules/processReporter/nodeprocesses/nodeprocesses_test.js diff --git a/gpii/node_modules/processes/package.json b/gpii/node_modules/processReporter/package.json similarity index 100% rename from gpii/node_modules/processes/package.json rename to gpii/node_modules/processReporter/package.json diff --git a/gpii/node_modules/processes/procDemo.js b/gpii/node_modules/processReporter/procDemo.js similarity index 100% rename from gpii/node_modules/processes/procDemo.js rename to gpii/node_modules/processReporter/procDemo.js diff --git a/gpii/node_modules/processes/processes.js b/gpii/node_modules/processReporter/processes.js similarity index 100% rename from gpii/node_modules/processes/processes.js rename to gpii/node_modules/processReporter/processes.js diff --git a/gpii/node_modules/processes/processes_test.js b/gpii/node_modules/processReporter/processes_test.js similarity index 100% rename from gpii/node_modules/processes/processes_test.js rename to gpii/node_modules/processReporter/processes_test.js From 474187824dcc9dbc794fc682b89cc67a9d515287 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Thu, 16 Oct 2014 12:07:33 -0400 Subject: [PATCH 20/78] GPII-442: Renamed to processReporter (part II). - renamed "processes.js" to "processReporter.js" - renamed "processes_test.js" to "processReporter_tests.js" - renamed "procDemo.js" to "processReporterDemo.js" - modified various names and namespaces to use "processReporter". --- .../{processes.js => processReporter.js} | 120 +++++++++--------- .../{procDemo.js => processReporterDemo.js} | 22 ++-- ...esses_test.js => processReporter_tests.js} | 88 ++++++------- 3 files changed, 116 insertions(+), 114 deletions(-) rename gpii/node_modules/processReporter/{processes.js => processReporter.js} (67%) rename gpii/node_modules/processReporter/{procDemo.js => processReporterDemo.js} (71%) rename gpii/node_modules/processReporter/{processes_test.js => processReporter_tests.js} (74%) diff --git a/gpii/node_modules/processReporter/processes.js b/gpii/node_modules/processReporter/processReporter.js similarity index 67% rename from gpii/node_modules/processReporter/processes.js rename to gpii/node_modules/processReporter/processReporter.js index 4c37e9e..47de3c0 100644 --- a/gpii/node_modules/processReporter/processes.js +++ b/gpii/node_modules/processReporter/processReporter.js @@ -1,5 +1,5 @@ /*! -GPII Processes Bridge -- gpii.processes. +GPII Process Reporter -- gpii.processReporter. Copyright 2014 Inclusive Design Research Centre, OCAD University @@ -19,9 +19,9 @@ https://github.com/gpii/universal/LICENSE.txt var gpii = fluid.registerNamespace ("gpii"); var nodeProcesses = require ("./nodeprocesses/build/Release/nodeprocesses.node"); - gpii.processes = fluid.registerNamespace ("gpii.processes"); + gpii.processReporter = fluid.registerNamespace ("gpii.processReporter"); - fluid.defaults ("gpii.processes", { + fluid.defaults ("gpii.processReporter", { gradeNames: ["fluid.eventedComponent", "autoInit"], events: { onRunStateChange: null, @@ -29,76 +29,76 @@ https://github.com/gpii/universal/LICENSE.txt }, invokers: { findSolutionsByCommands: { - funcName: "gpii.processes.findSolutionsByCommands", + funcName: "gpii.processReporter.findSolutionsByCommands", args: ["{arguments}.0"] // array of command names }, findSolutionsByPids: { - funcName: "gpii.processes.findSolutionsByPids", + funcName: "gpii.processReporter.findSolutionsByPids", args: ["{arguments}.0"] // array of pid (process ids) }, getProcesses: { - funcName: "gpii.processes.getProcesses", + funcName: "gpii.processReporter.getProcesses", args: [] }, findProcessByPid: { - funcName: "gpii.processes.findProcessByPid", + funcName: "gpii.processReporter.findProcessByPid", args: ["{arguments}.0", "{arguments}.1"] // pid, procArray (optional) }, findProcessesByCommand: { - funcName: "gpii.processes.findProcessesByCommand", + funcName: "gpii.processReporter.findProcessesByCommand", args: ["{arguments}.0", "{arguments}.1"] // command, procArray (optional) }, findFirstProcessByCommand: { - funcName: "gpii.processes.findFirstProcessByCmd", + funcName: "gpii.processReporter.findFirstProcessByCommand", args: ["{arguments}.0", "{arguments}.1"] // command, procArray (optional) }, hasStateChanged: { - funcName: "gpii.processes.hasStateChanged", + funcName: "gpii.processReporter.hasStateChanged", args: ["{arguments}.0"] // process info structure }, isRunning: { - funcName: "gpii.processes.isRunning", + funcName: "gpii.processReporter.isRunning", args: ["{arguments}.0"] // state (string) }, hasSwitchRunState: { - funcName: "gpii.processes.hasSwitchedRunState", + funcName: "gpii.processReporter.hasSwitchedRunState", args: ["{arguments}.0"] // monitor info structure }, updateProcInfo: { - funcName: "gpii.processes.updateProcInfo", + funcName: "gpii.processReporter.updateProcInfo", args: ["{arguments}.0"] // process info structure }, initProcInfoNotRunning: { - funcName: "gpii.processes.initProcInfoNotRunning", + funcName: "gpii.processReporter.initProcInfoNotRunning", args: ["{arguments}.0"] // command name (string) }, initMonitor: { - funcName: "gpii.processes.initMonitor", + funcName: "gpii.processReporter.initMonitor", args: ["{arguments}.0"] // process info structure }, monitorStateChange: { - funcName: "gpii.processes.monitorStateChange", + funcName: "gpii.processReporter.monitorStateChange", args: ["{that}", "{arguments}.0"] // monitor info structure }, monitorRunStateChanged: { - funcName: "gpii.processes.monitorRunStateChanged", + funcName: "gpii.processReporter.monitorRunStateChanged", args: ["{that}", "{arguments}.0"] // monitor info structure }, trackRunState: { - funcName: "gpii.processes.trackRunState", + funcName: "gpii.processReporter.trackRunState", args: ["{that}", "{arguments}.0", "{arguments}.1"] // process info, handler }, stopTrackingRunState: { - funcName: "gpii.processes.stopTrackingRunState", + funcName: "gpii.processReporter.stopTrackingRunState", args: ["{that}", "{arguments}.0", "{arguments}.1"] // handler, intervalID }, // Tracking *any* state change. trackState: { - funcName: "gpii.processes.trackState", + funcName: "gpii.processReporter.trackState", args: ["{that}", "{arguments}.0", "{arguments}.1"] // process info, handler }, stopTrackingState: { - funcName: "gpii.processes.stopTrackingState", + funcName: "gpii.processReporter.stopTrackingState", args: ["{that}", "{arguments}.0", "{arguments}.1"] // handler, intervalID } } @@ -106,10 +106,10 @@ https://github.com/gpii/universal/LICENSE.txt // Return an list of process information structures corresponding to the // names of each of the passed in commands. - gpii.processes.findSolutionsByCommands = function (commandNames) { + gpii.processReporter.findSolutionsByCommands = function (commandNames) { if (!!commandNames) { return fluid.accumulate (commandNames, function (aCommand, matches) { - var procInfos = gpii.processes.findProcessesByCommand (aCommand); + var procInfos = gpii.processReporter.findProcessesByCommand (aCommand); matches = matches.concat (procInfos); return matches; }, []); @@ -121,10 +121,10 @@ https://github.com/gpii/universal/LICENSE.txt // Return an list of process information structures corresponding to the // pids pass in. - gpii.processes.findSolutionsByPids = function (pids) { + gpii.processReporter.findSolutionsByPids = function (pids) { if (!!pids) { return fluid.accumulate (pids, function (aPid, matches) { - var found = gpii.processes.findProcessByPid (aPid); + var found = gpii.processReporter.findProcessByPid (aPid); if (found !== null) { matches.push (found); } @@ -137,15 +137,15 @@ https://github.com/gpii/universal/LICENSE.txt }, // Return a list of processes -- a snapshot of the current processes. - gpii.processes.getProcesses = function() { + gpii.processReporter.getProcessList = function() { return nodeProcesses.getProcesses(); }; // Return THE process info object that matches the given process id. // Note that it can return "null" meaning there is no such process. - gpii.processes.findProcessByPid = function (pid, procArray) { + gpii.processReporter.findProcessByPid = function (pid, procArray) { if (!procArray) { - procArray = gpii.processes.getProcesses(); + procArray = gpii.processReporter.getProcessList(); } return fluid.find (procArray, function (procInfo) { if (procInfo.pid === pid) { @@ -157,9 +157,9 @@ https://github.com/gpii/universal/LICENSE.txt // Return an array of process information objects that match the given // command name string. Note that it can return an empty array, meaning // there is no such process. - gpii.processes.findProcessesByCommand = function (commandName, procArray) { + gpii.processReporter.findProcessesByCommand = function (commandName, procArray) { if (!procArray) { - procArray = gpii.processes.getProcesses(); + procArray = gpii.processReporter.getProcessList(); } return fluid.accumulate (procArray, function (aProcInfo, matchingProcs) { if (aProcInfo.command === commandName) { @@ -171,10 +171,10 @@ https://github.com/gpii/universal/LICENSE.txt // Return the first process of an array of processes all with the same // command name string. If there are no matching processes, return null. - gpii.processes.findFirstProcessByCommand = + gpii.processReporter.findFirstProcessByCommand = function (commandName, procArray) { var commands = - gpii.processes.findProcessesByCommand (commandName, procArray); + gpii.processReporter.findProcessesByCommand (commandName, procArray); if (commands.length > 0) { return commands[0]; } @@ -185,17 +185,18 @@ https://github.com/gpii/universal/LICENSE.txt // Determine if the state of the given process has changed. Record the // new process information in the monitor. Return boolean. - gpii.processes.hasStateChanged = function (monitor) { + gpii.processReporter.hasStateChanged = function (monitor) { if (!monitor ||!monitor.procInfo) { return false; // nothing sought === nothing changed. } - monitor.newProcInfo = gpii.processes.updateProcInfo (monitor.procInfo); + monitor.newProcInfo = + gpii.processReporter.updateProcInfo (monitor.procInfo); return (monitor.procInfo.state !== monitor.newProcInfo.state); }; // Utility function to conflate process state values into "Running" // (= true) vs. "Not Running" (= false). Returns boolean. - gpii.processes.isRunning = function (state) { + gpii.processReporter.isRunning = function (state) { var result; switch (state) { case "Running": @@ -217,36 +218,37 @@ https://github.com/gpii/universal/LICENSE.txt // Determine if the state of the given process has changed from // "not running" to "running" OR from "running" to "not running". // Return boolean. - gpii.processes.hasSwitchedRunState = function (monitor) { + gpii.processReporter.hasSwitchedRunState = function (monitor) { if (!monitor || !monitor.procInfo) { // nothing sought === nothing changed. return false; } - monitor.newProcInfo = gpii.processes.updateProcInfo (monitor.procInfo); - var wasRunning = gpii.processes.isRunning (monitor.procInfo.state); - var isRunning = gpii.processes.isRunning (monitor.newProcInfo.state); + monitor.newProcInfo = + gpii.processReporter.updateProcInfo (monitor.procInfo); + var wasRunning = gpii.processReporter.isRunning (monitor.procInfo.state); + var isRunning = gpii.processReporter.isRunning (monitor.newProcInfo.state); return (isRunning !== wasRunning); }; // Renew the information on a process, or create a new "NoSuchProcces". // Returns a new procInfo structure. - gpii.processes.updateProcInfo = function (procInfo) { + gpii.processReporter.updateProcInfo = function (procInfo) { var newProcInfo = null; if (procInfo.state === "NoSuchProcess") { - newProcInfo = gpii.processes.findFirstProcessByCommand (procInfo.command); + newProcInfo = gpii.processReporter.findFirstProcessByCommand (procInfo.command); } else { - newProcInfo = gpii.processes.findProcessByPid (procInfo.pid); + newProcInfo = gpii.processReporter.findProcessByPid (procInfo.pid); } if (newProcInfo === null) { - newProcInfo = gpii.processes.initProcInfoNotRunning (procInfo.command); + newProcInfo = gpii.processReporter.initProcInfoNotRunning (procInfo.command); } return newProcInfo; }; // Create information on a non-running process, to use to detect when the // process starts. - gpii.processes.initProcInfoNotRunning = function (command) { + gpii.processReporter.initProcInfoNotRunning = function (command) { var process = {}; process.command = command; process.pid = -1; @@ -261,7 +263,7 @@ https://github.com/gpii/universal/LICENSE.txt // Create a monitor object for passing to a function that periodically // checks for chanages in the state of a process. - gpii.processes.initMonitor = function (procInfo) { + gpii.processReporter.initMonitor = function (procInfo) { var monitor = {}; monitor.intervalID = -1; monitor.procInfo = procInfo; @@ -271,12 +273,12 @@ https://github.com/gpii/universal/LICENSE.txt // Callback to pass to, e.g., setInterval() to periodically check the state // of a process. - gpii.processes.monitorStateChange = function (that, monitor) { - if (gpii.processes.hasStateChanged (monitor)) { + gpii.processReporter.monitorStateChange = function (that, monitor) { + if (gpii.processReporter.hasStateChanged (monitor)) { var oldProcInfo = monitor.procInfo; if (monitor.newProcInfo === null) { monitor.procInfo = - gpii.processes.initProcInfoNotRunning (monitor.procInfo.command); + gpii.processReporter.initProcInfoNotRunning (monitor.procInfo.command); } else { monitor.procInfo = monitor.newProcInfo; @@ -287,11 +289,11 @@ https://github.com/gpii/universal/LICENSE.txt // Callback to pass to setInterval() to periodically check when the state // changes from "running" to "not running" and vice versa. - gpii.processes.monitorRunStateChanged = function (that, monitor) { - if (gpii.processes.hasSwitchedRunState (monitor)) { + gpii.processReporter.monitorRunStateChanged = function (that, monitor) { + if (gpii.processReporter.hasSwitchedRunState (monitor)) { if (monitor.newProcInfo === null) { monitor.procInfo = - gpii.processes.initProcInfoNotRunning (monitor.procInfo.command); + gpii.processReporter.initProcInfoNotRunning (monitor.procInfo.command); } else { monitor.procInfo = monitor.newProcInfo; @@ -306,32 +308,32 @@ https://github.com/gpii/universal/LICENSE.txt // Provide a way for the outside world to pass in a handler for the // "onRunStateChange" event, and to cancel. - gpii.processes.trackRunState = function (that, procInfo, handler) { - var monitor = gpii.processes.initMonitor (procInfo); + gpii.processReporter.trackRunState = function (that, procInfo, handler) { + var monitor = gpii.processReporter.initMonitor (procInfo); that.events.onRunStateChange.addListener (handler); monitor.intervalID = setInterval (function() { - gpii.processes.monitorRunStateChanged (that, monitor); + gpii.processReporter.monitorRunStateChanged (that, monitor); }); return monitor.intervalID; }; - gpii.processes.stopTrackingRunState = function (that, handler, intervalID) { + gpii.processReporter.stopTrackingRunState = function (that, handler, intervalID) { that.events.onRunStateChange.removeListener (handler); clearInterval (intervalID); }; // Provide a way for the outside world to pass in a handler for the // "onStateChange" event, and to cancel. - gpii.processes.trackState = function (that, procInfo, handler) { - var monitor = gpii.processes.initMonitor (procInfo); + gpii.processReporter.trackState = function (that, procInfo, handler) { + var monitor = gpii.processReporter.initMonitor (procInfo); that.events.onStateChange.addListener (handler); monitor.intervalID = setInterval (function() { - gpii.processes.monitorStateChange (that, monitor); + gpii.processReporter.monitorStateChange (that, monitor); }); return monitor.intervalID; }; - gpii.processes.stopTrackingState = function (that, handler, intervalID) { + gpii.processReporter.stopTrackingState = function (that, handler, intervalID) { that.events.onStateChange.removeListener (handler); clearInterval (intervalID); }; diff --git a/gpii/node_modules/processReporter/procDemo.js b/gpii/node_modules/processReporter/processReporterDemo.js similarity index 71% rename from gpii/node_modules/processReporter/procDemo.js rename to gpii/node_modules/processReporter/processReporterDemo.js index 0d527a4..9fb6717 100644 --- a/gpii/node_modules/processReporter/procDemo.js +++ b/gpii/node_modules/processReporter/processReporterDemo.js @@ -1,5 +1,5 @@ /*! -GPII Prcoess Bridge Demo. +GPII Prcoess Reporter Demo. Copyright 2014 Inclusive Design Research Centre, OCAD University @@ -15,11 +15,11 @@ https://github.com/gpii/universal/LICENSE.txt var readline = require ("readline"); var fluid = require("universal"); -require ("./processes.js"); +require ("./processReporter.js"); var gpii = fluid.registerNamespace ("gpii"); -gpii.processes = fluid.registerNamespace ("gpii.processes"); -var processes = gpii.processes(); +gpii.processReporter = fluid.registerNamespace ("gpii.processReporter"); +var processReporter = gpii.processReporter(); var seekInput = readline.createInterface ({ input: process.stdin, @@ -33,7 +33,7 @@ var runStateChangeHandler = function (procInfo) { console.log ( procInfo.command + ": run state switched to " + procInfo.state + " (" + - ( processes.isRunning (procInfo.state) ? "Running" : "Stopped" ) + + ( processReporter.isRunning (procInfo.state) ? "Running" : "Stopped" ) + ")" ); }; @@ -48,8 +48,8 @@ var stateChangeHandler = function (oldProcInfo, newProcInfo) { // Initial assumption: not running. Then look for any running orca process. -var orcaProcInfo = processes.initProcInfoNotRunning ("orca"); -var orcaProcInfos = processes.findProcessesByCommand ("orca"); +var orcaProcInfo = processReporter.initProcInfoNotRunning ("orca"); +var orcaProcInfos = processReporter.findProcessesByCommand ("orca"); if (orcaProcInfos.length > 0) { orcaProcInfo = orcaProcInfos[0]; } @@ -59,8 +59,8 @@ if (orcaProcInfos.length > 0) { // the command line: // gsettings set org.gnome.desktop.a11y.applications screen-reader-enabled true/false var states = {}; -states.trackRunState = processes.trackRunState (orcaProcInfo, runStateChangeHandler); -states.trackState = processes.trackState (orcaProcInfo, stateChangeHandler); +states.trackRunState = processReporter.trackRunState (orcaProcInfo, runStateChangeHandler); +states.trackState = processReporter.trackState (orcaProcInfo, stateChangeHandler); console.log ("Waiting..."); @@ -70,8 +70,8 @@ seekInput.question ("Stop? ", function (answer) { console.log ("Okay, stopping"); // Cease periodic check of orca's state. - processes.stopTrackingRunState (runStateChangeHandler, states.trackRunState); - processes.stopTrackingState (stateChangeHandler, states.trackState); + processReporter.stopTrackingRunState (runStateChangeHandler, states.trackRunState); + processReporter.stopTrackingState (stateChangeHandler, states.trackState); seekInput.close(); } else { diff --git a/gpii/node_modules/processReporter/processes_test.js b/gpii/node_modules/processReporter/processReporter_tests.js similarity index 74% rename from gpii/node_modules/processReporter/processes_test.js rename to gpii/node_modules/processReporter/processReporter_tests.js index 7e23620..99e0f26 100644 --- a/gpii/node_modules/processReporter/processes_test.js +++ b/gpii/node_modules/processReporter/processReporter_tests.js @@ -22,9 +22,9 @@ https://github.com/gpii/universal/LICENSE.txt // TODO: Must be a better way to get node gsettings add-on. nodeGSettings = require ("../gsettingsBridge/nodegsettings/build/Release/nodegsettings.node"); - require ("./processes.js"); + require ("./processReporter.js"); - var processes = fluid.registerNamespace ("gpii.processes"); + var processReporter = fluid.registerNamespace ("gpii.processReporter"); var procTests = fluid.registerNamespace ("gpii.tests.processes"); // Delay 5 seconds. @@ -40,7 +40,7 @@ https://github.com/gpii/universal/LICENSE.txt jqUnit.test ( "Test getProceses()/findProcessByPid() with the nodejs process itself", function() { - var procInfos = processes.getProcesses(); + var procInfos = processReporter.getProcessList(); jqUnit.assertNotEquals ( "Listing all processes", 0, procInfos.length ); @@ -48,7 +48,7 @@ https://github.com/gpii/universal/LICENSE.txt // Check for the presence of this nodejs processs itself -- it must // be in the process list since this code is running inside that // process. - var nodeProc = processes.findProcessByPid (process.pid, procInfos); + var nodeProc = processReporter.findProcessByPid (process.pid, procInfos); jqUnit.assertNotNull ("Searching for 'node' process", nodeProc); }); @@ -56,14 +56,14 @@ https://github.com/gpii/universal/LICENSE.txt "Test findProcessByPid() with non-running process id", function() { jqUnit.assertNull ( - "Search negative process id value", processes.findProcessByPid (-1) + "Search negative process id value", processReporter.findProcessByPid (-1) ); }); jqUnit.test ( "Test findProcessByPid() against nodejs's own process object.", function() { - var nodeProcInfo = processes.findProcessByPid (process.pid); + var nodeProcInfo = processReporter.findProcessByPid (process.pid); jqUnit.assertEquals ("Node process 'name'", process.title, nodeProcInfo.command); @@ -100,7 +100,7 @@ https://github.com/gpii/universal/LICENSE.txt jqUnit.test ( "Test findProcessesByCmd()/findFirstProcessByCmd() with nodejs itself", function() { - var nodeProcInfos = processes.findProcessesByCommand ("node"); + var nodeProcInfos = processReporter.findProcessesByCommand ("node"); jqUnit.assertNotEquals ( "Getting all 'node' processes", 0, nodeProcInfos.length ); @@ -109,7 +109,7 @@ https://github.com/gpii/universal/LICENSE.txt "Node commmand name", "node", aProcInfo.command ); }); - var procInfo = processes.findFirstProcessByCommand ("node"); + var procInfo = processReporter.findFirstProcessByCommand ("node"); jqUnit.assertNotNull ("Looking for first 'node' processes", procInfo); jqUnit.assertEquals ("Node commmand name", "node", procInfo.command); }); @@ -117,7 +117,7 @@ https://github.com/gpii/universal/LICENSE.txt jqUnit.test ( "Test initProcInfoNotRunning()", function() { - var notRunning = processes.initProcInfoNotRunning ("grep"); + var notRunning = processReporter.initProcInfoNotRunning ("grep"); jqUnit.assertEquals ("Command name", notRunning.command, "grep"); jqUnit.assertEquals ("Negative process id", notRunning.pid, -1); jqUnit.assertEquals ( @@ -125,30 +125,30 @@ https://github.com/gpii/universal/LICENSE.txt ); jqUnit.assertNull ( "Search negative process id value", - processes.findProcessByPid (notRunning.pid) + processReporter.findProcessByPid (notRunning.pid) ); }); jqUnit.test ( "Test isRunning() with nodejs itself, and nonexistent process", function() { - var procInfo = processes.findProcessByPid (process.pid); + var procInfo = processReporter.findProcessByPid (process.pid); jqUnit.assertNotNull ("Searching for 'node' process", procInfo); jqUnit.assertTrue ( - "Check nodejs is running", processes.isRunning (procInfo.state) + "Check nodejs is running", processReporter.isRunning (procInfo.state) ); - procInfo = processes.initProcInfoNotRunning ("grep"); + procInfo = processReporter.initProcInfoNotRunning ("grep"); jqUnit.assertFalse ( - "Check nonexistent process running", processes.isRunning (procInfo) + "Check nonexistent process running", processReporter.isRunning (procInfo) ); }); jqUnit.test ( "Test updateProcInfo() against non-changing process", function() { - var procInfo = processes.findProcessByPid (process.pid); + var procInfo = processReporter.findProcessByPid (process.pid); jqUnit.assertNotNull ("Looking for 'node' processes", procInfo); - var newProcInfo = processes.updateProcInfo (procInfo); + var newProcInfo = processReporter.updateProcInfo (procInfo); jqUnit.assertDeepEq ( "Check change in process info", procInfo, newProcInfo ); @@ -158,10 +158,10 @@ https://github.com/gpii/universal/LICENSE.txt "Test updateProcInfo() against changing process", function() { var grep = spawn ("grep", ["ssh"]); - var grepInfo = processes.findProcessByPid (grep.pid); + var grepInfo = processReporter.findProcessByPid (grep.pid); jqUnit.assertNotNull ("Search 'grep' process", grepInfo); jqUnit.assertTrue ("Stop grep", grep.kill ("SIGHUP")); - var newGrepInfo = processes.updateProcInfo (grepInfo); + var newGrepInfo = processReporter.updateProcInfo (grepInfo); jqUnit.assertNotEquals ( "Update process state", newGrepInfo.state, grepInfo.state ); @@ -171,27 +171,27 @@ https://github.com/gpii/universal/LICENSE.txt "Test hasStateChanged()", function() { jqUnit.assertFalse ( - "Check null monitor", processes.hasStateChanged (null) + "Check null monitor", processReporter.hasStateChanged (null) ); - var catMonitor = processes.initMonitor (null); + var catMonitor = processReporter.initMonitor (null); jqUnit.assertFalse ( - "Check null process", processes.hasStateChanged (catMonitor) + "Check null process", processReporter.hasStateChanged (catMonitor) ); - var catProcInfo = processes.initProcInfoNotRunning ("cat"); - catMonitor = processes.initMonitor (catProcInfo); - var stateChanged = processes.hasStateChanged (catMonitor); + var catProcInfo = processReporter.initProcInfoNotRunning ("cat"); + catMonitor = processReporter.initMonitor (catProcInfo); + var stateChanged = processReporter.hasStateChanged (catMonitor); jqUnit.assertFalse ("Check non-running process", stateChanged); var cat = spawn ("cat"); - catMonitor = processes.initMonitor (catProcInfo); - stateChanged = processes.hasStateChanged (catMonitor); + catMonitor = processReporter.initMonitor (catProcInfo); + stateChanged = processReporter.hasStateChanged (catMonitor); jqUnit.assertTrue ("Check running process", stateChanged); // Get the running process info, kill cat, and check again. - catProcInfo = processes.findProcessByPid (cat.pid); - catMonitor = processes.initMonitor (catProcInfo); + catProcInfo = processReporter.findProcessByPid (cat.pid); + catMonitor = processReporter.initMonitor (catProcInfo); cat.kill ("SIGHUP"); - stateChanged = processes.hasStateChanged (catMonitor); + stateChanged = processReporter.hasStateChanged (catMonitor); jqUnit.assertTrue ("Check stopped process", stateChanged); }); @@ -199,16 +199,16 @@ https://github.com/gpii/universal/LICENSE.txt "Test hasSwitchedRunState()", function() { jqUnit.assertFalse ( - "Check null monitor", processes.hasSwitchedRunState (null) + "Check null monitor", processReporter.hasSwitchedRunState (null) ); - var grepProcMonitor = processes.initMonitor (null); + var grepProcMonitor = processReporter.initMonitor (null); jqUnit.assertFalse ( - "Check null process", processes.hasSwitchedRunState (grepProcMonitor) + "Check null process", processReporter.hasSwitchedRunState (grepProcMonitor) ); var grep = spawn ("grep", ["ssh"]); - var grepProcInfo = processes.findProcessByPid (grep.pid); - grepProcMonitor = processes.initMonitor (grepProcInfo); - var switched = processes.hasSwitchedRunState (grepProcMonitor); + var grepProcInfo = processReporter.findProcessByPid (grep.pid); + grepProcMonitor = processReporter.initMonitor (grepProcInfo); + var switched = processReporter.hasSwitchedRunState (grepProcMonitor); jqUnit.assertFalse ("Check running process", switched); jqUnit.assertEquals ( "Process state change", @@ -216,7 +216,7 @@ https://github.com/gpii/universal/LICENSE.txt ); // Kill grep, and check again. grep.kill ("SIGHUP"); - switched = processes.hasSwitchedRunState (grepProcMonitor); + switched = processReporter.hasSwitchedRunState (grepProcMonitor); jqUnit.assertTrue ("Check stopped process", switched); jqUnit.assertNotEquals ( "Process state change", @@ -230,7 +230,7 @@ https://github.com/gpii/universal/LICENSE.txt // Node is running. Add a running cat process. No such command as why. var cat = spawn ("cat"); var solutions = ["node", "cat", "why"]; - var procInfos = processes.findSolutionsByCommands (solutions); + var procInfos = processReporter.findSolutionsByCommands (solutions); jqUnit.assertTrue ("Node and cat processes", procInfos.length >= 2); procInfos.forEach (function (item) { var isNode = item.command === "node"; @@ -246,7 +246,7 @@ https://github.com/gpii/universal/LICENSE.txt // Node is running. Add a running cat process. var cat = spawn ("cat"); var pids = [process.pid, cat.pid]; - var procInfos = processes.findSolutionsByPids (pids); + var procInfos = processReporter.findSolutionsByPids (pids); jqUnit.assertEquals ("Node and cat processes", 2, procInfos.length); procInfos.forEach (function (item) { var isNode = item.pid === process.pid; @@ -259,9 +259,9 @@ https://github.com/gpii/universal/LICENSE.txt // Test real life scenario: Use the GPII's gsettings bridge to launch // and shut down orca, and track the changes in state. jqUnit.test ( - "Test gpii.processes against launching orca.", + "Test gpii.processReporter against launching orca.", function() { - var orcaProcInfo = processes.findFirstProcessByCommand ("orca"); + var orcaProcInfo = processReporter.findFirstProcessByCommand ("orca"); var wasRunning = (orcaProcInfo !== null); // Start orca -- does nothing if orca is already running. nodeGSettings.set_gsetting ( @@ -270,7 +270,7 @@ https://github.com/gpii/universal/LICENSE.txt // Give orca some time to start and initialize itself. Then look // for the 'orca' process. procTests.wait5sec(); - orcaProcInfo = processes.findFirstProcessByCommand ("orca"); + orcaProcInfo = processReporter.findFirstProcessByCommand ("orca"); jqUnit.assertNotNull ("Orca is running", orcaProcInfo); // Quit orca, giving it some time to quit itself. Then look for the @@ -279,10 +279,10 @@ https://github.com/gpii/universal/LICENSE.txt "org.gnome.desktop.a11y.applications", "screen-reader-enabled", false ); procTests.wait5sec(); - var orcaProcNewState = processes.findProcessByPid (orcaProcInfo.pid); + var orcaProcNewState = processReporter.findProcessByPid (orcaProcInfo.pid); jqUnit.assertNull ("Orca no longer running", orcaProcNewState); - var orcaMonitor = processes.initMonitor (orcaProcInfo); - processes.hasStateChanged (orcaMonitor); + var orcaMonitor = processReporter.initMonitor (orcaProcInfo); + processReporter.hasStateChanged (orcaMonitor); jqUnit.assertEquals ( "Orca process changed state", "NoSuchProcess", orcaMonitor.newProcInfo.state From 556d2872a1d2f41218c85558826aceeedfefe2b3 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Thu, 16 Oct 2014 16:53:16 -0400 Subject: [PATCH 21/78] GPII-442: Updated README.md Updated the readme file to reflect the latest changes. Also tidied the code. --- Gruntfile.js | 2 + gpii/node_modules/processReporter/README.md | 140 +++++++++++++----- .../processReporter/processReporter.js | 47 +++--- .../processReporter/processReporterDemo.js | 12 +- .../processReporter/processReporter_tests.js | 17 +-- 5 files changed, 152 insertions(+), 66 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 3c94efd..e556f2b 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -55,6 +55,8 @@ module.exports = function(grunt) { cleanAlsaBridge: nodeGypShell("node-gyp clean", "gpii/node_modules/alsa/nodealsa"), compileXrandrBridge: nodeGypShell("node-gyp configure build", "gpii/node_modules/xrandr/nodexrandr"), cleanXrandrBridge: nodeGypShell("node-gyp clean", "gpii/node_modules/xrandr/nodexrandr"), + compileProcesses: nodeGypShell("node-gyp configure build", "gpii/node_modules/processReporter/nodeprocesses"), + cleanProcesses: nodeGypShell("node-gyp clean", "gpii/node_modules/processReporter/nodeprocesses"), installUsbLib: { command: [ "sudo cp " + usbListenerDir + "/gpii-usb-user-listener /usr/bin/", diff --git a/gpii/node_modules/processReporter/README.md b/gpii/node_modules/processReporter/README.md index b100277..af53001 100644 --- a/gpii/node_modules/processReporter/README.md +++ b/gpii/node_modules/processReporter/README.md @@ -1,48 +1,120 @@ -GPII Node.js Processes Bridge ------------------------------ +# GPII Process Reporter -The GPII prcoesses bridge is a Node.js bridge to GNOME/Linux's native libraries -to acquire information about running processes, written in C++. +The GPII prcoesses reporter is made up of two parts: -To compile the module: +* a Nodejs bridge to GNOME/Linux's native libraries to acquire information about running processes. +* a fluid evented component that provides an interface for: + * locating processes based on solution "commands". + * locating processes based on solution process ids. + * locating processes by command. + * locating a process by its process id. + * emitting an event when a process changes state (`onStateChange`). + * emitting an event when a process switch run state (`onRunStateChange`). -* Run build.sh at the top of this repository (TBD -- use Gruntfile.js?). +Here is how the parts fit together, from the bottom up. -Or, by hand: +## Nodejs Bridge -* cd nodeprocesses -* node-gyp configure build -* node nodeprocesses_tests.js # Run the tests +The code for the bridge is in the sub-folder "nodeprocesses". In essence, it consists of one JavaScript function to acquire a list of all the processes on the machine, and represnt each process as a set of properties. The properties are: +* command - a string that identifies the command associated with the process. +* pid - an integer that uniquely identifies the process +* ppid - the parent process id. +* uid - an integer that uniquely identifies the associated user. +* gid - an integer that uniquely identifies the group that the user. +* fullPath - the full path to the executable that launched the process. +* argv - the array of arguments passed to the executable at launch. +* state - a string representing the current state of the process. -Notes ------ +Using orca as an example, the structure is: + +``` +{ + command: 'orca', + pid: 7330, + ppid: 1315, + uid: 1000, + gid: 1000, + fullPath: '/usr/bin/python3', + argv: [ '/usr/bin/python3', '/usr/bin/orca' ], + state: 'Sleeping' +} ``` -var procArray = nodeprocess.getProcesses(); +The state property can have a number of values, listed below. These are grouped according to how the processReporter component sees a process as "running" vs. "not-running": -var commandName = "orca"; -var orcaProc = fluid.find (procArray, function (procInfo) { - if (procInfo.command === commandName) { - return procInfo; - } - }, null); +* running: + * "Running" + * "Uninterruptible" + * "Sleeping" + * "Stopped" +* not-running: + * "Zombie" + * "NoSuchProcess" -A proccess is represented by the following structure (using orca as an example): +Note: "NoSuchProcess" is *not* returned by the nodeprocess bridge, nor the GNOME/Linux process library. If there is no process matching a pid or command, then there is no process information provided. The processReporter component adds the "NoSuchProcess" state as a special case. -{ - pid: 3911, - uid: 1000, - gid: 1000, - command: 'orca', - fullPath: '/usr/bin/python3', - argv: [ '/usr/bin/python3', '/usr/bin/orca' ], - state: 'Sleeping' +### Building Nodejs Bridge + +Use the grunt file in the parent "linux" folder: + +`$ grunt shell:compileProcesses` + +## Process Reporter + +The process reporter is a fluid evented component that makes use of the nodeprocesses bridge and provides filters for locating processes by command, or by process id. There are also methods for determing if a process has changed state, and, in particular, whether the process has switched between a "running" state vs. a "not-running" state. The relevant files are: + +* processReporter.js - the process reporter component. +* processReporter_tests.js - unit tests for the componenet. +* processReporterDemo.js - a demo script that tracks the status of the "orca' process. + +There are two experimental features of the reporter that likely require more thought. The first of these is a reliance on ```setInterval()``` to periodically check the status of a given process. The second is a guess as to how the proces reporter could interface with the solutions registry to determine if a solution is running or not. + +### Events `onRunStateChange` and `onStateChange` + +With respect to periodically checking for a change in process status, processReporter provides two events, each with methods for attaching listeners that react to changes in process status. + +The `onRunStateChange` event is fired when a process changes from a "running" state to a "not-running" state. The method `trackRunState()` takes a process information structure, and a handler function as input. It sets up a periodic check of the state of the given process using the global ```setInterval()```. If the process status changes from "running" to "not-running" or "not-running" to "running", the given handler function is called. The `trackRunState()` method returns the interval identifier returned by ```setIntervalId()```; however, the procesReporter provides a method `stopTrackingRunState()` for shutting down the entire tracking mechanics, including clearing the interval. + +There is also a `onStateChange` event, and associated methods `trackState()` and `stopTrackingState()` that can be used to periodically check *any* change in state of the given prcoess, and react to the change. + +A demonstration of the use of these events is provided in "processReporterDemo.js", using the Orca screen reader. The steps to run the demo are: + + 1. `$ node processReporterDemo.js` + 2. Start a separate terminal session. + 3. In this separate terminal, start/stop Orca the way GPII does: + * `$ gsettings set org.gnome.desktop.a11y.applications screen-reader-enabled true` + * `$ gsettings set org.gnome.desktop.a11y.applications screen-reader-enabled false` + +### Interface with Solutions Registry + +The process reporter also provides a preliminary way for locating processes based on "commands" as provided by the solutions registry. + +In the current solutions registry structure, a solution entry contains a pair of commands to start and stop that solution. These are in the lifeCycleManager sub-structure. In some cases, the actual commands/processes ultimately launched are not specified. + +Sometimes the way to start/stop the solution is to change a system setting. Using Orca as an example, the way to start Orca, if it is not running, is to change the sense of the "screen-reader-enabled" setting. On GNOME, changing that settting from "false" to "true" eventuates in a call to another command that launches the orca process. + +In other words, the process of interest is not directly launched by GPII; the orca process is indirectly launched by changing a setting. + +To make this concrete, here is the lifecycleManager object for the "ORCA Screen Reader" solution entry: + +``` +"lifecycleManager": { + "start": [ + "setSettings", + { + "type": "gpii.launch.exec", + "command": "gsettings set org.gnome.desktop.a11y.applications screen-reader-enabled true" + } + ], + "stop": [ + { + "type": "gpii.launch.exec", + "command": "gsettings set org.gnome.desktop.a11y.applications screen-reader-enabled false" + }, + "restoreSettings" + ] } ``` -The state member can be one of: -* Running -* Stopped -* Zombie -* Uninterruptible -* Sleeping + +There needs to be something in the life cycle structure that documents what *comamnd* is used to create the orca process. I'm assuming whatever that is, it can be passed to the process reporter's `findSolutionsByCommands()` to search the process list and find and return a matching process. From then on, the rest of the processReporter machinery can be used to track the state of that process, even when it is shut down by changing the screen-reader-enable setting to false. diff --git a/gpii/node_modules/processReporter/processReporter.js b/gpii/node_modules/processReporter/processReporter.js index 47de3c0..99e3b23 100644 --- a/gpii/node_modules/processReporter/processReporter.js +++ b/gpii/node_modules/processReporter/processReporter.js @@ -17,7 +17,8 @@ https://github.com/gpii/universal/LICENSE.txt var fluid = require ("universal"); var gpii = fluid.registerNamespace ("gpii"); - var nodeProcesses = require ("./nodeprocesses/build/Release/nodeprocesses.node"); + var nodeProcesses = + require ("./nodeprocesses/build/Release/nodeprocesses.node"); gpii.processReporter = fluid.registerNamespace ("gpii.processReporter"); @@ -34,10 +35,10 @@ https://github.com/gpii/universal/LICENSE.txt }, findSolutionsByPids: { funcName: "gpii.processReporter.findSolutionsByPids", - args: ["{arguments}.0"] // array of pid (process ids) + args: ["{arguments}.0"] // array of pids (process ids) }, getProcesses: { - funcName: "gpii.processReporter.getProcesses", + funcName: "gpii.processReporter.getProcessList", args: [] }, findProcessByPid: { @@ -46,11 +47,13 @@ https://github.com/gpii/universal/LICENSE.txt }, findProcessesByCommand: { funcName: "gpii.processReporter.findProcessesByCommand", - args: ["{arguments}.0", "{arguments}.1"] // command, procArray (optional) + args: ["{arguments}.0", "{arguments}.1"] + // command, procArray (optional) }, findFirstProcessByCommand: { funcName: "gpii.processReporter.findFirstProcessByCommand", - args: ["{arguments}.0", "{arguments}.1"] // command, procArray (optional) + args: ["{arguments}.0", "{arguments}.1"] + // command, procArray (optional) }, hasStateChanged: { funcName: "gpii.processReporter.hasStateChanged", @@ -86,20 +89,24 @@ https://github.com/gpii/universal/LICENSE.txt }, trackRunState: { funcName: "gpii.processReporter.trackRunState", - args: ["{that}", "{arguments}.0", "{arguments}.1"] // process info, handler + args: ["{that}", "{arguments}.0", "{arguments}.1"] + // process info, handler }, stopTrackingRunState: { funcName: "gpii.processReporter.stopTrackingRunState", - args: ["{that}", "{arguments}.0", "{arguments}.1"] // handler, intervalID + args: ["{that}", "{arguments}.0", "{arguments}.1"] + // handler, intervalID }, // Tracking *any* state change. trackState: { funcName: "gpii.processReporter.trackState", - args: ["{that}", "{arguments}.0", "{arguments}.1"] // process info, handler + args: ["{that}", "{arguments}.0", "{arguments}.1"] + // process info, handler }, stopTrackingState: { funcName: "gpii.processReporter.stopTrackingState", - args: ["{that}", "{arguments}.0", "{arguments}.1"] // handler, intervalID + args: ["{that}", "{arguments}.0", "{arguments}.1"] + // handler, intervalID } } }); @@ -109,7 +116,8 @@ https://github.com/gpii/universal/LICENSE.txt gpii.processReporter.findSolutionsByCommands = function (commandNames) { if (!!commandNames) { return fluid.accumulate (commandNames, function (aCommand, matches) { - var procInfos = gpii.processReporter.findProcessesByCommand (aCommand); + var procInfos = + gpii.processReporter.findProcessesByCommand (aCommand); matches = matches.concat (procInfos); return matches; }, []); @@ -171,9 +179,9 @@ https://github.com/gpii/universal/LICENSE.txt // Return the first process of an array of processes all with the same // command name string. If there are no matching processes, return null. - gpii.processReporter.findFirstProcessByCommand = + gpii.processReporter.findFirstProcessByCommand = function (commandName, procArray) { - var commands = + var commands = gpii.processReporter.findProcessesByCommand (commandName, procArray); if (commands.length > 0) { return commands[0]; @@ -186,10 +194,10 @@ https://github.com/gpii/universal/LICENSE.txt // Determine if the state of the given process has changed. Record the // new process information in the monitor. Return boolean. gpii.processReporter.hasStateChanged = function (monitor) { - if (!monitor ||!monitor.procInfo) { + if (!monitor || !monitor.procInfo) { return false; // nothing sought === nothing changed. } - monitor.newProcInfo = + monitor.newProcInfo = gpii.processReporter.updateProcInfo (monitor.procInfo); return (monitor.procInfo.state !== monitor.newProcInfo.state); }; @@ -223,10 +231,11 @@ https://github.com/gpii/universal/LICENSE.txt // nothing sought === nothing changed. return false; } - monitor.newProcInfo = + monitor.newProcInfo = gpii.processReporter.updateProcInfo (monitor.procInfo); var wasRunning = gpii.processReporter.isRunning (monitor.procInfo.state); - var isRunning = gpii.processReporter.isRunning (monitor.newProcInfo.state); + var isRunning = + gpii.processReporter.isRunning (monitor.newProcInfo.state); return (isRunning !== wasRunning); }; @@ -235,13 +244,15 @@ https://github.com/gpii/universal/LICENSE.txt gpii.processReporter.updateProcInfo = function (procInfo) { var newProcInfo = null; if (procInfo.state === "NoSuchProcess") { - newProcInfo = gpii.processReporter.findFirstProcessByCommand (procInfo.command); + newProcInfo = + gpii.processReporter.findFirstProcessByCommand (procInfo.command); } else { newProcInfo = gpii.processReporter.findProcessByPid (procInfo.pid); } if (newProcInfo === null) { - newProcInfo = gpii.processReporter.initProcInfoNotRunning (procInfo.command); + newProcInfo = + gpii.processReporter.initProcInfoNotRunning (procInfo.command); } return newProcInfo; }; diff --git a/gpii/node_modules/processReporter/processReporterDemo.js b/gpii/node_modules/processReporter/processReporterDemo.js index 9fb6717..f6bfbf3 100644 --- a/gpii/node_modules/processReporter/processReporterDemo.js +++ b/gpii/node_modules/processReporter/processReporterDemo.js @@ -33,7 +33,7 @@ var runStateChangeHandler = function (procInfo) { console.log ( procInfo.command + ": run state switched to " + procInfo.state + " (" + - ( processReporter.isRunning (procInfo.state) ? "Running" : "Stopped" ) + + ( processReporter.isRunning (procInfo.state) ? "Running" : "Stopped" ) + ")" ); }; @@ -59,8 +59,10 @@ if (orcaProcInfos.length > 0) { // the command line: // gsettings set org.gnome.desktop.a11y.applications screen-reader-enabled true/false var states = {}; -states.trackRunState = processReporter.trackRunState (orcaProcInfo, runStateChangeHandler); -states.trackState = processReporter.trackState (orcaProcInfo, stateChangeHandler); +states.trackRunState = + processReporter.trackRunState (orcaProcInfo, runStateChangeHandler); +states.trackState = + processReporter.trackState (orcaProcInfo, stateChangeHandler); console.log ("Waiting..."); @@ -70,7 +72,9 @@ seekInput.question ("Stop? ", function (answer) { console.log ("Okay, stopping"); // Cease periodic check of orca's state. - processReporter.stopTrackingRunState (runStateChangeHandler, states.trackRunState); + processReporter.stopTrackingRunState ( + runStateChangeHandler, states.trackRunState + ); processReporter.stopTrackingState (stateChangeHandler, states.trackState); seekInput.close(); } diff --git a/gpii/node_modules/processReporter/processReporter_tests.js b/gpii/node_modules/processReporter/processReporter_tests.js index 99e0f26..84233b2 100644 --- a/gpii/node_modules/processReporter/processReporter_tests.js +++ b/gpii/node_modules/processReporter/processReporter_tests.js @@ -26,7 +26,7 @@ https://github.com/gpii/universal/LICENSE.txt var processReporter = fluid.registerNamespace ("gpii.processReporter"); var procTests = fluid.registerNamespace ("gpii.tests.processes"); - + // Delay 5 seconds. procTests.wait5sec = function() { var t0 = Date.now(); @@ -59,7 +59,7 @@ https://github.com/gpii/universal/LICENSE.txt "Search negative process id value", processReporter.findProcessByPid (-1) ); }); - + jqUnit.test ( "Test findProcessByPid() against nodejs's own process object.", function() { @@ -111,9 +111,9 @@ https://github.com/gpii/universal/LICENSE.txt }); var procInfo = processReporter.findFirstProcessByCommand ("node"); jqUnit.assertNotNull ("Looking for first 'node' processes", procInfo); - jqUnit.assertEquals ("Node commmand name", "node", procInfo.command); + jqUnit.assertEquals ("Node commmand name", "node", procInfo.command); }); - + jqUnit.test ( "Test initProcInfoNotRunning()", function() { @@ -153,7 +153,7 @@ https://github.com/gpii/universal/LICENSE.txt "Check change in process info", procInfo, newProcInfo ); }); - + jqUnit.test ( "Test updateProcInfo() against changing process", function() { @@ -237,7 +237,7 @@ https://github.com/gpii/universal/LICENSE.txt var isCat = item.command === "cat"; jqUnit.assertTrue ("Process name node nor cat", isNode || isCat); }); - cat.kill ("SIGHUP"); + cat.kill ("SIGHUP"); }); jqUnit.test ( @@ -253,7 +253,7 @@ https://github.com/gpii/universal/LICENSE.txt var isCat = item.pid === cat.pid; jqUnit.assertTrue ("Process pid node nor cat", isNode || isCat); }); - cat.kill ("SIGHUP"); + cat.kill ("SIGHUP"); }); // Test real life scenario: Use the GPII's gsettings bridge to launch @@ -298,6 +298,3 @@ https://github.com/gpii/universal/LICENSE.txt }()); - - - From 13b218a2d3a041038912967fbcc556034f0e1800 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Fri, 17 Oct 2014 10:59:08 -0400 Subject: [PATCH 22/78] GPII-442: Modified README.md. Added rationale for use of "command" property as a way of identifying a process. --- gpii/node_modules/processReporter/README.md | 24 ++++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/gpii/node_modules/processReporter/README.md b/gpii/node_modules/processReporter/README.md index af53001..5ab0064 100644 --- a/gpii/node_modules/processReporter/README.md +++ b/gpii/node_modules/processReporter/README.md @@ -2,7 +2,7 @@ The GPII prcoesses reporter is made up of two parts: -* a Nodejs bridge to GNOME/Linux's native libraries to acquire information about running processes. +* a Nodejs bridge to GNOME/Linux's [libgtop library](https://developer.gnome.org/libgtop/stable/) to acquire information about running processes. * a fluid evented component that provides an interface for: * locating processes based on solution "commands". * locating processes based on solution process ids. @@ -15,13 +15,21 @@ Here is how the parts fit together, from the bottom up. ## Nodejs Bridge -The code for the bridge is in the sub-folder "nodeprocesses". In essence, it consists of one JavaScript function to acquire a list of all the processes on the machine, and represnt each process as a set of properties. The properties are: +The code for the bridge is in the sub-folder "nodeprocesses". In essence, it consists of one JavaScript function to acquire a list of all the processes on the machine, and represnt each process as a set of properties. + +The first property, "command", is provided by libgtop and is conceptually the name of the process. Both GNOME/Linux and Mac OS X have a GUI process viewer where they display this property as the "process name". Nodejs has a "process" global object, which represents the Nodejs process itself, that uses a "title" property for the same purpose. Within bash, a simple way to find a process is to list them all using `ps` and then `grep` for the command name, e.g.: + +```$ ps aux | grep node``` + +Unfortunately, the command name is not unique in the sense that more than one process can have the same name. There can be multiple "node" processes runnning simultaneously. The process id, however, is unique. Once a process has been found via its command name, thereafter, one can use its process id to reference that one process. + +The full set of properties are: * command - a string that identifies the command associated with the process. * pid - an integer that uniquely identifies the process -* ppid - the parent process id. +* ppid - the parent process id, unique to the parent. * uid - an integer that uniquely identifies the associated user. -* gid - an integer that uniquely identifies the group that the user. +* gid - an integer that uniquely identifies the group the user belongs to. * fullPath - the full path to the executable that launched the process. * argv - the array of arguments passed to the executable at launch. * state - a string representing the current state of the process. @@ -74,7 +82,7 @@ There are two experimental features of the reporter that likely require more tho With respect to periodically checking for a change in process status, processReporter provides two events, each with methods for attaching listeners that react to changes in process status. -The `onRunStateChange` event is fired when a process changes from a "running" state to a "not-running" state. The method `trackRunState()` takes a process information structure, and a handler function as input. It sets up a periodic check of the state of the given process using the global ```setInterval()```. If the process status changes from "running" to "not-running" or "not-running" to "running", the given handler function is called. The `trackRunState()` method returns the interval identifier returned by ```setIntervalId()```; however, the procesReporter provides a method `stopTrackingRunState()` for shutting down the entire tracking mechanics, including clearing the interval. +The `onRunStateChange` event is fired when a process changes from a "running" state to a "not-running" state. The method `trackRunState()` takes a process information structure, and a handler function as input. It sets up a periodic check of the state of the given process using the global ```setInterval()```. If the process status changes from "running" to "not-running" or "not-running" to "running", the given handler function is called. The `trackRunState()` method returns the interval identifier returned by ```setInterval()```; however, the procesReporter provides a method `stopTrackingRunState()` for shutting down the entire tracking mechanics, including clearing the interval. There is also a `onStateChange` event, and associated methods `trackState()` and `stopTrackingState()` that can be used to periodically check *any* change in state of the given prcoess, and react to the change. @@ -90,9 +98,9 @@ A demonstration of the use of these events is provided in "processReporterDemo.j The process reporter also provides a preliminary way for locating processes based on "commands" as provided by the solutions registry. -In the current solutions registry structure, a solution entry contains a pair of commands to start and stop that solution. These are in the lifeCycleManager sub-structure. In some cases, the actual commands/processes ultimately launched are not specified. +In the current solutions registry structure, a solution entry contains a pair of commands to start and stop that solution. These are in the lifeCycleManager sub-structure. In some cases, the actual commands/processes ultimately launched are not specified, but are invoked indirectly by changing a system setting. -Sometimes the way to start/stop the solution is to change a system setting. Using Orca as an example, the way to start Orca, if it is not running, is to change the sense of the "screen-reader-enabled" setting. On GNOME, changing that settting from "false" to "true" eventuates in a call to another command that launches the orca process. +Using Orca as an example, the way to start Orca, if it is not running, is to change the "screen-reader-enabled" setting. Changing that settting from "false" to "true" eventuates in a call to another command that launches the orca process. In other words, the process of interest is not directly launched by GPII; the orca process is indirectly launched by changing a setting. @@ -117,4 +125,4 @@ To make this concrete, here is the lifecycleManager object for the "ORCA Screen } ``` -There needs to be something in the life cycle structure that documents what *comamnd* is used to create the orca process. I'm assuming whatever that is, it can be passed to the process reporter's `findSolutionsByCommands()` to search the process list and find and return a matching process. From then on, the rest of the processReporter machinery can be used to track the state of that process, even when it is shut down by changing the screen-reader-enable setting to false. +There needs to be something in the life cycle structure that documents what *comamnd* corresponds to the orca process. I'm assuming whatever that is, it can be passed to the process reporter's `findSolutionsByCommands()` to search the process list and find and return matching processes. From then on, the rest of the processReporter machinery can be used to track the state of that process, even when it is shut down by changing the screen-reader-enable setting to false. From c1146137d7463dd541e6aa3f9c0a5725638a8160 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Fri, 30 Jan 2015 11:10:19 -0500 Subject: [PATCH 23/78] GPII-442: Modified Gruntfile.js Added the "shell:compileProcesses" and "shell:cleanProcesses" tasks to the main build and clean tasks. --- Gruntfile.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Gruntfile.js b/Gruntfile.js index e556f2b..561f9e6 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -83,6 +83,7 @@ module.exports = function(grunt) { grunt.task.run("shell:compileGSettings"); grunt.task.run("shell:compileAlsaBridge"); grunt.task.run("shell:compileXrandrBridge"); + grunt.task.run("shell:compileProcesses"); grunt.task.run("shell:installUsbLib"); }); @@ -90,6 +91,7 @@ module.exports = function(grunt) { grunt.task.run("shell:cleanGSettings"); grunt.task.run("shell:cleanAlsaBridge"); grunt.task.run("shell:cleanXrandrBridge"); + grunt.task.run("shell:cleanProcesses"); grunt.task.run("shell:uninstallUsbLib"); }); From c4ef9fef7ee65ce3577e480c946188edabc8037e Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Fri, 30 Jan 2015 14:17:57 -0500 Subject: [PATCH 24/78] GPII-434: Merge branch 'master' into GPII-442 Merge fire ball changes from upstream. --- Gruntfile.js | 4 +- LICENSE.txt | 23 ++- build.sh | 7 +- clean.sh | 7 +- gpii.js | 38 ++--- gpii/node_modules/alsa/alsa_bridge.js | 64 +++++-- gpii/node_modules/alsa/index.js | 26 +-- gpii/node_modules/alsa/nodealsa/nodealsa.cc | 16 ++ .../alsa/nodealsa/nodealsa_tests.js | 24 +-- .../alsa/test/alsaSettingsHandlerTests.js | 4 +- .../gsettingsBridge/gsettings_bridge.js | 26 +-- gpii/node_modules/gsettingsBridge/index.js | 26 +-- .../nodegsettings/nodegsettings.cc | 27 +-- .../nodegsettings/nodegsettings_tests.js | 26 +-- .../gsettingsBridge/tests/gsettingsTests.js | 26 +-- .../gsettingsBridge/tests/runUnitTests.sh | 14 ++ .../gsettingsBridge/tests/tests.js | 17 ++ gpii/node_modules/orca/index.js | 8 +- gpii/node_modules/orca/orcaSettingsHandler.js | 106 ++++++------ .../orca/test/orcaSettingsHandlerTests.js | 155 ++++++++++++----- gpii/node_modules/xrandr/index.js | 26 +-- .../xrandr/nodexrandr/nodexrandr.cc | 106 ++---------- .../xrandr/nodexrandr/nodexrandr_tests.js | 51 ++---- .../xrandr/test/xrandrSettingsHandlerTests.js | 44 ++--- gpii/node_modules/xrandr/xrandr_bridge.js | 60 ++----- index.js | 25 +++ start.sh | 6 +- tests/AcceptanceTests.js | 31 ++++ tests/README.txt | 25 +++ tests/UnitTests.sh | 35 ++++ .../AcceptanceTests_builtIn.js | 133 --------------- .../AcceptanceTests_builtIn.txt | 10 -- .../AcceptanceTests_include.js | 41 ----- tests/acceptanceTests/AcceptanceTests_orca.js | 156 ------------------ .../acceptanceTests/AcceptanceTests_orca.txt | 6 - .../configs/builtIn_config.json | 21 --- .../configs/builtIn_config.txt | 8 - .../acceptanceTests/configs/orca_config.json | 21 --- tests/acceptanceTests/configs/orca_config.txt | 8 - usbDriveListener/gpii-usb-user-listener | 6 +- 40 files changed, 628 insertions(+), 835 deletions(-) create mode 100644 index.js create mode 100644 tests/AcceptanceTests.js create mode 100644 tests/README.txt create mode 100755 tests/UnitTests.sh delete mode 100644 tests/acceptanceTests/AcceptanceTests_builtIn.js delete mode 100644 tests/acceptanceTests/AcceptanceTests_builtIn.txt delete mode 100644 tests/acceptanceTests/AcceptanceTests_include.js delete mode 100644 tests/acceptanceTests/AcceptanceTests_orca.js delete mode 100644 tests/acceptanceTests/AcceptanceTests_orca.txt delete mode 100644 tests/acceptanceTests/configs/builtIn_config.json delete mode 100644 tests/acceptanceTests/configs/builtIn_config.txt delete mode 100644 tests/acceptanceTests/configs/orca_config.json delete mode 100644 tests/acceptanceTests/configs/orca_config.txt diff --git a/Gruntfile.js b/Gruntfile.js index 561f9e6..4fcee01 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -62,7 +62,9 @@ module.exports = function(grunt) { "sudo cp " + usbListenerDir + "/gpii-usb-user-listener /usr/bin/", "sudo cp " + usbListenerDir + "/gpii-usb-user-listener.desktop /usr/share/applications/", - "sudo mkdir -p /var/lib/gpii" + "sudo mkdir -p /var/lib/gpii", + "sudo touch /var/lib/gpii/log.txt", + "sudo chmod a+rw /var/lib/gpii/log.txt" ].join("&&") }, uninstallUsbLib: { diff --git a/LICENSE.txt b/LICENSE.txt index a90784e..c7445c2 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,18 +1,23 @@ -Copyright 2012, OCAD University -Copyright 2012, Steven Githens -Copyright 2012, Astea Solutions +All modules are Copyright 2014 Raising the Floor - International except +where noted otherwise in the code itself, or if the modules reside in a +separate directory, they may contain explicit declarations of copyright +in both the LICENSE file in the directory in which they reside and in the +code itself. No external contributions are allowed under licenses which are +fundamentally incompatible with the BSD or Apache licenses that the GPII is +distributed under. + All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of OCAD University nor the names of its contributors may - be used to endorse or promote products derived from this software without + list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of OCAD University nor the names of its contributors may + be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" diff --git a/build.sh b/build.sh index 5ada533..d9f380b 100755 --- a/build.sh +++ b/build.sh @@ -7,8 +7,13 @@ # Licensed under the New BSD license. You may not use this file except in # compliance with this License. # +# The research leading to these results has received funding from the European Union's +# Seventh Framework Programme (FP7/2007-2013) +# under grant agreement no. 289016. +# # You may obtain a copy of the License at -# https://github.com/gpii/universal/LICENSE.txt +# https://github.com/GPII/universal/blob/master/LICENSE.txt + echo "This script is deprecated and will be removed in a future release. Please look at using our new grunt tasks." diff --git a/clean.sh b/clean.sh index 3ec362d..d3c8797 100755 --- a/clean.sh +++ b/clean.sh @@ -7,8 +7,13 @@ # Licensed under the New BSD license. You may not use this file except in # compliance with this License. # +# The research leading to these results has received funding from the European Union's +# Seventh Framework Programme (FP7/2007-2013) +# under grant agreement no. 289016. +# # You may obtain a copy of the License at -# https://github.com/gpii/universal/LICENSE.txt +# https://github.com/GPII/universal/blob/master/LICENSE.txt + echo "This script is deprecated and will be removed in a future release. Please look at using our new grunt tasks." diff --git a/gpii.js b/gpii.js index 1fd89bd..e414978 100644 --- a/gpii.js +++ b/gpii.js @@ -1,24 +1,24 @@ -/*! -GPII Linux Personalization Framework Node.js Bootstrap +/* + * GPII Windows Personalization Framework Node.js Bootstrap + * + * Copyright 2012 OCAD University + * Copyright 2014 Lucendo Development Ltd. + * + * Licensed under the New BSD license. You may not use this file except in + * compliance with this License. + * + * The research leading to these results has received funding from the European Union's + * Seventh Framework Programme (FP7/2007-2013) + * under grant agreement no. 289016. + * + * You may obtain a copy of the License at + * https://github.com/GPII/universal/blob/master/LICENSE.txt + */ -Copyright 2012 OCAD University - -Licensed under the New BSD license. You may not use this file except in -compliance with this License. - -You may obtain a copy of the License at -https://github.com/gpii/universal/LICENSE.txt -*/ var fluid = require("universal"), - kettle = fluid.registerNamespace("kettle"); + gpii = fluid.registerNamespace("gpii"); -fluid.require("./gpii/node_modules/gsettingsBridge", require); -fluid.require("./gpii/node_modules/orca", require); -fluid.require("./gpii/node_modules/alsa", require); -fluid.require("./gpii/node_modules/xrandr", require); +require("./index.js"); -kettle.config.makeConfigLoader({ - nodeEnv: kettle.config.getNodeEnv("fm.ps.sr.dr.mm.os.lms.development"), - configPath: kettle.config.getConfigPath() || "../node_modules/universal/gpii/configs" -}); +gpii.start(); diff --git a/gpii/node_modules/alsa/alsa_bridge.js b/gpii/node_modules/alsa/alsa_bridge.js index c72ba80..c4493a2 100644 --- a/gpii/node_modules/alsa/alsa_bridge.js +++ b/gpii/node_modules/alsa/alsa_bridge.js @@ -1,14 +1,18 @@ -/*! -GPII Node.js ALSA Volume Bridge - -Copyright 2013 Emergya - -Licensed under the New BSD license. You may not use this file except in -compliance with this License. - -You may obtain a copy of the License at -https://github.com/gpii/universal/LICENSE.txt -*/ +/* + * GPII Node.js ALSA Volume Bridge + * + * Copyright 2013 Emergya + * + * Licensed under the New BSD license. You may not use this file except in + * compliance with this License. + * + * The research leading to these results has received funding from the European Union's + * Seventh Framework Programme (FP7/2007-2013) + * under grant agreement no. 289016. + * + * You may obtain a copy of the License at + * https://github.com/GPII/universal/blob/master/LICENSE.txt + */ (function () { "use strict"; @@ -54,13 +58,43 @@ https://github.com/gpii/universal/LICENSE.txt return alsa.setSystemVolume(value); }; + // TODO: http://issues.gpii.net/browse/GPII-1028 + // This mechanism has been literaly copied/pasted from XRandR's settings + // handler, which looks like a good approach to deal with this kind of + // settings handler. The use of this approach should be consolidated + // as an utility inside the GPII. + // + gpii.alsa.allSettings = { + masterVolume: { + get: "gpii.alsa.getSystemVolume", + set: "gpii.alsa.setSystemVolume" + } + }; + + gpii.alsa.getImpl = function (settingsRequest) { + settingsRequest = settingsRequest || gpii.alsa.allSettings; + var settings = fluid.transform(settingsRequest, function (value, key) { + var funcEntry = gpii.alsa.allSettings[key]; + if (funcEntry) { + return fluid.invokeGlobalFunction(funcEntry.get); + } else { + fluid.fail("Invalid key to ALSA settings handler - " + + key + " - valid choices are " + JSON.stringify(fluid.keys(gpii.alsa.allSettings))); + } + }); + return settings; + }; + gpii.alsa.get = function (payload){ var app = fluid.copy(payload); + for (var appId in app) { + for (var j = 0; j < app[appId].length; j++) { + var settings = gpii.alsa.getImpl(app[appId][j].settings); - var newSettingsResponse = {masterVolume: gpii.alsa.getSystemVolume()}; - var noOptions = {settings: newSettingsResponse}; - app.data[0] = noOptions; - + var noOptions = { settings: settings }; + app[appId][j] = noOptions; + } + } return app; }; diff --git a/gpii/node_modules/alsa/index.js b/gpii/node_modules/alsa/index.js index 26b45a5..0fb0654 100644 --- a/gpii/node_modules/alsa/index.js +++ b/gpii/node_modules/alsa/index.js @@ -1,14 +1,18 @@ -/*! -GPII Node.js ALSA Volume Bridge - -Copyright 2013 Emergya - -Licensed under the New BSD license. You may not use this file except in -compliance with this License. - -You may obtain a copy of the License at -https://github.com/gpii/universal/LICENSE.txt -*/ +/* + * GPII Node.js ALSA Volume Bridge + * + * Copyright 2013 Emergya + * + * Licensed under the New BSD license. You may not use this file except in + * compliance with this License. + * + * The research leading to these results has received funding from the European Union's + * Seventh Framework Programme (FP7/2007-2013) + * under grant agreement no. 289016. + * + * You may obtain a copy of the License at + * https://github.com/GPII/universal/blob/master/LICENSE.txt + */ var fluid = require("universal"); diff --git a/gpii/node_modules/alsa/nodealsa/nodealsa.cc b/gpii/node_modules/alsa/nodealsa/nodealsa.cc index e92973d..8b0552a 100644 --- a/gpii/node_modules/alsa/nodealsa/nodealsa.cc +++ b/gpii/node_modules/alsa/nodealsa/nodealsa.cc @@ -1,3 +1,19 @@ +/* + * GPII Node.js Alsa bridge + * + * Copyright 2012 Emergya + * + * Licensed under the New BSD license. You may not use this file except in + * compliance with this License. + * + * The research leading to these results has received funding from the European Union's + * Seventh Framework Programme (FP7/2007-2013) + * under grant agreement no. 289016. + * + * You may obtain a copy of the License at + * https://github.com/GPII/universal/blob/master/LICENSE.txt + */ + #include #include diff --git a/gpii/node_modules/alsa/nodealsa/nodealsa_tests.js b/gpii/node_modules/alsa/nodealsa/nodealsa_tests.js index eaeac00..cafcc24 100644 --- a/gpii/node_modules/alsa/nodealsa/nodealsa_tests.js +++ b/gpii/node_modules/alsa/nodealsa/nodealsa_tests.js @@ -1,14 +1,18 @@ /* -GPII Node.js ALSA Volume Bridge - -Copyright 2013 Emergya - -Licensed under the New BSD license. You may not use this file except in -compliance with this License. - -You may obtain a copy of the License at -https://github.com/gpii/universal/LICENSE.txt -*/ + * GPII Node.js ALSA Volume Bridge + * + * Copyright 2013 Emergya + * + * Licensed under the New BSD license. You may not use this file except in + * compliance with this License. + * + * The research leading to these results has received funding from the European Union's + * Seventh Framework Programme (FP7/2007-2013) + * under grant agreement no. 289016. + * + * You may obtain a copy of the License at + * https://github.com/GPII/universal/blob/master/LICENSE.txt + */ "use strict"; diff --git a/gpii/node_modules/alsa/test/alsaSettingsHandlerTests.js b/gpii/node_modules/alsa/test/alsaSettingsHandlerTests.js index c33347b..8a4ed1d 100644 --- a/gpii/node_modules/alsa/test/alsaSettingsHandlerTests.js +++ b/gpii/node_modules/alsa/test/alsaSettingsHandlerTests.js @@ -47,8 +47,8 @@ jqUnit.test("Running tests for ALSA Settings Handler", function () { payload["org.alsa-project"][0].settings.masterVolume); var newPayload = fluid.copy(payload); - newPayload["org.alsa-project"][0].settingsmasterVolume = - returnPayload["org.alsa-project"][0].settingsmasterVolume.oldValue; + newPayload["org.alsa-project"][0].settings.masterVolume = + returnPayload["org.alsa-project"][0].settings.masterVolume.oldValue; var lastPayload = alsa.set(newPayload); diff --git a/gpii/node_modules/gsettingsBridge/gsettings_bridge.js b/gpii/node_modules/gsettingsBridge/gsettings_bridge.js index b364cd0..20adf32 100644 --- a/gpii/node_modules/gsettingsBridge/gsettings_bridge.js +++ b/gpii/node_modules/gsettingsBridge/gsettings_bridge.js @@ -1,14 +1,18 @@ -/*! -GPII Node.js GSettings Bridge - -Copyright 2012 Steven Githens - -Licensed under the New BSD license. You may not use this file except in -compliance with this License. - -You may obtain a copy of the License at -https://github.com/gpii/universal/LICENSE.txt -*/ +/* + * GPII Node.js GSettings Bridge + * + * Copyright 2012 Steven Githens + * + * Licensed under the New BSD license. You may not use this file except in + * compliance with this License. + * + * The research leading to these results has received funding from the European Union's + * Seventh Framework Programme (FP7/2007-2013) + * under grant agreement no. 289016. + * + * You may obtain a copy of the License at + * https://github.com/GPII/universal/blob/master/LICENSE.txt + */ (function () { "use strict"; diff --git a/gpii/node_modules/gsettingsBridge/index.js b/gpii/node_modules/gsettingsBridge/index.js index c03d2d6..7ae5f70 100644 --- a/gpii/node_modules/gsettingsBridge/index.js +++ b/gpii/node_modules/gsettingsBridge/index.js @@ -1,14 +1,18 @@ -/*! -GPII Node.js GSettings Bridge - -Copyright 2012 Steven Githens - -Licensed under the New BSD license. You may not use this file except in -compliance with this License. - -You may obtain a copy of the License at -https://github.com/gpii/universal/LICENSE.txt -*/ +/* + * GPII Node.js GSettings Bridge + * + * Copyright 2012 Steven Githens + * + * Licensed under the New BSD license. You may not use this file except in + * compliance with this License. + * + * The research leading to these results has received funding from the European Union's + * Seventh Framework Programme (FP7/2007-2013) + * under grant agreement no. 289016. + * + * You may obtain a copy of the License at + * https://github.com/GPII/universal/blob/master/LICENSE.txt + */ var fluid = require("universal"); diff --git a/gpii/node_modules/gsettingsBridge/nodegsettings/nodegsettings.cc b/gpii/node_modules/gsettingsBridge/nodegsettings/nodegsettings.cc index 04c9ce8..09a0593 100644 --- a/gpii/node_modules/gsettingsBridge/nodegsettings/nodegsettings.cc +++ b/gpii/node_modules/gsettingsBridge/nodegsettings/nodegsettings.cc @@ -1,14 +1,19 @@ /* -GPII Node.js GSettings Bridge + * GPII Node.js GSettings Bridge + * + * Copyright 2012 Steven Githens + * + * Licensed under the New BSD license. You may not use this file except in + * compliance with this License. + * + * The research leading to these results has received funding from the European Union's + * Seventh Framework Programme (FP7/2007-2013) + * under grant agreement no. 289016. + * + * You may obtain a copy of the License at + * https://github.com/GPII/universal/blob/master/LICENSE.txt + */ -Copyright 2012 Steven Githens - -Licensed under the New BSD license. You may not use this file except in -compliance with this License. - -You may obtain a copy of the License at -https://github.com/gpii/universal/LICENSE.txt -*/ #include #include @@ -49,7 +54,7 @@ Handle get_gsetting(const Arguments& args) { args[1]->ToString()->WriteAscii(key); GVariant* variant; const GVariantType* type; - + variant = g_settings_get_value(settings,key); type = g_variant_get_type(variant); @@ -85,7 +90,7 @@ Handle set_gsetting(const Arguments& args) { args[0]->ToString()->WriteAscii(schema); settings = g_settings_new(schema); args[1]->ToString()->WriteAscii(key); - if (args[2]->IsBoolean()) { + if (args[2]->IsBoolean()) { status = g_settings_set_boolean(settings,key,args[2]->BooleanValue()); } else if (args[2]->IsNumber()) { diff --git a/gpii/node_modules/gsettingsBridge/nodegsettings/nodegsettings_tests.js b/gpii/node_modules/gsettingsBridge/nodegsettings/nodegsettings_tests.js index 93298b8..c06a27e 100644 --- a/gpii/node_modules/gsettingsBridge/nodegsettings/nodegsettings_tests.js +++ b/gpii/node_modules/gsettingsBridge/nodegsettings/nodegsettings_tests.js @@ -1,14 +1,18 @@ -/*! -GPII Node.js GSettings Bridge - -Copyright 2012 Steven Githens - -Licensed under the New BSD license. You may not use this file except in -compliance with this License. - -You may obtain a copy of the License at -https://github.com/gpii/universal/LICENSE.txt -*/ +/* + * GPII Node.js GSettings Bridge + * + * Copyright 2012 Steven Githens + * + * Licensed under the New BSD license. You may not use this file except in + * compliance with this License. + * + * The research leading to these results has received funding from the European Union's + * Seventh Framework Programme (FP7/2007-2013) + * under grant agreement no. 289016. + * + * You may obtain a copy of the License at + * https://github.com/GPII/universal/blob/master/LICENSE.txt + */ "use strict"; diff --git a/gpii/node_modules/gsettingsBridge/tests/gsettingsTests.js b/gpii/node_modules/gsettingsBridge/tests/gsettingsTests.js index 33d9b94..8a31a9d 100644 --- a/gpii/node_modules/gsettingsBridge/tests/gsettingsTests.js +++ b/gpii/node_modules/gsettingsBridge/tests/gsettingsTests.js @@ -1,14 +1,18 @@ -/*! -XML Settings Handler Tests - -Copyright 2012 Raising the Floor - International - -Licensed under the New BSD license. You may not use this file except in -compliance with this License. - -You may obtain a copy of the License at -https://github.com/gpii/universal/LICENSE.txt -*/ +/* + * XML Settings Handler Tests + * + * Copyright 2012 Raising the Floor - International + * + * Licensed under the New BSD license. You may not use this file except in + * compliance with this License. + * + * The research leading to these results has received funding from the European Union's + * Seventh Framework Programme (FP7/2007-2013) + * under grant agreement no. 289016. + * + * You may obtain a copy of the License at + * https://github.com/GPII/universal/blob/master/LICENSE.txt + */ /*global require */ diff --git a/gpii/node_modules/gsettingsBridge/tests/runUnitTests.sh b/gpii/node_modules/gsettingsBridge/tests/runUnitTests.sh index 45bb241..88fc557 100755 --- a/gpii/node_modules/gsettingsBridge/tests/runUnitTests.sh +++ b/gpii/node_modules/gsettingsBridge/tests/runUnitTests.sh @@ -1,3 +1,17 @@ +# Unit test runner for gsettings bridge +# +# Copyright 2012 Emergya +# +# Licensed under the New BSD license. You may not use this file except in +# compliance with this License. +# +# The research leading to these results has received funding from the European Union's +# Seventh Framework Programme (FP7/2007-2013) +# under grant agreement no. 289016. +# +# You may obtain a copy of the License at +# https://github.com/GPII/universal/blob/master/LICENSE.txt + #!/bin/bash LOC="/usr/share/glib-2.0/schemas" diff --git a/gpii/node_modules/gsettingsBridge/tests/tests.js b/gpii/node_modules/gsettingsBridge/tests/tests.js index ccce352..fc530ce 100644 --- a/gpii/node_modules/gsettingsBridge/tests/tests.js +++ b/gpii/node_modules/gsettingsBridge/tests/tests.js @@ -1,5 +1,22 @@ +/* + * GPII GSettingsbridge tests + * + * Copyright 2013 Emergya + * + * Licensed under the New BSD license. You may not use this file except in + * compliance with this License. + * + * The research leading to these results has received funding from the European Union's + * Seventh Framework Programme (FP7/2007-2013) + * under grant agreement no. 289016. + * + * You may obtain a copy of the License at + * https://github.com/GPII/universal/blob/master/LICENSE.txt + */ "use strict"; +// TODO: These tests look like old junk and have not run in a while - we should probably delete them + var gsettings = require("../gsettings_bridge.js"); var util = require("util"); var fs = require("fs"); diff --git a/gpii/node_modules/orca/index.js b/gpii/node_modules/orca/index.js index 96647cb..8c2cacc 100644 --- a/gpii/node_modules/orca/index.js +++ b/gpii/node_modules/orca/index.js @@ -1,4 +1,4 @@ -/** +/* * GPII Orca Settings Handler * * Copyright 2013 Emergya @@ -7,8 +7,12 @@ * Licensed under the New BSD license. You may not use this file except in * compliance with this License. * + * The research leading to these results has received funding from the European Union's + * Seventh Framework Programme (FP7/2007-2013) + * under grant agreement no. 289016. + * * You may obtain a copy of the License at - * https://github.com/gpii/universal/LICENSE.txt + * https://github.com/GPII/universal/blob/master/LICENSE.txt */ var fluid = require("universal"); diff --git a/gpii/node_modules/orca/orcaSettingsHandler.js b/gpii/node_modules/orca/orcaSettingsHandler.js index b22266e..6941c91 100644 --- a/gpii/node_modules/orca/orcaSettingsHandler.js +++ b/gpii/node_modules/orca/orcaSettingsHandler.js @@ -1,4 +1,4 @@ -/** +/* * GPII Orca Settings Handler * * Copyright 2013 Emergya @@ -7,8 +7,12 @@ * Licensed under the New BSD license. You may not use this file except in * compliance with this License. * + * The research leading to these results has received funding from the European Union's + * Seventh Framework Programme (FP7/2007-2013) + * under grant agreement no. 289016. + * * You may obtain a copy of the License at - * https://github.com/gpii/universal/LICENSE.txt + * https://github.com/GPII/universal/blob/master/LICENSE.txt */ (function () { @@ -43,7 +47,7 @@ // which main key equals to the profile's id. As we need to retrieve a // specific profile under 'profiles' section, we need to get the second // value (the id) from the array. - // + // var PROFILE_ID = 1; fluid.registerNamespace("gpii.launch"); @@ -75,74 +79,64 @@ } function applySettings(app) { - var settings = app["org.gnome.orca"][0].settings; - var options = app["org.gnome.orca"][0].options; - var user = options.user; + var settings = app.settings; var userSettings = require(orcaSettingsFile); - var defaultProfiles = fluid.copy(userSettings.profiles); - var defaultStartingProfile = fluid.copy(userSettings.general.startingProfile); - var customizedProfile = fluid.copy(userSettings.general); - - if ("profiles" in settings) { - userSettings.profiles = settings.profiles; - userSettings.general.startingProfile = settings["general.startingProfile"]; - } else { - fluid.log("orcaSettingsHandler: User ", user, - " has requested these following settings: ", settings); - - for (var k in settings) { - fluid.set(customizedProfile, k, settings[k], fluid.model.escapedSetConfig); - } + var currentSettingsInProfile = userSettings.profiles[userSettings.general.activeProfile[PROFILE_ID]]; - customizedProfile.profile = customizedProfile.activeProfile = - customizedProfile.startingProfile = - [user, user]; + var applier = fluid.makeChangeApplier(currentSettingsInProfile, { + resolverGetConfig: fluid.model.escapedGetConfig, + resolverSetConfig: fluid.model.escapedSetConfig + }); - userSettings.profiles[user] = customizedProfile; - userSettings.general.startingProfile = [user, user]; - } + var newSettingsResponse = {}; + fluid.each(settings, function (settingVal, settingKey) { + var oldValue = fluid.get(currentSettingsInProfile, settingKey, + fluid.model.escapedGetConfig); + + var change = { + path: settingKey, + value: settingVal + }; + change.type = settingVal === undefined ? "DELETE" : "ADD"; + applier.fireChangeRequest(change); + + newSettingsResponse[settingKey] = { + "oldValue": oldValue, + "newValue": settingVal + }; + + fluid.set(currentSettingsInProfile, settingKey, settings[settingKey], + fluid.model.escapedSetConfig); + }); + + userSettings.profiles[userSettings.general.activeProfile[PROFILE_ID]] = currentSettingsInProfile; fs.writeFileSync(orcaSettingsFile, JSON.stringify(userSettings, null, 4)); - var newSettingsResponse = { - "profiles": { - "oldValue": defaultProfiles, - "newValue": userSettings.profiles - }, - "general.startingProfile": { - "oldValue": defaultStartingProfile, - "newValue": [user, user] - } - }; - - return { "settings": newSettingsResponse}; + return newSettingsResponse; } - gpii.orca.get = function (payload) { + gpii.orca.getImpl = function (payload) { var app = fluid.copy(payload); - var settings = fluid.get(app, "data.0.settings"); + var settings = app.settings; var newSettingsResponse = {}; - var userRequestedSettings = settings; var userSettings = require(orcaSettingsFile); - var currentSettings = userSettings.profiles[userSettings.general.startingProfile[PROFILE_ID]]; + var currentSettingsInProfile = userSettings.profiles[userSettings.general.activeProfile[PROFILE_ID]]; - fluid.each(userRequestedSettings, function (settingVal, settingKey) { - var value = fluid.get(currentSettings, settingKey, + newSettingsResponse = fluid.transform(settings, function (settingVal, settingKey) { + var value = fluid.get(currentSettingsInProfile, settingKey, fluid.model.escapedGetConfig); - newSettingsResponse[settingKey] = value; + return value; }); - var noOptions = {settings: newSettingsResponse}; - app.data[0] = noOptions; - - return app; + return newSettingsResponse; }; - gpii.orca.set = function (profile) { + gpii.orca.setImpl = function (profile) { var returnObj = fluid.copy(profile); var exists = fs.existsSync(orcaSettingsFile); @@ -171,9 +165,17 @@ } var returnValue = applySettings(profile); - fluid.set(returnObj, ["org.gnome.orca", 0], returnValue); + returnObj = returnValue; + + return returnValue; + }; + + gpii.orca.get = function (payload) { + return gpii.settingsHandlers.invokeSettingsHandler(gpii.orca.getImpl, payload); + }; - return returnObj; + gpii.orca.set = function (payload) { + return gpii.settingsHandlers.invokeSettingsHandler(gpii.orca.setImpl, payload); }; })(); diff --git a/gpii/node_modules/orca/test/orcaSettingsHandlerTests.js b/gpii/node_modules/orca/test/orcaSettingsHandlerTests.js index 4267a9f..19bda45 100644 --- a/gpii/node_modules/orca/test/orcaSettingsHandlerTests.js +++ b/gpii/node_modules/orca/test/orcaSettingsHandlerTests.js @@ -1,14 +1,18 @@ /* -Orca Settings Handler Tests - -Copyright 2013 Emergya - -Licensed under the New BSD license. You may not use this file except in -compliance with this License. - -You may obtain a copy of the License at -https://github.com/gpii/universal/LICENSE.txt -*/ + * Orca Settings Handler Tests + * + * Copyright 2013, 2014 Emergya + * + * Licensed under the New BSD license. You may not use this file except in + * compliance with this License. + * + * The research leading to these results has received funding from the European Union's + * Seventh Framework Programme (FP7/2007-2013) + * under grant agreement no. 289016. + * + * You may obtain a copy of the License at + * https://github.com/GPII/universal/blob/master/LICENSE.txt + */ "use strict"; @@ -16,19 +20,34 @@ var fluid = require("universal"), jqUnit = fluid.require("jqUnit"); require("orca"); +var gpii = fluid.registerNamespace("gpii"); var orca = fluid.registerNamespace("gpii.orca"); jqUnit.module("OrcaSettingsHandler Module"); jqUnit.test("Running tests for Orca Settings Handler", function () { - jqUnit.expect(10); - var payload = { + // Complete get/set flow + // + var getPayload = { "org.gnome.orca": [{ - options: { - "user": "test1" - }, - settings: { + "settings": { + "enableBraille": null, + "enableEchoByWord": null, + "enableEchoByCharacter": null, + "voices.default.rate": null, + "enableTutorialMessages": null, + "voices.default.family": null, + "verbalizePunctuationStyle": null + } + }] + }; + var defaultSettingsPayload = gpii.resolveSync(orca.get(getPayload)); + jqUnit.assertTrue("orca.get is returning a valid Object", defaultSettingsPayload); + + var setPayload = { + "org.gnome.orca": [{ + "settings": { "enableBraille": true, "enableEchoByWord": true, "enableEchoByCharacter": false, @@ -40,44 +59,92 @@ jqUnit.test("Running tests for Orca Settings Handler", function () { }] }; - var returnPayload = orca.set(payload); + var returnPayload = gpii.resolveSync(orca.set(setPayload)); + var settings = returnPayload["org.gnome.orca"][0].settings; - // Check if profile exists + fluid.each(settings, function (v, k) { + var expectedValue = setPayload["org.gnome.orca"][0].settings[k]; + jqUnit.assertDeepEq("Setting " + k + " is being set well", expectedValue, v.newValue); + }); - jqUnit.assertTrue("Profile 'test1' exists", returnPayload["org.gnome.orca"][0].settings.profiles.newValue.test1); + var returnGetPayload = gpii.resolveSync(orca.get(getPayload)); + jqUnit.assertDeepEq("Get payload is as expected after updating the settings", returnGetPayload, setPayload); - // Check if 'test1' is the default starting profile + orca.set(defaultSettingsPayload); + var currentSettingsPayload = gpii.resolveSync(orca.get(getPayload)); + jqUnit.assertDeepEq("Settings are being restored well", currentSettingsPayload, defaultSettingsPayload); - var actual = returnPayload["org.gnome.orca"][0].settings["general.startingProfile"].newValue; - jqUnit.assertDeepEq("'test1' is the new starting profile", ["test1", "test1"], actual); + // Complete get/set flow with non-existent settings. + // + var getPayload2 = { + "data": [{ + "settings": { + "foo": null, + "cat.name": null, + "cat.age": null + } + }] + }; - // Check for specific one-to-one settings from the payload + var defaultSettingsPayload2 = gpii.resolveSync(orca.get(getPayload2)); - for (var setting in ["enableBraille", "enableEchoByWord", "enableEchoByCharacter", "enableTutorialMessages", "verbalizePunctuationStyle"]) { - jqUnit.assertDeepEq("Checking " + setting + " setting", - payload["org.gnome.orca"][0].settings[setting], - returnPayload["org.gnome.orca"][0].settings.profiles.newValue.test1[setting]); - } + var setPayload2 = { + "data": [{ + "settings": { + "foo": "bar", + "cat.name": "CATTT", + "cat.age": 3 + } + }] + }; - // Check for voices' stuff - // - jqUnit.assertDeepEq("Checking for voices.default.rate setting", - payload["org.gnome.orca"][0].settings["voices.default.rate"], - returnPayload["org.gnome.orca"][0].settings.profiles.newValue.test1.voices["default"].rate); + var returnPayload2 = gpii.resolveSync(orca.set(setPayload2)); + var settings2 = fluid.copy(returnPayload2.data[0].settings); + fluid.each(settings2, function (v, k) { + var expectedValue = setPayload2.data[0].settings[k]; + jqUnit.assertDeepEq("Non-existent setting " + k + " is being set well", expectedValue, v.newValue); + }); - jqUnit.assertDeepEq("Checking for voices.default.family setting", - payload["org.gnome.orca"][0].settings["voices.default.family"], - returnPayload["org.gnome.orca"][0].settings.profiles.newValue.test1.voices["default"].family); + // Restore the settings + orca.set(defaultSettingsPayload2); + var currentSettingsPayload2 = gpii.resolveSync(orca.get(getPayload2)); + jqUnit.assertDeepEq("Non-existent settings are being restored well", currentSettingsPayload2, defaultSettingsPayload2); - // Let's simulate a logout and restore the settings file into its initial state + // Complete get/set flow with multiple solution entries. // - var newPayload = fluid.copy(payload); - newPayload["org.gnome.orca"][0].settings.profiles = returnPayload["org.gnome.orca"][0].settings.profiles.oldValue; - newPayload["org.gnome.orca"][0].settings["general.startingProfile"] = returnPayload["org.gnome.orca"][0].settings["general.startingProfile"].oldValue; - var newReturnPayload = orca.set(newPayload); + var getPayload3 = { + "data": [{ + "settings": { + "foo": null + } + }], + "otherData": [{ + "settings": { + "john": null + } + }] + }; - // Check if 'test1' profile has been removed successfully - // - jqUnit.assertFalse("Profile 'test1' does not exists", newReturnPayload["org.gnome.orca"][0].settings.profiles.newValue.test1); + var defaultSettingsPayload3 = gpii.resolveSync(orca.get(getPayload3)); + + var setPayload3 = { + "data": [{ + "settings": { + "foo": "bar" + } + }], + "otherData": [{ + "settings": { + "john": "doe" + } + }] + }; + + orca.set(setPayload3); + + // Restore the settings + orca.set(defaultSettingsPayload3); + var currentSettingsPayload3 = gpii.resolveSync(orca.get(getPayload3)); + jqUnit.assertDeepEq("Non-existent settings are being restored well", currentSettingsPayload3, defaultSettingsPayload3); }); diff --git a/gpii/node_modules/xrandr/index.js b/gpii/node_modules/xrandr/index.js index ab7f722..b8d9c41 100644 --- a/gpii/node_modules/xrandr/index.js +++ b/gpii/node_modules/xrandr/index.js @@ -1,14 +1,18 @@ -/*! -GPII Node.js Xrandr Bridge - -Copyright 2013 Emergya - -Licensed under the New BSD license. You may not use this file except in -compliance with this License. - -You may obtain a copy of the License at -https://github.com/gpii/universal/LICENSE.txt -*/ +/* + * GPII Node.js Xrandr Bridge + * + * Copyright 2013 Emergya + * + * Licensed under the New BSD license. You may not use this file except in + * compliance with this License. + * + * The research leading to these results has received funding from the European Union's + * Seventh Framework Programme (FP7/2007-2013) + * under grant agreement no. 289016. + * + * You may obtain a copy of the License at + * https://github.com/GPII/universal/blob/master/LICENSE.txt + */ var fluid = require("universal"); diff --git a/gpii/node_modules/xrandr/nodexrandr/nodexrandr.cc b/gpii/node_modules/xrandr/nodexrandr/nodexrandr.cc index daff26b..d214a7b 100644 --- a/gpii/node_modules/xrandr/nodexrandr/nodexrandr.cc +++ b/gpii/node_modules/xrandr/nodexrandr/nodexrandr.cc @@ -1,3 +1,19 @@ +/* + * GPII Xrandr Bridge Tests + * + * Copyright 2013 Emergya + * + * Licensed under the New BSD license. You may not use this file except in + * compliance with this License. + * + * The research leading to these results has received funding from the European Union's + * Seventh Framework Programme (FP7/2007-2013) + * under grant agreement no. 289016. + * + * You may obtain a copy of the License at + * https://github.com/GPII/universal/blob/master/LICENSE.txt + */ + #include #include @@ -206,92 +222,6 @@ Handle getDisplays(const Arguments& args) { return scope.Close(result); } -Handle getBrightness(const Arguments& args) { - HandleScope scope; - Display *dpy; - static Atom backlight; - int screen = 0, o = 0; - Window root; - XRRScreenResources *resources; - RROutput output; - XRRPropertyInfo *info; - double min, max; - - dpy = XOpenDisplay(NULL); - backlight = XInternAtom (dpy, "Backlight", True); - root = RootWindow(dpy, screen); - resources = XRRGetScreenResources(dpy, root); - output = resources->outputs[o]; - - unsigned char *prop; - int actual_format; - unsigned long nitems, bytes_after; - Atom actual_type; - - XRRGetOutputProperty (dpy, output, backlight, - 0, 100, False, False, - AnyPropertyType, - &actual_type, &actual_format, - &nitems, &bytes_after, &prop); - - info = XRRQueryOutputProperty(dpy, output, backlight); - - const int32_t *val = (const int32_t *) prop; - char backlight_value[11]; - snprintf( backlight_value, sizeof backlight_value, "%" PRId32, *val); - - min = info->values[0]; - max = info->values[1]; - - v8::Handle result = v8::Object::New(); - result->Set(String::New("value"), Int32::New(*val)); - result->Set(String::New("max"), Number::New(max)); - result->Set(String::New("min"), Number::New(min)); - - return scope.Close(result); -} - -Handle setBrightness(const Arguments& args) { - HandleScope scope; - Display *dpy; - static Atom backlight; - int screen = 0, o = 0; - Window root; - XRRScreenResources *resources; - RROutput output; - XRRPropertyInfo *info; - double min, max; - long value; - float argValue; - argValue = args[0]->ToNumber()->Value(); - - dpy = XOpenDisplay(NULL); - backlight = XInternAtom (dpy, "Backlight", True); - root = RootWindow(dpy, screen); - resources = XRRGetScreenResources(dpy, root); - output = resources->outputs[o]; - info = XRRQueryOutputProperty(dpy, output, backlight); - min = info->values[0]; - max = info->values[1]; - XFree(info); // Don't need this anymore - XRRFreeScreenResources(resources); // or this - - value = argValue; - - if (value>max) { - value = max; - } else if (value setScreenResolution(const Arguments& args) { HandleScope scope; Display *dpy; @@ -383,10 +313,6 @@ Handle setScreenResolution(const Arguments& args) { void init(Handle target) { target->Set(String::NewSymbol("getDisplays"), FunctionTemplate::New(getDisplays)->GetFunction()); - target->Set(String::NewSymbol("getBrightness"), - FunctionTemplate::New(getBrightness)->GetFunction()); - target->Set(String::NewSymbol("setBrightness"), - FunctionTemplate::New(setBrightness)->GetFunction()); target->Set(String::NewSymbol("setScreenResolution"), FunctionTemplate::New(setScreenResolution)->GetFunction()); } diff --git a/gpii/node_modules/xrandr/nodexrandr/nodexrandr_tests.js b/gpii/node_modules/xrandr/nodexrandr/nodexrandr_tests.js index cc9d70b..3ca803d 100644 --- a/gpii/node_modules/xrandr/nodexrandr/nodexrandr_tests.js +++ b/gpii/node_modules/xrandr/nodexrandr/nodexrandr_tests.js @@ -1,14 +1,18 @@ /* -GPII Xrandr Bridge Tests - -Copyright 2013 Emergya - -Licensed under the New BSD license. You may not use this file except in -compliance with this License. - -You may obtain a copy of the License at -https://github.com/gpii/universal/LICENSE.txt -*/ + * GPII Xrandr Bridge Tests + * + * Copyright 2013 Emergya + * + * Licensed under the New BSD license. You may not use this file except in + * compliance with this License. + * + * The research leading to these results has received funding from the European Union's + * Seventh Framework Programme (FP7/2007-2013) + * under grant agreement no. 289016. + * + * You may obtain a copy of the License at + * https://github.com/GPII/universal/blob/master/LICENSE.txt + */ "use strict"; @@ -19,39 +23,15 @@ var fluid = require("universal"), jqUnit.module("GPII Xrandr Module"); jqUnit.test("Running tests for Xrandr Bridge", function () { - jqUnit.expect(12); - // Check if all required methods are available through the Xrandr Bridge // - var methods = ["getBrightness", "setBrightness", - "getDisplays", "setScreenResolution"]; + var methods = ["getDisplays", "setScreenResolution"]; for (var method in methods) { jqUnit.assertTrue("Checking availability of method '" + method + "'", (methods[method] in xrandr)); } - var brightness = xrandr.getBrightness().value; - - // Check getBrightness and setBrightness methods - // - jqUnit.assertTrue("Checking that 'setBrightness' method is callable", - xrandr.setBrightness(1)); - - jqUnit.assertTrue("'getBrightness' is callable", - xrandr.getBrightness()); - - jqUnit.assertDeepEq("'getBrightness' returns a expected value" + - " and 'setBrightness' worked as expected", - xrandr.getBrightness().value, 1); - - // Restore brightness to its previous value - // - xrandr.setBrightness(brightness); - - jqUnit.assertDeepEq("Brightness is restored to its previous value", - xrandr.getBrightness().value, brightness); - // Check getDisplays and setScreenResolution methods // jqUnit.assertTrue("Checking that 'getDisplays' method is callable", @@ -71,5 +51,4 @@ jqUnit.test("Running tests for Xrandr Bridge", function () { jqUnit.assertDeepEq("Checking that 'setScreenSize' sets the resolution", xrandr.getDisplays()[0].resolution, resolution); - }); diff --git a/gpii/node_modules/xrandr/test/xrandrSettingsHandlerTests.js b/gpii/node_modules/xrandr/test/xrandrSettingsHandlerTests.js index 2e6d0c9..2ec47c3 100644 --- a/gpii/node_modules/xrandr/test/xrandrSettingsHandlerTests.js +++ b/gpii/node_modules/xrandr/test/xrandrSettingsHandlerTests.js @@ -1,14 +1,18 @@ /* -GPII Xrandr Settings Handler Tests - -Copyright 2013 Emergya - -Licensed under the New BSD license. You may not use this file except in -compliance with this License. - -You may obtain a copy of the License at -https://github.com/gpii/universal/LICENSE.txt -*/ + * GPII Xrandr Settings Handler Tests + * + * Copyright 2013 Emergya + * + * Licensed under the New BSD license. You may not use this file except in + * compliance with this License. + * + * The research leading to these results has received funding from the European Union's + * Seventh Framework Programme (FP7/2007-2013) + * under grant agreement no. 289016. + * + * You may obtain a copy of the License at + * https://github.com/GPII/universal/blob/master/LICENSE.txt + */ "use strict"; @@ -21,13 +25,10 @@ var xrandr = fluid.registerNamespace("gpii.xrandr"); jqUnit.module("GPII Xrandr Module"); jqUnit.test("Running tests for Xrandr Bridge", function () { - jqUnit.expect(10); - // Check if all required methods are available through the // Xrandr Settings Handler. // - var methods = ["getBrightness", "getScreenResolution", "setBrightness", - "setScreenResolution", "get", "set"]; + var methods = ["getScreenResolution", "setScreenResolution", "get", "set"]; for (var method in methods) { jqUnit.assertTrue("Checking availability of method '" + method + "'", (methods[method] in xrandr)); @@ -36,8 +37,7 @@ jqUnit.test("Running tests for Xrandr Bridge", function () { var payload = { "org.freedesktop.xrandr": [{ settings: { - "screen-resolution": {"width": 800, "height": 600}, - "screen-brightness": 1 + "screen-resolution": {"width": 800, "height": 600} } }] }; @@ -48,25 +48,13 @@ jqUnit.test("Running tests for Xrandr Bridge", function () { returnPayload["org.freedesktop.xrandr"][0].settings["screen-resolution"].newValue, payload["org.freedesktop.xrandr"][0].settings["screen-resolution"]); - jqUnit.assertDeepEq("The brightness is being setted well", - returnPayload["org.freedesktop.xrandr"][0].settings["screen-brightness"].newValue, - payload["org.freedesktop.xrandr"][0].settings["screen-brightness"]); - var newPayload = fluid.copy(payload); newPayload["org.freedesktop.xrandr"][0].settings["screen-resolution"] = returnPayload["org.freedesktop.xrandr"][0].settings["screen-resolution"].oldValue; - newPayload["org.freedesktop.xrandr"][0].settings["screen-brightness"] = - returnPayload["org.freedesktop.xrandr"][0].settings["screen-brightness"].oldValue; var lastPayload = xrandr.set(newPayload); jqUnit.assertDeepEq("The resolution is being restored well", returnPayload["org.freedesktop.xrandr"][0].settings["screen-resolution"].oldValue, lastPayload["org.freedesktop.xrandr"][0].settings["screen-resolution"].newValue); - - jqUnit.assertDeepEq("The brightness is being setted well", - returnPayload["org.freedesktop.xrandr"][0].settings["screen-brightness"].oldValue, - lastPayload["org.freedesktop.xrandr"][0].settings["screen-brightness"].newValue); - - }); diff --git a/gpii/node_modules/xrandr/xrandr_bridge.js b/gpii/node_modules/xrandr/xrandr_bridge.js index 4216fb9..7ebe744 100644 --- a/gpii/node_modules/xrandr/xrandr_bridge.js +++ b/gpii/node_modules/xrandr/xrandr_bridge.js @@ -1,14 +1,18 @@ -/*! -GPII Node.js Xrandr Bridge - -Copyright 2013 Emergya - -Licensed under the New BSD license. You may not use this file except in -compliance with this License. - -You may obtain a copy of the License at -https://github.com/gpii/universal/LICENSE.txt -*/ +/* + * GPII Node.js Xrandr Bridge + * + * Copyright 2013 Emergya + * + * Licensed under the New BSD license. You may not use this file except in + * compliance with this License. + * + * The research leading to these results has received funding from the European Union's + * Seventh Framework Programme (FP7/2007-2013) + * under grant agreement no. 289016. + * + * You may obtain a copy of the License at + * https://github.com/GPII/universal/blob/master/LICENSE.txt + */ (function () { "use strict"; @@ -19,25 +23,12 @@ https://github.com/gpii/universal/LICENSE.txt fluid.registerNamespace("gpii.xrandr"); - fluid.defaults("gpii.xrandr.getBrightness", { - gradeNames: "fluid.function", - argumentMap: { - } - }); - fluid.defaults("gpii.xrandr.getScreenResolution", { gradeNames: "fluid.function", argumentMap: { } }); - fluid.defaults("gpii.xrandr.setBrightness", { - gradeNames: "fluid.function", - argumentMap: { - value: 0 - } - }); - fluid.defaults("gpii.xrandr.setScreenResolution", { gradeNames: "fluid.function", argumentMap: { @@ -45,10 +36,6 @@ https://github.com/gpii/universal/LICENSE.txt } }); - gpii.xrandr.getBrightness = function () { - return xrandr.getBrightness().value; - }; - gpii.xrandr.getScreenResolution = function () { var displayInfo = xrandr.getDisplays(); for (var i=0; i Date: Fri, 30 Jan 2015 16:58:59 -0500 Subject: [PATCH 25/78] GPII-442: jshint fixes. --- gpii/node_modules/processReporter/processReporter.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gpii/node_modules/processReporter/processReporter.js b/gpii/node_modules/processReporter/processReporter.js index 99e3b23..eefd9e1 100644 --- a/gpii/node_modules/processReporter/processReporter.js +++ b/gpii/node_modules/processReporter/processReporter.js @@ -125,7 +125,7 @@ https://github.com/gpii/universal/LICENSE.txt else { return []; } - }, + }; // Return an list of process information structures corresponding to the // pids pass in. @@ -142,7 +142,7 @@ https://github.com/gpii/universal/LICENSE.txt else { return []; } - }, + }; // Return a list of processes -- a snapshot of the current processes. gpii.processReporter.getProcessList = function() { From a13c3f10966e0773d467f9e160bd64e9c9a62e0a Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Tue, 3 Feb 2015 13:55:26 -0500 Subject: [PATCH 26/78] GPII-442: Fix Linux/GNOME processReporter unit tests. Modified test for path argument of a process to use the full path. Fixed test for launching and quiting Orca (via gsettings) to test the quit aspect only if Orca started in the first place. --- .../nodeprocesses/nodeprocesses_test.js | 11 ++++--- .../processReporter/processReporter_tests.js | 30 +++++++++++-------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses_test.js b/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses_test.js index 664eef2..a60ec66 100644 --- a/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses_test.js +++ b/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses_test.js @@ -71,15 +71,18 @@ var path = require ("path"), // Loop to compare nodejs argument vector against the one found by // by procTests.getProcesses(). Note that the linux add-on (libgtop) - // returns only the basename for argv[1], whereas node has the full - // path. Compare using Path.basename(). + // returns a path relative to the current directory for argv[1], + // whereas node reports the full path. Compare using Path.resolve(). for (var i = 0; i < process.argv.length; i++) { + var processArg = process.argv[i]; + var nodeProcInfoArg = nodeProcInfo.argv[i]; var processArg = process.argv[i]; if (i === 1) { - processArg = path.basename (processArg); + processArg = path.resolve (processArg); + nodeProcInfoArg = path.resolve (nodeProcInfoArg); } jqUnit.assertEquals ("Node process 'argv[" + i + "]'", - processArg, nodeProcInfo.argv[i]); + processArg, nodeProcInfoArg); } }); diff --git a/gpii/node_modules/processReporter/processReporter_tests.js b/gpii/node_modules/processReporter/processReporter_tests.js index 84233b2..4850197 100644 --- a/gpii/node_modules/processReporter/processReporter_tests.js +++ b/gpii/node_modules/processReporter/processReporter_tests.js @@ -85,15 +85,17 @@ https://github.com/gpii/universal/LICENSE.txt // Loop to compare nodejs argument vector against the one found by // by procTests.getProcesses(). Note that the linux's libgtop - // returns only the basename for argv[1], whereas node has the full - // path. Compare using Path.basename(). + // returns a path relative to the current directory for argv[1], + // whereas node reports the full path. Compare using Path.resolve(). for (var i = 0; i < process.argv.length; i++) { var processArg = process.argv[i]; + var nodeProcInfoArg = nodeProcInfo.argv[i]; if (i === 1) { - processArg = path.basename (processArg); + processArg = path.resolve (processArg); + nodeProcInfoArg = path.resolve (nodeProcInfoArg); } jqUnit.assertEquals ("Node process 'argv[" + i + "]'", - processArg, nodeProcInfo.argv[i]); + processArg, nodeProcInfoArg); } }); @@ -271,7 +273,7 @@ https://github.com/gpii/universal/LICENSE.txt // for the 'orca' process. procTests.wait5sec(); orcaProcInfo = processReporter.findFirstProcessByCommand ("orca"); - jqUnit.assertNotNull ("Orca is running", orcaProcInfo); + jqUnit.assertNotNull ("Start Orca", orcaProcInfo); // Quit orca, giving it some time to quit itself. Then look for the // process whose id matches the formerly running 'orca' process. @@ -279,14 +281,16 @@ https://github.com/gpii/universal/LICENSE.txt "org.gnome.desktop.a11y.applications", "screen-reader-enabled", false ); procTests.wait5sec(); - var orcaProcNewState = processReporter.findProcessByPid (orcaProcInfo.pid); - jqUnit.assertNull ("Orca no longer running", orcaProcNewState); - var orcaMonitor = processReporter.initMonitor (orcaProcInfo); - processReporter.hasStateChanged (orcaMonitor); - jqUnit.assertEquals ( - "Orca process changed state", "NoSuchProcess", - orcaMonitor.newProcInfo.state - ); + if (orcaProcInfo !== null) { + var orcaProcNewState = processReporter.findProcessByPid (orcaProcInfo.pid); + jqUnit.assertNull ("Stop Orca", orcaProcNewState); + var orcaMonitor = processReporter.initMonitor (orcaProcInfo); + processReporter.hasStateChanged (orcaMonitor); + jqUnit.assertEquals ( + "Orca process changed state", "NoSuchProcess", + orcaMonitor.newProcInfo.state + ); + } // Clean up. if (wasRunning) { nodeGSettings.set_gsetting ( From 81b77f775cfaf5c23ca4879950d339e975382ef9 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Tue, 3 Feb 2015 15:55:55 -0500 Subject: [PATCH 27/78] GPII-442: Fixed typo. --- .../processReporter/nodeprocesses/nodeprocesses_test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses_test.js b/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses_test.js index a60ec66..3f2a97a 100644 --- a/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses_test.js +++ b/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses_test.js @@ -76,7 +76,6 @@ var path = require ("path"), for (var i = 0; i < process.argv.length; i++) { var processArg = process.argv[i]; var nodeProcInfoArg = nodeProcInfo.argv[i]; - var processArg = process.argv[i]; if (i === 1) { processArg = path.resolve (processArg); nodeProcInfoArg = path.resolve (nodeProcInfoArg); From 63d88bcc49990a3135490fd686814d264bd01a73 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Wed, 4 Feb 2015 11:13:37 -0500 Subject: [PATCH 28/78] GPII-442: Improved demo. --- .../processReporter/processReporterDemo.js | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/gpii/node_modules/processReporter/processReporterDemo.js b/gpii/node_modules/processReporter/processReporterDemo.js index f6bfbf3..9ccc6f4 100644 --- a/gpii/node_modules/processReporter/processReporterDemo.js +++ b/gpii/node_modules/processReporter/processReporterDemo.js @@ -55,7 +55,7 @@ if (orcaProcInfos.length > 0) { } // Start the periodic check of the change in run-state for orca. -// To see any changes, state/stop orca using, say, the accessibility menu, or +// To see any changes, startstop orca using, say, the accessibility menu, or // the command line: // gsettings set org.gnome.desktop.a11y.applications screen-reader-enabled true/false var states = {}; @@ -66,19 +66,27 @@ states.trackState = console.log ("Waiting..."); -seekInput.question ("Stop? ", function (answer) { +seekInput.setPrompt ("Stop? "); +seekInput.prompt(); +seekInput.on ("line", function (answer) { console.log ("You said " + answer); - if (answer === "yes") { - console.log ("Okay, stopping"); - - // Cease periodic check of orca's state. - processReporter.stopTrackingRunState ( - runStateChangeHandler, states.trackRunState - ); - processReporter.stopTrackingState (stateChangeHandler, states.trackState); - seekInput.close(); - } - else { - console.log ("Okay, continuing"); + switch (answer.trim()) { + case "yes": + console.log ("Okay, stopping"); + + // Cease periodic check of orca's state. + processReporter.stopTrackingRunState ( + runStateChangeHandler, states.trackRunState + ); + processReporter.stopTrackingState (stateChangeHandler, states.trackState); + seekInput.close(); + break; + + default: + console.log ("Okay, continuing"); + break; } + seekInput.prompt(); +}).on ("close", function() { + process.exit(0); }); From 822cb11eec3fabc3baed5922579d5903dc292932 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Wed, 1 Apr 2015 16:18:31 -0400 Subject: [PATCH 29/78] GPII-442: Fixed typo. --- .../node_modules/processReporter/nodeprocesses/nodeprocesses.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses.cc b/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses.cc index 587c5e1..ef942e1 100644 --- a/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses.cc +++ b/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses.cc @@ -1,5 +1,5 @@ /* -GPII Node.js Processes (glitop) Bridge +GPII Node.js Processes (glibtop) Bridge Copyright 2014 Inclusive Design Research Centre, OCAD University From 4eaef90720badeaba3a3ad6673053265ec6220c1 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Wed, 8 Apr 2015 11:17:54 -0400 Subject: [PATCH 30/78] GPII-442: Better variable name. Changed "processes" to "nodeProcesses". Matches variable used in ../processReporter.js (will be renamed to processReporterBridge.js). --- .../processReporter/nodeprocesses/nodeprocesses_test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses_test.js b/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses_test.js index 3f2a97a..e8557c6 100644 --- a/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses_test.js +++ b/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses_test.js @@ -1,5 +1,5 @@ /*! -GPII Node.js Processes Bridge +GPII Node.js Processes Add-on Copyright 2014 Inclusive Design Research Centre, OCAD University @@ -18,7 +18,7 @@ https://github.com/gpii/universal/LICENSE.txt var path = require ("path"), fluid = require ("universal"), jqUnit = fluid.require ("jqUnit"), - processes = require ("./build/Release/nodeprocesses.node"); + nodeProcesses = require ("./build/Release/nodeprocesses.node"); var procTests = fluid.registerNamespace ("gpii.tests.processes"); @@ -26,7 +26,7 @@ var path = require ("path"), // Note that it can return "null" meaning there is no such process running. procTests.matchProcByPid = function (pid, procArray) { if (!procArray) { - procArray = processes.getProcesses(); + procArray = nodeProcesses.getProcesses(); } return fluid.find (procArray, function (procInfo) { if (procInfo.pid === pid) { @@ -40,7 +40,7 @@ var path = require ("path"), jqUnit.test ( "Test getProceses() with 'node' (the nodejs process itself)", function() { - var procInfos = processes.getProcesses(); + var procInfos = nodeProcesses.getProcesses(); jqUnit.assertNotEquals ( "Getting all processes", 0, procInfos.length ); From 6ac330c256ecdce7d173d2639af97851d02e9071 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Wed, 8 Apr 2015 13:07:31 -0400 Subject: [PATCH 31/78] GPII-442: Renamed files and namespaces. - processReporter.js renamed to processesBridge.js - processReporter_tests.js renamed to processesBridge_tests.js - processReporterDemo.js renamed to processesBridgeDemo.js - 'gpii.processReporter' renamed to 'gpii.processes'. --- ...{processReporter.js => processesBridge.js} | 118 +++++++++--------- ...ReporterDemo.js => processesBridgeDemo.js} | 20 +-- ...rter_tests.js => processesBridge_tests.js} | 90 ++++++------- 3 files changed, 114 insertions(+), 114 deletions(-) rename gpii/node_modules/processReporter/{processReporter.js => processesBridge.js} (68%) rename gpii/node_modules/processReporter/{processReporterDemo.js => processesBridgeDemo.js} (79%) rename gpii/node_modules/processReporter/{processReporter_tests.js => processesBridge_tests.js} (76%) diff --git a/gpii/node_modules/processReporter/processReporter.js b/gpii/node_modules/processReporter/processesBridge.js similarity index 68% rename from gpii/node_modules/processReporter/processReporter.js rename to gpii/node_modules/processReporter/processesBridge.js index eefd9e1..8b33826 100644 --- a/gpii/node_modules/processReporter/processReporter.js +++ b/gpii/node_modules/processReporter/processesBridge.js @@ -1,5 +1,5 @@ /*! -GPII Process Reporter -- gpii.processReporter. +GPII Process Reporter processes bridge -- gpii.processes. Copyright 2014 Inclusive Design Research Centre, OCAD University @@ -20,9 +20,9 @@ https://github.com/gpii/universal/LICENSE.txt var nodeProcesses = require ("./nodeprocesses/build/Release/nodeprocesses.node"); - gpii.processReporter = fluid.registerNamespace ("gpii.processReporter"); + gpii.processes = fluid.registerNamespace ("gpii.processes"); - fluid.defaults ("gpii.processReporter", { + fluid.defaults ("gpii.processes", { gradeNames: ["fluid.eventedComponent", "autoInit"], events: { onRunStateChange: null, @@ -30,81 +30,81 @@ https://github.com/gpii/universal/LICENSE.txt }, invokers: { findSolutionsByCommands: { - funcName: "gpii.processReporter.findSolutionsByCommands", + funcName: "gpii.processes.findSolutionsByCommands", args: ["{arguments}.0"] // array of command names }, findSolutionsByPids: { - funcName: "gpii.processReporter.findSolutionsByPids", + funcName: "gpii.processes.findSolutionsByPids", args: ["{arguments}.0"] // array of pids (process ids) }, getProcesses: { - funcName: "gpii.processReporter.getProcessList", + funcName: "gpii.processes.getProcessList", args: [] }, findProcessByPid: { - funcName: "gpii.processReporter.findProcessByPid", + funcName: "gpii.processes.findProcessByPid", args: ["{arguments}.0", "{arguments}.1"] // pid, procArray (optional) }, findProcessesByCommand: { - funcName: "gpii.processReporter.findProcessesByCommand", + funcName: "gpii.processes.findProcessesByCommand", args: ["{arguments}.0", "{arguments}.1"] // command, procArray (optional) }, findFirstProcessByCommand: { - funcName: "gpii.processReporter.findFirstProcessByCommand", + funcName: "gpii.processes.findFirstProcessByCommand", args: ["{arguments}.0", "{arguments}.1"] // command, procArray (optional) }, hasStateChanged: { - funcName: "gpii.processReporter.hasStateChanged", + funcName: "gpii.processes.hasStateChanged", args: ["{arguments}.0"] // process info structure }, isRunning: { - funcName: "gpii.processReporter.isRunning", + funcName: "gpii.processes.isRunning", args: ["{arguments}.0"] // state (string) }, hasSwitchRunState: { - funcName: "gpii.processReporter.hasSwitchedRunState", + funcName: "gpii.processes.hasSwitchedRunState", args: ["{arguments}.0"] // monitor info structure }, updateProcInfo: { - funcName: "gpii.processReporter.updateProcInfo", + funcName: "gpii.processes.updateProcInfo", args: ["{arguments}.0"] // process info structure }, initProcInfoNotRunning: { - funcName: "gpii.processReporter.initProcInfoNotRunning", + funcName: "gpii.processes.initProcInfoNotRunning", args: ["{arguments}.0"] // command name (string) }, initMonitor: { - funcName: "gpii.processReporter.initMonitor", + funcName: "gpii.processes.initMonitor", args: ["{arguments}.0"] // process info structure }, monitorStateChange: { - funcName: "gpii.processReporter.monitorStateChange", + funcName: "gpii.processes.monitorStateChange", args: ["{that}", "{arguments}.0"] // monitor info structure }, monitorRunStateChanged: { - funcName: "gpii.processReporter.monitorRunStateChanged", + funcName: "gpii.processes.monitorRunStateChanged", args: ["{that}", "{arguments}.0"] // monitor info structure }, trackRunState: { - funcName: "gpii.processReporter.trackRunState", + funcName: "gpii.processes.trackRunState", args: ["{that}", "{arguments}.0", "{arguments}.1"] // process info, handler }, stopTrackingRunState: { - funcName: "gpii.processReporter.stopTrackingRunState", + funcName: "gpii.processes.stopTrackingRunState", args: ["{that}", "{arguments}.0", "{arguments}.1"] // handler, intervalID }, // Tracking *any* state change. trackState: { - funcName: "gpii.processReporter.trackState", + funcName: "gpii.processes.trackState", args: ["{that}", "{arguments}.0", "{arguments}.1"] // process info, handler }, stopTrackingState: { - funcName: "gpii.processReporter.stopTrackingState", + funcName: "gpii.processes.stopTrackingState", args: ["{that}", "{arguments}.0", "{arguments}.1"] // handler, intervalID } @@ -113,11 +113,11 @@ https://github.com/gpii/universal/LICENSE.txt // Return an list of process information structures corresponding to the // names of each of the passed in commands. - gpii.processReporter.findSolutionsByCommands = function (commandNames) { + gpii.processes.findSolutionsByCommands = function (commandNames) { if (!!commandNames) { return fluid.accumulate (commandNames, function (aCommand, matches) { var procInfos = - gpii.processReporter.findProcessesByCommand (aCommand); + gpii.processes.findProcessesByCommand (aCommand); matches = matches.concat (procInfos); return matches; }, []); @@ -129,10 +129,10 @@ https://github.com/gpii/universal/LICENSE.txt // Return an list of process information structures corresponding to the // pids pass in. - gpii.processReporter.findSolutionsByPids = function (pids) { + gpii.processes.findSolutionsByPids = function (pids) { if (!!pids) { return fluid.accumulate (pids, function (aPid, matches) { - var found = gpii.processReporter.findProcessByPid (aPid); + var found = gpii.processes.findProcessByPid (aPid); if (found !== null) { matches.push (found); } @@ -145,15 +145,15 @@ https://github.com/gpii/universal/LICENSE.txt }; // Return a list of processes -- a snapshot of the current processes. - gpii.processReporter.getProcessList = function() { + gpii.processes.getProcessList = function() { return nodeProcesses.getProcesses(); }; // Return THE process info object that matches the given process id. // Note that it can return "null" meaning there is no such process. - gpii.processReporter.findProcessByPid = function (pid, procArray) { + gpii.processes.findProcessByPid = function (pid, procArray) { if (!procArray) { - procArray = gpii.processReporter.getProcessList(); + procArray = gpii.processes.getProcessList(); } return fluid.find (procArray, function (procInfo) { if (procInfo.pid === pid) { @@ -165,9 +165,9 @@ https://github.com/gpii/universal/LICENSE.txt // Return an array of process information objects that match the given // command name string. Note that it can return an empty array, meaning // there is no such process. - gpii.processReporter.findProcessesByCommand = function (commandName, procArray) { + gpii.processes.findProcessesByCommand = function (commandName, procArray) { if (!procArray) { - procArray = gpii.processReporter.getProcessList(); + procArray = gpii.processes.getProcessList(); } return fluid.accumulate (procArray, function (aProcInfo, matchingProcs) { if (aProcInfo.command === commandName) { @@ -179,10 +179,10 @@ https://github.com/gpii/universal/LICENSE.txt // Return the first process of an array of processes all with the same // command name string. If there are no matching processes, return null. - gpii.processReporter.findFirstProcessByCommand = + gpii.processes.findFirstProcessByCommand = function (commandName, procArray) { var commands = - gpii.processReporter.findProcessesByCommand (commandName, procArray); + gpii.processes.findProcessesByCommand (commandName, procArray); if (commands.length > 0) { return commands[0]; } @@ -193,18 +193,18 @@ https://github.com/gpii/universal/LICENSE.txt // Determine if the state of the given process has changed. Record the // new process information in the monitor. Return boolean. - gpii.processReporter.hasStateChanged = function (monitor) { + gpii.processes.hasStateChanged = function (monitor) { if (!monitor || !monitor.procInfo) { return false; // nothing sought === nothing changed. } monitor.newProcInfo = - gpii.processReporter.updateProcInfo (monitor.procInfo); + gpii.processes.updateProcInfo (monitor.procInfo); return (monitor.procInfo.state !== monitor.newProcInfo.state); }; // Utility function to conflate process state values into "Running" // (= true) vs. "Not Running" (= false). Returns boolean. - gpii.processReporter.isRunning = function (state) { + gpii.processes.isRunning = function (state) { var result; switch (state) { case "Running": @@ -226,40 +226,40 @@ https://github.com/gpii/universal/LICENSE.txt // Determine if the state of the given process has changed from // "not running" to "running" OR from "running" to "not running". // Return boolean. - gpii.processReporter.hasSwitchedRunState = function (monitor) { + gpii.processes.hasSwitchedRunState = function (monitor) { if (!monitor || !monitor.procInfo) { // nothing sought === nothing changed. return false; } monitor.newProcInfo = - gpii.processReporter.updateProcInfo (monitor.procInfo); - var wasRunning = gpii.processReporter.isRunning (monitor.procInfo.state); + gpii.processes.updateProcInfo (monitor.procInfo); + var wasRunning = gpii.processes.isRunning (monitor.procInfo.state); var isRunning = - gpii.processReporter.isRunning (monitor.newProcInfo.state); + gpii.processes.isRunning (monitor.newProcInfo.state); return (isRunning !== wasRunning); }; // Renew the information on a process, or create a new "NoSuchProcces". // Returns a new procInfo structure. - gpii.processReporter.updateProcInfo = function (procInfo) { + gpii.processes.updateProcInfo = function (procInfo) { var newProcInfo = null; if (procInfo.state === "NoSuchProcess") { newProcInfo = - gpii.processReporter.findFirstProcessByCommand (procInfo.command); + gpii.processes.findFirstProcessByCommand (procInfo.command); } else { - newProcInfo = gpii.processReporter.findProcessByPid (procInfo.pid); + newProcInfo = gpii.processes.findProcessByPid (procInfo.pid); } if (newProcInfo === null) { newProcInfo = - gpii.processReporter.initProcInfoNotRunning (procInfo.command); + gpii.processes.initProcInfoNotRunning (procInfo.command); } return newProcInfo; }; // Create information on a non-running process, to use to detect when the // process starts. - gpii.processReporter.initProcInfoNotRunning = function (command) { + gpii.processes.initProcInfoNotRunning = function (command) { var process = {}; process.command = command; process.pid = -1; @@ -274,7 +274,7 @@ https://github.com/gpii/universal/LICENSE.txt // Create a monitor object for passing to a function that periodically // checks for chanages in the state of a process. - gpii.processReporter.initMonitor = function (procInfo) { + gpii.processes.initMonitor = function (procInfo) { var monitor = {}; monitor.intervalID = -1; monitor.procInfo = procInfo; @@ -284,12 +284,12 @@ https://github.com/gpii/universal/LICENSE.txt // Callback to pass to, e.g., setInterval() to periodically check the state // of a process. - gpii.processReporter.monitorStateChange = function (that, monitor) { - if (gpii.processReporter.hasStateChanged (monitor)) { + gpii.processes.monitorStateChange = function (that, monitor) { + if (gpii.processes.hasStateChanged (monitor)) { var oldProcInfo = monitor.procInfo; if (monitor.newProcInfo === null) { monitor.procInfo = - gpii.processReporter.initProcInfoNotRunning (monitor.procInfo.command); + gpii.processes.initProcInfoNotRunning (monitor.procInfo.command); } else { monitor.procInfo = monitor.newProcInfo; @@ -300,11 +300,11 @@ https://github.com/gpii/universal/LICENSE.txt // Callback to pass to setInterval() to periodically check when the state // changes from "running" to "not running" and vice versa. - gpii.processReporter.monitorRunStateChanged = function (that, monitor) { - if (gpii.processReporter.hasSwitchedRunState (monitor)) { + gpii.processes.monitorRunStateChanged = function (that, monitor) { + if (gpii.processes.hasSwitchedRunState (monitor)) { if (monitor.newProcInfo === null) { monitor.procInfo = - gpii.processReporter.initProcInfoNotRunning (monitor.procInfo.command); + gpii.processes.initProcInfoNotRunning (monitor.procInfo.command); } else { monitor.procInfo = monitor.newProcInfo; @@ -319,32 +319,32 @@ https://github.com/gpii/universal/LICENSE.txt // Provide a way for the outside world to pass in a handler for the // "onRunStateChange" event, and to cancel. - gpii.processReporter.trackRunState = function (that, procInfo, handler) { - var monitor = gpii.processReporter.initMonitor (procInfo); + gpii.processes.trackRunState = function (that, procInfo, handler) { + var monitor = gpii.processes.initMonitor (procInfo); that.events.onRunStateChange.addListener (handler); monitor.intervalID = setInterval (function() { - gpii.processReporter.monitorRunStateChanged (that, monitor); + gpii.processes.monitorRunStateChanged (that, monitor); }); return monitor.intervalID; }; - gpii.processReporter.stopTrackingRunState = function (that, handler, intervalID) { + gpii.processes.stopTrackingRunState = function (that, handler, intervalID) { that.events.onRunStateChange.removeListener (handler); clearInterval (intervalID); }; // Provide a way for the outside world to pass in a handler for the // "onStateChange" event, and to cancel. - gpii.processReporter.trackState = function (that, procInfo, handler) { - var monitor = gpii.processReporter.initMonitor (procInfo); + gpii.processes.trackState = function (that, procInfo, handler) { + var monitor = gpii.processes.initMonitor (procInfo); that.events.onStateChange.addListener (handler); monitor.intervalID = setInterval (function() { - gpii.processReporter.monitorStateChange (that, monitor); + gpii.processes.monitorStateChange (that, monitor); }); return monitor.intervalID; }; - gpii.processReporter.stopTrackingState = function (that, handler, intervalID) { + gpii.processes.stopTrackingState = function (that, handler, intervalID) { that.events.onStateChange.removeListener (handler); clearInterval (intervalID); }; diff --git a/gpii/node_modules/processReporter/processReporterDemo.js b/gpii/node_modules/processReporter/processesBridgeDemo.js similarity index 79% rename from gpii/node_modules/processReporter/processReporterDemo.js rename to gpii/node_modules/processReporter/processesBridgeDemo.js index 9ccc6f4..b5743c7 100644 --- a/gpii/node_modules/processReporter/processReporterDemo.js +++ b/gpii/node_modules/processReporter/processesBridgeDemo.js @@ -15,11 +15,11 @@ https://github.com/gpii/universal/LICENSE.txt var readline = require ("readline"); var fluid = require("universal"); -require ("./processReporter.js"); +require ("./processesBridge.js"); var gpii = fluid.registerNamespace ("gpii"); -gpii.processReporter = fluid.registerNamespace ("gpii.processReporter"); -var processReporter = gpii.processReporter(); +gpii.processesBridge = fluid.registerNamespace ("gpii.processes"); +var processesBridge = gpii.processesBridge(); var seekInput = readline.createInterface ({ input: process.stdin, @@ -33,7 +33,7 @@ var runStateChangeHandler = function (procInfo) { console.log ( procInfo.command + ": run state switched to " + procInfo.state + " (" + - ( processReporter.isRunning (procInfo.state) ? "Running" : "Stopped" ) + + ( processesBridge.isRunning (procInfo.state) ? "Running" : "Stopped" ) + ")" ); }; @@ -48,8 +48,8 @@ var stateChangeHandler = function (oldProcInfo, newProcInfo) { // Initial assumption: not running. Then look for any running orca process. -var orcaProcInfo = processReporter.initProcInfoNotRunning ("orca"); -var orcaProcInfos = processReporter.findProcessesByCommand ("orca"); +var orcaProcInfo = processesBridge.initProcInfoNotRunning ("orca"); +var orcaProcInfos = processesBridge.findProcessesByCommand ("orca"); if (orcaProcInfos.length > 0) { orcaProcInfo = orcaProcInfos[0]; } @@ -60,9 +60,9 @@ if (orcaProcInfos.length > 0) { // gsettings set org.gnome.desktop.a11y.applications screen-reader-enabled true/false var states = {}; states.trackRunState = - processReporter.trackRunState (orcaProcInfo, runStateChangeHandler); + processesBridge.trackRunState (orcaProcInfo, runStateChangeHandler); states.trackState = - processReporter.trackState (orcaProcInfo, stateChangeHandler); + processesBridge.trackState (orcaProcInfo, stateChangeHandler); console.log ("Waiting..."); @@ -75,10 +75,10 @@ seekInput.on ("line", function (answer) { console.log ("Okay, stopping"); // Cease periodic check of orca's state. - processReporter.stopTrackingRunState ( + processesBridge.stopTrackingRunState ( runStateChangeHandler, states.trackRunState ); - processReporter.stopTrackingState (stateChangeHandler, states.trackState); + processesBridge.stopTrackingState (stateChangeHandler, states.trackState); seekInput.close(); break; diff --git a/gpii/node_modules/processReporter/processReporter_tests.js b/gpii/node_modules/processReporter/processesBridge_tests.js similarity index 76% rename from gpii/node_modules/processReporter/processReporter_tests.js rename to gpii/node_modules/processReporter/processesBridge_tests.js index 4850197..613a00b 100644 --- a/gpii/node_modules/processReporter/processReporter_tests.js +++ b/gpii/node_modules/processReporter/processesBridge_tests.js @@ -1,5 +1,5 @@ /*! -GPII Node.js Processes Bridge +GPII Node.js Processes Bridge Unit Tests Copyright 2014 Inclusive Design Research Centre, OCAD University @@ -22,9 +22,9 @@ https://github.com/gpii/universal/LICENSE.txt // TODO: Must be a better way to get node gsettings add-on. nodeGSettings = require ("../gsettingsBridge/nodegsettings/build/Release/nodegsettings.node"); - require ("./processReporter.js"); + require ("./processesBridge.js"); - var processReporter = fluid.registerNamespace ("gpii.processReporter"); + var processesBridge = fluid.registerNamespace ("gpii.processes"); var procTests = fluid.registerNamespace ("gpii.tests.processes"); // Delay 5 seconds. @@ -40,7 +40,7 @@ https://github.com/gpii/universal/LICENSE.txt jqUnit.test ( "Test getProceses()/findProcessByPid() with the nodejs process itself", function() { - var procInfos = processReporter.getProcessList(); + var procInfos = processesBridge.getProcessList(); jqUnit.assertNotEquals ( "Listing all processes", 0, procInfos.length ); @@ -48,7 +48,7 @@ https://github.com/gpii/universal/LICENSE.txt // Check for the presence of this nodejs processs itself -- it must // be in the process list since this code is running inside that // process. - var nodeProc = processReporter.findProcessByPid (process.pid, procInfos); + var nodeProc = processesBridge.findProcessByPid (process.pid, procInfos); jqUnit.assertNotNull ("Searching for 'node' process", nodeProc); }); @@ -56,14 +56,14 @@ https://github.com/gpii/universal/LICENSE.txt "Test findProcessByPid() with non-running process id", function() { jqUnit.assertNull ( - "Search negative process id value", processReporter.findProcessByPid (-1) + "Search negative process id value", processesBridge.findProcessByPid (-1) ); }); jqUnit.test ( "Test findProcessByPid() against nodejs's own process object.", function() { - var nodeProcInfo = processReporter.findProcessByPid (process.pid); + var nodeProcInfo = processesBridge.findProcessByPid (process.pid); jqUnit.assertEquals ("Node process 'name'", process.title, nodeProcInfo.command); @@ -102,7 +102,7 @@ https://github.com/gpii/universal/LICENSE.txt jqUnit.test ( "Test findProcessesByCmd()/findFirstProcessByCmd() with nodejs itself", function() { - var nodeProcInfos = processReporter.findProcessesByCommand ("node"); + var nodeProcInfos = processesBridge.findProcessesByCommand ("node"); jqUnit.assertNotEquals ( "Getting all 'node' processes", 0, nodeProcInfos.length ); @@ -111,7 +111,7 @@ https://github.com/gpii/universal/LICENSE.txt "Node commmand name", "node", aProcInfo.command ); }); - var procInfo = processReporter.findFirstProcessByCommand ("node"); + var procInfo = processesBridge.findFirstProcessByCommand ("node"); jqUnit.assertNotNull ("Looking for first 'node' processes", procInfo); jqUnit.assertEquals ("Node commmand name", "node", procInfo.command); }); @@ -119,7 +119,7 @@ https://github.com/gpii/universal/LICENSE.txt jqUnit.test ( "Test initProcInfoNotRunning()", function() { - var notRunning = processReporter.initProcInfoNotRunning ("grep"); + var notRunning = processesBridge.initProcInfoNotRunning ("grep"); jqUnit.assertEquals ("Command name", notRunning.command, "grep"); jqUnit.assertEquals ("Negative process id", notRunning.pid, -1); jqUnit.assertEquals ( @@ -127,30 +127,30 @@ https://github.com/gpii/universal/LICENSE.txt ); jqUnit.assertNull ( "Search negative process id value", - processReporter.findProcessByPid (notRunning.pid) + processesBridge.findProcessByPid (notRunning.pid) ); }); jqUnit.test ( "Test isRunning() with nodejs itself, and nonexistent process", function() { - var procInfo = processReporter.findProcessByPid (process.pid); + var procInfo = processesBridge.findProcessByPid (process.pid); jqUnit.assertNotNull ("Searching for 'node' process", procInfo); jqUnit.assertTrue ( - "Check nodejs is running", processReporter.isRunning (procInfo.state) + "Check nodejs is running", processesBridge.isRunning (procInfo.state) ); - procInfo = processReporter.initProcInfoNotRunning ("grep"); + procInfo = processesBridge.initProcInfoNotRunning ("grep"); jqUnit.assertFalse ( - "Check nonexistent process running", processReporter.isRunning (procInfo) + "Check nonexistent process running", processesBridge.isRunning (procInfo) ); }); jqUnit.test ( "Test updateProcInfo() against non-changing process", function() { - var procInfo = processReporter.findProcessByPid (process.pid); + var procInfo = processesBridge.findProcessByPid (process.pid); jqUnit.assertNotNull ("Looking for 'node' processes", procInfo); - var newProcInfo = processReporter.updateProcInfo (procInfo); + var newProcInfo = processesBridge.updateProcInfo (procInfo); jqUnit.assertDeepEq ( "Check change in process info", procInfo, newProcInfo ); @@ -160,10 +160,10 @@ https://github.com/gpii/universal/LICENSE.txt "Test updateProcInfo() against changing process", function() { var grep = spawn ("grep", ["ssh"]); - var grepInfo = processReporter.findProcessByPid (grep.pid); + var grepInfo = processesBridge.findProcessByPid (grep.pid); jqUnit.assertNotNull ("Search 'grep' process", grepInfo); jqUnit.assertTrue ("Stop grep", grep.kill ("SIGHUP")); - var newGrepInfo = processReporter.updateProcInfo (grepInfo); + var newGrepInfo = processesBridge.updateProcInfo (grepInfo); jqUnit.assertNotEquals ( "Update process state", newGrepInfo.state, grepInfo.state ); @@ -173,27 +173,27 @@ https://github.com/gpii/universal/LICENSE.txt "Test hasStateChanged()", function() { jqUnit.assertFalse ( - "Check null monitor", processReporter.hasStateChanged (null) + "Check null monitor", processesBridge.hasStateChanged (null) ); - var catMonitor = processReporter.initMonitor (null); + var catMonitor = processesBridge.initMonitor (null); jqUnit.assertFalse ( - "Check null process", processReporter.hasStateChanged (catMonitor) + "Check null process", processesBridge.hasStateChanged (catMonitor) ); - var catProcInfo = processReporter.initProcInfoNotRunning ("cat"); - catMonitor = processReporter.initMonitor (catProcInfo); - var stateChanged = processReporter.hasStateChanged (catMonitor); + var catProcInfo = processesBridge.initProcInfoNotRunning ("cat"); + catMonitor = processesBridge.initMonitor (catProcInfo); + var stateChanged = processesBridge.hasStateChanged (catMonitor); jqUnit.assertFalse ("Check non-running process", stateChanged); var cat = spawn ("cat"); - catMonitor = processReporter.initMonitor (catProcInfo); - stateChanged = processReporter.hasStateChanged (catMonitor); + catMonitor = processesBridge.initMonitor (catProcInfo); + stateChanged = processesBridge.hasStateChanged (catMonitor); jqUnit.assertTrue ("Check running process", stateChanged); // Get the running process info, kill cat, and check again. - catProcInfo = processReporter.findProcessByPid (cat.pid); - catMonitor = processReporter.initMonitor (catProcInfo); + catProcInfo = processesBridge.findProcessByPid (cat.pid); + catMonitor = processesBridge.initMonitor (catProcInfo); cat.kill ("SIGHUP"); - stateChanged = processReporter.hasStateChanged (catMonitor); + stateChanged = processesBridge.hasStateChanged (catMonitor); jqUnit.assertTrue ("Check stopped process", stateChanged); }); @@ -201,16 +201,16 @@ https://github.com/gpii/universal/LICENSE.txt "Test hasSwitchedRunState()", function() { jqUnit.assertFalse ( - "Check null monitor", processReporter.hasSwitchedRunState (null) + "Check null monitor", processesBridge.hasSwitchedRunState (null) ); - var grepProcMonitor = processReporter.initMonitor (null); + var grepProcMonitor = processesBridge.initMonitor (null); jqUnit.assertFalse ( - "Check null process", processReporter.hasSwitchedRunState (grepProcMonitor) + "Check null process", processesBridge.hasSwitchedRunState (grepProcMonitor) ); var grep = spawn ("grep", ["ssh"]); - var grepProcInfo = processReporter.findProcessByPid (grep.pid); - grepProcMonitor = processReporter.initMonitor (grepProcInfo); - var switched = processReporter.hasSwitchedRunState (grepProcMonitor); + var grepProcInfo = processesBridge.findProcessByPid (grep.pid); + grepProcMonitor = processesBridge.initMonitor (grepProcInfo); + var switched = processesBridge.hasSwitchedRunState (grepProcMonitor); jqUnit.assertFalse ("Check running process", switched); jqUnit.assertEquals ( "Process state change", @@ -218,7 +218,7 @@ https://github.com/gpii/universal/LICENSE.txt ); // Kill grep, and check again. grep.kill ("SIGHUP"); - switched = processReporter.hasSwitchedRunState (grepProcMonitor); + switched = processesBridge.hasSwitchedRunState (grepProcMonitor); jqUnit.assertTrue ("Check stopped process", switched); jqUnit.assertNotEquals ( "Process state change", @@ -232,7 +232,7 @@ https://github.com/gpii/universal/LICENSE.txt // Node is running. Add a running cat process. No such command as why. var cat = spawn ("cat"); var solutions = ["node", "cat", "why"]; - var procInfos = processReporter.findSolutionsByCommands (solutions); + var procInfos = processesBridge.findSolutionsByCommands (solutions); jqUnit.assertTrue ("Node and cat processes", procInfos.length >= 2); procInfos.forEach (function (item) { var isNode = item.command === "node"; @@ -248,7 +248,7 @@ https://github.com/gpii/universal/LICENSE.txt // Node is running. Add a running cat process. var cat = spawn ("cat"); var pids = [process.pid, cat.pid]; - var procInfos = processReporter.findSolutionsByPids (pids); + var procInfos = processesBridge.findSolutionsByPids (pids); jqUnit.assertEquals ("Node and cat processes", 2, procInfos.length); procInfos.forEach (function (item) { var isNode = item.pid === process.pid; @@ -261,9 +261,9 @@ https://github.com/gpii/universal/LICENSE.txt // Test real life scenario: Use the GPII's gsettings bridge to launch // and shut down orca, and track the changes in state. jqUnit.test ( - "Test gpii.processReporter against launching orca.", + "Test gpii.processes against launching orca.", function() { - var orcaProcInfo = processReporter.findFirstProcessByCommand ("orca"); + var orcaProcInfo = processesBridge.findFirstProcessByCommand ("orca"); var wasRunning = (orcaProcInfo !== null); // Start orca -- does nothing if orca is already running. nodeGSettings.set_gsetting ( @@ -272,7 +272,7 @@ https://github.com/gpii/universal/LICENSE.txt // Give orca some time to start and initialize itself. Then look // for the 'orca' process. procTests.wait5sec(); - orcaProcInfo = processReporter.findFirstProcessByCommand ("orca"); + orcaProcInfo = processesBridge.findFirstProcessByCommand ("orca"); jqUnit.assertNotNull ("Start Orca", orcaProcInfo); // Quit orca, giving it some time to quit itself. Then look for the @@ -282,10 +282,10 @@ https://github.com/gpii/universal/LICENSE.txt ); procTests.wait5sec(); if (orcaProcInfo !== null) { - var orcaProcNewState = processReporter.findProcessByPid (orcaProcInfo.pid); + var orcaProcNewState = processesBridge.findProcessByPid (orcaProcInfo.pid); jqUnit.assertNull ("Stop Orca", orcaProcNewState); - var orcaMonitor = processReporter.initMonitor (orcaProcInfo); - processReporter.hasStateChanged (orcaMonitor); + var orcaMonitor = processesBridge.initMonitor (orcaProcInfo); + processesBridge.hasStateChanged (orcaMonitor); jqUnit.assertEquals ( "Orca process changed state", "NoSuchProcess", orcaMonitor.newProcInfo.state From c39b340187a3e58de4884018c2ab839e57df880f Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Wed, 8 Apr 2015 13:13:13 -0400 Subject: [PATCH 32/78] GPII-442: Fixed whitespace. --- .../node_modules/processReporter/nodeprocesses/nodeprocesses.cc | 2 +- gpii/node_modules/processReporter/processesBridgeDemo.js | 2 +- gpii/node_modules/processReporter/processesBridge_tests.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses.cc b/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses.cc index ef942e1..648a793 100644 --- a/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses.cc +++ b/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses.cc @@ -93,7 +93,7 @@ makeProcInfo (pid_t pid, glibtop_proclist* procList) { procInfo->Set(String::New("fullPath"), fullPath); procInfo->Set(String::New("argv"), arguments); procInfo->Set(String::New("state"), format_process_state (procstate.state)); - + if (argv != NULL) g_strfreev (argv); diff --git a/gpii/node_modules/processReporter/processesBridgeDemo.js b/gpii/node_modules/processReporter/processesBridgeDemo.js index b5743c7..a78cc56 100644 --- a/gpii/node_modules/processReporter/processesBridgeDemo.js +++ b/gpii/node_modules/processReporter/processesBridgeDemo.js @@ -41,7 +41,7 @@ var runStateChangeHandler = function (procInfo) { // Handler to use to detect any change in state, and print to console. var stateChangeHandler = function (oldProcInfo, newProcInfo) { console.log ( - oldProcInfo.command + " process state switched from " + + oldProcInfo.command + " process state switched from " + oldProcInfo.state + " to " + newProcInfo.state ); }; diff --git a/gpii/node_modules/processReporter/processesBridge_tests.js b/gpii/node_modules/processReporter/processesBridge_tests.js index 613a00b..7bd8011 100644 --- a/gpii/node_modules/processReporter/processesBridge_tests.js +++ b/gpii/node_modules/processReporter/processesBridge_tests.js @@ -267,7 +267,7 @@ https://github.com/gpii/universal/LICENSE.txt var wasRunning = (orcaProcInfo !== null); // Start orca -- does nothing if orca is already running. nodeGSettings.set_gsetting ( - "org.gnome.desktop.a11y.applications","screen-reader-enabled", true + "org.gnome.desktop.a11y.applications","screen-reader-enabled", true ); // Give orca some time to start and initialize itself. Then look // for the 'orca' process. From 8a7645a951ec67eb4979d3d33c082b9fbec9c205 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Fri, 10 Apr 2015 16:24:49 -0400 Subject: [PATCH 33/78] GPII-442: Updated README.md and package.json Updated the readme and package files to reflect the new names of the components/files. --- gpii/node_modules/processReporter/README.md | 20 ++++++++++--------- .../node_modules/processReporter/package.json | 4 ++-- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/gpii/node_modules/processReporter/README.md b/gpii/node_modules/processReporter/README.md index 5ab0064..ef973dc 100644 --- a/gpii/node_modules/processReporter/README.md +++ b/gpii/node_modules/processReporter/README.md @@ -15,9 +15,9 @@ Here is how the parts fit together, from the bottom up. ## Nodejs Bridge -The code for the bridge is in the sub-folder "nodeprocesses". In essence, it consists of one JavaScript function to acquire a list of all the processes on the machine, and represnt each process as a set of properties. +The code for the bridge is in the sub-folder "nodeprocesses". In essence, it consists of one JavaScript function to acquire a list of all the processes on the machine, and represent each process as a set of properties. -The first property, "command", is provided by libgtop and is conceptually the name of the process. Both GNOME/Linux and Mac OS X have a GUI process viewer where they display this property as the "process name". Nodejs has a "process" global object, which represents the Nodejs process itself, that uses a "title" property for the same purpose. Within bash, a simple way to find a process is to list them all using `ps` and then `grep` for the command name, e.g.: +The first property, "command", is provided by GNOME/Linux's libgtop library and is conceptually the name of the process. Both GNOME/Linux and Mac OS X have a GUI process viewer where they display this property as the "process name". Nodejs has a "process" global object, which represents the Nodejs process itself, that uses a "title" property for the same purpose. Within bash, a simple way to find a process is to list them all using `ps` and then `grep` for the command name, e.g.: ```$ ps aux | grep node``` @@ -60,7 +60,7 @@ The state property can have a number of values, listed below. These are grouped * "Zombie" * "NoSuchProcess" -Note: "NoSuchProcess" is *not* returned by the nodeprocess bridge, nor the GNOME/Linux process library. If there is no process matching a pid or command, then there is no process information provided. The processReporter component adds the "NoSuchProcess" state as a special case. +Note: "NoSuchProcess" is not returned by the nodeprocess add-on, nor the GNOME/Linux process library. If there is no process matching a pid or command, then there is no process information provided. The processReporter component adds the "NoSuchProcess" state as a special case. ### Building Nodejs Bridge @@ -68,13 +68,13 @@ Use the grunt file in the parent "linux" folder: `$ grunt shell:compileProcesses` -## Process Reporter +## Process Reporter Bridge -The process reporter is a fluid evented component that makes use of the nodeprocesses bridge and provides filters for locating processes by command, or by process id. There are also methods for determing if a process has changed state, and, in particular, whether the process has switched between a "running" state vs. a "not-running" state. The relevant files are: +The process reporter bridge is a fluid evented component that makes use of the nodeprocesses node add-on and provides filters for locating processes by command, or by process id. There are also methods for determing if a process has changed state, and, in particular, whether the process has switched between a "running" state vs. a "not-running" state. The relevant files are: -* processReporter.js - the process reporter component. -* processReporter_tests.js - unit tests for the componenet. -* processReporterDemo.js - a demo script that tracks the status of the "orca' process. +* processReporterBridge.js - the process reporter component. +* processReporterrBridge_tests.js - unit tests for the componenet. +* processReporterBridgerDemo.js - a demo script that tracks the status of the "orca' process. There are two experimental features of the reporter that likely require more thought. The first of these is a reliance on ```setInterval()``` to periodically check the status of a given process. The second is a guess as to how the proces reporter could interface with the solutions registry to determine if a solution is running or not. @@ -88,12 +88,14 @@ There is also a `onStateChange` event, and associated methods `trackState()` and A demonstration of the use of these events is provided in "processReporterDemo.js", using the Orca screen reader. The steps to run the demo are: - 1. `$ node processReporterDemo.js` + 1. `$ node processReporterBridgeDemo.js` 2. Start a separate terminal session. 3. In this separate terminal, start/stop Orca the way GPII does: * `$ gsettings set org.gnome.desktop.a11y.applications screen-reader-enabled true` * `$ gsettings set org.gnome.desktop.a11y.applications screen-reader-enabled false` +As the screen-reader-enabled setting is toggled between true and false, the processReporterBridgeDemo will output the new (changed) state of Orca. + ### Interface with Solutions Registry The process reporter also provides a preliminary way for locating processes based on "commands" as provided by the solutions registry. diff --git a/gpii/node_modules/processReporter/package.json b/gpii/node_modules/processReporter/package.json index 439888a..a540d41 100644 --- a/gpii/node_modules/processReporter/package.json +++ b/gpii/node_modules/processReporter/package.json @@ -1,6 +1,6 @@ { - "name": "processesBridge", - "description": "The processesBridge is a Node.js add-on using Libgtop.", + "name": "processReporter", + "description": "The Process Reporter module provides information about running solutions on a platform", "version": "0.1.0", "author": "Joseph Scheuhammer", "bugs": "http://wiki.gpii.net/index.php/Main_Page", From 2607cc04f5e4be2c675e323cadef79ba8179c04d Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Tue, 14 Apr 2015 15:00:14 -0400 Subject: [PATCH 34/78] GPII-442: Fixed "grunt jshint" errors. --- .../nodeprocesses/nodeprocesses_test.js | 123 ++-- .../processReporter/processesBridge.js | 465 +++++++------- .../processReporter/processesBridgeDemo.js | 92 +-- .../processReporter/processesBridge_tests.js | 565 +++++++++--------- 4 files changed, 632 insertions(+), 613 deletions(-) diff --git a/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses_test.js b/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses_test.js index e8557c6..8192ce9 100644 --- a/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses_test.js +++ b/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses_test.js @@ -12,77 +12,78 @@ https://github.com/gpii/universal/LICENSE.txt /*global require*/ -(function() { +(function () { "use strict"; -var path = require ("path"), - fluid = require ("universal"), - jqUnit = fluid.require ("jqUnit"), - nodeProcesses = require ("./build/Release/nodeprocesses.node"); + var path = require("path"), + fluid = require("universal"), + jqUnit = fluid.require("jqUnit"), + nodeProcesses = require("./build/Release/nodeprocesses.node"); - var procTests = fluid.registerNamespace ("gpii.tests.processes"); + var procTests = fluid.registerNamespace("gpii.tests.processes"); // Return the process info object that matches the given process id. // Note that it can return "null" meaning there is no such process running. procTests.matchProcByPid = function (pid, procArray) { - if (!procArray) { - procArray = nodeProcesses.getProcesses(); - } - return fluid.find (procArray, function (procInfo) { - if (procInfo.pid === pid) { - return procInfo; - } - }, null); + if (!procArray) { + procArray = nodeProcesses.getProcesses(); + } + return fluid.find(procArray, function (procInfo) { + if (procInfo.pid === pid) { + return procInfo; + } + }, null); }; - jqUnit.module ("Processes Bridge node add-on module"); + jqUnit.module("Processes Bridge node add-on module"); - jqUnit.test ( + jqUnit.test( "Test getProceses() with 'node' (the nodejs process itself)", - function() { - var procInfos = nodeProcesses.getProcesses(); - jqUnit.assertNotEquals ( - "Getting all processes", 0, procInfos.length - ); - - // Check for the presence of this nodejs processs itself -- it must - // be in the process list since this code is running inside that - // process. - var nodeProcInfo = procTests.matchProcByPid (process.pid, procInfos); - jqUnit.assertNotNull ("Searching for 'node' process", nodeProcInfo); - jqUnit.assertEquals ("Node process 'name'", - process.title, nodeProcInfo.command); - - // TODO: Redundant? This is how it was found. - jqUnit.assertEquals ("Node process 'pid'", - process.pid, nodeProcInfo.pid); - - jqUnit.assertEquals ("Node process 'uid'", - process.getuid(), nodeProcInfo.uid); - - jqUnit.assertEquals ("Node process 'gid'", - process.getgid(), nodeProcInfo.gid); - - jqUnit.assertEquals ("Node process 'argv' length'", - process.argv.length, nodeProcInfo.argv.length); - - jqUnit.assertEquals ("Node process status", - "Running", nodeProcInfo.state); - - // Loop to compare nodejs argument vector against the one found by - // by procTests.getProcesses(). Note that the linux add-on (libgtop) - // returns a path relative to the current directory for argv[1], - // whereas node reports the full path. Compare using Path.resolve(). - for (var i = 0; i < process.argv.length; i++) { - var processArg = process.argv[i]; - var nodeProcInfoArg = nodeProcInfo.argv[i]; - if (i === 1) { - processArg = path.resolve (processArg); - nodeProcInfoArg = path.resolve (nodeProcInfoArg); + function () { + var procInfos = nodeProcesses.getProcesses(); + jqUnit.assertNotEquals( + "Getting all processes", 0, procInfos.length + ); + + // Check for the presence of this nodejs processs itself -- it must + // be in the process list since this code is running inside that + // process. + var nodeProcInfo = procTests.matchProcByPid(process.pid, procInfos); + jqUnit.assertNotNull("Searching for 'node' process", nodeProcInfo); + jqUnit.assertEquals("Node process 'name'", + process.title, nodeProcInfo.command + ); + // TODO: Redundant? This is how it was found. + jqUnit.assertEquals("Node process 'pid'", + process.pid, nodeProcInfo.pid + ); + jqUnit.assertEquals("Node process 'uid'", + process.getuid(), nodeProcInfo.uid + ); + jqUnit.assertEquals("Node process 'gid'", + process.getgid(), nodeProcInfo.gid + ); + jqUnit.assertEquals("Node process 'argv' length'", + process.argv.length, nodeProcInfo.argv.length + ); + jqUnit.assertEquals("Node process status", + "Running", nodeProcInfo.state + ); + + // Loop to compare nodejs argument vector against the one found by + // by procTests.getProcesses(). Note that the linux add-on (libgtop) + // returns a path relative to the current directory for argv[1], + // whereas node reports the full path. Compare using Path.resolve(). + for (var i = 0; i < process.argv.length; i++) { + var processArg = process.argv[i]; + var nodeProcInfoArg = nodeProcInfo.argv[i]; + if (i === 1) { + processArg = path.resolve(processArg); + nodeProcInfoArg = path.resolve(nodeProcInfoArg); + } + jqUnit.assertEquals("Node process 'argv[" + i + "]'", + processArg, nodeProcInfoArg + ); } - jqUnit.assertEquals ("Node process 'argv[" + i + "]'", - processArg, nodeProcInfoArg); - } - }); - + }); }()); diff --git a/gpii/node_modules/processReporter/processesBridge.js b/gpii/node_modules/processReporter/processesBridge.js index 8b33826..880e989 100644 --- a/gpii/node_modules/processReporter/processesBridge.js +++ b/gpii/node_modules/processReporter/processesBridge.js @@ -12,305 +12,302 @@ https://github.com/gpii/universal/LICENSE.txt /*global require */ -(function() { +(function () { "use strict"; - var fluid = require ("universal"); - var gpii = fluid.registerNamespace ("gpii"); + var fluid = require("universal"); + var gpii = fluid.registerNamespace("gpii"); var nodeProcesses = - require ("./nodeprocesses/build/Release/nodeprocesses.node"); + require("./nodeprocesses/build/Release/nodeprocesses.node"); - gpii.processes = fluid.registerNamespace ("gpii.processes"); + gpii.processes = fluid.registerNamespace("gpii.processes"); - fluid.defaults ("gpii.processes", { - gradeNames: ["fluid.eventedComponent", "autoInit"], - events: { - onRunStateChange: null, - onStateChange: null - }, - invokers: { - findSolutionsByCommands: { - funcName: "gpii.processes.findSolutionsByCommands", - args: ["{arguments}.0"] // array of command names + fluid.defaults("gpii.processes", { + gradeNames: ["fluid.eventedComponent", "autoInit"], + events: { + onRunStateChange: null, + onStateChange: null }, - findSolutionsByPids: { - funcName: "gpii.processes.findSolutionsByPids", - args: ["{arguments}.0"] // array of pids (process ids) - }, - getProcesses: { - funcName: "gpii.processes.getProcessList", - args: [] - }, - findProcessByPid: { - funcName: "gpii.processes.findProcessByPid", - args: ["{arguments}.0", "{arguments}.1"] // pid, procArray (optional) - }, - findProcessesByCommand: { - funcName: "gpii.processes.findProcessesByCommand", - args: ["{arguments}.0", "{arguments}.1"] - // command, procArray (optional) - }, - findFirstProcessByCommand: { - funcName: "gpii.processes.findFirstProcessByCommand", - args: ["{arguments}.0", "{arguments}.1"] - // command, procArray (optional) - }, - hasStateChanged: { - funcName: "gpii.processes.hasStateChanged", - args: ["{arguments}.0"] // process info structure - }, - isRunning: { - funcName: "gpii.processes.isRunning", - args: ["{arguments}.0"] // state (string) - }, - hasSwitchRunState: { - funcName: "gpii.processes.hasSwitchedRunState", - args: ["{arguments}.0"] // monitor info structure - }, - updateProcInfo: { - funcName: "gpii.processes.updateProcInfo", - args: ["{arguments}.0"] // process info structure - }, - initProcInfoNotRunning: { - funcName: "gpii.processes.initProcInfoNotRunning", - args: ["{arguments}.0"] // command name (string) - }, - initMonitor: { - funcName: "gpii.processes.initMonitor", - args: ["{arguments}.0"] // process info structure - }, - monitorStateChange: { - funcName: "gpii.processes.monitorStateChange", - args: ["{that}", "{arguments}.0"] // monitor info structure - }, - monitorRunStateChanged: { - funcName: "gpii.processes.monitorRunStateChanged", - args: ["{that}", "{arguments}.0"] // monitor info structure - }, - trackRunState: { - funcName: "gpii.processes.trackRunState", - args: ["{that}", "{arguments}.0", "{arguments}.1"] - // process info, handler - }, - stopTrackingRunState: { - funcName: "gpii.processes.stopTrackingRunState", - args: ["{that}", "{arguments}.0", "{arguments}.1"] - // handler, intervalID - }, - // Tracking *any* state change. - trackState: { - funcName: "gpii.processes.trackState", - args: ["{that}", "{arguments}.0", "{arguments}.1"] - // process info, handler - }, - stopTrackingState: { - funcName: "gpii.processes.stopTrackingState", - args: ["{that}", "{arguments}.0", "{arguments}.1"] - // handler, intervalID + invokers: { + findSolutionsByCommands: { + funcName: "gpii.processes.findSolutionsByCommands", + args: ["{arguments}.0"] // array of command names + }, + findSolutionsByPids: { + funcName: "gpii.processes.findSolutionsByPids", + args: ["{arguments}.0"] // array of pids (process ids) + }, + getProcesses: { + funcName: "gpii.processes.getProcessList", + args: [] + }, + findProcessByPid: { + funcName: "gpii.processes.findProcessByPid", + args: ["{arguments}.0", "{arguments}.1"] // pid, procArray (optional) + }, + findProcessesByCommand: { + funcName: "gpii.processes.findProcessesByCommand", + args: ["{arguments}.0", "{arguments}.1"] + // command, procArray (optional) + }, + findFirstProcessByCommand: { + funcName: "gpii.processes.findFirstProcessByCommand", + args: ["{arguments}.0", "{arguments}.1"] + // command, procArray (optional) + }, + hasStateChanged: { + funcName: "gpii.processes.hasStateChanged", + args: ["{arguments}.0"] // process info structure + }, + isRunning: { + funcName: "gpii.processes.isRunning", + args: ["{arguments}.0"] // state (string) + }, + hasSwitchRunState: { + funcName: "gpii.processes.hasSwitchedRunState", + args: ["{arguments}.0"] // monitor info structure + }, + updateProcInfo: { + funcName: "gpii.processes.updateProcInfo", + args: ["{arguments}.0"] // process info structure + }, + initProcInfoNotRunning: { + funcName: "gpii.processes.initProcInfoNotRunning", + args: ["{arguments}.0"] // command name (string) + }, + initMonitor: { + funcName: "gpii.processes.initMonitor", + args: ["{arguments}.0"] // process info structure + }, + monitorStateChange: { + funcName: "gpii.processes.monitorStateChange", + args: ["{that}", "{arguments}.0"] // monitor info structure + }, + monitorRunStateChanged: { + funcName: "gpii.processes.monitorRunStateChanged", + args: ["{that}", "{arguments}.0"] // monitor info structure + }, + trackRunState: { + funcName: "gpii.processes.trackRunState", + args: ["{that}", "{arguments}.0", "{arguments}.1"] + // process info, handler + }, + stopTrackingRunState: { + funcName: "gpii.processes.stopTrackingRunState", + args: ["{that}", "{arguments}.0", "{arguments}.1"] + // handler, intervalID + }, + // Tracking *any* state change. + trackState: { + funcName: "gpii.processes.trackState", + args: ["{that}", "{arguments}.0", "{arguments}.1"] + // process info, handler + }, + stopTrackingState: { + funcName: "gpii.processes.stopTrackingState", + args: ["{that}", "{arguments}.0", "{arguments}.1"] + // handler, intervalID + } } - } }); // Return an list of process information structures corresponding to the // names of each of the passed in commands. gpii.processes.findSolutionsByCommands = function (commandNames) { - if (!!commandNames) { - return fluid.accumulate (commandNames, function (aCommand, matches) { - var procInfos = - gpii.processes.findProcessesByCommand (aCommand); - matches = matches.concat (procInfos); - return matches; - }, []); - } - else { - return []; - } + if (!!commandNames) { + return fluid.accumulate(commandNames, function (aCommand, matches) { + var procInfos = gpii.processes.findProcessesByCommand(aCommand); + matches = matches.concat(procInfos); + return matches; + }, []); + } + else { + return []; + } }; // Return an list of process information structures corresponding to the // pids pass in. gpii.processes.findSolutionsByPids = function (pids) { - if (!!pids) { - return fluid.accumulate (pids, function (aPid, matches) { - var found = gpii.processes.findProcessByPid (aPid); - if (found !== null) { - matches.push (found); - } - return matches; - }, []); - } - else { - return []; - } + if (!!pids) { + return fluid.accumulate(pids, function (aPid, matches) { + var found = gpii.processes.findProcessByPid(aPid); + if (found !== null) { + matches.push(found); + } + return matches; + }, []); + } + else { + return []; + } }; // Return a list of processes -- a snapshot of the current processes. - gpii.processes.getProcessList = function() { - return nodeProcesses.getProcesses(); + gpii.processes.getProcessList = function () { + return nodeProcesses.getProcesses(); }; // Return THE process info object that matches the given process id. // Note that it can return "null" meaning there is no such process. gpii.processes.findProcessByPid = function (pid, procArray) { - if (!procArray) { - procArray = gpii.processes.getProcessList(); - } - return fluid.find (procArray, function (procInfo) { - if (procInfo.pid === pid) { - return procInfo; - } - }, null); + if (!procArray) { + procArray = gpii.processes.getProcessList(); + } + return fluid.find(procArray, function (procInfo) { + if (procInfo.pid === pid) { + return procInfo; + } + }, null); }; // Return an array of process information objects that match the given // command name string. Note that it can return an empty array, meaning // there is no such process. gpii.processes.findProcessesByCommand = function (commandName, procArray) { - if (!procArray) { - procArray = gpii.processes.getProcessList(); - } - return fluid.accumulate (procArray, function (aProcInfo, matchingProcs) { - if (aProcInfo.command === commandName) { - matchingProcs.push (aProcInfo); - } - return matchingProcs; - }, []); + if (!procArray) { + procArray = gpii.processes.getProcessList(); + } + return fluid.accumulate(procArray, function (aProcInfo, matchingProcs) { + if (aProcInfo.command === commandName) { + matchingProcs.push(aProcInfo); + } + return matchingProcs; + }, []); }; // Return the first process of an array of processes all with the same // command name string. If there are no matching processes, return null. gpii.processes.findFirstProcessByCommand = function (commandName, procArray) { - var commands = - gpii.processes.findProcessesByCommand (commandName, procArray); - if (commands.length > 0) { - return commands[0]; - } - else { - return null; - } + var commands = + gpii.processes.findProcessesByCommand(commandName, procArray); + if (commands.length > 0) { + return commands[0]; + } + else { + return null; + } }; // Determine if the state of the given process has changed. Record the // new process information in the monitor. Return boolean. gpii.processes.hasStateChanged = function (monitor) { - if (!monitor || !monitor.procInfo) { - return false; // nothing sought === nothing changed. - } - monitor.newProcInfo = - gpii.processes.updateProcInfo (monitor.procInfo); - return (monitor.procInfo.state !== monitor.newProcInfo.state); + if (!monitor || !monitor.procInfo) { + return false; // nothing sought === nothing changed. + } + monitor.newProcInfo = + gpii.processes.updateProcInfo(monitor.procInfo); + return (monitor.procInfo.state !== monitor.newProcInfo.state); }; // Utility function to conflate process state values into "Running" // (= true) vs. "Not Running" (= false). Returns boolean. gpii.processes.isRunning = function (state) { - var result; - switch (state) { - case "Running": - case "Uninterruptible": - case "Sleeping": - case "Stopped": - result = true; - break; + var result; + switch (state) { + case "Running": + case "Uninterruptible": + case "Sleeping": + case "Stopped": + result = true; + break; - default: - case "Zombie": - case "NoSuchProcess": - result = false; - break; - } - return result; + default: + case "Zombie": + case "NoSuchProcess": + result = false; + break; + } + return result; }; // Determine if the state of the given process has changed from // "not running" to "running" OR from "running" to "not running". // Return boolean. gpii.processes.hasSwitchedRunState = function (monitor) { - if (!monitor || !monitor.procInfo) { - // nothing sought === nothing changed. - return false; - } - monitor.newProcInfo = - gpii.processes.updateProcInfo (monitor.procInfo); - var wasRunning = gpii.processes.isRunning (monitor.procInfo.state); - var isRunning = - gpii.processes.isRunning (monitor.newProcInfo.state); - return (isRunning !== wasRunning); + if (!monitor || !monitor.procInfo) { + // nothing sought === nothing changed. + return false; + } + monitor.newProcInfo = + gpii.processes.updateProcInfo(monitor.procInfo); + var wasRunning = gpii.processes.isRunning(monitor.procInfo.state); + var isRunning = + gpii.processes.isRunning(monitor.newProcInfo.state); + return (isRunning !== wasRunning); }; // Renew the information on a process, or create a new "NoSuchProcces". // Returns a new procInfo structure. gpii.processes.updateProcInfo = function (procInfo) { - var newProcInfo = null; - if (procInfo.state === "NoSuchProcess") { - newProcInfo = - gpii.processes.findFirstProcessByCommand (procInfo.command); - } - else { - newProcInfo = gpii.processes.findProcessByPid (procInfo.pid); - } - if (newProcInfo === null) { - newProcInfo = - gpii.processes.initProcInfoNotRunning (procInfo.command); - } - return newProcInfo; + var newProcInfo = null; + if (procInfo.state === "NoSuchProcess") { + newProcInfo = + gpii.processes.findFirstProcessByCommand(procInfo.command); + } + else { + newProcInfo = gpii.processes.findProcessByPid(procInfo.pid); + } + if (newProcInfo === null) { + newProcInfo = + gpii.processes.initProcInfoNotRunning(procInfo.command); + } + return newProcInfo; }; // Create information on a non-running process, to use to detect when the // process starts. gpii.processes.initProcInfoNotRunning = function (command) { - var process = {}; - process.command = command; - process.pid = -1; - process.ppid = -1; - process.uid = -1; - process.gid = -1; - process.fullPath = ""; - process.argv = ""; - process.state = "NoSuchProcess"; - return process; + var process = {}; + process.command = command; + process.pid = -1; + process.ppid = -1; + process.uid = -1; + process.gid = -1; + process.fullPath = ""; + process.argv = ""; + process.state = "NoSuchProcess"; + return process; }; // Create a monitor object for passing to a function that periodically // checks for chanages in the state of a process. gpii.processes.initMonitor = function (procInfo) { - var monitor = {}; - monitor.intervalID = -1; - monitor.procInfo = procInfo; - monitor.newProcInfo = null; - return monitor; + var monitor = {}; + monitor.intervalID = -1; + monitor.procInfo = procInfo; + monitor.newProcInfo = null; + return monitor; }; // Callback to pass to, e.g., setInterval() to periodically check the state // of a process. gpii.processes.monitorStateChange = function (that, monitor) { - if (gpii.processes.hasStateChanged (monitor)) { - var oldProcInfo = monitor.procInfo; - if (monitor.newProcInfo === null) { - monitor.procInfo = - gpii.processes.initProcInfoNotRunning (monitor.procInfo.command); - } - else { - monitor.procInfo = monitor.newProcInfo; + if (gpii.processes.hasStateChanged(monitor)) { + var oldProcInfo = monitor.procInfo; + if (monitor.newProcInfo === null) { + monitor.procInfo = gpii.processes.initProcInfoNotRunning(monitor.procInfo.command); + } + else { + monitor.procInfo = monitor.newProcInfo; + } + that.events.onStateChange.fire(oldProcInfo, monitor.newProcInfo); } - that.events.onStateChange.fire (oldProcInfo, monitor.newProcInfo); - } }; // Callback to pass to setInterval() to periodically check when the state // changes from "running" to "not running" and vice versa. gpii.processes.monitorRunStateChanged = function (that, monitor) { - if (gpii.processes.hasSwitchedRunState (monitor)) { - if (monitor.newProcInfo === null) { - monitor.procInfo = - gpii.processes.initProcInfoNotRunning (monitor.procInfo.command); - } - else { - monitor.procInfo = monitor.newProcInfo; + if (gpii.processes.hasSwitchedRunState(monitor)) { + if (monitor.newProcInfo === null) { + monitor.procInfo = gpii.processes.initProcInfoNotRunning(monitor.procInfo.command); + } + else { + monitor.procInfo = monitor.newProcInfo; + } + that.events.onRunStateChange.fire(monitor.procInfo); } - that.events.onRunStateChange.fire (monitor.procInfo); - } }; // ============== @@ -320,33 +317,33 @@ https://github.com/gpii/universal/LICENSE.txt // Provide a way for the outside world to pass in a handler for the // "onRunStateChange" event, and to cancel. gpii.processes.trackRunState = function (that, procInfo, handler) { - var monitor = gpii.processes.initMonitor (procInfo); - that.events.onRunStateChange.addListener (handler); - monitor.intervalID = setInterval (function() { - gpii.processes.monitorRunStateChanged (that, monitor); - }); - return monitor.intervalID; + var monitor = gpii.processes.initMonitor(procInfo); + that.events.onRunStateChange.addListener(handler); + monitor.intervalID = setInterval(function () { + gpii.processes.monitorRunStateChanged(that, monitor); + }); + return monitor.intervalID; }; gpii.processes.stopTrackingRunState = function (that, handler, intervalID) { - that.events.onRunStateChange.removeListener (handler); - clearInterval (intervalID); + that.events.onRunStateChange.removeListener(handler); + clearInterval(intervalID); }; // Provide a way for the outside world to pass in a handler for the // "onStateChange" event, and to cancel. gpii.processes.trackState = function (that, procInfo, handler) { - var monitor = gpii.processes.initMonitor (procInfo); - that.events.onStateChange.addListener (handler); - monitor.intervalID = setInterval (function() { - gpii.processes.monitorStateChange (that, monitor); - }); - return monitor.intervalID; + var monitor = gpii.processes.initMonitor(procInfo); + that.events.onStateChange.addListener(handler); + monitor.intervalID = setInterval(function () { + gpii.processes.monitorStateChange(that, monitor); + }); + return monitor.intervalID; }; gpii.processes.stopTrackingState = function (that, handler, intervalID) { - that.events.onStateChange.removeListener (handler); - clearInterval (intervalID); + that.events.onStateChange.removeListener(handler); + clearInterval(intervalID); }; }()); diff --git a/gpii/node_modules/processReporter/processesBridgeDemo.js b/gpii/node_modules/processReporter/processesBridgeDemo.js index a78cc56..3c41b08 100644 --- a/gpii/node_modules/processReporter/processesBridgeDemo.js +++ b/gpii/node_modules/processReporter/processesBridgeDemo.js @@ -13,45 +13,45 @@ https://github.com/gpii/universal/LICENSE.txt /*global require */ "use strict"; -var readline = require ("readline"); +var readline = require("readline"); var fluid = require("universal"); -require ("./processesBridge.js"); +require("./processesBridge.js"); -var gpii = fluid.registerNamespace ("gpii"); -gpii.processesBridge = fluid.registerNamespace ("gpii.processes"); +var gpii = fluid.registerNamespace("gpii"); +gpii.processesBridge = fluid.registerNamespace("gpii.processes"); var processesBridge = gpii.processesBridge(); -var seekInput = readline.createInterface ({ - input: process.stdin, - output: process.stdout +var seekInput = readline.createInterface({ + input: process.stdin, + output: process.stdout }); // Handler for processes to use to detect change from "not running" to "running" // or "running" to "not running". For this demo, just print the new run state // on the console. var runStateChangeHandler = function (procInfo) { - console.log ( - procInfo.command + ": run state switched to " + procInfo.state + - " (" + - ( processesBridge.isRunning (procInfo.state) ? "Running" : "Stopped" ) + - ")" - ); + console.log( + procInfo.command + ": run state switched to " + procInfo.state + + "(" + + (processesBridge.isRunning(procInfo.state) ? "Running" : "Stopped") + + ")" + ); }; // Handler to use to detect any change in state, and print to console. var stateChangeHandler = function (oldProcInfo, newProcInfo) { - console.log ( - oldProcInfo.command + " process state switched from " + - oldProcInfo.state + " to " + newProcInfo.state - ); + console.log( + oldProcInfo.command + " process state switched from " + + oldProcInfo.state + " to " + newProcInfo.state + ); }; // Initial assumption: not running. Then look for any running orca process. -var orcaProcInfo = processesBridge.initProcInfoNotRunning ("orca"); -var orcaProcInfos = processesBridge.findProcessesByCommand ("orca"); +var orcaProcInfo = processesBridge.initProcInfoNotRunning("orca"); +var orcaProcInfos = processesBridge.findProcessesByCommand("orca"); if (orcaProcInfos.length > 0) { - orcaProcInfo = orcaProcInfos[0]; + orcaProcInfo = orcaProcInfos[0]; } // Start the periodic check of the change in run-state for orca. @@ -60,33 +60,35 @@ if (orcaProcInfos.length > 0) { // gsettings set org.gnome.desktop.a11y.applications screen-reader-enabled true/false var states = {}; states.trackRunState = - processesBridge.trackRunState (orcaProcInfo, runStateChangeHandler); + processesBridge.trackRunState(orcaProcInfo, runStateChangeHandler); states.trackState = - processesBridge.trackState (orcaProcInfo, stateChangeHandler); + processesBridge.trackState(orcaProcInfo, stateChangeHandler); -console.log ("Waiting..."); +console.log("Waiting..."); -seekInput.setPrompt ("Stop? "); +seekInput.setPrompt("Stop? "); seekInput.prompt(); -seekInput.on ("line", function (answer) { - console.log ("You said " + answer); - switch (answer.trim()) { - case "yes": - console.log ("Okay, stopping"); - - // Cease periodic check of orca's state. - processesBridge.stopTrackingRunState ( - runStateChangeHandler, states.trackRunState - ); - processesBridge.stopTrackingState (stateChangeHandler, states.trackState); - seekInput.close(); - break; - - default: - console.log ("Okay, continuing"); - break; - } - seekInput.prompt(); -}).on ("close", function() { - process.exit(0); +seekInput.on("line", function (answer) { + console.log("You said " + answer); + switch (answer.trim()) { + case "yes": + console.log("Okay, stopping"); + + // Cease periodic check of orca's state. + processesBridge.stopTrackingRunState( + runStateChangeHandler, states.trackRunState + ); + processesBridge.stopTrackingState( + stateChangeHandler, states.trackState + ); + seekInput.close(); + break; + + default: + console.log("Okay, continuing"); + break; + } + seekInput.prompt(); +}).on("close", function () { + process.exit(0); }); diff --git a/gpii/node_modules/processReporter/processesBridge_tests.js b/gpii/node_modules/processReporter/processesBridge_tests.js index 7bd8011..17e5cf7 100644 --- a/gpii/node_modules/processReporter/processesBridge_tests.js +++ b/gpii/node_modules/processReporter/processesBridge_tests.js @@ -12,293 +12,312 @@ https://github.com/gpii/universal/LICENSE.txt /*global require*/ -(function() { +(function () { "use strict"; - var path = require ("path"), - spawn = require("child_process").spawn, - fluid = require ("universal"), - jqUnit = fluid.require ("jqUnit"), + var path = require("path"), + spawn = require("child_process").spawn, + fluid = require("universal"), + jqUnit = fluid.require("jqUnit"), // TODO: Must be a better way to get node gsettings add-on. - nodeGSettings = require ("../gsettingsBridge/nodegsettings/build/Release/nodegsettings.node"); - require ("./processesBridge.js"); + nodeGSettings = require("../gsettingsBridge/nodegsettings/build/Release/nodegsettings.node"); + require("./processesBridge.js"); - var processesBridge = fluid.registerNamespace ("gpii.processes"); - var procTests = fluid.registerNamespace ("gpii.tests.processes"); + var processesBridge = fluid.registerNamespace("gpii.processes"); + var procTests = fluid.registerNamespace("gpii.tests.processes"); // Delay 5 seconds. - procTests.wait5sec = function() { - var t0 = Date.now(); - var longEnough = false; - while (!longEnough) { - longEnough = ((Date.now() - t0) > 5000); - } + procTests.wait5sec = function () { + var t0 = Date.now(); + var longEnough = false; + while (!longEnough) { + longEnough = ((Date.now() - t0) > 5000); + } }; - jqUnit.module ("Processes Bridge node add-on module"); - jqUnit.test ( - "Test getProceses()/findProcessByPid() with the nodejs process itself", - function() { - var procInfos = processesBridge.getProcessList(); - jqUnit.assertNotEquals ( - "Listing all processes", 0, procInfos.length - ); - - // Check for the presence of this nodejs processs itself -- it must - // be in the process list since this code is running inside that - // process. - var nodeProc = processesBridge.findProcessByPid (process.pid, procInfos); - jqUnit.assertNotNull ("Searching for 'node' process", nodeProc); - }); - - jqUnit.test ( - "Test findProcessByPid() with non-running process id", - function() { - jqUnit.assertNull ( - "Search negative process id value", processesBridge.findProcessByPid (-1) - ); - }); - - jqUnit.test ( + jqUnit.module("Processes Bridge node add-on module"); + jqUnit.test( + "Test getProceses()/findProcessByPid() with the nodejs process itself", + function () { + var procInfos = processesBridge.getProcessList(); + jqUnit.assertNotEquals( + "Listing all processes", 0, procInfos.length + ); + + // Check for the presence of this nodejs processs itself -- it must + // be in the process list since this code is running inside that + // process. + var nodeProc = processesBridge.findProcessByPid(process.pid, procInfos); + jqUnit.assertNotNull("Searching for 'node' process", nodeProc); + } + ); + + jqUnit.test( + "Test findProcessByPid() with non-running process id", + function () { + jqUnit.assertNull( + "Search negative process id value", processesBridge.findProcessByPid(-1) + ); + } + ); + + jqUnit.test( "Test findProcessByPid() against nodejs's own process object.", - function() { - var nodeProcInfo = processesBridge.findProcessByPid (process.pid); - jqUnit.assertEquals ("Node process 'name'", - process.title, nodeProcInfo.command); - - // Redundant? This is how it was found. - jqUnit.assertEquals ("Node process 'pid'", - process.pid, nodeProcInfo.pid); - - jqUnit.assertEquals ("Node process 'uid'", - process.getuid(), nodeProcInfo.uid); - - jqUnit.assertEquals ("Node process 'gid'", - process.getgid(), nodeProcInfo.gid); - - jqUnit.assertEquals ("Node process 'argv' length'", - process.argv.length, nodeProcInfo.argv.length); - - jqUnit.assertEquals ("Node process status", - "Running", nodeProcInfo.state); - - // Loop to compare nodejs argument vector against the one found by - // by procTests.getProcesses(). Note that the linux's libgtop - // returns a path relative to the current directory for argv[1], - // whereas node reports the full path. Compare using Path.resolve(). - for (var i = 0; i < process.argv.length; i++) { - var processArg = process.argv[i]; - var nodeProcInfoArg = nodeProcInfo.argv[i]; - if (i === 1) { - processArg = path.resolve (processArg); - nodeProcInfoArg = path.resolve (nodeProcInfoArg); + function () { + var nodeProcInfo = processesBridge.findProcessByPid(process.pid); + jqUnit.assertEquals("Node process 'name'", + process.title, nodeProcInfo.command); + + // Redundant? This is how it was found. + jqUnit.assertEquals("Node process 'pid'", + process.pid, nodeProcInfo.pid); + + jqUnit.assertEquals("Node process 'uid'", + process.getuid(), nodeProcInfo.uid); + + jqUnit.assertEquals("Node process 'gid'", + process.getgid(), nodeProcInfo.gid); + + jqUnit.assertEquals("Node process 'argv' length'", + process.argv.length, nodeProcInfo.argv.length); + + jqUnit.assertEquals("Node process status", + "Running", nodeProcInfo.state); + + // Loop to compare nodejs argument vector against the one found by + // by procTests.getProcesses(). Note that the linux's libgtop + // returns a path relative to the current directory for argv[1], + // whereas node reports the full path. Compare using Path.resolve(). + for (var i = 0; i < process.argv.length; i++) { + var processArg = process.argv[i]; + var nodeProcInfoArg = nodeProcInfo.argv[i]; + if (i === 1) { + processArg = path.resolve(processArg); + nodeProcInfoArg = path.resolve(nodeProcInfoArg); + } + jqUnit.assertEquals("Node process 'argv[" + i + "]'", + processArg, nodeProcInfoArg); } - jqUnit.assertEquals ("Node process 'argv[" + i + "]'", - processArg, nodeProcInfoArg); - } - }); - - jqUnit.test ( - "Test findProcessesByCmd()/findFirstProcessByCmd() with nodejs itself", - function() { - var nodeProcInfos = processesBridge.findProcessesByCommand ("node"); - jqUnit.assertNotEquals ( - "Getting all 'node' processes", 0, nodeProcInfos.length - ); - nodeProcInfos.forEach (function (aProcInfo) { - jqUnit.assertEquals ( - "Node commmand name", "node", aProcInfo.command - ); - }); - var procInfo = processesBridge.findFirstProcessByCommand ("node"); - jqUnit.assertNotNull ("Looking for first 'node' processes", procInfo); - jqUnit.assertEquals ("Node commmand name", "node", procInfo.command); - }); - - jqUnit.test ( - "Test initProcInfoNotRunning()", - function() { - var notRunning = processesBridge.initProcInfoNotRunning ("grep"); - jqUnit.assertEquals ("Command name", notRunning.command, "grep"); - jqUnit.assertEquals ("Negative process id", notRunning.pid, -1); - jqUnit.assertEquals ( - "'NoSuchProcess' state", notRunning.state, "NoSuchProcess" - ); - jqUnit.assertNull ( - "Search negative process id value", - processesBridge.findProcessByPid (notRunning.pid) - ); - }); - - jqUnit.test ( - "Test isRunning() with nodejs itself, and nonexistent process", - function() { - var procInfo = processesBridge.findProcessByPid (process.pid); - jqUnit.assertNotNull ("Searching for 'node' process", procInfo); - jqUnit.assertTrue ( - "Check nodejs is running", processesBridge.isRunning (procInfo.state) - ); - procInfo = processesBridge.initProcInfoNotRunning ("grep"); - jqUnit.assertFalse ( - "Check nonexistent process running", processesBridge.isRunning (procInfo) - ); - }); - - jqUnit.test ( - "Test updateProcInfo() against non-changing process", - function() { - var procInfo = processesBridge.findProcessByPid (process.pid); - jqUnit.assertNotNull ("Looking for 'node' processes", procInfo); - var newProcInfo = processesBridge.updateProcInfo (procInfo); - jqUnit.assertDeepEq ( - "Check change in process info", procInfo, newProcInfo - ); - }); - - jqUnit.test ( - "Test updateProcInfo() against changing process", - function() { - var grep = spawn ("grep", ["ssh"]); - var grepInfo = processesBridge.findProcessByPid (grep.pid); - jqUnit.assertNotNull ("Search 'grep' process", grepInfo); - jqUnit.assertTrue ("Stop grep", grep.kill ("SIGHUP")); - var newGrepInfo = processesBridge.updateProcInfo (grepInfo); - jqUnit.assertNotEquals ( - "Update process state", newGrepInfo.state, grepInfo.state - ); - }); - - jqUnit.test ( - "Test hasStateChanged()", - function() { - jqUnit.assertFalse ( - "Check null monitor", processesBridge.hasStateChanged (null) - ); - var catMonitor = processesBridge.initMonitor (null); - jqUnit.assertFalse ( - "Check null process", processesBridge.hasStateChanged (catMonitor) - ); - var catProcInfo = processesBridge.initProcInfoNotRunning ("cat"); - catMonitor = processesBridge.initMonitor (catProcInfo); - var stateChanged = processesBridge.hasStateChanged (catMonitor); - jqUnit.assertFalse ("Check non-running process", stateChanged); - - var cat = spawn ("cat"); - catMonitor = processesBridge.initMonitor (catProcInfo); - stateChanged = processesBridge.hasStateChanged (catMonitor); - jqUnit.assertTrue ("Check running process", stateChanged); - - // Get the running process info, kill cat, and check again. - catProcInfo = processesBridge.findProcessByPid (cat.pid); - catMonitor = processesBridge.initMonitor (catProcInfo); - cat.kill ("SIGHUP"); - stateChanged = processesBridge.hasStateChanged (catMonitor); - jqUnit.assertTrue ("Check stopped process", stateChanged); - }); - - jqUnit.test ( - "Test hasSwitchedRunState()", - function() { - jqUnit.assertFalse ( - "Check null monitor", processesBridge.hasSwitchedRunState (null) - ); - var grepProcMonitor = processesBridge.initMonitor (null); - jqUnit.assertFalse ( - "Check null process", processesBridge.hasSwitchedRunState (grepProcMonitor) - ); - var grep = spawn ("grep", ["ssh"]); - var grepProcInfo = processesBridge.findProcessByPid (grep.pid); - grepProcMonitor = processesBridge.initMonitor (grepProcInfo); - var switched = processesBridge.hasSwitchedRunState (grepProcMonitor); - jqUnit.assertFalse ("Check running process", switched); - jqUnit.assertEquals ( - "Process state change", - grepProcInfo.state, grepProcMonitor.newProcInfo.state - ); - // Kill grep, and check again. - grep.kill ("SIGHUP"); - switched = processesBridge.hasSwitchedRunState (grepProcMonitor); - jqUnit.assertTrue ("Check stopped process", switched); - jqUnit.assertNotEquals ( - "Process state change", - grepProcInfo.state, grepProcMonitor.newProcInfo.state - ); - }); - - jqUnit.test ( - "Test findSolutionsByCommands()", - function() { - // Node is running. Add a running cat process. No such command as why. - var cat = spawn ("cat"); - var solutions = ["node", "cat", "why"]; - var procInfos = processesBridge.findSolutionsByCommands (solutions); - jqUnit.assertTrue ("Node and cat processes", procInfos.length >= 2); - procInfos.forEach (function (item) { - var isNode = item.command === "node"; - var isCat = item.command === "cat"; - jqUnit.assertTrue ("Process name node nor cat", isNode || isCat); - }); - cat.kill ("SIGHUP"); - }); - - jqUnit.test ( - "Test findSolutionsByPids()", - function() { - // Node is running. Add a running cat process. - var cat = spawn ("cat"); - var pids = [process.pid, cat.pid]; - var procInfos = processesBridge.findSolutionsByPids (pids); - jqUnit.assertEquals ("Node and cat processes", 2, procInfos.length); - procInfos.forEach (function (item) { - var isNode = item.pid === process.pid; - var isCat = item.pid === cat.pid; - jqUnit.assertTrue ("Process pid node nor cat", isNode || isCat); - }); - cat.kill ("SIGHUP"); - }); + } + ); + + jqUnit.test( + "Test findProcessesByCmd()/findFirstProcessByCmd() with nodejs itself", + function () { + var nodeProcInfos = processesBridge.findProcessesByCommand("node"); + jqUnit.assertNotEquals( + "Getting all 'node' processes", 0, nodeProcInfos.length + ); + nodeProcInfos.forEach(function (aProcInfo) { + jqUnit.assertEquals( + "Node commmand name", "node", aProcInfo.command + ); + }); + var procInfo = processesBridge.findFirstProcessByCommand("node"); + jqUnit.assertNotNull( + "Looking for first 'node' processes", procInfo); + jqUnit.assertEquals("Node commmand name", "node", procInfo.command); + } + ); + + jqUnit.test( + "Test initProcInfoNotRunning()", + function () { + var notRunning = processesBridge.initProcInfoNotRunning("grep"); + jqUnit.assertEquals("Command name", notRunning.command, "grep"); + jqUnit.assertEquals("Negative process id", notRunning.pid, -1); + jqUnit.assertEquals( + "'NoSuchProcess' state", notRunning.state, "NoSuchProcess" + ); + jqUnit.assertNull( + "Search negative process id value", + processesBridge.findProcessByPid(notRunning.pid) + ); + } + ); + + jqUnit.test( + "Test isRunning() with nodejs itself, and nonexistent process", + function () { + var procInfo = processesBridge.findProcessByPid(process.pid); + jqUnit.assertNotNull("Searching for 'node' process", procInfo); + jqUnit.assertTrue( + "Check nodejs is running", + processesBridge.isRunning(procInfo.state) + ); + procInfo = processesBridge.initProcInfoNotRunning("grep"); + jqUnit.assertFalse( + "Check nonexistent process running", + processesBridge.isRunning(procInfo) + ); + } + ); + + jqUnit.test( + "Test updateProcInfo() against non-changing process", + function () { + var procInfo = processesBridge.findProcessByPid(process.pid); + jqUnit.assertNotNull("Looking for 'node' processes", procInfo); + var newProcInfo = processesBridge.updateProcInfo(procInfo); + jqUnit.assertDeepEq( + "Check change in process info", procInfo, newProcInfo + ); + } + ); + + jqUnit.test( + "Test updateProcInfo() against changing process", + function () { + var grep = spawn("grep", ["ssh"]); + var grepInfo = processesBridge.findProcessByPid(grep.pid); + jqUnit.assertNotNull("Search 'grep' process", grepInfo); + jqUnit.assertTrue("Stop grep", grep.kill("SIGHUP")); + var newGrepInfo = processesBridge.updateProcInfo(grepInfo); + jqUnit.assertNotEquals( + "Update process state", newGrepInfo.state, grepInfo.state + ); + } + ); + + jqUnit.test( + "Test hasStateChanged()", + function () { + jqUnit.assertFalse( + "Check null monitor", processesBridge.hasStateChanged(null) + ); + var catMonitor = processesBridge.initMonitor(null); + jqUnit.assertFalse( + "Check null process", + processesBridge.hasStateChanged(catMonitor) + ); + var catProcInfo = processesBridge.initProcInfoNotRunning("cat"); + catMonitor = processesBridge.initMonitor(catProcInfo); + var stateChanged = processesBridge.hasStateChanged(catMonitor); + jqUnit.assertFalse("Check non-running process", stateChanged); + + var cat = spawn("cat"); + catMonitor = processesBridge.initMonitor(catProcInfo); + stateChanged = processesBridge.hasStateChanged(catMonitor); + jqUnit.assertTrue("Check running process", stateChanged); + + // Get the running process info, kill cat, and check again. + catProcInfo = processesBridge.findProcessByPid(cat.pid); + catMonitor = processesBridge.initMonitor(catProcInfo); + cat.kill("SIGHUP"); + stateChanged = processesBridge.hasStateChanged(catMonitor); + jqUnit.assertTrue("Check stopped process", stateChanged); + } + ); + + jqUnit.test( + "Test hasSwitchedRunState()", + function () { + jqUnit.assertFalse( + "Check null monitor", processesBridge.hasSwitchedRunState(null) + ); + var grepProcMonitor = processesBridge.initMonitor(null); + jqUnit.assertFalse( + "Check null process", + processesBridge.hasSwitchedRunState(grepProcMonitor) + ); + var grep = spawn("grep", ["ssh"]); + var grepProcInfo = processesBridge.findProcessByPid(grep.pid); + grepProcMonitor = processesBridge.initMonitor(grepProcInfo); + var switched = processesBridge.hasSwitchedRunState(grepProcMonitor); + jqUnit.assertFalse("Check running process", switched); + jqUnit.assertEquals( + "Process state change", + grepProcInfo.state, grepProcMonitor.newProcInfo.state + ); + // Kill grep, and check again. + grep.kill("SIGHUP"); + switched = processesBridge.hasSwitchedRunState(grepProcMonitor); + jqUnit.assertTrue("Check stopped process", switched); + jqUnit.assertNotEquals( + "Process state change", + grepProcInfo.state, grepProcMonitor.newProcInfo.state + ); + } + ); + + jqUnit.test( + "Test findSolutionsByCommands()", + function () { + // Node is running. Add a running cat process. No such command as why. + var cat = spawn("cat"); + var solutions = ["node", "cat", "why"]; + var procInfos = processesBridge.findSolutionsByCommands(solutions); + jqUnit.assertTrue("Node and cat processes", procInfos.length >= 2); + procInfos.forEach(function (item) { + var isNode = item.command === "node"; + var isCat = item.command === "cat"; + jqUnit.assertTrue("Process name node nor cat", isNode || isCat); + }); + cat.kill("SIGHUP"); + } + ); + + jqUnit.test( + "Test findSolutionsByPids()", + function () { + // Node is running. Add a running cat process. + var cat = spawn("cat"); + var pids = [process.pid, cat.pid]; + var procInfos = processesBridge.findSolutionsByPids(pids); + jqUnit.assertEquals("Node and cat processes", 2, procInfos.length); + procInfos.forEach(function (item) { + var isNode = item.pid === process.pid; + var isCat = item.pid === cat.pid; + jqUnit.assertTrue("Process pid node nor cat", isNode || isCat); + }); + cat.kill("SIGHUP"); + } + ); // Test real life scenario: Use the GPII's gsettings bridge to launch // and shut down orca, and track the changes in state. - jqUnit.test ( - "Test gpii.processes against launching orca.", - function() { - var orcaProcInfo = processesBridge.findFirstProcessByCommand ("orca"); - var wasRunning = (orcaProcInfo !== null); - // Start orca -- does nothing if orca is already running. - nodeGSettings.set_gsetting ( - "org.gnome.desktop.a11y.applications","screen-reader-enabled", true - ); - // Give orca some time to start and initialize itself. Then look - // for the 'orca' process. - procTests.wait5sec(); - orcaProcInfo = processesBridge.findFirstProcessByCommand ("orca"); - jqUnit.assertNotNull ("Start Orca", orcaProcInfo); - - // Quit orca, giving it some time to quit itself. Then look for the - // process whose id matches the formerly running 'orca' process. - nodeGSettings.set_gsetting ( - "org.gnome.desktop.a11y.applications", "screen-reader-enabled", false - ); - procTests.wait5sec(); - if (orcaProcInfo !== null) { - var orcaProcNewState = processesBridge.findProcessByPid (orcaProcInfo.pid); - jqUnit.assertNull ("Stop Orca", orcaProcNewState); - var orcaMonitor = processesBridge.initMonitor (orcaProcInfo); - processesBridge.hasStateChanged (orcaMonitor); - jqUnit.assertEquals ( - "Orca process changed state", "NoSuchProcess", - orcaMonitor.newProcInfo.state - ); - } - // Clean up. - if (wasRunning) { - nodeGSettings.set_gsetting ( - "org.gnome.desktop.a11y.applications", - "screen-reader-enabled", true - ); + jqUnit.test( + "Test gpii.processes against launching orca.", + function () { + var orcaProcInfo = processesBridge.findFirstProcessByCommand("orca"); + var wasRunning = (orcaProcInfo !== null); + // Start orca -- does nothing if orca is already running. + nodeGSettings.set_gsetting( + "org.gnome.desktop.a11y.applications", + "screen-reader-enabled", true + ); + // Give orca some time to start and initialize itself. Then look + // for the 'orca' process. + procTests.wait5sec(); + orcaProcInfo = processesBridge.findFirstProcessByCommand("orca"); + jqUnit.assertNotNull("Start Orca", orcaProcInfo); + + // Quit orca, giving it some time to quit itself. Then look for the + // process whose id matches the formerly running 'orca' process. + nodeGSettings.set_gsetting( + "org.gnome.desktop.a11y.applications", "screen-reader-enabled", false + ); + procTests.wait5sec(); + if (orcaProcInfo !== null) { + var orcaProcNewState = + processesBridge.findProcessByPid(orcaProcInfo.pid); + jqUnit.assertNull("Stop Orca", orcaProcNewState); + var orcaMonitor = processesBridge.initMonitor(orcaProcInfo); + processesBridge.hasStateChanged(orcaMonitor); + jqUnit.assertEquals( + "Orca process changed state", "NoSuchProcess", + orcaMonitor.newProcInfo.state + ); + } + // Clean up. + if (wasRunning) { + nodeGSettings.set_gsetting( + "org.gnome.desktop.a11y.applications", + "screen-reader-enabled", true + ); + } } - }); - + ); }()); From e6c67d461ba26886be8b0b55f482d85ff5df9ad6 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Tue, 28 Apr 2015 14:17:46 -0400 Subject: [PATCH 35/78] GPII-442: First pass at a process reporter service. --- gpii/node_modules/processReporter/index.js | 18 +++++++++ .../processReporter/processReporter.js | 37 +++++++++++++++++++ index.js | 1 + 3 files changed, 56 insertions(+) create mode 100644 gpii/node_modules/processReporter/index.js create mode 100644 gpii/node_modules/processReporter/processReporter.js diff --git a/gpii/node_modules/processReporter/index.js b/gpii/node_modules/processReporter/index.js new file mode 100644 index 0000000..f289832 --- /dev/null +++ b/gpii/node_modules/processReporter/index.js @@ -0,0 +1,18 @@ +/** + * GPII gliptop Process Reporter + * + * Copyright 2015 Inclusive Design Research Centre, OCAD University + * + * Licensed under the New BSD license. You may not use this file except in + * compliance with this License. + * + * You may obtain a copy of the License at + * https://github.com/gpii/universal/LICENSE.txt + */ + +var fluid = require("universal"); + +var loader = fluid.getLoader(__dirname); + +loader.require("./processReporter.js"); + diff --git a/gpii/node_modules/processReporter/processReporter.js b/gpii/node_modules/processReporter/processReporter.js new file mode 100644 index 0000000..e86b497 --- /dev/null +++ b/gpii/node_modules/processReporter/processReporter.js @@ -0,0 +1,37 @@ +/** + * GPII Process Reporter Bridge (Linux -- GLiBTop). + * + * Copyright 2015 OCAD University + * + * Licensed under the New BSD license. You may not use this file except in + * compliance with this License. + * + * You may obtain a copy of the License at + * https://github.com/gpii/universal/LICENSE.txt + */ + +(function () { + "use strict"; + + var fluid = require("universal"); + var gpii = fluid.registerNamespace("gpii"); + require("./processesBridge.js"); + + var processes = gpii.processes(); + + fluid.registerNamespace("gpii.processReporter"); + fluid.defaults("gpii.processReporter.find", { + gradeNames: "fluid.function", + argumentMap: { + command: 0 + } + }); + + gpii.processReporter.find = function (commandName) { + return { + "id": "gpii.processReporter", + "data": processes.findSolutionsByCommands([commandName]) + }; + }; + +})(); diff --git a/index.js b/index.js index f62cda2..b6bc54c 100644 --- a/index.js +++ b/index.js @@ -23,3 +23,4 @@ fluid.require("./gpii/node_modules/gsettingsBridge", require); fluid.require("./gpii/node_modules/orca", require); fluid.require("./gpii/node_modules/alsa", require); fluid.require("./gpii/node_modules/xrandr", require); +fluid.require("./gpii/node_modules/processReporter", require); From 3ae53770b59f0973e6c25b96669bcd72283afaa5 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Tue, 28 Apr 2015 16:45:48 -0400 Subject: [PATCH 36/78] GPII-442: Improved results returned by process reporter service. Now just returns an array of processes that match the command name. --- gpii/node_modules/processReporter/processReporter.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/gpii/node_modules/processReporter/processReporter.js b/gpii/node_modules/processReporter/processReporter.js index e86b497..6ac8050 100644 --- a/gpii/node_modules/processReporter/processReporter.js +++ b/gpii/node_modules/processReporter/processReporter.js @@ -28,10 +28,7 @@ }); gpii.processReporter.find = function (commandName) { - return { - "id": "gpii.processReporter", - "data": processes.findSolutionsByCommands([commandName]) - }; + return processes.findSolutionsByCommands([commandName]); }; })(); From 6c76cd41282167ee66f05355de76243cf685ae78 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Wed, 29 Apr 2015 11:12:04 -0400 Subject: [PATCH 37/78] GPII-442: Preliminary process reporter service. Tweaked the return value for when the process is not running. Previously, it was returning an empty array. Now, it returns a full json object where the state property is "ProcessNotRunning". --- gpii/node_modules/processReporter/processReporter.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gpii/node_modules/processReporter/processReporter.js b/gpii/node_modules/processReporter/processReporter.js index 6ac8050..b67cfc2 100644 --- a/gpii/node_modules/processReporter/processReporter.js +++ b/gpii/node_modules/processReporter/processReporter.js @@ -28,7 +28,11 @@ }); gpii.processReporter.find = function (commandName) { - return processes.findSolutionsByCommands([commandName]); + var procInfos = processes.findSolutionsByCommands([commandName]); + if (procInfos.length === 0) { + procInfos.push(processes.initProcInfoNotRunning(commandName)); + } + return procInfos; }; })(); From 603bfb119cbf6540a30ca99ad71717eaf7d35c0b Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Fri, 1 May 2015 14:49:21 -0400 Subject: [PATCH 38/78] GPII-442: Hooked process reporter unit tests into main unit test launcher. --- .../processReporter/{ => test}/processesBridge_tests.js | 4 ++-- tests/UnitTests.sh | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) rename gpii/node_modules/processReporter/{ => test}/processesBridge_tests.js (98%) diff --git a/gpii/node_modules/processReporter/processesBridge_tests.js b/gpii/node_modules/processReporter/test/processesBridge_tests.js similarity index 98% rename from gpii/node_modules/processReporter/processesBridge_tests.js rename to gpii/node_modules/processReporter/test/processesBridge_tests.js index 17e5cf7..6d2443d 100644 --- a/gpii/node_modules/processReporter/processesBridge_tests.js +++ b/gpii/node_modules/processReporter/test/processesBridge_tests.js @@ -21,8 +21,8 @@ https://github.com/gpii/universal/LICENSE.txt jqUnit = fluid.require("jqUnit"), // TODO: Must be a better way to get node gsettings add-on. - nodeGSettings = require("../gsettingsBridge/nodegsettings/build/Release/nodegsettings.node"); - require("./processesBridge.js"); + nodeGSettings = require("../../gsettingsBridge/nodegsettings/build/Release/nodegsettings.node"); + require("../processesBridge.js"); var processesBridge = fluid.registerNamespace("gpii.processes"); var procTests = fluid.registerNamespace("gpii.tests.processes"); diff --git a/tests/UnitTests.sh b/tests/UnitTests.sh index 499cc3c..78f02c9 100755 --- a/tests/UnitTests.sh +++ b/tests/UnitTests.sh @@ -30,6 +30,13 @@ cd ../gpii/node_modules/orca/test node orcaSettingsHandlerTests.js popd +pushd . +cd ../gpii/node_modules/processReporter/test +node processesBridge_tests.js +cd ../nodeprocesses +node nodeprocesses_test.js +popd + # These XRANDR tests crash out on my system (AMB - Fedora 19 64-bit in VMWare Workstation 10.0.1 on Windows 7 64-bit) node ../gpii/node_modules/xrandr/nodexrandr/nodexrandr_tests.js node ../gpii/node_modules/xrandr/test/xrandrSettingsHandlerTests.js From 25588033a9b4614216fc4a91ee912b29086451c0 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Fri, 1 May 2015 14:58:25 -0400 Subject: [PATCH 39/78] GPII-442: Cleaned up white space. --- gpii/node_modules/processReporter/processReporter.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gpii/node_modules/processReporter/processReporter.js b/gpii/node_modules/processReporter/processReporter.js index b67cfc2..13c3bcc 100644 --- a/gpii/node_modules/processReporter/processReporter.js +++ b/gpii/node_modules/processReporter/processReporter.js @@ -16,7 +16,7 @@ var fluid = require("universal"); var gpii = fluid.registerNamespace("gpii"); require("./processesBridge.js"); - + var processes = gpii.processes(); fluid.registerNamespace("gpii.processReporter"); @@ -26,7 +26,7 @@ command: 0 } }); - + gpii.processReporter.find = function (commandName) { var procInfos = processes.findSolutionsByCommands([commandName]); if (procInfos.length === 0) { From 6c971e7a0374a95db5151c50f7e53cefcc3658d2 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Tue, 30 Jun 2015 11:05:35 -0400 Subject: [PATCH 40/78] GPII-442: Re-factored processes bridge. Moved those functions, which gets information about running processes, to universal since they do not depend on the underlying OS. --- .../processReporter/processesBridge.js | 321 +----------------- 1 file changed, 6 insertions(+), 315 deletions(-) diff --git a/gpii/node_modules/processReporter/processesBridge.js b/gpii/node_modules/processReporter/processesBridge.js index 880e989..254e142 100644 --- a/gpii/node_modules/processReporter/processesBridge.js +++ b/gpii/node_modules/processReporter/processesBridge.js @@ -22,328 +22,19 @@ https://github.com/gpii/universal/LICENSE.txt gpii.processes = fluid.registerNamespace("gpii.processes"); - fluid.defaults("gpii.processes", { - gradeNames: ["fluid.eventedComponent", "autoInit"], - events: { - onRunStateChange: null, - onStateChange: null - }, + fluid.defaults("gpii.processes.native", { + gradeNames: ["fluid.littleComponent", "autoInit"], invokers: { - findSolutionsByCommands: { - funcName: "gpii.processes.findSolutionsByCommands", - args: ["{arguments}.0"] // array of command names - }, - findSolutionsByPids: { - funcName: "gpii.processes.findSolutionsByPids", - args: ["{arguments}.0"] // array of pids (process ids) - }, - getProcesses: { - funcName: "gpii.processes.getProcessList", + getProcessList: { + funcName: "gpii.processes.native.getProcessList", args: [] - }, - findProcessByPid: { - funcName: "gpii.processes.findProcessByPid", - args: ["{arguments}.0", "{arguments}.1"] // pid, procArray (optional) - }, - findProcessesByCommand: { - funcName: "gpii.processes.findProcessesByCommand", - args: ["{arguments}.0", "{arguments}.1"] - // command, procArray (optional) - }, - findFirstProcessByCommand: { - funcName: "gpii.processes.findFirstProcessByCommand", - args: ["{arguments}.0", "{arguments}.1"] - // command, procArray (optional) - }, - hasStateChanged: { - funcName: "gpii.processes.hasStateChanged", - args: ["{arguments}.0"] // process info structure - }, - isRunning: { - funcName: "gpii.processes.isRunning", - args: ["{arguments}.0"] // state (string) - }, - hasSwitchRunState: { - funcName: "gpii.processes.hasSwitchedRunState", - args: ["{arguments}.0"] // monitor info structure - }, - updateProcInfo: { - funcName: "gpii.processes.updateProcInfo", - args: ["{arguments}.0"] // process info structure - }, - initProcInfoNotRunning: { - funcName: "gpii.processes.initProcInfoNotRunning", - args: ["{arguments}.0"] // command name (string) - }, - initMonitor: { - funcName: "gpii.processes.initMonitor", - args: ["{arguments}.0"] // process info structure - }, - monitorStateChange: { - funcName: "gpii.processes.monitorStateChange", - args: ["{that}", "{arguments}.0"] // monitor info structure - }, - monitorRunStateChanged: { - funcName: "gpii.processes.monitorRunStateChanged", - args: ["{that}", "{arguments}.0"] // monitor info structure - }, - trackRunState: { - funcName: "gpii.processes.trackRunState", - args: ["{that}", "{arguments}.0", "{arguments}.1"] - // process info, handler - }, - stopTrackingRunState: { - funcName: "gpii.processes.stopTrackingRunState", - args: ["{that}", "{arguments}.0", "{arguments}.1"] - // handler, intervalID - }, - // Tracking *any* state change. - trackState: { - funcName: "gpii.processes.trackState", - args: ["{that}", "{arguments}.0", "{arguments}.1"] - // process info, handler - }, - stopTrackingState: { - funcName: "gpii.processes.stopTrackingState", - args: ["{that}", "{arguments}.0", "{arguments}.1"] - // handler, intervalID } } }); - // Return an list of process information structures corresponding to the - // names of each of the passed in commands. - gpii.processes.findSolutionsByCommands = function (commandNames) { - if (!!commandNames) { - return fluid.accumulate(commandNames, function (aCommand, matches) { - var procInfos = gpii.processes.findProcessesByCommand(aCommand); - matches = matches.concat(procInfos); - return matches; - }, []); - } - else { - return []; - } - }; - - // Return an list of process information structures corresponding to the - // pids pass in. - gpii.processes.findSolutionsByPids = function (pids) { - if (!!pids) { - return fluid.accumulate(pids, function (aPid, matches) { - var found = gpii.processes.findProcessByPid(aPid); - if (found !== null) { - matches.push(found); - } - return matches; - }, []); - } - else { - return []; - } - }; - // Return a list of processes -- a snapshot of the current processes. - gpii.processes.getProcessList = function () { + gpii.processes["native"].getProcessList = function () { return nodeProcesses.getProcesses(); }; - - // Return THE process info object that matches the given process id. - // Note that it can return "null" meaning there is no such process. - gpii.processes.findProcessByPid = function (pid, procArray) { - if (!procArray) { - procArray = gpii.processes.getProcessList(); - } - return fluid.find(procArray, function (procInfo) { - if (procInfo.pid === pid) { - return procInfo; - } - }, null); - }; - - // Return an array of process information objects that match the given - // command name string. Note that it can return an empty array, meaning - // there is no such process. - gpii.processes.findProcessesByCommand = function (commandName, procArray) { - if (!procArray) { - procArray = gpii.processes.getProcessList(); - } - return fluid.accumulate(procArray, function (aProcInfo, matchingProcs) { - if (aProcInfo.command === commandName) { - matchingProcs.push(aProcInfo); - } - return matchingProcs; - }, []); - }; - - // Return the first process of an array of processes all with the same - // command name string. If there are no matching processes, return null. - gpii.processes.findFirstProcessByCommand = - function (commandName, procArray) { - var commands = - gpii.processes.findProcessesByCommand(commandName, procArray); - if (commands.length > 0) { - return commands[0]; - } - else { - return null; - } - }; - - // Determine if the state of the given process has changed. Record the - // new process information in the monitor. Return boolean. - gpii.processes.hasStateChanged = function (monitor) { - if (!monitor || !monitor.procInfo) { - return false; // nothing sought === nothing changed. - } - monitor.newProcInfo = - gpii.processes.updateProcInfo(monitor.procInfo); - return (monitor.procInfo.state !== monitor.newProcInfo.state); - }; - - // Utility function to conflate process state values into "Running" - // (= true) vs. "Not Running" (= false). Returns boolean. - gpii.processes.isRunning = function (state) { - var result; - switch (state) { - case "Running": - case "Uninterruptible": - case "Sleeping": - case "Stopped": - result = true; - break; - - default: - case "Zombie": - case "NoSuchProcess": - result = false; - break; - } - return result; - }; - - // Determine if the state of the given process has changed from - // "not running" to "running" OR from "running" to "not running". - // Return boolean. - gpii.processes.hasSwitchedRunState = function (monitor) { - if (!monitor || !monitor.procInfo) { - // nothing sought === nothing changed. - return false; - } - monitor.newProcInfo = - gpii.processes.updateProcInfo(monitor.procInfo); - var wasRunning = gpii.processes.isRunning(monitor.procInfo.state); - var isRunning = - gpii.processes.isRunning(monitor.newProcInfo.state); - return (isRunning !== wasRunning); - }; - - // Renew the information on a process, or create a new "NoSuchProcces". - // Returns a new procInfo structure. - gpii.processes.updateProcInfo = function (procInfo) { - var newProcInfo = null; - if (procInfo.state === "NoSuchProcess") { - newProcInfo = - gpii.processes.findFirstProcessByCommand(procInfo.command); - } - else { - newProcInfo = gpii.processes.findProcessByPid(procInfo.pid); - } - if (newProcInfo === null) { - newProcInfo = - gpii.processes.initProcInfoNotRunning(procInfo.command); - } - return newProcInfo; - }; - - // Create information on a non-running process, to use to detect when the - // process starts. - gpii.processes.initProcInfoNotRunning = function (command) { - var process = {}; - process.command = command; - process.pid = -1; - process.ppid = -1; - process.uid = -1; - process.gid = -1; - process.fullPath = ""; - process.argv = ""; - process.state = "NoSuchProcess"; - return process; - }; - - // Create a monitor object for passing to a function that periodically - // checks for chanages in the state of a process. - gpii.processes.initMonitor = function (procInfo) { - var monitor = {}; - monitor.intervalID = -1; - monitor.procInfo = procInfo; - monitor.newProcInfo = null; - return monitor; - }; - - // Callback to pass to, e.g., setInterval() to periodically check the state - // of a process. - gpii.processes.monitorStateChange = function (that, monitor) { - if (gpii.processes.hasStateChanged(monitor)) { - var oldProcInfo = monitor.procInfo; - if (monitor.newProcInfo === null) { - monitor.procInfo = gpii.processes.initProcInfoNotRunning(monitor.procInfo.command); - } - else { - monitor.procInfo = monitor.newProcInfo; - } - that.events.onStateChange.fire(oldProcInfo, monitor.newProcInfo); - } - }; - - // Callback to pass to setInterval() to periodically check when the state - // changes from "running" to "not running" and vice versa. - gpii.processes.monitorRunStateChanged = function (that, monitor) { - if (gpii.processes.hasSwitchedRunState(monitor)) { - if (monitor.newProcInfo === null) { - monitor.procInfo = gpii.processes.initProcInfoNotRunning(monitor.procInfo.command); - } - else { - monitor.procInfo = monitor.newProcInfo; - } - that.events.onRunStateChange.fire(monitor.procInfo); - } - }; - - // ============== - // Event handling - // ============== - - // Provide a way for the outside world to pass in a handler for the - // "onRunStateChange" event, and to cancel. - gpii.processes.trackRunState = function (that, procInfo, handler) { - var monitor = gpii.processes.initMonitor(procInfo); - that.events.onRunStateChange.addListener(handler); - monitor.intervalID = setInterval(function () { - gpii.processes.monitorRunStateChanged(that, monitor); - }); - return monitor.intervalID; - }; - - gpii.processes.stopTrackingRunState = function (that, handler, intervalID) { - that.events.onRunStateChange.removeListener(handler); - clearInterval(intervalID); - }; - - // Provide a way for the outside world to pass in a handler for the - // "onStateChange" event, and to cancel. - gpii.processes.trackState = function (that, procInfo, handler) { - var monitor = gpii.processes.initMonitor(procInfo); - that.events.onStateChange.addListener(handler); - monitor.intervalID = setInterval(function () { - gpii.processes.monitorStateChange(that, monitor); - }); - return monitor.intervalID; - }; - - gpii.processes.stopTrackingState = function (that, handler, intervalID) { - that.events.onStateChange.removeListener(handler); - clearInterval(intervalID); - }; - + }()); From 5035227567087ac9d19dc895c7e4e325d726731f Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Tue, 30 Jun 2015 11:23:06 -0400 Subject: [PATCH 41/78] GPII-442: Updated unit tests due to re-factoring. --- gpii/node_modules/processReporter/test/processesBridge_tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gpii/node_modules/processReporter/test/processesBridge_tests.js b/gpii/node_modules/processReporter/test/processesBridge_tests.js index 6d2443d..39e910f 100644 --- a/gpii/node_modules/processReporter/test/processesBridge_tests.js +++ b/gpii/node_modules/processReporter/test/processesBridge_tests.js @@ -40,7 +40,7 @@ https://github.com/gpii/universal/LICENSE.txt jqUnit.test( "Test getProceses()/findProcessByPid() with the nodejs process itself", function () { - var procInfos = processesBridge.getProcessList(); + var procInfos = processesBridge["native"].getProcessList(); jqUnit.assertNotEquals( "Listing all processes", 0, procInfos.length ); From d952e8153fb566c0a11160923b9fbf9f0ae0c4d2 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Tue, 30 Jun 2015 16:59:01 -0400 Subject: [PATCH 42/78] GPII-442: Updated to reflect the more recent changes. --- gpii/node_modules/processReporter/README.md | 70 ++++++++++----------- 1 file changed, 33 insertions(+), 37 deletions(-) diff --git a/gpii/node_modules/processReporter/README.md b/gpii/node_modules/processReporter/README.md index ef973dc..b08c381 100644 --- a/gpii/node_modules/processReporter/README.md +++ b/gpii/node_modules/processReporter/README.md @@ -9,7 +9,7 @@ The GPII prcoesses reporter is made up of two parts: * locating processes by command. * locating a process by its process id. * emitting an event when a process changes state (`onStateChange`). - * emitting an event when a process switch run state (`onRunStateChange`). + * emitting an event when a process switches run state (`onRunStateChange`). Here is how the parts fit together, from the bottom up. @@ -70,61 +70,57 @@ Use the grunt file in the parent "linux" folder: ## Process Reporter Bridge -The process reporter bridge is a fluid evented component that makes use of the nodeprocesses node add-on and provides filters for locating processes by command, or by process id. There are also methods for determing if a process has changed state, and, in particular, whether the process has switched between a "running" state vs. a "not-running" state. The relevant files are: +The process reporter bridge is a fluid evented component that makes use of the nodeprocesses node add-on and provides filters for locating processes by command, or by process id. There are also methods for determing if a process has changed state, and, in particular, whether the process has switched between a "running" state vs. a "not-running" state. -* processReporterBridge.js - the process reporter component. -* processReporterrBridge_tests.js - unit tests for the componenet. -* processReporterBridgerDemo.js - a demo script that tracks the status of the "orca' process. +Most of the functionality of the bridge is in universal, since that functionality is not specific to GNOME/Linux. The interface to GNOME/Linux is handled by the "gpii.processes.native" (little) component. It has one invoker for acquiring a list of all processes. The "gpii.proccesses" (evented) component, in universal, has all the platform neutral functionality for finding specific processes, and monitoring them. -There are two experimental features of the reporter that likely require more thought. The first of these is a reliance on ```setInterval()``` to periodically check the status of a given process. The second is a guess as to how the proces reporter could interface with the solutions registry to determine if a solution is running or not. +The files here are: + +* processesBridge.js - the native process component. (Note: the platform neutral code is in ".../universal/gpii/node_modules/processReporter/src/"). +* processesBridge_tests.js - unit tests for the component. +* processReporterBridgeDemo.js - a demo script that shows the evented compontent tracking the status of the "orca" process. +* ProcessReporter.js - for interfacing with the solutions registry. + +There are two experimental features of the evented component that likely require more thought. The first of these is a reliance on ```setInterval()``` to periodically check the status of a given process. The second is a guess as to how the proces reporter could interface with the solutions registry to determine if a solution is running or not. ### Events `onRunStateChange` and `onStateChange` -With respect to periodically checking for a change in process status, processReporter provides two events, each with methods for attaching listeners that react to changes in process status. +With respect to periodically checking for a change in process status, processesBridge (in universal) provides two events, each with methods for attaching listeners that react to changes in process status. -The `onRunStateChange` event is fired when a process changes from a "running" state to a "not-running" state. The method `trackRunState()` takes a process information structure, and a handler function as input. It sets up a periodic check of the state of the given process using the global ```setInterval()```. If the process status changes from "running" to "not-running" or "not-running" to "running", the given handler function is called. The `trackRunState()` method returns the interval identifier returned by ```setInterval()```; however, the procesReporter provides a method `stopTrackingRunState()` for shutting down the entire tracking mechanics, including clearing the interval. +The `onRunStateChange` event is fired when a process changes from a "running" state to a "not-running" state. The method `trackRunState()` takes a process information structure, and a handler function as input. It sets up a periodic check of the state of the given process using the global ```setInterval()``` function. If the process status changes from "running" to "not-running" or "not-running" to "running", the given handler function is called. The `trackRunState()` method returns the interval identifier returned by ```setInterval()```; however, the procesReporter provides a method `stopTrackingRunState()` for shutting down the entire tracking mechanics, including clearing the interval. There is also a `onStateChange` event, and associated methods `trackState()` and `stopTrackingState()` that can be used to periodically check *any* change in state of the given prcoess, and react to the change. -A demonstration of the use of these events is provided in "processReporterDemo.js", using the Orca screen reader. The steps to run the demo are: +A demonstration of the use of these events is provided in "processesBridgeDemo.js", using the Orca screen reader. The steps to run the demo are: - 1. `$ node processReporterBridgeDemo.js` + 1. `$ node processesBridgeDemo.js` 2. Start a separate terminal session. 3. In this separate terminal, start/stop Orca the way GPII does: * `$ gsettings set org.gnome.desktop.a11y.applications screen-reader-enabled true` * `$ gsettings set org.gnome.desktop.a11y.applications screen-reader-enabled false` -As the screen-reader-enabled setting is toggled between true and false, the processReporterBridgeDemo will output the new (changed) state of Orca. +As the screen-reader-enabled setting is toggled between true and false, the processesBridgeDemo will output the new (changed) state of Orca. ### Interface with Solutions Registry -The process reporter also provides a preliminary way for locating processes based on "commands" as provided by the solutions registry. - -In the current solutions registry structure, a solution entry contains a pair of commands to start and stop that solution. These are in the lifeCycleManager sub-structure. In some cases, the actual commands/processes ultimately launched are not specified, but are invoked indirectly by changing a system setting. - -Using Orca as an example, the way to start Orca, if it is not running, is to change the "screen-reader-enabled" setting. Changing that settting from "false" to "true" eventuates in a call to another command that launches the orca process. - -In other words, the process of interest is not directly launched by GPII; the orca process is indirectly launched by changing a setting. - -To make this concrete, here is the lifecycleManager object for the "ORCA Screen Reader" solution entry: +The process reporter also provides a preliminary way for locating processes based on "commands" as provided by the solutions registry. For each solution entry, there is an `"isRunning":` property that lists the function to invoke to find all processes associated with a given command name. For example the following fragment shows the "`isRunning`" property inside the solution entry for the Orca screen reader: ``` -"lifecycleManager": { - "start": [ - "setSettings", - { - "type": "gpii.launch.exec", - "command": "gsettings set org.gnome.desktop.a11y.applications screen-reader-enabled true" - } - ], - "stop": [ - { - "type": "gpii.launch.exec", - "command": "gsettings set org.gnome.desktop.a11y.applications screen-reader-enabled false" - }, - "restoreSettings" - ] -} +... +"org.gnome.orca": { + "name": "ORCA Screen Reader", + "contexts": { + "OS": [{ + "id": "linux", + "version": ">=2.6.26" + }], + "isRunning": [ + { + "type": "gpii.processReporter.find", + "command": "orca" + } + ] + }, +... ``` -There needs to be something in the life cycle structure that documents what *comamnd* corresponds to the orca process. I'm assuming whatever that is, it can be passed to the process reporter's `findSolutionsByCommands()` to search the process list and find and return matching processes. From then on, the rest of the processReporter machinery can be used to track the state of that process, even when it is shut down by changing the screen-reader-enable setting to false. From 2af65d4aadb24169e2451ae8901f9ad24f38bf5b Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Fri, 17 Jul 2015 16:46:25 -0400 Subject: [PATCH 43/78] GPII-442: Better way to include gsettings bridge code. Uses fluid.require() rather than require(). --- .../test/processesBridge_tests.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/gpii/node_modules/processReporter/test/processesBridge_tests.js b/gpii/node_modules/processReporter/test/processesBridge_tests.js index 39e910f..bc061ab 100644 --- a/gpii/node_modules/processReporter/test/processesBridge_tests.js +++ b/gpii/node_modules/processReporter/test/processesBridge_tests.js @@ -18,12 +18,11 @@ https://github.com/gpii/universal/LICENSE.txt var path = require("path"), spawn = require("child_process").spawn, fluid = require("universal"), - jqUnit = fluid.require("jqUnit"), + jqUnit = fluid.require("jqUnit"); - // TODO: Must be a better way to get node gsettings add-on. - nodeGSettings = require("../../gsettingsBridge/nodegsettings/build/Release/nodegsettings.node"); require("../processesBridge.js"); - + fluid.require("gsettingsBridge", require); + var gsettings = fluid.registerNamespace("gpii.gsettings"); var processesBridge = fluid.registerNamespace("gpii.processes"); var procTests = fluid.registerNamespace("gpii.tests.processes"); @@ -283,7 +282,7 @@ https://github.com/gpii/universal/LICENSE.txt var orcaProcInfo = processesBridge.findFirstProcessByCommand("orca"); var wasRunning = (orcaProcInfo !== null); // Start orca -- does nothing if orca is already running. - nodeGSettings.set_gsetting( + gsettings.setSingleKey( "org.gnome.desktop.a11y.applications", "screen-reader-enabled", true ); @@ -295,8 +294,9 @@ https://github.com/gpii/universal/LICENSE.txt // Quit orca, giving it some time to quit itself. Then look for the // process whose id matches the formerly running 'orca' process. - nodeGSettings.set_gsetting( - "org.gnome.desktop.a11y.applications", "screen-reader-enabled", false + gsettings.setSingleKey( + "org.gnome.desktop.a11y.applications", + "screen-reader-enabled", false ); procTests.wait5sec(); if (orcaProcInfo !== null) { @@ -312,7 +312,7 @@ https://github.com/gpii/universal/LICENSE.txt } // Clean up. if (wasRunning) { - nodeGSettings.set_gsetting( + gsettings.setSingleKey( "org.gnome.desktop.a11y.applications", "screen-reader-enabled", true ); From 3a0895f455fa6da1bcdd3aabdc7768c7135463cd Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Mon, 20 Jul 2015 16:06:30 -0400 Subject: [PATCH 44/78] GPII-442: Added ability to check for process and relevant setting. Added a findAndCheckSetting() for solutions that do not actually have a specific process to track, but only a setting on a larger process (e.g., gnome-shell's built-in magnifier). Also, added module unit tests, and an "all-tests.js". --- .../processReporter/processReporter.js | 25 +++++++++- .../processReporter/test/all-tests.js | 28 +++++++++++ .../test/processReporterModuleTests.js | 46 +++++++++++++++++++ 3 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 gpii/node_modules/processReporter/test/all-tests.js create mode 100644 gpii/node_modules/processReporter/test/processReporterModuleTests.js diff --git a/gpii/node_modules/processReporter/processReporter.js b/gpii/node_modules/processReporter/processReporter.js index 13c3bcc..bad5836 100644 --- a/gpii/node_modules/processReporter/processReporter.js +++ b/gpii/node_modules/processReporter/processReporter.js @@ -19,6 +19,9 @@ var processes = gpii.processes(); + fluid.require("gsettingsBridge", require); + var gsettings = fluid.registerNamespace("gpii.gsettings"); + fluid.registerNamespace("gpii.processReporter"); fluid.defaults("gpii.processReporter.find", { gradeNames: "fluid.function", @@ -27,12 +30,32 @@ } }); + fluid.defaults("gpii.processReporter.findAndCheckSetting", { + gradeNames: "fluid.function", + argumentMap: { + command: 0, + schema: 1, + setting: 2 + } + }); + gpii.processReporter.find = function (commandName) { var procInfos = processes.findSolutionsByCommands([commandName]); if (procInfos.length === 0) { procInfos.push(processes.initProcInfoNotRunning(commandName)); } - return procInfos; + return { "processes": procInfos }; + }; + + gpii.processReporter.findAndCheckSetting = function (commandName, schema, setting) { + var procInfo = gpii.processReporter.find(commandName); + var settingValue = gsettings.getSingleKey(schema, setting); + procInfo["setting"] = { + "schema": schema, + "key": setting, + "value": settingValue + }; + return procInfo; }; })(); diff --git a/gpii/node_modules/processReporter/test/all-tests.js b/gpii/node_modules/processReporter/test/all-tests.js new file mode 100644 index 0000000..9f547c0 --- /dev/null +++ b/gpii/node_modules/processReporter/test/all-tests.js @@ -0,0 +1,28 @@ +/** + * GPII PackageKit Device Reporter Tests + * + * Copyright 2015 Inclusive Design Research Centre, OCAD University + * + * Licensed under the New BSD license. You may not use this file except in + * compliance with this License. + * + * You may obtain a copy of the License at + * https://github.com/gpii/universal/LICENSE.txt + */ +"use strict"; + +var fluid = require("universal"), + kettle = fluid.require("kettle"); + +kettle.loadTestingSupport(); + +var testIncludes = [ + "./processesBridge_tests.js", + "./processReporterModuleTests.js" +]; + +var tests = []; + +fluid.each(testIncludes, function (path) { + tests = tests.concat(fluid.require(path, require)); +}); diff --git a/gpii/node_modules/processReporter/test/processReporterModuleTests.js b/gpii/node_modules/processReporter/test/processReporterModuleTests.js new file mode 100644 index 0000000..cc16e20 --- /dev/null +++ b/gpii/node_modules/processReporter/test/processReporterModuleTests.js @@ -0,0 +1,46 @@ +/** + * GPII PackageKit Process Reporter Tests + * + * Copyright 2015 Inclusive Design Research Centre, OCAD University + * + * Licensed under the New BSD license. You may not use this file except in + * compliance with this License. + * + * You may obtain a copy of the License at + * https://github.com/gpii/universal/LICENSE.txt + */ +"use strict"; + +var fluid = require("universal"), + jqUnit = fluid.require("jqUnit"); + +require("processReporter"); + +var gpii = fluid.registerNamespace("gpii"); +var processReporter = fluid.registerNamespace("gpii.processReporter"); + +jqUnit.module("GPII Linux ProcessReporter Module"); + +jqUnit.test("Running tests for Linux/GNOME Process Reporter", function () { + jqUnit.expect(4); + + // Check that the bridge is loaded and required methods are available + // + var methods = ["find", "findAndCheckSetting"]; + for (var method in methods) { + jqUnit.assertTrue("Checking availability of method '" + method + "'", + (methods[method] in processReporter)); + } + + jqUnit.assertDeepEq("Checking that 'find' reports 'proccesses'", + ["processes"], + Object.keys(gpii.processReporter.find("orca"))); + + jqUnit.assertTrue( + "Checking that 'findAndCheckSetting' reports 'processes', 'setting'", + Object.keys(gpii.processReporter.findAndCheckSetting( + "orca", + "org.gnome.desktop.a11y.applications", + "screen-reader-enabled" + ))); +}); From 7f5c152bb162da40d40e16068b717f4423ab812f Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Thu, 17 Sep 2015 16:22:45 -0400 Subject: [PATCH 45/78] GPII-442: Simplified payload for reporting which solution is running. Payload no longer reports uid, pid, ppid, etc. but simply whether the solution is running or not. Also, removed findAndCheckSetting() by adding optional schema/setting parameters to find(). --- .../processReporter/processReporter.js | 42 +++++++++---------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/gpii/node_modules/processReporter/processReporter.js b/gpii/node_modules/processReporter/processReporter.js index bad5836..75163fb 100644 --- a/gpii/node_modules/processReporter/processReporter.js +++ b/gpii/node_modules/processReporter/processReporter.js @@ -24,38 +24,34 @@ fluid.registerNamespace("gpii.processReporter"); fluid.defaults("gpii.processReporter.find", { - gradeNames: "fluid.function", - argumentMap: { - command: 0 - } - }); - - fluid.defaults("gpii.processReporter.findAndCheckSetting", { gradeNames: "fluid.function", argumentMap: { command: 0, - schema: 1, - setting: 2 + schema: 1, // optional + setting: 2 // optional } }); - gpii.processReporter.find = function (commandName) { + // Search for the process using its command name, and, optionally, if the + // given GSetting is set. Returns a boolean indicating if the process is + // running (and if the setting is set). + gpii.processReporter.find = function (commandName, schema, setting) { + var running = false; var procInfos = processes.findSolutionsByCommands([commandName]); - if (procInfos.length === 0) { - procInfos.push(processes.initProcInfoNotRunning(commandName)); + var theProcess = fluid.find(procInfos, function (aProcInfo) { + if (aProcInfo.uid === process.getuid()) { + return aProcInfo; + } + }, null); + if (theProcess !== null) { + running = processes.isRunning(theProcess.state); } - return { "processes": procInfos }; - }; - gpii.processReporter.findAndCheckSetting = function (commandName, schema, setting) { - var procInfo = gpii.processReporter.find(commandName); - var settingValue = gsettings.getSingleKey(schema, setting); - procInfo["setting"] = { - "schema": schema, - "key": setting, - "value": settingValue - }; - return procInfo; + // Check GSetting as neccessary. + if (!!schema && !!setting) { + running = (running && gsettings.getSingleKey(schema, setting)); + } + return running; }; })(); From a2edeaf49526d68f6d183581e393c158b85bf9ca Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Fri, 18 Sep 2015 16:28:36 -0400 Subject: [PATCH 46/78] GPII-442: Updated module test to fit with last change. Updated unit tests due to change in simplified payload. --- .../test/processReporterModuleTests.js | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/gpii/node_modules/processReporter/test/processReporterModuleTests.js b/gpii/node_modules/processReporter/test/processReporterModuleTests.js index cc16e20..0f3152a 100644 --- a/gpii/node_modules/processReporter/test/processReporterModuleTests.js +++ b/gpii/node_modules/processReporter/test/processReporterModuleTests.js @@ -1,5 +1,5 @@ /** - * GPII PackageKit Process Reporter Tests + * GPII Process Reporter Tests * * Copyright 2015 Inclusive Design Research Centre, OCAD University * @@ -26,21 +26,21 @@ jqUnit.test("Running tests for Linux/GNOME Process Reporter", function () { // Check that the bridge is loaded and required methods are available // - var methods = ["find", "findAndCheckSetting"]; + var methods = ["find"]; for (var method in methods) { jqUnit.assertTrue("Checking availability of method '" + method + "'", (methods[method] in processReporter)); } - jqUnit.assertDeepEq("Checking that 'find' reports 'proccesses'", - ["processes"], - Object.keys(gpii.processReporter.find("orca"))); - - jqUnit.assertTrue( - "Checking that 'findAndCheckSetting' reports 'processes', 'setting'", - Object.keys(gpii.processReporter.findAndCheckSetting( - "orca", - "org.gnome.desktop.a11y.applications", - "screen-reader-enabled" - ))); + // This is running inside 'node' itself, so the uid matches. + jqUnit.assertTrue("Checking run-status of process 'node'", + gpii.processReporter.find("node")); + + // Unlikely there is ever a process named "T6y7u8i9C". + jqUnit.assertFalse("Checking run-status of process 'T6y7u8i9'", + gpii.processReporter.find("T6y7u8i9C")); + + // There is likely a 'gdm' process, but its uid is not us. + jqUnit.assertFalse("Checking run-status of un-owned 'gdm' process", + gpii.processReporter.find("gdm")); }); From 4dfe90ad9f514cce3e6ea2d550bfd4eb92c70956 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Tue, 22 Sep 2015 13:59:21 -0400 Subject: [PATCH 47/78] GPII-442: Fixed nodeprocesses node add-on. Compensated for gliptop's truncation of the process's command name given in the glibtop_proc_state struct. --- .../nodeprocesses/nodeprocesses.cc | 42 +++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses.cc b/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses.cc index 648a793..8b1cf3a 100644 --- a/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses.cc +++ b/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses.cc @@ -12,6 +12,7 @@ You may obtain a copy of the License at #include #include +#include #include #include #include @@ -30,6 +31,40 @@ const char* STATE_ZOMBIE = "Zombie"; const char* STATE_UNINTERRUPTIBLE = "Uninterruptible"; const char* STATE_SLEEPING = "Sleeping"; +// The following is based on code in gnome-system-monitor (the "System Monitor" +// application). The problem is the command name in the glibtop_proc_state +// struct is truncated. The full name is in the process arguments vector. + +static v8::Local +get_process_name (const gchar *cmd, const char** argv) +{ + char *basename = NULL; + v8::Local procname; + + if (argv) { + // look for /usr/bin/very_long_name (argv[0]), or + // /usr/bin/interpreter /usr/.../very_long_name (argv[1]) + // which may have used prctl to alter 'cmd' name. + for (int i = 0; i != 2 && argv[i]; i++) { + basename = g_path_get_basename (argv[i]); + if (g_str_has_prefix (basename, cmd)) { + break; + } + g_free (basename); + basename = NULL; + } + } + if (basename != NULL) { + procname = String::New (basename); + g_free (basename); + } + else { + procname = String::New (cmd); + } + return procname; +} + + static v8::Local format_process_state (guint state) { @@ -68,8 +103,10 @@ makeProcInfo (pid_t pid, glibtop_proclist* procList) { glibtop_proc_uid procuid; char** argv = NULL; + v8::Local procname; v8::Local fullPath = String::Empty(); v8::Handle arguments = v8::Array::New(); + v8::Handle procInfo = v8::Object::New(); glibtop_get_proc_state (&procstate, pid); glibtop_get_proc_uid (&procuid, pid); @@ -83,9 +120,8 @@ makeProcInfo (pid_t pid, glibtop_proclist* procList) { arguments->Set (i, String::New(argv[i])); } } - - v8::Handle procInfo = v8::Object::New(); - procInfo->Set(String::New("command"), String::New (procstate.cmd)); + procname = get_process_name (procstate.cmd, (const char**) argv); + procInfo->Set(String::New("command"), procname); procInfo->Set(String::New("pid"), Integer::New (pid)); procInfo->Set(String::New("ppid"), Integer::New (procuid.ppid)); procInfo->Set(String::New("uid"), Integer::New (procuid.uid)); From df128e8943e5858fe1c05b58ee120ce0c4aac605 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Fri, 18 Dec 2015 16:11:59 -0500 Subject: [PATCH 48/78] GPII-442/GPII-1383: Port the nodeprocesses add-on to Nan. Ported nodeprocesses.cc to use Nan. Note that running the add-on's unit tests requires GPII-1383 in universal. --- .../processReporter/nodeprocesses/binding.gyp | 1 + .../nodeprocesses/nodeprocesses.cc | 119 ++++++++++-------- .../nodeprocesses/nodeprocesses_test.js | 32 ++--- 3 files changed, 84 insertions(+), 68 deletions(-) diff --git a/gpii/node_modules/processReporter/nodeprocesses/binding.gyp b/gpii/node_modules/processReporter/nodeprocesses/binding.gyp index 051d2dc..59e0b35 100644 --- a/gpii/node_modules/processReporter/nodeprocesses/binding.gyp +++ b/gpii/node_modules/processReporter/nodeprocesses/binding.gyp @@ -3,6 +3,7 @@ { "target_name": "nodeprocesses", "sources": ["nodeprocesses.cc"], + "include_dirs": [" -#include +#include #include #include #include @@ -22,24 +21,42 @@ You may obtain a copy of the License at #include using namespace v8; +using v8::FunctionTemplate; +using v8::Handle; +using v8::Object; +using v8::String; +using v8::Value; +using v8::Array; +using Nan::GetFunction; +using Nan::New; +using Nan::Set; static glibtop* glibtopPtr = NULL; -const char* STATE_RUNNING = "Running"; -const char* STATE_STOPPED = "Stopped"; -const char* STATE_ZOMBIE = "Zombie"; -const char* STATE_UNINTERRUPTIBLE = "Uninterruptible"; -const char* STATE_SLEEPING = "Sleeping"; +const char* STATE_RUNNING = "Running"; +const char* STATE_STOPPED = "Stopped"; +const char* STATE_ZOMBIE = "Zombie"; +const char* STATE_UNINTERRUPTIBLE = "Uninterruptible"; +const char* STATE_SLEEPING = "Sleeping"; + +const guint64 GET_ALL_ARGS = 0; +const guint64 KERN_PROC_ALL_ARG = 0; + +static Handle +nanEncodeUtf8 (const char* string) { + return Nan::Encode (string, strlen (string), Nan::UTF8); +} + // The following is based on code in gnome-system-monitor (the "System Monitor" // application). The problem is the command name in the glibtop_proc_state // struct is truncated. The full name is in the process arguments vector. -static v8::Local +static Handle get_process_name (const gchar *cmd, const char** argv) { char *basename = NULL; - v8::Local procname; + Handle procname; if (argv) { // look for /usr/bin/very_long_name (argv[0]), or @@ -55,80 +72,82 @@ get_process_name (const gchar *cmd, const char** argv) } } if (basename != NULL) { - procname = String::New (basename); + procname = nanEncodeUtf8 (basename); g_free (basename); } else { - procname = String::New (cmd); + procname = nanEncodeUtf8 (cmd); } return procname; } - -static v8::Local +static Handle format_process_state (guint state) { - v8::Local status; + Handle status; switch (state) { case GLIBTOP_PROCESS_RUNNING: - status = String::New (STATE_RUNNING); + status = nanEncodeUtf8 (STATE_RUNNING); break; case GLIBTOP_PROCESS_STOPPED: - status = String::New (STATE_STOPPED); + status = nanEncodeUtf8 (STATE_STOPPED); break; case GLIBTOP_PROCESS_ZOMBIE: - status = String::New (STATE_ZOMBIE); + status =nanEncodeUtf8 (STATE_ZOMBIE); break; case GLIBTOP_PROCESS_UNINTERRUPTIBLE: - status = String::New (STATE_UNINTERRUPTIBLE); + status = nanEncodeUtf8 (STATE_UNINTERRUPTIBLE); break; default: - status = String::New (STATE_SLEEPING); + status = nanEncodeUtf8 (STATE_SLEEPING); break; } return status; } - -static v8::Handle -makeProcInfo (pid_t pid, glibtop_proclist* procList) { +static Handle +makeProcInfo (pid_t pid) { glibtop_proc_state procstate; glibtop_proc_args procargs; glibtop_proc_uid procuid; char** argv = NULL; - v8::Local procname; - v8::Local fullPath = String::Empty(); - v8::Handle arguments = v8::Array::New(); - v8::Handle procInfo = v8::Object::New(); + Handle encodedString; + Handle procname; + Handle fullPath = Nan::EmptyString(); + Handle arguments = Nan::New(); + Handle procInfo = Nan::New(); glibtop_get_proc_state (&procstate, pid); glibtop_get_proc_uid (&procuid, pid); - argv = glibtop_get_proc_argv (&procargs, pid, 0); + // Get the argument vector of the process and store the arguments in a v8 + // array. The first element in argv is usually (alas, not always) the + // full path to the executable. Store that as a separate property. + argv = glibtop_get_proc_argv (&procargs, pid, GET_ALL_ARGS); if (argv != NULL) { - if (argv[0] != NULL) - fullPath = String::New (argv[0]); - + if (argv[0] != NULL) { + fullPath = nanEncodeUtf8 (argv[0]); + } for (int i = 0; argv[i]; i++) { - arguments->Set (i, String::New(argv[i])); + arguments->Set (i, nanEncodeUtf8 (argv[i])); } } procname = get_process_name (procstate.cmd, (const char**) argv); - procInfo->Set(String::New("command"), procname); - procInfo->Set(String::New("pid"), Integer::New (pid)); - procInfo->Set(String::New("ppid"), Integer::New (procuid.ppid)); - procInfo->Set(String::New("uid"), Integer::New (procuid.uid)); - procInfo->Set(String::New("gid"), Integer::New (procuid.gid)); - procInfo->Set(String::New("fullPath"), fullPath); - procInfo->Set(String::New("argv"), arguments); - procInfo->Set(String::New("state"), format_process_state (procstate.state)); + procInfo->Set (nanEncodeUtf8 ("command"), procname); + procInfo->Set (nanEncodeUtf8 ("pid"), Nan::New (pid)); + procInfo->Set (nanEncodeUtf8 ("ppid"), Nan::New (procuid.ppid)); + procInfo->Set (nanEncodeUtf8 ("uid"), Nan::New (procuid.uid)); + procInfo->Set (nanEncodeUtf8 ("gid"), Nan::New (procuid.gid)); + procInfo->Set (nanEncodeUtf8 ("fullPath"), fullPath); + procInfo->Set (nanEncodeUtf8 ("argv"), arguments); + procInfo->Set (nanEncodeUtf8 ("state"), format_process_state (procstate.state)); if (argv != NULL) g_strfreev (argv); @@ -142,35 +161,31 @@ makeProcInfo (pid_t pid, glibtop_proclist* procList) { * Returns: Array of currently running processes. * FIXME: make "Returns:" more explicit. */ -Handle getProcesses (const Arguments& args) { - HandleScope scope; +NAN_METHOD(getProcesses) { pid_t* pidArray = NULL; glibtop_proclist procList; - v8::Handle procInfo; - v8::Handle result = v8::Array::New(); - - gint64 which = GLIBTOP_KERN_PROC_ALL; - gint64 arg = 0; + Handle procInfo; - pidArray = glibtop_get_proclist (&procList, which, arg); + pidArray = glibtop_get_proclist (&procList, GLIBTOP_KERN_PROC_ALL, KERN_PROC_ALL_ARG); + Local result = Nan::New (procList.number); for (unsigned int i=0; iSet (i, procInfo); } if (pidArray != NULL) g_free (pidArray); - return scope.Close (result); + info.GetReturnValue().Set (result); } -void init(Handle target) { +NAN_MODULE_INIT(init) { // Safe to call glibtop_init() since it does nothing if already initialized, // and it returns a pointer to the glibtop structure. glibtopPtr = glibtop_init(); - target->Set(String::NewSymbol("getProcesses"), - FunctionTemplate::New(getProcesses)->GetFunction()); + Nan::Set (target, New("getProcesses").ToLocalChecked(), + GetFunction (New(getProcesses)).ToLocalChecked()); } NODE_MODULE(nodeprocesses, init) diff --git a/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses_test.js b/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses_test.js index 8192ce9..983da3a 100644 --- a/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses_test.js +++ b/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses_test.js @@ -17,7 +17,7 @@ https://github.com/gpii/universal/LICENSE.txt var path = require("path"), fluid = require("universal"), - jqUnit = fluid.require("jqUnit"), + jqUnit = fluid.require("node-jqunit"), nodeProcesses = require("./build/Release/nodeprocesses.node"); var procTests = fluid.registerNamespace("gpii.tests.processes"); @@ -70,20 +70,20 @@ https://github.com/gpii/universal/LICENSE.txt "Running", nodeProcInfo.state ); - // Loop to compare nodejs argument vector against the one found by - // by procTests.getProcesses(). Note that the linux add-on (libgtop) - // returns a path relative to the current directory for argv[1], - // whereas node reports the full path. Compare using Path.resolve(). - for (var i = 0; i < process.argv.length; i++) { - var processArg = process.argv[i]; - var nodeProcInfoArg = nodeProcInfo.argv[i]; - if (i === 1) { - processArg = path.resolve(processArg); - nodeProcInfoArg = path.resolve(nodeProcInfoArg); - } - jqUnit.assertEquals("Node process 'argv[" + i + "]'", - processArg, nodeProcInfoArg - ); - } + // The "fullPath" property is added by the process node add-on. + // It should match the full path to process.title. + jqUnit.assertEquals("Node process fullPath", + path.resolve(process.title), + path.resolve(nodeProcInfo.fullPath) + ); + + // The order of process.argv is 'node', 'script file', and the rest. + // The order of nodeProcInfo.args is as the "user" typed it, where + // the first argument is the command. Hence, can only test that + // the first argument is the command in both cases. + jqUnit.assertEquals("Node process argv[0]", + path.basename(process.argv[0]), + path.basename(nodeProcInfo.argv[0]) + ); }); }()); From 375b3325480bd78f97bd4787b8aaeb88324c7e5b Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Fri, 8 Jan 2016 14:34:55 -0500 Subject: [PATCH 49/78] GPII-442/GPII-1383: Port the nodeprocesses add-on to Nan. Fixed one unit test to guarantee use of the correct forms of the paths to the process's executable. --- .../test/processesBridge_tests.js | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/gpii/node_modules/processReporter/test/processesBridge_tests.js b/gpii/node_modules/processReporter/test/processesBridge_tests.js index bc061ab..9be515f 100644 --- a/gpii/node_modules/processReporter/test/processesBridge_tests.js +++ b/gpii/node_modules/processReporter/test/processesBridge_tests.js @@ -18,7 +18,7 @@ https://github.com/gpii/universal/LICENSE.txt var path = require("path"), spawn = require("child_process").spawn, fluid = require("universal"), - jqUnit = fluid.require("jqUnit"); + jqUnit = fluid.require("node-jqunit"); require("../processesBridge.js"); fluid.require("gsettingsBridge", require); @@ -84,20 +84,22 @@ https://github.com/gpii/universal/LICENSE.txt jqUnit.assertEquals("Node process status", "Running", nodeProcInfo.state); - // Loop to compare nodejs argument vector against the one found by - // by procTests.getProcesses(). Note that the linux's libgtop - // returns a path relative to the current directory for argv[1], - // whereas node reports the full path. Compare using Path.resolve(). - for (var i = 0; i < process.argv.length; i++) { - var processArg = process.argv[i]; - var nodeProcInfoArg = nodeProcInfo.argv[i]; - if (i === 1) { - processArg = path.resolve(processArg); - nodeProcInfoArg = path.resolve(nodeProcInfoArg); - } - jqUnit.assertEquals("Node process 'argv[" + i + "]'", - processArg, nodeProcInfoArg); - } + // The "fullPath" property is added by the process node add-on. + // It should match the full path to process.title. + jqUnit.assertEquals("Node process fullPath", + path.resolve(process.title), + path.resolve(nodeProcInfo.fullPath) + ); + + // The order of process.argv and nodeProcInfo.argv is not + // necessarily the same, nor are the number of arguments the same. + // Only the first argument of vectors match as the name of the + // process (here "node"). Hence, can only test that the first + // argument is the command in both cases. + jqUnit.assertEquals("Node process argv[0]", + path.basename(process.argv[0]), + path.basename(nodeProcInfo.argv[0]) + ); } ); From f7751f76bd607ea6d32850485dc53c421a103cb9 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Fri, 15 Jan 2016 11:35:29 -0500 Subject: [PATCH 50/78] GPII-442/GPII-1318: Update to new core infusion. Updated gpii.processes.native component to use the new fluid component grades. --- gpii/node_modules/processReporter/processesBridge.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gpii/node_modules/processReporter/processesBridge.js b/gpii/node_modules/processReporter/processesBridge.js index 254e142..c589c5c 100644 --- a/gpii/node_modules/processReporter/processesBridge.js +++ b/gpii/node_modules/processReporter/processesBridge.js @@ -1,7 +1,7 @@ /*! GPII Process Reporter processes bridge -- gpii.processes. -Copyright 2014 Inclusive Design Research Centre, OCAD University +Copyright 2014-2016 Inclusive Design Research Centre, OCAD University Licensed under the New BSD license. You may not use this file except in compliance with this License. @@ -23,7 +23,7 @@ https://github.com/gpii/universal/LICENSE.txt gpii.processes = fluid.registerNamespace("gpii.processes"); fluid.defaults("gpii.processes.native", { - gradeNames: ["fluid.littleComponent", "autoInit"], + gradeNames: ["fluid.component"], invokers: { getProcessList: { funcName: "gpii.processes.native.getProcessList", From 812a44e05527a5d3a7e411ec65be8b7a651cb945 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Fri, 15 Jan 2016 16:17:31 -0500 Subject: [PATCH 51/78] GPII-442/GPII-1318: Update to new core unit testing framework. Require 'node-jqunit' insted of 'jqUnit'. --- .../processReporter/test/processReporterModuleTests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gpii/node_modules/processReporter/test/processReporterModuleTests.js b/gpii/node_modules/processReporter/test/processReporterModuleTests.js index 0f3152a..d0962c0 100644 --- a/gpii/node_modules/processReporter/test/processReporterModuleTests.js +++ b/gpii/node_modules/processReporter/test/processReporterModuleTests.js @@ -12,7 +12,7 @@ "use strict"; var fluid = require("universal"), - jqUnit = fluid.require("jqUnit"); + jqUnit = fluid.require("node-jqunit"); require("processReporter"); From 333ebe0b909088cd8194cd63f0000c77d185a434 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Tue, 15 Mar 2016 12:20:05 -0400 Subject: [PATCH 52/78] GPII-442: ProcessReporter - use correct name for loading jqUnit. In a previous commit, inadvertently updated to load 'node-jqunit' instead of 'jqUnit'. The former is for use with GPII-1318. Changing back to 'jqUnit' to work with current GPII master branch. --- .../processReporter/nodeprocesses/nodeprocesses_test.js | 2 +- gpii/node_modules/processReporter/test/processesBridge_tests.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses_test.js b/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses_test.js index 983da3a..ea73380 100644 --- a/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses_test.js +++ b/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses_test.js @@ -17,7 +17,7 @@ https://github.com/gpii/universal/LICENSE.txt var path = require("path"), fluid = require("universal"), - jqUnit = fluid.require("node-jqunit"), + jqUnit = fluid.require("jqUnit"), nodeProcesses = require("./build/Release/nodeprocesses.node"); var procTests = fluid.registerNamespace("gpii.tests.processes"); diff --git a/gpii/node_modules/processReporter/test/processesBridge_tests.js b/gpii/node_modules/processReporter/test/processesBridge_tests.js index 9be515f..46db001 100644 --- a/gpii/node_modules/processReporter/test/processesBridge_tests.js +++ b/gpii/node_modules/processReporter/test/processesBridge_tests.js @@ -18,7 +18,7 @@ https://github.com/gpii/universal/LICENSE.txt var path = require("path"), spawn = require("child_process").spawn, fluid = require("universal"), - jqUnit = fluid.require("node-jqunit"); + jqUnit = fluid.require("jqUnit"); require("../processesBridge.js"); fluid.require("gsettingsBridge", require); From d4930bb312f0b057e6de1f5987bd2d518fcd102d Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Mon, 30 May 2016 11:20:10 -0400 Subject: [PATCH 53/78] Merge branch 'GPII-1526' into GPII-1526_GPII-442. --- gpii/node_modules/alsa/nodealsa/nodealsa.cc | 20 +- .../nodegsettings/nodegsettings.cc | 84 ++++---- .../nodegsettings/nodegsettings_tests.js | 62 +++--- gpii/node_modules/orca/orcaSettingsHandler.js | 166 +++++++++++----- .../orca/test/orcaSettingsHandlerTests.js | 2 +- .../nodepackagekit/nodepackagekit.cc | 184 +++++++++--------- .../nodepackagekit/nodepackagekit_test.js | 6 +- .../xrandr/nodexrandr/nodexrandr.cc | 179 ++++++++--------- .../xrandr/nodexrandr/nodexrandr_tests.js | 4 +- 9 files changed, 379 insertions(+), 328 deletions(-) diff --git a/gpii/node_modules/alsa/nodealsa/nodealsa.cc b/gpii/node_modules/alsa/nodealsa/nodealsa.cc index 4bd32a4..d885eae 100644 --- a/gpii/node_modules/alsa/nodealsa/nodealsa.cc +++ b/gpii/node_modules/alsa/nodealsa/nodealsa.cc @@ -20,16 +20,6 @@ #include #include -using namespace v8; -using v8::FunctionTemplate; -using v8::Object; -using v8::String; -using Nan::GetFunction; -using Nan::New; -using Nan::Set; -using Nan::ThrowError; - - NAN_METHOD(getSystemVolume) { snd_mixer_t *handle; snd_mixer_selem_id_t *sid; @@ -54,7 +44,7 @@ NAN_METHOD(getSystemVolume) { snd_mixer_close(handle); - info.GetReturnValue().Set(New(curr)); + info.GetReturnValue().Set(Nan::New(curr)); } NAN_METHOD(setSystemVolume) { @@ -84,10 +74,10 @@ NAN_METHOD(setSystemVolume) { } NAN_MODULE_INIT(init) { - Nan::Set(target, New("setSystemVolume").ToLocalChecked(), - GetFunction(New(setSystemVolume)).ToLocalChecked()); - Nan::Set(target, New("getSystemVolume").ToLocalChecked(), - GetFunction(New(getSystemVolume)).ToLocalChecked()); + Nan::Set(target, Nan::New("setSystemVolume").ToLocalChecked(), + Nan::GetFunction(Nan::New(setSystemVolume)).ToLocalChecked()); + Nan::Set(target, Nan::New("getSystemVolume").ToLocalChecked(), + Nan::GetFunction(Nan::New(getSystemVolume)).ToLocalChecked()); } NODE_MODULE(nodealsa, init) diff --git a/gpii/node_modules/gsettingsBridge/nodegsettings/nodegsettings.cc b/gpii/node_modules/gsettingsBridge/nodegsettings/nodegsettings.cc index 2810621..22914d1 100644 --- a/gpii/node_modules/gsettingsBridge/nodegsettings/nodegsettings.cc +++ b/gpii/node_modules/gsettingsBridge/nodegsettings/nodegsettings.cc @@ -19,36 +19,29 @@ #include #include -using namespace v8; -using v8::FunctionTemplate; -using v8::Local; -using v8::Object; -using v8::String; -using Nan::Encode; -using Nan::GetFunction; -using Nan::New; -using Nan::Set; -using Nan::ThrowError; - NAN_METHOD(get_gsetting_keys) { GSettings *settings; + GSettingsSchema *gschema; gchar **keys; gint i; gint size = 0; - Local schema = info[0].As(); - settings = g_settings_new(*String::Utf8Value(schema)); - keys = g_settings_list_keys(settings); + v8::Local schema = info[0].As(); + settings = g_settings_new(*v8::String::Utf8Value(schema)); + + g_object_get(settings, "settings-schema", &gschema, NULL); + keys = g_settings_schema_list_keys(gschema); for (i = 0; keys[i]; i++) { size++; // Figure out how to do this in 1 loop } - Local togo = New(size); + v8::Local togo = Nan::New(size); for (i = 0; keys[i]; i++) { togo->Set(i, Nan::Encode(keys[i], strlen(keys[i]), Nan::UTF8)); } g_free(keys); - g_clear_object(&settings); + g_settings_schema_unref(gschema); + g_object_unref(settings); info.GetReturnValue().Set(togo); } @@ -56,31 +49,30 @@ NAN_METHOD(get_gsetting_keys) { ///* Should take schema and key */ NAN_METHOD(get_gsetting) { GSettings *settings; - Local schema = info[0].As(); - Local key = info[1].As(); - settings = g_settings_new(*String::Utf8Value(schema)); + v8::Local schema = info[0].As(); + v8::Local key = info[1].As(); + settings = g_settings_new(*v8::String::Utf8Value(schema)); GVariant* variant; const GVariantType* type; - variant = g_settings_get_value(settings, *String::Utf8Value(key)); + variant = g_settings_get_value(settings, *v8::String::Utf8Value(key)); type = g_variant_get_type(variant); if (g_variant_type_equal(type,G_VARIANT_TYPE_DOUBLE)) { - info.GetReturnValue().Set(New(g_variant_get_double(variant))); + info.GetReturnValue().Set(Nan::New(g_variant_get_double(variant))); } else if (g_variant_type_equal(type,G_VARIANT_TYPE_INT32)) { - info.GetReturnValue().Set(New(g_variant_get_int32(variant))); + info.GetReturnValue().Set(Nan::New(g_variant_get_int32(variant))); } else if (g_variant_type_equal(type,G_VARIANT_TYPE_STRING)) { - info.GetReturnValue().Set(New(g_variant_get_string(variant,NULL)).ToLocalChecked()); + info.GetReturnValue().Set(Nan::New(g_variant_get_string(variant,NULL)).ToLocalChecked()); } else if (g_variant_type_equal(type,G_VARIANT_TYPE_BOOLEAN)) { - info.GetReturnValue().Set(New(g_variant_get_boolean(variant))); + info.GetReturnValue().Set(Nan::New(g_variant_get_boolean(variant))); } else { g_print("The type is %s\n", g_variant_type_peek_string(type)); - ThrowError(New("Need to implement reading that value type").ToLocalChecked()); - info.GetReturnValue().Set(Nan::False()); + Nan::ThrowError(Nan::New("Need to implement reading that value type").ToLocalChecked()); } g_clear_object(&settings); @@ -92,56 +84,56 @@ NAN_METHOD(set_gsetting) { GSettings *settings; GVariant* variant; const GVariantType* type; - Local schema = info[0].As(); - Local key = info[1].As(); + v8::Local schema = info[0].As(); + v8::Local key = info[1].As(); bool status = false; - settings = g_settings_new(*String::Utf8Value(schema)); + settings = g_settings_new(*v8::String::Utf8Value(schema)); if (info[2]->IsBoolean()) { - status = g_settings_set_boolean(settings, *String::Utf8Value(key), + status = g_settings_set_boolean(settings, *v8::String::Utf8Value(key), info[2]->BooleanValue()); } else if (info[2]->IsNumber()) { - variant = g_settings_get_value(settings, *String::Utf8Value(key)); + variant = g_settings_get_value(settings, *v8::String::Utf8Value(key)); type = g_variant_get_type(variant); if (g_variant_type_equal(type,G_VARIANT_TYPE_DOUBLE)) { - status = g_settings_set_double(settings, *String::Utf8Value(key), + status = g_settings_set_double(settings, *v8::String::Utf8Value(key), info[2]->ToNumber()->Value()); } else if (g_variant_type_equal(type,G_VARIANT_TYPE_INT32)) { - status = g_settings_set_int(settings, *String::Utf8Value(key), + status = g_settings_set_int(settings, *v8::String::Utf8Value(key), info[2]->ToInt32()->Value()); } else { g_print("The type is %s\n", g_variant_type_peek_string(type)); - ThrowError(New("We haven't implemented this number type yet!").ToLocalChecked()); + Nan::ThrowError(Nan::New("We haven't implemented this number type yet!").ToLocalChecked()); } g_variant_unref(variant); } else if (info[2]->IsString()) { - Local val = info[2].As(); - variant = g_settings_get_value(settings, *String::Utf8Value(key)); + v8::Local val = info[2].As(); + variant = g_settings_get_value(settings, *v8::String::Utf8Value(key)); type = g_variant_get_type(variant); - status = g_settings_set_string(settings, *String::Utf8Value(key), - *String::Utf8Value(val)); + status = g_settings_set_string(settings, *v8::String::Utf8Value(key), + *v8::String::Utf8Value(val)); g_variant_unref(variant); } else { - ThrowError(New("We haven't implemented this type yet!").ToLocalChecked()); + Nan::ThrowError(Nan::New("We haven't implemented this type yet!").ToLocalChecked()); } g_settings_sync(); g_clear_object(&settings); - info.GetReturnValue().Set(New(status)); + info.GetReturnValue().Set(Nan::New(status)); } NAN_MODULE_INIT(init) { - Nan::Set(target, New("set_gsetting").ToLocalChecked(), - GetFunction(New(set_gsetting)).ToLocalChecked()); - Nan::Set(target, New("get_gsetting").ToLocalChecked(), - GetFunction(New(get_gsetting)).ToLocalChecked()); - Nan::Set(target, New("get_gsetting_keys").ToLocalChecked(), - GetFunction(New(get_gsetting_keys)).ToLocalChecked()); + Nan::Set(target, Nan::New("set_gsetting").ToLocalChecked(), + Nan::GetFunction(Nan::New(set_gsetting)).ToLocalChecked()); + Nan::Set(target, Nan::New("get_gsetting").ToLocalChecked(), + Nan::GetFunction(Nan::New(get_gsetting)).ToLocalChecked()); + Nan::Set(target, Nan::New("get_gsetting_keys").ToLocalChecked(), + Nan::GetFunction(Nan::New(get_gsetting_keys)).ToLocalChecked()); } NODE_MODULE(nodegsettings, init) diff --git a/gpii/node_modules/gsettingsBridge/nodegsettings/nodegsettings_tests.js b/gpii/node_modules/gsettingsBridge/nodegsettings/nodegsettings_tests.js index 94ab805..c5b1ccf 100644 --- a/gpii/node_modules/gsettingsBridge/nodegsettings/nodegsettings_tests.js +++ b/gpii/node_modules/gsettingsBridge/nodegsettings/nodegsettings_tests.js @@ -25,9 +25,16 @@ var keyScreenmag = "org.gnome.desktop.a11y.magnifier"; /* Test getting and setting boolean values */ var testBooleanValues = function () { + var original = gsettings.get_gsetting(keyScreenmag, "show-cross-hairs"); + assert.deepEqual(typeof(original), "boolean", "We got a boolean as expected"); + var ret = gsettings.set_gsetting(keyScreenmag, "show-cross-hairs", true); assert.ok(ret); - ret = gsettings.set_gsetting(keyScreenmag, "show-cross-hairs", false); + + var actual = gsettings.get_gsetting(keyScreenmag, "show-cross-hairs"); + assert.deepStrictEqual(actual, true, "We can set boolean values"); + + ret = gsettings.set_gsetting(keyScreenmag, "show-cross-hairs", original); assert.ok(ret); // Todo need to set up an event for these assertions, they run too fast, @@ -45,54 +52,53 @@ var testBooleanValues = function () { }; var testDecimalValues = function () { + var original = gsettings.get_gsetting(keyScreenmag, "mag-factor"); var ret = gsettings.set_gsetting(keyScreenmag, "mag-factor", 3.0); assert.ok(ret); + + var actual = gsettings.get_gsetting(keyScreenmag, "mag-factor"); + assert.deepStrictEqual(actual, 3.0, "We can set decimal values"); + var ret2 = gsettings.set_gsetting(keyScreenmag, "mag-factor", 5.3); assert.ok(ret2); + actual = gsettings.get_gsetting(keyScreenmag, "mag-factor"); + assert.deepStrictEqual(actual, 5.3, "We can set decimal values"); + + var ret3 = gsettings.set_gsetting(keyScreenmag, "mag-factor", original); + assert.ok(ret3); }; -var testStringToEnumValues = function () { +var testStringValues = function () { + var original = gsettings.get_gsetting(keyScreenmag, "screen-position"); var ret = gsettings.set_gsetting(keyScreenmag, "screen-position", "left-half"); assert.ok(ret); + var actual = gsettings.get_gsetting(keyScreenmag, "screen-position"); + assert.deepStrictEqual(actual, "left-half", "We can set string values"); + var ret2 = gsettings.set_gsetting(keyScreenmag, "screen-position", original); + assert.ok(ret2); }; var testIntegerValues = function () { + var original = gsettings.get_gsetting(keyScreenmag, "cross-hairs-thickness"); var ret = gsettings.set_gsetting(keyScreenmag, "cross-hairs-thickness", 7); assert.ok(ret); + var actual = gsettings.get_gsetting(keyScreenmag, "cross-hairs-thickness"); + assert.deepStrictEqual(actual, 7, "We can set integer values"); + var ret2 = gsettings.set_gsetting(keyScreenmag, "cross-hairs-thickness", original); + assert.ok(ret2); }; -/* Test Reading Values */ -var testReadingDoubleValues = function () { - var ret = gsettings.get_gsetting(keyScreenmag, "mag-factor"); - console.log("The mag-factor is: " + ret); -}; - -var testReadingIntegerValues = function () { - var ret = gsettings.get_gsetting(keyScreenmag, "cross-hairs-thickness"); - console.log("The cross hairs thickness is: " + ret); -}; - -var testReadingStringValues = function () { - var ret = gsettings.get_gsetting(keyScreenmag, "screen-position"); - console.log("The screen-position is: " + ret); -}; - -var testStuff = function () { - console.log("Testing Stuff"); +var testListKeys = function () { var keys = gsettings.get_gsetting_keys(keyScreenmag); + assert.ok(Array.isArray(keys)); for (var i = 0; i < keys.length; i++) { - console.log("Ok: " + keys[i]); + assert.ok("string", typeof(keys[i])); } - console.log("Done Testing Stuff"); }; -testStuff(); - /* Run test functions */ testBooleanValues(); testDecimalValues(); -testStringToEnumValues(); +testStringValues(); testIntegerValues(); -testReadingDoubleValues(); -testReadingIntegerValues(); -testReadingStringValues(); +testListKeys(); diff --git a/gpii/node_modules/orca/orcaSettingsHandler.js b/gpii/node_modules/orca/orcaSettingsHandler.js index 59a40ee..157593f 100644 --- a/gpii/node_modules/orca/orcaSettingsHandler.js +++ b/gpii/node_modules/orca/orcaSettingsHandler.js @@ -2,7 +2,7 @@ * GPII Orca Settings Handler * * Copyright 2013-2015 Emergya - * Copyright 2015 RtF-US + * Copyright 2015-2016 RtF-US * * Licensed under the New BSD license. You may not use this file except in * compliance with this License. @@ -21,12 +21,19 @@ var fluid = require("universal"); var gpii = fluid.registerNamespace("gpii"); var fs = require("fs"); + var spawn = require("child_process").spawn; var path = require("path"); var HOME = process.env.HOME; var XDG_DATA_HOME = process.env.XDG_DATA_HOME || path.resolve(HOME, ".local/share"); var orcaSettingsFile = path.resolve(XDG_DATA_HOME, "orca/user-settings.conf"); + var ORCA_ARGS = ["--disable", "speech", + "--disable", "braille", + "--disable", "braille-monitor", + "--disable", "main-window", + "--disable", "splash-window"]; + // When Orca is referencing a profile in a setting, it uses an array // containing the profile's name and id. // ie: startingProfile: ["Default", "default"] @@ -38,18 +45,10 @@ // var PROFILE_ID = 1; - fluid.registerNamespace("gpii.launch"); fluid.registerNamespace("gpii.orca"); fluid.defaults("gpii.orca.settingsHandler", { - gradeNames: ["fluid.modelComponent"], - changeApplierOptions: { - resolverGetConfig: fluid.model.escapedGetConfig, - resolverSetConfig: fluid.model.escapedSetConfig - }, - model: { - settings: {} - }, + gradeNames: ["fluid.component"], invokers: { get: { funcName: "gpii.orca.settingsHandler.get", @@ -66,58 +65,125 @@ setImpl: { funcName: "gpii.orca.settingsHandler.setImpl", args: ["{that}", "{arguments}.0"] - } - }, - listeners: { - onCreate: { - funcName: "gpii.orca.settingsHandler.onCreate", - args: ["{that}"] + }, + getSettings: { + funcName: "gpii.orca.settingsHandler.getSettings", + args: ["{that}", "{arguments}.0", "{arguments}.1"] + }, + setSettings: { + funcName: "gpii.orca.settingsHandler.setSettings", + args: ["{that}", "{arguments}.0"] + }, + makeConfigurable: { + funcName: "gpii.orca.settingsHandler.makeConfigurable" + }, + loadSettings: { + funcName: "gpii.orca.settingsHandler.loadSettings", + args: "{that}" } } }); - gpii.orca.settingsHandler.onCreate = function (that) { - var userSettings = fs.readFileSync(orcaSettingsFile); - that.applier.change("settings", JSON.parse(userSettings)); - }; - - gpii.orca.settingsHandler.getImpl = function (that, payload) { - var profile = that.model.settings.general.activeProfile[PROFILE_ID]; - - var results = fluid.transform(payload.settings, function (value, key) { - var currentValue = fluid.get(that.model.settings, ["profiles", profile, key]); - return currentValue; - }); + gpii.orca.settingsHandler.loadSettings = function (that) { + var togo = fluid.promise(); + + var performRead = function () { + try { + var userSettings = fs.readFileSync(orcaSettingsFile); + togo.resolve(JSON.parse(userSettings)); + } catch (err) { + var rej = { + isError: true, + message: "Unable to read Orca settings file: " + err + }; + togo.reject(rej); + } + }; + + try { + fs.statSync(orcaSettingsFile); + performRead(); + } catch (err) { + var makeConfigurable = that.makeConfigurable(); + makeConfigurable.then(function () { + performRead(); + }, function (err) { + togo.reject(err); + }); + } - return results; + return togo; }; - gpii.orca.settingsHandler.setImpl = function (that, payload) { - var profile = that.model.settings.general.activeProfile[PROFILE_ID]; - - var results = fluid.transform(payload.settings, function (value, key) { - var oldValue = fluid.get(that.model.settings, ["profiles", profile, key]); - var type; - - if (oldValue === undefined) { - type = "ADD"; - } else if (value === undefined) { - type = "DELETE"; + gpii.orca.settingsHandler.makeConfigurable = function () { + var togo = fluid.promise(); + + var orcaSpawn = spawn("orca", ORCA_ARGS); + var pass = 0; + var maxPass = 10; + + var checkIfFileGetsCreated = function () { + pass++; + if (pass === maxPass) { + orcaSpawn.kill("SIGKILL"); + var err = "Time limit exceeded [" + maxPass * 500 + + "ms] for creating Orca's configuration file"; + var rej = { + isError: true, + message: err + }; + togo.reject(rej); } else { - type = null; + try { + fs.statSync(orcaSettingsFile); + orcaSpawn.kill("SIGKILL"); + togo.resolve(); + } catch (err) { + gpii.invokeLater(checkIfFileGetsCreated, 500); + } } + }; - that.applier.change(["settings", "profiles", profile, key], value, type); + gpii.invokeLater(checkIfFileGetsCreated, 500); + return togo; + }; - var newValue = fluid.get(that.model.settings, ["profiles", profile, key]); + gpii.orca.settingsHandler.getSettings = function (that, payload) { + var loadSettings = that.loadSettings(); + return fluid.promise.map(loadSettings, function (userSettings) { + var profile = userSettings.general.activeProfile[PROFILE_ID]; + var results = fluid.transform(payload.settings, function (value, key) { + var currentValue = fluid.get(userSettings, ["profiles", profile, key]); + return currentValue; + }); + return results; + }); + }; - return { - oldValue: oldValue, - newValue: newValue - }; + gpii.orca.settingsHandler.setSettings = function (that, payload) { + var loadSettings = that.loadSettings(); + return fluid.promise.map(loadSettings, function (userSettings) { + var profile = userSettings.general.activeProfile[PROFILE_ID]; + var results = fluid.transform(payload.settings, function (value, key) { + var oldValue = fluid.get(userSettings, ["profiles", profile, key]); + fluid.set(userSettings, ["profiles", profile, key], value); + var newValue = fluid.get(userSettings, ["profiles", profile, key]); + return { + oldValue: oldValue, + newValue: newValue + }; + }); + fs.writeFileSync(orcaSettingsFile, JSON.stringify(userSettings, null, 4)); + return results; }); + }; + + gpii.orca.settingsHandler.getImpl = function (that, payload) { + return that.getSettings(payload); + }; - return results; + gpii.orca.settingsHandler.setImpl = function (that, payload) { + return that.setSettings(payload); }; gpii.orca.settingsHandler.get = function (that, payload) { @@ -125,9 +191,7 @@ }; gpii.orca.settingsHandler.set = function (that, payload) { - var results = gpii.settingsHandlers.invokeSettingsHandler(that.setImpl, payload); - fs.writeFileSync(orcaSettingsFile, JSON.stringify(that.model.settings, null, 4)); - return results; + return gpii.settingsHandlers.invokeSettingsHandler(that.setImpl, payload); }; var orcaSettingsHandler = gpii.orca.settingsHandler(); diff --git a/gpii/node_modules/orca/test/orcaSettingsHandlerTests.js b/gpii/node_modules/orca/test/orcaSettingsHandlerTests.js index 16ba93c..6862287 100644 --- a/gpii/node_modules/orca/test/orcaSettingsHandlerTests.js +++ b/gpii/node_modules/orca/test/orcaSettingsHandlerTests.js @@ -120,7 +120,7 @@ jqUnit.test("Running tests for Orca Settings Handler", function () { var content = JSON.parse(fs.readFileSync(orcaSettingsFile)); var profile = content.general.activeProfile[1]; - var settings = content.profiles[profile]; + settings = content.profiles[profile]; jqUnit.assertFalse("No 'foo' setting in Orca's config file", settings.hasOwnProperty("foo")); jqUnit.assertFalse("No 'cat' setting in Orca's config file", settings.hasOwnProperty("cat")); diff --git a/gpii/node_modules/packagekit/nodepackagekit/nodepackagekit.cc b/gpii/node_modules/packagekit/nodepackagekit/nodepackagekit.cc index 99980c7..a4dd66e 100644 --- a/gpii/node_modules/packagekit/nodepackagekit/nodepackagekit.cc +++ b/gpii/node_modules/packagekit/nodepackagekit/nodepackagekit.cc @@ -19,21 +19,10 @@ You may obtain a copy of the License at #include #include -using namespace v8; -using v8::FunctionTemplate; -using v8::Handle; -using v8::Object; -using v8::String; -using v8::Value; -using Nan::GetFunction; -using Nan::New; -using Nan::Set; -using Nan::ThrowError; - /* Set DEBUG to TRUE in order to see the transactions' progress * TODO: Allow switching DEBUG value from Node.js side */ -static gboolean DEBUG = FALSE; +static gboolean DEBUG = TRUE; static gchar TAG[] = "[nodePackagekit]"; @@ -43,14 +32,20 @@ typedef struct { } PkitPropAccess; static std::basic_string -utf8StringFromValue (Handle value) +utf8StringFromValue(v8::Handle value) { std::basic_string result; - Nan::Utf8String nanUtf8 (value); + Nan::Utf8String nanUtf8(value); + + // According to the Nan documentation, if the conversion to Nan::Utf8String + // fails, then the '*' operator gives a NULL result and not the empty + // string. However, its length() method returns zero. To avoid NULL, check + // the length, and if zero, skip. + // https://github.com/nodejs/nan/blob/master/doc/v8_misc.md#nanutf8string if (nanUtf8.length() != 0) { - result.append (*nanUtf8); + result.append(*nanUtf8); } - return (result); + return result; } static void @@ -60,6 +55,8 @@ progressCallback(PkProgress *progress, PkProgressType type) { gint percentage; gboolean allow_cancel; + static gboolean extranewline = FALSE; + g_object_get(progress, "status", &status, "percentage", &percentage, @@ -67,15 +64,22 @@ progressCallback(PkProgress *progress, PkProgressType type) { NULL); if (type == PK_PROGRESS_TYPE_STATUS) { - printf ("%s Transaction status: %s\n", TAG, pk_status_enum_to_string (status)); + if (extranewline == TRUE) { + printf("\n"); + extranewline = FALSE; + } + printf("%s Transaction status: %s\n", TAG, pk_status_enum_to_string(status)); } else if (type == PK_PROGRESS_TYPE_PERCENTAGE) { - if (percentage > 0) - printf ("%s Current percentage: %d%%\n", TAG, percentage); + if (percentage > 0) { + printf(" %d%% ", percentage); + fflush(stdout); + extranewline = TRUE; + } } } static PkBitfield -handleFiltersArgument (const Nan::FunctionCallbackInfo& args, const int filterIndex) { +handleFiltersArgument(const Nan::FunctionCallbackInfo& args, const int filterIndex) { std::basic_string filters; if (args.Length() > filterIndex) { @@ -84,14 +88,14 @@ handleFiltersArgument (const Nan::FunctionCallbackInfo& args, const i else { filters = (gchar *) "none"; } - return pk_filter_bitfield_from_string (filters.c_str()); + return pk_filter_bitfield_from_string(filters.c_str()); } -static Handle -makePac (PkPackage *package) { - Handle pac = Nan::New(); - Handle key; - Handle value; +static v8::Handle +makePac(PkPackage *package) { + v8::Handle pac = Nan::New(); + v8::Handle key; + v8::Handle value; const gchar *pkString; PkitPropAccess propAccess[] = { @@ -106,14 +110,14 @@ makePac (PkPackage *package) { PkitPropAccess aPropAccess = propAccess[0]; for (int i = 1; aPropAccess.property != NULL; i++) { pkString = aPropAccess.property; - key = Nan::Encode (pkString, strlen (pkString), Nan::UTF8); - pkString = (aPropAccess.accessFunc) (package); - value = Nan::Encode (pkString, strlen (pkString), Nan::UTF8); - pac->Set (key, value); + key = Nan::Encode(pkString, strlen(pkString), Nan::UTF8); + pkString = (aPropAccess.accessFunc)(package); + value = Nan::Encode(pkString, strlen(pkString), Nan::UTF8); + pac->Set(key, value); aPropAccess = propAccess[i]; } - return (pac); + return pac; } /** @@ -134,39 +138,39 @@ NAN_METHOD(searchPackage) { std::basic_string name; PkBitfield filtersBitField; GError *err = NULL; - Handle pac; - Handle result; + v8::Handle pac; + v8::Handle result; name = utf8StringFromValue(info[0]); gchar *names[sizeof(name)] = {&name[0]}; - filtersBitField = handleFiltersArgument (info, 1); + filtersBitField = handleFiltersArgument(info, 1); client = pk_client_new(); - pkResults = pk_client_search_names ( + pkResults = pk_client_search_names( client, filtersBitField, names, NULL, (PkProgressCallback) progressCallback, NULL, &err ); sack = pk_results_get_package_sack(pkResults); - pk_package_sack_sort (sack, PK_PACKAGE_SACK_SORT_TYPE_NAME); - array = pk_package_sack_get_array (sack); + pk_package_sack_sort(sack, PK_PACKAGE_SACK_SORT_TYPE_NAME); + array = pk_package_sack_get_array(sack); - result = Nan::New(array->len); + result = Nan::New(array->len); for (unsigned int i=0; ilen; i++) { PkPackage *package = (PkPackage *) g_ptr_array_index(array, i); - pac = makePac (package); - result->Set (i, pac); + pac = makePac(package); + result->Set(i, pac); } - g_clear_object (&pkResults); - g_clear_object (&sack); - g_clear_object (&client); + g_clear_object(&pkResults); + g_clear_object(&sack); + g_clear_object(&client); if (array != NULL) g_ptr_array_unref(array); if (err != NULL) g_clear_error(&err); - info.GetReturnValue().Set (result); + info.GetReturnValue().Set(result); } /** @@ -187,38 +191,38 @@ NAN_METHOD(searchFiles) { std::basic_string pathName; PkBitfield filtersBitField; GError *err = NULL; - Handle pac; - Handle result; + v8::Handle pac; + v8::Handle result; - pathName = utf8StringFromValue (info[0]); + pathName = utf8StringFromValue(info[0]); gchar *pathNames[sizeof(pathName)] = {&pathName[0]}; - filtersBitField = handleFiltersArgument (info, 1); + filtersBitField = handleFiltersArgument(info, 1); client = pk_client_new(); - pkResults = pk_client_search_files ( + pkResults = pk_client_search_files( client, filtersBitField, pathNames, NULL, (PkProgressCallback) progressCallback, NULL, &err ); sack = pk_results_get_package_sack(pkResults); - pk_package_sack_sort (sack, PK_PACKAGE_SACK_SORT_TYPE_NAME); - array = pk_package_sack_get_array (sack); + pk_package_sack_sort(sack, PK_PACKAGE_SACK_SORT_TYPE_NAME); + array = pk_package_sack_get_array(sack); - result = Nan::New(array->len); + result = Nan::New(array->len); for (unsigned int i=0; ilen; i++) { PkPackage *package = (PkPackage *) g_ptr_array_index(array, i); - pac = makePac (package); - result->Set (i,pac); + pac = makePac(package); + result->Set(i,pac); } - g_clear_object (&pkResults); - g_clear_object (&sack); - g_clear_object (&client); + g_clear_object(&pkResults); + g_clear_object(&sack); + g_clear_object(&client); if (array != NULL) g_ptr_array_unref(array); if (err != NULL) g_clear_error(&err); - info.GetReturnValue().Set (result); + info.GetReturnValue().Set(result); } /** @@ -241,36 +245,36 @@ NAN_METHOD(getPackages) { PkPackageSack *sack = NULL; PkBitfield filtersBitField; GError *err = NULL; - Handle pac; - Handle result; + v8::Handle pac; + v8::Handle result; - filtersBitField = handleFiltersArgument (info, 0); + filtersBitField = handleFiltersArgument(info, 0); client = pk_client_new(); - pkResults = pk_client_get_packages ( + pkResults = pk_client_get_packages( client, filtersBitField, NULL, (PkProgressCallback) progressCallback, NULL, &err ); - sack = pk_results_get_package_sack (pkResults); - pk_package_sack_sort (sack, PK_PACKAGE_SACK_SORT_TYPE_NAME); - array = pk_package_sack_get_array (sack); + sack = pk_results_get_package_sack(pkResults); + pk_package_sack_sort(sack, PK_PACKAGE_SACK_SORT_TYPE_NAME); + array = pk_package_sack_get_array(sack); - result = Nan::New(array->len); + result = Nan::New(array->len); for (unsigned int i=0; ilen; i++) { PkPackage *package = (PkPackage *) g_ptr_array_index(array, i); - pac = makePac (package); - result->Set (i,pac); + pac = makePac(package); + result->Set(i,pac); } - g_clear_object (&pkResults); - g_clear_object (&sack); - g_clear_object (&client); + g_clear_object(&pkResults); + g_clear_object(&sack); + g_clear_object(&client); if (array != NULL) g_ptr_array_unref(array); if (err != NULL) g_clear_error(&err); - info.GetReturnValue().Set (result); + info.GetReturnValue().Set(result); } /** @@ -290,45 +294,49 @@ NAN_METHOD(performAction) { gchar **package_ids = NULL; task = pk_task_new(); - package_ids = pk_package_ids_from_id (name.c_str()); + package_ids = pk_package_ids_from_id(name.c_str()); if (action == "install") { - pk_task_install_packages_sync (task, package_ids, NULL, + pk_task_install_packages_sync(task, package_ids, NULL, (PkProgressCallback) progressCallback, NULL, &err); } else if (action == "update") { - pk_task_update_packages_sync (task, package_ids, NULL, + pk_task_update_packages_sync(task, package_ids, NULL, (PkProgressCallback) progressCallback, NULL, &err); } else if (action == "remove") { - pk_task_remove_packages_sync (task, package_ids, TRUE, FALSE, NULL, + pk_task_remove_packages_sync(task, package_ids, TRUE, FALSE, NULL, (PkProgressCallback) progressCallback, NULL, &err); } else { - ThrowError( + g_clear_object(&task); + task = NULL; + g_strfreev(package_ids); + package_ids = NULL; + Nan::ThrowError( "You have to provide the action to be performed, either 'install', " "'update' or 'remove'"); } - g_clear_object (&task); - g_strfreev (package_ids); + g_clear_object(&task); + g_strfreev(package_ids); if (err != NULL) g_clear_error(&err); - info.GetReturnValue().Set (Nan::True()); + info.GetReturnValue().Set(Nan::True()); } NAN_MODULE_INIT(init) { - Nan::Set (target, New("searchPackage").ToLocalChecked(), - GetFunction (New(searchPackage)).ToLocalChecked()); + Nan::Set(target, Nan::New("searchPackage").ToLocalChecked(), + Nan::GetFunction(Nan::New(searchPackage)).ToLocalChecked()); - Nan::Set (target, New("searchFiles").ToLocalChecked(), - GetFunction (New(searchFiles)).ToLocalChecked()); + Nan::Set(target, Nan::New("searchFiles").ToLocalChecked(), + Nan::GetFunction(Nan::New(searchFiles)).ToLocalChecked()); - Nan::Set (target, New("getPackages").ToLocalChecked(), - GetFunction (New(getPackages)).ToLocalChecked()); + Nan::Set(target, Nan::New("getPackages").ToLocalChecked(), + Nan::GetFunction(Nan::New(getPackages)).ToLocalChecked()); - Nan::Set (target, New("performAction").ToLocalChecked(), - GetFunction (New(performAction)).ToLocalChecked()); + Nan::Set(target, Nan::New("performAction").ToLocalChecked(), + Nan::GetFunction(Nan::New(performAction)).ToLocalChecked()); } NODE_MODULE(nodepackagekit, init) diff --git a/gpii/node_modules/packagekit/nodepackagekit/nodepackagekit_test.js b/gpii/node_modules/packagekit/nodepackagekit/nodepackagekit_test.js index b3f7a69..5903c4e 100644 --- a/gpii/node_modules/packagekit/nodepackagekit/nodepackagekit_test.js +++ b/gpii/node_modules/packagekit/nodepackagekit/nodepackagekit_test.js @@ -155,12 +155,12 @@ var fluid = require("universal"), return matchPkg; }; - pkTests.testPerformActionFailure = function() { + pkTests.testPerformActionFailure = function () { var errMsg = "No Error Message"; try { packagekit.performAction("foo", "bar"); } - catch(error) { + catch (error) { errMsg = error.message; } return errMsg; @@ -239,7 +239,7 @@ var fluid = require("universal"), } }); - jqUnit.test("Test performAction() with invalid argments", function() { + jqUnit.test("Test performAction() with invalid argments", function () { var errorMessage = pkTests.testPerformActionFailure(); jqUnit.assertEquals( "Result of ThrowError():", diff --git a/gpii/node_modules/xrandr/nodexrandr/nodexrandr.cc b/gpii/node_modules/xrandr/nodexrandr/nodexrandr.cc index 0da6912..069ed37 100644 --- a/gpii/node_modules/xrandr/nodexrandr/nodexrandr.cc +++ b/gpii/node_modules/xrandr/nodexrandr/nodexrandr.cc @@ -38,16 +38,6 @@ #include "config.h" #endif -using namespace v8; -using v8::FunctionTemplate; -using v8::Local; -using v8::Object; -using Nan::GetFunction; -using Nan::New; -using Nan::Set; - -using namespace std; - typedef enum _name_kind { name_none = 0, name_string = (1 << 0), @@ -60,24 +50,24 @@ typedef struct { name_kind_t kind; char *string; XID xid; - int index; + int index; } name_t; static void -init_name (name_t *name) +init_name(name_t *name) { name->kind = name_none; } static void -set_name_xid (name_t *name, XID xid) +set_name_xid(name_t *name, XID xid) { name->kind |= name_xid; name->xid = xid; } static double -mode_refresh (XRRModeInfo *mode_info) +mode_refresh(XRRModeInfo *mode_info) { double rate; unsigned int vTotal = mode_info->vTotal; @@ -102,7 +92,7 @@ mode_refresh (XRRModeInfo *mode_info) } static XRRModeInfo * -find_mode (name_t *name, double refresh, XRRScreenResources *res) +find_mode(name_t *name, double refresh, XRRScreenResources *res) { int m; XRRModeInfo *best = NULL; @@ -116,12 +106,12 @@ find_mode (name_t *name, double refresh, XRRScreenResources *res) best = mode; break; } - if ((name->kind & name_string) && !strcmp (name->string, mode->name)) + if ((name->kind & name_string) && !strcmp(name->string, mode->name)) { double dist; if (refresh) - dist = fabs (mode_refresh (mode) - refresh); + dist = fabs(mode_refresh(mode) - refresh); else dist = 0; if (!best || dist < bestDist) @@ -135,95 +125,98 @@ find_mode (name_t *name, double refresh, XRRScreenResources *res) } static XRRModeInfo * -find_mode_by_xid (RRMode mode, XRRScreenResources *res) +find_mode_by_xid(RRMode mode, XRRScreenResources *res) { name_t mode_name; - init_name (&mode_name); - set_name_xid (&mode_name, mode); - return find_mode (&mode_name, 0, res); + init_name(&mode_name); + set_name_xid(&mode_name, mode); + return find_mode(&mode_name, 0, res); } NAN_METHOD(getDisplays) { Display *dpy; - Window root; + char *display_name; + int screen; + char screenNumber[8]; + Window root; XRRScreenResources *res; XRRScreenConfiguration *sc; + std::basic_string errMsg; + v8::Local result = Nan::New(); - Local result = New(); - - char *display_name = NULL; - int screen = -1; - - dpy = XOpenDisplay (display_name); + // Get default display name. + display_name = XDisplayName(NULL); + dpy = XOpenDisplay(display_name); if (dpy == NULL) { - fprintf (stderr, "Can't open display %s\n", XDisplayName(display_name)); - exit (1); + errMsg.append("Can't open display ").append(display_name); + Nan::ThrowError(errMsg.c_str()); } - if (screen < 0) - screen = DefaultScreen (dpy); - if (screen >= ScreenCount (dpy)) { - fprintf (stderr, "Invalid screen number %d (display has %d)\n", - screen, ScreenCount (dpy)); - exit (1); + screen = DefaultScreen(dpy); + if (screen >= ScreenCount(dpy)) { + sprintf(screenNumber, "%d", screen); + errMsg.append("Invalid screen number (display has ").append(screenNumber).append(")"); + Nan::ThrowError(errMsg.c_str()); } - root = RootWindow (dpy, screen); + root = RootWindow(dpy, screen); // get current resolution // - sc = XRRGetScreenInfo (dpy, root); + sc = XRRGetScreenInfo(dpy, root); Rotation current_rotation; SizeID current_size; XRRScreenSize *sizes; int nsize; - current_size = XRRConfigCurrentConfiguration (sc, ¤t_rotation); + current_size = XRRConfigCurrentConfiguration(sc, ¤t_rotation); sizes = XRRConfigSizes(sc, &nsize); - Local resolution_object = New(); + v8::Local resolution_object = Nan::New(); - res = XRRGetScreenResourcesCurrent (dpy, root); + res = XRRGetScreenResourcesCurrent(dpy, root); for (int i=0; inoutput; i++) { XRROutputInfo *output_info; output_info = XRRGetOutputInfo(dpy, res, res->outputs[i]); - Local output = New(); + v8::Local output = Nan::New(); - output->Set(New("name").ToLocalChecked(), - New(output_info->name).ToLocalChecked()); + output->Set(Nan::New("name").ToLocalChecked(), + Nan::New(output_info->name).ToLocalChecked()); switch (output_info->connection) { case RR_Connected: - output->Set(New("status").ToLocalChecked(), - New("connected").ToLocalChecked()); + output->Set(Nan::New("status").ToLocalChecked(), + Nan::New("connected").ToLocalChecked()); - resolution_object->Set(New("width").ToLocalChecked(), - New(sizes[current_size].width)); - resolution_object->Set(New("height").ToLocalChecked(), - New(sizes[current_size].height)); + resolution_object->Set(Nan::New("width").ToLocalChecked(), + Nan::New(sizes[current_size].width)); + resolution_object->Set(Nan::New("height").ToLocalChecked(), + Nan::New(sizes[current_size].height)); - resolution_object->Set(New("mwidth").ToLocalChecked(), - New(sizes[current_size].mwidth)); - resolution_object->Set(New("mheight").ToLocalChecked(), - New(sizes[current_size].mheight)); + resolution_object->Set(Nan::New("mwidth").ToLocalChecked(), + Nan::New(sizes[current_size].mwidth)); + resolution_object->Set(Nan::New("mheight").ToLocalChecked(), + Nan::New(sizes[current_size].mheight)); - output->Set(New("resolution").ToLocalChecked(), resolution_object); + output->Set(Nan::New("resolution").ToLocalChecked(), resolution_object); break; case RR_Disconnected: - output->Set(New("status").ToLocalChecked(), - New("disconnected").ToLocalChecked()); + output->Set(Nan::New("status").ToLocalChecked(), + Nan::New("disconnected").ToLocalChecked()); break; } - Local available_resolutions = New(); + v8::Local available_resolutions = Nan::New(); + char *resolution; for (int j=0; jnmode; j++) { - char *resolution; - XRRModeInfo *mode = find_mode_by_xid (output_info->modes[j], res); + XRRModeInfo *mode = find_mode_by_xid(output_info->modes[j], res); asprintf(&resolution, "%dx%d", mode->width, mode->height); available_resolutions->Set(j, Nan::Encode(resolution, strlen(resolution), Nan::UTF8)); + free(resolution); + resolution = NULL; } - output->Set(New("available_resolutions").ToLocalChecked(), + output->Set(Nan::New("available_resolutions").ToLocalChecked(), available_resolutions); result->Set(i,output); @@ -243,31 +236,31 @@ NAN_METHOD(setScreenResolution) { char *displayname = NULL; - dpy = XOpenDisplay (displayname); + dpy = XOpenDisplay(displayname); if (dpy == NULL) { - printf ("Cannot open display %s\n", displayname); - return info.GetReturnValue().Set(New(False)); + printf("Cannot open display %s\n", displayname); + return info.GetReturnValue().Set(Nan::New(False)); } - int screen = DefaultScreen (dpy); - Window root = RootWindow (dpy, screen); + int screen = DefaultScreen(dpy); + Window root = RootWindow(dpy, screen); int eventbase; int errorbase; if (!XRRQueryExtension(dpy, &eventbase, &errorbase)) { - printf ("RandR extension missing\n"); - return info.GetReturnValue().Set(New(False)); + printf("RandR extension missing\n"); + return info.GetReturnValue().Set(Nan::New(False)); } - XRRScreenConfiguration *sc = XRRGetScreenInfo (dpy, root); + XRRScreenConfiguration *sc = XRRGetScreenInfo(dpy, root); if (sc == NULL) { - printf ("Cannot get screen info\n"); - return info.GetReturnValue().Set(New(False)); + printf("Cannot get screen info\n"); + return info.GetReturnValue().Set(Nan::New(False)); } - XSelectInput (dpy, root, StructureNotifyMask); - XRRSelectInput (dpy, root, RRScreenChangeNotifyMask); + XSelectInput(dpy, root, StructureNotifyMask); + XRRSelectInput(dpy, root, RRScreenChangeNotifyMask); Rotation current_rotation; SizeID current_size; - current_size = XRRConfigCurrentConfiguration (sc, ¤t_rotation); + current_size = XRRConfigCurrentConfiguration(sc, ¤t_rotation); int nsize; XRRScreenSize *sizes = XRRConfigSizes(sc, &nsize); @@ -280,20 +273,20 @@ NAN_METHOD(setScreenResolution) { } if (sizeindex >= nsize) { - printf ("%dx%d resolution not available\n", width, height); - XRRFreeScreenConfigInfo (sc); - return info.GetReturnValue().Set(New(False)); + printf("%dx%d resolution not available\n", width, height); + XRRFreeScreenConfigInfo(sc); + return info.GetReturnValue().Set(Nan::New(False)); } - Status status = XRRSetScreenConfig (dpy, sc, - DefaultRootWindow (dpy), - sizeindex, - (Rotation) (rotation | reflection), - CurrentTime); + Status status = XRRSetScreenConfig(dpy, sc, + DefaultRootWindow(dpy), + sizeindex, + (Rotation) (rotation | reflection), + CurrentTime); if (status == RRSetConfigFailed) { - printf ("Failed to change the screen resolution.\n"); - XRRFreeScreenConfigInfo (sc); - return info.GetReturnValue().Set(New(False)); + printf("Failed to change the screen resolution.\n"); + XRRFreeScreenConfigInfo(sc); + return info.GetReturnValue().Set(Nan::New(False)); } else { // status == RRSetConfigSuccess if (sizeindex != current_size) { @@ -301,8 +294,8 @@ NAN_METHOD(setScreenResolution) { bool rcvdrrnotify = false; while (!rcvdrrnotify) { XNextEvent(dpy, (XEvent *) &event); - //printf ("Event received, type = %d\n", event.type); - XRRUpdateConfiguration (&event) ; + //printf("Event received, type = %d\n", event.type); + XRRUpdateConfiguration(&event) ; switch (event.type - eventbase) { case RRScreenChangeNotify: rcvdrrnotify = true; @@ -316,14 +309,14 @@ NAN_METHOD(setScreenResolution) { } } } - XRRFreeScreenConfigInfo (sc); - info.GetReturnValue().Set(New(True)); + XRRFreeScreenConfigInfo(sc); + info.GetReturnValue().Set(Nan::New(True)); } NAN_MODULE_INIT(init) { - Nan::Set(target, New("getDisplays").ToLocalChecked(), - GetFunction(New(getDisplays)).ToLocalChecked()); - Nan::Set(target, New("setScreenResolution").ToLocalChecked(), - GetFunction(New(setScreenResolution)).ToLocalChecked()); + Nan::Set(target, Nan::New("getDisplays").ToLocalChecked(), + Nan::GetFunction(Nan::New(getDisplays)).ToLocalChecked()); + Nan::Set(target, Nan::New("setScreenResolution").ToLocalChecked(), + Nan::GetFunction(Nan::New(setScreenResolution)).ToLocalChecked()); } NODE_MODULE(nodexrandr, init) diff --git a/gpii/node_modules/xrandr/nodexrandr/nodexrandr_tests.js b/gpii/node_modules/xrandr/nodexrandr/nodexrandr_tests.js index 63612f7..cacc60d 100644 --- a/gpii/node_modules/xrandr/nodexrandr/nodexrandr_tests.js +++ b/gpii/node_modules/xrandr/nodexrandr/nodexrandr_tests.js @@ -55,9 +55,7 @@ jqUnit.test("Running tests for Xrandr Bridge", function () { // var display = xrandr.getDisplays()[0]; jqUnit.assertFalse("Checking 'setScreenResolution' with impossible size", - xrandr.setScreenResolution( - display.resolution.mwidth - 1, - display.resolution.mheight - 1)); + xrandr.setScreenResolution(-1, -1)); // Convert the current resolution to a string, and see if there is a // different available resolution to test setScreenResolution(). From 2c41418d2ab91d0ababccbedd91e035fe88b7e40 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Wed, 1 Jun 2016 09:25:53 -0400 Subject: [PATCH 54/78] GPII-1318: Modified due to removal of unnecessary utility fluid.getLoader. --- gpii/node_modules/processReporter/index.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/gpii/node_modules/processReporter/index.js b/gpii/node_modules/processReporter/index.js index f289832..571bd60 100644 --- a/gpii/node_modules/processReporter/index.js +++ b/gpii/node_modules/processReporter/index.js @@ -10,9 +10,5 @@ * https://github.com/gpii/universal/LICENSE.txt */ -var fluid = require("universal"); - -var loader = fluid.getLoader(__dirname); - -loader.require("./processReporter.js"); +require("./processReporter.js"); From 1fee6d753f2c3f0e9dbd81a4cf88e28683ab1a7b Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Fri, 3 Jun 2016 14:38:48 -0400 Subject: [PATCH 55/78] GPII-1318/GPII-442: Fixed errant references to 'jqUnit'. Replaced 'jqUnit' with 'node-jqunit'. --- .../processReporter/nodeprocesses/nodeprocesses_test.js | 2 +- gpii/node_modules/processReporter/test/processesBridge_tests.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses_test.js b/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses_test.js index ea73380..983da3a 100644 --- a/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses_test.js +++ b/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses_test.js @@ -17,7 +17,7 @@ https://github.com/gpii/universal/LICENSE.txt var path = require("path"), fluid = require("universal"), - jqUnit = fluid.require("jqUnit"), + jqUnit = fluid.require("node-jqunit"), nodeProcesses = require("./build/Release/nodeprocesses.node"); var procTests = fluid.registerNamespace("gpii.tests.processes"); diff --git a/gpii/node_modules/processReporter/test/processesBridge_tests.js b/gpii/node_modules/processReporter/test/processesBridge_tests.js index 46db001..9be515f 100644 --- a/gpii/node_modules/processReporter/test/processesBridge_tests.js +++ b/gpii/node_modules/processReporter/test/processesBridge_tests.js @@ -18,7 +18,7 @@ https://github.com/gpii/universal/LICENSE.txt var path = require("path"), spawn = require("child_process").spawn, fluid = require("universal"), - jqUnit = fluid.require("jqUnit"); + jqUnit = fluid.require("node-jqunit"); require("../processesBridge.js"); fluid.require("gsettingsBridge", require); From 2bb6d6d44e987a440cb12a924d85e7c7d8527320 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Mon, 25 Jul 2016 16:42:01 -0400 Subject: [PATCH 56/78] GPII-442: Fixed "lint" errors in C++ file. Code style changes to follow the GPII C++ styles. --- .../nodeprocesses/nodeprocesses.cc | 84 +++++++++---------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses.cc b/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses.cc index d364739..00d5b36 100644 --- a/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses.cc +++ b/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses.cc @@ -43,8 +43,8 @@ const guint64 GET_ALL_ARGS = 0; const guint64 KERN_PROC_ALL_ARG = 0; static Handle -nanEncodeUtf8 (const char* string) { - return Nan::Encode (string, strlen (string), Nan::UTF8); +nanEncodeUtf8(const char* string) { + return Nan::Encode(string, strlen(string), Nan::UTF8); } @@ -53,66 +53,66 @@ nanEncodeUtf8 (const char* string) { // struct is truncated. The full name is in the process arguments vector. static Handle -get_process_name (const gchar *cmd, const char** argv) +get_process_name(const gchar *cmd, const char** argv) { char *basename = NULL; Handle procname; if (argv) { - // look for /usr/bin/very_long_name (argv[0]), or - // /usr/bin/interpreter /usr/.../very_long_name (argv[1]) + // look for /usr/bin/very_long_name(argv[0]), or + // /usr/bin/interpreter /usr/.../very_long_name(argv[1]) // which may have used prctl to alter 'cmd' name. for (int i = 0; i != 2 && argv[i]; i++) { - basename = g_path_get_basename (argv[i]); - if (g_str_has_prefix (basename, cmd)) { + basename = g_path_get_basename(argv[i]); + if (g_str_has_prefix(basename, cmd)) { break; } - g_free (basename); + g_free(basename); basename = NULL; } } if (basename != NULL) { - procname = nanEncodeUtf8 (basename); - g_free (basename); + procname = nanEncodeUtf8(basename); + g_free(basename); } else { - procname = nanEncodeUtf8 (cmd); + procname = nanEncodeUtf8(cmd); } return procname; } static Handle -format_process_state (guint state) +format_process_state(guint state) { Handle status; switch (state) { case GLIBTOP_PROCESS_RUNNING: - status = nanEncodeUtf8 (STATE_RUNNING); + status = nanEncodeUtf8(STATE_RUNNING); break; case GLIBTOP_PROCESS_STOPPED: - status = nanEncodeUtf8 (STATE_STOPPED); + status = nanEncodeUtf8(STATE_STOPPED); break; case GLIBTOP_PROCESS_ZOMBIE: - status =nanEncodeUtf8 (STATE_ZOMBIE); + status =nanEncodeUtf8(STATE_ZOMBIE); break; case GLIBTOP_PROCESS_UNINTERRUPTIBLE: - status = nanEncodeUtf8 (STATE_UNINTERRUPTIBLE); + status = nanEncodeUtf8(STATE_UNINTERRUPTIBLE); break; default: - status = nanEncodeUtf8 (STATE_SLEEPING); + status = nanEncodeUtf8(STATE_SLEEPING); break; } return status; } static Handle -makeProcInfo (pid_t pid) { +makeProcInfo(pid_t pid) { glibtop_proc_state procstate; glibtop_proc_args procargs; glibtop_proc_uid procuid; @@ -124,35 +124,35 @@ makeProcInfo (pid_t pid) { Handle arguments = Nan::New(); Handle procInfo = Nan::New(); - glibtop_get_proc_state (&procstate, pid); - glibtop_get_proc_uid (&procuid, pid); + glibtop_get_proc_state(&procstate, pid); + glibtop_get_proc_uid(&procuid, pid); // Get the argument vector of the process and store the arguments in a v8 // array. The first element in argv is usually (alas, not always) the // full path to the executable. Store that as a separate property. - argv = glibtop_get_proc_argv (&procargs, pid, GET_ALL_ARGS); + argv = glibtop_get_proc_argv(&procargs, pid, GET_ALL_ARGS); if (argv != NULL) { if (argv[0] != NULL) { - fullPath = nanEncodeUtf8 (argv[0]); + fullPath = nanEncodeUtf8(argv[0]); } for (int i = 0; argv[i]; i++) { - arguments->Set (i, nanEncodeUtf8 (argv[i])); + arguments->Set(i, nanEncodeUtf8(argv[i])); } } - procname = get_process_name (procstate.cmd, (const char**) argv); - procInfo->Set (nanEncodeUtf8 ("command"), procname); - procInfo->Set (nanEncodeUtf8 ("pid"), Nan::New (pid)); - procInfo->Set (nanEncodeUtf8 ("ppid"), Nan::New (procuid.ppid)); - procInfo->Set (nanEncodeUtf8 ("uid"), Nan::New (procuid.uid)); - procInfo->Set (nanEncodeUtf8 ("gid"), Nan::New (procuid.gid)); - procInfo->Set (nanEncodeUtf8 ("fullPath"), fullPath); - procInfo->Set (nanEncodeUtf8 ("argv"), arguments); - procInfo->Set (nanEncodeUtf8 ("state"), format_process_state (procstate.state)); + procname = get_process_name(procstate.cmd, (const char**) argv); + procInfo->Set(nanEncodeUtf8("command"), procname); + procInfo->Set(nanEncodeUtf8("pid"), Nan::New(pid)); + procInfo->Set(nanEncodeUtf8("ppid"), Nan::New(procuid.ppid)); + procInfo->Set(nanEncodeUtf8("uid"), Nan::New(procuid.uid)); + procInfo->Set(nanEncodeUtf8("gid"), Nan::New(procuid.gid)); + procInfo->Set(nanEncodeUtf8("fullPath"), fullPath); + procInfo->Set(nanEncodeUtf8("argv"), arguments); + procInfo->Set(nanEncodeUtf8("state"), format_process_state(procstate.state)); if (argv != NULL) - g_strfreev (argv); + g_strfreev(argv); - return (procInfo); + return procInfo; } /** @@ -166,17 +166,17 @@ NAN_METHOD(getProcesses) { glibtop_proclist procList; Handle procInfo; - pidArray = glibtop_get_proclist (&procList, GLIBTOP_KERN_PROC_ALL, KERN_PROC_ALL_ARG); + pidArray = glibtop_get_proclist(&procList, GLIBTOP_KERN_PROC_ALL, KERN_PROC_ALL_ARG); - Local result = Nan::New (procList.number); + Local result = Nan::New(procList.number); for (unsigned int i=0; iSet (i, procInfo); + procInfo = makeProcInfo(pidArray[i]); + result->Set(i, procInfo); } if (pidArray != NULL) - g_free (pidArray); + g_free(pidArray); - info.GetReturnValue().Set (result); + info.GetReturnValue().Set(result); } NAN_MODULE_INIT(init) { @@ -184,8 +184,8 @@ NAN_MODULE_INIT(init) { // and it returns a pointer to the glibtop structure. glibtopPtr = glibtop_init(); - Nan::Set (target, New("getProcesses").ToLocalChecked(), - GetFunction (New(getProcesses)).ToLocalChecked()); + Nan::Set(target, New("getProcesses").ToLocalChecked(), + GetFunction(New(getProcesses)).ToLocalChecked()); } NODE_MODULE(nodeprocesses, init) From 7def1b886e637c5acf6e816707ae86293a440205 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Tue, 26 Jul 2016 13:29:46 -0400 Subject: [PATCH 57/78] GPII-442/GPII-1848: Updated process reporter code. Fixed lint errors. --- gpii/node_modules/processReporter/index.js | 2 + .../nodeprocesses/nodeprocesses_test.js | 130 ++-- .../processReporter/processReporter.js | 85 ++- .../processReporter/processesBridge.js | 47 +- .../processReporter/processesBridgeDemo.js | 32 +- .../test/processesBridge_tests.js | 602 +++++++++--------- 6 files changed, 445 insertions(+), 453 deletions(-) diff --git a/gpii/node_modules/processReporter/index.js b/gpii/node_modules/processReporter/index.js index 571bd60..70bdf05 100644 --- a/gpii/node_modules/processReporter/index.js +++ b/gpii/node_modules/processReporter/index.js @@ -10,5 +10,7 @@ * https://github.com/gpii/universal/LICENSE.txt */ +"use strict"; + require("./processReporter.js"); diff --git a/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses_test.js b/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses_test.js index 983da3a..2f1aa2b 100644 --- a/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses_test.js +++ b/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses_test.js @@ -12,78 +12,76 @@ https://github.com/gpii/universal/LICENSE.txt /*global require*/ -(function () { - "use strict"; +"use strict"; - var path = require("path"), - fluid = require("universal"), - jqUnit = fluid.require("node-jqunit"), - nodeProcesses = require("./build/Release/nodeprocesses.node"); +var path = require("path"), + fluid = require("universal"), + jqUnit = fluid.require("node-jqunit"), + nodeProcesses = require("./build/Release/nodeprocesses.node"); - var procTests = fluid.registerNamespace("gpii.tests.processes"); +var procTests = fluid.registerNamespace("gpii.tests.processes"); - // Return the process info object that matches the given process id. - // Note that it can return "null" meaning there is no such process running. - procTests.matchProcByPid = function (pid, procArray) { - if (!procArray) { - procArray = nodeProcesses.getProcesses(); +// Return the process info object that matches the given process id. +// Note that it can return "null" meaning there is no such process running. +procTests.matchProcByPid = function (pid, procArray) { + if (!procArray) { + procArray = nodeProcesses.getProcesses(); + } + return fluid.find(procArray, function (procInfo) { + if (procInfo.pid === pid) { + return procInfo; } - return fluid.find(procArray, function (procInfo) { - if (procInfo.pid === pid) { - return procInfo; - } - }, null); - }; + }, null); +}; - jqUnit.module("Processes Bridge node add-on module"); +jqUnit.module("Processes Bridge node add-on module"); - jqUnit.test( - "Test getProceses() with 'node' (the nodejs process itself)", - function () { - var procInfos = nodeProcesses.getProcesses(); - jqUnit.assertNotEquals( - "Getting all processes", 0, procInfos.length - ); +jqUnit.test( +"Test getProceses() with 'node' (the nodejs process itself)", +function () { + var procInfos = nodeProcesses.getProcesses(); + jqUnit.assertNotEquals( + "Getting all processes", 0, procInfos.length + ); - // Check for the presence of this nodejs processs itself -- it must - // be in the process list since this code is running inside that - // process. - var nodeProcInfo = procTests.matchProcByPid(process.pid, procInfos); - jqUnit.assertNotNull("Searching for 'node' process", nodeProcInfo); - jqUnit.assertEquals("Node process 'name'", - process.title, nodeProcInfo.command - ); - // TODO: Redundant? This is how it was found. - jqUnit.assertEquals("Node process 'pid'", - process.pid, nodeProcInfo.pid - ); - jqUnit.assertEquals("Node process 'uid'", - process.getuid(), nodeProcInfo.uid - ); - jqUnit.assertEquals("Node process 'gid'", - process.getgid(), nodeProcInfo.gid - ); - jqUnit.assertEquals("Node process 'argv' length'", - process.argv.length, nodeProcInfo.argv.length - ); - jqUnit.assertEquals("Node process status", - "Running", nodeProcInfo.state - ); + // Check for the presence of this nodejs processs itself -- it must + // be in the process list since this code is running inside that + // process. + var nodeProcInfo = procTests.matchProcByPid(process.pid, procInfos); + jqUnit.assertNotNull("Searching for 'node' process", nodeProcInfo); + jqUnit.assertEquals("Node process 'name'", + process.title, nodeProcInfo.command + ); + // TODO: Redundant? This is how it was found. + jqUnit.assertEquals("Node process 'pid'", + process.pid, nodeProcInfo.pid + ); + jqUnit.assertEquals("Node process 'uid'", + process.getuid(), nodeProcInfo.uid + ); + jqUnit.assertEquals("Node process 'gid'", + process.getgid(), nodeProcInfo.gid + ); + jqUnit.assertEquals("Node process 'argv' length'", + process.argv.length, nodeProcInfo.argv.length + ); + jqUnit.assertEquals("Node process status", + "Running", nodeProcInfo.state + ); - // The "fullPath" property is added by the process node add-on. - // It should match the full path to process.title. - jqUnit.assertEquals("Node process fullPath", - path.resolve(process.title), - path.resolve(nodeProcInfo.fullPath) - ); + // The "fullPath" property is added by the process node add-on. + // It should match the full path to process.title. + jqUnit.assertEquals("Node process fullPath", + path.resolve(process.title), + path.resolve(nodeProcInfo.fullPath) + ); - // The order of process.argv is 'node', 'script file', and the rest. - // The order of nodeProcInfo.args is as the "user" typed it, where - // the first argument is the command. Hence, can only test that - // the first argument is the command in both cases. - jqUnit.assertEquals("Node process argv[0]", - path.basename(process.argv[0]), - path.basename(nodeProcInfo.argv[0]) - ); - }); -}()); + // The order of process.argv is 'node', 'script file', and the rest. + // The order of nodeProcInfo.args is as the "user" typed it, where + // the first argument is the command. Hence, can only test that + // the first argument is the command in both cases. + jqUnit.assertEquals("Node process argv[0]", + path.basename(process.argv[0]), + path.basename(nodeProcInfo.argv[0]) + ); +}); diff --git a/gpii/node_modules/processReporter/processReporter.js b/gpii/node_modules/processReporter/processReporter.js index 75163fb..d1bb206 100644 --- a/gpii/node_modules/processReporter/processReporter.js +++ b/gpii/node_modules/processReporter/processReporter.js @@ -10,48 +10,45 @@ * https://github.com/gpii/universal/LICENSE.txt */ -(function () { - "use strict"; - - var fluid = require("universal"); - var gpii = fluid.registerNamespace("gpii"); - require("./processesBridge.js"); - - var processes = gpii.processes(); - - fluid.require("gsettingsBridge", require); - var gsettings = fluid.registerNamespace("gpii.gsettings"); - - fluid.registerNamespace("gpii.processReporter"); - fluid.defaults("gpii.processReporter.find", { - gradeNames: "fluid.function", - argumentMap: { - command: 0, - schema: 1, // optional - setting: 2 // optional +"use strict"; + +var fluid = require("universal"); +var gpii = fluid.registerNamespace("gpii"); +require("./processesBridge.js"); + +var processes = gpii.processes(); + +fluid.require("gsettingsBridge", require); +var gsettings = fluid.registerNamespace("gpii.gsettings"); + +fluid.registerNamespace("gpii.processReporter"); +fluid.defaults("gpii.processReporter.find", { + gradeNames: "fluid.function", + argumentMap: { + command: 0, + schema: 1, // optional + setting: 2 // optional + } +}); + +// Search for the process using its command name, and, optionally, if the +// given GSetting is set. Returns a boolean indicating if the process is +// running (and if the setting is set). +gpii.processReporter.find = function (commandName, schema, setting) { + var running = false; + var procInfos = processes.findSolutionsByCommands([commandName]); + var theProcess = fluid.find(procInfos, function (aProcInfo) { + if (aProcInfo.uid === process.getuid()) { + return aProcInfo; } - }); - - // Search for the process using its command name, and, optionally, if the - // given GSetting is set. Returns a boolean indicating if the process is - // running (and if the setting is set). - gpii.processReporter.find = function (commandName, schema, setting) { - var running = false; - var procInfos = processes.findSolutionsByCommands([commandName]); - var theProcess = fluid.find(procInfos, function (aProcInfo) { - if (aProcInfo.uid === process.getuid()) { - return aProcInfo; - } - }, null); - if (theProcess !== null) { - running = processes.isRunning(theProcess.state); - } - - // Check GSetting as neccessary. - if (!!schema && !!setting) { - running = (running && gsettings.getSingleKey(schema, setting)); - } - return running; - }; - -})(); + }, null); + if (theProcess !== null) { + running = processes.isRunning(theProcess.state); + } + + // Check GSetting as neccessary. + if (!!schema && !!setting) { + running = (running && gsettings.getSingleKey(schema, setting)); + } + return running; +}; diff --git a/gpii/node_modules/processReporter/processesBridge.js b/gpii/node_modules/processReporter/processesBridge.js index c589c5c..8add9b5 100644 --- a/gpii/node_modules/processReporter/processesBridge.js +++ b/gpii/node_modules/processReporter/processesBridge.js @@ -12,29 +12,26 @@ https://github.com/gpii/universal/LICENSE.txt /*global require */ -(function () { - "use strict"; - - var fluid = require("universal"); - var gpii = fluid.registerNamespace("gpii"); - var nodeProcesses = - require("./nodeprocesses/build/Release/nodeprocesses.node"); - - gpii.processes = fluid.registerNamespace("gpii.processes"); - - fluid.defaults("gpii.processes.native", { - gradeNames: ["fluid.component"], - invokers: { - getProcessList: { - funcName: "gpii.processes.native.getProcessList", - args: [] - } +"use strict"; + +var fluid = require("universal"); +var gpii = fluid.registerNamespace("gpii"); +var nodeProcesses = + require("./nodeprocesses/build/Release/nodeprocesses.node"); + +gpii.processes = fluid.registerNamespace("gpii.processes"); + +fluid.defaults("gpii.processes.native", { + gradeNames: ["fluid.component"], + invokers: { + getProcessList: { + funcName: "gpii.processes.native.getProcessList", + args: [] } - }); - - // Return a list of processes -- a snapshot of the current processes. - gpii.processes["native"].getProcessList = function () { - return nodeProcesses.getProcesses(); - }; - -}()); + } +}); + +// Return a list of processes -- a snapshot of the current processes. +gpii.processes["native"].getProcessList = function () { + return nodeProcesses.getProcesses(); +}; diff --git a/gpii/node_modules/processReporter/processesBridgeDemo.js b/gpii/node_modules/processReporter/processesBridgeDemo.js index 3c41b08..cad5317 100644 --- a/gpii/node_modules/processReporter/processesBridgeDemo.js +++ b/gpii/node_modules/processReporter/processesBridgeDemo.js @@ -71,22 +71,22 @@ seekInput.prompt(); seekInput.on("line", function (answer) { console.log("You said " + answer); switch (answer.trim()) { - case "yes": - console.log("Okay, stopping"); - - // Cease periodic check of orca's state. - processesBridge.stopTrackingRunState( - runStateChangeHandler, states.trackRunState - ); - processesBridge.stopTrackingState( - stateChangeHandler, states.trackState - ); - seekInput.close(); - break; - - default: - console.log("Okay, continuing"); - break; + case "yes": + console.log("Okay, stopping"); + + // Cease periodic check of orca's state. + processesBridge.stopTrackingRunState( + runStateChangeHandler, states.trackRunState + ); + processesBridge.stopTrackingState( + stateChangeHandler, states.trackState + ); + seekInput.close(); + break; + + default: + console.log("Okay, continuing"); + break; } seekInput.prompt(); }).on("close", function () { diff --git a/gpii/node_modules/processReporter/test/processesBridge_tests.js b/gpii/node_modules/processReporter/test/processesBridge_tests.js index 9be515f..6258e26 100644 --- a/gpii/node_modules/processReporter/test/processesBridge_tests.js +++ b/gpii/node_modules/processReporter/test/processesBridge_tests.js @@ -12,314 +12,312 @@ https://github.com/gpii/universal/LICENSE.txt /*global require*/ -(function () { - "use strict"; - - var path = require("path"), - spawn = require("child_process").spawn, - fluid = require("universal"), - jqUnit = fluid.require("node-jqunit"); - - require("../processesBridge.js"); - fluid.require("gsettingsBridge", require); - var gsettings = fluid.registerNamespace("gpii.gsettings"); - var processesBridge = fluid.registerNamespace("gpii.processes"); - var procTests = fluid.registerNamespace("gpii.tests.processes"); - - // Delay 5 seconds. - procTests.wait5sec = function () { - var t0 = Date.now(); - var longEnough = false; - while (!longEnough) { - longEnough = ((Date.now() - t0) > 5000); - } - }; - - jqUnit.module("Processes Bridge node add-on module"); - jqUnit.test( - "Test getProceses()/findProcessByPid() with the nodejs process itself", - function () { - var procInfos = processesBridge["native"].getProcessList(); - jqUnit.assertNotEquals( - "Listing all processes", 0, procInfos.length - ); - - // Check for the presence of this nodejs processs itself -- it must - // be in the process list since this code is running inside that - // process. - var nodeProc = processesBridge.findProcessByPid(process.pid, procInfos); - jqUnit.assertNotNull("Searching for 'node' process", nodeProc); - } - ); - - jqUnit.test( - "Test findProcessByPid() with non-running process id", - function () { - jqUnit.assertNull( - "Search negative process id value", processesBridge.findProcessByPid(-1) - ); - } - ); - - jqUnit.test( - "Test findProcessByPid() against nodejs's own process object.", - function () { - var nodeProcInfo = processesBridge.findProcessByPid(process.pid); - jqUnit.assertEquals("Node process 'name'", - process.title, nodeProcInfo.command); - - // Redundant? This is how it was found. - jqUnit.assertEquals("Node process 'pid'", - process.pid, nodeProcInfo.pid); - - jqUnit.assertEquals("Node process 'uid'", - process.getuid(), nodeProcInfo.uid); - - jqUnit.assertEquals("Node process 'gid'", - process.getgid(), nodeProcInfo.gid); - - jqUnit.assertEquals("Node process 'argv' length'", - process.argv.length, nodeProcInfo.argv.length); - - jqUnit.assertEquals("Node process status", - "Running", nodeProcInfo.state); - - // The "fullPath" property is added by the process node add-on. - // It should match the full path to process.title. - jqUnit.assertEquals("Node process fullPath", - path.resolve(process.title), - path.resolve(nodeProcInfo.fullPath) - ); - - // The order of process.argv and nodeProcInfo.argv is not - // necessarily the same, nor are the number of arguments the same. - // Only the first argument of vectors match as the name of the - // process (here "node"). Hence, can only test that the first - // argument is the command in both cases. - jqUnit.assertEquals("Node process argv[0]", - path.basename(process.argv[0]), - path.basename(nodeProcInfo.argv[0]) - ); - } - ); - - jqUnit.test( - "Test findProcessesByCmd()/findFirstProcessByCmd() with nodejs itself", - function () { - var nodeProcInfos = processesBridge.findProcessesByCommand("node"); - jqUnit.assertNotEquals( - "Getting all 'node' processes", 0, nodeProcInfos.length - ); - nodeProcInfos.forEach(function (aProcInfo) { - jqUnit.assertEquals( - "Node commmand name", "node", aProcInfo.command - ); - }); - var procInfo = processesBridge.findFirstProcessByCommand("node"); - jqUnit.assertNotNull( - "Looking for first 'node' processes", procInfo); - jqUnit.assertEquals("Node commmand name", "node", procInfo.command); - } - ); - - jqUnit.test( - "Test initProcInfoNotRunning()", - function () { - var notRunning = processesBridge.initProcInfoNotRunning("grep"); - jqUnit.assertEquals("Command name", notRunning.command, "grep"); - jqUnit.assertEquals("Negative process id", notRunning.pid, -1); +"use strict"; + +var path = require("path"), + spawn = require("child_process").spawn, + fluid = require("universal"), + jqUnit = fluid.require("node-jqunit"); + +require("../processesBridge.js"); +fluid.require("gsettingsBridge", require); +var gsettings = fluid.registerNamespace("gpii.gsettings"); +var processesBridge = fluid.registerNamespace("gpii.processes"); +var procTests = fluid.registerNamespace("gpii.tests.processes"); + +// Delay 5 seconds. +procTests.wait5sec = function () { + var t0 = Date.now(); + var longEnough = false; + while (!longEnough) { + longEnough = ((Date.now() - t0) > 5000); + } +}; + +jqUnit.module("Processes Bridge node add-on module"); +jqUnit.test( + "Test getProceses()/findProcessByPid() with the nodejs process itself", + function () { + var procInfos = processesBridge["native"].getProcessList(); + jqUnit.assertNotEquals( + "Listing all processes", 0, procInfos.length + ); + + // Check for the presence of this nodejs processs itself -- it must + // be in the process list since this code is running inside that + // process. + var nodeProc = processesBridge.findProcessByPid(process.pid, procInfos); + jqUnit.assertNotNull("Searching for 'node' process", nodeProc); + } +); + +jqUnit.test( + "Test findProcessByPid() with non-running process id", + function () { + jqUnit.assertNull( + "Search negative process id value", processesBridge.findProcessByPid(-1) + ); + } +); + +jqUnit.test( + "Test findProcessByPid() against nodejs's own process object.", + function () { + var nodeProcInfo = processesBridge.findProcessByPid(process.pid); + jqUnit.assertEquals("Node process 'name'", + process.title, nodeProcInfo.command); + + // Redundant? This is how it was found. + jqUnit.assertEquals("Node process 'pid'", + process.pid, nodeProcInfo.pid); + + jqUnit.assertEquals("Node process 'uid'", + process.getuid(), nodeProcInfo.uid); + + jqUnit.assertEquals("Node process 'gid'", + process.getgid(), nodeProcInfo.gid); + + jqUnit.assertEquals("Node process 'argv' length'", + process.argv.length, nodeProcInfo.argv.length); + + jqUnit.assertEquals("Node process status", + "Running", nodeProcInfo.state); + + // The "fullPath" property is added by the process node add-on. + // It should match the full path to process.title. + jqUnit.assertEquals("Node process fullPath", + path.resolve(process.title), + path.resolve(nodeProcInfo.fullPath) + ); + + // The order of process.argv and nodeProcInfo.argv is not + // necessarily the same, nor are the number of arguments the same. + // Only the first argument of vectors match as the name of the + // process (here "node"). Hence, can only test that the first + // argument is the command in both cases. + jqUnit.assertEquals("Node process argv[0]", + path.basename(process.argv[0]), + path.basename(nodeProcInfo.argv[0]) + ); + } +); + +jqUnit.test( + "Test findProcessesByCmd()/findFirstProcessByCmd() with nodejs itself", + function () { + var nodeProcInfos = processesBridge.findProcessesByCommand("node"); + jqUnit.assertNotEquals( + "Getting all 'node' processes", 0, nodeProcInfos.length + ); + nodeProcInfos.forEach(function (aProcInfo) { jqUnit.assertEquals( - "'NoSuchProcess' state", notRunning.state, "NoSuchProcess" - ); - jqUnit.assertNull( - "Search negative process id value", - processesBridge.findProcessByPid(notRunning.pid) + "Node commmand name", "node", aProcInfo.command ); - } - ); - - jqUnit.test( - "Test isRunning() with nodejs itself, and nonexistent process", - function () { - var procInfo = processesBridge.findProcessByPid(process.pid); - jqUnit.assertNotNull("Searching for 'node' process", procInfo); - jqUnit.assertTrue( - "Check nodejs is running", - processesBridge.isRunning(procInfo.state) - ); - procInfo = processesBridge.initProcInfoNotRunning("grep"); - jqUnit.assertFalse( - "Check nonexistent process running", - processesBridge.isRunning(procInfo) - ); - } - ); - - jqUnit.test( - "Test updateProcInfo() against non-changing process", - function () { - var procInfo = processesBridge.findProcessByPid(process.pid); - jqUnit.assertNotNull("Looking for 'node' processes", procInfo); - var newProcInfo = processesBridge.updateProcInfo(procInfo); - jqUnit.assertDeepEq( - "Check change in process info", procInfo, newProcInfo - ); - } - ); - - jqUnit.test( - "Test updateProcInfo() against changing process", - function () { - var grep = spawn("grep", ["ssh"]); - var grepInfo = processesBridge.findProcessByPid(grep.pid); - jqUnit.assertNotNull("Search 'grep' process", grepInfo); - jqUnit.assertTrue("Stop grep", grep.kill("SIGHUP")); - var newGrepInfo = processesBridge.updateProcInfo(grepInfo); - jqUnit.assertNotEquals( - "Update process state", newGrepInfo.state, grepInfo.state - ); - } - ); - - jqUnit.test( - "Test hasStateChanged()", - function () { - jqUnit.assertFalse( - "Check null monitor", processesBridge.hasStateChanged(null) - ); - var catMonitor = processesBridge.initMonitor(null); - jqUnit.assertFalse( - "Check null process", - processesBridge.hasStateChanged(catMonitor) - ); - var catProcInfo = processesBridge.initProcInfoNotRunning("cat"); - catMonitor = processesBridge.initMonitor(catProcInfo); - var stateChanged = processesBridge.hasStateChanged(catMonitor); - jqUnit.assertFalse("Check non-running process", stateChanged); - - var cat = spawn("cat"); - catMonitor = processesBridge.initMonitor(catProcInfo); - stateChanged = processesBridge.hasStateChanged(catMonitor); - jqUnit.assertTrue("Check running process", stateChanged); - - // Get the running process info, kill cat, and check again. - catProcInfo = processesBridge.findProcessByPid(cat.pid); - catMonitor = processesBridge.initMonitor(catProcInfo); - cat.kill("SIGHUP"); - stateChanged = processesBridge.hasStateChanged(catMonitor); - jqUnit.assertTrue("Check stopped process", stateChanged); - } - ); - - jqUnit.test( - "Test hasSwitchedRunState()", - function () { - jqUnit.assertFalse( - "Check null monitor", processesBridge.hasSwitchedRunState(null) - ); - var grepProcMonitor = processesBridge.initMonitor(null); - jqUnit.assertFalse( - "Check null process", - processesBridge.hasSwitchedRunState(grepProcMonitor) - ); - var grep = spawn("grep", ["ssh"]); - var grepProcInfo = processesBridge.findProcessByPid(grep.pid); - grepProcMonitor = processesBridge.initMonitor(grepProcInfo); - var switched = processesBridge.hasSwitchedRunState(grepProcMonitor); - jqUnit.assertFalse("Check running process", switched); + }); + var procInfo = processesBridge.findFirstProcessByCommand("node"); + jqUnit.assertNotNull( + "Looking for first 'node' processes", procInfo); + jqUnit.assertEquals("Node commmand name", "node", procInfo.command); + } +); + +jqUnit.test( + "Test initProcInfoNotRunning()", + function () { + var notRunning = processesBridge.initProcInfoNotRunning("grep"); + jqUnit.assertEquals("Command name", notRunning.command, "grep"); + jqUnit.assertEquals("Negative process id", notRunning.pid, -1); + jqUnit.assertEquals( + "'NoSuchProcess' state", notRunning.state, "NoSuchProcess" + ); + jqUnit.assertNull( + "Search negative process id value", + processesBridge.findProcessByPid(notRunning.pid) + ); + } +); + +jqUnit.test( + "Test isRunning() with nodejs itself, and nonexistent process", + function () { + var procInfo = processesBridge.findProcessByPid(process.pid); + jqUnit.assertNotNull("Searching for 'node' process", procInfo); + jqUnit.assertTrue( + "Check nodejs is running", + processesBridge.isRunning(procInfo.state) + ); + procInfo = processesBridge.initProcInfoNotRunning("grep"); + jqUnit.assertFalse( + "Check nonexistent process running", + processesBridge.isRunning(procInfo) + ); + } +); + +jqUnit.test( + "Test updateProcInfo() against non-changing process", + function () { + var procInfo = processesBridge.findProcessByPid(process.pid); + jqUnit.assertNotNull("Looking for 'node' processes", procInfo); + var newProcInfo = processesBridge.updateProcInfo(procInfo); + jqUnit.assertDeepEq( + "Check change in process info", procInfo, newProcInfo + ); + } +); + +jqUnit.test( + "Test updateProcInfo() against changing process", + function () { + var grep = spawn("grep", ["ssh"]); + var grepInfo = processesBridge.findProcessByPid(grep.pid); + jqUnit.assertNotNull("Search 'grep' process", grepInfo); + jqUnit.assertTrue("Stop grep", grep.kill("SIGHUP")); + var newGrepInfo = processesBridge.updateProcInfo(grepInfo); + jqUnit.assertNotEquals( + "Update process state", newGrepInfo.state, grepInfo.state + ); + } +); + +jqUnit.test( + "Test hasStateChanged()", + function () { + jqUnit.assertFalse( + "Check null monitor", processesBridge.hasStateChanged(null) + ); + var catMonitor = processesBridge.initMonitor(null); + jqUnit.assertFalse( + "Check null process", + processesBridge.hasStateChanged(catMonitor) + ); + var catProcInfo = processesBridge.initProcInfoNotRunning("cat"); + catMonitor = processesBridge.initMonitor(catProcInfo); + var stateChanged = processesBridge.hasStateChanged(catMonitor); + jqUnit.assertFalse("Check non-running process", stateChanged); + + var cat = spawn("cat"); + catMonitor = processesBridge.initMonitor(catProcInfo); + stateChanged = processesBridge.hasStateChanged(catMonitor); + jqUnit.assertTrue("Check running process", stateChanged); + + // Get the running process info, kill cat, and check again. + catProcInfo = processesBridge.findProcessByPid(cat.pid); + catMonitor = processesBridge.initMonitor(catProcInfo); + cat.kill("SIGHUP"); + stateChanged = processesBridge.hasStateChanged(catMonitor); + jqUnit.assertTrue("Check stopped process", stateChanged); + } +); + +jqUnit.test( + "Test hasSwitchedRunState()", + function () { + jqUnit.assertFalse( + "Check null monitor", processesBridge.hasSwitchedRunState(null) + ); + var grepProcMonitor = processesBridge.initMonitor(null); + jqUnit.assertFalse( + "Check null process", + processesBridge.hasSwitchedRunState(grepProcMonitor) + ); + var grep = spawn("grep", ["ssh"]); + var grepProcInfo = processesBridge.findProcessByPid(grep.pid); + grepProcMonitor = processesBridge.initMonitor(grepProcInfo); + var switched = processesBridge.hasSwitchedRunState(grepProcMonitor); + jqUnit.assertFalse("Check running process", switched); + jqUnit.assertEquals( + "Process state change", + grepProcInfo.state, grepProcMonitor.newProcInfo.state + ); + // Kill grep, and check again. + grep.kill("SIGHUP"); + switched = processesBridge.hasSwitchedRunState(grepProcMonitor); + jqUnit.assertTrue("Check stopped process", switched); + jqUnit.assertNotEquals( + "Process state change", + grepProcInfo.state, grepProcMonitor.newProcInfo.state + ); + } +); + +jqUnit.test( + "Test findSolutionsByCommands()", + function () { + // Node is running. Add a running cat process. No such command as why. + var cat = spawn("cat"); + var solutions = ["node", "cat", "why"]; + var procInfos = processesBridge.findSolutionsByCommands(solutions); + jqUnit.assertTrue("Node and cat processes", procInfos.length >= 2); + procInfos.forEach(function (item) { + var isNode = item.command === "node"; + var isCat = item.command === "cat"; + jqUnit.assertTrue("Process name node nor cat", isNode || isCat); + }); + cat.kill("SIGHUP"); + } +); + +jqUnit.test( + "Test findSolutionsByPids()", + function () { + // Node is running. Add a running cat process. + var cat = spawn("cat"); + var pids = [process.pid, cat.pid]; + var procInfos = processesBridge.findSolutionsByPids(pids); + jqUnit.assertEquals("Node and cat processes", 2, procInfos.length); + procInfos.forEach(function (item) { + var isNode = item.pid === process.pid; + var isCat = item.pid === cat.pid; + jqUnit.assertTrue("Process pid node nor cat", isNode || isCat); + }); + cat.kill("SIGHUP"); + } +); + +// Test real life scenario: Use the GPII's gsettings bridge to launch +// and shut down orca, and track the changes in state. +jqUnit.test( + "Test gpii.processes against launching orca.", + function () { + var orcaProcInfo = processesBridge.findFirstProcessByCommand("orca"); + var wasRunning = (orcaProcInfo !== null); + // Start orca -- does nothing if orca is already running. + gsettings.setSingleKey( + "org.gnome.desktop.a11y.applications", + "screen-reader-enabled", true + ); + // Give orca some time to start and initialize itself. Then look + // for the 'orca' process. + procTests.wait5sec(); + orcaProcInfo = processesBridge.findFirstProcessByCommand("orca"); + jqUnit.assertNotNull("Start Orca", orcaProcInfo); + + // Quit orca, giving it some time to quit itself. Then look for the + // process whose id matches the formerly running 'orca' process. + gsettings.setSingleKey( + "org.gnome.desktop.a11y.applications", + "screen-reader-enabled", false + ); + procTests.wait5sec(); + if (orcaProcInfo !== null) { + var orcaProcNewState = + processesBridge.findProcessByPid(orcaProcInfo.pid); + jqUnit.assertNull("Stop Orca", orcaProcNewState); + var orcaMonitor = processesBridge.initMonitor(orcaProcInfo); + processesBridge.hasStateChanged(orcaMonitor); jqUnit.assertEquals( - "Process state change", - grepProcInfo.state, grepProcMonitor.newProcInfo.state + "Orca process changed state", "NoSuchProcess", + orcaMonitor.newProcInfo.state ); - // Kill grep, and check again. - grep.kill("SIGHUP"); - switched = processesBridge.hasSwitchedRunState(grepProcMonitor); - jqUnit.assertTrue("Check stopped process", switched); - jqUnit.assertNotEquals( - "Process state change", - grepProcInfo.state, grepProcMonitor.newProcInfo.state - ); - } - ); - - jqUnit.test( - "Test findSolutionsByCommands()", - function () { - // Node is running. Add a running cat process. No such command as why. - var cat = spawn("cat"); - var solutions = ["node", "cat", "why"]; - var procInfos = processesBridge.findSolutionsByCommands(solutions); - jqUnit.assertTrue("Node and cat processes", procInfos.length >= 2); - procInfos.forEach(function (item) { - var isNode = item.command === "node"; - var isCat = item.command === "cat"; - jqUnit.assertTrue("Process name node nor cat", isNode || isCat); - }); - cat.kill("SIGHUP"); - } - ); - - jqUnit.test( - "Test findSolutionsByPids()", - function () { - // Node is running. Add a running cat process. - var cat = spawn("cat"); - var pids = [process.pid, cat.pid]; - var procInfos = processesBridge.findSolutionsByPids(pids); - jqUnit.assertEquals("Node and cat processes", 2, procInfos.length); - procInfos.forEach(function (item) { - var isNode = item.pid === process.pid; - var isCat = item.pid === cat.pid; - jqUnit.assertTrue("Process pid node nor cat", isNode || isCat); - }); - cat.kill("SIGHUP"); } - ); - - // Test real life scenario: Use the GPII's gsettings bridge to launch - // and shut down orca, and track the changes in state. - jqUnit.test( - "Test gpii.processes against launching orca.", - function () { - var orcaProcInfo = processesBridge.findFirstProcessByCommand("orca"); - var wasRunning = (orcaProcInfo !== null); - // Start orca -- does nothing if orca is already running. - gsettings.setSingleKey( - "org.gnome.desktop.a11y.applications", - "screen-reader-enabled", true - ); - // Give orca some time to start and initialize itself. Then look - // for the 'orca' process. - procTests.wait5sec(); - orcaProcInfo = processesBridge.findFirstProcessByCommand("orca"); - jqUnit.assertNotNull("Start Orca", orcaProcInfo); - - // Quit orca, giving it some time to quit itself. Then look for the - // process whose id matches the formerly running 'orca' process. + // Clean up. + if (wasRunning) { gsettings.setSingleKey( - "org.gnome.desktop.a11y.applications", - "screen-reader-enabled", false + "org.gnome.desktop.a11y.applications", + "screen-reader-enabled", true ); - procTests.wait5sec(); - if (orcaProcInfo !== null) { - var orcaProcNewState = - processesBridge.findProcessByPid(orcaProcInfo.pid); - jqUnit.assertNull("Stop Orca", orcaProcNewState); - var orcaMonitor = processesBridge.initMonitor(orcaProcInfo); - processesBridge.hasStateChanged(orcaMonitor); - jqUnit.assertEquals( - "Orca process changed state", "NoSuchProcess", - orcaMonitor.newProcInfo.state - ); - } - // Clean up. - if (wasRunning) { - gsettings.setSingleKey( - "org.gnome.desktop.a11y.applications", - "screen-reader-enabled", true - ); - } } - ); -}()); + } +); From 2e66d0b668f9b85dcc6522cec760f1a1f9d7e90b Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Wed, 27 Jul 2016 16:49:15 -0400 Subject: [PATCH 58/78] GPII-442/GPII-1848: Updated process reporter package information. Modified the "dependencies" block to point to tip of my GPII-442 branch in universal. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f2f50ee..82a848c 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "bugs": "http://issues.gpii.net/browse/GPII", "homepage": "http://gpii.net/", "dependencies": { - "universal": "gpii/universal#98561d07c0b49d4d565be9027adebf36c1d1fe82" + "universal": "klown/universal#93591d8cc27a29a4885ebb9d5471987b655b41b3" }, "devDependencies": { "grunt": "1.0.1", From c1bd18b7a687fc5ea6074c3b3ceedea9a7a9c8e8 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Thu, 4 Aug 2016 10:45:56 -0400 Subject: [PATCH 59/78] GPII-442: Update to provisioning to include libgtop2 development. Modified vars.yml to include libgtop2-devel package for compiling the nodeprocesses.cc node add-on. --- provisioning/vars.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/provisioning/vars.yml b/provisioning/vars.yml index 779dd32..46253bf 100644 --- a/provisioning/vars.yml +++ b/provisioning/vars.yml @@ -35,6 +35,7 @@ nodejs_app_rpm_packages: - libstdc++-devel - libuv - libuv-devel + - libgtop2-devel nodejs_app_npm_packages: - node-gyp From 3ec8647bd1d7cb41607dd539f8bfc9164b411d5f Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Fri, 5 Aug 2016 15:09:32 -0400 Subject: [PATCH 60/78] GPII-442: Updated package information. Modified the "dependencies" block to point to tip of GPII-442 branch in universal. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 82a848c..8578d04 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "bugs": "http://issues.gpii.net/browse/GPII", "homepage": "http://gpii.net/", "dependencies": { - "universal": "klown/universal#93591d8cc27a29a4885ebb9d5471987b655b41b3" + "universal": "klown/universal#f14cf3c609a1f9c93935035b2016aa11bf57df24" }, "devDependencies": { "grunt": "1.0.1", From f2711fc3559b93d432604451edda54907f47d4b9 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Mon, 8 Aug 2016 16:08:03 -0400 Subject: [PATCH 61/78] GPII-442: Processes bridge unit tests. Removed orca start/stop test since it's really an integration test. Fixed race condition on the test case involving a 'grep' command. --- .../test/processesBridge_tests.js | 60 +++---------------- 1 file changed, 7 insertions(+), 53 deletions(-) diff --git a/gpii/node_modules/processReporter/test/processesBridge_tests.js b/gpii/node_modules/processReporter/test/processesBridge_tests.js index 6258e26..e99e2af 100644 --- a/gpii/node_modules/processReporter/test/processesBridge_tests.js +++ b/gpii/node_modules/processReporter/test/processesBridge_tests.js @@ -20,17 +20,14 @@ var path = require("path"), jqUnit = fluid.require("node-jqunit"); require("../processesBridge.js"); -fluid.require("gsettingsBridge", require); -var gsettings = fluid.registerNamespace("gpii.gsettings"); var processesBridge = fluid.registerNamespace("gpii.processes"); var procTests = fluid.registerNamespace("gpii.tests.processes"); -// Delay 5 seconds. -procTests.wait5sec = function () { +procTests.waitMsec = function (msec) { var t0 = Date.now(); var longEnough = false; while (!longEnough) { - longEnough = ((Date.now() - t0) > 5000); + longEnough = ((Date.now() - t0) > msec); } }; @@ -221,7 +218,10 @@ jqUnit.test( "Check null process", processesBridge.hasSwitchedRunState(grepProcMonitor) ); + // Spawn a "grep" process, and give it a little time to start up. var grep = spawn("grep", ["ssh"]); + procTests.waitMsec(500); + var grepProcInfo = processesBridge.findProcessByPid(grep.pid); grepProcMonitor = processesBridge.initMonitor(grepProcInfo); var switched = processesBridge.hasSwitchedRunState(grepProcMonitor); @@ -244,9 +244,9 @@ jqUnit.test( jqUnit.test( "Test findSolutionsByCommands()", function () { - // Node is running. Add a running cat process. No such command as why. + // Node is running. Add a running cat. No such command as T6y7u8i9. var cat = spawn("cat"); - var solutions = ["node", "cat", "why"]; + var solutions = ["node", "cat", "T6y7u8i9"]; var procInfos = processesBridge.findSolutionsByCommands(solutions); jqUnit.assertTrue("Node and cat processes", procInfos.length >= 2); procInfos.forEach(function (item) { @@ -275,49 +275,3 @@ jqUnit.test( } ); -// Test real life scenario: Use the GPII's gsettings bridge to launch -// and shut down orca, and track the changes in state. -jqUnit.test( - "Test gpii.processes against launching orca.", - function () { - var orcaProcInfo = processesBridge.findFirstProcessByCommand("orca"); - var wasRunning = (orcaProcInfo !== null); - // Start orca -- does nothing if orca is already running. - gsettings.setSingleKey( - "org.gnome.desktop.a11y.applications", - "screen-reader-enabled", true - ); - // Give orca some time to start and initialize itself. Then look - // for the 'orca' process. - procTests.wait5sec(); - orcaProcInfo = processesBridge.findFirstProcessByCommand("orca"); - jqUnit.assertNotNull("Start Orca", orcaProcInfo); - - // Quit orca, giving it some time to quit itself. Then look for the - // process whose id matches the formerly running 'orca' process. - gsettings.setSingleKey( - "org.gnome.desktop.a11y.applications", - "screen-reader-enabled", false - ); - procTests.wait5sec(); - if (orcaProcInfo !== null) { - var orcaProcNewState = - processesBridge.findProcessByPid(orcaProcInfo.pid); - jqUnit.assertNull("Stop Orca", orcaProcNewState); - var orcaMonitor = processesBridge.initMonitor(orcaProcInfo); - processesBridge.hasStateChanged(orcaMonitor); - jqUnit.assertEquals( - "Orca process changed state", "NoSuchProcess", - orcaMonitor.newProcInfo.state - ); - } - // Clean up. - if (wasRunning) { - gsettings.setSingleKey( - "org.gnome.desktop.a11y.applications", - "screen-reader-enabled", true - ); - } - } -); - From b8fa598130e5ef673a1e4e7c04eb7e340130e48e Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Fri, 12 Aug 2016 16:19:24 -0400 Subject: [PATCH 62/78] GPII-442: Update to latest processes bridge in universal. Point to the processes bridge component in universal. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8578d04..af54eb4 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "bugs": "http://issues.gpii.net/browse/GPII", "homepage": "http://gpii.net/", "dependencies": { - "universal": "klown/universal#f14cf3c609a1f9c93935035b2016aa11bf57df24" + "universal": "klown/universal#a84cb28ee6a71e899e66c710371cdd20128ed289" }, "devDependencies": { "grunt": "1.0.1", From 5b2f7193281618b0f444cd4f7e5362bf1233b776 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Thu, 1 Sep 2016 09:40:13 -0400 Subject: [PATCH 63/78] GPII-442: Updated package information. Modified the "dependencies" block to point to tip of GPII-442 branch in universal. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index af54eb4..f5cf381 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "bugs": "http://issues.gpii.net/browse/GPII", "homepage": "http://gpii.net/", "dependencies": { - "universal": "klown/universal#a84cb28ee6a71e899e66c710371cdd20128ed289" + "universal": "klown/universal#ba1fbb856ff9d7084185b745d149aface60c07d7" }, "devDependencies": { "grunt": "1.0.1", From 4aa7951c0371f16d46cb377cec22f0f41df96905 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Tue, 6 Sep 2016 10:33:50 -0400 Subject: [PATCH 64/78] GPII-442: Processe bridge state change tests. Added unit tests for the processes bridge functions that track changes in the state of the process (e.g., changing from "running" to "no such process"). --- .../processReporter/test/all-tests.js | 1 + .../test/processesBridge_stateChangeTests.js | 95 +++++++++++++++++++ tests/UnitTests.sh | 2 +- 3 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 gpii/node_modules/processReporter/test/processesBridge_stateChangeTests.js diff --git a/gpii/node_modules/processReporter/test/all-tests.js b/gpii/node_modules/processReporter/test/all-tests.js index 9f547c0..ecbec62 100644 --- a/gpii/node_modules/processReporter/test/all-tests.js +++ b/gpii/node_modules/processReporter/test/all-tests.js @@ -17,6 +17,7 @@ var fluid = require("universal"), kettle.loadTestingSupport(); var testIncludes = [ + "./processesBridge_stateChangeTests.js", "./processesBridge_tests.js", "./processReporterModuleTests.js" ]; diff --git a/gpii/node_modules/processReporter/test/processesBridge_stateChangeTests.js b/gpii/node_modules/processReporter/test/processesBridge_stateChangeTests.js new file mode 100644 index 0000000..dfe9ccc --- /dev/null +++ b/gpii/node_modules/processReporter/test/processesBridge_stateChangeTests.js @@ -0,0 +1,95 @@ +/*! +GPII Node.js Processes Bridge Unit Tests + +Copyright 2016 Inclusive Design Research Centre, OCAD University + +Licensed under the New BSD license. You may not use this file except in +compliance with this License. + +You may obtain a copy of the License at +https://github.com/gpii/universal/LICENSE.txt +*/ + +/*global require*/ + +"use strict"; + +var spawn = require("child_process").spawn, + fluid = require("universal"); + +require("../processesBridge.js"); +var gpii = fluid.registerNamespace("gpii"); +gpii.processes = fluid.registerNamespace("gpii.processes"); +var processesBridge = gpii.processes(); + +var procTests = fluid.registerNamespace("gpii.tests.processes"); + +// Handler to detect any change in state. +procTests.stateChangedHandler = function (oldProcInfo, newProcInfo) { + // Track until the state changes. + if (oldProcInfo.state !== newProcInfo.state) { + procTests.states.stateN = newProcInfo.state; + processesBridge.stopTrackingState( + procTests.stateChangedHandler, procTests.trackState + ); + } +}; + +// Handler to detect change from "not running" to "running", or "running" to +// "not running". +procTests.runStateChangedHandler = function (procInfo) { + // Track until the run state changes. + procTests.states.runN = processesBridge.isRunning(procInfo.state); + if (procTests.states.run0 !== procTests.states.runN) { + processesBridge.stopTrackingRunState( + procTests.runStateChangedHandler, procTests.trackRunState + ); + } +}; + +// Set up to track the "grep" application state. Start it here. +procTests.initStateTracking = function () { + var grepProcInfo = processesBridge.findFirstProcessByCommand("grep"); + if (grepProcInfo === null) { + grepProcInfo = processesBridge.initProcInfoNotRunning("grep"); + } + procTests.states = {}; + procTests.states.state0 = grepProcInfo.state; + procTests.states.stateN = procTests.states.state0; + procTests.states.run0 = processesBridge.isRunning(grepProcInfo.state); + procTests.states.runN = procTests.states.run0; + + procTests.trackState = processesBridge.trackState( + grepProcInfo, procTests.stateChangedHandler + ); + procTests.trackRunState = processesBridge.trackRunState( + grepProcInfo, procTests.runStateChangedHandler + ); +}; + +// Setup: start the tracking, then launch "grep". +procTests.initStateTracking(); +var grep = spawn("grep", ["ssh"]); + +// Wait a bit to allow the tracking functions to run, and then execute the +// tests. +setTimeout(function () { + var jqUnit = fluid.require("node-jqunit"); + jqUnit.module("Processes Bridge module (tracking states)"); + jqUnit.test( + "Test processes bridge tracking launching grep", + function () { + jqUnit.assertNotEquals("Process 'grep' state change", + procTests.states.state0, procTests.states.stateN + ); + jqUnit.assertFalse("Process 'grep' initial run state", + procTests.states.run0 + ); + jqUnit.assertTrue("Process 'grep' final run state", + procTests.states.runN + ); + grep.kill("SIGHUP"); + } + ); +}, 100); + diff --git a/tests/UnitTests.sh b/tests/UnitTests.sh index c087760..9f10a69 100755 --- a/tests/UnitTests.sh +++ b/tests/UnitTests.sh @@ -43,7 +43,7 @@ popd pushd . cd ../gpii/node_modules/processReporter/test/ -node processesBridge_tests.js +node ./all-tests.js cd ../nodeprocesses node nodeprocesses_test.js popd From 3497de7eb7ac93a57e764147e201ce33f6297c85 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Wed, 21 Sep 2016 11:11:36 -0400 Subject: [PATCH 65/78] GPII-442: Updated package information. Modified the "dependencies" block to point to tip of GPII-442 branch in universal. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f5cf381..69ee5c6 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "bugs": "http://issues.gpii.net/browse/GPII", "homepage": "http://gpii.net/", "dependencies": { - "universal": "klown/universal#ba1fbb856ff9d7084185b745d149aface60c07d7" + "universal": "klown/universal#a83cd1744329a8bfd487c21988f3d98970557ec0" }, "devDependencies": { "grunt": "1.0.1", From 0c792b7da97599409ce4c1d36a604e9a3b263d22 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Fri, 14 Oct 2016 15:55:07 -0400 Subject: [PATCH 66/78] GPII-442: Updated package information. Modified the "dependencies" block to point to tip of GPII-442 branch in universal. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 07ae4c5..3ec2cd3 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "bugs": "http://issues.gpii.net/browse/GPII", "homepage": "http://gpii.net/", "dependencies": { - "universal": "klown/universal#8120b2e812edb4cb342e30d538ca342585373cef" + "universal": "klown/universal#9570774f39fbef8f58b3cd2a0623dcdfa8ac5341" }, "devDependencies": { "grunt": "1.0.1", From 2b88c335306c31d7568c480fe1e5b0b2662f3ff4 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Thu, 27 Oct 2016 10:44:38 -0400 Subject: [PATCH 67/78] GPII-442: Updated package information. Modified the "dependencies" block: - in main package.json to point always to tip of GPII-442 branch in universal. - modifiled process reporter to depend on at least node 4.2.18. --- gpii/node_modules/processReporter/package.json | 2 +- package.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gpii/node_modules/processReporter/package.json b/gpii/node_modules/processReporter/package.json index a540d41..a17e890 100644 --- a/gpii/node_modules/processReporter/package.json +++ b/gpii/node_modules/processReporter/package.json @@ -15,5 +15,5 @@ "keywords": ["gpii", "accessibility", "processes", "fluid", "linux"], "repository": "git://github.com:GPII/linux.git", "main": "./index.js", - "engines": { "node" : ">=0.8" } + "engines": { "node" : ">=4.2.18" } } diff --git a/package.json b/package.json index 3ec2cd3..35f6fba 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "bugs": "http://issues.gpii.net/browse/GPII", "homepage": "http://gpii.net/", "dependencies": { - "universal": "klown/universal#9570774f39fbef8f58b3cd2a0623dcdfa8ac5341" + "universal": "klown/universal#GPII-442" }, "devDependencies": { "grunt": "1.0.1", @@ -29,6 +29,6 @@ "repository": "git://github.com/GPII/linux.git", "main": "./gpii/index.js", "engines": { - "node": ">=4.2.1" + "node": ">=4.2.18" } } From 42e05a3801671417c9a0b09022ae060a76206418 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Wed, 23 Nov 2016 11:27:09 -0500 Subject: [PATCH 68/78] GPII-442: Removed state tracking functionality from processesBridge. Reduced the functionality of the processesBridge component to only find solutions/processes, but no longer track their state. Moved the state tracking code to new branch GPII-442-trackState: (https://github.com/klown/linux/tree/GPII-442-trackState). --- .../processReporter/processesBridgeDemo.js | 94 ------------------ .../processReporter/test/all-tests.js | 1 - .../test/processesBridge_stateChangeTests.js | 95 ------------------- .../test/processesBridge_tests.js | 64 ------------- 4 files changed, 254 deletions(-) delete mode 100644 gpii/node_modules/processReporter/processesBridgeDemo.js delete mode 100644 gpii/node_modules/processReporter/test/processesBridge_stateChangeTests.js diff --git a/gpii/node_modules/processReporter/processesBridgeDemo.js b/gpii/node_modules/processReporter/processesBridgeDemo.js deleted file mode 100644 index cad5317..0000000 --- a/gpii/node_modules/processReporter/processesBridgeDemo.js +++ /dev/null @@ -1,94 +0,0 @@ -/*! -GPII Prcoess Reporter Demo. - -Copyright 2014 Inclusive Design Research Centre, OCAD University - -Licensed under the New BSD license. You may not use this file except in -compliance with this License. - -You may obtain a copy of the License at -https://github.com/gpii/universal/LICENSE.txt -*/ - -/*global require */ -"use strict"; - -var readline = require("readline"); -var fluid = require("universal"); -require("./processesBridge.js"); - -var gpii = fluid.registerNamespace("gpii"); -gpii.processesBridge = fluid.registerNamespace("gpii.processes"); -var processesBridge = gpii.processesBridge(); - -var seekInput = readline.createInterface({ - input: process.stdin, - output: process.stdout -}); - -// Handler for processes to use to detect change from "not running" to "running" -// or "running" to "not running". For this demo, just print the new run state -// on the console. -var runStateChangeHandler = function (procInfo) { - console.log( - procInfo.command + ": run state switched to " + procInfo.state + - "(" + - (processesBridge.isRunning(procInfo.state) ? "Running" : "Stopped") + - ")" - ); -}; - -// Handler to use to detect any change in state, and print to console. -var stateChangeHandler = function (oldProcInfo, newProcInfo) { - console.log( - oldProcInfo.command + " process state switched from " + - oldProcInfo.state + " to " + newProcInfo.state - ); -}; - - -// Initial assumption: not running. Then look for any running orca process. -var orcaProcInfo = processesBridge.initProcInfoNotRunning("orca"); -var orcaProcInfos = processesBridge.findProcessesByCommand("orca"); -if (orcaProcInfos.length > 0) { - orcaProcInfo = orcaProcInfos[0]; -} - -// Start the periodic check of the change in run-state for orca. -// To see any changes, startstop orca using, say, the accessibility menu, or -// the command line: -// gsettings set org.gnome.desktop.a11y.applications screen-reader-enabled true/false -var states = {}; -states.trackRunState = - processesBridge.trackRunState(orcaProcInfo, runStateChangeHandler); -states.trackState = - processesBridge.trackState(orcaProcInfo, stateChangeHandler); - -console.log("Waiting..."); - -seekInput.setPrompt("Stop? "); -seekInput.prompt(); -seekInput.on("line", function (answer) { - console.log("You said " + answer); - switch (answer.trim()) { - case "yes": - console.log("Okay, stopping"); - - // Cease periodic check of orca's state. - processesBridge.stopTrackingRunState( - runStateChangeHandler, states.trackRunState - ); - processesBridge.stopTrackingState( - stateChangeHandler, states.trackState - ); - seekInput.close(); - break; - - default: - console.log("Okay, continuing"); - break; - } - seekInput.prompt(); -}).on("close", function () { - process.exit(0); -}); diff --git a/gpii/node_modules/processReporter/test/all-tests.js b/gpii/node_modules/processReporter/test/all-tests.js index ecbec62..9f547c0 100644 --- a/gpii/node_modules/processReporter/test/all-tests.js +++ b/gpii/node_modules/processReporter/test/all-tests.js @@ -17,7 +17,6 @@ var fluid = require("universal"), kettle.loadTestingSupport(); var testIncludes = [ - "./processesBridge_stateChangeTests.js", "./processesBridge_tests.js", "./processReporterModuleTests.js" ]; diff --git a/gpii/node_modules/processReporter/test/processesBridge_stateChangeTests.js b/gpii/node_modules/processReporter/test/processesBridge_stateChangeTests.js deleted file mode 100644 index dfe9ccc..0000000 --- a/gpii/node_modules/processReporter/test/processesBridge_stateChangeTests.js +++ /dev/null @@ -1,95 +0,0 @@ -/*! -GPII Node.js Processes Bridge Unit Tests - -Copyright 2016 Inclusive Design Research Centre, OCAD University - -Licensed under the New BSD license. You may not use this file except in -compliance with this License. - -You may obtain a copy of the License at -https://github.com/gpii/universal/LICENSE.txt -*/ - -/*global require*/ - -"use strict"; - -var spawn = require("child_process").spawn, - fluid = require("universal"); - -require("../processesBridge.js"); -var gpii = fluid.registerNamespace("gpii"); -gpii.processes = fluid.registerNamespace("gpii.processes"); -var processesBridge = gpii.processes(); - -var procTests = fluid.registerNamespace("gpii.tests.processes"); - -// Handler to detect any change in state. -procTests.stateChangedHandler = function (oldProcInfo, newProcInfo) { - // Track until the state changes. - if (oldProcInfo.state !== newProcInfo.state) { - procTests.states.stateN = newProcInfo.state; - processesBridge.stopTrackingState( - procTests.stateChangedHandler, procTests.trackState - ); - } -}; - -// Handler to detect change from "not running" to "running", or "running" to -// "not running". -procTests.runStateChangedHandler = function (procInfo) { - // Track until the run state changes. - procTests.states.runN = processesBridge.isRunning(procInfo.state); - if (procTests.states.run0 !== procTests.states.runN) { - processesBridge.stopTrackingRunState( - procTests.runStateChangedHandler, procTests.trackRunState - ); - } -}; - -// Set up to track the "grep" application state. Start it here. -procTests.initStateTracking = function () { - var grepProcInfo = processesBridge.findFirstProcessByCommand("grep"); - if (grepProcInfo === null) { - grepProcInfo = processesBridge.initProcInfoNotRunning("grep"); - } - procTests.states = {}; - procTests.states.state0 = grepProcInfo.state; - procTests.states.stateN = procTests.states.state0; - procTests.states.run0 = processesBridge.isRunning(grepProcInfo.state); - procTests.states.runN = procTests.states.run0; - - procTests.trackState = processesBridge.trackState( - grepProcInfo, procTests.stateChangedHandler - ); - procTests.trackRunState = processesBridge.trackRunState( - grepProcInfo, procTests.runStateChangedHandler - ); -}; - -// Setup: start the tracking, then launch "grep". -procTests.initStateTracking(); -var grep = spawn("grep", ["ssh"]); - -// Wait a bit to allow the tracking functions to run, and then execute the -// tests. -setTimeout(function () { - var jqUnit = fluid.require("node-jqunit"); - jqUnit.module("Processes Bridge module (tracking states)"); - jqUnit.test( - "Test processes bridge tracking launching grep", - function () { - jqUnit.assertNotEquals("Process 'grep' state change", - procTests.states.state0, procTests.states.stateN - ); - jqUnit.assertFalse("Process 'grep' initial run state", - procTests.states.run0 - ); - jqUnit.assertTrue("Process 'grep' final run state", - procTests.states.runN - ); - grep.kill("SIGHUP"); - } - ); -}, 100); - diff --git a/gpii/node_modules/processReporter/test/processesBridge_tests.js b/gpii/node_modules/processReporter/test/processesBridge_tests.js index e99e2af..bcbc6f5 100644 --- a/gpii/node_modules/processReporter/test/processesBridge_tests.js +++ b/gpii/node_modules/processReporter/test/processesBridge_tests.js @@ -177,70 +177,6 @@ jqUnit.test( } ); -jqUnit.test( - "Test hasStateChanged()", - function () { - jqUnit.assertFalse( - "Check null monitor", processesBridge.hasStateChanged(null) - ); - var catMonitor = processesBridge.initMonitor(null); - jqUnit.assertFalse( - "Check null process", - processesBridge.hasStateChanged(catMonitor) - ); - var catProcInfo = processesBridge.initProcInfoNotRunning("cat"); - catMonitor = processesBridge.initMonitor(catProcInfo); - var stateChanged = processesBridge.hasStateChanged(catMonitor); - jqUnit.assertFalse("Check non-running process", stateChanged); - - var cat = spawn("cat"); - catMonitor = processesBridge.initMonitor(catProcInfo); - stateChanged = processesBridge.hasStateChanged(catMonitor); - jqUnit.assertTrue("Check running process", stateChanged); - - // Get the running process info, kill cat, and check again. - catProcInfo = processesBridge.findProcessByPid(cat.pid); - catMonitor = processesBridge.initMonitor(catProcInfo); - cat.kill("SIGHUP"); - stateChanged = processesBridge.hasStateChanged(catMonitor); - jqUnit.assertTrue("Check stopped process", stateChanged); - } -); - -jqUnit.test( - "Test hasSwitchedRunState()", - function () { - jqUnit.assertFalse( - "Check null monitor", processesBridge.hasSwitchedRunState(null) - ); - var grepProcMonitor = processesBridge.initMonitor(null); - jqUnit.assertFalse( - "Check null process", - processesBridge.hasSwitchedRunState(grepProcMonitor) - ); - // Spawn a "grep" process, and give it a little time to start up. - var grep = spawn("grep", ["ssh"]); - procTests.waitMsec(500); - - var grepProcInfo = processesBridge.findProcessByPid(grep.pid); - grepProcMonitor = processesBridge.initMonitor(grepProcInfo); - var switched = processesBridge.hasSwitchedRunState(grepProcMonitor); - jqUnit.assertFalse("Check running process", switched); - jqUnit.assertEquals( - "Process state change", - grepProcInfo.state, grepProcMonitor.newProcInfo.state - ); - // Kill grep, and check again. - grep.kill("SIGHUP"); - switched = processesBridge.hasSwitchedRunState(grepProcMonitor); - jqUnit.assertTrue("Check stopped process", switched); - jqUnit.assertNotEquals( - "Process state change", - grepProcInfo.state, grepProcMonitor.newProcInfo.state - ); - } -); - jqUnit.test( "Test findSolutionsByCommands()", function () { From 075b8e7a714005bf9c0e65a3b4f1a39d83b1304d Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Mon, 12 Dec 2016 14:15:32 -0500 Subject: [PATCH 69/78] GPII-442: Separated functions for finding process and checking settings. Refactored the dual functionality of process finding and settings checking implemented in find() into a find() and a checkSetting(). --- .../processReporter/processReporter.js | 32 +++++++++++++------ .../test/processReporterModuleTests.js | 14 ++++++-- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/gpii/node_modules/processReporter/processReporter.js b/gpii/node_modules/processReporter/processReporter.js index d1bb206..0b9accd 100644 --- a/gpii/node_modules/processReporter/processReporter.js +++ b/gpii/node_modules/processReporter/processReporter.js @@ -25,16 +25,21 @@ fluid.registerNamespace("gpii.processReporter"); fluid.defaults("gpii.processReporter.find", { gradeNames: "fluid.function", argumentMap: { - command: 0, - schema: 1, // optional - setting: 2 // optional + command: 0 } }); -// Search for the process using its command name, and, optionally, if the -// given GSetting is set. Returns a boolean indicating if the process is -// running (and if the setting is set). -gpii.processReporter.find = function (commandName, schema, setting) { +fluid.defaults("gpii.processReporter.checkSetting", { + gradeNames: "fluid.function", + argumentMap: { + schema: 0, + setting: 1 + } +}); + +// Search for the process using its command name. Returns a boolean indicating +// if the process is running. +gpii.processReporter.find = function (commandName) { var running = false; var procInfos = processes.findSolutionsByCommands([commandName]); var theProcess = fluid.find(procInfos, function (aProcInfo) { @@ -42,13 +47,20 @@ gpii.processReporter.find = function (commandName, schema, setting) { return aProcInfo; } }, null); + if (theProcess !== null) { running = processes.isRunning(theProcess.state); } + return running; +}; - // Check GSetting as neccessary. - if (!!schema && !!setting) { - running = (running && gsettings.getSingleKey(schema, setting)); +// Check if the given GSetting is set. Returns a boolean indicating whether the +// setting is set. +gpii.processReporter.checkSetting = function (schema, setting) { + var running = false; + if (schema && setting) { + running = !!gsettings.getSingleKey(schema, setting); } return running; }; + diff --git a/gpii/node_modules/processReporter/test/processReporterModuleTests.js b/gpii/node_modules/processReporter/test/processReporterModuleTests.js index d0962c0..0520aa0 100644 --- a/gpii/node_modules/processReporter/test/processReporterModuleTests.js +++ b/gpii/node_modules/processReporter/test/processReporterModuleTests.js @@ -22,16 +22,15 @@ var processReporter = fluid.registerNamespace("gpii.processReporter"); jqUnit.module("GPII Linux ProcessReporter Module"); jqUnit.test("Running tests for Linux/GNOME Process Reporter", function () { - jqUnit.expect(4); + jqUnit.expect(6); // Check that the bridge is loaded and required methods are available // - var methods = ["find"]; + var methods = ["find", "checkSetting"]; for (var method in methods) { jqUnit.assertTrue("Checking availability of method '" + method + "'", (methods[method] in processReporter)); } - // This is running inside 'node' itself, so the uid matches. jqUnit.assertTrue("Checking run-status of process 'node'", gpii.processReporter.find("node")); @@ -43,4 +42,13 @@ jqUnit.test("Running tests for Linux/GNOME Process Reporter", function () { // There is likely a 'gdm' process, but its uid is not us. jqUnit.assertFalse("Checking run-status of un-owned 'gdm' process", gpii.processReporter.find("gdm")); + + // Unknown what the status of a given setting is, but checkSetting() should + // always return a boolean value. + jqUnit.assertEquals("Checking retrieval of a setting", + typeof true, + typeof gpii.processReporter.checkSetting( + "org.gnome.desktop.a11y.applications", + "screen-magnifier-enabled" + )); }); From f41d9d43c505877b2629f5313404e9eb21ad5325 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Thu, 15 Dec 2016 16:54:00 -0500 Subject: [PATCH 70/78] GPII-442: Generalized checkSetting() Modified checking the setting to match the required value of the setting. --- .../processReporter/processReporter.js | 11 +++--- .../test/processReporterModuleTests.js | 36 +++++++++++++++---- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/gpii/node_modules/processReporter/processReporter.js b/gpii/node_modules/processReporter/processReporter.js index 0b9accd..7e0d018 100644 --- a/gpii/node_modules/processReporter/processReporter.js +++ b/gpii/node_modules/processReporter/processReporter.js @@ -33,7 +33,8 @@ fluid.defaults("gpii.processReporter.checkSetting", { gradeNames: "fluid.function", argumentMap: { schema: 0, - setting: 1 + setting: 1, + value: 2 } }); @@ -56,11 +57,11 @@ gpii.processReporter.find = function (commandName) { // Check if the given GSetting is set. Returns a boolean indicating whether the // setting is set. -gpii.processReporter.checkSetting = function (schema, setting) { - var running = false; +gpii.processReporter.checkSetting = function (schema, setting, value) { + var actualValue = undefined; if (schema && setting) { - running = !!gsettings.getSingleKey(schema, setting); + actualValue = gsettings.getSingleKey(schema, setting); } - return running; + return value === actualValue; }; diff --git a/gpii/node_modules/processReporter/test/processReporterModuleTests.js b/gpii/node_modules/processReporter/test/processReporterModuleTests.js index 0520aa0..ba064ba 100644 --- a/gpii/node_modules/processReporter/test/processReporterModuleTests.js +++ b/gpii/node_modules/processReporter/test/processReporterModuleTests.js @@ -19,10 +19,13 @@ require("processReporter"); var gpii = fluid.registerNamespace("gpii"); var processReporter = fluid.registerNamespace("gpii.processReporter"); +fluid.require("gsettingsBridge", require); +var gsettings = fluid.registerNamespace("gpii.gsettings"); + jqUnit.module("GPII Linux ProcessReporter Module"); jqUnit.test("Running tests for Linux/GNOME Process Reporter", function () { - jqUnit.expect(6); + jqUnit.expect(8); // Check that the bridge is loaded and required methods are available // @@ -45,10 +48,29 @@ jqUnit.test("Running tests for Linux/GNOME Process Reporter", function () { // Unknown what the status of a given setting is, but checkSetting() should // always return a boolean value. - jqUnit.assertEquals("Checking retrieval of a setting", - typeof true, - typeof gpii.processReporter.checkSetting( - "org.gnome.desktop.a11y.applications", - "screen-magnifier-enabled" - )); + var aValue = gsettings.getSingleKey( + "org.gnome.desktop.a11y.applications", "screen-magnifier-enabled" + ); + jqUnit.assertTrue("Checking retrieval of a boolean setting", + gpii.processReporter.checkSetting( + "org.gnome.desktop.a11y.applications", + "screen-magnifier-enabled", + aValue) + ); + aValue = gsettings.getSingleKey( + "org.gnome.desktop.a11y.magnifier", "mag-factor" + ); + jqUnit.assertTrue("Checking retrieval of a numeric setting", + gpii.processReporter.checkSetting( + "org.gnome.desktop.a11y.magnifier", + "mag-factor", + aValue) + ); + aValue = "foobar"; + jqUnit.assertFalse("Checking retrieval of a non-existent setting", + gpii.processReporter.checkSetting( + "org.gnome.desktop.a11y.applications", + "screen-magnifier-enabled", + aValue) + ); }); From b5b6f038b216c346ae6fb6f0a1ae5d5b82db6089 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Mon, 24 Jul 2017 16:25:02 -0400 Subject: [PATCH 71/78] GPII-442: Modified processes bridge. Updated bridge and reporter due to modifications in the universal branch. --- .../processReporter/processReporter.js | 6 +++--- .../processReporter/processesBridge.js | 15 +++++++-------- .../test/processesBridge_tests.js | 16 ++++------------ 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/gpii/node_modules/processReporter/processReporter.js b/gpii/node_modules/processReporter/processReporter.js index 7e0d018..803d693 100644 --- a/gpii/node_modules/processReporter/processReporter.js +++ b/gpii/node_modules/processReporter/processReporter.js @@ -16,7 +16,7 @@ var fluid = require("universal"); var gpii = fluid.registerNamespace("gpii"); require("./processesBridge.js"); -var processes = gpii.processes(); +var processesBridge = gpii.processes.linux(); fluid.require("gsettingsBridge", require); var gsettings = fluid.registerNamespace("gpii.gsettings"); @@ -42,7 +42,7 @@ fluid.defaults("gpii.processReporter.checkSetting", { // if the process is running. gpii.processReporter.find = function (commandName) { var running = false; - var procInfos = processes.findSolutionsByCommands([commandName]); + var procInfos = processesBridge.findSolutionsByCommands([commandName]); var theProcess = fluid.find(procInfos, function (aProcInfo) { if (aProcInfo.uid === process.getuid()) { return aProcInfo; @@ -50,7 +50,7 @@ gpii.processReporter.find = function (commandName) { }, null); if (theProcess !== null) { - running = processes.isRunning(theProcess.state); + running = processesBridge.isRunning(theProcess.state); } return running; }; diff --git a/gpii/node_modules/processReporter/processesBridge.js b/gpii/node_modules/processReporter/processesBridge.js index 8add9b5..8b7f634 100644 --- a/gpii/node_modules/processReporter/processesBridge.js +++ b/gpii/node_modules/processReporter/processesBridge.js @@ -1,7 +1,7 @@ /*! GPII Process Reporter processes bridge -- gpii.processes. -Copyright 2014-2016 Inclusive Design Research Centre, OCAD University +Copyright 2014-2017 Inclusive Design Research Centre, OCAD University Licensed under the New BSD license. You may not use this file except in compliance with this License. @@ -16,22 +16,21 @@ https://github.com/gpii/universal/LICENSE.txt var fluid = require("universal"); var gpii = fluid.registerNamespace("gpii"); -var nodeProcesses = - require("./nodeprocesses/build/Release/nodeprocesses.node"); +var nodeProcesses = require("./nodeprocesses/build/Release/nodeprocesses.node"); -gpii.processes = fluid.registerNamespace("gpii.processes"); +var gpii = fluid.registerNamespace("gpii"); -fluid.defaults("gpii.processes.native", { - gradeNames: ["fluid.component"], +fluid.defaults("gpii.processes.linux", { + gradeNames: ["gpii.processes"], invokers: { getProcessList: { - funcName: "gpii.processes.native.getProcessList", + funcName: "gpii.processes.linux.getProcessList", args: [] } } }); // Return a list of processes -- a snapshot of the current processes. -gpii.processes["native"].getProcessList = function () { +gpii.processes.linux.getProcessList = function () { return nodeProcesses.getProcesses(); }; diff --git a/gpii/node_modules/processReporter/test/processesBridge_tests.js b/gpii/node_modules/processReporter/test/processesBridge_tests.js index bcbc6f5..646bf42 100644 --- a/gpii/node_modules/processReporter/test/processesBridge_tests.js +++ b/gpii/node_modules/processReporter/test/processesBridge_tests.js @@ -20,26 +20,18 @@ var path = require("path"), jqUnit = fluid.require("node-jqunit"); require("../processesBridge.js"); -var processesBridge = fluid.registerNamespace("gpii.processes"); -var procTests = fluid.registerNamespace("gpii.tests.processes"); - -procTests.waitMsec = function (msec) { - var t0 = Date.now(); - var longEnough = false; - while (!longEnough) { - longEnough = ((Date.now() - t0) > msec); - } -}; + +var gpii = fluid.registerNamespace("gpii"); +var processesBridge = gpii.processes.linux(); jqUnit.module("Processes Bridge node add-on module"); jqUnit.test( "Test getProceses()/findProcessByPid() with the nodejs process itself", function () { - var procInfos = processesBridge["native"].getProcessList(); + var procInfos = processesBridge.getProcessList(); jqUnit.assertNotEquals( "Listing all processes", 0, procInfos.length ); - // Check for the presence of this nodejs processs itself -- it must // be in the process list since this code is running inside that // process. From f3730cfd01864ce980516276367b09852c04bb3c Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Tue, 22 Aug 2017 16:01:50 -0400 Subject: [PATCH 72/78] GPII-442: Process Reporter context awareness. Improved context aware inokers for getting the platorm specific list of running processes. --- gpii/node_modules/processReporter/processesBridge.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gpii/node_modules/processReporter/processesBridge.js b/gpii/node_modules/processReporter/processesBridge.js index 8b7f634..977e552 100644 --- a/gpii/node_modules/processReporter/processesBridge.js +++ b/gpii/node_modules/processReporter/processesBridge.js @@ -23,7 +23,7 @@ var gpii = fluid.registerNamespace("gpii"); fluid.defaults("gpii.processes.linux", { gradeNames: ["gpii.processes"], invokers: { - getProcessList: { + getPlaformProcesssList: { funcName: "gpii.processes.linux.getProcessList", args: [] } From 08a48dad4110adf57445b6f0e4d864c1aafb2ee7 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Tue, 5 Sep 2017 16:21:37 -0400 Subject: [PATCH 73/78] GPII-442: Removed getPlatformProcessList() invoker from the processes bridge Removed getPlatformProcessList() and collapsed implementation into getProcessList(). --- gpii/node_modules/processReporter/processesBridge.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gpii/node_modules/processReporter/processesBridge.js b/gpii/node_modules/processReporter/processesBridge.js index 977e552..8b7f634 100644 --- a/gpii/node_modules/processReporter/processesBridge.js +++ b/gpii/node_modules/processReporter/processesBridge.js @@ -23,7 +23,7 @@ var gpii = fluid.registerNamespace("gpii"); fluid.defaults("gpii.processes.linux", { gradeNames: ["gpii.processes"], invokers: { - getPlaformProcesssList: { + getProcessList: { funcName: "gpii.processes.linux.getProcessList", args: [] } From 3a362fe1d36440cdf92014d19fd2ec2bf5d3f8b0 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Fri, 15 Sep 2017 12:26:19 -0400 Subject: [PATCH 74/78] GPII-442: Updated package.json to point to the correct universal revision. Universal dependency points to the revision that includes the latest Process Reporter code. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 35f6fba..a773df1 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "bugs": "http://issues.gpii.net/browse/GPII", "homepage": "http://gpii.net/", "dependencies": { - "universal": "klown/universal#GPII-442" + "universal": "gpii/universal#60daaf849ac8b774a6ce5ede34f82259253b067b" }, "devDependencies": { "grunt": "1.0.1", From bb3a2ecfdb6c536c2f0fd7036f4131270eaaaee2 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Mon, 2 Apr 2018 16:05:47 -0400 Subject: [PATCH 75/78] GPII-442: Merge branch 'GPII-2568' into GPII-442 Merge use of "gpii-universal" instead of "universal" into Linux ProcessReporter branch. --- gpii/node_modules/alsa/alsa_bridge.js | 2 +- gpii/node_modules/alsa/nodealsa/nodealsa_tests.js | 2 +- gpii/node_modules/alsa/test/alsaSettingsHandlerTests.js | 2 +- gpii/node_modules/gsettingsBridge/gsettings_bridge.js | 2 +- gpii/node_modules/gsettingsBridge/tests/gsettingsTests.js | 2 +- gpii/node_modules/orca/orcaSettingsHandler.js | 2 +- gpii/node_modules/orca/test/orcaSettingsHandlerTests.js | 2 +- gpii/node_modules/packagekit/index.js | 2 +- .../packagekit/nodepackagekit/nodepackagekit_test.js | 2 +- gpii/node_modules/packagekit/packageKitDeviceReporter.js | 2 +- gpii/node_modules/packagekit/test/all-tests.js | 2 +- .../packagekit/test/packageKitDeviceReporterTests.js | 2 +- gpii/node_modules/packagekit/test/packageKitModuleTests.js | 2 +- gpii/node_modules/xrandr/nodexrandr/nodexrandr_tests.js | 2 +- gpii/node_modules/xrandr/test/xrandrSettingsHandlerTests.js | 2 +- gpii/node_modules/xrandr/xrandr_bridge.js | 2 +- index.js | 2 +- package.json | 4 ++-- tests/AcceptanceTests.js | 6 +++--- 19 files changed, 22 insertions(+), 22 deletions(-) diff --git a/gpii/node_modules/alsa/alsa_bridge.js b/gpii/node_modules/alsa/alsa_bridge.js index a80f5ac..cea1387 100644 --- a/gpii/node_modules/alsa/alsa_bridge.js +++ b/gpii/node_modules/alsa/alsa_bridge.js @@ -16,7 +16,7 @@ "use strict"; -var fluid = require("universal"); +var fluid = require("gpii-universal"); var gpii = fluid.registerNamespace("gpii"); var alsa = require("./nodealsa/build/Release/nodealsa.node"); diff --git a/gpii/node_modules/alsa/nodealsa/nodealsa_tests.js b/gpii/node_modules/alsa/nodealsa/nodealsa_tests.js index bd6c02c..1d74142 100644 --- a/gpii/node_modules/alsa/nodealsa/nodealsa_tests.js +++ b/gpii/node_modules/alsa/nodealsa/nodealsa_tests.js @@ -16,7 +16,7 @@ "use strict"; -var fluid = require("universal"), +var fluid = require("gpii-universal"), jqUnit = fluid.require("node-jqunit"), alsa = require("./build/Release/nodealsa.node"); diff --git a/gpii/node_modules/alsa/test/alsaSettingsHandlerTests.js b/gpii/node_modules/alsa/test/alsaSettingsHandlerTests.js index 0f93256..d940fec 100644 --- a/gpii/node_modules/alsa/test/alsaSettingsHandlerTests.js +++ b/gpii/node_modules/alsa/test/alsaSettingsHandlerTests.js @@ -16,7 +16,7 @@ "use strict"; -var fluid = require("universal"), +var fluid = require("gpii-universal"), jqUnit = fluid.require("node-jqunit"); require("alsa"); diff --git a/gpii/node_modules/gsettingsBridge/gsettings_bridge.js b/gpii/node_modules/gsettingsBridge/gsettings_bridge.js index 8ce8681..711677c 100644 --- a/gpii/node_modules/gsettingsBridge/gsettings_bridge.js +++ b/gpii/node_modules/gsettingsBridge/gsettings_bridge.js @@ -16,7 +16,7 @@ "use strict"; -var fluid = require("universal"); +var fluid = require("gpii-universal"); var gpii = fluid.registerNamespace("gpii"); var nodeGSettings = require("./nodegsettings/build/Release/nodegsettings.node"); diff --git a/gpii/node_modules/gsettingsBridge/tests/gsettingsTests.js b/gpii/node_modules/gsettingsBridge/tests/gsettingsTests.js index d052953..5928882 100644 --- a/gpii/node_modules/gsettingsBridge/tests/gsettingsTests.js +++ b/gpii/node_modules/gsettingsBridge/tests/gsettingsTests.js @@ -16,7 +16,7 @@ "use strict"; -var fluid = require("universal"), +var fluid = require("gpii-universal"), gpii = fluid.registerNamespace("gpii"), jqUnit = fluid.require("node-jqunit"); diff --git a/gpii/node_modules/orca/orcaSettingsHandler.js b/gpii/node_modules/orca/orcaSettingsHandler.js index d52337c..683d850 100644 --- a/gpii/node_modules/orca/orcaSettingsHandler.js +++ b/gpii/node_modules/orca/orcaSettingsHandler.js @@ -18,7 +18,7 @@ "use strict"; -var fluid = require("universal"); +var fluid = require("gpii-universal"); var gpii = fluid.registerNamespace("gpii"); var fs = require("fs"); var spawn = require("child_process").spawn; diff --git a/gpii/node_modules/orca/test/orcaSettingsHandlerTests.js b/gpii/node_modules/orca/test/orcaSettingsHandlerTests.js index fef1f70..838b97e 100644 --- a/gpii/node_modules/orca/test/orcaSettingsHandlerTests.js +++ b/gpii/node_modules/orca/test/orcaSettingsHandlerTests.js @@ -17,7 +17,7 @@ "use strict"; -var fluid = require("universal"), +var fluid = require("gpii-universal"), jqUnit = fluid.require("node-jqunit"); require("orca"); diff --git a/gpii/node_modules/packagekit/index.js b/gpii/node_modules/packagekit/index.js index e497b7d..dddf29e 100644 --- a/gpii/node_modules/packagekit/index.js +++ b/gpii/node_modules/packagekit/index.js @@ -16,7 +16,7 @@ "use strict"; -var fluid = require("universal"); +var fluid = require("gpii-universal"); require("./packageKitDeviceReporter.js"); diff --git a/gpii/node_modules/packagekit/nodepackagekit/nodepackagekit_test.js b/gpii/node_modules/packagekit/nodepackagekit/nodepackagekit_test.js index df58763..3115834 100644 --- a/gpii/node_modules/packagekit/nodepackagekit/nodepackagekit_test.js +++ b/gpii/node_modules/packagekit/nodepackagekit/nodepackagekit_test.js @@ -14,7 +14,7 @@ https://github.com/gpii/universal/LICENSE.txt "use strict"; -var fluid = require("universal"), +var fluid = require("gpii-universal"), jqUnit = fluid.require("node-jqunit"), gpii = fluid.registerNamespace("gpii"), packagekit = require("./build/Release/nodepackagekit.node"); diff --git a/gpii/node_modules/packagekit/packageKitDeviceReporter.js b/gpii/node_modules/packagekit/packageKitDeviceReporter.js index 3f75954..eda347e 100644 --- a/gpii/node_modules/packagekit/packageKitDeviceReporter.js +++ b/gpii/node_modules/packagekit/packageKitDeviceReporter.js @@ -16,7 +16,7 @@ "use strict"; -var fluid = require("universal"); +var fluid = require("gpii-universal"); var gpii = fluid.registerNamespace("gpii"); var packageKit = require("./nodepackagekit/build/Release/nodepackagekit.node"); diff --git a/gpii/node_modules/packagekit/test/all-tests.js b/gpii/node_modules/packagekit/test/all-tests.js index f5e88b9..d5e54cc 100644 --- a/gpii/node_modules/packagekit/test/all-tests.js +++ b/gpii/node_modules/packagekit/test/all-tests.js @@ -11,7 +11,7 @@ */ "use strict"; -var fluid = require("universal"), +var fluid = require("gpii-universal"), kettle = fluid.require("kettle"); kettle.loadTestingSupport(); diff --git a/gpii/node_modules/packagekit/test/packageKitDeviceReporterTests.js b/gpii/node_modules/packagekit/test/packageKitDeviceReporterTests.js index 079057e..8bb845d 100644 --- a/gpii/node_modules/packagekit/test/packageKitDeviceReporterTests.js +++ b/gpii/node_modules/packagekit/test/packageKitDeviceReporterTests.js @@ -15,7 +15,7 @@ */ "use strict"; -var fluid = require("universal"), +var fluid = require("gpii-universal"), gpii = fluid.registerNamespace("gpii"), jqUnit = fluid.require("node-jqunit"); diff --git a/gpii/node_modules/packagekit/test/packageKitModuleTests.js b/gpii/node_modules/packagekit/test/packageKitModuleTests.js index 5d95122..373ffe9 100644 --- a/gpii/node_modules/packagekit/test/packageKitModuleTests.js +++ b/gpii/node_modules/packagekit/test/packageKitModuleTests.js @@ -15,7 +15,7 @@ */ "use strict"; -var fluid = require("universal"), +var fluid = require("gpii-universal"), jqUnit = fluid.require("node-jqunit"); require("packagekit"); diff --git a/gpii/node_modules/xrandr/nodexrandr/nodexrandr_tests.js b/gpii/node_modules/xrandr/nodexrandr/nodexrandr_tests.js index 56358be..55068af 100644 --- a/gpii/node_modules/xrandr/nodexrandr/nodexrandr_tests.js +++ b/gpii/node_modules/xrandr/nodexrandr/nodexrandr_tests.js @@ -16,7 +16,7 @@ "use strict"; -var fluid = require("universal"), +var fluid = require("gpii-universal"), jqUnit = fluid.require("node-jqunit"), xrandr = require("./build/Release/nodexrandr.node"); diff --git a/gpii/node_modules/xrandr/test/xrandrSettingsHandlerTests.js b/gpii/node_modules/xrandr/test/xrandrSettingsHandlerTests.js index 936929b..34c0810 100644 --- a/gpii/node_modules/xrandr/test/xrandrSettingsHandlerTests.js +++ b/gpii/node_modules/xrandr/test/xrandrSettingsHandlerTests.js @@ -16,7 +16,7 @@ "use strict"; -var fluid = require("universal"), +var fluid = require("gpii-universal"), jqUnit = fluid.require("node-jqunit"); require("xrandr"); diff --git a/gpii/node_modules/xrandr/xrandr_bridge.js b/gpii/node_modules/xrandr/xrandr_bridge.js index b54442f..4154afc 100644 --- a/gpii/node_modules/xrandr/xrandr_bridge.js +++ b/gpii/node_modules/xrandr/xrandr_bridge.js @@ -17,7 +17,7 @@ "use strict"; -var fluid = require("universal"); +var fluid = require("gpii-universal"); var gpii = fluid.registerNamespace("gpii"); var xrandr = require("./nodexrandr/build/Release/nodexrandr.node"); diff --git a/index.js b/index.js index 7f25954..f2c5113 100644 --- a/index.js +++ b/index.js @@ -17,7 +17,7 @@ "use strict"; -var fluid = require("universal"); +var fluid = require("gpii-universal"); fluid.module.register("gpii-linux", __dirname, require); diff --git a/package.json b/package.json index a773df1..b981b48 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "bugs": "http://issues.gpii.net/browse/GPII", "homepage": "http://gpii.net/", "dependencies": { - "universal": "gpii/universal#60daaf849ac8b774a6ce5ede34f82259253b067b" + "gpii-universal": "0.3.0-dev.20180221T093422Z.50833c1" }, "devDependencies": { "grunt": "1.0.1", @@ -15,7 +15,7 @@ "grunt-shell": "1.3.0", "nan": "2.4.0" }, - "license" : "BSD-3-Clause", + "license": "BSD-3-Clause", "keywords": [ "gpii", "accessibility", diff --git a/tests/AcceptanceTests.js b/tests/AcceptanceTests.js index d1ca5f8..19baac2 100644 --- a/tests/AcceptanceTests.js +++ b/tests/AcceptanceTests.js @@ -16,7 +16,7 @@ Seventh Framework Programme (FP7/2007-2013) under grant agreement no. 289016. "use strict"; -var fluid = require("universal"), +var fluid = require("gpii-universal"), gpii = fluid.registerNamespace("gpii"); gpii.loadTestingSupport(); @@ -25,7 +25,7 @@ fluid.registerNamespace("gpii.acceptanceTesting.linux"); require("../index.js"); -var baseDir = fluid.module.resolvePath("%universal/tests/"); -var linuxFiles = fluid.require("%universal/tests/platform/index-linux.js"); +var baseDir = fluid.module.resolvePath("%gpii-universal/tests/"); +var linuxFiles = fluid.require("%gpii-universal/tests/platform/index-linux.js"); gpii.test.runSuitesWithFiltering(linuxFiles, baseDir, ["gpii.test.acceptance.testCaseHolder"]); From f1e24e3dab97c957aaf17f9d7e0c0be794c3951b Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Mon, 2 Apr 2018 16:31:15 -0400 Subject: [PATCH 76/78] GPII-442: Use "gpii-universal" in Process Reporter code. --- .../processReporter/nodeprocesses/nodeprocesses_test.js | 2 +- gpii/node_modules/processReporter/processReporter.js | 2 +- gpii/node_modules/processReporter/processesBridge.js | 2 +- gpii/node_modules/processReporter/test/all-tests.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses_test.js b/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses_test.js index 2f1aa2b..a3df51a 100644 --- a/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses_test.js +++ b/gpii/node_modules/processReporter/nodeprocesses/nodeprocesses_test.js @@ -15,7 +15,7 @@ https://github.com/gpii/universal/LICENSE.txt "use strict"; var path = require("path"), - fluid = require("universal"), + fluid = require("gpii-universal"), jqUnit = fluid.require("node-jqunit"), nodeProcesses = require("./build/Release/nodeprocesses.node"); diff --git a/gpii/node_modules/processReporter/processReporter.js b/gpii/node_modules/processReporter/processReporter.js index 803d693..0415e31 100644 --- a/gpii/node_modules/processReporter/processReporter.js +++ b/gpii/node_modules/processReporter/processReporter.js @@ -12,7 +12,7 @@ "use strict"; -var fluid = require("universal"); +var fluid = require("gpii-universal"); var gpii = fluid.registerNamespace("gpii"); require("./processesBridge.js"); diff --git a/gpii/node_modules/processReporter/processesBridge.js b/gpii/node_modules/processReporter/processesBridge.js index 8b7f634..f17bb84 100644 --- a/gpii/node_modules/processReporter/processesBridge.js +++ b/gpii/node_modules/processReporter/processesBridge.js @@ -14,7 +14,7 @@ https://github.com/gpii/universal/LICENSE.txt "use strict"; -var fluid = require("universal"); +var fluid = require("gpii-universal"); var gpii = fluid.registerNamespace("gpii"); var nodeProcesses = require("./nodeprocesses/build/Release/nodeprocesses.node"); diff --git a/gpii/node_modules/processReporter/test/all-tests.js b/gpii/node_modules/processReporter/test/all-tests.js index 9f547c0..4474763 100644 --- a/gpii/node_modules/processReporter/test/all-tests.js +++ b/gpii/node_modules/processReporter/test/all-tests.js @@ -11,7 +11,7 @@ */ "use strict"; -var fluid = require("universal"), +var fluid = require("gpii-universal"), kettle = fluid.require("kettle"); kettle.loadTestingSupport(); From 61df30dbb8ff13ea5983b2c4175112befd8b8a3f Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Mon, 2 Apr 2018 16:52:43 -0400 Subject: [PATCH 77/78] GPII-442: Use "gpii-universal" in Process Reporter code. Added a "gpii-universal" missed from previous commit --- gpii/node_modules/processReporter/test/processesBridge_tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gpii/node_modules/processReporter/test/processesBridge_tests.js b/gpii/node_modules/processReporter/test/processesBridge_tests.js index 646bf42..9d3e1fc 100644 --- a/gpii/node_modules/processReporter/test/processesBridge_tests.js +++ b/gpii/node_modules/processReporter/test/processesBridge_tests.js @@ -16,7 +16,7 @@ https://github.com/gpii/universal/LICENSE.txt var path = require("path"), spawn = require("child_process").spawn, - fluid = require("universal"), + fluid = require("gpii-universal"), jqUnit = fluid.require("node-jqunit"); require("../processesBridge.js"); From 4458bf80df5e4fe263dfedc676ec12e979149d2d Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Mon, 2 Apr 2018 17:08:22 -0400 Subject: [PATCH 78/78] GPII-442: Use "gpii-universal" in Process Reporter code. Added one more "gpii-universal" missed from previous commits --- .../processReporter/test/processReporterModuleTests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gpii/node_modules/processReporter/test/processReporterModuleTests.js b/gpii/node_modules/processReporter/test/processReporterModuleTests.js index ba064ba..6d05df4 100644 --- a/gpii/node_modules/processReporter/test/processReporterModuleTests.js +++ b/gpii/node_modules/processReporter/test/processReporterModuleTests.js @@ -11,7 +11,7 @@ */ "use strict"; -var fluid = require("universal"), +var fluid = require("gpii-universal"), jqUnit = fluid.require("node-jqunit"); require("processReporter");