blob: 2af8e845401c26ccd140f115778a906090797c13 [file] [log] [blame]
// Copyright 2016 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
'use strict';
/**
* @fileoverview WiFiStateMachine class to represent and hold state for each
* instance of an Android WiFiStateMachine for a given log being processed.
*/
/**
* @constructor
*
* @param {String} id Identifier for new WifiStateMachine instance.
* @param {long} ms WifiStateMachine start time in ms.
*/
function WifiStateMachine(id, ms) {
this.id = id;
this.startTime = ms;
this.scans = 0;
this.scanDetails = [];
this.networkDetailedStates = [];
this.endTime = -1;
this.supplicantStates = [];
}
/**
* This method adds supplicant state transitions.
*
* @param {Update} update Object holding previous state, new state and time.
*/
WifiStateMachine.prototype.addSupplicantState = function(update) {
if (update.time == null) {
this.supplicantStates.push({'x': 0, 'y': update.newState});
return;
}
var updateElapsedTime = Date.parse(update.time) - this.startTime;
if (update.oldState == update.newState) {
// not a new state transition... still check if we have anything stored
if (this.supplicantStates.length > 0) {
// not a new transition... return
return;
}
this.supplicantStates.push({'x': updateElapsedTime, 'y': update.oldState});
return;
}
// now we know the states are different, we need to process this update
if (this.supplicantStates.length > 0) {
// should check states to make sure they match
var lastUpdate = this.supplicantStates[this.supplicantStates.length - 1];
if (lastUpdate.y != update.oldState) {
this.supplicantStates.push({'x': updateElapsedTime,
'y': lastUpdate.y});
this.supplicantStates.push({'x': updateElapsedTime,
'y': update.oldState});
}
} else {
// need to enter previous state - use update time since we do not have the
// start time.
this.supplicantStates.push({'x': updateElapsedTime, 'y': update.oldState});
}
this.supplicantStates.push({'x': updateElapsedTime,
'y': update.oldState});
this.supplicantStates.push({'x': updateElapsedTime,
'y': update.newState});
};