| // Copyright 2015 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 Service class to represent and hold state for each instance |
| * of a shill service for a given log being processed. |
| */ |
| |
| /** |
| * @constructor |
| * |
| * @param {String} serviceId Identifier for the new service instance. |
| * */ |
| function Service(serviceId) { |
| this.serviceId = serviceId; |
| this.states = []; |
| this.isActive = false; |
| this.connections = 0; |
| this.graphData = []; |
| } |
| |
| /** |
| * Method to add an update to a service. |
| * |
| * @param {Update} update Update object to add. |
| */ |
| Service.prototype.addUpdate = function(update) { |
| if (update.time == null) { |
| this.graphData.push({'x': 0, 'y': update.state}); |
| return; |
| } |
| |
| if (netlogSummary.isActive(update.state)) { |
| this.isActive = true; |
| } |
| if (this.states.length > 0) { |
| var lastUpdate = this.states[this.states.length - 1]; |
| if (lastUpdate.state != update.state || update.failure) { |
| this.states.push(update); |
| this.graphData.push({'x': update.time, 'y': lastUpdate.state}); |
| } else { |
| console.log('last state update was the same... ignoring'); |
| return; |
| } |
| } else { |
| if (this.graphData.length > 0) { |
| this.graphData.push({'x': update.time, 'y': this.graphData[0].y}); |
| } |
| this.states.push(update); |
| } |
| this.graphData.push({'x': update.time, 'y': update.state}); |
| if (update.state == 'Associating') { |
| this.connections++; |
| } |
| }; |
| |
| /** |
| * Method to return most recent update for a service. Returns null if no |
| * state updates exist. |
| * |
| * @return {Update} The last update for this service. |
| */ |
| Service.prototype.getCurrentUpdate = function() { |
| if (this.states.length > 0) |
| return this.states[this.states.length - 1]; |
| return null; |
| }; |
| |