1 /*******************************************************************************
2 * Copyright (c) 2009 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation
11 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.lttng
.state
.model
;
14 import java
.util
.Stack
;
16 import org
.eclipse
.linuxtools
.lttng
.state
.StateStrings
;
17 import org
.eclipse
.linuxtools
.lttng
.state
.StateStrings
.CpuMode
;
20 * <b><u>LTTngCPUState</u></b>
24 public class LTTngCPUState
implements Cloneable
{
25 // ========================================================================
27 // =======================================================================
28 private Stack
<StateStrings
.CpuMode
> mode_stack
= new Stack
<StateStrings
.CpuMode
>();
29 private Stack
<Long
> irq_stack
= new Stack
<Long
>();
30 private Stack
<Long
> softirq_stack
= new Stack
<Long
>();
31 private Stack
<Long
> trap_stack
= new Stack
<Long
>();
33 // ========================================================================
35 // =======================================================================
36 public LTTngCPUState() {
37 mode_stack
.push(CpuMode
.LTTV_CPU_UNKNOWN
);
39 softirq_stack
.push(-1L);
44 @SuppressWarnings("unchecked")
45 public LTTngCPUState
clone() {
46 LTTngCPUState newState
= null;
49 newState
= (LTTngCPUState
) super.clone();
51 // // *** IMPORTANT ***
52 // // Basic type in java are immutable!
53 // // Thus, using assignation ("=") on basic type is CORRECT,
54 // // but we should ALWAYS use "new" or "clone()" on "non basic"
57 // Clone should work correctly for all stack object that contain
58 // basic java object (String, Long, etc...)
59 newState
.mode_stack
= (Stack
<StateStrings
.CpuMode
>) this.mode_stack
61 newState
.irq_stack
= (Stack
<Long
>) this.irq_stack
.clone();
62 newState
.softirq_stack
= (Stack
<Long
>) this.softirq_stack
.clone();
63 newState
.trap_stack
= (Stack
<Long
>) this.trap_stack
.clone();
64 } catch (CloneNotSupportedException e
) {
65 System
.out
.println("Cloning failed with : " + e
.getMessage()); //$NON-NLS-1$
71 // ========================================================================
73 public void clearAndSetBaseToCpuStack(StateStrings
.CpuMode newCpuMode
) {
76 softirq_stack
.clear();
79 // Ensure that there is always at least 1 item in the stack
80 mode_stack
.push(newCpuMode
);
82 softirq_stack
.push(-1L);
87 public void pushToCpuStack(StateStrings
.CpuMode newCpuMode
) {
88 mode_stack
.push(newCpuMode
);
91 public void pushToIrqStack(Long irqID
) {
92 irq_stack
.push(irqID
);
95 public void pushToSoftIrqStack(Long softIrqID
) {
96 softirq_stack
.push(softIrqID
);
99 public void pushToTrapStack(Long trapID
) {
100 trap_stack
.push(trapID
);
104 public StateStrings
.CpuMode
popFromCpuStack() {
106 StateStrings
.CpuMode returnedMode
= mode_stack
.pop();
108 if (mode_stack
.size() < 1) {
109 // Ensure that there is always at least 1 item in the stack
110 mode_stack
.push(StateStrings
.CpuMode
.LTTV_CPU_UNKNOWN
);
117 public Long
popFromIrqStack() {
118 Long irq
= irq_stack
.pop();
120 if (irq_stack
.size() < 1) {
121 // make sure the stack is not empty
127 public Long
popFromSoftIrqStack() {
128 Long softirq
= softirq_stack
.pop();
130 if (softirq_stack
.size() < 1) {
131 // make sure the stack is not empty
132 softirq_stack
.push(-1L);
137 public Long
popFromTrapStack() {
138 Long trap
= trap_stack
.pop();
140 if (trap_stack
.size() < 1) {
141 // make sure the stack is not empty
142 trap_stack
.push(-1L);
148 public StateStrings
.CpuMode
peekFromCpuStack() {
149 return mode_stack
.peek();
152 public Long
peekFromIrqStack() {
153 return irq_stack
.peek();
156 public Long
peekFromSoftIrqStack() {
157 return softirq_stack
.peek();
160 public Long
peekFromTrapStack() {
161 return trap_stack
.peek();
165 public void reset() {
168 softirq_stack
.clear();
171 // Ensure that there is always at least 1 item in the stack
172 mode_stack
.push(CpuMode
.LTTV_CPU_UNKNOWN
);
174 softirq_stack
.push(-1L);
175 trap_stack
.push(-1L);