Skip to content

Commit dd37461

Browse files
crokitashiniwatrenonick87
authored
Feature/choice set manager (#371)
* Implementing SDL 0274: Add preferred FPS to VideoStreamingCapability. * Added preferredFPS to ideoStreamingParametersTest. * Set up foundational APIs and classes * Finish main implementation of choice set manager * Fix linter issues * Fix reference issues * Add unit tests and update files based on test results * Fix more bugs found during testing * Update rpc_spec, .gitmodules, some JSs in accordance with code review at #357. * Apply suggestions from code review Co-authored-by: renonick87 <[email protected]> * Apply feedback from review * Resolve merge conflicts * Revert "Merge branch 'feature/issue-115' of https://github.com/shiniwat/sdl_javascript_suite into feature/choice-set-manager" This reverts commit 4c2ee61, reversing changes made to e692b28. * Finish review revisions * Fix test failures Co-authored-by: Shinichi Watanabe <[email protected]> Co-authored-by: renonick87 <[email protected]>
1 parent 16fab63 commit dd37461

27 files changed

+3839
-6
lines changed

lib/js/src/manager/_SubManagerBase.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { _Task } from './_Task.js';
3535
import { FunctionID } from '../rpc/enums/FunctionID.js';
3636
import { PredefinedWindows } from '../rpc/enums/PredefinedWindows.js';
3737
import { SystemCapabilityType } from '../rpc/enums/SystemCapabilityType.js';
38+
import { SystemContext } from '../rpc/enums/SystemContext.js';
3839

3940
/**
4041
* _SubManagerBase handles the basic state transitions from
@@ -58,6 +59,7 @@ class _SubManagerBase {
5859
this._canRunTasks = false; // whether the task queue can run
5960
this._isTaskRunning = false; // whether tasks are running
6061
this._taskQueue = [];
62+
this._currentSystemContext = SystemContext.SYSCTXT_MAIN;
6163
this._transitionToState(SETTING_UP);
6264
}
6365

@@ -94,6 +96,7 @@ class _SubManagerBase {
9496

9597
if (this._isHandlingTasks) {
9698
this._currentHmiLevel = HMILevel.HMI_NONE;
99+
this._currentSystemContext = null;
97100
this._taskQueue.splice(0, this._taskQueue.length);
98101
this._canRunTasks = false;
99102
if (typeof this._hmiListener === 'function') {
@@ -102,6 +105,7 @@ class _SubManagerBase {
102105
this._isHandlingTasks = false;
103106
}
104107

108+
105109
this._transitionToState(SHUTDOWN);
106110
}
107111

@@ -185,8 +189,9 @@ class _SubManagerBase {
185189
* Sets up a listener to the OnHMIStatus and manages the task queue
186190
* Uses the HMI level state to determine whether the task queue should be run
187191
* @private
192+
* @param {Boolean} readSystemContext - Whether to use OnHMIStatus's system context value to pause and resume the task queue
188193
*/
189-
_handleTaskQueue () {
194+
_handleTaskQueue (readSystemContext = false) {
190195
this._isHandlingTasks = true;
191196
this._hmiListener = (onHmiStatus) => {
192197
if (onHmiStatus.getWindowID() !== null && onHmiStatus.getWindowID() !== PredefinedWindows.DEFAULT_WINDOW) {
@@ -203,6 +208,17 @@ class _SubManagerBase {
203208
if (oldHmiLevel !== HMILevel.HMI_NONE && this._currentHmiLevel === HMILevel.HMI_NONE) {
204209
this._canRunTasks = false;
205210
}
211+
212+
// used when we want to read system context to determine the queue status
213+
if (readSystemContext) {
214+
this._currentSystemContext = onHmiStatus.getSystemContext();
215+
if (this._currentSystemContext === SystemContext.SYSCTXT_HMI_OBSCURED || this._currentSystemContext === SystemContext.SYSCTXT_ALERT) {
216+
this._canRunTasks = false;
217+
}
218+
if (this._currentSystemContext === SystemContext.SYSCTXT_MAIN && this._currentHmiLevel !== HMILevel.HMI_NONE) {
219+
this._canRunTasks = true;
220+
}
221+
}
206222
};
207223

208224
this._lifecycleManager.addRpcListener(FunctionID.OnHMIStatus, this._hmiListener);
@@ -257,6 +273,7 @@ class _SubManagerBase {
257273
/**
258274
* Execute the task queue if there are tasks and if tasks can be run. Will recurse until all tasks are completed
259275
* @private
276+
* @returns {Promise} - No value returned from the promise
260277
*/
261278
async _invokeTaskQueue () {
262279
if (!this._isHandlingTasks) {

lib/js/src/manager/file/filetypes/SdlFile.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,44 @@ class SdlFile {
177177
getOverwrite () {
178178
return this._overwrite;
179179
}
180+
181+
/**
182+
* Checks whether two SdlFiles can be considered equivalent
183+
* @param {SdlFile} other - The object to compare
184+
* @returns {Boolean} - Whether the objects are the same or not
185+
*/
186+
equals (other) {
187+
if (other === null || other === undefined) {
188+
return false;
189+
}
190+
if (this === other) {
191+
return true;
192+
}
193+
if (!(other instanceof SdlFile)) {
194+
return false;
195+
}
196+
197+
// main comparison check
198+
if (this.getName() !== other.getName()) {
199+
return false;
200+
}
201+
if (this.getFilePath() !== other.getFilePath()) {
202+
return false;
203+
}
204+
if (this.getFileData() !== other.getFileData()) {
205+
return false;
206+
}
207+
if (this.getType() !== other.getType()) {
208+
return false;
209+
}
210+
if (this.isPersistent() !== other.isPersistent()) {
211+
return false;
212+
}
213+
if (this.isStaticIcon() !== other.isStaticIcon()) {
214+
return false;
215+
}
216+
return true;
217+
}
180218
}
181219

182220

lib/js/src/manager/screen/_ScreenManagerBase.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { _SoftButtonManager } from './_SoftButtonManager.js';
3535
import { _TextAndGraphicManager } from './_TextAndGraphicManager.js';
3636
import { _VoiceCommandManager } from './_VoiceCommandManager.js';
3737
import { _SubscribeButtonManager } from './_SubscribeButtonManager';
38+
import { _ChoiceSetManagerBase } from './choiceset/_ChoiceSetManagerBase';
3839

3940
class _ScreenManagerBase extends _SubManagerBase {
4041
/**
@@ -51,6 +52,7 @@ class _ScreenManagerBase extends _SubManagerBase {
5152
if (this._fileManager !== null) {
5253
this._softButtonManager = new _SoftButtonManager(lifecycleManager, this._fileManager);
5354
this._textAndGraphicManager = new _TextAndGraphicManager(lifecycleManager, this._fileManager, this._softButtonManager);
55+
this._choiceSetManagerBase = new _ChoiceSetManagerBase(lifecycleManager, this._fileManager);
5456
}
5557
this._voiceCommandManager = new _VoiceCommandManager(lifecycleManager);
5658
this._subscribeButtonManager = new _SubscribeButtonManager(lifecycleManager);
@@ -66,6 +68,7 @@ class _ScreenManagerBase extends _SubManagerBase {
6668
this._textAndGraphicManager.start(),
6769
this._voiceCommandManager.start(),
6870
this._subscribeButtonManager.start(),
71+
this._choiceSetManagerBase.start(),
6972
]);
7073
this._transitionToState(_SubManagerBase.READY);
7174
await super.start();
@@ -79,6 +82,7 @@ class _ScreenManagerBase extends _SubManagerBase {
7982
this._textAndGraphicManager.dispose();
8083
this._voiceCommandManager.dispose();
8184
this._subscribeButtonManager.dispose();
85+
this._choiceSetManagerBase.dispose();
8286
super.dispose();
8387
}
8488

@@ -442,6 +446,78 @@ class _ScreenManagerBase extends _SubManagerBase {
442446
return this._voiceCommandManager.setVoiceCommands(voiceCommands);
443447
}
444448

449+
/**
450+
* Deletes choices that were sent previously
451+
* @param {ChoiceCell[]} choices - A list of ChoiceCell objects
452+
* @returns {Promise} - A promise that resolves to a Boolean of whether the operation is a success
453+
*/
454+
async deleteChoices (choices) {
455+
return this._choiceSetManagerBase.deleteChoices(choices);
456+
}
457+
458+
/**
459+
* Preload choices to improve performance while presenting a choice set at a later time
460+
* @param {ChoiceCell[]} choices - a list of ChoiceCell objects that will be part of a choice set later
461+
* @returns {Promise} - A promise.
462+
*/
463+
async preloadChoices (choices) {
464+
return this._choiceSetManagerBase.preloadChoices(choices);
465+
}
466+
467+
/**
468+
* Presents a searchable choice set
469+
* @param {ChoiceSet} choiceSet - The choice set to be presented. This can include Choice Cells that were preloaded or not
470+
* @param {InteractionMode} mode - The intended interaction mode
471+
* @param {KeyboardListener} keyboardListener - A keyboard listener to capture user input
472+
*/
473+
presentSearchableChoiceSet (choiceSet, mode, keyboardListener) {
474+
this._choiceSetManagerBase.presentChoiceSet(choiceSet, mode, keyboardListener);
475+
}
476+
477+
/**
478+
* Presents a choice set
479+
* @param {ChoiceSet} choiceSet - The choice set to be presented. This can include Choice Cells that were preloaded or not
480+
* @param {InteractionMode} mode - The intended interaction mode
481+
*/
482+
presentChoiceSet (choiceSet, mode) {
483+
this._choiceSetManagerBase.presentChoiceSet(choiceSet, mode, null);
484+
}
485+
486+
/**
487+
* Presents a keyboard on the Head unit to capture user input
488+
* @param {String} initialText - The initial text that is used as a placeholder text. It might not work on some head units.
489+
* @param {KeyboardProperties} customKeyboardProperties - the custom keyboard configuration to be used when the keyboard is displayed
490+
* @param {KeyboardListener} keyboardListener - A keyboard listener to capture user input
491+
* @returns {Number|null} - A unique cancel ID that can be used to cancel this keyboard. If `null`, no keyboard was created.
492+
*/
493+
presentKeyboard (initialText, customKeyboardProperties, keyboardListener) {
494+
return this._choiceSetManagerBase.presentKeyboard(initialText, customKeyboardProperties, keyboardListener);
495+
}
496+
497+
/**
498+
* Set a custom keyboard configuration for this session. If set to null, it will reset to default keyboard configuration.
499+
* @param {KeyboardProperties} keyboardConfiguration - the custom keyboard configuration to be used when the keyboard is displayed
500+
*/
501+
setKeyboardConfiguration (keyboardConfiguration) {
502+
this._choiceSetManagerBase.setKeyboardConfiguration(keyboardConfiguration);
503+
}
504+
505+
/**
506+
* Get the preloaded choices
507+
* @returns {ChoiceCell[]} - A set of choice cells that have been preloaded to the head unit
508+
*/
509+
getPreloadedChoices () {
510+
return this._choiceSetManagerBase.getPreloadedChoices();
511+
}
512+
513+
/**
514+
* Dismisses a currently presented keyboard with the associated ID. Canceling a keyboard only works when connected to SDL Core v.6.0+. When connected to older versions of SDL Core the keyboard will not be dismissed.
515+
* @param {Number} cancelId - The unique ID assigned to the keyboard
516+
*/
517+
dismissKeyboard (cancelId) {
518+
this._choiceSetManagerBase.dismissKeyboard(cancelId);
519+
}
520+
445521
/**
446522
* Begin a multiple updates transaction. The updates will be applied when commit() is called. Note: if we don't use beginTransaction & commit, every update will be sent individually.
447523
*/

0 commit comments

Comments
 (0)